]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- update patches for 2.6.32; they apply when using --without grsecurity
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.32/arch/alpha/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/alpha/Kconfig
2 --- linux-2.6.32/arch/alpha/Kconfig     2009-12-03 20:01:49.000000000 +0100
3 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/alpha/kernel/entry.S linux-2.6.32-vs2.3.0.36.26/arch/alpha/kernel/entry.S
14 --- linux-2.6.32/arch/alpha/kernel/entry.S      2009-06-11 17:11:46.000000000 +0200
15 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/alpha/kernel/osf_sys.c linux-2.6.32-vs2.3.0.36.26/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.32/arch/alpha/kernel/osf_sys.c    2009-09-10 15:25:14.000000000 +0200
50 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/alpha/kernel/ptrace.c linux-2.6.32-vs2.3.0.36.26/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.32/arch/alpha/kernel/ptrace.c     2009-09-10 15:25:14.000000000 +0200
62 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/alpha/kernel/systbls.S linux-2.6.32-vs2.3.0.36.26/arch/alpha/kernel/systbls.S
72 --- linux-2.6.32/arch/alpha/kernel/systbls.S    2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/alpha/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/alpha/kernel/traps.c
84 --- linux-2.6.32/arch/alpha/kernel/traps.c      2009-06-11 17:11:46.000000000 +0200
85 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/alpha/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/alpha/mm/fault.c
97 --- linux-2.6.32/arch/alpha/mm/fault.c  2009-09-10 15:25:14.000000000 +0200
98 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/arm/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/arm/Kconfig
111 --- linux-2.6.32/arch/arm/Kconfig       2009-12-03 20:01:49.000000000 +0100
112 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/arm/kernel/calls.S linux-2.6.32-vs2.3.0.36.26/arch/arm/kernel/calls.S
123 --- linux-2.6.32/arch/arm/kernel/calls.S        2009-12-03 20:01:50.000000000 +0100
124 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/arm/kernel/process.c linux-2.6.32-vs2.3.0.36.26/arch/arm/kernel/process.c
135 --- linux-2.6.32/arch/arm/kernel/process.c      2009-12-03 20:01:50.000000000 +0100
136 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/arm/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/arm/kernel/traps.c
148 --- linux-2.6.32/arch/arm/kernel/traps.c        2009-12-03 20:01:50.000000000 +0100
149 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/avr32/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/avr32/mm/fault.c
162 --- linux-2.6.32/arch/avr32/mm/fault.c  2009-09-10 15:25:20.000000000 +0200
163 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/cris/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/cris/Kconfig
175 --- linux-2.6.32/arch/cris/Kconfig      2009-06-11 17:11:56.000000000 +0200
176 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/cris/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/cris/mm/fault.c
187 --- linux-2.6.32/arch/cris/mm/fault.c   2009-12-03 20:01:56.000000000 +0100
188 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/frv/kernel/kernel_thread.S linux-2.6.32-vs2.3.0.36.26/arch/frv/kernel/kernel_thread.S
200 --- linux-2.6.32/arch/frv/kernel/kernel_thread.S        2008-12-25 00:26:37.000000000 +0100
201 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/frv/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/frv/mm/fault.c
212 --- linux-2.6.32/arch/frv/mm/fault.c    2009-09-10 15:25:22.000000000 +0200
213 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/h8300/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/h8300/Kconfig
225 --- linux-2.6.32/arch/h8300/Kconfig     2009-03-24 14:18:24.000000000 +0100
226 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/ia32/ia32_entry.S linux-2.6.32-vs2.3.0.36.26/arch/ia64/ia32/ia32_entry.S
237 --- linux-2.6.32/arch/ia64/ia32/ia32_entry.S    2009-06-11 17:11:57.000000000 +0200
238 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/ia64/Kconfig
249 --- linux-2.6.32/arch/ia64/Kconfig      2009-12-03 20:01:56.000000000 +0100
250 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/kernel/entry.S linux-2.6.32-vs2.3.0.36.26/arch/ia64/kernel/entry.S
261 --- linux-2.6.32/arch/ia64/kernel/entry.S       2009-09-10 15:25:22.000000000 +0200
262 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/kernel/perfmon.c linux-2.6.32-vs2.3.0.36.26/arch/ia64/kernel/perfmon.c
273 --- linux-2.6.32/arch/ia64/kernel/perfmon.c     2009-09-10 15:25:22.000000000 +0200
274 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/kernel/process.c linux-2.6.32-vs2.3.0.36.26/arch/ia64/kernel/process.c
293 --- linux-2.6.32/arch/ia64/kernel/process.c     2009-12-03 20:01:56.000000000 +0100
294 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/kernel/ptrace.c linux-2.6.32-vs2.3.0.36.26/arch/ia64/kernel/ptrace.c
307 --- linux-2.6.32/arch/ia64/kernel/ptrace.c      2009-09-10 15:25:22.000000000 +0200
308 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/ia64/kernel/traps.c
318 --- linux-2.6.32/arch/ia64/kernel/traps.c       2008-12-25 00:26:37.000000000 +0100
319 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/ia64/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/ia64/mm/fault.c
345 --- linux-2.6.32/arch/ia64/mm/fault.c   2009-09-10 15:25:23.000000000 +0200
346 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m32r/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/m32r/kernel/traps.c
366 --- linux-2.6.32/arch/m32r/kernel/traps.c       2009-12-03 20:01:57.000000000 +0100
367 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m32r/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/m32r/mm/fault.c
381 --- linux-2.6.32/arch/m32r/mm/fault.c   2009-09-10 15:25:23.000000000 +0200
382 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m68k/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/m68k/Kconfig
394 --- linux-2.6.32/arch/m68k/Kconfig      2009-12-03 20:01:57.000000000 +0100
395 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m68k/kernel/ptrace.c linux-2.6.32-vs2.3.0.36.26/arch/m68k/kernel/ptrace.c
406 --- linux-2.6.32/arch/m68k/kernel/ptrace.c      2008-12-25 00:26:37.000000000 +0100
407 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m68k/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/m68k/kernel/traps.c
426 --- linux-2.6.32/arch/m68k/kernel/traps.c       2009-09-10 15:25:23.000000000 +0200
427 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m68k/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/m68k/mm/fault.c
440 --- linux-2.6.32/arch/m68k/mm/fault.c   2009-09-10 15:25:23.000000000 +0200
441 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m68knommu/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/m68knommu/Kconfig
453 --- linux-2.6.32/arch/m68knommu/Kconfig 2009-12-03 20:01:57.000000000 +0100
454 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/m68knommu/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/m68knommu/kernel/traps.c
465 --- linux-2.6.32/arch/m68knommu/kernel/traps.c  2009-09-10 15:25:23.000000000 +0200
466 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/microblaze/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/microblaze/mm/fault.c
480 --- linux-2.6.32/arch/microblaze/mm/fault.c     2009-09-10 15:25:24.000000000 +0200
481 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/mips/Kconfig
493 --- linux-2.6.32/arch/mips/Kconfig      2009-12-03 20:01:58.000000000 +0100
494 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/kernel/ptrace.c linux-2.6.32-vs2.3.0.36.26/arch/mips/kernel/ptrace.c
505 --- linux-2.6.32/arch/mips/kernel/ptrace.c      2008-12-25 00:26:37.000000000 +0100
506 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/kernel/scall32-o32.S linux-2.6.32-vs2.3.0.36.26/arch/mips/kernel/scall32-o32.S
526 --- linux-2.6.32/arch/mips/kernel/scall32-o32.S 2009-12-03 20:01:59.000000000 +0100
527 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/kernel/scall64-64.S linux-2.6.32-vs2.3.0.36.26/arch/mips/kernel/scall64-64.S
538 --- linux-2.6.32/arch/mips/kernel/scall64-64.S  2009-12-03 20:01:59.000000000 +0100
539 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/kernel/scall64-n32.S linux-2.6.32-vs2.3.0.36.26/arch/mips/kernel/scall64-n32.S
550 --- linux-2.6.32/arch/mips/kernel/scall64-n32.S 2009-12-03 20:01:59.000000000 +0100
551 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/kernel/scall64-o32.S linux-2.6.32-vs2.3.0.36.26/arch/mips/kernel/scall64-o32.S
562 --- linux-2.6.32/arch/mips/kernel/scall64-o32.S 2009-12-03 20:01:59.000000000 +0100
563 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mips/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/mips/kernel/traps.c
574 --- linux-2.6.32/arch/mips/kernel/traps.c       2009-12-03 20:01:59.000000000 +0100
575 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/mn10300/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/mn10300/mm/fault.c
591 --- linux-2.6.32/arch/mn10300/mm/fault.c        2009-09-10 15:25:39.000000000 +0200
592 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/parisc/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/parisc/Kconfig
604 --- linux-2.6.32/arch/parisc/Kconfig    2009-12-03 20:02:00.000000000 +0100
605 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/parisc/kernel/syscall_table.S linux-2.6.32-vs2.3.0.36.26/arch/parisc/kernel/syscall_table.S
616 --- linux-2.6.32/arch/parisc/kernel/syscall_table.S     2009-12-03 20:02:00.000000000 +0100
617 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/parisc/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/parisc/kernel/traps.c
628 --- linux-2.6.32/arch/parisc/kernel/traps.c     2009-09-10 15:25:40.000000000 +0200
629 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/parisc/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/parisc/mm/fault.c
654 --- linux-2.6.32/arch/parisc/mm/fault.c 2009-09-10 15:25:40.000000000 +0200
655 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/include/asm/unistd.h linux-2.6.32-vs2.3.0.36.26/arch/powerpc/include/asm/unistd.h
679 --- linux-2.6.32/arch/powerpc/include/asm/unistd.h      2009-12-03 20:02:01.000000000 +0100
680 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/powerpc/Kconfig
691 --- linux-2.6.32/arch/powerpc/Kconfig   2009-12-03 20:02:00.000000000 +0100
692 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/kernel/irq.c linux-2.6.32-vs2.3.0.36.26/arch/powerpc/kernel/irq.c
703 --- linux-2.6.32/arch/powerpc/kernel/irq.c      2009-12-03 20:02:01.000000000 +0100
704 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/kernel/process.c linux-2.6.32-vs2.3.0.36.26/arch/powerpc/kernel/process.c
714 --- linux-2.6.32/arch/powerpc/kernel/process.c  2009-12-03 20:02:02.000000000 +0100
715 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/kernel/traps.c linux-2.6.32-vs2.3.0.36.26/arch/powerpc/kernel/traps.c
729 --- linux-2.6.32/arch/powerpc/kernel/traps.c    2009-09-10 15:25:41.000000000 +0200
730 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/kernel/vdso.c linux-2.6.32-vs2.3.0.36.26/arch/powerpc/kernel/vdso.c
744 --- linux-2.6.32/arch/powerpc/kernel/vdso.c     2009-12-03 20:02:02.000000000 +0100
745 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/powerpc/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/powerpc/mm/fault.c
755 --- linux-2.6.32/arch/powerpc/mm/fault.c        2009-12-03 20:02:02.000000000 +0100
756 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/s390/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/s390/Kconfig
768 --- linux-2.6.32/arch/s390/Kconfig      2009-12-03 20:02:03.000000000 +0100
769 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/s390/kernel/ptrace.c linux-2.6.32-vs2.3.0.36.26/arch/s390/kernel/ptrace.c
780 --- linux-2.6.32/arch/s390/kernel/ptrace.c      2009-12-03 20:02:03.000000000 +0100
781 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/s390/kernel/syscalls.S linux-2.6.32-vs2.3.0.36.26/arch/s390/kernel/syscalls.S
791 --- linux-2.6.32/arch/s390/kernel/syscalls.S    2009-12-03 20:02:03.000000000 +0100
792 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/s390/lib/uaccess_pt.c linux-2.6.32-vs2.3.0.36.26/arch/s390/lib/uaccess_pt.c
803 --- linux-2.6.32/arch/s390/lib/uaccess_pt.c     2009-09-10 15:25:43.000000000 +0200
804 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sh/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/sh/Kconfig
816 --- linux-2.6.32/arch/sh/Kconfig        2009-12-03 20:02:03.000000000 +0100
817 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sh/kernel/irq.c linux-2.6.32-vs2.3.0.36.26/arch/sh/kernel/irq.c
828 --- linux-2.6.32/arch/sh/kernel/irq.c   2009-12-03 20:02:10.000000000 +0100
829 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.32-vs2.3.0.36.26/arch/sh/kernel/vsyscall/vsyscall.c
839 --- linux-2.6.32/arch/sh/kernel/vsyscall/vsyscall.c     2009-03-24 14:18:42.000000000 +0100
840 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sh/mm/fault_32.c linux-2.6.32-vs2.3.0.36.26/arch/sh/mm/fault_32.c
850 --- linux-2.6.32/arch/sh/mm/fault_32.c  2009-12-03 20:02:14.000000000 +0100
851 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sh/mm/tlbflush_64.c linux-2.6.32-vs2.3.0.36.26/arch/sh/mm/tlbflush_64.c
863 --- linux-2.6.32/arch/sh/mm/tlbflush_64.c       2009-12-03 20:02:14.000000000 +0100
864 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sparc/include/asm/tlb_64.h linux-2.6.32-vs2.3.0.36.26/arch/sparc/include/asm/tlb_64.h
876 --- linux-2.6.32/arch/sparc/include/asm/tlb_64.h        2009-09-10 15:25:45.000000000 +0200
877 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sparc/include/asm/unistd.h linux-2.6.32-vs2.3.0.36.26/arch/sparc/include/asm/unistd.h
887 --- linux-2.6.32/arch/sparc/include/asm/unistd.h        2009-12-03 20:02:15.000000000 +0100
888 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sparc/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/sparc/Kconfig
899 --- linux-2.6.32/arch/sparc/Kconfig     2009-12-03 20:02:14.000000000 +0100
900 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sparc/kernel/systbls_32.S linux-2.6.32-vs2.3.0.36.26/arch/sparc/kernel/systbls_32.S
911 --- linux-2.6.32/arch/sparc/kernel/systbls_32.S 2009-12-03 20:02:15.000000000 +0100
912 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/sparc/kernel/systbls_64.S linux-2.6.32-vs2.3.0.36.26/arch/sparc/kernel/systbls_64.S
923 --- linux-2.6.32/arch/sparc/kernel/systbls_64.S 2009-12-03 20:02:15.000000000 +0100
924 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/x86/ia32/ia32entry.S linux-2.6.32-vs2.3.0.36.26/arch/x86/ia32/ia32entry.S
944 --- linux-2.6.32/arch/x86/ia32/ia32entry.S      2009-12-03 20:02:15.000000000 +0100
945 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/x86/include/asm/unistd_64.h linux-2.6.32-vs2.3.0.36.26/arch/x86/include/asm/unistd_64.h
956 --- linux-2.6.32/arch/x86/include/asm/unistd_64.h       2009-12-03 20:02:16.000000000 +0100
957 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/x86/Kconfig linux-2.6.32-vs2.3.0.36.26/arch/x86/Kconfig
968 --- linux-2.6.32/arch/x86/Kconfig       2009-12-03 20:02:15.000000000 +0100
969 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/x86/kernel/syscall_table_32.S linux-2.6.32-vs2.3.0.36.26/arch/x86/kernel/syscall_table_32.S
980 --- linux-2.6.32/arch/x86/kernel/syscall_table_32.S     2009-12-03 20:02:16.000000000 +0100
981 +++ linux-2.6.32-vs2.3.0.36.26/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/arch/xtensa/mm/fault.c linux-2.6.32-vs2.3.0.36.26/arch/xtensa/mm/fault.c
992 --- linux-2.6.32/arch/xtensa/mm/fault.c 2009-09-10 15:25:48.000000000 +0200
993 +++ linux-2.6.32-vs2.3.0.36.26/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/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.32-vs2.3.0.36.26/Documentation/scheduler/sched-cfs-hard-limits.txt
1005 --- linux-2.6.32/Documentation/scheduler/sched-cfs-hard-limits.txt      1970-01-01 01:00:00.000000000 +0100
1006 +++ linux-2.6.32-vs2.3.0.36.26/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/Documentation/vserver/debug.txt linux-2.6.32-vs2.3.0.36.26/Documentation/vserver/debug.txt
1057 --- linux-2.6.32/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
1058 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/block/Kconfig linux-2.6.32-vs2.3.0.36.26/drivers/block/Kconfig
1215 --- linux-2.6.32/drivers/block/Kconfig  2009-09-10 15:25:49.000000000 +0200
1216 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/block/loop.c linux-2.6.32-vs2.3.0.36.26/drivers/block/loop.c
1232 --- linux-2.6.32/drivers/block/loop.c   2009-12-03 20:02:19.000000000 +0100
1233 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/block/Makefile linux-2.6.32-vs2.3.0.36.26/drivers/block/Makefile
1288 --- linux-2.6.32/drivers/block/Makefile 2009-09-10 15:25:49.000000000 +0200
1289 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/block/vroot.c linux-2.6.32-vs2.3.0.36.26/drivers/block/vroot.c
1299 --- linux-2.6.32/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
1300 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/char/sysrq.c linux-2.6.32-vs2.3.0.36.26/drivers/char/sysrq.c
1584 --- linux-2.6.32/drivers/char/sysrq.c   2009-12-03 20:02:20.000000000 +0100
1585 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/char/tty_io.c linux-2.6.32-vs2.3.0.36.26/drivers/char/tty_io.c
1638 --- linux-2.6.32/drivers/char/tty_io.c  2009-12-03 20:02:20.000000000 +0100
1639 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.32-vs2.3.0.36.26/drivers/infiniband/hw/ipath/ipath_user_pages.c
1667 --- linux-2.6.32/drivers/infiniband/hw/ipath/ipath_user_pages.c 2009-12-03 20:02:23.000000000 +0100
1668 +++ linux-2.6.32-vs2.3.0.36.26/drivers/infiniband/hw/ipath/ipath_user_pages.c   2009-12-03 20:04:56.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/drivers/md/dm.c linux-2.6.32-vs2.3.0.36.26/drivers/md/dm.c
1715 --- linux-2.6.32/drivers/md/dm.c        2009-12-03 20:02:25.000000000 +0100
1716 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/md/dm.h linux-2.6.32-vs2.3.0.36.26/drivers/md/dm.h
1791 --- linux-2.6.32/drivers/md/dm.h        2009-09-10 15:25:55.000000000 +0200
1792 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/md/dm-ioctl.c linux-2.6.32-vs2.3.0.36.26/drivers/md/dm-ioctl.c
1803 --- linux-2.6.32/drivers/md/dm-ioctl.c  2009-12-03 20:02:25.000000000 +0100
1804 +++ linux-2.6.32-vs2.3.0.36.26/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/drivers/net/tun.c linux-2.6.32-vs2.3.0.36.26/drivers/net/tun.c
1887 --- linux-2.6.32/drivers/net/tun.c      2009-12-03 20:02:32.000000000 +0100
1888 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/attr.c linux-2.6.32-vs2.3.0.36.26/fs/attr.c
1959 --- linux-2.6.32/fs/attr.c      2009-12-03 20:02:51.000000000 +0100
1960 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/binfmt_aout.c linux-2.6.32-vs2.3.0.36.26/fs/binfmt_aout.c
2002 --- linux-2.6.32/fs/binfmt_aout.c       2009-03-24 14:22:24.000000000 +0100
2003 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/binfmt_elf.c linux-2.6.32-vs2.3.0.36.26/fs/binfmt_elf.c
2013 --- linux-2.6.32/fs/binfmt_elf.c        2009-12-03 20:02:51.000000000 +0100
2014 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/binfmt_flat.c linux-2.6.32-vs2.3.0.36.26/fs/binfmt_flat.c
2024 --- linux-2.6.32/fs/binfmt_flat.c       2009-12-03 20:02:51.000000000 +0100
2025 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/binfmt_som.c linux-2.6.32-vs2.3.0.36.26/fs/binfmt_som.c
2035 --- linux-2.6.32/fs/binfmt_som.c        2009-06-11 17:13:02.000000000 +0200
2036 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/block_dev.c linux-2.6.32-vs2.3.0.36.26/fs/block_dev.c
2046 --- linux-2.6.32/fs/block_dev.c 2009-12-03 20:02:51.000000000 +0100
2047 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/btrfs/ctree.h linux-2.6.32-vs2.3.0.36.26/fs/btrfs/ctree.h
2086 --- linux-2.6.32/fs/btrfs/ctree.h       2009-12-03 20:02:51.000000000 +0100
2087 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/btrfs/disk-io.c linux-2.6.32-vs2.3.0.36.26/fs/btrfs/disk-io.c
2141 --- linux-2.6.32/fs/btrfs/disk-io.c     2009-12-03 20:02:51.000000000 +0100
2142 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/btrfs/inode.c linux-2.6.32-vs2.3.0.36.26/fs/btrfs/inode.c
2154 --- linux-2.6.32/fs/btrfs/inode.c       2009-12-03 20:02:51.000000000 +0100
2155 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/btrfs/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/btrfs/ioctl.c
2233 --- linux-2.6.32/fs/btrfs/ioctl.c       2009-12-03 20:02:51.000000000 +0100
2234 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/btrfs/super.c linux-2.6.32-vs2.3.0.36.26/fs/btrfs/super.c
2417 --- linux-2.6.32/fs/btrfs/super.c       2009-12-03 20:02:51.000000000 +0100
2418 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/char_dev.c linux-2.6.32-vs2.3.0.36.26/fs/char_dev.c
2475 --- linux-2.6.32/fs/char_dev.c  2009-12-03 20:02:51.000000000 +0100
2476 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/dcache.c linux-2.6.32-vs2.3.0.36.26/fs/dcache.c
2510 --- linux-2.6.32/fs/dcache.c    2009-12-03 20:02:51.000000000 +0100
2511 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/devpts/inode.c linux-2.6.32-vs2.3.0.36.26/fs/devpts/inode.c
2564 --- linux-2.6.32/fs/devpts/inode.c      2009-12-03 20:02:51.000000000 +0100
2565 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/exec.c linux-2.6.32-vs2.3.0.36.26/fs/exec.c
2649 --- linux-2.6.32/fs/exec.c      2009-12-03 20:02:51.000000000 +0100
2650 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/balloc.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/balloc.c
2672 --- linux-2.6.32/fs/ext2/balloc.c       2009-06-11 17:13:03.000000000 +0200
2673 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/ext2.h linux-2.6.32-vs2.3.0.36.26/fs/ext2/ext2.h
2683 --- linux-2.6.32/fs/ext2/ext2.h 2009-09-10 15:26:21.000000000 +0200
2684 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/file.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/file.c
2694 --- linux-2.6.32/fs/ext2/file.c 2009-12-03 20:02:51.000000000 +0100
2695 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/ialloc.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/ialloc.c
2703 --- linux-2.6.32/fs/ext2/ialloc.c       2009-06-11 17:13:03.000000000 +0200
2704 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/inode.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/inode.c
2722 --- linux-2.6.32/fs/ext2/inode.c        2009-12-03 20:02:51.000000000 +0100
2723 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/ioctl.c
2873 --- linux-2.6.32/fs/ext2/ioctl.c        2009-09-10 15:26:21.000000000 +0200
2874 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/namei.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/namei.c
2925 --- linux-2.6.32/fs/ext2/namei.c        2009-12-03 20:02:51.000000000 +0100
2926 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext2/super.c linux-2.6.32-vs2.3.0.36.26/fs/ext2/super.c
2952 --- linux-2.6.32/fs/ext2/super.c        2009-09-10 15:26:21.000000000 +0200
2953 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext3/file.c linux-2.6.32-vs2.3.0.36.26/fs/ext3/file.c
3020 --- linux-2.6.32/fs/ext3/file.c 2009-12-03 20:02:51.000000000 +0100
3021 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext3/ialloc.c linux-2.6.32-vs2.3.0.36.26/fs/ext3/ialloc.c
3030 --- linux-2.6.32/fs/ext3/ialloc.c       2009-09-10 15:26:21.000000000 +0200
3031 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext3/inode.c linux-2.6.32-vs2.3.0.36.26/fs/ext3/inode.c
3049 --- linux-2.6.32/fs/ext3/inode.c        2009-12-03 20:02:51.000000000 +0100
3050 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext3/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/ext3/ioctl.c
3235 --- linux-2.6.32/fs/ext3/ioctl.c        2009-06-11 17:13:03.000000000 +0200
3236 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext3/namei.c linux-2.6.32-vs2.3.0.36.26/fs/ext3/namei.c
3313 --- linux-2.6.32/fs/ext3/namei.c        2009-12-03 20:02:51.000000000 +0100
3314 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext3/super.c linux-2.6.32-vs2.3.0.36.26/fs/ext3/super.c
3340 --- linux-2.6.32/fs/ext3/super.c        2009-12-03 20:02:51.000000000 +0100
3341 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext4/ext4.h linux-2.6.32-vs2.3.0.36.26/fs/ext4/ext4.h
3408 --- linux-2.6.32/fs/ext4/ext4.h 2009-12-03 20:02:51.000000000 +0100
3409 +++ linux-2.6.32-vs2.3.0.36.26/fs/ext4/ext4.h   2009-12-03 20:04:56.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 @@ -744,6 +750,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 @@ -1734,6 +1741,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/fs/ext4/file.c linux-2.6.32-vs2.3.0.36.26/fs/ext4/file.c
3458 --- linux-2.6.32/fs/ext4/file.c 2009-12-03 20:02:51.000000000 +0100
3459 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext4/ialloc.c linux-2.6.32-vs2.3.0.36.26/fs/ext4/ialloc.c
3468 --- linux-2.6.32/fs/ext4/ialloc.c       2009-12-03 20:02:51.000000000 +0100
3469 +++ linux-2.6.32-vs2.3.0.36.26/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/fs/ext4/inode.c linux-2.6.32-vs2.3.0.36.26/fs/ext4/inode.c
3487 --- linux-2.6.32/fs/ext4/inode.c        2009-12-03 20:02:51.000000000 +0100
3488 +++ linux-2.6.32-vs2.3.0.36.26/fs/ext4/inode.c  2009-12-03 20:04:56.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 @@ -4370,7 +4371,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 @@ -4721,36 +4722,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 @@ -4785,6 +4810,8 @@ struct inode *ext4_iget(struct super_blo
3575         struct inode *inode;
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 @@ -4800,12 +4827,16 @@ struct inode *ext4_iget(struct super_blo
3584         bh = iloc.bh;
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 @@ -5006,6 +5037,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 @@ -5016,29 +5049,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 @@ -5222,7 +5258,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 @@ -5244,6 +5281,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/fs/ext4/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/ext4/ioctl.c
3672 --- linux-2.6.32/fs/ext4/ioctl.c        2009-12-03 20:02:51.000000000 +0100
3673 +++ linux-2.6.32-vs2.3.0.36.26/fs/ext4/ioctl.c  2009-12-03 20:04:56.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/fs/ext4/namei.c linux-2.6.32-vs2.3.0.36.26/fs/ext4/namei.c
3738 --- linux-2.6.32/fs/ext4/namei.c        2009-12-03 20:02:51.000000000 +0100
3739 +++ linux-2.6.32-vs2.3.0.36.26/fs/ext4/namei.c  2009-12-03 20:04:56.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 @@ -2539,6 +2541,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/fs/ext4/super.c linux-2.6.32-vs2.3.0.36.26/fs/ext4/super.c
3765 --- linux-2.6.32/fs/ext4/super.c        2009-12-03 20:02:51.000000000 +0100
3766 +++ linux-2.6.32-vs2.3.0.36.26/fs/ext4/super.c  2009-12-03 20:04:56.000000000 +0100
3767 @@ -1079,7 +1079,8 @@ enum {
3768         Opt_usrquota, Opt_grpquota, Opt_i_version,
3769         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3770         Opt_block_validity, Opt_noblock_validity,
3771 -       Opt_inode_readahead_blks, Opt_journal_ioprio
3772 +       Opt_inode_readahead_blks, Opt_journal_ioprio,
3773 +       Opt_tag, Opt_notag, Opt_tagid
3774  };
3775  
3776  static const match_table_t tokens = {
3777 @@ -1144,6 +1145,9 @@ static const match_table_t tokens = {
3778         {Opt_auto_da_alloc, "auto_da_alloc=%u"},
3779         {Opt_auto_da_alloc, "auto_da_alloc"},
3780         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3781 +       {Opt_tag, "tag"},
3782 +       {Opt_notag, "notag"},
3783 +       {Opt_tagid, "tagid=%u"},
3784         {Opt_err, NULL},
3785  };
3786  
3787 @@ -1241,6 +1245,20 @@ static int parse_options(char *options, 
3788                 case Opt_nouid32:
3789                         set_opt(sbi->s_mount_opt, NO_UID32);
3790                         break;
3791 +#ifndef CONFIG_TAGGING_NONE
3792 +               case Opt_tag:
3793 +                       set_opt (sbi->s_mount_opt, TAGGED);
3794 +                       break;
3795 +               case Opt_notag:
3796 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3797 +                       break;
3798 +#endif
3799 +#ifdef CONFIG_PROPAGATE
3800 +               case Opt_tagid:
3801 +                       /* use args[0] */
3802 +                       set_opt (sbi->s_mount_opt, TAGGED);
3803 +                       break;
3804 +#endif
3805                 case Opt_debug:
3806                         set_opt(sbi->s_mount_opt, DEBUG);
3807                         break;
3808 @@ -2435,6 +2453,9 @@ static int ext4_fill_super(struct super_
3809                            &journal_ioprio, NULL, 0))
3810                 goto failed_mount;
3811  
3812 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3813 +               sb->s_flags |= MS_TAGGED;
3814 +
3815         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3816                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3817  
3818 @@ -3492,6 +3513,14 @@ static int ext4_remount(struct super_blo
3819         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3820                 ext4_abort(sb, __func__, "Abort forced by user");
3821  
3822 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3823 +               !(sb->s_flags & MS_TAGGED)) {
3824 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3825 +                       sb->s_id);
3826 +               err = -EINVAL;
3827 +               goto restore_opts;
3828 +       }
3829 +
3830         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3831                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3832  
3833 diff -NurpP --minimal linux-2.6.32/fs/fcntl.c linux-2.6.32-vs2.3.0.36.26/fs/fcntl.c
3834 --- linux-2.6.32/fs/fcntl.c     2009-12-03 20:02:51.000000000 +0100
3835 +++ linux-2.6.32-vs2.3.0.36.26/fs/fcntl.c       2009-12-03 20:04:56.000000000 +0100
3836 @@ -19,6 +19,7 @@
3837  #include <linux/signal.h>
3838  #include <linux/rcupdate.h>
3839  #include <linux/pid_namespace.h>
3840 +#include <linux/vs_limit.h>
3841  
3842  #include <asm/poll.h>
3843  #include <asm/siginfo.h>
3844 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3845  
3846         if (tofree)
3847                 filp_close(tofree, files);
3848 +       else
3849 +               vx_openfd_inc(newfd);   /* fd was unused */
3850  
3851         return newfd;
3852  
3853 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3854         filp = fget(fd);
3855         if (!filp)
3856                 goto out;
3857 +       if (!vx_files_avail(1))
3858 +               goto out;
3859  
3860         err = security_file_fcntl(filp, cmd, arg);
3861         if (err) {
3862 diff -NurpP --minimal linux-2.6.32/fs/file.c linux-2.6.32-vs2.3.0.36.26/fs/file.c
3863 --- linux-2.6.32/fs/file.c      2009-12-03 20:02:51.000000000 +0100
3864 +++ linux-2.6.32-vs2.3.0.36.26/fs/file.c        2009-12-03 20:04:56.000000000 +0100
3865 @@ -20,6 +20,7 @@
3866  #include <linux/spinlock.h>
3867  #include <linux/rcupdate.h>
3868  #include <linux/workqueue.h>
3869 +#include <linux/vs_limit.h>
3870  
3871  struct fdtable_defer {
3872         spinlock_t lock;
3873 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3874                 struct file *f = *old_fds++;
3875                 if (f) {
3876                         get_file(f);
3877 +                       /* TODO: sum it first for check and performance */
3878 +                       vx_openfd_inc(open_files - i);
3879                 } else {
3880                         /*
3881                          * The fd may be claimed in the fd bitmap but not yet
3882 @@ -476,6 +479,7 @@ repeat:
3883         else
3884                 FD_CLR(fd, fdt->close_on_exec);
3885         error = fd;
3886 +       vx_openfd_inc(fd);
3887  #if 1
3888         /* Sanity check */
3889         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3890 diff -NurpP --minimal linux-2.6.32/fs/file_table.c linux-2.6.32-vs2.3.0.36.26/fs/file_table.c
3891 --- linux-2.6.32/fs/file_table.c        2009-12-03 20:02:51.000000000 +0100
3892 +++ linux-2.6.32-vs2.3.0.36.26/fs/file_table.c  2009-12-03 20:04:56.000000000 +0100
3893 @@ -22,6 +22,8 @@
3894  #include <linux/fsnotify.h>
3895  #include <linux/sysctl.h>
3896  #include <linux/percpu_counter.h>
3897 +#include <linux/vs_limit.h>
3898 +#include <linux/vs_context.h>
3899  
3900  #include <asm/atomic.h>
3901  
3902 @@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
3903         spin_lock_init(&f->f_lock);
3904         eventpoll_init_file(f);
3905         /* f->f_version: 0 */
3906 +       f->f_xid = vx_current_xid();
3907 +       vx_files_inc(f);
3908         return f;
3909  
3910  over:
3911 @@ -285,6 +289,8 @@ void __fput(struct file *file)
3912                 cdev_put(inode->i_cdev);
3913         fops_put(file->f_op);
3914         put_pid(file->f_owner.pid);
3915 +       vx_files_dec(file);
3916 +       file->f_xid = 0;
3917         file_kill(file);
3918         if (file->f_mode & FMODE_WRITE)
3919                 drop_file_write_access(file);
3920 @@ -352,6 +358,8 @@ void put_filp(struct file *file)
3921  {
3922         if (atomic_long_dec_and_test(&file->f_count)) {
3923                 security_file_free(file);
3924 +               vx_files_dec(file);
3925 +               file->f_xid = 0;
3926                 file_kill(file);
3927                 file_free(file);
3928         }
3929 diff -NurpP --minimal linux-2.6.32/fs/fs_struct.c linux-2.6.32-vs2.3.0.36.26/fs/fs_struct.c
3930 --- linux-2.6.32/fs/fs_struct.c 2009-06-11 17:13:04.000000000 +0200
3931 +++ linux-2.6.32-vs2.3.0.36.26/fs/fs_struct.c   2009-12-03 20:04:56.000000000 +0100
3932 @@ -4,6 +4,7 @@
3933  #include <linux/path.h>
3934  #include <linux/slab.h>
3935  #include <linux/fs_struct.h>
3936 +#include <linux/vserver/global.h>
3937  
3938  /*
3939   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
3940 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
3941  {
3942         path_put(&fs->root);
3943         path_put(&fs->pwd);
3944 +       atomic_dec(&vs_global_fs);
3945         kmem_cache_free(fs_cachep, fs);
3946  }
3947  
3948 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
3949                 fs->pwd = old->pwd;
3950                 path_get(&old->pwd);
3951                 read_unlock(&old->lock);
3952 +               atomic_inc(&vs_global_fs);
3953         }
3954         return fs;
3955  }
3956 diff -NurpP --minimal linux-2.6.32/fs/gfs2/file.c linux-2.6.32-vs2.3.0.36.26/fs/gfs2/file.c
3957 --- linux-2.6.32/fs/gfs2/file.c 2009-12-03 20:02:52.000000000 +0100
3958 +++ linux-2.6.32-vs2.3.0.36.26/fs/gfs2/file.c   2009-12-03 20:04:56.000000000 +0100
3959 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
3960         [7] = GFS2_DIF_NOATIME,
3961         [12] = GFS2_DIF_EXHASH,
3962         [14] = GFS2_DIF_INHERIT_JDATA,
3963 +       [27] = GFS2_DIF_IXUNLINK,
3964 +       [26] = GFS2_DIF_BARRIER,
3965 +       [29] = GFS2_DIF_COW,
3966  };
3967  
3968  static const u32 gfs2_to_fsflags[32] = {
3969 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
3970         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3971         [gfs2fl_ExHash] = FS_INDEX_FL,
3972         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3973 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3974 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3975 +       [gfs2fl_Cow] = FS_COW_FL,
3976  };
3977  
3978  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3979 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
3980  {
3981         struct gfs2_inode *ip = GFS2_I(inode);
3982         unsigned int flags = inode->i_flags;
3983 +       unsigned int vflags = inode->i_vflags;
3984 +
3985 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3986 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3987  
3988 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3989         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3990                 flags |= S_IMMUTABLE;
3991 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3992 +               flags |= S_IXUNLINK;
3993 +
3994         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3995                 flags |= S_APPEND;
3996         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3997 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
3998         if (ip->i_diskflags & GFS2_DIF_SYNC)
3999                 flags |= S_SYNC;
4000         inode->i_flags = flags;
4001 +
4002 +       vflags &= ~(V_BARRIER | V_COW);
4003 +
4004 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4005 +               vflags |= V_BARRIER;
4006 +       if (ip->i_diskflags & GFS2_DIF_COW)
4007 +               vflags |= V_COW;
4008 +       inode->i_vflags = vflags;
4009 +}
4010 +
4011 +void gfs2_get_inode_flags(struct inode *inode)
4012 +{
4013 +       struct gfs2_inode *ip = GFS2_I(inode);
4014 +       unsigned int flags = inode->i_flags;
4015 +       unsigned int vflags = inode->i_vflags;
4016 +
4017 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4018 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4019 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4020 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4021 +
4022 +       if (flags & S_IMMUTABLE)
4023 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4024 +       if (flags & S_IXUNLINK)
4025 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4026 +
4027 +       if (flags & S_APPEND)
4028 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4029 +       if (flags & S_NOATIME)
4030 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4031 +       if (flags & S_SYNC)
4032 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4033 +
4034 +       if (vflags & V_BARRIER)
4035 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4036 +       if (vflags & V_COW)
4037 +               ip->i_diskflags |= GFS2_DIF_COW;
4038  }
4039  
4040  /* Flags that can be set by user space */
4041 @@ -286,6 +335,37 @@ static int gfs2_set_flags(struct file *f
4042         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4043  }
4044  
4045 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4046 +{
4047 +       struct gfs2_inode *ip = GFS2_I(inode);
4048 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4049 +       struct buffer_head *bh;
4050 +       struct gfs2_holder gh;
4051 +       int error;
4052 +
4053 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4054 +       if (error)
4055 +               return error;
4056 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4057 +       if (error)
4058 +               goto out;
4059 +       error = gfs2_meta_inode_buffer(ip, &bh);
4060 +       if (error)
4061 +               goto out_trans_end;
4062 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4063 +       inode->i_flags = flags;
4064 +       inode->i_vflags = vflags;
4065 +       gfs2_get_inode_flags(inode);
4066 +       gfs2_dinode_out(ip, bh->b_data);
4067 +       brelse(bh);
4068 +       gfs2_set_aops(inode);
4069 +out_trans_end:
4070 +       gfs2_trans_end(sdp);
4071 +out:
4072 +       gfs2_glock_dq_uninit(&gh);
4073 +       return error;
4074 +}
4075 +
4076  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4077  {
4078         switch(cmd) {
4079 diff -NurpP --minimal linux-2.6.32/fs/gfs2/inode.h linux-2.6.32-vs2.3.0.36.26/fs/gfs2/inode.h
4080 --- linux-2.6.32/fs/gfs2/inode.h        2009-09-10 15:26:22.000000000 +0200
4081 +++ linux-2.6.32-vs2.3.0.36.26/fs/gfs2/inode.h  2009-12-03 20:04:56.000000000 +0100
4082 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4083  extern const struct file_operations gfs2_dir_fops_nolock;
4084  
4085  extern void gfs2_set_inode_flags(struct inode *inode);
4086 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4087   
4088  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4089  extern const struct file_operations gfs2_file_fops;
4090 diff -NurpP --minimal linux-2.6.32/fs/gfs2/ops_inode.c linux-2.6.32-vs2.3.0.36.26/fs/gfs2/ops_inode.c
4091 --- linux-2.6.32/fs/gfs2/ops_inode.c    2009-12-03 20:02:52.000000000 +0100
4092 +++ linux-2.6.32-vs2.3.0.36.26/fs/gfs2/ops_inode.c      2009-12-03 20:04:56.000000000 +0100
4093 @@ -1400,6 +1400,7 @@ const struct inode_operations gfs2_file_
4094         .listxattr = gfs2_listxattr,
4095         .removexattr = gfs2_removexattr,
4096         .fiemap = gfs2_fiemap,
4097 +       .sync_flags = gfs2_sync_flags,
4098  };
4099  
4100  const struct inode_operations gfs2_dir_iops = {
4101 @@ -1420,6 +1421,7 @@ const struct inode_operations gfs2_dir_i
4102         .listxattr = gfs2_listxattr,
4103         .removexattr = gfs2_removexattr,
4104         .fiemap = gfs2_fiemap,
4105 +       .sync_flags = gfs2_sync_flags,
4106  };
4107  
4108  const struct inode_operations gfs2_symlink_iops = {
4109 diff -NurpP --minimal linux-2.6.32/fs/hfsplus/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/hfsplus/ioctl.c
4110 --- linux-2.6.32/fs/hfsplus/ioctl.c     2008-12-25 00:26:37.000000000 +0100
4111 +++ linux-2.6.32-vs2.3.0.36.26/fs/hfsplus/ioctl.c       2009-12-03 20:04:56.000000000 +0100
4112 @@ -17,6 +17,7 @@
4113  #include <linux/mount.h>
4114  #include <linux/sched.h>
4115  #include <linux/xattr.h>
4116 +#include <linux/mount.h>
4117  #include <asm/uaccess.h>
4118  #include "hfsplus_fs.h"
4119  
4120 diff -NurpP --minimal linux-2.6.32/fs/inode.c linux-2.6.32-vs2.3.0.36.26/fs/inode.c
4121 --- linux-2.6.32/fs/inode.c     2009-12-03 20:02:52.000000000 +0100
4122 +++ linux-2.6.32-vs2.3.0.36.26/fs/inode.c       2009-12-03 20:04:56.000000000 +0100
4123 @@ -133,6 +133,9 @@ int inode_init_always(struct super_block
4124         struct address_space *const mapping = &inode->i_data;
4125  
4126         inode->i_sb = sb;
4127 +
4128 +       /* essential because of inode slab reuse */
4129 +       inode->i_tag = 0;
4130         inode->i_blkbits = sb->s_blocksize_bits;
4131         inode->i_flags = 0;
4132         atomic_set(&inode->i_count, 1);
4133 @@ -153,6 +156,7 @@ int inode_init_always(struct super_block
4134         inode->i_bdev = NULL;
4135         inode->i_cdev = NULL;
4136         inode->i_rdev = 0;
4137 +       inode->i_mdev = 0;
4138         inode->dirtied_when = 0;
4139  
4140         if (security_inode_alloc(inode))
4141 @@ -307,6 +311,8 @@ void __iget(struct inode *inode)
4142         inodes_stat.nr_unused--;
4143  }
4144  
4145 +EXPORT_SYMBOL_GPL(__iget);
4146 +
4147  /**
4148   * clear_inode - clear an inode
4149   * @inode: inode to clear
4150 @@ -1611,9 +1617,11 @@ void init_special_inode(struct inode *in
4151         if (S_ISCHR(mode)) {
4152                 inode->i_fop = &def_chr_fops;
4153                 inode->i_rdev = rdev;
4154 +               inode->i_mdev = rdev;
4155         } else if (S_ISBLK(mode)) {
4156                 inode->i_fop = &def_blk_fops;
4157                 inode->i_rdev = rdev;
4158 +               inode->i_mdev = rdev;
4159         } else if (S_ISFIFO(mode))
4160                 inode->i_fop = &def_fifo_fops;
4161         else if (S_ISSOCK(mode))
4162 diff -NurpP --minimal linux-2.6.32/fs/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/ioctl.c
4163 --- linux-2.6.32/fs/ioctl.c     2009-12-03 20:02:52.000000000 +0100
4164 +++ linux-2.6.32-vs2.3.0.36.26/fs/ioctl.c       2009-12-03 20:04:56.000000000 +0100
4165 @@ -16,6 +16,9 @@
4166  #include <linux/writeback.h>
4167  #include <linux/buffer_head.h>
4168  #include <linux/falloc.h>
4169 +#include <linux/proc_fs.h>
4170 +#include <linux/vserver/inode.h>
4171 +#include <linux/vs_tag.h>
4172  
4173  #include <asm/ioctls.h>
4174  
4175 diff -NurpP --minimal linux-2.6.32/fs/ioprio.c linux-2.6.32-vs2.3.0.36.26/fs/ioprio.c
4176 --- linux-2.6.32/fs/ioprio.c    2009-03-24 14:22:26.000000000 +0100
4177 +++ linux-2.6.32-vs2.3.0.36.26/fs/ioprio.c      2009-12-03 20:04:56.000000000 +0100
4178 @@ -26,6 +26,7 @@
4179  #include <linux/syscalls.h>
4180  #include <linux/security.h>
4181  #include <linux/pid_namespace.h>
4182 +#include <linux/vs_base.h>
4183  
4184  int set_task_ioprio(struct task_struct *task, int ioprio)
4185  {
4186 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4187                         else
4188                                 pgrp = find_vpid(who);
4189                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4190 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4191 +                                       continue;
4192                                 ret = set_task_ioprio(p, ioprio);
4193                                 if (ret)
4194                                         break;
4195 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4196                         else
4197                                 pgrp = find_vpid(who);
4198                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4199 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4200 +                                       continue;
4201                                 tmpio = get_task_ioprio(p);
4202                                 if (tmpio < 0)
4203                                         continue;
4204 diff -NurpP --minimal linux-2.6.32/fs/jfs/acl.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/acl.c
4205 --- linux-2.6.32/fs/jfs/acl.c   2009-12-03 20:02:52.000000000 +0100
4206 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/acl.c     2009-12-03 20:04:56.000000000 +0100
4207 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4208                 return rc;
4209  
4210         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4211 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4212 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4213 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4214                 if (vfs_dq_transfer(inode, iattr))
4215                         return -EDQUOT;
4216         }
4217 diff -NurpP --minimal linux-2.6.32/fs/jfs/file.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/file.c
4218 --- linux-2.6.32/fs/jfs/file.c  2009-12-03 20:02:52.000000000 +0100
4219 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/file.c    2009-12-03 20:04:56.000000000 +0100
4220 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4221         .setattr        = jfs_setattr,
4222         .check_acl      = jfs_check_acl,
4223  #endif
4224 +       .sync_flags     = jfs_sync_flags,
4225  };
4226  
4227  const struct file_operations jfs_file_operations = {
4228 diff -NurpP --minimal linux-2.6.32/fs/jfs/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/ioctl.c
4229 --- linux-2.6.32/fs/jfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
4230 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/ioctl.c   2009-12-03 20:04:56.000000000 +0100
4231 @@ -11,6 +11,7 @@
4232  #include <linux/mount.h>
4233  #include <linux/time.h>
4234  #include <linux/sched.h>
4235 +#include <linux/mount.h>
4236  #include <asm/current.h>
4237  #include <asm/uaccess.h>
4238  
4239 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4240  }
4241  
4242  
4243 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4244 +{
4245 +       inode->i_flags = flags;
4246 +       inode->i_vflags = vflags;
4247 +       jfs_get_inode_flags(JFS_IP(inode));
4248 +       inode->i_ctime = CURRENT_TIME_SEC;
4249 +       mark_inode_dirty(inode);
4250 +       return 0;
4251 +}
4252 +
4253  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4254  {
4255         struct inode *inode = filp->f_dentry->d_inode;
4256 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4257                 if (!S_ISDIR(inode->i_mode))
4258                         flags &= ~JFS_DIRSYNC_FL;
4259  
4260 +               if (IS_BARRIER(inode)) {
4261 +                       vxwprintk_task(1, "messing with the barrier.");
4262 +                       return -EACCES;
4263 +               }
4264 +
4265                 /* Is it quota file? Do not allow user to mess with it */
4266                 if (IS_NOQUOTA(inode)) {
4267                         err = -EPERM;
4268 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4269                  * the relevant capability.
4270                  */
4271                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4272 -                       ((flags ^ oldflags) &
4273 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4274 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4275 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4276                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4277                                 mutex_unlock(&inode->i_mutex);
4278                                 err = -EPERM;
4279 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4280                         }
4281                 }
4282  
4283 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4284 +               flags &= JFS_FL_USER_MODIFIABLE;
4285                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4286                 jfs_inode->mode2 = flags;
4287  
4288 diff -NurpP --minimal linux-2.6.32/fs/jfs/jfs_dinode.h linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_dinode.h
4289 --- linux-2.6.32/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
4290 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_dinode.h      2009-12-03 20:04:56.000000000 +0100
4291 @@ -161,9 +161,13 @@ struct dinode {
4292  
4293  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4294  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4295 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4296  
4297 -#define JFS_FL_USER_VISIBLE    0x03F80000
4298 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4299 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4300 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4301 +
4302 +#define JFS_FL_USER_VISIBLE    0x07F80000
4303 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4304  #define JFS_FL_INHERIT         0x03C80000
4305  
4306  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4307 diff -NurpP --minimal linux-2.6.32/fs/jfs/jfs_filsys.h linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_filsys.h
4308 --- linux-2.6.32/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
4309 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_filsys.h      2009-12-03 20:04:56.000000000 +0100
4310 @@ -263,6 +263,7 @@
4311  #define JFS_NAME_MAX   255
4312  #define JFS_PATH_MAX   BPSIZE
4313  
4314 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4315  
4316  /*
4317   *     file system state (superblock state)
4318 diff -NurpP --minimal linux-2.6.32/fs/jfs/jfs_imap.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_imap.c
4319 --- linux-2.6.32/fs/jfs/jfs_imap.c      2009-09-10 15:26:22.000000000 +0200
4320 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_imap.c        2009-12-03 20:04:56.000000000 +0100
4321 @@ -45,6 +45,7 @@
4322  #include <linux/buffer_head.h>
4323  #include <linux/pagemap.h>
4324  #include <linux/quotaops.h>
4325 +#include <linux/vs_tag.h>
4326  
4327  #include "jfs_incore.h"
4328  #include "jfs_inode.h"
4329 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4330  {
4331         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4332         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4333 +       uid_t uid;
4334 +       gid_t gid;
4335  
4336         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4337         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4338 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4339         }
4340         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4341  
4342 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4343 +       uid = le32_to_cpu(dip->di_uid);
4344 +       gid = le32_to_cpu(dip->di_gid);
4345 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4346 +
4347 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4348         if (sbi->uid == -1)
4349                 ip->i_uid = jfs_ip->saved_uid;
4350         else {
4351                 ip->i_uid = sbi->uid;
4352         }
4353  
4354 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4355 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4356         if (sbi->gid == -1)
4357                 ip->i_gid = jfs_ip->saved_gid;
4358         else {
4359 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4360         dip->di_size = cpu_to_le64(ip->i_size);
4361         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4362         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4363 -       if (sbi->uid == -1)
4364 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4365 -       else
4366 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4367 -       if (sbi->gid == -1)
4368 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4369 -       else
4370 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4371 +
4372 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4373 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4374 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4375 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4376 +
4377         jfs_get_inode_flags(jfs_ip);
4378         /*
4379          * mode2 is only needed for storing the higher order bits.
4380 diff -NurpP --minimal linux-2.6.32/fs/jfs/jfs_inode.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_inode.c
4381 --- linux-2.6.32/fs/jfs/jfs_inode.c     2009-06-11 17:13:05.000000000 +0200
4382 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_inode.c       2009-12-03 20:04:56.000000000 +0100
4383 @@ -18,6 +18,7 @@
4384  
4385  #include <linux/fs.h>
4386  #include <linux/quotaops.h>
4387 +#include <linux/vs_tag.h>
4388  #include "jfs_incore.h"
4389  #include "jfs_inode.h"
4390  #include "jfs_filsys.h"
4391 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4392  {
4393         unsigned int flags = JFS_IP(inode)->mode2;
4394  
4395 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4396 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4397 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4398 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4399  
4400         if (flags & JFS_IMMUTABLE_FL)
4401                 inode->i_flags |= S_IMMUTABLE;
4402 +       if (flags & JFS_IXUNLINK_FL)
4403 +               inode->i_flags |= S_IXUNLINK;
4404 +
4405 +       if (flags & JFS_SYNC_FL)
4406 +               inode->i_flags |= S_SYNC;
4407         if (flags & JFS_APPEND_FL)
4408                 inode->i_flags |= S_APPEND;
4409         if (flags & JFS_NOATIME_FL)
4410                 inode->i_flags |= S_NOATIME;
4411         if (flags & JFS_DIRSYNC_FL)
4412                 inode->i_flags |= S_DIRSYNC;
4413 -       if (flags & JFS_SYNC_FL)
4414 -               inode->i_flags |= S_SYNC;
4415 +
4416 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4417 +
4418 +       if (flags & JFS_BARRIER_FL)
4419 +               inode->i_vflags |= V_BARRIER;
4420 +       if (flags & JFS_COW_FL)
4421 +               inode->i_vflags |= V_COW;
4422  }
4423  
4424  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4425  {
4426         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4427 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4428 +
4429 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4430 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4431 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4432 +                          JFS_BARRIER_FL | JFS_COW_FL);
4433  
4434 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4435 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4436         if (flags & S_IMMUTABLE)
4437                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4438 +       if (flags & S_IXUNLINK)
4439 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4440 +
4441         if (flags & S_APPEND)
4442                 jfs_ip->mode2 |= JFS_APPEND_FL;
4443         if (flags & S_NOATIME)
4444 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4445                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4446         if (flags & S_SYNC)
4447                 jfs_ip->mode2 |= JFS_SYNC_FL;
4448 +
4449 +       if (vflags & V_BARRIER)
4450 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4451 +       if (vflags & V_COW)
4452 +               jfs_ip->mode2 |= JFS_COW_FL;
4453  }
4454  
4455  /*
4456 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4457                         mode |= S_ISGID;
4458         } else
4459                 inode->i_gid = current_fsgid();
4460 +       inode->i_tag = dx_current_fstag(sb);
4461  
4462         /*
4463          * New inodes need to save sane values on disk when
4464 diff -NurpP --minimal linux-2.6.32/fs/jfs/jfs_inode.h linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_inode.h
4465 --- linux-2.6.32/fs/jfs/jfs_inode.h     2009-06-11 17:13:05.000000000 +0200
4466 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/jfs_inode.h       2009-12-03 20:04:56.000000000 +0100
4467 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4468  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4469         int fh_len, int fh_type);
4470  extern void jfs_set_inode_flags(struct inode *);
4471 +extern int jfs_sync_flags(struct inode *, int, int);
4472  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4473  
4474  extern const struct address_space_operations jfs_aops;
4475 diff -NurpP --minimal linux-2.6.32/fs/jfs/namei.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/namei.c
4476 --- linux-2.6.32/fs/jfs/namei.c 2009-12-03 20:02:52.000000000 +0100
4477 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/namei.c   2009-12-03 20:04:56.000000000 +0100
4478 @@ -21,6 +21,7 @@
4479  #include <linux/ctype.h>
4480  #include <linux/quotaops.h>
4481  #include <linux/exportfs.h>
4482 +#include <linux/vs_tag.h>
4483  #include "jfs_incore.h"
4484  #include "jfs_superblock.h"
4485  #include "jfs_inode.h"
4486 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4487                 return ERR_CAST(ip);
4488         }
4489  
4490 +       dx_propagate_tag(nd, ip);
4491         dentry = d_splice_alias(ip, dentry);
4492  
4493         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4494 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4495         .setattr        = jfs_setattr,
4496         .check_acl      = jfs_check_acl,
4497  #endif
4498 +       .sync_flags     = jfs_sync_flags,
4499  };
4500  
4501  const struct file_operations jfs_dir_operations = {
4502 diff -NurpP --minimal linux-2.6.32/fs/jfs/super.c linux-2.6.32-vs2.3.0.36.26/fs/jfs/super.c
4503 --- linux-2.6.32/fs/jfs/super.c 2009-12-03 20:02:52.000000000 +0100
4504 +++ linux-2.6.32-vs2.3.0.36.26/fs/jfs/super.c   2009-12-03 20:04:56.000000000 +0100
4505 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4506  enum {
4507         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4508         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4509 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4510 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4511 +       Opt_tag, Opt_notag, Opt_tagid
4512  };
4513  
4514  static const match_table_t tokens = {
4515 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4516         {Opt_resize, "resize=%u"},
4517         {Opt_resize_nosize, "resize"},
4518         {Opt_errors, "errors=%s"},
4519 +       {Opt_tag, "tag"},
4520 +       {Opt_notag, "notag"},
4521 +       {Opt_tagid, "tagid=%u"},
4522 +       {Opt_tag, "tagxid"},
4523         {Opt_ignore, "noquota"},
4524         {Opt_ignore, "quota"},
4525         {Opt_usrquota, "usrquota"},
4526 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4527                         }
4528                         break;
4529                 }
4530 +#ifndef CONFIG_TAGGING_NONE
4531 +               case Opt_tag:
4532 +                       *flag |= JFS_TAGGED;
4533 +                       break;
4534 +               case Opt_notag:
4535 +                       *flag &= JFS_TAGGED;
4536 +                       break;
4537 +#endif
4538 +#ifdef CONFIG_PROPAGATE
4539 +               case Opt_tagid:
4540 +                       /* use args[0] */
4541 +                       *flag |= JFS_TAGGED;
4542 +                       break;
4543 +#endif
4544                 default:
4545                         printk("jfs: Unrecognized mount option \"%s\" "
4546                                         " or missing value\n", p);
4547 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4548         if (!parse_options(data, sb, &newLVSize, &flag)) {
4549                 return -EINVAL;
4550         }
4551 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4552 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4553 +                       sb->s_id);
4554 +               return -EINVAL;
4555 +       }
4556 +
4557         lock_kernel();
4558         if (newLVSize) {
4559                 if (sb->s_flags & MS_RDONLY) {
4560 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4561  #ifdef CONFIG_JFS_POSIX_ACL
4562         sb->s_flags |= MS_POSIXACL;
4563  #endif
4564 +       /* map mount option tagxid */
4565 +       if (sbi->flag & JFS_TAGGED)
4566 +               sb->s_flags |= MS_TAGGED;
4567  
4568         if (newLVSize) {
4569                 printk(KERN_ERR "resize option for remount only\n");
4570 diff -NurpP --minimal linux-2.6.32/fs/libfs.c linux-2.6.32-vs2.3.0.36.26/fs/libfs.c
4571 --- linux-2.6.32/fs/libfs.c     2009-12-03 20:02:52.000000000 +0100
4572 +++ linux-2.6.32-vs2.3.0.36.26/fs/libfs.c       2009-12-03 20:04:56.000000000 +0100
4573 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4574   * both impossible due to the lock on directory.
4575   */
4576  
4577 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4578 +static inline int do_dcache_readdir_filter(struct file *filp,
4579 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4580  {
4581         struct dentry *dentry = filp->f_path.dentry;
4582         struct dentry *cursor = filp->private_data;
4583 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4584                                 next = list_entry(p, struct dentry, d_u.d_child);
4585                                 if (d_unhashed(next) || !next->d_inode)
4586                                         continue;
4587 +                               if (filter && !filter(next))
4588 +                                       continue;
4589  
4590                                 spin_unlock(&dcache_lock);
4591                                 if (filldir(dirent, next->d_name.name, 
4592 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4593         return 0;
4594  }
4595  
4596 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4597 +{
4598 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4599 +}
4600 +
4601 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4602 +       int (*filter)(struct dentry *))
4603 +{
4604 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4605 +}
4606 +
4607 +
4608  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4609  {
4610         return -EISDIR;
4611 @@ -841,6 +856,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4612  EXPORT_SYMBOL(dcache_dir_lseek);
4613  EXPORT_SYMBOL(dcache_dir_open);
4614  EXPORT_SYMBOL(dcache_readdir);
4615 +EXPORT_SYMBOL(dcache_readdir_filter);
4616  EXPORT_SYMBOL(generic_read_dir);
4617  EXPORT_SYMBOL(get_sb_pseudo);
4618  EXPORT_SYMBOL(simple_write_begin);
4619 diff -NurpP --minimal linux-2.6.32/fs/locks.c linux-2.6.32-vs2.3.0.36.26/fs/locks.c
4620 --- linux-2.6.32/fs/locks.c     2009-12-03 20:02:52.000000000 +0100
4621 +++ linux-2.6.32-vs2.3.0.36.26/fs/locks.c       2009-12-03 20:04:56.000000000 +0100
4622 @@ -127,6 +127,8 @@
4623  #include <linux/time.h>
4624  #include <linux/rcupdate.h>
4625  #include <linux/pid_namespace.h>
4626 +#include <linux/vs_base.h>
4627 +#include <linux/vs_limit.h>
4628  
4629  #include <asm/uaccess.h>
4630  
4631 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4632  /* Allocate an empty lock structure. */
4633  static struct file_lock *locks_alloc_lock(void)
4634  {
4635 +       if (!vx_locks_avail(1))
4636 +               return NULL;
4637         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4638  }
4639  
4640 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4641         BUG_ON(!list_empty(&fl->fl_block));
4642         BUG_ON(!list_empty(&fl->fl_link));
4643  
4644 +       vx_locks_dec(fl);
4645         locks_release_private(fl);
4646         kmem_cache_free(filelock_cache, fl);
4647  }
4648 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4649         fl->fl_start = fl->fl_end = 0;
4650         fl->fl_ops = NULL;
4651         fl->fl_lmops = NULL;
4652 +       fl->fl_xid = -1;
4653  }
4654  
4655  EXPORT_SYMBOL(locks_init_lock);
4656 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4657         new->fl_file = fl->fl_file;
4658         new->fl_ops = fl->fl_ops;
4659         new->fl_lmops = fl->fl_lmops;
4660 +       new->fl_xid = fl->fl_xid;
4661  
4662         locks_copy_private(new, fl);
4663  }
4664 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4665         fl->fl_flags = FL_FLOCK;
4666         fl->fl_type = type;
4667         fl->fl_end = OFFSET_MAX;
4668 +
4669 +       vxd_assert(filp->f_xid == vx_current_xid(),
4670 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4671 +       fl->fl_xid = filp->f_xid;
4672 +       vx_locks_inc(fl);
4673         
4674         *lock = fl;
4675         return 0;
4676 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4677  
4678         fl->fl_owner = current->files;
4679         fl->fl_pid = current->tgid;
4680 +       fl->fl_xid = vx_current_xid();
4681  
4682         fl->fl_file = filp;
4683         fl->fl_flags = FL_LEASE;
4684 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4685         if (fl == NULL)
4686                 return ERR_PTR(error);
4687  
4688 +       fl->fl_xid = vx_current_xid();
4689 +       if (filp)
4690 +               vxd_assert(filp->f_xid == fl->fl_xid,
4691 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4692 +       vx_locks_inc(fl);
4693         error = lease_init(filp, type, fl);
4694         if (error) {
4695                 locks_free_lock(fl);
4696 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4697         if (found)
4698                 cond_resched();
4699  
4700 +       new_fl->fl_xid = -1;
4701  find_conflict:
4702         for_each_lock(inode, before) {
4703                 struct file_lock *fl = *before;
4704 @@ -790,6 +809,7 @@ find_conflict:
4705                 goto out;
4706         locks_copy_lock(new_fl, request);
4707         locks_insert_lock(before, new_fl);
4708 +       vx_locks_inc(new_fl);
4709         new_fl = NULL;
4710         error = 0;
4711  
4712 @@ -800,7 +820,8 @@ out:
4713         return error;
4714  }
4715  
4716 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4717 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4718 +       struct file_lock *conflock, xid_t xid)
4719  {
4720         struct file_lock *fl;
4721         struct file_lock *new_fl = NULL;
4722 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4723         struct file_lock **before;
4724         int error, added = 0;
4725  
4726 +       vxd_assert(xid == vx_current_xid(),
4727 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4728         /*
4729          * We may need two file_lock structures for this operation,
4730          * so we get them in advance to avoid races.
4731 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4732             (request->fl_type != F_UNLCK ||
4733              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4734                 new_fl = locks_alloc_lock();
4735 +               new_fl->fl_xid = xid;
4736 +               vx_locks_inc(new_fl);
4737                 new_fl2 = locks_alloc_lock();
4738 +               new_fl2->fl_xid = xid;
4739 +               vx_locks_inc(new_fl2);
4740         }
4741  
4742         lock_kernel();
4743 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4744  int posix_lock_file(struct file *filp, struct file_lock *fl,
4745                         struct file_lock *conflock)
4746  {
4747 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4748 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4749 +               fl, conflock, filp->f_xid);
4750  }
4751  EXPORT_SYMBOL(posix_lock_file);
4752  
4753 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4754         fl.fl_end = offset + count - 1;
4755  
4756         for (;;) {
4757 -               error = __posix_lock_file(inode, &fl, NULL);
4758 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4759                 if (error != FILE_LOCK_DEFERRED)
4760                         break;
4761                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4762 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4763  
4764         locks_copy_lock(new_fl, lease);
4765         locks_insert_lock(before, new_fl);
4766 +       vx_locks_inc(new_fl);
4767  
4768         *flp = new_fl;
4769         return 0;
4770 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4771         if (file_lock == NULL)
4772                 return -ENOLCK;
4773  
4774 +       vxd_assert(filp->f_xid == vx_current_xid(),
4775 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4776 +       file_lock->fl_xid = filp->f_xid;
4777 +       vx_locks_inc(file_lock);
4778 +
4779         /*
4780          * This might block, so we do it before checking the inode.
4781          */
4782 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4783         if (file_lock == NULL)
4784                 return -ENOLCK;
4785  
4786 +       vxd_assert(filp->f_xid == vx_current_xid(),
4787 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4788 +       file_lock->fl_xid = filp->f_xid;
4789 +       vx_locks_inc(file_lock);
4790 +
4791         /*
4792          * This might block, so we do it before checking the inode.
4793          */
4794 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4795  
4796         lock_get_status(f, fl, (long)f->private, "");
4797  
4798 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4799 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4800 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4801 +                       continue;
4802                 lock_get_status(f, bfl, (long)f->private, " ->");
4803 +       }
4804  
4805         f->private++;
4806         return 0;
4807 diff -NurpP --minimal linux-2.6.32/fs/namei.c linux-2.6.32-vs2.3.0.36.26/fs/namei.c
4808 --- linux-2.6.32/fs/namei.c     2009-12-03 20:02:52.000000000 +0100
4809 +++ linux-2.6.32-vs2.3.0.36.26/fs/namei.c       2009-12-03 20:04:56.000000000 +0100
4810 @@ -33,6 +33,14 @@
4811  #include <linux/fcntl.h>
4812  #include <linux/device_cgroup.h>
4813  #include <linux/fs_struct.h>
4814 +#include <linux/proc_fs.h>
4815 +#include <linux/vserver/inode.h>
4816 +#include <linux/vs_base.h>
4817 +#include <linux/vs_tag.h>
4818 +#include <linux/vs_cowbl.h>
4819 +#include <linux/vs_device.h>
4820 +#include <linux/vs_context.h>
4821 +#include <linux/pid_namespace.h>
4822  #include <asm/uaccess.h>
4823  
4824  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4825 @@ -169,6 +177,77 @@ void putname(const char *name)
4826  EXPORT_SYMBOL(putname);
4827  #endif
4828  
4829 +static inline int dx_barrier(const struct inode *inode)
4830 +{
4831 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4832 +               vxwprintk_task(1, "did hit the barrier.");
4833 +               return 1;
4834 +       }
4835 +       return 0;
4836 +}
4837 +
4838 +static int __dx_permission(const struct inode *inode, int mask)
4839 +{
4840 +       if (dx_barrier(inode))
4841 +               return -EACCES;
4842 +
4843 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4844 +               /* devpts is xid tagged */
4845 +               if (S_ISDIR(inode->i_mode) ||
4846 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4847 +                       return 0;
4848 +       }
4849 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4850 +               struct proc_dir_entry *de = PDE(inode);
4851 +
4852 +               if (de && !vx_hide_check(0, de->vx_flags))
4853 +                       goto out;
4854 +
4855 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4856 +                       struct pid *pid;
4857 +                       struct task_struct *tsk;
4858 +
4859 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4860 +                           vx_flags(VXF_STATE_SETUP, 0))
4861 +                               return 0;
4862 +
4863 +                       pid = PROC_I(inode)->pid;
4864 +                       if (!pid)
4865 +                               goto out;
4866 +
4867 +                       tsk = pid_task(pid, PIDTYPE_PID);
4868 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4869 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4870 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4871 +                               return 0;
4872 +               }
4873 +               else {
4874 +                       /* FIXME: Should we block some entries here? */
4875 +                       return 0;
4876 +               }
4877 +       }
4878 +       else {
4879 +               if (dx_notagcheck(inode->i_sb) ||
4880 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4881 +                            DX_IDENT))
4882 +                       return 0;
4883 +       }
4884 +
4885 +out:
4886 +       return -EACCES;
4887 +}
4888 +
4889 +int dx_permission(const struct inode *inode, int mask)
4890 +{
4891 +       int ret = __dx_permission(inode, mask);
4892 +       if (unlikely(ret)) {
4893 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4894 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4895 +                       inode->i_ino);
4896 +       }
4897 +       return ret;
4898 +}
4899 +
4900  /*
4901   * This does basic POSIX ACL permission checking
4902   */
4903 @@ -268,10 +347,14 @@ int inode_permission(struct inode *inode
4904                 /*
4905                  * Nobody gets write access to an immutable file.
4906                  */
4907 -               if (IS_IMMUTABLE(inode))
4908 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4909                         return -EACCES;
4910         }
4911  
4912 +       retval = dx_permission(inode, mask);
4913 +       if (retval)
4914 +               return retval;
4915 +
4916         if (inode->i_op->permission)
4917                 retval = inode->i_op->permission(inode, mask);
4918         else
4919 @@ -447,6 +530,9 @@ static int exec_permission_lite(struct i
4920  {
4921         int ret;
4922  
4923 +       if (dx_barrier(inode))
4924 +               return -EACCES;
4925 +
4926         if (inode->i_op->permission) {
4927                 ret = inode->i_op->permission(inode, MAY_EXEC);
4928                 if (!ret)
4929 @@ -762,7 +848,8 @@ static __always_inline void follow_dotdo
4930  
4931                 if (nd->path.dentry == nd->root.dentry &&
4932                     nd->path.mnt == nd->root.mnt) {
4933 -                       break;
4934 +                       /* for sane '/' avoid follow_mount() */
4935 +                       return;
4936                 }
4937                 spin_lock(&dcache_lock);
4938                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4939 @@ -798,16 +885,30 @@ static int do_lookup(struct nameidata *n
4940  {
4941         struct vfsmount *mnt = nd->path.mnt;
4942         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
4943 +       struct inode *inode;
4944  
4945         if (!dentry)
4946                 goto need_lookup;
4947         if (dentry->d_op && dentry->d_op->d_revalidate)
4948                 goto need_revalidate;
4949 +       inode = dentry->d_inode;
4950 +       if (!inode)
4951 +               goto done;
4952 +
4953 +       if (__dx_permission(inode, MAY_ACCESS))
4954 +               goto hidden;
4955 +
4956  done:
4957         path->mnt = mnt;
4958         path->dentry = dentry;
4959         __follow_mount(path);
4960         return 0;
4961 +hidden:
4962 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
4963 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
4964 +               vxd_path(&nd->path), name->len, name->name);
4965 +       dput(dentry);
4966 +       return -ENOENT;
4967  
4968  need_lookup:
4969         dentry = real_lookup(nd->path.dentry, name, nd);
4970 @@ -1389,7 +1490,7 @@ static int may_delete(struct inode *dir,
4971         if (IS_APPEND(dir))
4972                 return -EPERM;
4973         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4974 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4975 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4976                 return -EPERM;
4977         if (isdir) {
4978                 if (!S_ISDIR(victim->d_inode->i_mode))
4979 @@ -1529,6 +1630,14 @@ int may_open(struct path *path, int acc_
4980                 break;
4981         }
4982  
4983 +#ifdef CONFIG_VSERVER_COWBL
4984 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
4985 +               if (IS_COW_LINK(inode))
4986 +                       return -EMLINK;
4987 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4988 +               mark_inode_dirty(inode);
4989 +       }
4990 +#endif
4991         error = inode_permission(inode, acc_mode);
4992         if (error)
4993                 return error;
4994 @@ -1677,7 +1786,11 @@ struct file *do_filp_open(int dfd, const
4995         int count = 0;
4996         int will_write;
4997         int flag = open_to_namei_flags(open_flag);
4998 -
4999 +#ifdef CONFIG_VSERVER_COWBL
5000 +       int rflag = flag;
5001 +       int rmode = mode;
5002 +restart:
5003 +#endif
5004         if (!acc_mode)
5005                 acc_mode = MAY_OPEN | ACC_MODE(flag);
5006  
5007 @@ -1825,6 +1938,25 @@ ok:
5008                         goto exit;
5009         }
5010         error = may_open(&nd.path, acc_mode, flag);
5011 +#ifdef CONFIG_VSERVER_COWBL
5012 +       if (error == -EMLINK) {
5013 +               struct dentry *dentry;
5014 +               dentry = cow_break_link(pathname);
5015 +               if (IS_ERR(dentry)) {
5016 +                       error = PTR_ERR(dentry);
5017 +                       goto exit_cow;
5018 +               }
5019 +               dput(dentry);
5020 +               if (will_write)
5021 +                       mnt_drop_write(nd.path.mnt);
5022 +               release_open_intent(&nd);
5023 +               path_put(&nd.path);
5024 +               flag = rflag;
5025 +               mode = rmode;
5026 +               goto restart;
5027 +       }
5028 +exit_cow:
5029 +#endif
5030         if (error) {
5031                 if (will_write)
5032                         mnt_drop_write(nd.path.mnt);
5033 @@ -1987,9 +2119,17 @@ int vfs_mknod(struct inode *dir, struct 
5034         if (error)
5035                 return error;
5036  
5037 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5038 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5039 +               goto okay;
5040 +
5041 +       if (!capable(CAP_MKNOD))
5042                 return -EPERM;
5043  
5044 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5045 +               return -EPERM;
5046 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5047 +               return -EPERM;
5048 +okay:
5049         if (!dir->i_op->mknod)
5050                 return -EPERM;
5051  
5052 @@ -2456,7 +2596,7 @@ int vfs_link(struct dentry *old_dentry, 
5053         /*
5054          * A link to an append-only or immutable file cannot be created.
5055          */
5056 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5057 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5058                 return -EPERM;
5059         if (!dir->i_op->link)
5060                 return -EPERM;
5061 @@ -2829,6 +2969,219 @@ int vfs_follow_link(struct nameidata *nd
5062         return __vfs_follow_link(nd, link);
5063  }
5064  
5065 +
5066 +#ifdef CONFIG_VSERVER_COWBL
5067 +
5068 +#include <linux/file.h>
5069 +
5070 +static inline
5071 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5072 +{
5073 +       loff_t ppos = 0;
5074 +
5075 +       return do_splice_direct(in, &ppos, out, len, 0);
5076 +}
5077 +
5078 +struct dentry *cow_break_link(const char *pathname)
5079 +{
5080 +       int ret, mode, pathlen, redo = 0;
5081 +       struct nameidata old_nd, dir_nd;
5082 +       struct path old_path, new_path;
5083 +       struct dentry *dir, *res = NULL;
5084 +       struct file *old_file;
5085 +       struct file *new_file;
5086 +       char *to, *path, pad='\251';
5087 +       loff_t size;
5088 +
5089 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5090 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5091 +       ret = -ENOMEM;
5092 +       if (!path)
5093 +               goto out;
5094 +
5095 +       /* old_nd will have refs to dentry and mnt */
5096 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5097 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5098 +       if (ret < 0)
5099 +               goto out_free_path;
5100 +
5101 +       old_path = old_nd.path;
5102 +       mode = old_path.dentry->d_inode->i_mode;
5103 +
5104 +       to = d_path(&old_path, path, PATH_MAX-2);
5105 +       pathlen = strlen(to);
5106 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5107 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5108 +               old_path.dentry->d_name.len);
5109 +
5110 +       to[pathlen + 1] = 0;
5111 +retry:
5112 +       to[pathlen] = pad--;
5113 +       ret = -EMLINK;
5114 +       if (pad <= '\240')
5115 +               goto out_rel_old;
5116 +
5117 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5118 +       /* dir_nd will have refs to dentry and mnt */
5119 +       ret = path_lookup(to,
5120 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5121 +       vxdprintk(VXD_CBIT(misc, 2),
5122 +               "path_lookup(new): %d", ret);
5123 +       if (ret < 0)
5124 +               goto retry;
5125 +
5126 +       /* this puppy downs the inode mutex */
5127 +       new_path.dentry = lookup_create(&dir_nd, 0);
5128 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5129 +               vxdprintk(VXD_CBIT(misc, 2),
5130 +                       "lookup_create(new): %p", new_path.dentry);
5131 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5132 +               path_put(&dir_nd.path);
5133 +               goto retry;
5134 +       }
5135 +       vxdprintk(VXD_CBIT(misc, 2),
5136 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5137 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5138 +               new_path.dentry->d_name.len);
5139 +       dir = dir_nd.path.dentry;
5140 +
5141 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5142 +       vxdprintk(VXD_CBIT(misc, 2),
5143 +               "vfs_create(new): %d", ret);
5144 +       if (ret == -EEXIST) {
5145 +               mutex_unlock(&dir->d_inode->i_mutex);
5146 +               dput(new_path.dentry);
5147 +               path_put(&dir_nd.path);
5148 +               goto retry;
5149 +       }
5150 +       else if (ret < 0)
5151 +               goto out_unlock_new;
5152 +
5153 +       /* drop out early, ret passes ENOENT */
5154 +       ret = -ENOENT;
5155 +       if ((redo = d_unhashed(old_path.dentry)))
5156 +               goto out_unlock_new;
5157 +
5158 +       new_path.mnt = dir_nd.path.mnt;
5159 +       dget(old_path.dentry);
5160 +       mntget(old_path.mnt);
5161 +       /* this one cleans up the dentry/mnt in case of failure */
5162 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5163 +               O_RDONLY, current_cred());
5164 +       vxdprintk(VXD_CBIT(misc, 2),
5165 +               "dentry_open(old): %p", old_file);
5166 +       if (!old_file || IS_ERR(old_file)) {
5167 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5168 +               goto out_unlock_new;
5169 +       }
5170 +
5171 +       dget(new_path.dentry);
5172 +       mntget(new_path.mnt);
5173 +       /* this one cleans up the dentry/mnt in case of failure */
5174 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5175 +               O_WRONLY, current_cred());
5176 +       vxdprintk(VXD_CBIT(misc, 2),
5177 +               "dentry_open(new): %p", new_file);
5178 +
5179 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5180 +       if (!new_file || IS_ERR(new_file))
5181 +               goto out_fput_old;
5182 +
5183 +       size = i_size_read(old_file->f_dentry->d_inode);
5184 +       ret = do_cow_splice(old_file, new_file, size);
5185 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5186 +       if (ret < 0) {
5187 +               goto out_fput_both;
5188 +       } else if (ret < size) {
5189 +               ret = -ENOSPC;
5190 +               goto out_fput_both;
5191 +       } else {
5192 +               struct inode *old_inode = old_path.dentry->d_inode;
5193 +               struct inode *new_inode = new_path.dentry->d_inode;
5194 +               struct iattr attr = {
5195 +                       .ia_uid = old_inode->i_uid,
5196 +                       .ia_gid = old_inode->i_gid,
5197 +                       .ia_valid = ATTR_UID | ATTR_GID
5198 +                       };
5199 +
5200 +               ret = inode_setattr(new_inode, &attr);
5201 +               if (ret)
5202 +                       goto out_fput_both;
5203 +       }
5204 +
5205 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5206 +
5207 +       /* drop out late */
5208 +       ret = -ENOENT;
5209 +       if ((redo = d_unhashed(old_path.dentry)))
5210 +               goto out_unlock;
5211 +
5212 +       vxdprintk(VXD_CBIT(misc, 2),
5213 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5214 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5215 +               new_path.dentry->d_name.len,
5216 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5217 +               old_path.dentry->d_name.len);
5218 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5219 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5220 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5221 +       res = new_path.dentry;
5222 +
5223 +out_unlock:
5224 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5225 +
5226 +out_fput_both:
5227 +       vxdprintk(VXD_CBIT(misc, 3),
5228 +               "fput(new_file=%p[#%ld])", new_file,
5229 +               atomic_long_read(&new_file->f_count));
5230 +       fput(new_file);
5231 +
5232 +out_fput_old:
5233 +       vxdprintk(VXD_CBIT(misc, 3),
5234 +               "fput(old_file=%p[#%ld])", old_file,
5235 +               atomic_long_read(&old_file->f_count));
5236 +       fput(old_file);
5237 +
5238 +out_unlock_new:
5239 +       mutex_unlock(&dir->d_inode->i_mutex);
5240 +       if (!ret)
5241 +               goto out_redo;
5242 +
5243 +       /* error path cleanup */
5244 +       vfs_unlink(dir->d_inode, new_path.dentry);
5245 +       dput(new_path.dentry);
5246 +
5247 +out_redo:
5248 +       if (!redo)
5249 +               goto out_rel_both;
5250 +       /* lookup dentry once again */
5251 +       path_put(&old_nd.path);
5252 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5253 +       if (ret)
5254 +               goto out_rel_both;
5255 +
5256 +       new_path.dentry = old_nd.path.dentry;
5257 +       vxdprintk(VXD_CBIT(misc, 2),
5258 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5259 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5260 +               new_path.dentry->d_name.len);
5261 +       dget(new_path.dentry);
5262 +       res = new_path.dentry;
5263 +
5264 +out_rel_both:
5265 +       path_put(&dir_nd.path);
5266 +out_rel_old:
5267 +       path_put(&old_nd.path);
5268 +out_free_path:
5269 +       kfree(path);
5270 +out:
5271 +       if (ret)
5272 +               res = ERR_PTR(ret);
5273 +       return res;
5274 +}
5275 +
5276 +#endif
5277 +
5278  /* get the link contents into pagecache */
5279  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5280  {
5281 diff -NurpP --minimal linux-2.6.32/fs/namespace.c linux-2.6.32-vs2.3.0.36.26/fs/namespace.c
5282 --- linux-2.6.32/fs/namespace.c 2009-12-03 20:02:52.000000000 +0100
5283 +++ linux-2.6.32-vs2.3.0.36.26/fs/namespace.c   2009-12-03 20:04:56.000000000 +0100
5284 @@ -29,6 +29,11 @@
5285  #include <linux/log2.h>
5286  #include <linux/idr.h>
5287  #include <linux/fs_struct.h>
5288 +#include <linux/vs_base.h>
5289 +#include <linux/vs_context.h>
5290 +#include <linux/vs_tag.h>
5291 +#include <linux/vserver/space.h>
5292 +#include <linux/vserver/global.h>
5293  #include <asm/uaccess.h>
5294  #include <asm/unistd.h>
5295  #include "pnode.h"
5296 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5297                 mnt->mnt_root = dget(root);
5298                 mnt->mnt_mountpoint = mnt->mnt_root;
5299                 mnt->mnt_parent = mnt;
5300 +               mnt->mnt_tag = old->mnt_tag;
5301  
5302                 if (flag & CL_SLAVE) {
5303                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5304 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5305         seq_escape(m, s, " \t\n\\");
5306  }
5307  
5308 +static int mnt_is_reachable(struct vfsmount *mnt)
5309 +{
5310 +       struct path root;
5311 +       struct dentry *point;
5312 +       int ret;
5313 +
5314 +       if (mnt == mnt->mnt_ns->root)
5315 +               return 1;
5316 +
5317 +       spin_lock(&vfsmount_lock);
5318 +       root = current->fs->root;
5319 +       point = root.dentry;
5320 +
5321 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5322 +               point = mnt->mnt_mountpoint;
5323 +               mnt = mnt->mnt_parent;
5324 +       }
5325 +
5326 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5327 +
5328 +       spin_unlock(&vfsmount_lock);
5329 +
5330 +       return ret;
5331 +}
5332 +
5333  /*
5334   * Simple .show_options callback for filesystems which don't want to
5335   * implement more complex mount option showing.
5336 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5337                 { MS_SYNCHRONOUS, ",sync" },
5338                 { MS_DIRSYNC, ",dirsync" },
5339                 { MS_MANDLOCK, ",mand" },
5340 +               { MS_TAGGED, ",tag" },
5341 +               { MS_NOTAGCHECK, ",notagcheck" },
5342                 { 0, NULL }
5343         };
5344         const struct proc_fs_info *fs_infop;
5345 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5346         int err = 0;
5347         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5348  
5349 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5350 -       seq_putc(m, ' ');
5351 -       seq_path(m, &mnt_path, " \t\n\\");
5352 -       seq_putc(m, ' ');
5353 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5354 +               return SEQ_SKIP;
5355 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5356 +               return SEQ_SKIP;
5357 +
5358 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5359 +               mnt == current->fs->root.mnt) {
5360 +               seq_puts(m, "/dev/root / ");
5361 +       } else {
5362 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5363 +               seq_putc(m, ' ');
5364 +               seq_path(m, &mnt_path, " \t\n\\");
5365 +               seq_putc(m, ' ');
5366 +       }
5367         show_type(m, mnt->mnt_sb);
5368         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5369         err = show_sb_opts(m, mnt->mnt_sb);
5370 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5371         struct path root = p->root;
5372         int err = 0;
5373  
5374 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5375 +               return SEQ_SKIP;
5376 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5377 +               return SEQ_SKIP;
5378 +
5379         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5380                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5381         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5382 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5383         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5384         int err = 0;
5385  
5386 -       /* device */
5387 -       if (mnt->mnt_devname) {
5388 -               seq_puts(m, "device ");
5389 -               mangle(m, mnt->mnt_devname);
5390 -       } else
5391 -               seq_puts(m, "no device");
5392 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5393 +               return SEQ_SKIP;
5394 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5395 +               return SEQ_SKIP;
5396  
5397 -       /* mount point */
5398 -       seq_puts(m, " mounted on ");
5399 -       seq_path(m, &mnt_path, " \t\n\\");
5400 -       seq_putc(m, ' ');
5401 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5402 +               mnt == current->fs->root.mnt) {
5403 +               seq_puts(m, "device /dev/root mounted on / ");
5404 +       } else {
5405 +               /* device */
5406 +               if (mnt->mnt_devname) {
5407 +                       seq_puts(m, "device ");
5408 +                       mangle(m, mnt->mnt_devname);
5409 +               } else
5410 +                       seq_puts(m, "no device");
5411 +
5412 +               /* mount point */
5413 +               seq_puts(m, " mounted on ");
5414 +               seq_path(m, &mnt_path, " \t\n\\");
5415 +               seq_putc(m, ' ');
5416 +       }
5417  
5418         /* file system type */
5419         seq_puts(m, "with fstype ");
5420 @@ -1130,7 +1188,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5421                 goto dput_and_out;
5422  
5423         retval = -EPERM;
5424 -       if (!capable(CAP_SYS_ADMIN))
5425 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5426                 goto dput_and_out;
5427  
5428         retval = do_umount(path.mnt, flags);
5429 @@ -1156,7 +1214,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5430  
5431  static int mount_is_safe(struct path *path)
5432  {
5433 -       if (capable(CAP_SYS_ADMIN))
5434 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5435                 return 0;
5436         return -EPERM;
5437  #ifdef notyet
5438 @@ -1420,7 +1478,7 @@ static int do_change_type(struct path *p
5439         int type = flag & ~MS_REC;
5440         int err = 0;
5441  
5442 -       if (!capable(CAP_SYS_ADMIN))
5443 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5444                 return -EPERM;
5445  
5446         if (path->dentry != path->mnt->mnt_root)
5447 @@ -1447,11 +1505,13 @@ static int do_change_type(struct path *p
5448   * do loopback mount.
5449   */
5450  static int do_loopback(struct path *path, char *old_name,
5451 -                               int recurse)
5452 +       tag_t tag, unsigned long flags, int mnt_flags)
5453  {
5454         struct path old_path;
5455         struct vfsmount *mnt = NULL;
5456         int err = mount_is_safe(path);
5457 +       int recurse = flags & MS_REC;
5458 +
5459         if (err)
5460                 return err;
5461         if (!old_name || !*old_name)
5462 @@ -1485,6 +1545,7 @@ static int do_loopback(struct path *path
5463                 spin_unlock(&vfsmount_lock);
5464                 release_mounts(&umount_list);
5465         }
5466 +       mnt->mnt_flags = mnt_flags;
5467  
5468  out:
5469         up_write(&namespace_sem);
5470 @@ -1515,12 +1576,12 @@ static int change_mount_flags(struct vfs
5471   * on it - tough luck.
5472   */
5473  static int do_remount(struct path *path, int flags, int mnt_flags,
5474 -                     void *data)
5475 +       void *data, xid_t xid)
5476  {
5477         int err;
5478         struct super_block *sb = path->mnt->mnt_sb;
5479  
5480 -       if (!capable(CAP_SYS_ADMIN))
5481 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5482                 return -EPERM;
5483  
5484         if (!check_mnt(path->mnt))
5485 @@ -1562,7 +1623,7 @@ static int do_move_mount(struct path *pa
5486         struct path old_path, parent_path;
5487         struct vfsmount *p;
5488         int err = 0;
5489 -       if (!capable(CAP_SYS_ADMIN))
5490 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5491                 return -EPERM;
5492         if (!old_name || !*old_name)
5493                 return -EINVAL;
5494 @@ -1644,7 +1705,7 @@ static int do_new_mount(struct path *pat
5495                 return -EINVAL;
5496  
5497         /* we need capabilities... */
5498 -       if (!capable(CAP_SYS_ADMIN))
5499 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5500                 return -EPERM;
5501  
5502         lock_kernel();
5503 @@ -1908,6 +1969,7 @@ long do_mount(char *dev_name, char *dir_
5504         struct path path;
5505         int retval = 0;
5506         int mnt_flags = 0;
5507 +       tag_t tag = 0;
5508  
5509         /* Discard magic */
5510         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5511 @@ -1925,6 +1987,12 @@ long do_mount(char *dev_name, char *dir_
5512         if (!(flags & MS_NOATIME))
5513                 mnt_flags |= MNT_RELATIME;
5514  
5515 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5516 +               /* FIXME: bind and re-mounts get the tag flag? */
5517 +               if (flags & (MS_BIND|MS_REMOUNT))
5518 +                       flags |= MS_TAGID;
5519 +       }
5520 +
5521         /* Separate the per-mountpoint flags */
5522         if (flags & MS_NOSUID)
5523                 mnt_flags |= MNT_NOSUID;
5524 @@ -1941,6 +2009,8 @@ long do_mount(char *dev_name, char *dir_
5525         if (flags & MS_RDONLY)
5526                 mnt_flags |= MNT_READONLY;
5527  
5528 +       if (!capable(CAP_SYS_ADMIN))
5529 +               mnt_flags |= MNT_NODEV;
5530         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5531                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5532                    MS_STRICTATIME);
5533 @@ -1957,9 +2027,9 @@ long do_mount(char *dev_name, char *dir_
5534  
5535         if (flags & MS_REMOUNT)
5536                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5537 -                                   data_page);
5538 +                                   data_page, tag);
5539         else if (flags & MS_BIND)
5540 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5541 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5542         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5543                 retval = do_change_type(&path, flags);
5544         else if (flags & MS_MOVE)
5545 @@ -2038,6 +2108,7 @@ static struct mnt_namespace *dup_mnt_ns(
5546                 q = next_mnt(q, new_ns->root);
5547         }
5548         up_write(&namespace_sem);
5549 +       atomic_inc(&vs_global_mnt_ns);
5550  
5551         if (rootmnt)
5552                 mntput(rootmnt);
5553 @@ -2182,9 +2253,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5554         down_write(&namespace_sem);
5555         mutex_lock(&old.dentry->d_inode->i_mutex);
5556         error = -EINVAL;
5557 -       if (IS_MNT_SHARED(old.mnt) ||
5558 +       if ((IS_MNT_SHARED(old.mnt) ||
5559                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5560 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5561 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5562 +               !vx_flags(VXF_STATE_SETUP, 0))
5563                 goto out2;
5564         if (!check_mnt(root.mnt))
5565                 goto out2;
5566 @@ -2320,6 +2392,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5567         spin_unlock(&vfsmount_lock);
5568         up_write(&namespace_sem);
5569         release_mounts(&umount_list);
5570 +       atomic_dec(&vs_global_mnt_ns);
5571         kfree(ns);
5572  }
5573  EXPORT_SYMBOL(put_mnt_ns);
5574 diff -NurpP --minimal linux-2.6.32/fs/nfs/client.c linux-2.6.32-vs2.3.0.36.26/fs/nfs/client.c
5575 --- linux-2.6.32/fs/nfs/client.c        2009-12-03 20:02:52.000000000 +0100
5576 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfs/client.c  2009-12-03 20:04:56.000000000 +0100
5577 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5578         if (server->flags & NFS_MOUNT_SOFT)
5579                 server->client->cl_softrtry = 1;
5580  
5581 +       server->client->cl_tag = 0;
5582 +       if (server->flags & NFS_MOUNT_TAGGED)
5583 +               server->client->cl_tag = 1;
5584         return 0;
5585  }
5586  
5587 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5588                 server->acdirmin = server->acdirmax = 0;
5589         }
5590  
5591 +       /* FIXME: needs fsinfo
5592 +       if (server->flags & NFS_MOUNT_TAGGED)
5593 +               sb->s_flags |= MS_TAGGED;       */
5594 +
5595         server->maxfilesize = fsinfo->maxfilesize;
5596  
5597         /* We're airborne Set socket buffersize */
5598 diff -NurpP --minimal linux-2.6.32/fs/nfs/dir.c linux-2.6.32-vs2.3.0.36.26/fs/nfs/dir.c
5599 --- linux-2.6.32/fs/nfs/dir.c   2009-12-03 20:02:52.000000000 +0100
5600 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfs/dir.c     2009-12-03 20:04:56.000000000 +0100
5601 @@ -33,6 +33,7 @@
5602  #include <linux/namei.h>
5603  #include <linux/mount.h>
5604  #include <linux/sched.h>
5605 +#include <linux/vs_tag.h>
5606  
5607  #include "nfs4_fs.h"
5608  #include "delegation.h"
5609 @@ -949,6 +950,7 @@ static struct dentry *nfs_lookup(struct 
5610         if (IS_ERR(res))
5611                 goto out_unblock_sillyrename;
5612  
5613 +       dx_propagate_tag(nd, inode);
5614  no_entry:
5615         res = d_materialise_unique(dentry, inode);
5616         if (res != NULL) {
5617 diff -NurpP --minimal linux-2.6.32/fs/nfs/inode.c linux-2.6.32-vs2.3.0.36.26/fs/nfs/inode.c
5618 --- linux-2.6.32/fs/nfs/inode.c 2009-12-03 20:02:52.000000000 +0100
5619 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfs/inode.c   2009-12-03 20:04:56.000000000 +0100
5620 @@ -36,6 +36,7 @@
5621  #include <linux/vfs.h>
5622  #include <linux/inet.h>
5623  #include <linux/nfs_xdr.h>
5624 +#include <linux/vs_tag.h>
5625  
5626  #include <asm/system.h>
5627  #include <asm/uaccess.h>
5628 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5629         if (inode->i_state & I_NEW) {
5630                 struct nfs_inode *nfsi = NFS_I(inode);
5631                 unsigned long now = jiffies;
5632 +               uid_t uid;
5633 +               gid_t gid;
5634  
5635                 /* We set i_ino for the few things that still rely on it,
5636                  * such as stat(2) */
5637 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5638                 nfsi->change_attr = 0;
5639                 inode->i_size = 0;
5640                 inode->i_nlink = 0;
5641 -               inode->i_uid = -2;
5642 -               inode->i_gid = -2;
5643 +               uid = -2;
5644 +               gid = -2;
5645                 inode->i_blocks = 0;
5646                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5647  
5648 @@ -365,13 +368,13 @@ nfs_fhget(struct super_block *sb, struct
5649                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5650                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5651                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5652 -                       inode->i_uid = fattr->uid;
5653 +                       uid = fattr->uid;
5654                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5655                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5656                                 | NFS_INO_INVALID_ACCESS
5657                                 | NFS_INO_INVALID_ACL;
5658                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5659 -                       inode->i_gid = fattr->gid;
5660 +                       gid = fattr->gid;
5661                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5662                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5663                                 | NFS_INO_INVALID_ACCESS
5664 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5665                          */
5666                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5667                 }
5668 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5669 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5670 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5671 +                               /* maybe fattr->xid someday */
5672 +
5673                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5674                 nfsi->attrtimeo_timestamp = now;
5675                 nfsi->access_cache = RB_ROOT;
5676 @@ -496,6 +504,8 @@ void nfs_setattr_update_inode(struct ino
5677                         inode->i_uid = attr->ia_uid;
5678                 if ((attr->ia_valid & ATTR_GID) != 0)
5679                         inode->i_gid = attr->ia_gid;
5680 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5681 +                       inode->i_tag = attr->ia_tag;
5682                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5683                 spin_unlock(&inode->i_lock);
5684         }
5685 @@ -906,6 +916,9 @@ static int nfs_check_inode_attributes(st
5686         struct nfs_inode *nfsi = NFS_I(inode);
5687         loff_t cur_size, new_isize;
5688         unsigned long invalid = 0;
5689 +       uid_t uid;
5690 +       gid_t gid;
5691 +       tag_t tag;
5692  
5693  
5694         /* Has the inode gone and changed behind our back? */
5695 @@ -929,13 +942,18 @@ static int nfs_check_inode_attributes(st
5696                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5697         }
5698  
5699 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5700 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5701 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5702 +
5703         /* Have any file permissions changed? */
5704         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5705                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5706 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5707 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5708                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5709 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5710 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5711                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5712 +               /* maybe check for tag too? */
5713  
5714         /* Has the link count changed? */
5715         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5716 @@ -1150,6 +1168,9 @@ static int nfs_update_inode(struct inode
5717         unsigned long invalid = 0;
5718         unsigned long now = jiffies;
5719         unsigned long save_cache_validity;
5720 +       uid_t uid;
5721 +       gid_t gid;
5722 +       tag_t tag;
5723  
5724         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5725                         __func__, inode->i_sb->s_id, inode->i_ino,
5726 @@ -1252,6 +1273,9 @@ static int nfs_update_inode(struct inode
5727                                 | NFS_INO_REVAL_PAGECACHE
5728                                 | NFS_INO_REVAL_FORCED);
5729  
5730 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5731 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5732 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5733  
5734         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5735                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5736 @@ -1271,9 +1295,9 @@ static int nfs_update_inode(struct inode
5737                                 | NFS_INO_REVAL_FORCED);
5738  
5739         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5740 -               if (inode->i_uid != fattr->uid) {
5741 +               if (uid != fattr->uid) {
5742                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5743 -                       inode->i_uid = fattr->uid;
5744 +                       uid = fattr->uid;
5745                 }
5746         } else if (server->caps & NFS_CAP_OWNER)
5747                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5748 @@ -1282,9 +1306,9 @@ static int nfs_update_inode(struct inode
5749                                 | NFS_INO_REVAL_FORCED);
5750  
5751         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5752 -               if (inode->i_gid != fattr->gid) {
5753 +               if (gid != fattr->gid) {
5754                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5755 -                       inode->i_gid = fattr->gid;
5756 +                       gid = fattr->gid;
5757                 }
5758         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5759                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5760 @@ -1292,6 +1316,10 @@ static int nfs_update_inode(struct inode
5761                                 | NFS_INO_INVALID_ACL
5762                                 | NFS_INO_REVAL_FORCED);
5763  
5764 +       inode->i_uid = uid;
5765 +       inode->i_gid = gid;
5766 +       inode->i_tag = tag;
5767 +
5768         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5769                 if (inode->i_nlink != fattr->nlink) {
5770                         invalid |= NFS_INO_INVALID_ATTR;
5771 diff -NurpP --minimal linux-2.6.32/fs/nfs/nfs3xdr.c linux-2.6.32-vs2.3.0.36.26/fs/nfs/nfs3xdr.c
5772 --- linux-2.6.32/fs/nfs/nfs3xdr.c       2009-12-03 20:02:52.000000000 +0100
5773 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfs/nfs3xdr.c 2009-12-03 20:04:56.000000000 +0100
5774 @@ -21,6 +21,7 @@
5775  #include <linux/nfs3.h>
5776  #include <linux/nfs_fs.h>
5777  #include <linux/nfsacl.h>
5778 +#include <linux/vs_tag.h>
5779  #include "internal.h"
5780  
5781  #define NFSDBG_FACILITY                NFSDBG_XDR
5782 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5783  }
5784  
5785  static inline __be32 *
5786 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5787 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5788  {
5789         if (attr->ia_valid & ATTR_MODE) {
5790                 *p++ = xdr_one;
5791 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5792         } else {
5793                 *p++ = xdr_zero;
5794         }
5795 -       if (attr->ia_valid & ATTR_UID) {
5796 +       if (attr->ia_valid & ATTR_UID ||
5797 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5798                 *p++ = xdr_one;
5799 -               *p++ = htonl(attr->ia_uid);
5800 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5801         } else {
5802                 *p++ = xdr_zero;
5803         }
5804 -       if (attr->ia_valid & ATTR_GID) {
5805 +       if (attr->ia_valid & ATTR_GID ||
5806 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5807                 *p++ = xdr_one;
5808 -               *p++ = htonl(attr->ia_gid);
5809 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5810         } else {
5811                 *p++ = xdr_zero;
5812         }
5813 @@ -279,7 +282,8 @@ static int
5814  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5815  {
5816         p = xdr_encode_fhandle(p, args->fh);
5817 -       p = xdr_encode_sattr(p, args->sattr);
5818 +       p = xdr_encode_sattr(p, args->sattr,
5819 +               req->rq_task->tk_client->cl_tag);
5820         *p++ = htonl(args->guard);
5821         if (args->guard)
5822                 p = xdr_encode_time3(p, &args->guardtime);
5823 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5824                 *p++ = args->verifier[0];
5825                 *p++ = args->verifier[1];
5826         } else
5827 -               p = xdr_encode_sattr(p, args->sattr);
5828 +               p = xdr_encode_sattr(p, args->sattr,
5829 +                       req->rq_task->tk_client->cl_tag);
5830  
5831         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5832         return 0;
5833 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5834  {
5835         p = xdr_encode_fhandle(p, args->fh);
5836         p = xdr_encode_array(p, args->name, args->len);
5837 -       p = xdr_encode_sattr(p, args->sattr);
5838 +       p = xdr_encode_sattr(p, args->sattr,
5839 +               req->rq_task->tk_client->cl_tag);
5840         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5841         return 0;
5842  }
5843 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5844  {
5845         p = xdr_encode_fhandle(p, args->fromfh);
5846         p = xdr_encode_array(p, args->fromname, args->fromlen);
5847 -       p = xdr_encode_sattr(p, args->sattr);
5848 +       p = xdr_encode_sattr(p, args->sattr,
5849 +               req->rq_task->tk_client->cl_tag);
5850         *p++ = htonl(args->pathlen);
5851         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5852  
5853 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5854         p = xdr_encode_fhandle(p, args->fh);
5855         p = xdr_encode_array(p, args->name, args->len);
5856         *p++ = htonl(args->type);
5857 -       p = xdr_encode_sattr(p, args->sattr);
5858 +       p = xdr_encode_sattr(p, args->sattr,
5859 +               req->rq_task->tk_client->cl_tag);
5860         if (args->type == NF3CHR || args->type == NF3BLK) {
5861                 *p++ = htonl(MAJOR(args->rdev));
5862                 *p++ = htonl(MINOR(args->rdev));
5863 diff -NurpP --minimal linux-2.6.32/fs/nfs/nfsroot.c linux-2.6.32-vs2.3.0.36.26/fs/nfs/nfsroot.c
5864 --- linux-2.6.32/fs/nfs/nfsroot.c       2009-09-10 15:26:23.000000000 +0200
5865 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfs/nfsroot.c 2009-12-03 20:04:56.000000000 +0100
5866 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5867  enum {
5868         /* Options that take integer arguments */
5869         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5870 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5871 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5872         /* Options that take no arguments */
5873         Opt_soft, Opt_hard, Opt_intr,
5874         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5875         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5876 -       Opt_acl, Opt_noacl,
5877 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5878         /* Error token */
5879         Opt_err
5880  };
5881 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5882         {Opt_tcp, "tcp"},
5883         {Opt_acl, "acl"},
5884         {Opt_noacl, "noacl"},
5885 +       {Opt_tag, "tag"},
5886 +       {Opt_notag, "notag"},
5887 +       {Opt_tagid, "tagid=%u"},
5888         {Opt_err, NULL}
5889         
5890  };
5891 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5892                         case Opt_noacl:
5893                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5894                                 break;
5895 +#ifndef CONFIG_TAGGING_NONE
5896 +                       case Opt_tag:
5897 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5898 +                               break;
5899 +                       case Opt_notag:
5900 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5901 +                               break;
5902 +#endif
5903 +#ifdef CONFIG_PROPAGATE
5904 +                       case Opt_tagid:
5905 +                               /* use args[0] */
5906 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5907 +                               break;
5908 +#endif
5909                         default:
5910                                 printk(KERN_WARNING "Root-NFS: unknown "
5911                                         "option: %s\n", p);
5912 diff -NurpP --minimal linux-2.6.32/fs/nfs/super.c linux-2.6.32-vs2.3.0.36.26/fs/nfs/super.c
5913 --- linux-2.6.32/fs/nfs/super.c 2009-12-03 20:02:52.000000000 +0100
5914 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfs/super.c   2009-12-03 20:04:56.000000000 +0100
5915 @@ -53,6 +53,7 @@
5916  #include <linux/nfs_xdr.h>
5917  #include <linux/magic.h>
5918  #include <linux/parser.h>
5919 +#include <linux/vs_tag.h>
5920  
5921  #include <asm/system.h>
5922  #include <asm/uaccess.h>
5923 @@ -551,6 +552,7 @@ static void nfs_show_mount_options(struc
5924                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5925                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5926                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5927 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5928                 { 0, NULL, NULL }
5929         };
5930         const struct proc_nfs_info *nfs_infop;
5931 diff -NurpP --minimal linux-2.6.32/fs/nfsd/auth.c linux-2.6.32-vs2.3.0.36.26/fs/nfsd/auth.c
5932 --- linux-2.6.32/fs/nfsd/auth.c 2009-12-03 20:02:52.000000000 +0100
5933 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfsd/auth.c   2009-12-03 20:04:56.000000000 +0100
5934 @@ -10,6 +10,7 @@
5935  #include <linux/sunrpc/svcauth.h>
5936  #include <linux/nfsd/nfsd.h>
5937  #include <linux/nfsd/export.h>
5938 +#include <linux/vs_tag.h>
5939  #include "auth.h"
5940  
5941  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
5942 @@ -44,6 +45,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5943  
5944         new->fsuid = rqstp->rq_cred.cr_uid;
5945         new->fsgid = rqstp->rq_cred.cr_gid;
5946 +       /* FIXME: this desperately needs a tag :)
5947 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5948 +                       */
5949  
5950         rqgi = rqstp->rq_cred.cr_group_info;
5951  
5952 diff -NurpP --minimal linux-2.6.32/fs/nfsd/nfs3xdr.c linux-2.6.32-vs2.3.0.36.26/fs/nfsd/nfs3xdr.c
5953 --- linux-2.6.32/fs/nfsd/nfs3xdr.c      2009-12-03 20:02:52.000000000 +0100
5954 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfsd/nfs3xdr.c        2009-12-03 20:04:56.000000000 +0100
5955 @@ -21,6 +21,7 @@
5956  #include <linux/sunrpc/svc.h>
5957  #include <linux/nfsd/nfsd.h>
5958  #include <linux/nfsd/xdr3.h>
5959 +#include <linux/vs_tag.h>
5960  #include "auth.h"
5961  
5962  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5963 @@ -108,6 +109,8 @@ static __be32 *
5964  decode_sattr3(__be32 *p, struct iattr *iap)
5965  {
5966         u32     tmp;
5967 +       uid_t   uid = 0;
5968 +       gid_t   gid = 0;
5969  
5970         iap->ia_valid = 0;
5971  
5972 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5973         }
5974         if (*p++) {
5975                 iap->ia_valid |= ATTR_UID;
5976 -               iap->ia_uid = ntohl(*p++);
5977 +               uid = ntohl(*p++);
5978         }
5979         if (*p++) {
5980                 iap->ia_valid |= ATTR_GID;
5981 -               iap->ia_gid = ntohl(*p++);
5982 +               gid = ntohl(*p++);
5983         }
5984 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5985 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5986 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5987         if (*p++) {
5988                 u64     newsize;
5989  
5990 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5991         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5992         *p++ = htonl((u32) stat->mode);
5993         *p++ = htonl((u32) stat->nlink);
5994 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5995 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5996 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5997 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5998 +               stat->uid, stat->tag)));
5999 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6000 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6001 +               stat->gid, stat->tag)));
6002         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6003                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6004         } else {
6005 diff -NurpP --minimal linux-2.6.32/fs/nfsd/nfs4xdr.c linux-2.6.32-vs2.3.0.36.26/fs/nfsd/nfs4xdr.c
6006 --- linux-2.6.32/fs/nfsd/nfs4xdr.c      2009-12-03 20:02:52.000000000 +0100
6007 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfsd/nfs4xdr.c        2009-12-03 20:04:56.000000000 +0100
6008 @@ -57,6 +57,7 @@
6009  #include <linux/nfs4_acl.h>
6010  #include <linux/sunrpc/gss_api.h>
6011  #include <linux/sunrpc/svcauth_gss.h>
6012 +#include <linux/vs_tag.h>
6013  
6014  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6015  
6016 @@ -2050,14 +2051,18 @@ out_acl:
6017                 WRITE32(stat.nlink);
6018         }
6019         if (bmval1 & FATTR4_WORD1_OWNER) {
6020 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6021 +               status = nfsd4_encode_user(rqstp,
6022 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6023 +                       stat.uid, stat.tag), &p, &buflen);
6024                 if (status == nfserr_resource)
6025                         goto out_resource;
6026                 if (status)
6027                         goto out;
6028         }
6029         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6030 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6031 +               status = nfsd4_encode_group(rqstp,
6032 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6033 +                       stat.gid, stat.tag), &p, &buflen);
6034                 if (status == nfserr_resource)
6035                         goto out_resource;
6036                 if (status)
6037 diff -NurpP --minimal linux-2.6.32/fs/nfsd/nfsxdr.c linux-2.6.32-vs2.3.0.36.26/fs/nfsd/nfsxdr.c
6038 --- linux-2.6.32/fs/nfsd/nfsxdr.c       2008-12-25 00:26:37.000000000 +0100
6039 +++ linux-2.6.32-vs2.3.0.36.26/fs/nfsd/nfsxdr.c 2009-12-03 20:04:56.000000000 +0100
6040 @@ -15,6 +15,7 @@
6041  #include <linux/nfsd/nfsd.h>
6042  #include <linux/nfsd/xdr.h>
6043  #include <linux/mm.h>
6044 +#include <linux/vs_tag.h>
6045  #include "auth.h"
6046  
6047  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6048 @@ -98,6 +99,8 @@ static __be32 *
6049  decode_sattr(__be32 *p, struct iattr *iap)
6050  {
6051         u32     tmp, tmp1;
6052 +       uid_t   uid = 0;
6053 +       gid_t   gid = 0;
6054  
6055         iap->ia_valid = 0;
6056  
6057 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6058         }
6059         if ((tmp = ntohl(*p++)) != (u32)-1) {
6060                 iap->ia_valid |= ATTR_UID;
6061 -               iap->ia_uid = tmp;
6062 +               uid = tmp;
6063         }
6064         if ((tmp = ntohl(*p++)) != (u32)-1) {
6065                 iap->ia_valid |= ATTR_GID;
6066 -               iap->ia_gid = tmp;
6067 +               gid = tmp;
6068         }
6069 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6070 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6071 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6072         if ((tmp = ntohl(*p++)) != (u32)-1) {
6073                 iap->ia_valid |= ATTR_SIZE;
6074                 iap->ia_size = tmp;
6075 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6076         *p++ = htonl(nfs_ftypes[type >> 12]);
6077         *p++ = htonl((u32) stat->mode);
6078         *p++ = htonl((u32) stat->nlink);
6079 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6080 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6081 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6082 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6083 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6084 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6085  
6086         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6087                 *p++ = htonl(NFS_MAXPATHLEN);
6088 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/dlm/dlmfs.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/dlm/dlmfs.c
6089 --- linux-2.6.32/fs/ocfs2/dlm/dlmfs.c   2009-12-03 20:02:53.000000000 +0100
6090 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/dlm/dlmfs.c     2009-12-03 20:04:56.000000000 +0100
6091 @@ -43,6 +43,7 @@
6092  #include <linux/init.h>
6093  #include <linux/string.h>
6094  #include <linux/backing-dev.h>
6095 +#include <linux/vs_tag.h>
6096  
6097  #include <asm/uaccess.h>
6098  
6099 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6100                 inode->i_mode = mode;
6101                 inode->i_uid = current_fsuid();
6102                 inode->i_gid = current_fsgid();
6103 +               inode->i_tag = dx_current_fstag(sb);
6104                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6105                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6106                 inc_nlink(inode);
6107 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6108         inode->i_mode = mode;
6109         inode->i_uid = current_fsuid();
6110         inode->i_gid = current_fsgid();
6111 +       inode->i_tag = dx_current_fstag(sb);
6112         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6113         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6114  
6115 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/dlmglue.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/dlmglue.c
6116 --- linux-2.6.32/fs/ocfs2/dlmglue.c     2009-12-03 20:02:53.000000000 +0100
6117 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/dlmglue.c       2009-12-03 20:04:56.000000000 +0100
6118 @@ -1991,6 +1991,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6119         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6120         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6121         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6122 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6123         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6124         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6125         lvb->lvb_iatime_packed  =
6126 @@ -2045,6 +2046,7 @@ static void ocfs2_refresh_inode_from_lvb
6127  
6128         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6129         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6130 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6131         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6132         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6133         ocfs2_unpack_timespec(&inode->i_atime,
6134 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/dlmglue.h linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/dlmglue.h
6135 --- linux-2.6.32/fs/ocfs2/dlmglue.h     2009-12-03 20:02:53.000000000 +0100
6136 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/dlmglue.h       2009-12-03 20:04:56.000000000 +0100
6137 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6138         __be16       lvb_inlink;
6139         __be32       lvb_iattr;
6140         __be32       lvb_igeneration;
6141 -       __be32       lvb_reserved2;
6142 +       __be16       lvb_itag;
6143 +       __be16       lvb_reserved2;
6144  };
6145  
6146  #define OCFS2_QINFO_LVB_VERSION 1
6147 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/file.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/file.c
6148 --- linux-2.6.32/fs/ocfs2/file.c        2009-12-03 20:02:53.000000000 +0100
6149 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/file.c  2009-12-03 20:04:56.000000000 +0100
6150 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6151                 mlog(0, "uid change: %d\n", attr->ia_uid);
6152         if (attr->ia_valid & ATTR_GID)
6153                 mlog(0, "gid change: %d\n", attr->ia_gid);
6154 +       if (attr->ia_valid & ATTR_TAG)
6155 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6156         if (attr->ia_valid & ATTR_SIZE)
6157                 mlog(0, "size change...\n");
6158         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6159                 mlog(0, "time change...\n");
6160  
6161  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6162 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6163 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6164         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6165                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6166                 return 0;
6167 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/inode.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/inode.c
6168 --- linux-2.6.32/fs/ocfs2/inode.c       2009-12-03 20:02:53.000000000 +0100
6169 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/inode.c 2009-12-03 20:04:56.000000000 +0100
6170 @@ -29,6 +29,7 @@
6171  #include <linux/highmem.h>
6172  #include <linux/pagemap.h>
6173  #include <linux/quotaops.h>
6174 +#include <linux/vs_tag.h>
6175  
6176  #include <asm/byteorder.h>
6177  
6178 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6179  {
6180         unsigned int flags = OCFS2_I(inode)->ip_attr;
6181  
6182 -       inode->i_flags &= ~(S_IMMUTABLE |
6183 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6184                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6185  
6186         if (flags & OCFS2_IMMUTABLE_FL)
6187                 inode->i_flags |= S_IMMUTABLE;
6188 +       if (flags & OCFS2_IXUNLINK_FL)
6189 +               inode->i_flags |= S_IXUNLINK;
6190  
6191         if (flags & OCFS2_SYNC_FL)
6192                 inode->i_flags |= S_SYNC;
6193 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6194                 inode->i_flags |= S_NOATIME;
6195         if (flags & OCFS2_DIRSYNC_FL)
6196                 inode->i_flags |= S_DIRSYNC;
6197 +
6198 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6199 +
6200 +       if (flags & OCFS2_BARRIER_FL)
6201 +               inode->i_vflags |= V_BARRIER;
6202 +       if (flags & OCFS2_COW_FL)
6203 +               inode->i_vflags |= V_COW;
6204  }
6205  
6206  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6207  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6208  {
6209         unsigned int flags = oi->vfs_inode.i_flags;
6210 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6211 +
6212 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6213 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6214 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6215 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6216 +
6217 +       if (flags & S_IMMUTABLE)
6218 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6219 +       if (flags & S_IXUNLINK)
6220 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6221  
6222 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6223 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6224         if (flags & S_SYNC)
6225                 oi->ip_attr |= OCFS2_SYNC_FL;
6226         if (flags & S_APPEND)
6227                 oi->ip_attr |= OCFS2_APPEND_FL;
6228 -       if (flags & S_IMMUTABLE)
6229 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6230         if (flags & S_NOATIME)
6231                 oi->ip_attr |= OCFS2_NOATIME_FL;
6232         if (flags & S_DIRSYNC)
6233                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6234 +
6235 +       if (vflags & V_BARRIER)
6236 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6237 +       if (vflags & V_COW)
6238 +               oi->ip_attr |= OCFS2_COW_FL;
6239  }
6240  
6241  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6242 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6243         struct super_block *sb;
6244         struct ocfs2_super *osb;
6245         int use_plocks = 1;
6246 +       uid_t uid;
6247 +       gid_t gid;
6248  
6249         mlog_entry("(0x%p, size:%llu)\n", inode,
6250                    (unsigned long long)le64_to_cpu(fe->i_size));
6251 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6252         inode->i_generation = le32_to_cpu(fe->i_generation);
6253         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6254         inode->i_mode = le16_to_cpu(fe->i_mode);
6255 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6256 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6257 +       uid = le32_to_cpu(fe->i_uid);
6258 +       gid = le32_to_cpu(fe->i_gid);
6259 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6260 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6261 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6262 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6263  
6264         /* Fast symlinks will have i_size but no allocated clusters. */
6265         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6266 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/inode.h linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/inode.h
6267 --- linux-2.6.32/fs/ocfs2/inode.h       2009-12-03 20:02:53.000000000 +0100
6268 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/inode.h 2009-12-03 20:04:56.000000000 +0100
6269 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6270  
6271  void ocfs2_set_inode_flags(struct inode *inode);
6272  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6273 +int ocfs2_sync_flags(struct inode *inode, int, int);
6274  
6275  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6276  {
6277 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/ioctl.c
6278 --- linux-2.6.32/fs/ocfs2/ioctl.c       2009-12-03 20:02:53.000000000 +0100
6279 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/ioctl.c 2009-12-03 20:04:56.000000000 +0100
6280 @@ -42,7 +42,41 @@ static int ocfs2_get_inode_attr(struct i
6281         return status;
6282  }
6283  
6284 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6285 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6286 +{
6287 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6288 +       struct buffer_head *bh = NULL;
6289 +       handle_t *handle = NULL;
6290 +       int status;
6291 +
6292 +       status = ocfs2_inode_lock(inode, &bh, 1);
6293 +       if (status < 0) {
6294 +               mlog_errno(status);
6295 +               return status;
6296 +       }
6297 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6298 +       if (IS_ERR(handle)) {
6299 +               status = PTR_ERR(handle);
6300 +               mlog_errno(status);
6301 +               goto bail_unlock;
6302 +       }
6303 +
6304 +       inode->i_flags = flags;
6305 +       inode->i_vflags = vflags;
6306 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6307 +
6308 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6309 +       if (status < 0)
6310 +               mlog_errno(status);
6311 +
6312 +       ocfs2_commit_trans(osb, handle);
6313 +bail_unlock:
6314 +       ocfs2_inode_unlock(inode, 1);
6315 +       brelse(bh);
6316 +       return status;
6317 +}
6318 +
6319 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6320                                 unsigned mask)
6321  {
6322         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6323 @@ -67,6 +101,11 @@ static int ocfs2_set_inode_attr(struct i
6324         if (!S_ISDIR(inode->i_mode))
6325                 flags &= ~OCFS2_DIRSYNC_FL;
6326  
6327 +       if (IS_BARRIER(inode)) {
6328 +               vxwprintk_task(1, "messing with the barrier.");
6329 +               goto bail_unlock;
6330 +       }
6331 +
6332         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6333         if (IS_ERR(handle)) {
6334                 status = PTR_ERR(handle);
6335 @@ -108,6 +147,7 @@ bail:
6336         return status;
6337  }
6338  
6339 +
6340  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6341  {
6342         struct inode *inode = filp->f_path.dentry->d_inode;
6343 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/namei.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/namei.c
6344 --- linux-2.6.32/fs/ocfs2/namei.c       2009-12-03 20:02:53.000000000 +0100
6345 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/namei.c 2009-12-03 20:04:56.000000000 +0100
6346 @@ -41,6 +41,7 @@
6347  #include <linux/slab.h>
6348  #include <linux/highmem.h>
6349  #include <linux/quotaops.h>
6350 +#include <linux/vs_tag.h>
6351  
6352  #define MLOG_MASK_PREFIX ML_NAMEI
6353  #include <cluster/masklog.h>
6354 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6355         u64 fe_blkno = 0;
6356         u16 suballoc_bit;
6357         u16 feat;
6358 +       tag_t tag;
6359  
6360         *new_fe_bh = NULL;
6361  
6362 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6363         fe->i_blkno = cpu_to_le64(fe_blkno);
6364         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6365         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6366 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6367 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6368 +
6369 +       tag = dx_current_fstag(osb->sb);
6370 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6371 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6372 +       inode->i_tag = tag;
6373         fe->i_mode = cpu_to_le16(inode->i_mode);
6374         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6375                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6376 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/ocfs2_fs.h linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/ocfs2_fs.h
6377 --- linux-2.6.32/fs/ocfs2/ocfs2_fs.h    2009-12-03 20:02:53.000000000 +0100
6378 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/ocfs2_fs.h      2009-12-03 20:04:56.000000000 +0100
6379 @@ -231,18 +231,23 @@
6380  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6381  
6382  /* Inode attributes, keep in sync with EXT2 */
6383 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6384 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6385 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6386 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6387 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6388 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6389 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6390 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6391 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6392 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6393 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6394 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6395 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6396 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6397 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6398 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6399 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6400  
6401 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6402 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6403 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6404 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6405 +
6406 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6407 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6408 +
6409 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6410 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6411  
6412  /*
6413   * Extent record flags (e_node.leaf.flags)
6414 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/ocfs2.h linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/ocfs2.h
6415 --- linux-2.6.32/fs/ocfs2/ocfs2.h       2009-12-03 20:02:53.000000000 +0100
6416 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/ocfs2.h 2009-12-03 20:04:56.000000000 +0100
6417 @@ -248,6 +248,7 @@ enum ocfs2_mount_options
6418         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6419         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6420         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6421 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6422  };
6423  
6424  #define OCFS2_OSB_SOFT_RO                      0x0001
6425 diff -NurpP --minimal linux-2.6.32/fs/ocfs2/super.c linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/super.c
6426 --- linux-2.6.32/fs/ocfs2/super.c       2009-12-03 20:02:53.000000000 +0100
6427 +++ linux-2.6.32-vs2.3.0.36.26/fs/ocfs2/super.c 2009-12-03 20:04:56.000000000 +0100
6428 @@ -173,6 +173,7 @@ enum {
6429         Opt_noacl,
6430         Opt_usrquota,
6431         Opt_grpquota,
6432 +       Opt_tag, Opt_notag, Opt_tagid,
6433         Opt_err,
6434  };
6435  
6436 @@ -199,6 +200,9 @@ static const match_table_t tokens = {
6437         {Opt_noacl, "noacl"},
6438         {Opt_usrquota, "usrquota"},
6439         {Opt_grpquota, "grpquota"},
6440 +       {Opt_tag, "tag"},
6441 +       {Opt_notag, "notag"},
6442 +       {Opt_tagid, "tagid=%u"},
6443         {Opt_err, NULL}
6444  };
6445  
6446 @@ -605,6 +609,13 @@ static int ocfs2_remount(struct super_bl
6447                 goto out;
6448         }
6449  
6450 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6451 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6452 +               ret = -EINVAL;
6453 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6454 +               goto out;
6455 +       }
6456 +
6457         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6458             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6459                 ret = -EINVAL;
6460 @@ -1148,6 +1159,9 @@ static int ocfs2_fill_super(struct super
6461  
6462         ocfs2_complete_mount_recovery(osb);
6463  
6464 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6465 +               sb->s_flags |= MS_TAGGED;
6466 +
6467         if (ocfs2_mount_local(osb))
6468                 snprintf(nodestr, sizeof(nodestr), "local");
6469         else
6470 @@ -1426,6 +1440,20 @@ static int ocfs2_parse_options(struct su
6471                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6472                         break;
6473  #endif
6474 +#ifndef CONFIG_TAGGING_NONE
6475 +               case Opt_tag:
6476 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6477 +                       break;
6478 +               case Opt_notag:
6479 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6480 +                       break;
6481 +#endif
6482 +#ifdef CONFIG_PROPAGATE
6483 +               case Opt_tagid:
6484 +                       /* use args[0] */
6485 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6486 +                       break;
6487 +#endif
6488                 default:
6489                         mlog(ML_ERROR,
6490                              "Unrecognized mount option \"%s\" "
6491 diff -NurpP --minimal linux-2.6.32/fs/open.c linux-2.6.32-vs2.3.0.36.26/fs/open.c
6492 --- linux-2.6.32/fs/open.c      2009-12-03 20:02:53.000000000 +0100
6493 +++ linux-2.6.32-vs2.3.0.36.26/fs/open.c        2009-12-03 20:04:56.000000000 +0100
6494 @@ -30,22 +30,30 @@
6495  #include <linux/audit.h>
6496  #include <linux/falloc.h>
6497  #include <linux/fs_struct.h>
6498 +#include <linux/vs_base.h>
6499 +#include <linux/vs_limit.h>
6500 +#include <linux/vs_tag.h>
6501 +#include <linux/vs_cowbl.h>
6502  
6503  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6504  {
6505         int retval = -ENODEV;
6506  
6507         if (dentry) {
6508 +               struct super_block *sb = dentry->d_sb;
6509 +
6510                 retval = -ENOSYS;
6511 -               if (dentry->d_sb->s_op->statfs) {
6512 +               if (sb->s_op->statfs) {
6513                         memset(buf, 0, sizeof(*buf));
6514                         retval = security_sb_statfs(dentry);
6515                         if (retval)
6516                                 return retval;
6517 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6518 +                       retval = sb->s_op->statfs(dentry, buf);
6519                         if (retval == 0 && buf->f_frsize == 0)
6520                                 buf->f_frsize = buf->f_bsize;
6521                 }
6522 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6523 +                       vx_vsi_statfs(sb, buf);
6524         }
6525         return retval;
6526  }
6527 @@ -640,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6528         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6529         if (error)
6530                 goto out;
6531 +
6532 +       error = cow_check_and_break(&path);
6533 +       if (error)
6534 +               goto dput_and_out;
6535         inode = path.dentry->d_inode;
6536  
6537         error = mnt_want_write(path.mnt);
6538 @@ -673,11 +685,11 @@ static int chown_common(struct dentry * 
6539         newattrs.ia_valid =  ATTR_CTIME;
6540         if (user != (uid_t) -1) {
6541                 newattrs.ia_valid |= ATTR_UID;
6542 -               newattrs.ia_uid = user;
6543 +               newattrs.ia_uid = dx_map_uid(user);
6544         }
6545         if (group != (gid_t) -1) {
6546                 newattrs.ia_valid |= ATTR_GID;
6547 -               newattrs.ia_gid = group;
6548 +               newattrs.ia_gid = dx_map_gid(group);
6549         }
6550         if (!S_ISDIR(inode->i_mode))
6551                 newattrs.ia_valid |=
6552 @@ -700,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
6553         error = mnt_want_write(path.mnt);
6554         if (error)
6555                 goto out_release;
6556 -       error = chown_common(path.dentry, user, group);
6557 +#ifdef CONFIG_VSERVER_COWBL
6558 +       error = cow_check_and_break(&path);
6559 +       if (!error)
6560 +#endif
6561 +               error = chown_common(path.dentry, user, group);
6562         mnt_drop_write(path.mnt);
6563  out_release:
6564         path_put(&path);
6565 @@ -725,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6566         error = mnt_want_write(path.mnt);
6567         if (error)
6568                 goto out_release;
6569 -       error = chown_common(path.dentry, user, group);
6570 +#ifdef CONFIG_VSERVER_COWBL
6571 +       error = cow_check_and_break(&path);
6572 +       if (!error)
6573 +#endif
6574 +               error = chown_common(path.dentry, user, group);
6575         mnt_drop_write(path.mnt);
6576  out_release:
6577         path_put(&path);
6578 @@ -744,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6579         error = mnt_want_write(path.mnt);
6580         if (error)
6581                 goto out_release;
6582 -       error = chown_common(path.dentry, user, group);
6583 +#ifdef CONFIG_VSERVER_COWBL
6584 +       error = cow_check_and_break(&path);
6585 +       if (!error)
6586 +#endif
6587 +               error = chown_common(path.dentry, user, group);
6588         mnt_drop_write(path.mnt);
6589  out_release:
6590         path_put(&path);
6591 @@ -990,6 +1014,7 @@ static void __put_unused_fd(struct files
6592         __FD_CLR(fd, fdt->open_fds);
6593         if (fd < files->next_fd)
6594                 files->next_fd = fd;
6595 +       vx_openfd_dec(fd);
6596  }
6597  
6598  void put_unused_fd(unsigned int fd)
6599 diff -NurpP --minimal linux-2.6.32/fs/proc/array.c linux-2.6.32-vs2.3.0.36.26/fs/proc/array.c
6600 --- linux-2.6.32/fs/proc/array.c        2009-12-03 20:02:53.000000000 +0100
6601 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/array.c  2009-12-03 20:04:56.000000000 +0100
6602 @@ -83,6 +83,8 @@
6603  #include <linux/ptrace.h>
6604  #include <linux/tracehook.h>
6605  #include <linux/swapops.h>
6606 +#include <linux/vs_context.h>
6607 +#include <linux/vs_network.h>
6608  
6609  #include <asm/pgtable.h>
6610  #include <asm/processor.h>
6611 @@ -139,8 +141,9 @@ static const char *task_state_array[] = 
6612         "D (disk sleep)",       /*  2 */
6613         "T (stopped)",          /*  4 */
6614         "T (tracing stop)",     /*  8 */
6615 -       "Z (zombie)",           /* 16 */
6616 -       "X (dead)"              /* 32 */
6617 +       "H (on hold)",          /* 16 */
6618 +       "Z (zombie)",           /* 32 */
6619 +       "X (dead)",             /* 64 */
6620  };
6621  
6622  static inline const char *get_task_state(struct task_struct *tsk)
6623 @@ -167,6 +170,9 @@ static inline void task_state(struct seq
6624         rcu_read_lock();
6625         ppid = pid_alive(p) ?
6626                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6627 +       if (unlikely(vx_current_initpid(p->pid)))
6628 +               ppid = 0;
6629 +
6630         tpid = 0;
6631         if (pid_alive(p)) {
6632                 struct task_struct *tracer = tracehook_tracer_task(p);
6633 @@ -282,7 +288,7 @@ static inline void task_sig(struct seq_f
6634  }
6635  
6636  static void render_cap_t(struct seq_file *m, const char *header,
6637 -                       kernel_cap_t *a)
6638 +                       struct vx_info *vxi, kernel_cap_t *a)
6639  {
6640         unsigned __capi;
6641  
6642 @@ -307,10 +313,11 @@ static inline void task_cap(struct seq_f
6643         cap_bset        = cred->cap_bset;
6644         rcu_read_unlock();
6645  
6646 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6647 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6648 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6649 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6650 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6651 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6652 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6653 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6654 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6655  }
6656  
6657  static inline void task_context_switch_counts(struct seq_file *m,
6658 @@ -410,6 +417,42 @@ static void task_show_stack_usage(struct
6659  }
6660  #endif         /* CONFIG_MMU */
6661  
6662 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6663 +                       struct pid *pid, struct task_struct *task)
6664 +{
6665 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6666 +                       "Count:\t%u\n"
6667 +                       "uts:\t%p(%c)\n"
6668 +                       "ipc:\t%p(%c)\n"
6669 +                       "mnt:\t%p(%c)\n"
6670 +                       "pid:\t%p(%c)\n"
6671 +                       "net:\t%p(%c)\n",
6672 +                       task->nsproxy,
6673 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6674 +                       atomic_read(&task->nsproxy->count),
6675 +                       task->nsproxy->uts_ns,
6676 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6677 +                       task->nsproxy->ipc_ns,
6678 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6679 +                       task->nsproxy->mnt_ns,
6680 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6681 +                       task->nsproxy->pid_ns,
6682 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6683 +                       task->nsproxy->net_ns,
6684 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6685 +       return 0;
6686 +}
6687 +
6688 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6689 +{
6690 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6691 +               return;
6692 +
6693 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6694 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6695 +}
6696 +
6697 +
6698  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6699                         struct pid *pid, struct task_struct *task)
6700  {
6701 @@ -425,6 +468,7 @@ int proc_pid_status(struct seq_file *m, 
6702         task_sig(m, task);
6703         task_cap(m, task);
6704         cpuset_task_status_allowed(m, task);
6705 +       task_vs_id(m, task);
6706  #if defined(CONFIG_S390)
6707         task_show_regs(m, task);
6708  #endif
6709 @@ -542,6 +586,17 @@ static int do_task_stat(struct seq_file 
6710         /* convert nsec -> ticks */
6711         start_time = nsec_to_clock_t(start_time);
6712  
6713 +       /* fixup start time for virt uptime */
6714 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6715 +               unsigned long long bias =
6716 +                       current->vx_info->cvirt.bias_clock;
6717 +
6718 +               if (start_time > bias)
6719 +                       start_time -= bias;
6720 +               else
6721 +                       start_time = 0;
6722 +       }
6723 +
6724         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6725  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6726  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6727 diff -NurpP --minimal linux-2.6.32/fs/proc/base.c linux-2.6.32-vs2.3.0.36.26/fs/proc/base.c
6728 --- linux-2.6.32/fs/proc/base.c 2009-12-03 20:02:53.000000000 +0100
6729 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/base.c   2009-12-03 20:04:56.000000000 +0100
6730 @@ -81,6 +81,8 @@
6731  #include <linux/elf.h>
6732  #include <linux/pid_namespace.h>
6733  #include <linux/fs_struct.h>
6734 +#include <linux/vs_context.h>
6735 +#include <linux/vs_network.h>
6736  #include "internal.h"
6737  
6738  /* NOTE:
6739 @@ -1047,12 +1049,17 @@ static ssize_t oom_adjust_write(struct f
6740                 return -ESRCH;
6741         }
6742  
6743 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6744 +       if (oom_adjust < task->signal->oom_adj &&
6745 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6746                 unlock_task_sighand(task, &flags);
6747                 put_task_struct(task);
6748                 return -EACCES;
6749         }
6750  
6751 +       /* prevent guest processes from circumventing the oom killer */
6752 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6753 +               oom_adjust = OOM_ADJUST_MIN;
6754 +
6755         task->signal->oom_adj = oom_adjust;
6756  
6757         unlock_task_sighand(task, &flags);
6758 @@ -1092,7 +1099,7 @@ static ssize_t proc_loginuid_write(struc
6759         ssize_t length;
6760         uid_t loginuid;
6761  
6762 -       if (!capable(CAP_AUDIT_CONTROL))
6763 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6764                 return -EPERM;
6765  
6766         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6767 @@ -1458,6 +1465,8 @@ static struct inode *proc_pid_make_inode
6768                 inode->i_gid = cred->egid;
6769                 rcu_read_unlock();
6770         }
6771 +       /* procfs is xid tagged */
6772 +       inode->i_tag = (tag_t)vx_task_xid(task);
6773         security_task_to_inode(task, inode);
6774  
6775  out:
6776 @@ -2008,6 +2017,13 @@ static struct dentry *proc_pident_lookup
6777         if (!task)
6778                 goto out_no_task;
6779  
6780 +       /* TODO: maybe we can come up with a generic approach? */
6781 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6782 +               (dentry->d_name.len == 5) &&
6783 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6784 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6785 +               goto out;
6786 +
6787         /*
6788          * Yes, it does not scale. And it should not. Don't add
6789          * new entries into /proc/<tgid>/ without very good reasons.
6790 @@ -2399,7 +2415,7 @@ out_iput:
6791  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6792  {
6793         struct dentry *error;
6794 -       struct task_struct *task = get_proc_task(dir);
6795 +       struct task_struct *task = get_proc_task_real(dir);
6796         const struct pid_entry *p, *last;
6797  
6798         error = ERR_PTR(-ENOENT);
6799 @@ -2489,6 +2505,9 @@ static int proc_pid_personality(struct s
6800  static const struct file_operations proc_task_operations;
6801  static const struct inode_operations proc_task_inode_operations;
6802  
6803 +extern int proc_pid_vx_info(struct task_struct *, char *);
6804 +extern int proc_pid_nx_info(struct task_struct *, char *);
6805 +
6806  static const struct pid_entry tgid_base_stuff[] = {
6807         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6808         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6809 @@ -2547,6 +2566,8 @@ static const struct pid_entry tgid_base_
6810  #ifdef CONFIG_CGROUPS
6811         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6812  #endif
6813 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6814 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6815         INF("oom_score",  S_IRUGO, proc_oom_score),
6816         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6817  #ifdef CONFIG_AUDITSYSCALL
6818 @@ -2562,6 +2583,7 @@ static const struct pid_entry tgid_base_
6819  #ifdef CONFIG_TASK_IO_ACCOUNTING
6820         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6821  #endif
6822 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6823  };
6824  
6825  static int proc_tgid_base_readdir(struct file * filp,
6826 @@ -2753,7 +2775,7 @@ retry:
6827         iter.task = NULL;
6828         pid = find_ge_pid(iter.tgid, ns);
6829         if (pid) {
6830 -               iter.tgid = pid_nr_ns(pid, ns);
6831 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6832                 iter.task = pid_task(pid, PIDTYPE_PID);
6833                 /* What we to know is if the pid we have find is the
6834                  * pid of a thread_group_leader.  Testing for task
6835 @@ -2783,7 +2805,7 @@ static int proc_pid_fill_cache(struct fi
6836         struct tgid_iter iter)
6837  {
6838         char name[PROC_NUMBUF];
6839 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6840 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6841         return proc_fill_cache(filp, dirent, filldir, name, len,
6842                                 proc_pid_instantiate, iter.task, NULL);
6843  }
6844 @@ -2792,7 +2814,7 @@ static int proc_pid_fill_cache(struct fi
6845  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6846  {
6847         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6848 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6849 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6850         struct tgid_iter iter;
6851         struct pid_namespace *ns;
6852  
6853 @@ -2812,6 +2834,8 @@ int proc_pid_readdir(struct file * filp,
6854              iter.task;
6855              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6856                 filp->f_pos = iter.tgid + TGID_OFFSET;
6857 +               if (!vx_proc_task_visible(iter.task))
6858 +                       continue;
6859                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6860                         put_task_struct(iter.task);
6861                         goto out;
6862 @@ -2958,6 +2982,8 @@ static struct dentry *proc_task_lookup(s
6863         tid = name_to_int(dentry);
6864         if (tid == ~0U)
6865                 goto out;
6866 +       if (vx_current_initpid(tid))
6867 +               goto out;
6868  
6869         ns = dentry->d_sb->s_fs_info;
6870         rcu_read_lock();
6871 diff -NurpP --minimal linux-2.6.32/fs/proc/generic.c linux-2.6.32-vs2.3.0.36.26/fs/proc/generic.c
6872 --- linux-2.6.32/fs/proc/generic.c      2009-06-11 17:13:07.000000000 +0200
6873 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/generic.c        2009-12-03 20:04:56.000000000 +0100
6874 @@ -20,6 +20,7 @@
6875  #include <linux/bitops.h>
6876  #include <linux/spinlock.h>
6877  #include <linux/completion.h>
6878 +#include <linux/vserver/inode.h>
6879  #include <asm/uaccess.h>
6880  
6881  #include "internal.h"
6882 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6883         for (de = de->subdir; de ; de = de->next) {
6884                 if (de->namelen != dentry->d_name.len)
6885                         continue;
6886 +                       if (!vx_hide_check(0, de->vx_flags))
6887 +                               continue;
6888                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6889                         unsigned int ino;
6890  
6891 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6892                         spin_unlock(&proc_subdir_lock);
6893                         error = -EINVAL;
6894                         inode = proc_get_inode(dir->i_sb, ino, de);
6895 +                               /* generic proc entries belong to the host */
6896 +                               inode->i_tag = 0;
6897                         goto out_unlock;
6898                 }
6899         }
6900 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6901  
6902                                 /* filldir passes info to user space */
6903                                 de_get(de);
6904 +                               if (!vx_hide_check(0, de->vx_flags))
6905 +                                       goto skip;
6906                                 spin_unlock(&proc_subdir_lock);
6907                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6908                                             de->low_ino, de->mode >> 12) < 0) {
6909 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6910                                         goto out;
6911                                 }
6912                                 spin_lock(&proc_subdir_lock);
6913 +                       skip:
6914                                 filp->f_pos++;
6915                                 next = de->next;
6916                                 de_put(de);
6917 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
6918         ent->nlink = nlink;
6919         atomic_set(&ent->count, 1);
6920         ent->pde_users = 0;
6921 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6922         spin_lock_init(&ent->pde_unload_lock);
6923         ent->pde_unload_completion = NULL;
6924         INIT_LIST_HEAD(&ent->pde_openers);
6925 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
6926                                 kfree(ent->data);
6927                                 kfree(ent);
6928                                 ent = NULL;
6929 -                       }
6930 +                       } else
6931 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6932                 } else {
6933                         kfree(ent);
6934                         ent = NULL;
6935 diff -NurpP --minimal linux-2.6.32/fs/proc/inode.c linux-2.6.32-vs2.3.0.36.26/fs/proc/inode.c
6936 --- linux-2.6.32/fs/proc/inode.c        2009-06-11 17:13:07.000000000 +0200
6937 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/inode.c  2009-12-03 20:04:56.000000000 +0100
6938 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
6939                         inode->i_uid = de->uid;
6940                         inode->i_gid = de->gid;
6941                 }
6942 +               if (de->vx_flags)
6943 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6944                 if (de->size)
6945                         inode->i_size = de->size;
6946                 if (de->nlink)
6947 diff -NurpP --minimal linux-2.6.32/fs/proc/internal.h linux-2.6.32-vs2.3.0.36.26/fs/proc/internal.h
6948 --- linux-2.6.32/fs/proc/internal.h     2009-09-10 15:26:23.000000000 +0200
6949 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/internal.h       2009-12-03 20:04:56.000000000 +0100
6950 @@ -10,6 +10,7 @@
6951   */
6952  
6953  #include <linux/proc_fs.h>
6954 +#include <linux/vs_pid.h>
6955  
6956  extern struct proc_dir_entry proc_root;
6957  #ifdef CONFIG_PROC_SYSCTL
6958 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6959                                 struct pid *pid, struct task_struct *task);
6960  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6961                                 struct pid *pid, struct task_struct *task);
6962 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6963 +                               struct pid *pid, struct task_struct *task);
6964 +
6965  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6966  
6967  extern const struct file_operations proc_maps_operations;
6968 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
6969         return PROC_I(inode)->pid;
6970  }
6971  
6972 -static inline struct task_struct *get_proc_task(struct inode *inode)
6973 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6974  {
6975         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6976  }
6977  
6978 +static inline struct task_struct *get_proc_task(struct inode *inode)
6979 +{
6980 +       return vx_get_proc_task(inode, proc_pid(inode));
6981 +}
6982 +
6983  static inline int proc_fd(struct inode *inode)
6984  {
6985         return PROC_I(inode)->fd;
6986 diff -NurpP --minimal linux-2.6.32/fs/proc/loadavg.c linux-2.6.32-vs2.3.0.36.26/fs/proc/loadavg.c
6987 --- linux-2.6.32/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
6988 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/loadavg.c        2009-12-03 20:04:56.000000000 +0100
6989 @@ -12,15 +12,27 @@
6990  
6991  static int loadavg_proc_show(struct seq_file *m, void *v)
6992  {
6993 +       unsigned long running;
6994 +       unsigned int threads;
6995         unsigned long avnrun[3];
6996  
6997         get_avenrun(avnrun, FIXED_1/200, 0);
6998  
6999 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7000 +               struct vx_info *vxi = current_vx_info();
7001 +
7002 +               running = atomic_read(&vxi->cvirt.nr_running);
7003 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7004 +       } else {
7005 +               running = nr_running();
7006 +               threads = nr_threads;
7007 +       }
7008 +
7009         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7010                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7011                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7012                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7013 -               nr_running(), nr_threads,
7014 +               running, threads,
7015                 task_active_pid_ns(current)->last_pid);
7016         return 0;
7017  }
7018 diff -NurpP --minimal linux-2.6.32/fs/proc/meminfo.c linux-2.6.32-vs2.3.0.36.26/fs/proc/meminfo.c
7019 --- linux-2.6.32/fs/proc/meminfo.c      2009-12-03 20:02:53.000000000 +0100
7020 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/meminfo.c        2009-12-03 20:04:56.000000000 +0100
7021 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
7022  
7023         cached = global_page_state(NR_FILE_PAGES) -
7024                         total_swapcache_pages - i.bufferram;
7025 -       if (cached < 0)
7026 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7027                 cached = 0;
7028  
7029         get_vmalloc_info(&vmi);
7030 diff -NurpP --minimal linux-2.6.32/fs/proc/root.c linux-2.6.32-vs2.3.0.36.26/fs/proc/root.c
7031 --- linux-2.6.32/fs/proc/root.c 2009-06-11 17:13:07.000000000 +0200
7032 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/root.c   2009-12-03 20:04:56.000000000 +0100
7033 @@ -18,9 +18,14 @@
7034  #include <linux/bitops.h>
7035  #include <linux/mount.h>
7036  #include <linux/pid_namespace.h>
7037 +#include <linux/vserver/inode.h>
7038  
7039  #include "internal.h"
7040  
7041 +struct proc_dir_entry *proc_virtual;
7042 +
7043 +extern void proc_vx_init(void);
7044 +
7045  static int proc_test_super(struct super_block *sb, void *data)
7046  {
7047         return sb->s_fs_info == data;
7048 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7049  #endif
7050         proc_mkdir("bus", NULL);
7051         proc_sys_init();
7052 +       proc_vx_init();
7053  }
7054  
7055  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7056 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7057         .proc_iops      = &proc_root_inode_operations, 
7058         .proc_fops      = &proc_root_operations,
7059         .parent         = &proc_root,
7060 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7061  };
7062  
7063  int pid_ns_prepare_proc(struct pid_namespace *ns)
7064 diff -NurpP --minimal linux-2.6.32/fs/proc/uptime.c linux-2.6.32-vs2.3.0.36.26/fs/proc/uptime.c
7065 --- linux-2.6.32/fs/proc/uptime.c       2009-12-03 20:02:53.000000000 +0100
7066 +++ linux-2.6.32-vs2.3.0.36.26/fs/proc/uptime.c 2009-12-03 20:04:56.000000000 +0100
7067 @@ -4,22 +4,22 @@
7068  #include <linux/sched.h>
7069  #include <linux/seq_file.h>
7070  #include <linux/time.h>
7071 -#include <linux/kernel_stat.h>
7072 +#include <linux/vserver/cvirt.h>
7073  #include <asm/cputime.h>
7074  
7075  static int uptime_proc_show(struct seq_file *m, void *v)
7076  {
7077         struct timespec uptime;
7078         struct timespec idle;
7079 -       int i;
7080 -       cputime_t idletime = cputime_zero;
7081 -
7082 -       for_each_possible_cpu(i)
7083 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7084 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7085  
7086         do_posix_clock_monotonic_gettime(&uptime);
7087         monotonic_to_bootbased(&uptime);
7088         cputime_to_timespec(idletime, &idle);
7089 +
7090 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7091 +               vx_vsi_uptime(&uptime, &idle);
7092 +
7093         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7094                         (unsigned long) uptime.tv_sec,
7095                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7096 diff -NurpP --minimal linux-2.6.32/fs/quota/quota.c linux-2.6.32-vs2.3.0.36.26/fs/quota/quota.c
7097 --- linux-2.6.32/fs/quota/quota.c       2009-09-10 15:26:24.000000000 +0200
7098 +++ linux-2.6.32-vs2.3.0.36.26/fs/quota/quota.c 2009-12-03 20:04:56.000000000 +0100
7099 @@ -18,6 +18,7 @@
7100  #include <linux/capability.h>
7101  #include <linux/quotaops.h>
7102  #include <linux/types.h>
7103 +#include <linux/vs_context.h>
7104  
7105  /* Check validity of generic quotactl commands */
7106  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
7107 @@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
7108         if (cmd == Q_GETQUOTA) {
7109                 if (((type == USRQUOTA && current_euid() != id) ||
7110                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7111 -                   !capable(CAP_SYS_ADMIN))
7112 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7113                         return -EPERM;
7114         }
7115         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7116 -               if (!capable(CAP_SYS_ADMIN))
7117 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7118                         return -EPERM;
7119  
7120         return 0;
7121 @@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
7122         if (cmd == Q_XGETQUOTA) {
7123                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7124                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7125 -                    !capable(CAP_SYS_ADMIN))
7126 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7127                         return -EPERM;
7128         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7129 -               if (!capable(CAP_SYS_ADMIN))
7130 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7131                         return -EPERM;
7132         }
7133  
7134 @@ -351,6 +352,46 @@ static int do_quotactl(struct super_bloc
7135         return 0;
7136  }
7137  
7138 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7139 +
7140 +#include <linux/vroot.h>
7141 +#include <linux/major.h>
7142 +#include <linux/module.h>
7143 +#include <linux/kallsyms.h>
7144 +#include <linux/vserver/debug.h>
7145 +
7146 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7147 +
7148 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7149 +
7150 +int register_vroot_grb(vroot_grb_func *func) {
7151 +       int ret = -EBUSY;
7152 +
7153 +       spin_lock(&vroot_grb_lock);
7154 +       if (!vroot_get_real_bdev) {
7155 +               vroot_get_real_bdev = func;
7156 +               ret = 0;
7157 +       }
7158 +       spin_unlock(&vroot_grb_lock);
7159 +       return ret;
7160 +}
7161 +EXPORT_SYMBOL(register_vroot_grb);
7162 +
7163 +int unregister_vroot_grb(vroot_grb_func *func) {
7164 +       int ret = -EINVAL;
7165 +
7166 +       spin_lock(&vroot_grb_lock);
7167 +       if (vroot_get_real_bdev) {
7168 +               vroot_get_real_bdev = NULL;
7169 +               ret = 0;
7170 +       }
7171 +       spin_unlock(&vroot_grb_lock);
7172 +       return ret;
7173 +}
7174 +EXPORT_SYMBOL(unregister_vroot_grb);
7175 +
7176 +#endif
7177 +
7178  /*
7179   * look up a superblock on which quota ops will be performed
7180   * - use the name of a block device to find the superblock thereon
7181 @@ -368,6 +409,22 @@ static struct super_block *quotactl_bloc
7182         putname(tmp);
7183         if (IS_ERR(bdev))
7184                 return ERR_CAST(bdev);
7185 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7186 +       if (bdev && bdev->bd_inode &&
7187 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7188 +               struct block_device *bdnew = (void *)-EINVAL;
7189 +
7190 +               if (vroot_get_real_bdev)
7191 +                       bdnew = vroot_get_real_bdev(bdev);
7192 +               else
7193 +                       vxdprintk(VXD_CBIT(misc, 0),
7194 +                                       "vroot_get_real_bdev not set");
7195 +               bdput(bdev);
7196 +               if (IS_ERR(bdnew))
7197 +                       return ERR_PTR(PTR_ERR(bdnew));
7198 +               bdev = bdnew;
7199 +       }
7200 +#endif
7201         sb = get_super(bdev);
7202         bdput(bdev);
7203         if (!sb)
7204 diff -NurpP --minimal linux-2.6.32/fs/reiserfs/file.c linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/file.c
7205 --- linux-2.6.32/fs/reiserfs/file.c     2009-06-11 17:13:08.000000000 +0200
7206 +++ linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/file.c       2009-12-03 20:04:56.000000000 +0100
7207 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7208         .listxattr = reiserfs_listxattr,
7209         .removexattr = reiserfs_removexattr,
7210         .permission = reiserfs_permission,
7211 +       .sync_flags = reiserfs_sync_flags,
7212  };
7213 diff -NurpP --minimal linux-2.6.32/fs/reiserfs/inode.c linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/inode.c
7214 --- linux-2.6.32/fs/reiserfs/inode.c    2009-09-10 15:26:24.000000000 +0200
7215 +++ linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/inode.c      2009-12-03 20:04:56.000000000 +0100
7216 @@ -18,6 +18,7 @@
7217  #include <linux/writeback.h>
7218  #include <linux/quotaops.h>
7219  #include <linux/swap.h>
7220 +#include <linux/vs_tag.h>
7221  
7222  int reiserfs_commit_write(struct file *f, struct page *page,
7223                           unsigned from, unsigned to);
7224 @@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
7225         struct buffer_head *bh;
7226         struct item_head *ih;
7227         __u32 rdev;
7228 +       uid_t uid;
7229 +       gid_t gid;
7230         //int version = ITEM_VERSION_1;
7231  
7232         bh = PATH_PLAST_BUFFER(path);
7233 @@ -1138,12 +1141,13 @@ static void init_inode(struct inode *ino
7234                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7235                 unsigned long blocks;
7236  
7237 +               uid = sd_v1_uid(sd);
7238 +               gid = sd_v1_gid(sd);
7239 +
7240                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7241                 set_inode_sd_version(inode, STAT_DATA_V1);
7242                 inode->i_mode = sd_v1_mode(sd);
7243                 inode->i_nlink = sd_v1_nlink(sd);
7244 -               inode->i_uid = sd_v1_uid(sd);
7245 -               inode->i_gid = sd_v1_gid(sd);
7246                 inode->i_size = sd_v1_size(sd);
7247                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7248                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7249 @@ -1185,11 +1189,12 @@ static void init_inode(struct inode *ino
7250                 // (directories and symlinks)
7251                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7252  
7253 +               uid    = sd_v2_uid(sd);
7254 +               gid    = sd_v2_gid(sd);
7255 +
7256                 inode->i_mode = sd_v2_mode(sd);
7257                 inode->i_nlink = sd_v2_nlink(sd);
7258 -               inode->i_uid = sd_v2_uid(sd);
7259                 inode->i_size = sd_v2_size(sd);
7260 -               inode->i_gid = sd_v2_gid(sd);
7261                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7262                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7263                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7264 @@ -1219,6 +1224,10 @@ static void init_inode(struct inode *ino
7265                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7266         }
7267  
7268 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7269 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7270 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7271 +
7272         pathrelse(path);
7273         if (S_ISREG(inode->i_mode)) {
7274                 inode->i_op = &reiserfs_file_inode_operations;
7275 @@ -1241,13 +1250,15 @@ static void init_inode(struct inode *ino
7276  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7277  {
7278         struct stat_data *sd_v2 = (struct stat_data *)sd;
7279 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7280 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7281         __u16 flags;
7282  
7283 +       set_sd_v2_uid(sd_v2, uid);
7284 +       set_sd_v2_gid(sd_v2, gid);
7285         set_sd_v2_mode(sd_v2, inode->i_mode);
7286         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7287 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7288         set_sd_v2_size(sd_v2, size);
7289 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7290         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7291         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7292         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7293 @@ -2828,14 +2839,19 @@ int reiserfs_commit_write(struct file *f
7294  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7295  {
7296         if (reiserfs_attrs(inode->i_sb)) {
7297 -               if (sd_attrs & REISERFS_SYNC_FL)
7298 -                       inode->i_flags |= S_SYNC;
7299 -               else
7300 -                       inode->i_flags &= ~S_SYNC;
7301                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7302                         inode->i_flags |= S_IMMUTABLE;
7303                 else
7304                         inode->i_flags &= ~S_IMMUTABLE;
7305 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7306 +                       inode->i_flags |= S_IXUNLINK;
7307 +               else
7308 +                       inode->i_flags &= ~S_IXUNLINK;
7309 +
7310 +               if (sd_attrs & REISERFS_SYNC_FL)
7311 +                       inode->i_flags |= S_SYNC;
7312 +               else
7313 +                       inode->i_flags &= ~S_SYNC;
7314                 if (sd_attrs & REISERFS_APPEND_FL)
7315                         inode->i_flags |= S_APPEND;
7316                 else
7317 @@ -2848,6 +2864,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7318                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7319                 else
7320                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7321 +
7322 +               if (sd_attrs & REISERFS_BARRIER_FL)
7323 +                       inode->i_vflags |= V_BARRIER;
7324 +               else
7325 +                       inode->i_vflags &= ~V_BARRIER;
7326 +               if (sd_attrs & REISERFS_COW_FL)
7327 +                       inode->i_vflags |= V_COW;
7328 +               else
7329 +                       inode->i_vflags &= ~V_COW;
7330         }
7331  }
7332  
7333 @@ -2858,6 +2883,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7334                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7335                 else
7336                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7337 +               if (inode->i_flags & S_IXUNLINK)
7338 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7339 +               else
7340 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7341 +
7342                 if (inode->i_flags & S_SYNC)
7343                         *sd_attrs |= REISERFS_SYNC_FL;
7344                 else
7345 @@ -2870,6 +2900,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7346                         *sd_attrs |= REISERFS_NOTAIL_FL;
7347                 else
7348                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7349 +
7350 +               if (inode->i_vflags & V_BARRIER)
7351 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7352 +               else
7353 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7354 +               if (inode->i_vflags & V_COW)
7355 +                       *sd_attrs |= REISERFS_COW_FL;
7356 +               else
7357 +                       *sd_attrs &= ~REISERFS_COW_FL;
7358         }
7359  }
7360  
7361 @@ -3090,9 +3129,11 @@ int reiserfs_setattr(struct dentry *dent
7362         }
7363  
7364         error = inode_change_ok(inode, attr);
7365 +
7366         if (!error) {
7367                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7368 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7369 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7370 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7371                         error = reiserfs_chown_xattrs(inode, attr);
7372  
7373                         if (!error) {
7374 @@ -3122,6 +3163,9 @@ int reiserfs_setattr(struct dentry *dent
7375                                         inode->i_uid = attr->ia_uid;
7376                                 if (attr->ia_valid & ATTR_GID)
7377                                         inode->i_gid = attr->ia_gid;
7378 +                               if ((attr->ia_valid & ATTR_TAG) &&
7379 +                                       IS_TAGGED(inode))
7380 +                                       inode->i_tag = attr->ia_tag;
7381                                 mark_inode_dirty(inode);
7382                                 error =
7383                                     journal_end(&th, inode->i_sb, jbegin_count);
7384 diff -NurpP --minimal linux-2.6.32/fs/reiserfs/ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/ioctl.c
7385 --- linux-2.6.32/fs/reiserfs/ioctl.c    2009-06-11 17:13:08.000000000 +0200
7386 +++ linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/ioctl.c      2009-12-03 20:04:56.000000000 +0100
7387 @@ -7,11 +7,27 @@
7388  #include <linux/mount.h>
7389  #include <linux/reiserfs_fs.h>
7390  #include <linux/time.h>
7391 +#include <linux/mount.h>
7392  #include <asm/uaccess.h>
7393  #include <linux/pagemap.h>
7394  #include <linux/smp_lock.h>
7395  #include <linux/compat.h>
7396  
7397 +
7398 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7399 +{
7400 +       __u16 sd_attrs = 0;
7401 +
7402 +       inode->i_flags = flags;
7403 +       inode->i_vflags = vflags;
7404 +
7405 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7406 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7407 +       inode->i_ctime = CURRENT_TIME_SEC;
7408 +       mark_inode_dirty(inode);
7409 +       return 0;
7410 +}
7411 +
7412  /*
7413  ** reiserfs_ioctl - handler for ioctl for inode
7414  ** supported commands:
7415 @@ -23,7 +39,7 @@
7416  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7417                    unsigned long arg)
7418  {
7419 -       unsigned int flags;
7420 +       unsigned int flags, oldflags;
7421         int err = 0;
7422  
7423         switch (cmd) {
7424 @@ -43,6 +59,7 @@ int reiserfs_ioctl(struct inode *inode, 
7425  
7426                 flags = REISERFS_I(inode)->i_attrs;
7427                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7428 +               flags &= REISERFS_FL_USER_VISIBLE;
7429                 return put_user(flags, (int __user *)arg);
7430         case REISERFS_IOC_SETFLAGS:{
7431                         if (!reiserfs_attrs(inode->i_sb))
7432 @@ -60,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
7433                                 err = -EFAULT;
7434                                 goto setflags_out;
7435                         }
7436 +                       if (IS_BARRIER(inode)) {
7437 +                               vxwprintk_task(1, "messing with the barrier.");
7438 +                               return -EACCES;
7439 +                       }
7440                         /*
7441                          * Is it quota file? Do not allow user to mess with it
7442                          */
7443 @@ -84,6 +105,10 @@ int reiserfs_ioctl(struct inode *inode, 
7444                                         goto setflags_out;
7445                                 }
7446                         }
7447 +
7448 +                       oldflags = REISERFS_I(inode)->i_attrs;
7449 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7450 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7451                         sd_attrs_to_i_attrs(flags, inode);
7452                         REISERFS_I(inode)->i_attrs = flags;
7453                         inode->i_ctime = CURRENT_TIME_SEC;
7454 diff -NurpP --minimal linux-2.6.32/fs/reiserfs/namei.c linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/namei.c
7455 --- linux-2.6.32/fs/reiserfs/namei.c    2009-06-11 17:13:08.000000000 +0200
7456 +++ linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/namei.c      2009-12-03 20:04:56.000000000 +0100
7457 @@ -17,6 +17,7 @@
7458  #include <linux/reiserfs_acl.h>
7459  #include <linux/reiserfs_xattr.h>
7460  #include <linux/quotaops.h>
7461 +#include <linux/vs_tag.h>
7462  
7463  #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; }
7464  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7465 @@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
7466         if (retval == IO_ERROR) {
7467                 return ERR_PTR(-EIO);
7468         }
7469 +               dx_propagate_tag(nd, inode);
7470  
7471         return d_splice_alias(inode, dentry);
7472  }
7473 @@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
7474         } else {
7475                 inode->i_gid = current_fsgid();
7476         }
7477 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7478         vfs_dq_init(inode);
7479         return 0;
7480  }
7481 @@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
7482         .listxattr = reiserfs_listxattr,
7483         .removexattr = reiserfs_removexattr,
7484         .permission = reiserfs_permission,
7485 +       .sync_flags = reiserfs_sync_flags,
7486  };
7487  
7488  /*
7489 diff -NurpP --minimal linux-2.6.32/fs/reiserfs/super.c linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/super.c
7490 --- linux-2.6.32/fs/reiserfs/super.c    2009-12-03 20:02:53.000000000 +0100
7491 +++ linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/super.c      2009-12-03 20:04:56.000000000 +0100
7492 @@ -884,6 +884,14 @@ static int reiserfs_parse_options(struct
7493                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7494                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7495  #endif
7496 +#ifndef CONFIG_TAGGING_NONE
7497 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7498 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7499 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7500 +#endif
7501 +#ifdef CONFIG_PROPAGATE
7502 +               {"tag",.arg_required = 'T',.values = NULL},
7503 +#endif
7504  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7505                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7506                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7507 @@ -1190,6 +1198,14 @@ static int reiserfs_remount(struct super
7508         handle_quota_files(s, qf_names, &qfmt);
7509  #endif
7510  
7511 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7512 +               !(s->s_flags & MS_TAGGED)) {
7513 +               reiserfs_warning(s, "super-vs01",
7514 +                       "reiserfs: tagging not permitted on remount.");
7515 +               err = -EINVAL;
7516 +               goto out_err;
7517 +       }
7518 +
7519         handle_attrs(s);
7520  
7521         /* Add options that are safe here */
7522 @@ -1652,6 +1668,10 @@ static int reiserfs_fill_super(struct su
7523                 goto error;
7524         }
7525  
7526 +       /* map mount option tagxid */
7527 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7528 +               s->s_flags |= MS_TAGGED;
7529 +
7530         rs = SB_DISK_SUPER_BLOCK(s);
7531         /* Let's do basic sanity check to verify that underlying device is not
7532            smaller than the filesystem. If the check fails then abort and scream,
7533 diff -NurpP --minimal linux-2.6.32/fs/reiserfs/xattr.c linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/xattr.c
7534 --- linux-2.6.32/fs/reiserfs/xattr.c    2009-09-10 15:26:24.000000000 +0200
7535 +++ linux-2.6.32-vs2.3.0.36.26/fs/reiserfs/xattr.c      2009-12-03 20:04:56.000000000 +0100
7536 @@ -39,6 +39,7 @@
7537  #include <linux/namei.h>
7538  #include <linux/errno.h>
7539  #include <linux/fs.h>
7540 +#include <linux/mount.h>
7541  #include <linux/file.h>
7542  #include <linux/pagemap.h>
7543  #include <linux/xattr.h>
7544 diff -NurpP --minimal linux-2.6.32/fs/stat.c linux-2.6.32-vs2.3.0.36.26/fs/stat.c
7545 --- linux-2.6.32/fs/stat.c      2009-06-11 17:13:08.000000000 +0200
7546 +++ linux-2.6.32-vs2.3.0.36.26/fs/stat.c        2009-12-03 20:04:56.000000000 +0100
7547 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7548         stat->nlink = inode->i_nlink;
7549         stat->uid = inode->i_uid;
7550         stat->gid = inode->i_gid;
7551 +       stat->tag = inode->i_tag;
7552         stat->rdev = inode->i_rdev;
7553         stat->atime = inode->i_atime;
7554         stat->mtime = inode->i_mtime;
7555 diff -NurpP --minimal linux-2.6.32/fs/super.c linux-2.6.32-vs2.3.0.36.26/fs/super.c
7556 --- linux-2.6.32/fs/super.c     2009-12-03 20:02:53.000000000 +0100
7557 +++ linux-2.6.32-vs2.3.0.36.26/fs/super.c       2009-12-03 20:04:56.000000000 +0100
7558 @@ -37,6 +37,9 @@
7559  #include <linux/kobject.h>
7560  #include <linux/mutex.h>
7561  #include <linux/file.h>
7562 +#include <linux/devpts_fs.h>
7563 +#include <linux/proc_fs.h>
7564 +#include <linux/vs_context.h>
7565  #include <asm/uaccess.h>
7566  #include "internal.h"
7567  
7568 @@ -913,12 +916,18 @@ struct vfsmount *
7569  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7570  {
7571         struct vfsmount *mnt;
7572 +       struct super_block *sb;
7573         char *secdata = NULL;
7574         int error;
7575  
7576         if (!type)
7577                 return ERR_PTR(-ENODEV);
7578  
7579 +       error = -EPERM;
7580 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7581 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7582 +               goto out;
7583 +
7584         error = -ENOMEM;
7585         mnt = alloc_vfsmnt(name);
7586         if (!mnt)
7587 @@ -937,9 +946,17 @@ vfs_kern_mount(struct file_system_type *
7588         error = type->get_sb(type, flags, name, data, mnt);
7589         if (error < 0)
7590                 goto out_free_secdata;
7591 -       BUG_ON(!mnt->mnt_sb);
7592  
7593 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7594 +       sb = mnt->mnt_sb;
7595 +       BUG_ON(!sb);
7596 +
7597 +       error = -EPERM;
7598 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7599 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7600 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7601 +               goto out_sb;
7602 +
7603 +       error = security_sb_kern_mount(sb, flags, secdata);
7604         if (error)
7605                 goto out_sb;
7606  
7607 diff -NurpP --minimal linux-2.6.32/fs/sysfs/mount.c linux-2.6.32-vs2.3.0.36.26/fs/sysfs/mount.c
7608 --- linux-2.6.32/fs/sysfs/mount.c       2009-06-11 17:13:08.000000000 +0200
7609 +++ linux-2.6.32-vs2.3.0.36.26/fs/sysfs/mount.c 2009-12-03 20:04:56.000000000 +0100
7610 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7611  
7612         sb->s_blocksize = PAGE_CACHE_SIZE;
7613         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7614 -       sb->s_magic = SYSFS_MAGIC;
7615 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7616         sb->s_op = &sysfs_ops;
7617         sb->s_time_gran = 1;
7618         sysfs_sb = sb;
7619 diff -NurpP --minimal linux-2.6.32/fs/.tmp_dcache.ver linux-2.6.32-vs2.3.0.36.26/fs/.tmp_dcache.ver
7620 --- linux-2.6.32/fs/.tmp_dcache.ver     1970-01-01 01:00:00.000000000 +0100
7621 +++ linux-2.6.32-vs2.3.0.36.26/fs/.tmp_dcache.ver       2009-12-03 20:07:43.000000000 +0100
7622 @@ -0,0 +1,27 @@
7623 +__crc_sysctl_vfs_cache_pressure = 0x82d79b51 ;
7624 +__crc_dcache_lock = 0x58e482c7 ;
7625 +__crc_d_instantiate_unique = 0x7c189418 ;
7626 +__crc_d_obtain_alias = 0xbcd8dfe6 ;
7627 +__crc_d_genocide = 0x761de69d ;
7628 +__crc_d_alloc = 0x4491e67e ;
7629 +__crc_d_alloc_root = 0xb6aa3916 ;
7630 +__crc_d_delete = 0xc921f8ba ;
7631 +__crc_d_find_alias = 0xe28b75d1 ;
7632 +__crc_d_instantiate = 0x01b0011d ;
7633 +__crc_d_invalidate = 0xfe4bec19 ;
7634 +__crc_d_lookup = 0xb2a5ca18 ;
7635 +__crc_d_move = 0xe574db65 ;
7636 +__crc_d_materialise_unique = 0xa5c0aff6 ;
7637 +__crc_d_path = 0x9db28e8c ;
7638 +__crc_d_prune_aliases = 0x916c21f8 ;
7639 +__crc_d_rehash = 0x57bab990 ;
7640 +__crc_d_splice_alias = 0x65a3aa7d ;
7641 +__crc_d_add_ci = 0x8097dd72 ;
7642 +__crc_d_validate = 0xa68ca558 ;
7643 +__crc_dget_locked = 0x860c45d4 ;
7644 +__crc_dput = 0x9515eed3 ;
7645 +__crc_find_inode_number = 0xb4fb4528 ;
7646 +__crc_have_submounts = 0x9ea1ad9e ;
7647 +__crc_names_cachep = 0x28306992 ;
7648 +__crc_shrink_dcache_parent = 0x6876d637 ;
7649 +__crc_shrink_dcache_sb = 0x0c87c8c6 ;
7650 diff -NurpP --minimal linux-2.6.32/fs/utimes.c linux-2.6.32-vs2.3.0.36.26/fs/utimes.c
7651 --- linux-2.6.32/fs/utimes.c    2009-03-24 14:22:37.000000000 +0100
7652 +++ linux-2.6.32-vs2.3.0.36.26/fs/utimes.c      2009-12-03 20:04:56.000000000 +0100
7653 @@ -8,6 +8,8 @@
7654  #include <linux/stat.h>
7655  #include <linux/utime.h>
7656  #include <linux/syscalls.h>
7657 +#include <linux/mount.h>
7658 +#include <linux/vs_cowbl.h>
7659  #include <asm/uaccess.h>
7660  #include <asm/unistd.h>
7661  
7662 diff -NurpP --minimal linux-2.6.32/fs/xattr.c linux-2.6.32-vs2.3.0.36.26/fs/xattr.c
7663 --- linux-2.6.32/fs/xattr.c     2009-12-03 20:02:53.000000000 +0100
7664 +++ linux-2.6.32-vs2.3.0.36.26/fs/xattr.c       2009-12-03 20:04:56.000000000 +0100
7665 @@ -18,6 +18,7 @@
7666  #include <linux/module.h>
7667  #include <linux/fsnotify.h>
7668  #include <linux/audit.h>
7669 +#include <linux/mount.h>
7670  #include <asm/uaccess.h>
7671  
7672  
7673 diff -NurpP --minimal linux-2.6.32/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_ioctl.c
7674 --- linux-2.6.32/fs/xfs/linux-2.6/xfs_ioctl.c   2009-09-10 15:26:24.000000000 +0200
7675 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_ioctl.c     2009-12-03 20:04:56.000000000 +0100
7676 @@ -34,7 +34,6 @@
7677  #include "xfs_dir2_sf.h"
7678  #include "xfs_dinode.h"
7679  #include "xfs_inode.h"
7680 -#include "xfs_ioctl.h"
7681  #include "xfs_btree.h"
7682  #include "xfs_ialloc.h"
7683  #include "xfs_rtalloc.h"
7684 @@ -742,6 +741,10 @@ xfs_merge_ioc_xflags(
7685                 xflags |= XFS_XFLAG_IMMUTABLE;
7686         else
7687                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7688 +       if (flags & FS_IXUNLINK_FL)
7689 +               xflags |= XFS_XFLAG_IXUNLINK;
7690 +       else
7691 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7692         if (flags & FS_APPEND_FL)
7693                 xflags |= XFS_XFLAG_APPEND;
7694         else
7695 @@ -770,6 +773,8 @@ xfs_di2lxflags(
7696  
7697         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7698                 flags |= FS_IMMUTABLE_FL;
7699 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7700 +               flags |= FS_IXUNLINK_FL;
7701         if (di_flags & XFS_DIFLAG_APPEND)
7702                 flags |= FS_APPEND_FL;
7703         if (di_flags & XFS_DIFLAG_SYNC)
7704 @@ -828,6 +833,8 @@ xfs_set_diflags(
7705         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7706         if (xflags & XFS_XFLAG_IMMUTABLE)
7707                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7708 +       if (xflags & XFS_XFLAG_IXUNLINK)
7709 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7710         if (xflags & XFS_XFLAG_APPEND)
7711                 di_flags |= XFS_DIFLAG_APPEND;
7712         if (xflags & XFS_XFLAG_SYNC)
7713 @@ -870,6 +877,10 @@ xfs_diflags_to_linux(
7714                 inode->i_flags |= S_IMMUTABLE;
7715         else
7716                 inode->i_flags &= ~S_IMMUTABLE;
7717 +       if (xflags & XFS_XFLAG_IXUNLINK)
7718 +               inode->i_flags |= S_IXUNLINK;
7719 +       else
7720 +               inode->i_flags &= ~S_IXUNLINK;
7721         if (xflags & XFS_XFLAG_APPEND)
7722                 inode->i_flags |= S_APPEND;
7723         else
7724 @@ -1346,10 +1357,18 @@ xfs_file_ioctl(
7725         case XFS_IOC_FSGETXATTRA:
7726                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7727         case XFS_IOC_FSSETXATTR:
7728 +               if (IS_BARRIER(inode)) {
7729 +                       vxwprintk_task(1, "messing with the barrier.");
7730 +                       return -XFS_ERROR(EACCES);
7731 +               }
7732                 return xfs_ioc_fssetxattr(ip, filp, arg);
7733         case XFS_IOC_GETXFLAGS:
7734                 return xfs_ioc_getxflags(ip, arg);
7735         case XFS_IOC_SETXFLAGS:
7736 +               if (IS_BARRIER(inode)) {
7737 +                       vxwprintk_task(1, "messing with the barrier.");
7738 +                       return -XFS_ERROR(EACCES);
7739 +               }
7740                 return xfs_ioc_setxflags(ip, filp, arg);
7741  
7742         case XFS_IOC_FSSETDM: {
7743 diff -NurpP --minimal linux-2.6.32/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_ioctl.h
7744 --- linux-2.6.32/fs/xfs/linux-2.6/xfs_ioctl.h   2009-03-24 14:22:37.000000000 +0100
7745 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_ioctl.h     2009-12-03 20:04:56.000000000 +0100
7746 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7747         void __user             *uhandle,
7748         u32                     hlen);
7749  
7750 +extern int
7751 +xfs_sync_flags(
7752 +       struct inode            *inode,
7753 +       int                     flags,
7754 +       int                     vflags);
7755 +
7756  extern long
7757  xfs_file_ioctl(
7758         struct file             *filp,
7759 diff -NurpP --minimal linux-2.6.32/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_iops.c
7760 --- linux-2.6.32/fs/xfs/linux-2.6/xfs_iops.c    2009-12-03 20:02:53.000000000 +0100
7761 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_iops.c      2009-12-03 20:04:56.000000000 +0100
7762 @@ -36,6 +36,7 @@
7763  #include "xfs_attr_sf.h"
7764  #include "xfs_dinode.h"
7765  #include "xfs_inode.h"
7766 +#include "xfs_ioctl.h"
7767  #include "xfs_bmap.h"
7768  #include "xfs_btree.h"
7769  #include "xfs_ialloc.h"
7770 @@ -55,6 +56,7 @@
7771  #include <linux/security.h>
7772  #include <linux/falloc.h>
7773  #include <linux/fiemap.h>
7774 +#include <linux/vs_tag.h>
7775  
7776  /*
7777   * Bring the timestamps in the XFS inode uptodate.
7778 @@ -495,6 +497,7 @@ xfs_vn_getattr(
7779         stat->nlink = ip->i_d.di_nlink;
7780         stat->uid = ip->i_d.di_uid;
7781         stat->gid = ip->i_d.di_gid;
7782 +       stat->tag = ip->i_d.di_tag;
7783         stat->ino = ip->i_ino;
7784         stat->atime = inode->i_atime;
7785         stat->mtime = inode->i_mtime;
7786 @@ -686,6 +689,7 @@ static const struct inode_operations xfs
7787         .listxattr              = xfs_vn_listxattr,
7788         .fallocate              = xfs_vn_fallocate,
7789         .fiemap                 = xfs_vn_fiemap,
7790 +       .sync_flags             = xfs_sync_flags,
7791  };
7792  
7793  static const struct inode_operations xfs_dir_inode_operations = {
7794 @@ -711,6 +715,7 @@ static const struct inode_operations xfs
7795         .getxattr               = generic_getxattr,
7796         .removexattr            = generic_removexattr,
7797         .listxattr              = xfs_vn_listxattr,
7798 +       .sync_flags             = xfs_sync_flags,
7799  };
7800  
7801  static const struct inode_operations xfs_dir_ci_inode_operations = {
7802 @@ -760,6 +765,10 @@ xfs_diflags_to_iflags(
7803                 inode->i_flags |= S_IMMUTABLE;
7804         else
7805                 inode->i_flags &= ~S_IMMUTABLE;
7806 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7807 +               inode->i_flags |= S_IXUNLINK;
7808 +       else
7809 +               inode->i_flags &= ~S_IXUNLINK;
7810         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7811                 inode->i_flags |= S_APPEND;
7812         else
7813 @@ -772,6 +781,15 @@ xfs_diflags_to_iflags(
7814                 inode->i_flags |= S_NOATIME;
7815         else
7816                 inode->i_flags &= ~S_NOATIME;
7817 +
7818 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7819 +               inode->i_vflags |= V_BARRIER;
7820 +       else
7821 +               inode->i_vflags &= ~V_BARRIER;
7822 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7823 +               inode->i_vflags |= V_COW;
7824 +       else
7825 +               inode->i_vflags &= ~V_COW;
7826  }
7827  
7828  /*
7829 @@ -800,6 +818,7 @@ xfs_setup_inode(
7830         inode->i_nlink  = ip->i_d.di_nlink;
7831         inode->i_uid    = ip->i_d.di_uid;
7832         inode->i_gid    = ip->i_d.di_gid;
7833 +       inode->i_tag    = ip->i_d.di_tag;
7834  
7835         switch (inode->i_mode & S_IFMT) {
7836         case S_IFBLK:
7837 diff -NurpP --minimal linux-2.6.32/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_linux.h
7838 --- linux-2.6.32/fs/xfs/linux-2.6/xfs_linux.h   2009-09-10 15:26:24.000000000 +0200
7839 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_linux.h     2009-12-03 20:04:56.000000000 +0100
7840 @@ -119,6 +119,7 @@
7841  
7842  #define current_cpu()          (raw_smp_processor_id())
7843  #define current_pid()          (current->pid)
7844 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7845  #define current_test_flags(f)  (current->flags & (f))
7846  #define current_set_flags_nested(sp, f)                \
7847                 (*(sp) = current->flags, current->flags |= (f))
7848 diff -NurpP --minimal linux-2.6.32/fs/xfs/linux-2.6/xfs_super.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_super.c
7849 --- linux-2.6.32/fs/xfs/linux-2.6/xfs_super.c   2009-12-03 20:02:53.000000000 +0100
7850 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/linux-2.6/xfs_super.c     2009-12-03 20:04:56.000000000 +0100
7851 @@ -117,6 +117,9 @@ mempool_t *xfs_ioend_pool;
7852  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7853  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7854  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7855 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7856 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7857 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7858  
7859  /*
7860   * Table driven mount option parser.
7861 @@ -125,10 +128,14 @@ mempool_t *xfs_ioend_pool;
7862   * in the future, too.
7863   */
7864  enum {
7865 +       Opt_tag, Opt_notag,
7866         Opt_barrier, Opt_nobarrier, Opt_err
7867  };
7868  
7869  static const match_table_t tokens = {
7870 +       {Opt_tag, "tagxid"},
7871 +       {Opt_tag, "tag"},
7872 +       {Opt_notag, "notag"},
7873         {Opt_barrier, "barrier"},
7874         {Opt_nobarrier, "nobarrier"},
7875         {Opt_err, NULL}
7876 @@ -382,6 +389,19 @@ xfs_parseargs(
7877                 } else if (!strcmp(this_char, "irixsgid")) {
7878                         cmn_err(CE_WARN,
7879         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7880 +#ifndef CONFIG_TAGGING_NONE
7881 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7882 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7883 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7884 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7885 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7886 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7887 +#endif
7888 +#ifdef CONFIG_PROPAGATE
7889 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7890 +                       /* use value */
7891 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7892 +#endif
7893                 } else {
7894                         cmn_err(CE_WARN,
7895                                 "XFS: unknown mount option [%s].", this_char);
7896 @@ -1270,6 +1290,16 @@ xfs_fs_remount(
7897                 case Opt_nobarrier:
7898                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7899                         break;
7900 +               case Opt_tag:
7901 +                       if (!(sb->s_flags & MS_TAGGED)) {
7902 +                               printk(KERN_INFO
7903 +                                       "XFS: %s: tagging not permitted on remount.\n",
7904 +                                       sb->s_id);
7905 +                               return -EINVAL;
7906 +                       }
7907 +                       break;
7908 +               case Opt_notag:
7909 +                       break;
7910                 default:
7911                         /*
7912                          * Logically we would return an error here to prevent
7913 @@ -1477,6 +1507,9 @@ xfs_fs_fill_super(
7914  
7915         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7916  
7917 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7918 +               sb->s_flags |= MS_TAGGED;
7919 +
7920         sb->s_magic = XFS_SB_MAGIC;
7921         sb->s_blocksize = mp->m_sb.sb_blocksize;
7922         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7923 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_dinode.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_dinode.h
7924 --- linux-2.6.32/fs/xfs/xfs_dinode.h    2009-06-11 17:13:09.000000000 +0200
7925 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_dinode.h      2009-12-03 20:04:56.000000000 +0100
7926 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7927         __be32          di_gid;         /* owner's group id */
7928         __be32          di_nlink;       /* number of links to file */
7929         __be16          di_projid;      /* owner's project id */
7930 -       __u8            di_pad[8];      /* unused, zeroed space */
7931 +       __be16          di_tag;         /* context tagging */
7932 +       __be16          di_vflags;      /* vserver specific flags */
7933 +       __u8            di_pad[4];      /* unused, zeroed space */
7934         __be16          di_flushiter;   /* incremented on flush */
7935         xfs_timestamp_t di_atime;       /* time last accessed */
7936         xfs_timestamp_t di_mtime;       /* time last modified */
7937 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7938  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7939  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7940  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7941 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7942 +
7943  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7944  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7945  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7946 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
7947  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7948  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7949  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7950 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7951  
7952  #ifdef CONFIG_XFS_RT
7953  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7954 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
7955          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7956          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7957          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7958 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7959 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7960 +        XFS_DIFLAG_IXUNLINK)
7961 +
7962 +#define XFS_DIVFLAG_BARRIER    0x01
7963 +#define XFS_DIVFLAG_COW                0x02
7964  
7965  #endif /* __XFS_DINODE_H__ */
7966 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_fs.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_fs.h
7967 --- linux-2.6.32/fs/xfs/xfs_fs.h        2009-12-03 20:02:53.000000000 +0100
7968 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_fs.h  2009-12-03 20:04:56.000000000 +0100
7969 @@ -67,6 +67,9 @@ struct fsxattr {
7970  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7971  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7972  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7973 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7974 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7975 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7976  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7977  
7978  /*
7979 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
7980         __s32           bs_extents;     /* number of extents            */
7981         __u32           bs_gen;         /* generation count             */
7982         __u16           bs_projid;      /* project id                   */
7983 -       unsigned char   bs_pad[14];     /* pad space, unused            */
7984 +       __u16           bs_tag;         /* context tagging              */
7985 +       unsigned char   bs_pad[12];     /* pad space, unused            */
7986         __u32           bs_dmevmask;    /* DMIG event mask              */
7987         __u16           bs_dmstate;     /* DMIG state info              */
7988         __u16           bs_aextents;    /* attribute number of extents  */
7989 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_ialloc.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_ialloc.c
7990 --- linux-2.6.32/fs/xfs/xfs_ialloc.c    2009-12-03 20:02:53.000000000 +0100
7991 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_ialloc.c      2009-12-03 20:04:56.000000000 +0100
7992 @@ -41,7 +41,6 @@
7993  #include "xfs_error.h"
7994  #include "xfs_bmap.h"
7995  
7996 -
7997  /*
7998   * Allocation group level functions.
7999   */
8000 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_inode.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_inode.c
8001 --- linux-2.6.32/fs/xfs/xfs_inode.c     2009-12-03 20:02:54.000000000 +0100
8002 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_inode.c       2009-12-03 20:04:56.000000000 +0100
8003 @@ -249,6 +249,7 @@ xfs_inotobp(
8004         return 0;
8005  }
8006  
8007 +#include <linux/vs_tag.h>
8008  
8009  /*
8010   * This routine is called to map an inode to the buffer containing
8011 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8012  STATIC void
8013  xfs_dinode_from_disk(
8014         xfs_icdinode_t          *to,
8015 -       xfs_dinode_t            *from)
8016 +       xfs_dinode_t            *from,
8017 +       int tagged)
8018  {
8019 +       uint32_t uid, gid, tag;
8020 +
8021         to->di_magic = be16_to_cpu(from->di_magic);
8022         to->di_mode = be16_to_cpu(from->di_mode);
8023         to->di_version = from ->di_version;
8024         to->di_format = from->di_format;
8025         to->di_onlink = be16_to_cpu(from->di_onlink);
8026 -       to->di_uid = be32_to_cpu(from->di_uid);
8027 -       to->di_gid = be32_to_cpu(from->di_gid);
8028 +
8029 +       uid = be32_to_cpu(from->di_uid);
8030 +       gid = be32_to_cpu(from->di_gid);
8031 +       tag = be16_to_cpu(from->di_tag);
8032 +
8033 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8034 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8035 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8036 +
8037         to->di_nlink = be32_to_cpu(from->di_nlink);
8038         to->di_projid = be16_to_cpu(from->di_projid);
8039         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8040 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8041         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8042         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8043         to->di_flags    = be16_to_cpu(from->di_flags);
8044 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8045         to->di_gen      = be32_to_cpu(from->di_gen);
8046  }
8047  
8048  void
8049  xfs_dinode_to_disk(
8050         xfs_dinode_t            *to,
8051 -       xfs_icdinode_t          *from)
8052 +       xfs_icdinode_t          *from,
8053 +       int tagged)
8054  {
8055         to->di_magic = cpu_to_be16(from->di_magic);
8056         to->di_mode = cpu_to_be16(from->di_mode);
8057         to->di_version = from ->di_version;
8058         to->di_format = from->di_format;
8059         to->di_onlink = cpu_to_be16(from->di_onlink);
8060 -       to->di_uid = cpu_to_be32(from->di_uid);
8061 -       to->di_gid = cpu_to_be32(from->di_gid);
8062 +
8063 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8064 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8065 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8066 +
8067         to->di_nlink = cpu_to_be32(from->di_nlink);
8068         to->di_projid = cpu_to_be16(from->di_projid);
8069         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8070 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8071         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8072         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8073         to->di_flags = cpu_to_be16(from->di_flags);
8074 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8075         to->di_gen = cpu_to_be32(from->di_gen);
8076  }
8077  
8078  STATIC uint
8079  _xfs_dic2xflags(
8080 -       __uint16_t              di_flags)
8081 +       __uint16_t              di_flags,
8082 +       __uint16_t              di_vflags)
8083  {
8084         uint                    flags = 0;
8085  
8086 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8087                         flags |= XFS_XFLAG_PREALLOC;
8088                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8089                         flags |= XFS_XFLAG_IMMUTABLE;
8090 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8091 +                       flags |= XFS_XFLAG_IXUNLINK;
8092                 if (di_flags & XFS_DIFLAG_APPEND)
8093                         flags |= XFS_XFLAG_APPEND;
8094                 if (di_flags & XFS_DIFLAG_SYNC)
8095 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8096                         flags |= XFS_XFLAG_FILESTREAM;
8097         }
8098  
8099 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8100 +               flags |= FS_BARRIER_FL;
8101 +       if (di_vflags & XFS_DIVFLAG_COW)
8102 +               flags |= FS_COW_FL;
8103         return flags;
8104  }
8105  
8106 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8107  {
8108         xfs_icdinode_t          *dic = &ip->i_d;
8109  
8110 -       return _xfs_dic2xflags(dic->di_flags) |
8111 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8112                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8113  }
8114  
8115 @@ -775,7 +799,8 @@ uint
8116  xfs_dic2xflags(
8117         xfs_dinode_t            *dip)
8118  {
8119 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8120 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8121 +                               be16_to_cpu(dip->di_vflags)) |
8122                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8123  }
8124  
8125 @@ -811,7 +836,6 @@ xfs_iread(
8126         if (error)
8127                 return error;
8128         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8129 -
8130         /*
8131          * If we got something that isn't an inode it means someone
8132          * (nfs or dmi) has a stale handle.
8133 @@ -836,7 +860,8 @@ xfs_iread(
8134          * Otherwise, just get the truly permanent information.
8135          */
8136         if (dip->di_mode) {
8137 -               xfs_dinode_from_disk(&ip->i_d, dip);
8138 +               xfs_dinode_from_disk(&ip->i_d, dip,
8139 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8140                 error = xfs_iformat(ip, dip);
8141                 if (error)  {
8142  #ifdef DEBUG
8143 @@ -1036,6 +1061,7 @@ xfs_ialloc(
8144         ASSERT(ip->i_d.di_nlink == nlink);
8145         ip->i_d.di_uid = current_fsuid();
8146         ip->i_d.di_gid = current_fsgid();
8147 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8148         ip->i_d.di_projid = prid;
8149         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8150  
8151 @@ -1096,6 +1122,7 @@ xfs_ialloc(
8152         ip->i_d.di_dmevmask = 0;
8153         ip->i_d.di_dmstate = 0;
8154         ip->i_d.di_flags = 0;
8155 +       ip->i_d.di_vflags = 0;
8156         flags = XFS_ILOG_CORE;
8157         switch (mode & S_IFMT) {
8158         case S_IFIFO:
8159 @@ -2172,6 +2199,7 @@ xfs_ifree(
8160         }
8161         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8162         ip->i_d.di_flags = 0;
8163 +       ip->i_d.di_vflags = 0;
8164         ip->i_d.di_dmevmask = 0;
8165         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8166         ip->i_df.if_ext_max =
8167 @@ -3139,7 +3167,8 @@ xfs_iflush_int(
8168          * because if the inode is dirty at all the core must
8169          * be.
8170          */
8171 -       xfs_dinode_to_disk(dip, &ip->i_d);
8172 +       xfs_dinode_to_disk(dip, &ip->i_d,
8173 +               mp->m_flags & XFS_MOUNT_TAGGED);
8174  
8175         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8176         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8177 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_inode.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_inode.h
8178 --- linux-2.6.32/fs/xfs/xfs_inode.h     2009-12-03 20:02:54.000000000 +0100
8179 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_inode.h       2009-12-03 20:04:56.000000000 +0100
8180 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8181         __uint32_t      di_gid;         /* owner's group id */
8182         __uint32_t      di_nlink;       /* number of links to file */
8183         __uint16_t      di_projid;      /* owner's project id */
8184 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8185 +       __uint16_t      di_tag;         /* context tagging */
8186 +       __uint16_t      di_vflags;      /* vserver specific flags */
8187 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8188         __uint16_t      di_flushiter;   /* incremented on flush */
8189         xfs_ictimestamp_t di_atime;     /* time last accessed */
8190         xfs_ictimestamp_t di_mtime;     /* time last modified */
8191 @@ -569,7 +571,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8192  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8193                           struct xfs_inode *, xfs_daddr_t, uint);
8194  void           xfs_dinode_to_disk(struct xfs_dinode *,
8195 -                                  struct xfs_icdinode *);
8196 +                                  struct xfs_icdinode *, int);
8197  void           xfs_idestroy_fork(struct xfs_inode *, int);
8198  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8199  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8200 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_itable.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_itable.c
8201 --- linux-2.6.32/fs/xfs/xfs_itable.c    2009-12-03 20:02:54.000000000 +0100
8202 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_itable.c      2009-12-03 20:04:56.000000000 +0100
8203 @@ -84,6 +84,7 @@ xfs_bulkstat_one_iget(
8204         buf->bs_mode = dic->di_mode;
8205         buf->bs_uid = dic->di_uid;
8206         buf->bs_gid = dic->di_gid;
8207 +       buf->bs_tag = dic->di_tag;
8208         buf->bs_size = dic->di_size;
8209  
8210         /*
8211 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_log_recover.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_log_recover.c
8212 --- linux-2.6.32/fs/xfs/xfs_log_recover.c       2009-12-03 20:02:54.000000000 +0100
8213 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_log_recover.c 2009-12-03 20:04:56.000000000 +0100
8214 @@ -2467,7 +2467,8 @@ xlog_recover_do_inode_trans(
8215         }
8216  
8217         /* The core is in in-core format */
8218 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8219 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8220 +               mp->m_flags & XFS_MOUNT_TAGGED);
8221  
8222         /* the rest is in on-disk format */
8223         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8224 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_mount.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_mount.h
8225 --- linux-2.6.32/fs/xfs/xfs_mount.h     2009-12-03 20:02:54.000000000 +0100
8226 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_mount.h       2009-12-03 20:04:56.000000000 +0100
8227 @@ -283,6 +283,7 @@ typedef struct xfs_mount {
8228                                                    allocator */
8229  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8230  
8231 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8232  
8233  /*
8234   * Default minimum read and write sizes.
8235 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_vnodeops.c linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_vnodeops.c
8236 --- linux-2.6.32/fs/xfs/xfs_vnodeops.c  2009-12-03 20:02:54.000000000 +0100
8237 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_vnodeops.c    2009-12-03 20:04:56.000000000 +0100
8238 @@ -54,6 +54,80 @@
8239  #include "xfs_filestream.h"
8240  #include "xfs_vnodeops.h"
8241  
8242 +
8243 +STATIC void
8244 +xfs_get_inode_flags(
8245 +       xfs_inode_t     *ip)
8246 +{
8247 +       struct inode    *inode = VFS_I(ip);
8248 +       unsigned int    flags = inode->i_flags;
8249 +       unsigned int    vflags = inode->i_vflags;
8250 +
8251 +       if (flags & S_IMMUTABLE)
8252 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8253 +       else
8254 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8255 +       if (flags & S_IXUNLINK)
8256 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8257 +       else
8258 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8259 +
8260 +       if (vflags & V_BARRIER)
8261 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8262 +       else
8263 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8264 +       if (vflags & V_COW)
8265 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8266 +       else
8267 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8268 +}
8269 +
8270 +int
8271 +xfs_sync_flags(
8272 +       struct inode            *inode,
8273 +       int                     flags,
8274 +       int                     vflags)
8275 +{
8276 +       struct xfs_inode        *ip = XFS_I(inode);
8277 +       struct xfs_mount        *mp = ip->i_mount;
8278 +       struct xfs_trans        *tp;
8279 +       unsigned int            lock_flags = 0;
8280 +       int                     code;
8281 +
8282 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8283 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8284 +       if (code)
8285 +               goto error_out;
8286 +
8287 +       lock_flags = XFS_ILOCK_EXCL;
8288 +       xfs_ilock(ip, lock_flags);
8289 +
8290 +       xfs_trans_ijoin(tp, ip, lock_flags);
8291 +       xfs_trans_ihold(tp, ip);
8292 +
8293 +       inode->i_flags = flags;
8294 +       inode->i_vflags = vflags;
8295 +       xfs_get_inode_flags(ip);
8296 +
8297 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8298 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8299 +
8300 +       XFS_STATS_INC(xs_ig_attrchg);
8301 +
8302 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8303 +               xfs_trans_set_sync(tp);
8304 +       code = xfs_trans_commit(tp, 0);
8305 +       xfs_iunlock(ip, lock_flags);
8306 +       return code;
8307 +
8308 +error_out:
8309 +       xfs_trans_cancel(tp, 0);
8310 +       if (lock_flags)
8311 +               xfs_iunlock(ip, lock_flags);
8312 +       return code;
8313 +}
8314 +
8315 +
8316  int
8317  xfs_setattr(
8318         struct xfs_inode        *ip,
8319 @@ -69,6 +143,7 @@ xfs_setattr(
8320         uint                    commit_flags=0;
8321         uid_t                   uid=0, iuid=0;
8322         gid_t                   gid=0, igid=0;
8323 +       tag_t                   tag=0, itag=0;
8324         int                     timeflags = 0;
8325         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8326         int                     need_iolock = 1;
8327 @@ -165,7 +240,7 @@ xfs_setattr(
8328         /*
8329          * Change file ownership.  Must be the owner or privileged.
8330          */
8331 -       if (mask & (ATTR_UID|ATTR_GID)) {
8332 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8333                 /*
8334                  * These IDs could have changed since we last looked at them.
8335                  * But, we're assured that if the ownership did change
8336 @@ -174,8 +249,10 @@ xfs_setattr(
8337                  */
8338                 iuid = ip->i_d.di_uid;
8339                 igid = ip->i_d.di_gid;
8340 +               itag = ip->i_d.di_tag;
8341                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8342                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8343 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8344  
8345                 /*
8346                  * Do a quota reservation only if uid/gid is actually
8347 @@ -183,7 +260,8 @@ xfs_setattr(
8348                  */
8349                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8350                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8351 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8352 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8353 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8354                         ASSERT(tp);
8355                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8356                                                 capable(CAP_FOWNER) ?
8357 @@ -336,7 +414,7 @@ xfs_setattr(
8358         /*
8359          * Change file ownership.  Must be the owner or privileged.
8360          */
8361 -       if (mask & (ATTR_UID|ATTR_GID)) {
8362 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8363                 /*
8364                  * CAP_FSETID overrides the following restrictions:
8365                  *
8366 @@ -352,6 +430,10 @@ xfs_setattr(
8367                  * Change the ownerships and register quota modifications
8368                  * in the transaction.
8369                  */
8370 +               if (itag != tag) {
8371 +                       ip->i_d.di_tag = tag;
8372 +                       inode->i_tag = tag;
8373 +               }
8374                 if (iuid != uid) {
8375                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8376                                 ASSERT(mask & ATTR_UID);
8377 diff -NurpP --minimal linux-2.6.32/fs/xfs/xfs_vnodeops.h linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_vnodeops.h
8378 --- linux-2.6.32/fs/xfs/xfs_vnodeops.h  2009-09-10 15:26:24.000000000 +0200
8379 +++ linux-2.6.32-vs2.3.0.36.26/fs/xfs/xfs_vnodeops.h    2009-12-03 20:04:56.000000000 +0100
8380 @@ -14,6 +14,7 @@ struct xfs_inode;
8381  struct xfs_iomap;
8382  
8383  
8384 +int xfs_sync_xflags(struct xfs_inode *ip);
8385  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8386  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8387  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8388 diff -NurpP --minimal linux-2.6.32/include/asm-generic/tlb.h linux-2.6.32-vs2.3.0.36.26/include/asm-generic/tlb.h
8389 --- linux-2.6.32/include/asm-generic/tlb.h      2009-09-10 15:26:24.000000000 +0200
8390 +++ linux-2.6.32-vs2.3.0.36.26/include/asm-generic/tlb.h        2009-12-03 20:04:56.000000000 +0100
8391 @@ -14,6 +14,7 @@
8392  #define _ASM_GENERIC__TLB_H
8393  
8394  #include <linux/swap.h>
8395 +#include <linux/vs_memory.h>
8396  #include <asm/pgalloc.h>
8397  #include <asm/tlbflush.h>
8398  
8399 diff -NurpP --minimal linux-2.6.32/include/linux/capability.h linux-2.6.32-vs2.3.0.36.26/include/linux/capability.h
8400 --- linux-2.6.32/include/linux/capability.h     2009-12-03 20:02:54.000000000 +0100
8401 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/capability.h       2009-12-03 20:04:56.000000000 +0100
8402 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8403     arbitrary SCSI commands */
8404  /* Allow setting encryption key on loopback filesystem */
8405  /* Allow setting zone reclaim policy */
8406 +/* Allow the selection of a security context */
8407  
8408  #define CAP_SYS_ADMIN        21
8409  
8410 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8411  
8412  #define CAP_MAC_ADMIN        33
8413  
8414 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8415 +/* Allow context manipulations */
8416 +/* Allow changing context info on files */
8417 +
8418 +#define CAP_CONTEXT         34
8419 +
8420 +
8421 +#define CAP_LAST_CAP         CAP_CONTEXT
8422  
8423  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8424  
8425 diff -NurpP --minimal linux-2.6.32/include/linux/devpts_fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/devpts_fs.h
8426 --- linux-2.6.32/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8427 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/devpts_fs.h        2009-12-03 20:04:56.000000000 +0100
8428 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8429  
8430  #endif
8431  
8432 -
8433  #endif /* _LINUX_DEVPTS_FS_H */
8434 diff -NurpP --minimal linux-2.6.32/include/linux/ext2_fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/ext2_fs.h
8435 --- linux-2.6.32/include/linux/ext2_fs.h        2009-03-24 14:22:41.000000000 +0100
8436 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/ext2_fs.h  2009-12-03 20:04:56.000000000 +0100
8437 @@ -189,8 +189,12 @@ struct ext2_group_desc
8438  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8439  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8440  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8441 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8442  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8443  
8444 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8445 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8446 +
8447  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8448  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8449  
8450 @@ -274,7 +278,8 @@ struct ext2_inode {
8451                         __u16   i_pad1;
8452                         __le16  l_i_uid_high;   /* these 2 fields    */
8453                         __le16  l_i_gid_high;   /* were reserved2[0] */
8454 -                       __u32   l_i_reserved2;
8455 +                       __le16  l_i_tag;        /* Context Tag */
8456 +                       __u16   l_i_reserved2;
8457                 } linux2;
8458                 struct {
8459                         __u8    h_i_frag;       /* Fragment number */
8460 @@ -303,6 +308,7 @@ struct ext2_inode {
8461  #define i_gid_low      i_gid
8462  #define i_uid_high     osd2.linux2.l_i_uid_high
8463  #define i_gid_high     osd2.linux2.l_i_gid_high
8464 +#define i_raw_tag      osd2.linux2.l_i_tag
8465  #define i_reserved2    osd2.linux2.l_i_reserved2
8466  #endif
8467  
8468 @@ -347,6 +353,7 @@ struct ext2_inode {
8469  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8470  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8471  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8472 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8473  
8474  
8475  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8476 diff -NurpP --minimal linux-2.6.32/include/linux/ext3_fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/ext3_fs.h
8477 --- linux-2.6.32/include/linux/ext3_fs.h        2009-09-10 15:26:25.000000000 +0200
8478 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/ext3_fs.h  2009-12-03 20:04:56.000000000 +0100
8479 @@ -173,10 +173,14 @@ struct ext3_group_desc
8480  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8481  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8482  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8483 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8484  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8485  
8486 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8487 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8488 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8489 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8490 +
8491 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8492 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8493  
8494  /* Flags that should be inherited by new inodes from their parent. */
8495  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8496 @@ -320,7 +324,8 @@ struct ext3_inode {
8497                         __u16   i_pad1;
8498                         __le16  l_i_uid_high;   /* these 2 fields    */
8499                         __le16  l_i_gid_high;   /* were reserved2[0] */
8500 -                       __u32   l_i_reserved2;
8501 +                       __le16  l_i_tag;        /* Context Tag */
8502 +                       __u16   l_i_reserved2;
8503                 } linux2;
8504                 struct {
8505                         __u8    h_i_frag;       /* Fragment number */
8506 @@ -351,6 +356,7 @@ struct ext3_inode {
8507  #define i_gid_low      i_gid
8508  #define i_uid_high     osd2.linux2.l_i_uid_high
8509  #define i_gid_high     osd2.linux2.l_i_gid_high
8510 +#define i_raw_tag      osd2.linux2.l_i_tag
8511  #define i_reserved2    osd2.linux2.l_i_reserved2
8512  
8513  #elif defined(__GNU__)
8514 @@ -414,6 +420,7 @@ struct ext3_inode {
8515  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8516  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8517                                                   * error in ordered mode */
8518 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8519  
8520  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8521  #ifndef _LINUX_EXT2_FS_H
8522 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8523  extern void ext3_set_aops(struct inode *inode);
8524  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8525                        u64 start, u64 len);
8526 +extern int ext3_sync_flags(struct inode *, int, int);
8527  
8528  /* ioctl.c */
8529  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8530 diff -NurpP --minimal linux-2.6.32/include/linux/fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/fs.h
8531 --- linux-2.6.32/include/linux/fs.h     2009-12-03 20:02:55.000000000 +0100
8532 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/fs.h       2009-12-03 20:04:56.000000000 +0100
8533 @@ -205,6 +205,9 @@ struct inodes_stat_t {
8534  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8535  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8536  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8537 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8538 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8539 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8540  #define MS_ACTIVE      (1<<30)
8541  #define MS_NOUSER      (1<<31)
8542  
8543 @@ -231,6 +234,14 @@ struct inodes_stat_t {
8544  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8545  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8546  #define S_PRIVATE      512     /* Inode is fs-internal */
8547 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8548 +
8549 +/* Linux-VServer related Inode flags */
8550 +
8551 +#define V_VALID                1
8552 +#define V_XATTR                2
8553 +#define V_BARRIER      4       /* Barrier for chroot() */
8554 +#define V_COW          8       /* Copy on Write */
8555  
8556  /*
8557   * Note that nosuid etc flags are inode-specific: setting some file-system
8558 @@ -253,12 +264,15 @@ struct inodes_stat_t {
8559  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8560                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8561  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8562 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8563 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8564 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8565 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8566 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8567  
8568  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8569  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8570  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8571 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8572 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8573  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8574  
8575  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8576 @@ -266,6 +280,16 @@ struct inodes_stat_t {
8577  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8578  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8579  
8580 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8581 +
8582 +#ifdef CONFIG_VSERVER_COWBL
8583 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8584 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8585 +#else
8586 +#  define IS_COW(inode)                (0)
8587 +#  define IS_COW_LINK(inode)   (0)
8588 +#endif
8589 +
8590  /* the read-only stuff doesn't really belong here, but any other place is
8591     probably as bad and I don't want to create yet another include file. */
8592  
8593 @@ -347,11 +371,14 @@ struct inodes_stat_t {
8594  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8595  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8596  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8597 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8598  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8599  
8600 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8601 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8602 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8603 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8604  
8605 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8606 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8607  
8608  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8609  #define SYNC_FILE_RANGE_WRITE          2
8610 @@ -433,6 +460,7 @@ typedef void (dio_iodone_t)(struct kiocb
8611  #define ATTR_KILL_PRIV (1 << 14)
8612  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8613  #define ATTR_TIMES_SET (1 << 16)
8614 +#define ATTR_TAG       (1 << 17)
8615  
8616  /*
8617   * This is the Inode Attributes structure, used for notify_change().  It
8618 @@ -448,6 +476,7 @@ struct iattr {
8619         umode_t         ia_mode;
8620         uid_t           ia_uid;
8621         gid_t           ia_gid;
8622 +       tag_t           ia_tag;
8623         loff_t          ia_size;
8624         struct timespec ia_atime;
8625         struct timespec ia_mtime;
8626 @@ -461,6 +490,9 @@ struct iattr {
8627         struct file     *ia_file;
8628  };
8629  
8630 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8631 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8632 +
8633  /*
8634   * Includes for diskquotas.
8635   */
8636 @@ -726,7 +758,9 @@ struct inode {
8637         unsigned int            i_nlink;
8638         uid_t                   i_uid;
8639         gid_t                   i_gid;
8640 +       tag_t                   i_tag;
8641         dev_t                   i_rdev;
8642 +       dev_t                   i_mdev;
8643         u64                     i_version;
8644         loff_t                  i_size;
8645  #ifdef __NEED_I_SIZE_ORDERED
8646 @@ -773,7 +807,8 @@ struct inode {
8647         unsigned long           i_state;
8648         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8649  
8650 -       unsigned int            i_flags;
8651 +       unsigned short          i_flags;
8652 +       unsigned short          i_vflags;
8653  
8654         atomic_t                i_writecount;
8655  #ifdef CONFIG_SECURITY
8656 @@ -861,12 +896,12 @@ static inline void i_size_write(struct i
8657  
8658  static inline unsigned iminor(const struct inode *inode)
8659  {
8660 -       return MINOR(inode->i_rdev);
8661 +       return MINOR(inode->i_mdev);
8662  }
8663  
8664  static inline unsigned imajor(const struct inode *inode)
8665  {
8666 -       return MAJOR(inode->i_rdev);
8667 +       return MAJOR(inode->i_mdev);
8668  }
8669  
8670  extern struct block_device *I_BDEV(struct inode *inode);
8671 @@ -925,6 +960,7 @@ struct file {
8672         loff_t                  f_pos;
8673         struct fown_struct      f_owner;
8674         const struct cred       *f_cred;
8675 +       xid_t                   f_xid;
8676         struct file_ra_state    f_ra;
8677  
8678         u64                     f_version;
8679 @@ -1066,6 +1102,7 @@ struct file_lock {
8680         struct file *fl_file;
8681         loff_t fl_start;
8682         loff_t fl_end;
8683 +       xid_t fl_xid;
8684  
8685         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8686         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8687 @@ -1531,6 +1568,7 @@ struct inode_operations {
8688         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8689         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8690         int (*removexattr) (struct dentry *, const char *);
8691 +       int (*sync_flags) (struct inode *, int, int);
8692         void (*truncate_range)(struct inode *, loff_t, loff_t);
8693         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8694                           loff_t len);
8695 @@ -1551,6 +1589,7 @@ extern ssize_t vfs_readv(struct file *, 
8696                 unsigned long, loff_t *);
8697  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8698                 unsigned long, loff_t *);
8699 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8700  
8701  struct super_operations {
8702         struct inode *(*alloc_inode)(struct super_block *sb);
8703 @@ -2347,6 +2386,7 @@ extern int dcache_dir_open(struct inode 
8704  extern int dcache_dir_close(struct inode *, struct file *);
8705  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8706  extern int dcache_readdir(struct file *, void *, filldir_t);
8707 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8708  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8709  extern int simple_statfs(struct dentry *, struct kstatfs *);
8710  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8711 diff -NurpP --minimal linux-2.6.32/include/linux/gfs2_ondisk.h linux-2.6.32-vs2.3.0.36.26/include/linux/gfs2_ondisk.h
8712 --- linux-2.6.32/include/linux/gfs2_ondisk.h    2009-12-03 20:02:55.000000000 +0100
8713 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/gfs2_ondisk.h      2009-12-03 20:04:56.000000000 +0100
8714 @@ -235,6 +235,9 @@ enum {
8715         gfs2fl_NoAtime          = 7,
8716         gfs2fl_Sync             = 8,
8717         gfs2fl_System           = 9,
8718 +       gfs2fl_IXUnlink         = 16,
8719 +       gfs2fl_Barrier          = 17,
8720 +       gfs2fl_Cow              = 18,
8721         gfs2fl_TruncInProg      = 29,
8722         gfs2fl_InheritDirectio  = 30,
8723         gfs2fl_InheritJdata     = 31,
8724 @@ -251,6 +254,9 @@ enum {
8725  #define GFS2_DIF_NOATIME               0x00000080
8726  #define GFS2_DIF_SYNC                  0x00000100
8727  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8728 +#define GFS2_DIF_IXUNLINK              0x00010000
8729 +#define GFS2_DIF_BARRIER               0x00020000
8730 +#define GFS2_DIF_COW                   0x00040000
8731  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8732  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8733  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8734 diff -NurpP --minimal linux-2.6.32/include/linux/if_tun.h linux-2.6.32-vs2.3.0.36.26/include/linux/if_tun.h
8735 --- linux-2.6.32/include/linux/if_tun.h 2009-12-03 20:02:55.000000000 +0100
8736 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/if_tun.h   2009-12-03 20:04:56.000000000 +0100
8737 @@ -48,6 +48,7 @@
8738  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8739  #define TUNGETSNDBUF   _IOR('T', 211, int)
8740  #define TUNSETSNDBUF   _IOW('T', 212, int)
8741 +#define TUNSETNID     _IOW('T', 215, int)
8742  
8743  /* TUNSETIFF ifr flags */
8744  #define IFF_TUN                0x0001
8745 diff -NurpP --minimal linux-2.6.32/include/linux/init_task.h linux-2.6.32-vs2.3.0.36.26/include/linux/init_task.h
8746 --- linux-2.6.32/include/linux/init_task.h      2009-12-03 20:02:55.000000000 +0100
8747 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/init_task.h        2009-12-03 20:04:56.000000000 +0100
8748 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8749         INIT_FTRACE_GRAPH                                               \
8750         INIT_TRACE_RECURSION                                            \
8751         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8752 +       .xid            = 0,                                            \
8753 +       .vx_info        = NULL,                                         \
8754 +       .nid            = 0,                                            \
8755 +       .nx_info        = NULL,                                         \
8756  }
8757  
8758  
8759 diff -NurpP --minimal linux-2.6.32/include/linux/ipc.h linux-2.6.32-vs2.3.0.36.26/include/linux/ipc.h
8760 --- linux-2.6.32/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8761 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/ipc.h      2009-12-03 20:04:56.000000000 +0100
8762 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8763         key_t           key;
8764         uid_t           uid;
8765         gid_t           gid;
8766 +       xid_t           xid;
8767         uid_t           cuid;
8768         gid_t           cgid;
8769         mode_t          mode; 
8770 diff -NurpP --minimal linux-2.6.32/include/linux/Kbuild linux-2.6.32-vs2.3.0.36.26/include/linux/Kbuild
8771 --- linux-2.6.32/include/linux/Kbuild   2009-12-03 20:02:54.000000000 +0100
8772 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/Kbuild     2009-12-03 20:04:56.000000000 +0100
8773 @@ -382,5 +382,8 @@ unifdef-y += xattr.h
8774  unifdef-y += xfrm.h
8775  
8776  objhdr-y += version.h
8777 +
8778 +header-y += vserver/
8779  header-y += wimax.h
8780  header-y += wimax/
8781 +
8782 diff -NurpP --minimal linux-2.6.32/include/linux/loop.h linux-2.6.32-vs2.3.0.36.26/include/linux/loop.h
8783 --- linux-2.6.32/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8784 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/loop.h     2009-12-03 20:04:56.000000000 +0100
8785 @@ -45,6 +45,7 @@ struct loop_device {
8786         struct loop_func_table *lo_encryption;
8787         __u32           lo_init[2];
8788         uid_t           lo_key_owner;   /* Who set the key */
8789 +       xid_t           lo_xid;
8790         int             (*ioctl)(struct loop_device *, int cmd, 
8791                                  unsigned long arg); 
8792  
8793 diff -NurpP --minimal linux-2.6.32/include/linux/magic.h linux-2.6.32-vs2.3.0.36.26/include/linux/magic.h
8794 --- linux-2.6.32/include/linux/magic.h  2009-12-03 20:02:55.000000000 +0100
8795 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/magic.h    2009-12-03 20:04:56.000000000 +0100
8796 @@ -3,7 +3,7 @@
8797  
8798  #define ADFS_SUPER_MAGIC       0xadf5
8799  #define AFFS_SUPER_MAGIC       0xadff
8800 -#define AFS_SUPER_MAGIC                0x5346414F
8801 +#define AFS_SUPER_MAGIC                0x5346414F
8802  #define AUTOFS_SUPER_MAGIC     0x0187
8803  #define CODA_SUPER_MAGIC       0x73757245
8804  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8805 @@ -38,6 +38,7 @@
8806  #define NFS_SUPER_MAGIC                0x6969
8807  #define OPENPROM_SUPER_MAGIC   0x9fa1
8808  #define PROC_SUPER_MAGIC       0x9fa0
8809 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8810  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8811  
8812  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8813 diff -NurpP --minimal linux-2.6.32/include/linux/major.h linux-2.6.32-vs2.3.0.36.26/include/linux/major.h
8814 --- linux-2.6.32/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8815 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/major.h    2009-12-03 20:04:56.000000000 +0100
8816 @@ -15,6 +15,7 @@
8817  #define HD_MAJOR               IDE0_MAJOR
8818  #define PTY_SLAVE_MAJOR                3
8819  #define TTY_MAJOR              4
8820 +#define VROOT_MAJOR            4
8821  #define TTYAUX_MAJOR           5
8822  #define LP_MAJOR               6
8823  #define VCS_MAJOR              7
8824 diff -NurpP --minimal linux-2.6.32/include/linux/mm_types.h linux-2.6.32-vs2.3.0.36.26/include/linux/mm_types.h
8825 --- linux-2.6.32/include/linux/mm_types.h       2009-12-03 20:02:55.000000000 +0100
8826 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/mm_types.h 2009-12-03 20:04:56.000000000 +0100
8827 @@ -246,6 +246,7 @@ struct mm_struct {
8828  
8829         /* Architecture-specific MM context */
8830         mm_context_t context;
8831 +       struct vx_info *mm_vx_info;
8832  
8833         /* Swap token stuff */
8834         /*
8835 diff -NurpP --minimal linux-2.6.32/include/linux/mount.h linux-2.6.32-vs2.3.0.36.26/include/linux/mount.h
8836 --- linux-2.6.32/include/linux/mount.h  2009-09-10 15:26:25.000000000 +0200
8837 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/mount.h    2009-12-03 20:04:56.000000000 +0100
8838 @@ -36,6 +36,9 @@ struct mnt_namespace;
8839  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8840  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8841  
8842 +#define MNT_TAGID      0x10000
8843 +#define MNT_NOTAG      0x20000
8844 +
8845  struct vfsmount {
8846         struct list_head mnt_hash;
8847         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8848 @@ -70,6 +73,7 @@ struct vfsmount {
8849  #else
8850         int mnt_writers;
8851  #endif
8852 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8853  };
8854  
8855  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8856 diff -NurpP --minimal linux-2.6.32/include/linux/net.h linux-2.6.32-vs2.3.0.36.26/include/linux/net.h
8857 --- linux-2.6.32/include/linux/net.h    2009-12-03 20:02:55.000000000 +0100
8858 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/net.h      2009-12-03 20:04:56.000000000 +0100
8859 @@ -69,6 +69,7 @@ struct net;
8860  #define SOCK_NOSPACE           2
8861  #define SOCK_PASSCRED          3
8862  #define SOCK_PASSSEC           4
8863 +#define SOCK_USER_SOCKET       5
8864  
8865  #ifndef ARCH_HAS_SOCKET_TYPES
8866  /**
8867 diff -NurpP --minimal linux-2.6.32/include/linux/nfs_mount.h linux-2.6.32-vs2.3.0.36.26/include/linux/nfs_mount.h
8868 --- linux-2.6.32/include/linux/nfs_mount.h      2009-03-24 14:22:43.000000000 +0100
8869 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/nfs_mount.h        2009-12-03 20:04:56.000000000 +0100
8870 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8871  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8872  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8873  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8874 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8875 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8876 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8877  
8878  /* The following are for internal use only */
8879  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8880 diff -NurpP --minimal linux-2.6.32/include/linux/nsproxy.h linux-2.6.32-vs2.3.0.36.26/include/linux/nsproxy.h
8881 --- linux-2.6.32/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
8882 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/nsproxy.h  2009-12-03 20:04:56.000000000 +0100
8883 @@ -3,6 +3,7 @@
8884  
8885  #include <linux/spinlock.h>
8886  #include <linux/sched.h>
8887 +#include <linux/vserver/debug.h>
8888  
8889  struct mnt_namespace;
8890  struct uts_namespace;
8891 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8892  }
8893  
8894  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8895 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8896  void exit_task_namespaces(struct task_struct *tsk);
8897  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8898  void free_nsproxy(struct nsproxy *ns);
8899  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8900         struct fs_struct *);
8901  
8902 -static inline void put_nsproxy(struct nsproxy *ns)
8903 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8904 +
8905 +static inline void __get_nsproxy(struct nsproxy *ns,
8906 +       const char *_file, int _line)
8907  {
8908 -       if (atomic_dec_and_test(&ns->count)) {
8909 -               free_nsproxy(ns);
8910 -       }
8911 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8912 +               ns, atomic_read(&ns->count), _file, _line);
8913 +       atomic_inc(&ns->count);
8914  }
8915  
8916 -static inline void get_nsproxy(struct nsproxy *ns)
8917 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8918 +
8919 +static inline void __put_nsproxy(struct nsproxy *ns,
8920 +       const char *_file, int _line)
8921  {
8922 -       atomic_inc(&ns->count);
8923 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8924 +               ns, atomic_read(&ns->count), _file, _line);
8925 +       if (atomic_dec_and_test(&ns->count)) {
8926 +               free_nsproxy(ns);
8927 +       }
8928  }
8929  
8930  #ifdef CONFIG_CGROUP_NS
8931 diff -NurpP --minimal linux-2.6.32/include/linux/pid.h linux-2.6.32-vs2.3.0.36.26/include/linux/pid.h
8932 --- linux-2.6.32/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
8933 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/pid.h      2009-12-03 20:04:56.000000000 +0100
8934 @@ -8,7 +8,8 @@ enum pid_type
8935         PIDTYPE_PID,
8936         PIDTYPE_PGID,
8937         PIDTYPE_SID,
8938 -       PIDTYPE_MAX
8939 +       PIDTYPE_MAX,
8940 +       PIDTYPE_REALPID
8941  };
8942  
8943  /*
8944 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
8945  }
8946  
8947  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8948 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8949  pid_t pid_vnr(struct pid *pid);
8950  
8951  #define do_each_pid_task(pid, type, task)                              \
8952 diff -NurpP --minimal linux-2.6.32/include/linux/proc_fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/proc_fs.h
8953 --- linux-2.6.32/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
8954 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/proc_fs.h  2009-12-03 20:04:56.000000000 +0100
8955 @@ -56,6 +56,7 @@ struct proc_dir_entry {
8956         nlink_t nlink;
8957         uid_t uid;
8958         gid_t gid;
8959 +       int vx_flags;
8960         loff_t size;
8961         const struct inode_operations *proc_iops;
8962         /*
8963 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
8964  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
8965  #endif
8966  
8967 +struct vx_info;
8968 +struct nx_info;
8969 +
8970  union proc_op {
8971         int (*proc_get_link)(struct inode *, struct path *);
8972         int (*proc_read)(struct task_struct *task, char *page);
8973         int (*proc_show)(struct seq_file *m,
8974                 struct pid_namespace *ns, struct pid *pid,
8975                 struct task_struct *task);
8976 +       int (*proc_vs_read)(char *page);
8977 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8978 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8979  };
8980  
8981  struct ctl_table_header;
8982 @@ -263,6 +270,7 @@ struct ctl_table;
8983  
8984  struct proc_inode {
8985         struct pid *pid;
8986 +       int vx_flags;
8987         int fd;
8988         union proc_op op;
8989         struct proc_dir_entry *pde;
8990 diff -NurpP --minimal linux-2.6.32/include/linux/quotaops.h linux-2.6.32-vs2.3.0.36.26/include/linux/quotaops.h
8991 --- linux-2.6.32/include/linux/quotaops.h       2009-12-03 20:02:56.000000000 +0100
8992 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/quotaops.h 2009-12-03 20:04:56.000000000 +0100
8993 @@ -8,6 +8,7 @@
8994  #define _LINUX_QUOTAOPS_
8995  
8996  #include <linux/fs.h>
8997 +#include <linux/vs_dlimit.h>
8998  
8999  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9000  {
9001 @@ -154,10 +155,14 @@ static inline void vfs_dq_init(struct in
9002   * a transaction (deadlocks possible otherwise) */
9003  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9004  {
9005 +       if (dl_alloc_space(inode, nr))
9006 +               return 1;
9007         if (sb_any_quota_active(inode->i_sb)) {
9008                 /* Used space is updated in alloc_space() */
9009 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9010 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9011 +                       dl_free_space(inode, nr);
9012                         return 1;
9013 +               }
9014         }
9015         else
9016                 inode_add_bytes(inode, nr);
9017 @@ -174,10 +179,14 @@ static inline int vfs_dq_prealloc_space(
9018  
9019  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9020  {
9021 +       if (dl_alloc_space(inode, nr))
9022 +               return 1;
9023         if (sb_any_quota_active(inode->i_sb)) {
9024                 /* Used space is updated in alloc_space() */
9025 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
9026 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9027 +                       dl_free_space(inode, nr);
9028                         return 1;
9029 +               }
9030         }
9031         else
9032                 inode_add_bytes(inode, nr);
9033 @@ -194,20 +203,28 @@ static inline int vfs_dq_alloc_space(str
9034  
9035  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9036  {
9037 +       if (dl_reserve_space(inode, nr))
9038 +               return 1;
9039         if (sb_any_quota_active(inode->i_sb)) {
9040                 /* Used space is updated in alloc_space() */
9041 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9042 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9043 +                       dl_release_space(inode, nr);
9044                         return 1;
9045 +               }
9046         }
9047         return 0;
9048  }
9049  
9050  static inline int vfs_dq_alloc_inode(struct inode *inode)
9051  {
9052 +       if (dl_alloc_inode(inode))
9053 +               return 1;
9054         if (sb_any_quota_active(inode->i_sb)) {
9055                 vfs_dq_init(inode);
9056 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9057 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9058 +                       dl_free_inode(inode);
9059                         return 1;
9060 +               }
9061         }
9062         return 0;
9063  }
9064 @@ -217,9 +234,13 @@ static inline int vfs_dq_alloc_inode(str
9065   */
9066  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9067  {
9068 +       if (dl_claim_space(inode, nr))
9069 +               return 1;
9070         if (sb_any_quota_active(inode->i_sb)) {
9071 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9072 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9073 +                       dl_release_space(inode, nr);
9074                         return 1;
9075 +               }
9076         } else
9077                 inode_add_bytes(inode, nr);
9078  
9079 @@ -235,6 +256,7 @@ void vfs_dq_release_reservation_space(st
9080  {
9081         if (sb_any_quota_active(inode->i_sb))
9082                 inode->i_sb->dq_op->release_rsv(inode, nr);
9083 +       dl_release_space(inode, nr);
9084  }
9085  
9086  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9087 @@ -243,6 +265,7 @@ static inline void vfs_dq_free_space_nod
9088                 inode->i_sb->dq_op->free_space(inode, nr);
9089         else
9090                 inode_sub_bytes(inode, nr);
9091 +       dl_free_space(inode, nr);
9092  }
9093  
9094  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9095 @@ -255,6 +278,7 @@ static inline void vfs_dq_free_inode(str
9096  {
9097         if (sb_any_quota_active(inode->i_sb))
9098                 inode->i_sb->dq_op->free_inode(inode, 1);
9099 +       dl_free_inode(inode);
9100  }
9101  
9102  /* Cannot be called inside a transaction */
9103 @@ -358,6 +382,8 @@ static inline int vfs_dq_transfer(struct
9104  
9105  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9106  {
9107 +       if (dl_alloc_space(inode, nr))
9108 +               return 1;
9109         inode_add_bytes(inode, nr);
9110         return 0;
9111  }
9112 @@ -371,6 +397,8 @@ static inline int vfs_dq_prealloc_space(
9113  
9114  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9115  {
9116 +       if (dl_alloc_space(inode, nr))
9117 +               return 1;
9118         inode_add_bytes(inode, nr);
9119         return 0;
9120  }
9121 @@ -384,22 +412,28 @@ static inline int vfs_dq_alloc_space(str
9122  
9123  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9124  {
9125 +       if (dl_reserve_space(inode, nr))
9126 +               return 1;
9127         return 0;
9128  }
9129  
9130  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9131  {
9132 +       if (dl_claim_space(inode, nr))
9133 +               return 1;
9134         return vfs_dq_alloc_space(inode, nr);
9135  }
9136  
9137  static inline
9138  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9139  {
9140 +       dl_release_space(inode, nr);
9141         return 0;
9142  }
9143  
9144  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9145  {
9146 +       dl_free_space(inode, nr);
9147         inode_sub_bytes(inode, nr);
9148  }
9149  
9150 diff -NurpP --minimal linux-2.6.32/include/linux/reiserfs_fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/reiserfs_fs.h
9151 --- linux-2.6.32/include/linux/reiserfs_fs.h    2009-09-10 15:26:26.000000000 +0200
9152 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/reiserfs_fs.h      2009-12-03 20:04:56.000000000 +0100
9153 @@ -899,6 +899,11 @@ struct stat_data_v1 {
9154  #define REISERFS_COMPR_FL     FS_COMPR_FL
9155  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9156  
9157 +/* unfortunately reiserfs sdattr is only 16 bit */
9158 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9159 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9160 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9161 +
9162  /* persistent flags that file inherits from the parent directory */
9163  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9164                                 REISERFS_SYNC_FL |      \
9165 @@ -908,6 +913,9 @@ struct stat_data_v1 {
9166                                 REISERFS_COMPR_FL |     \
9167                                 REISERFS_NOTAIL_FL )
9168  
9169 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9170 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9171 +
9172  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9173     address blocks) */
9174  struct stat_data {
9175 @@ -1989,6 +1997,7 @@ static inline void reiserfs_update_sd(st
9176  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9177  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9178  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9179 +int reiserfs_sync_flags(struct inode *inode, int, int);
9180  
9181  /* namei.c */
9182  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9183 diff -NurpP --minimal linux-2.6.32/include/linux/reiserfs_fs_sb.h linux-2.6.32-vs2.3.0.36.26/include/linux/reiserfs_fs_sb.h
9184 --- linux-2.6.32/include/linux/reiserfs_fs_sb.h 2009-09-10 15:26:26.000000000 +0200
9185 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/reiserfs_fs_sb.h   2009-12-03 20:04:56.000000000 +0100
9186 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9187         REISERFS_EXPOSE_PRIVROOT,
9188         REISERFS_BARRIER_NONE,
9189         REISERFS_BARRIER_FLUSH,
9190 +       REISERFS_TAGGED,
9191  
9192         /* Actions on error */
9193         REISERFS_ERROR_PANIC,
9194 diff -NurpP --minimal linux-2.6.32/include/linux/sched.h linux-2.6.32-vs2.3.0.36.26/include/linux/sched.h
9195 --- linux-2.6.32/include/linux/sched.h  2009-12-03 20:02:56.000000000 +0100
9196 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/sched.h    2009-12-03 20:04:56.000000000 +0100
9197 @@ -390,25 +390,28 @@ extern void arch_unmap_area_topdown(stru
9198   * The mm counters are not protected by its page_table_lock,
9199   * so must be incremented atomically.
9200   */
9201 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9202 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9203 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9204 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9205 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9206 +#define __set_mm_counter(mm, member, value) \
9207 +       atomic_long_set(&(mm)->_##member, value)
9208 +#define get_mm_counter(mm, member) \
9209 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9210  
9211  #else  /* !USE_SPLIT_PTLOCKS */
9212  /*
9213   * The mm counters are protected by its page_table_lock,
9214   * so can be incremented directly.
9215   */
9216 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9217 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9218  #define get_mm_counter(mm, member) ((mm)->_##member)
9219 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9220 -#define inc_mm_counter(mm, member) (mm)->_##member++
9221 -#define dec_mm_counter(mm, member) (mm)->_##member--
9222  
9223  #endif /* !USE_SPLIT_PTLOCKS */
9224  
9225 +#define set_mm_counter(mm, member, value) \
9226 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9227 +#define add_mm_counter(mm, member, value) \
9228 +       vx_ ## member ## pages_add((mm), (value))
9229 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9230 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9231 +
9232  #define get_mm_rss(mm)                                 \
9233         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9234  #define update_hiwater_rss(mm) do {                    \
9235 @@ -1183,6 +1186,12 @@ struct sched_entity {
9236         u64                     nr_wakeups_affine_attempts;
9237         u64                     nr_wakeups_passive;
9238         u64                     nr_wakeups_idle;
9239 +#ifdef CONFIG_CFS_HARD_LIMITS
9240 +       u64                     throttle_start;
9241 +       u64                     throttle_max;
9242 +       u64                     throttle_count;
9243 +       u64                     throttle_sum;
9244 +#endif
9245  #endif
9246  
9247  #ifdef CONFIG_FAIR_GROUP_SCHED
9248 @@ -1393,6 +1402,14 @@ struct task_struct {
9249  #endif
9250         seccomp_t seccomp;
9251  
9252 +/* vserver context data */
9253 +       struct vx_info *vx_info;
9254 +       struct nx_info *nx_info;
9255 +
9256 +       xid_t xid;
9257 +       nid_t nid;
9258 +       tag_t tag;
9259 +
9260  /* Thread group tracking */
9261         u32 parent_exec_id;
9262         u32 self_exec_id;
9263 @@ -1618,6 +1635,11 @@ struct pid_namespace;
9264  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9265                         struct pid_namespace *ns);
9266  
9267 +#include <linux/vserver/base.h>
9268 +#include <linux/vserver/context.h>
9269 +#include <linux/vserver/debug.h>
9270 +#include <linux/vserver/pid.h>
9271 +
9272  static inline pid_t task_pid_nr(struct task_struct *tsk)
9273  {
9274         return tsk->pid;
9275 @@ -1631,7 +1653,8 @@ static inline pid_t task_pid_nr_ns(struc
9276  
9277  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9278  {
9279 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9280 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9281 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9282  }
9283  
9284  
9285 @@ -1644,7 +1667,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9286  
9287  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9288  {
9289 -       return pid_vnr(task_tgid(tsk));
9290 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9291  }
9292  
9293  
9294 diff -NurpP --minimal linux-2.6.32/include/linux/shmem_fs.h linux-2.6.32-vs2.3.0.36.26/include/linux/shmem_fs.h
9295 --- linux-2.6.32/include/linux/shmem_fs.h       2009-12-03 20:02:56.000000000 +0100
9296 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/shmem_fs.h 2009-12-03 20:04:56.000000000 +0100
9297 @@ -8,6 +8,9 @@
9298  
9299  #define SHMEM_NR_DIRECT 16
9300  
9301 +#define TMPFS_SUPER_MAGIC      0x01021994
9302 +
9303 +
9304  struct shmem_inode_info {
9305         spinlock_t              lock;
9306         unsigned long           flags;
9307 diff -NurpP --minimal linux-2.6.32/include/linux/stat.h linux-2.6.32-vs2.3.0.36.26/include/linux/stat.h
9308 --- linux-2.6.32/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9309 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/stat.h     2009-12-03 20:04:56.000000000 +0100
9310 @@ -66,6 +66,7 @@ struct kstat {
9311         unsigned int    nlink;
9312         uid_t           uid;
9313         gid_t           gid;
9314 +       tag_t           tag;
9315         dev_t           rdev;
9316         loff_t          size;
9317         struct timespec  atime;
9318 diff -NurpP --minimal linux-2.6.32/include/linux/sunrpc/auth.h linux-2.6.32-vs2.3.0.36.26/include/linux/sunrpc/auth.h
9319 --- linux-2.6.32/include/linux/sunrpc/auth.h    2009-12-03 20:02:56.000000000 +0100
9320 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/sunrpc/auth.h      2009-12-03 20:04:56.000000000 +0100
9321 @@ -25,6 +25,7 @@
9322  struct auth_cred {
9323         uid_t   uid;
9324         gid_t   gid;
9325 +       tag_t   tag;
9326         struct group_info *group_info;
9327         unsigned char machine_cred : 1;
9328  };
9329 diff -NurpP --minimal linux-2.6.32/include/linux/sunrpc/clnt.h linux-2.6.32-vs2.3.0.36.26/include/linux/sunrpc/clnt.h
9330 --- linux-2.6.32/include/linux/sunrpc/clnt.h    2009-12-03 20:02:56.000000000 +0100
9331 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/sunrpc/clnt.h      2009-12-03 20:04:56.000000000 +0100
9332 @@ -49,7 +49,8 @@ struct rpc_clnt {
9333         unsigned int            cl_softrtry : 1,/* soft timeouts */
9334                                 cl_discrtry : 1,/* disconnect before retry */
9335                                 cl_autobind : 1,/* use getport() */
9336 -                               cl_chatty   : 1;/* be verbose */
9337 +                               cl_chatty   : 1,/* be verbose */
9338 +                               cl_tag      : 1;/* context tagging */
9339  
9340         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9341         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9342 diff -NurpP --minimal linux-2.6.32/include/linux/syscalls.h linux-2.6.32-vs2.3.0.36.26/include/linux/syscalls.h
9343 --- linux-2.6.32/include/linux/syscalls.h       2009-12-03 20:02:56.000000000 +0100
9344 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/syscalls.h 2009-12-03 20:04:56.000000000 +0100
9345 @@ -546,6 +546,8 @@ asmlinkage long sys_symlink(const char _
9346  asmlinkage long sys_unlink(const char __user *pathname);
9347  asmlinkage long sys_rename(const char __user *oldname,
9348                                 const char __user *newname);
9349 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9350 +                               umode_t mode);
9351  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9352  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9353  
9354 diff -NurpP --minimal linux-2.6.32/include/linux/sysctl.h linux-2.6.32-vs2.3.0.36.26/include/linux/sysctl.h
9355 --- linux-2.6.32/include/linux/sysctl.h 2009-12-03 20:02:56.000000000 +0100
9356 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/sysctl.h   2009-12-03 20:04:56.000000000 +0100
9357 @@ -69,6 +69,7 @@ enum
9358         CTL_ABI=9,              /* Binary emulation */
9359         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9360         CTL_ARLAN=254,          /* arlan wireless driver */
9361 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9362         CTL_S390DBF=5677,       /* s390 debug */
9363         CTL_SUNRPC=7249,        /* sunrpc debug */
9364         CTL_PM=9899,            /* frv power management */
9365 @@ -103,6 +104,7 @@ enum
9366  
9367         KERN_PANIC=15,          /* int: panic timeout */
9368         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9369 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9370  
9371         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9372         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9373 diff -NurpP --minimal linux-2.6.32/include/linux/sysfs.h linux-2.6.32-vs2.3.0.36.26/include/linux/sysfs.h
9374 --- linux-2.6.32/include/linux/sysfs.h  2008-12-25 00:26:37.000000000 +0100
9375 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/sysfs.h    2009-12-03 20:04:56.000000000 +0100
9376 @@ -17,6 +17,8 @@
9377  #include <linux/list.h>
9378  #include <asm/atomic.h>
9379  
9380 +#define SYSFS_SUPER_MAGIC      0x62656572
9381 +
9382  struct kobject;
9383  struct module;
9384  
9385 diff -NurpP --minimal linux-2.6.32/include/linux/time.h linux-2.6.32-vs2.3.0.36.26/include/linux/time.h
9386 --- linux-2.6.32/include/linux/time.h   2009-12-03 20:02:56.000000000 +0100
9387 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/time.h     2009-12-03 20:04:56.000000000 +0100
9388 @@ -237,6 +237,9 @@ static __always_inline void timespec_add
9389         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9390         a->tv_nsec = ns;
9391  }
9392 +
9393 +#include <linux/vs_time.h>
9394 +
9395  #endif /* __KERNEL__ */
9396  
9397  #define NFDBITS                        __NFDBITS
9398 diff -NurpP --minimal linux-2.6.32/include/linux/types.h linux-2.6.32-vs2.3.0.36.26/include/linux/types.h
9399 --- linux-2.6.32/include/linux/types.h  2009-09-10 15:26:26.000000000 +0200
9400 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/types.h    2009-12-03 20:04:56.000000000 +0100
9401 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9402  typedef __kernel_gid32_t       gid_t;
9403  typedef __kernel_uid16_t        uid16_t;
9404  typedef __kernel_gid16_t        gid16_t;
9405 +typedef unsigned int           xid_t;
9406 +typedef unsigned int           nid_t;
9407 +typedef unsigned int           tag_t;
9408  
9409  typedef unsigned long          uintptr_t;
9410  
9411 diff -NurpP --minimal linux-2.6.32/include/linux/vroot.h linux-2.6.32-vs2.3.0.36.26/include/linux/vroot.h
9412 --- linux-2.6.32/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9413 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vroot.h    2009-12-03 20:04:56.000000000 +0100
9414 @@ -0,0 +1,51 @@
9415 +
9416 +/*
9417 + * include/linux/vroot.h
9418 + *
9419 + * written by Herbert Pötzl, 9/11/2002
9420 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9421 + *
9422 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9423 + * Redistribution of this file is permitted under the
9424 + * GNU General Public License.
9425 + */
9426 +
9427 +#ifndef _LINUX_VROOT_H
9428 +#define _LINUX_VROOT_H
9429 +
9430 +
9431 +#ifdef __KERNEL__
9432 +
9433 +/* Possible states of device */
9434 +enum {
9435 +       Vr_unbound,
9436 +       Vr_bound,
9437 +};
9438 +
9439 +struct vroot_device {
9440 +       int             vr_number;
9441 +       int             vr_refcnt;
9442 +
9443 +       struct semaphore        vr_ctl_mutex;
9444 +       struct block_device    *vr_device;
9445 +       int                     vr_state;
9446 +};
9447 +
9448 +
9449 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9450 +
9451 +extern int register_vroot_grb(vroot_grb_func *);
9452 +extern int unregister_vroot_grb(vroot_grb_func *);
9453 +
9454 +#endif /* __KERNEL__ */
9455 +
9456 +#define MAX_VROOT_DEFAULT      8
9457 +
9458 +/*
9459 + * IOCTL commands --- we will commandeer 0x56 ('V')
9460 + */
9461 +
9462 +#define VROOT_SET_DEV          0x5600
9463 +#define VROOT_CLR_DEV          0x5601
9464 +
9465 +#endif /* _LINUX_VROOT_H */
9466 diff -NurpP --minimal linux-2.6.32/include/linux/vs_base.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_base.h
9467 --- linux-2.6.32/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9468 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_base.h  2009-12-03 20:04:56.000000000 +0100
9469 @@ -0,0 +1,10 @@
9470 +#ifndef _VS_BASE_H
9471 +#define _VS_BASE_H
9472 +
9473 +#include "vserver/base.h"
9474 +#include "vserver/check.h"
9475 +#include "vserver/debug.h"
9476 +
9477 +#else
9478 +#warning duplicate inclusion
9479 +#endif
9480 diff -NurpP --minimal linux-2.6.32/include/linux/vs_context.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_context.h
9481 --- linux-2.6.32/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9482 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_context.h       2009-12-03 20:04:56.000000000 +0100
9483 @@ -0,0 +1,242 @@
9484 +#ifndef _VS_CONTEXT_H
9485 +#define _VS_CONTEXT_H
9486 +
9487 +#include "vserver/base.h"
9488 +#include "vserver/check.h"
9489 +#include "vserver/context.h"
9490 +#include "vserver/history.h"
9491 +#include "vserver/debug.h"
9492 +
9493 +#include <linux/sched.h>
9494 +
9495 +
9496 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9497 +
9498 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9499 +       const char *_file, int _line, void *_here)
9500 +{
9501 +       if (!vxi)
9502 +               return NULL;
9503 +
9504 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9505 +               vxi, vxi ? vxi->vx_id : 0,
9506 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9507 +               _file, _line);
9508 +       __vxh_get_vx_info(vxi, _here);
9509 +
9510 +       atomic_inc(&vxi->vx_usecnt);
9511 +       return vxi;
9512 +}
9513 +
9514 +
9515 +extern void free_vx_info(struct vx_info *);
9516 +
9517 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9518 +
9519 +static inline void __put_vx_info(struct vx_info *vxi,
9520 +       const char *_file, int _line, void *_here)
9521 +{
9522 +       if (!vxi)
9523 +               return;
9524 +
9525 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9526 +               vxi, vxi ? vxi->vx_id : 0,
9527 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9528 +               _file, _line);
9529 +       __vxh_put_vx_info(vxi, _here);
9530 +
9531 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9532 +               free_vx_info(vxi);
9533 +}
9534 +
9535 +
9536 +#define init_vx_info(p, i) \
9537 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9538 +
9539 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9540 +       const char *_file, int _line, void *_here)
9541 +{
9542 +       if (vxi) {
9543 +               vxlprintk(VXD_CBIT(xid, 3),
9544 +                       "init_vx_info(%p[#%d.%d])",
9545 +                       vxi, vxi ? vxi->vx_id : 0,
9546 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9547 +                       _file, _line);
9548 +               __vxh_init_vx_info(vxi, vxp, _here);
9549 +
9550 +               atomic_inc(&vxi->vx_usecnt);
9551 +       }
9552 +       *vxp = vxi;
9553 +}
9554 +
9555 +
9556 +#define set_vx_info(p, i) \
9557 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9558 +
9559 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9560 +       const char *_file, int _line, void *_here)
9561 +{
9562 +       struct vx_info *vxo;
9563 +
9564 +       if (!vxi)
9565 +               return;
9566 +
9567 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9568 +               vxi, vxi ? vxi->vx_id : 0,
9569 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9570 +               _file, _line);
9571 +       __vxh_set_vx_info(vxi, vxp, _here);
9572 +
9573 +       atomic_inc(&vxi->vx_usecnt);
9574 +       vxo = xchg(vxp, vxi);
9575 +       BUG_ON(vxo);
9576 +}
9577 +
9578 +
9579 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9580 +
9581 +static inline void __clr_vx_info(struct vx_info **vxp,
9582 +       const char *_file, int _line, void *_here)
9583 +{
9584 +       struct vx_info *vxo;
9585 +
9586 +       vxo = xchg(vxp, NULL);
9587 +       if (!vxo)
9588 +               return;
9589 +
9590 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9591 +               vxo, vxo ? vxo->vx_id : 0,
9592 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9593 +               _file, _line);
9594 +       __vxh_clr_vx_info(vxo, vxp, _here);
9595 +
9596 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9597 +               free_vx_info(vxo);
9598 +}
9599 +
9600 +
9601 +#define claim_vx_info(v, p) \
9602 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9603 +
9604 +static inline void __claim_vx_info(struct vx_info *vxi,
9605 +       struct task_struct *task,
9606 +       const char *_file, int _line, void *_here)
9607 +{
9608 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9609 +               vxi, vxi ? vxi->vx_id : 0,
9610 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9611 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9612 +               task, _file, _line);
9613 +       __vxh_claim_vx_info(vxi, task, _here);
9614 +
9615 +       atomic_inc(&vxi->vx_tasks);
9616 +}
9617 +
9618 +
9619 +extern void unhash_vx_info(struct vx_info *);
9620 +
9621 +#define release_vx_info(v, p) \
9622 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9623 +
9624 +static inline void __release_vx_info(struct vx_info *vxi,
9625 +       struct task_struct *task,
9626 +       const char *_file, int _line, void *_here)
9627 +{
9628 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9629 +               vxi, vxi ? vxi->vx_id : 0,
9630 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9631 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9632 +               task, _file, _line);
9633 +       __vxh_release_vx_info(vxi, task, _here);
9634 +
9635 +       might_sleep();
9636 +
9637 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9638 +               unhash_vx_info(vxi);
9639 +}
9640 +
9641 +
9642 +#define task_get_vx_info(p) \
9643 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9644 +
9645 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9646 +       const char *_file, int _line, void *_here)
9647 +{
9648 +       struct vx_info *vxi;
9649 +
9650 +       task_lock(p);
9651 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9652 +               p, _file, _line);
9653 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9654 +       task_unlock(p);
9655 +       return vxi;
9656 +}
9657 +
9658 +
9659 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9660 +{
9661 +       if (waitqueue_active(&vxi->vx_wait))
9662 +               wake_up_interruptible(&vxi->vx_wait);
9663 +}
9664 +
9665 +
9666 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9667 +
9668 +static inline void __enter_vx_info(struct vx_info *vxi,
9669 +       struct vx_info_save *vxis, const char *_file, int _line)
9670 +{
9671 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9672 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9673 +               current->xid, current->vx_info, _file, _line);
9674 +       vxis->vxi = xchg(&current->vx_info, vxi);
9675 +       vxis->xid = current->xid;
9676 +       current->xid = vxi ? vxi->vx_id : 0;
9677 +}
9678 +
9679 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9680 +
9681 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9682 +       const char *_file, int _line)
9683 +{
9684 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9685 +               vxis, vxis->xid, vxis->vxi, current,
9686 +               current->xid, current->vx_info, _file, _line);
9687 +       (void)xchg(&current->vx_info, vxis->vxi);
9688 +       current->xid = vxis->xid;
9689 +}
9690 +
9691 +
9692 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9693 +{
9694 +       vxis->vxi = xchg(&current->vx_info, NULL);
9695 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9696 +}
9697 +
9698 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9699 +{
9700 +       (void)xchg(&current->xid, vxis->xid);
9701 +       (void)xchg(&current->vx_info, vxis->vxi);
9702 +}
9703 +
9704 +#define task_is_init(p) \
9705 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9706 +
9707 +static inline int __task_is_init(struct task_struct *p,
9708 +       const char *_file, int _line, void *_here)
9709 +{
9710 +       int is_init = is_global_init(p);
9711 +
9712 +       task_lock(p);
9713 +       if (p->vx_info)
9714 +               is_init = p->vx_info->vx_initpid == p->pid;
9715 +       task_unlock(p);
9716 +       return is_init;
9717 +}
9718 +
9719 +extern void exit_vx_info(struct task_struct *, int);
9720 +extern void exit_vx_info_early(struct task_struct *, int);
9721 +
9722 +
9723 +#else
9724 +#warning duplicate inclusion
9725 +#endif
9726 diff -NurpP --minimal linux-2.6.32/include/linux/vs_cowbl.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_cowbl.h
9727 --- linux-2.6.32/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9728 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_cowbl.h 2009-12-03 20:04:56.000000000 +0100
9729 @@ -0,0 +1,47 @@
9730 +#ifndef _VS_COWBL_H
9731 +#define _VS_COWBL_H
9732 +
9733 +#include <linux/fs.h>
9734 +#include <linux/dcache.h>
9735 +#include <linux/namei.h>
9736 +
9737 +extern struct dentry *cow_break_link(const char *pathname);
9738 +
9739 +static inline int cow_check_and_break(struct path *path)
9740 +{
9741 +       struct inode *inode = path->dentry->d_inode;
9742 +       int error = 0;
9743 +
9744 +       /* do we need this check? */
9745 +       if (IS_RDONLY(inode))
9746 +               return -EROFS;
9747 +
9748 +       if (IS_COW(inode)) {
9749 +               if (IS_COW_LINK(inode)) {
9750 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9751 +                       char *pp, *buf;
9752 +
9753 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9754 +                       if (!buf) {
9755 +                               return -ENOMEM;
9756 +                       }
9757 +                       pp = d_path(path, buf, PATH_MAX);
9758 +                       new_dentry = cow_break_link(pp);
9759 +                       kfree(buf);
9760 +                       if (!IS_ERR(new_dentry)) {
9761 +                               path->dentry = new_dentry;
9762 +                               dput(old_dentry);
9763 +                       } else
9764 +                               error = PTR_ERR(new_dentry);
9765 +               } else {
9766 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9767 +                       inode->i_ctime = CURRENT_TIME;
9768 +                       mark_inode_dirty(inode);
9769 +               }
9770 +       }
9771 +       return error;
9772 +}
9773 +
9774 +#else
9775 +#warning duplicate inclusion
9776 +#endif
9777 diff -NurpP --minimal linux-2.6.32/include/linux/vs_cvirt.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_cvirt.h
9778 --- linux-2.6.32/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9779 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_cvirt.h 2009-12-03 20:04:56.000000000 +0100
9780 @@ -0,0 +1,50 @@
9781 +#ifndef _VS_CVIRT_H
9782 +#define _VS_CVIRT_H
9783 +
9784 +#include "vserver/cvirt.h"
9785 +#include "vserver/context.h"
9786 +#include "vserver/base.h"
9787 +#include "vserver/check.h"
9788 +#include "vserver/debug.h"
9789 +
9790 +
9791 +static inline void vx_activate_task(struct task_struct *p)
9792 +{
9793 +       struct vx_info *vxi;
9794 +
9795 +       if ((vxi = p->vx_info)) {
9796 +               vx_update_load(vxi);
9797 +               atomic_inc(&vxi->cvirt.nr_running);
9798 +       }
9799 +}
9800 +
9801 +static inline void vx_deactivate_task(struct task_struct *p)
9802 +{
9803 +       struct vx_info *vxi;
9804 +
9805 +       if ((vxi = p->vx_info)) {
9806 +               vx_update_load(vxi);
9807 +               atomic_dec(&vxi->cvirt.nr_running);
9808 +       }
9809 +}
9810 +
9811 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9812 +{
9813 +       struct vx_info *vxi;
9814 +
9815 +       if ((vxi = p->vx_info))
9816 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9817 +}
9818 +
9819 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9820 +{
9821 +       struct vx_info *vxi;
9822 +
9823 +       if ((vxi = p->vx_info))
9824 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9825 +}
9826 +
9827 +
9828 +#else
9829 +#warning duplicate inclusion
9830 +#endif
9831 diff -NurpP --minimal linux-2.6.32/include/linux/vs_device.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_device.h
9832 --- linux-2.6.32/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9833 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_device.h        2009-12-03 20:04:56.000000000 +0100
9834 @@ -0,0 +1,45 @@
9835 +#ifndef _VS_DEVICE_H
9836 +#define _VS_DEVICE_H
9837 +
9838 +#include "vserver/base.h"
9839 +#include "vserver/device.h"
9840 +#include "vserver/debug.h"
9841 +
9842 +
9843 +#ifdef CONFIG_VSERVER_DEVICE
9844 +
9845 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9846 +
9847 +#define vs_device_perm(v, d, m, p) \
9848 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9849 +
9850 +#else
9851 +
9852 +static inline
9853 +int vs_map_device(struct vx_info *vxi,
9854 +       dev_t device, dev_t *target, umode_t mode)
9855 +{
9856 +       if (target)
9857 +               *target = device;
9858 +       return ~0;
9859 +}
9860 +
9861 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9862 +
9863 +#endif
9864 +
9865 +
9866 +#define vs_map_chrdev(d, t, p) \
9867 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9868 +#define vs_map_blkdev(d, t, p) \
9869 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9870 +
9871 +#define vs_chrdev_perm(d, p) \
9872 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9873 +#define vs_blkdev_perm(d, p) \
9874 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9875 +
9876 +
9877 +#else
9878 +#warning duplicate inclusion
9879 +#endif
9880 diff -NurpP --minimal linux-2.6.32/include/linux/vs_dlimit.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_dlimit.h
9881 --- linux-2.6.32/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9882 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_dlimit.h        2009-12-03 20:04:56.000000000 +0100
9883 @@ -0,0 +1,216 @@
9884 +#ifndef _VS_DLIMIT_H
9885 +#define _VS_DLIMIT_H
9886 +
9887 +#include <linux/fs.h>
9888 +
9889 +#include "vserver/dlimit.h"
9890 +#include "vserver/base.h"
9891 +#include "vserver/debug.h"
9892 +
9893 +
9894 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9895 +
9896 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9897 +       const char *_file, int _line)
9898 +{
9899 +       if (!dli)
9900 +               return NULL;
9901 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9902 +               dli, dli ? dli->dl_tag : 0,
9903 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9904 +               _file, _line);
9905 +       atomic_inc(&dli->dl_usecnt);
9906 +       return dli;
9907 +}
9908 +
9909 +
9910 +#define free_dl_info(i) \
9911 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9912 +
9913 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9914 +
9915 +static inline void __put_dl_info(struct dl_info *dli,
9916 +       const char *_file, int _line)
9917 +{
9918 +       if (!dli)
9919 +               return;
9920 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9921 +               dli, dli ? dli->dl_tag : 0,
9922 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9923 +               _file, _line);
9924 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9925 +               free_dl_info(dli);
9926 +}
9927 +
9928 +
9929 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9930 +
9931 +static inline int __dl_alloc_space(struct super_block *sb,
9932 +       tag_t tag, dlsize_t nr, const char *file, int line)
9933 +{
9934 +       struct dl_info *dli = NULL;
9935 +       int ret = 0;
9936 +
9937 +       if (nr == 0)
9938 +               goto out;
9939 +       dli = locate_dl_info(sb, tag);
9940 +       if (!dli)
9941 +               goto out;
9942 +
9943 +       spin_lock(&dli->dl_lock);
9944 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9945 +       if (!ret)
9946 +               dli->dl_space_used += nr;
9947 +       spin_unlock(&dli->dl_lock);
9948 +       put_dl_info(dli);
9949 +out:
9950 +       vxlprintk(VXD_CBIT(dlim, 1),
9951 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9952 +               sb, tag, __dlimit_char(dli), (long long)nr,
9953 +               ret, file, line);
9954 +       return ret;
9955 +}
9956 +
9957 +static inline void __dl_free_space(struct super_block *sb,
9958 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9959 +{
9960 +       struct dl_info *dli = NULL;
9961 +
9962 +       if (nr == 0)
9963 +               goto out;
9964 +       dli = locate_dl_info(sb, tag);
9965 +       if (!dli)
9966 +               goto out;
9967 +
9968 +       spin_lock(&dli->dl_lock);
9969 +       if (dli->dl_space_used > nr)
9970 +               dli->dl_space_used -= nr;
9971 +       else
9972 +               dli->dl_space_used = 0;
9973 +       spin_unlock(&dli->dl_lock);
9974 +       put_dl_info(dli);
9975 +out:
9976 +       vxlprintk(VXD_CBIT(dlim, 1),
9977 +               "FREE  (%p,#%d)%c %lld bytes",
9978 +               sb, tag, __dlimit_char(dli), (long long)nr,
9979 +               _file, _line);
9980 +}
9981 +
9982 +static inline int __dl_alloc_inode(struct super_block *sb,
9983 +       tag_t tag, const char *_file, int _line)
9984 +{
9985 +       struct dl_info *dli;
9986 +       int ret = 0;
9987 +
9988 +       dli = locate_dl_info(sb, tag);
9989 +       if (!dli)
9990 +               goto out;
9991 +
9992 +       spin_lock(&dli->dl_lock);
9993 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
9994 +       if (!ret)
9995 +               dli->dl_inodes_used++;
9996 +       spin_unlock(&dli->dl_lock);
9997 +       put_dl_info(dli);
9998 +out:
9999 +       vxlprintk(VXD_CBIT(dlim, 0),
10000 +               "ALLOC (%p,#%d)%c inode (%d)",
10001 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10002 +       return ret;
10003 +}
10004 +
10005 +static inline void __dl_free_inode(struct super_block *sb,
10006 +       tag_t tag, const char *_file, int _line)
10007 +{
10008 +       struct dl_info *dli;
10009 +
10010 +       dli = locate_dl_info(sb, tag);
10011 +       if (!dli)
10012 +               goto out;
10013 +
10014 +       spin_lock(&dli->dl_lock);
10015 +       if (dli->dl_inodes_used > 1)
10016 +               dli->dl_inodes_used--;
10017 +       else
10018 +               dli->dl_inodes_used = 0;
10019 +       spin_unlock(&dli->dl_lock);
10020 +       put_dl_info(dli);
10021 +out:
10022 +       vxlprintk(VXD_CBIT(dlim, 0),
10023 +               "FREE  (%p,#%d)%c inode",
10024 +               sb, tag, __dlimit_char(dli), _file, _line);
10025 +}
10026 +
10027 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10028 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10029 +       const char *_file, int _line)
10030 +{
10031 +       struct dl_info *dli;
10032 +       uint64_t broot, bfree;
10033 +
10034 +       dli = locate_dl_info(sb, tag);
10035 +       if (!dli)
10036 +               return;
10037 +
10038 +       spin_lock(&dli->dl_lock);
10039 +       broot = (dli->dl_space_total -
10040 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10041 +               >> sb->s_blocksize_bits;
10042 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10043 +                       >> sb->s_blocksize_bits;
10044 +       spin_unlock(&dli->dl_lock);
10045 +
10046 +       vxlprintk(VXD_CBIT(dlim, 2),
10047 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10048 +               (long long)bfree, (long long)broot,
10049 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10050 +               _file, _line);
10051 +       if (free_blocks) {
10052 +               if (*free_blocks > bfree)
10053 +                       *free_blocks = bfree;
10054 +       }
10055 +       if (root_blocks) {
10056 +               if (*root_blocks > broot)
10057 +                       *root_blocks = broot;
10058 +       }
10059 +       put_dl_info(dli);
10060 +}
10061 +
10062 +#define dl_prealloc_space(in, bytes) \
10063 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10064 +               __FILE__, __LINE__ )
10065 +
10066 +#define dl_alloc_space(in, bytes) \
10067 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10068 +               __FILE__, __LINE__ )
10069 +
10070 +#define dl_reserve_space(in, bytes) \
10071 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10072 +               __FILE__, __LINE__ )
10073 +
10074 +#define dl_claim_space(in, bytes) (0)
10075 +
10076 +#define dl_release_space(in, bytes) \
10077 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10078 +               __FILE__, __LINE__ )
10079 +
10080 +#define dl_free_space(in, bytes) \
10081 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10082 +               __FILE__, __LINE__ )
10083 +
10084 +
10085 +
10086 +#define dl_alloc_inode(in) \
10087 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10088 +
10089 +#define dl_free_inode(in) \
10090 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10091 +
10092 +
10093 +#define dl_adjust_block(sb, tag, fb, rb) \
10094 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10095 +
10096 +
10097 +#else
10098 +#warning duplicate inclusion
10099 +#endif
10100 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/base.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/base.h
10101 --- linux-2.6.32/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10102 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/base.h     2009-12-03 20:04:56.000000000 +0100
10103 @@ -0,0 +1,170 @@
10104 +#ifndef _VX_BASE_H
10105 +#define _VX_BASE_H
10106 +
10107 +
10108 +/* context state changes */
10109 +
10110 +enum {
10111 +       VSC_STARTUP = 1,
10112 +       VSC_SHUTDOWN,
10113 +
10114 +       VSC_NETUP,
10115 +       VSC_NETDOWN,
10116 +};
10117 +
10118 +
10119 +
10120 +#define vx_task_xid(t) ((t)->xid)
10121 +
10122 +#define vx_current_xid() vx_task_xid(current)
10123 +
10124 +#define current_vx_info() (current->vx_info)
10125 +
10126 +
10127 +#define nx_task_nid(t) ((t)->nid)
10128 +
10129 +#define nx_current_nid() nx_task_nid(current)
10130 +
10131 +#define current_nx_info() (current->nx_info)
10132 +
10133 +
10134 +/* generic flag merging */
10135 +
10136 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10137 +
10138 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10139 +
10140 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10141 +
10142 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10143 +
10144 +
10145 +/* context flags */
10146 +
10147 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10148 +
10149 +#define vx_current_flags()     __vx_flags(current_vx_info())
10150 +
10151 +#define vx_info_flags(v, m, f) \
10152 +       vs_check_flags(__vx_flags(v), m, f)
10153 +
10154 +#define task_vx_flags(t, m, f) \
10155 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10156 +
10157 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10158 +
10159 +
10160 +/* context caps */
10161 +
10162 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10163 +
10164 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10165 +
10166 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10167 +
10168 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10169 +
10170 +
10171 +
10172 +/* network flags */
10173 +
10174 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10175 +
10176 +#define nx_current_flags()     __nx_flags(current_nx_info())
10177 +
10178 +#define nx_info_flags(n, m, f) \
10179 +       vs_check_flags(__nx_flags(n), m, f)
10180 +
10181 +#define task_nx_flags(t, m, f) \
10182 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10183 +
10184 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10185 +
10186 +
10187 +/* network caps */
10188 +
10189 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10190 +
10191 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10192 +
10193 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10194 +
10195 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10196 +
10197 +
10198 +/* context mask capabilities */
10199 +
10200 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10201 +
10202 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10203 +
10204 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10205 +
10206 +
10207 +/* context bcap mask */
10208 +
10209 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10210 +
10211 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10212 +
10213 +
10214 +/* mask given bcaps */
10215 +
10216 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10217 +
10218 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10219 +
10220 +
10221 +/* masked cap_bset */
10222 +
10223 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10224 +
10225 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10226 +
10227 +#if 0
10228 +#define vx_info_mbcap(v, b) \
10229 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10230 +       vx_info_bcaps(v, b) : (b))
10231 +
10232 +#define task_vx_mbcap(t, b) \
10233 +       vx_info_mbcap((t)->vx_info, (t)->b)
10234 +
10235 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10236 +#endif
10237 +
10238 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10239 +
10240 +#define vx_capable(b, c) (capable(b) || \
10241 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10242 +
10243 +#define nx_capable(b, c) (capable(b) || \
10244 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10245 +
10246 +#define vx_task_initpid(t, n) \
10247 +       ((t)->vx_info && \
10248 +       ((t)->vx_info->vx_initpid == (n)))
10249 +
10250 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10251 +
10252 +
10253 +/* context unshare mask */
10254 +
10255 +#define __vx_umask(v)          ((v)->vx_umask)
10256 +
10257 +#define vx_current_umask()     __vx_umask(current_vx_info())
10258 +
10259 +#define vx_can_unshare(b, f) (capable(b) || \
10260 +       (cap_raised(current_cap(), b) && \
10261 +       !((f) & ~vx_current_umask())))
10262 +
10263 +
10264 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10265 +
10266 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10267 +
10268 +
10269 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10270 +
10271 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10272 +
10273 +#endif
10274 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cacct_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct_cmd.h
10275 --- linux-2.6.32/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10276 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct_cmd.h        2009-12-03 20:04:56.000000000 +0100
10277 @@ -0,0 +1,23 @@
10278 +#ifndef _VX_CACCT_CMD_H
10279 +#define _VX_CACCT_CMD_H
10280 +
10281 +
10282 +/* virtual host info name commands */
10283 +
10284 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10285 +
10286 +struct vcmd_sock_stat_v0 {
10287 +       uint32_t field;
10288 +       uint32_t count[3];
10289 +       uint64_t total[3];
10290 +};
10291 +
10292 +
10293 +#ifdef __KERNEL__
10294 +
10295 +#include <linux/compiler.h>
10296 +
10297 +extern int vc_sock_stat(struct vx_info *, void __user *);
10298 +
10299 +#endif /* __KERNEL__ */
10300 +#endif /* _VX_CACCT_CMD_H */
10301 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cacct_def.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct_def.h
10302 --- linux-2.6.32/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10303 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct_def.h        2009-12-03 20:04:56.000000000 +0100
10304 @@ -0,0 +1,43 @@
10305 +#ifndef _VX_CACCT_DEF_H
10306 +#define _VX_CACCT_DEF_H
10307 +
10308 +#include <asm/atomic.h>
10309 +#include <linux/vserver/cacct.h>
10310 +
10311 +
10312 +struct _vx_sock_acc {
10313 +       atomic_long_t count;
10314 +       atomic_long_t total;
10315 +};
10316 +
10317 +/* context sub struct */
10318 +
10319 +struct _vx_cacct {
10320 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10321 +       atomic_t slab[8];
10322 +       atomic_t page[6][8];
10323 +};
10324 +
10325 +#ifdef CONFIG_VSERVER_DEBUG
10326 +
10327 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10328 +{
10329 +       int i, j;
10330 +
10331 +       printk("\t_vx_cacct:");
10332 +       for (i = 0; i < 6; i++) {
10333 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10334 +
10335 +               printk("\t [%d] =", i);
10336 +               for (j = 0; j < 3; j++) {
10337 +                       printk(" [%d] = %8lu, %8lu", j,
10338 +                               atomic_long_read(&ptr[j].count),
10339 +                               atomic_long_read(&ptr[j].total));
10340 +               }
10341 +               printk("\n");
10342 +       }
10343 +}
10344 +
10345 +#endif
10346 +
10347 +#endif /* _VX_CACCT_DEF_H */
10348 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cacct.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct.h
10349 --- linux-2.6.32/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10350 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct.h    2009-12-03 20:04:56.000000000 +0100
10351 @@ -0,0 +1,15 @@
10352 +#ifndef _VX_CACCT_H
10353 +#define _VX_CACCT_H
10354 +
10355 +
10356 +enum sock_acc_field {
10357 +       VXA_SOCK_UNSPEC = 0,
10358 +       VXA_SOCK_UNIX,
10359 +       VXA_SOCK_INET,
10360 +       VXA_SOCK_INET6,
10361 +       VXA_SOCK_PACKET,
10362 +       VXA_SOCK_OTHER,
10363 +       VXA_SOCK_SIZE   /* array size */
10364 +};
10365 +
10366 +#endif /* _VX_CACCT_H */
10367 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cacct_int.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct_int.h
10368 --- linux-2.6.32/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10369 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cacct_int.h        2009-12-03 20:04:56.000000000 +0100
10370 @@ -0,0 +1,21 @@
10371 +#ifndef _VX_CACCT_INT_H
10372 +#define _VX_CACCT_INT_H
10373 +
10374 +
10375 +#ifdef __KERNEL__
10376 +
10377 +static inline
10378 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10379 +{
10380 +       return atomic_long_read(&cacct->sock[type][pos].count);
10381 +}
10382 +
10383 +
10384 +static inline
10385 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10386 +{
10387 +       return atomic_long_read(&cacct->sock[type][pos].total);
10388 +}
10389 +
10390 +#endif /* __KERNEL__ */
10391 +#endif /* _VX_CACCT_INT_H */
10392 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/check.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/check.h
10393 --- linux-2.6.32/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10394 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/check.h    2009-12-03 20:04:56.000000000 +0100
10395 @@ -0,0 +1,89 @@
10396 +#ifndef _VS_CHECK_H
10397 +#define _VS_CHECK_H
10398 +
10399 +
10400 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10401 +
10402 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10403 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10404 +#else
10405 +#define MIN_D_CONTEXT  65536
10406 +#endif
10407 +
10408 +/* check conditions */
10409 +
10410 +#define VS_ADMIN       0x0001
10411 +#define VS_WATCH       0x0002
10412 +#define VS_HIDE                0x0004
10413 +#define VS_HOSTID      0x0008
10414 +
10415 +#define VS_IDENT       0x0010
10416 +#define VS_EQUIV       0x0020
10417 +#define VS_PARENT      0x0040
10418 +#define VS_CHILD       0x0080
10419 +
10420 +#define VS_ARG_MASK    0x00F0
10421 +
10422 +#define VS_DYNAMIC     0x0100
10423 +#define VS_STATIC      0x0200
10424 +
10425 +#define VS_ATR_MASK    0x0F00
10426 +
10427 +#ifdef CONFIG_VSERVER_PRIVACY
10428 +#define VS_ADMIN_P     (0)
10429 +#define VS_WATCH_P     (0)
10430 +#else
10431 +#define VS_ADMIN_P     VS_ADMIN
10432 +#define VS_WATCH_P     VS_WATCH
10433 +#endif
10434 +
10435 +#define VS_HARDIRQ     0x1000
10436 +#define VS_SOFTIRQ     0x2000
10437 +#define VS_IRQ         0x4000
10438 +
10439 +#define VS_IRQ_MASK    0xF000
10440 +
10441 +#include <linux/hardirq.h>
10442 +
10443 +/*
10444 + * check current context for ADMIN/WATCH and
10445 + * optionally against supplied argument
10446 + */
10447 +static inline int __vs_check(int cid, int id, unsigned int mode)
10448 +{
10449 +       if (mode & VS_ARG_MASK) {
10450 +               if ((mode & VS_IDENT) && (id == cid))
10451 +                       return 1;
10452 +       }
10453 +       if (mode & VS_ATR_MASK) {
10454 +               if ((mode & VS_DYNAMIC) &&
10455 +                       (id >= MIN_D_CONTEXT) &&
10456 +                       (id <= MAX_S_CONTEXT))
10457 +                       return 1;
10458 +               if ((mode & VS_STATIC) &&
10459 +                       (id > 1) && (id < MIN_D_CONTEXT))
10460 +                       return 1;
10461 +       }
10462 +       if (mode & VS_IRQ_MASK) {
10463 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10464 +                       return 1;
10465 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10466 +                       return 1;
10467 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10468 +                       return 1;
10469 +       }
10470 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10471 +               ((mode & VS_WATCH) && (cid == 1)) ||
10472 +               ((mode & VS_HOSTID) && (id == 0)));
10473 +}
10474 +
10475 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10476 +
10477 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10478 +
10479 +
10480 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10481 +
10482 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10483 +
10484 +#endif
10485 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/context_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/context_cmd.h
10486 --- linux-2.6.32/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10487 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/context_cmd.h      2009-12-03 20:04:56.000000000 +0100
10488 @@ -0,0 +1,145 @@
10489 +#ifndef _VX_CONTEXT_CMD_H
10490 +#define _VX_CONTEXT_CMD_H
10491 +
10492 +
10493 +/* vinfo commands */
10494 +
10495 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10496 +
10497 +#ifdef __KERNEL__
10498 +extern int vc_task_xid(uint32_t);
10499 +
10500 +#endif /* __KERNEL__ */
10501 +
10502 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10503 +
10504 +struct vcmd_vx_info_v0 {
10505 +       uint32_t xid;
10506 +       uint32_t initpid;
10507 +       /* more to come */
10508 +};
10509 +
10510 +#ifdef __KERNEL__
10511 +extern int vc_vx_info(struct vx_info *, void __user *);
10512 +
10513 +#endif /* __KERNEL__ */
10514 +
10515 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10516 +
10517 +struct vcmd_ctx_stat_v0 {
10518 +       uint32_t usecnt;
10519 +       uint32_t tasks;
10520 +       /* more to come */
10521 +};
10522 +
10523 +#ifdef __KERNEL__
10524 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10525 +
10526 +#endif /* __KERNEL__ */
10527 +
10528 +/* context commands */
10529 +
10530 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10531 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10532 +
10533 +struct vcmd_ctx_create {
10534 +       uint64_t flagword;
10535 +};
10536 +
10537 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10538 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10539 +
10540 +struct vcmd_ctx_migrate {
10541 +       uint64_t flagword;
10542 +};
10543 +
10544 +#ifdef __KERNEL__
10545 +extern int vc_ctx_create(uint32_t, void __user *);
10546 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10547 +
10548 +#endif /* __KERNEL__ */
10549 +
10550 +
10551 +/* flag commands */
10552 +
10553 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10554 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10555 +
10556 +struct vcmd_ctx_flags_v0 {
10557 +       uint64_t flagword;
10558 +       uint64_t mask;
10559 +};
10560 +
10561 +#ifdef __KERNEL__
10562 +extern int vc_get_cflags(struct vx_info *, void __user *);
10563 +extern int vc_set_cflags(struct vx_info *, void __user *);
10564 +
10565 +#endif /* __KERNEL__ */
10566 +
10567 +
10568 +/* context caps commands */
10569 +
10570 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10571 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10572 +
10573 +struct vcmd_ctx_caps_v1 {
10574 +       uint64_t ccaps;
10575 +       uint64_t cmask;
10576 +};
10577 +
10578 +#ifdef __KERNEL__
10579 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10580 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10581 +
10582 +#endif /* __KERNEL__ */
10583 +
10584 +
10585 +/* bcaps commands */
10586 +
10587 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10588 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10589 +
10590 +struct vcmd_bcaps {
10591 +       uint64_t bcaps;
10592 +       uint64_t bmask;
10593 +};
10594 +
10595 +#ifdef __KERNEL__
10596 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10597 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10598 +
10599 +#endif /* __KERNEL__ */
10600 +
10601 +
10602 +/* umask commands */
10603 +
10604 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10605 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10606 +
10607 +struct vcmd_umask {
10608 +       uint64_t umask;
10609 +       uint64_t mask;
10610 +};
10611 +
10612 +#ifdef __KERNEL__
10613 +extern int vc_get_umask(struct vx_info *, void __user *);
10614 +extern int vc_set_umask(struct vx_info *, void __user *);
10615 +
10616 +#endif /* __KERNEL__ */
10617 +
10618 +
10619 +/* OOM badness */
10620 +
10621 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10622 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10623 +
10624 +struct vcmd_badness_v0 {
10625 +       int64_t bias;
10626 +};
10627 +
10628 +#ifdef __KERNEL__
10629 +extern int vc_get_badness(struct vx_info *, void __user *);
10630 +extern int vc_set_badness(struct vx_info *, void __user *);
10631 +
10632 +#endif /* __KERNEL__ */
10633 +#endif /* _VX_CONTEXT_CMD_H */
10634 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/context.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/context.h
10635 --- linux-2.6.32/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10636 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/context.h  2009-12-03 20:04:56.000000000 +0100
10637 @@ -0,0 +1,183 @@
10638 +#ifndef _VX_CONTEXT_H
10639 +#define _VX_CONTEXT_H
10640 +
10641 +#include <linux/types.h>
10642 +#include <linux/capability.h>
10643 +
10644 +
10645 +/* context flags */
10646 +
10647 +#define VXF_INFO_SCHED         0x00000002
10648 +#define VXF_INFO_NPROC         0x00000004
10649 +#define VXF_INFO_PRIVATE       0x00000008
10650 +
10651 +#define VXF_INFO_INIT          0x00000010
10652 +#define VXF_INFO_HIDE          0x00000020
10653 +#define VXF_INFO_ULIMIT                0x00000040
10654 +#define VXF_INFO_NSPACE                0x00000080
10655 +
10656 +#define VXF_SCHED_HARD         0x00000100
10657 +#define VXF_SCHED_PRIO         0x00000200
10658 +#define VXF_SCHED_PAUSE                0x00000400
10659 +
10660 +#define VXF_VIRT_MEM           0x00010000
10661 +#define VXF_VIRT_UPTIME                0x00020000
10662 +#define VXF_VIRT_CPU           0x00040000
10663 +#define VXF_VIRT_LOAD          0x00080000
10664 +#define VXF_VIRT_TIME          0x00100000
10665 +
10666 +#define VXF_HIDE_MOUNT         0x01000000
10667 +/* was VXF_HIDE_NETIF          0x02000000 */
10668 +#define VXF_HIDE_VINFO         0x04000000
10669 +
10670 +#define VXF_STATE_SETUP                (1ULL << 32)
10671 +#define VXF_STATE_INIT         (1ULL << 33)
10672 +#define VXF_STATE_ADMIN                (1ULL << 34)
10673 +
10674 +#define VXF_SC_HELPER          (1ULL << 36)
10675 +#define VXF_REBOOT_KILL                (1ULL << 37)
10676 +#define VXF_PERSISTENT         (1ULL << 38)
10677 +
10678 +#define VXF_FORK_RSS           (1ULL << 48)
10679 +#define VXF_PROLIFIC           (1ULL << 49)
10680 +
10681 +#define VXF_IGNEG_NICE         (1ULL << 52)
10682 +
10683 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10684 +
10685 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10686 +
10687 +
10688 +/* context migration */
10689 +
10690 +#define VXM_SET_INIT           0x00000001
10691 +#define VXM_SET_REAPER         0x00000002
10692 +
10693 +/* context caps */
10694 +
10695 +#define VXC_CAP_MASK           0x00000000
10696 +
10697 +#define VXC_SET_UTSNAME                0x00000001
10698 +#define VXC_SET_RLIMIT         0x00000002
10699 +#define VXC_FS_SECURITY                0x00000004
10700 +#define VXC_TIOCSTI            0x00000010
10701 +
10702 +/* was VXC_RAW_ICMP            0x00000100 */
10703 +#define VXC_SYSLOG             0x00001000
10704 +#define VXC_OOM_ADJUST         0x00002000
10705 +#define VXC_AUDIT_CONTROL      0x00004000
10706 +
10707 +#define VXC_SECURE_MOUNT       0x00010000
10708 +#define VXC_SECURE_REMOUNT     0x00020000
10709 +#define VXC_BINARY_MOUNT       0x00040000
10710 +
10711 +#define VXC_QUOTA_CTL          0x00100000
10712 +#define VXC_ADMIN_MAPPER       0x00200000
10713 +#define VXC_ADMIN_CLOOP                0x00400000
10714 +
10715 +#define VXC_KTHREAD            0x01000000
10716 +#define VXC_NAMESPACE          0x02000000
10717 +
10718 +
10719 +#ifdef __KERNEL__
10720 +
10721 +#include <linux/list.h>
10722 +#include <linux/spinlock.h>
10723 +#include <linux/rcupdate.h>
10724 +
10725 +#include "limit_def.h"
10726 +#include "sched_def.h"
10727 +#include "cvirt_def.h"
10728 +#include "cacct_def.h"
10729 +#include "device_def.h"
10730 +
10731 +#define VX_SPACES      2
10732 +
10733 +struct _vx_info_pc {
10734 +       struct _vx_sched_pc sched_pc;
10735 +       struct _vx_cvirt_pc cvirt_pc;
10736 +};
10737 +
10738 +struct vx_info {
10739 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10740 +       xid_t vx_id;                            /* context id */
10741 +       atomic_t vx_usecnt;                     /* usage count */
10742 +       atomic_t vx_tasks;                      /* tasks count */
10743 +       struct vx_info *vx_parent;              /* parent context */
10744 +       int vx_state;                           /* context state */
10745 +
10746 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10747 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10748 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10749 +
10750 +       uint64_t vx_flags;                      /* context flags */
10751 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10752 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10753 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10754 +
10755 +       struct task_struct *vx_reaper;          /* guest reaper process */
10756 +       pid_t vx_initpid;                       /* PID of guest init */
10757 +       int64_t vx_badness_bias;                /* OOM points bias */
10758 +
10759 +       struct _vx_limit limit;                 /* vserver limits */
10760 +       struct _vx_sched sched;                 /* vserver scheduler */
10761 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10762 +       struct _vx_cacct cacct;                 /* context accounting */
10763 +
10764 +       struct _vx_device dmap;                 /* default device map targets */
10765 +
10766 +#ifndef CONFIG_SMP
10767 +       struct _vx_info_pc info_pc;             /* per cpu data */
10768 +#else
10769 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10770 +#endif
10771 +
10772 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10773 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10774 +       int exit_code;                          /* last process exit code */
10775 +
10776 +       char vx_name[65];                       /* vserver name */
10777 +};
10778 +
10779 +#ifndef CONFIG_SMP
10780 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10781 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10782 +#else
10783 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10784 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10785 +#endif
10786 +
10787 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10788 +
10789 +
10790 +struct vx_info_save {
10791 +       struct vx_info *vxi;
10792 +       xid_t xid;
10793 +};
10794 +
10795 +
10796 +/* status flags */
10797 +
10798 +#define VXS_HASHED     0x0001
10799 +#define VXS_PAUSED     0x0010
10800 +#define VXS_SHUTDOWN   0x0100
10801 +#define VXS_HELPER     0x1000
10802 +#define VXS_RELEASED   0x8000
10803 +
10804 +
10805 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10806 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10807 +
10808 +extern struct vx_info *lookup_vx_info(int);
10809 +extern struct vx_info *lookup_or_create_vx_info(int);
10810 +
10811 +extern int get_xid_list(int, unsigned int *, int);
10812 +extern int xid_is_hashed(xid_t);
10813 +
10814 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10815 +
10816 +extern long vs_state_change(struct vx_info *, unsigned int);
10817 +
10818 +
10819 +#endif /* __KERNEL__ */
10820 +#endif /* _VX_CONTEXT_H */
10821 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cvirt_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cvirt_cmd.h
10822 --- linux-2.6.32/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10823 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cvirt_cmd.h        2009-12-03 20:04:56.000000000 +0100
10824 @@ -0,0 +1,53 @@
10825 +#ifndef _VX_CVIRT_CMD_H
10826 +#define _VX_CVIRT_CMD_H
10827 +
10828 +
10829 +/* virtual host info name commands */
10830 +
10831 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10832 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10833 +
10834 +struct vcmd_vhi_name_v0 {
10835 +       uint32_t field;
10836 +       char name[65];
10837 +};
10838 +
10839 +
10840 +enum vhi_name_field {
10841 +       VHIN_CONTEXT = 0,
10842 +       VHIN_SYSNAME,
10843 +       VHIN_NODENAME,
10844 +       VHIN_RELEASE,
10845 +       VHIN_VERSION,
10846 +       VHIN_MACHINE,
10847 +       VHIN_DOMAINNAME,
10848 +};
10849 +
10850 +
10851 +#ifdef __KERNEL__
10852 +
10853 +#include <linux/compiler.h>
10854 +
10855 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10856 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10857 +
10858 +#endif /* __KERNEL__ */
10859 +
10860 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10861 +
10862 +struct vcmd_virt_stat_v0 {
10863 +       uint64_t offset;
10864 +       uint64_t uptime;
10865 +       uint32_t nr_threads;
10866 +       uint32_t nr_running;
10867 +       uint32_t nr_uninterruptible;
10868 +       uint32_t nr_onhold;
10869 +       uint32_t nr_forks;
10870 +       uint32_t load[3];
10871 +};
10872 +
10873 +#ifdef __KERNEL__
10874 +extern int vc_virt_stat(struct vx_info *, void __user *);
10875 +
10876 +#endif /* __KERNEL__ */
10877 +#endif /* _VX_CVIRT_CMD_H */
10878 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cvirt_def.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cvirt_def.h
10879 --- linux-2.6.32/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10880 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cvirt_def.h        2009-12-03 20:04:56.000000000 +0100
10881 @@ -0,0 +1,80 @@
10882 +#ifndef _VX_CVIRT_DEF_H
10883 +#define _VX_CVIRT_DEF_H
10884 +
10885 +#include <linux/jiffies.h>
10886 +#include <linux/spinlock.h>
10887 +#include <linux/wait.h>
10888 +#include <linux/time.h>
10889 +#include <asm/atomic.h>
10890 +
10891 +
10892 +struct _vx_usage_stat {
10893 +       uint64_t user;
10894 +       uint64_t nice;
10895 +       uint64_t system;
10896 +       uint64_t softirq;
10897 +       uint64_t irq;
10898 +       uint64_t idle;
10899 +       uint64_t iowait;
10900 +};
10901 +
10902 +struct _vx_syslog {
10903 +       wait_queue_head_t log_wait;
10904 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10905 +
10906 +       unsigned long log_start;        /* next char to be read by syslog() */
10907 +       unsigned long con_start;        /* next char to be sent to consoles */
10908 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10909 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10910 +
10911 +       char log_buf[1024];
10912 +};
10913 +
10914 +
10915 +/* context sub struct */
10916 +
10917 +struct _vx_cvirt {
10918 +       atomic_t nr_threads;            /* number of current threads */
10919 +       atomic_t nr_running;            /* number of running threads */
10920 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10921 +
10922 +       atomic_t nr_onhold;             /* processes on hold */
10923 +       uint32_t onhold_last;           /* jiffies when put on hold */
10924 +
10925 +       struct timeval bias_tv;         /* time offset to the host */
10926 +       struct timespec bias_idle;
10927 +       struct timespec bias_uptime;    /* context creation point */
10928 +       uint64_t bias_clock;            /* offset in clock_t */
10929 +
10930 +       spinlock_t load_lock;           /* lock for the load averages */
10931 +       atomic_t load_updates;          /* nr of load updates done so far */
10932 +       uint32_t load_last;             /* last time load was calculated */
10933 +       uint32_t load[3];               /* load averages 1,5,15 */
10934 +
10935 +       atomic_t total_forks;           /* number of forks so far */
10936 +
10937 +       struct _vx_syslog syslog;
10938 +};
10939 +
10940 +struct _vx_cvirt_pc {
10941 +       struct _vx_usage_stat cpustat;
10942 +};
10943 +
10944 +
10945 +#ifdef CONFIG_VSERVER_DEBUG
10946 +
10947 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10948 +{
10949 +       printk("\t_vx_cvirt:\n");
10950 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10951 +               atomic_read(&cvirt->nr_threads),
10952 +               atomic_read(&cvirt->nr_running),
10953 +               atomic_read(&cvirt->nr_uninterruptible),
10954 +               atomic_read(&cvirt->nr_onhold));
10955 +       /* add rest here */
10956 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10957 +}
10958 +
10959 +#endif
10960 +
10961 +#endif /* _VX_CVIRT_DEF_H */
10962 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/cvirt.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cvirt.h
10963 --- linux-2.6.32/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10964 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/cvirt.h    2009-12-03 20:04:56.000000000 +0100
10965 @@ -0,0 +1,20 @@
10966 +#ifndef _VX_CVIRT_H
10967 +#define _VX_CVIRT_H
10968 +
10969 +
10970 +#ifdef __KERNEL__
10971 +
10972 +struct timespec;
10973 +
10974 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10975 +
10976 +
10977 +struct vx_info;
10978 +
10979 +void vx_update_load(struct vx_info *);
10980 +
10981 +
10982 +int vx_do_syslog(int, char __user *, int);
10983 +
10984 +#endif /* __KERNEL__ */
10985 +#endif /* _VX_CVIRT_H */
10986 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/debug_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/debug_cmd.h
10987 --- linux-2.6.32/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
10988 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/debug_cmd.h        2009-12-03 20:04:56.000000000 +0100
10989 @@ -0,0 +1,58 @@
10990 +#ifndef _VX_DEBUG_CMD_H
10991 +#define _VX_DEBUG_CMD_H
10992 +
10993 +
10994 +/* debug commands */
10995 +
10996 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10997 +
10998 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10999 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11000 +
11001 +struct  vcmd_read_history_v0 {
11002 +       uint32_t index;
11003 +       uint32_t count;
11004 +       char __user *data;
11005 +};
11006 +
11007 +struct  vcmd_read_monitor_v0 {
11008 +       uint32_t index;
11009 +       uint32_t count;
11010 +       char __user *data;
11011 +};
11012 +
11013 +
11014 +#ifdef __KERNEL__
11015 +
11016 +#ifdef CONFIG_COMPAT
11017 +
11018 +#include <asm/compat.h>
11019 +
11020 +struct vcmd_read_history_v0_x32 {
11021 +       uint32_t index;
11022 +       uint32_t count;
11023 +       compat_uptr_t data_ptr;
11024 +};
11025 +
11026 +struct vcmd_read_monitor_v0_x32 {
11027 +       uint32_t index;
11028 +       uint32_t count;
11029 +       compat_uptr_t data_ptr;
11030 +};
11031 +
11032 +#endif  /* CONFIG_COMPAT */
11033 +
11034 +extern int vc_dump_history(uint32_t);
11035 +
11036 +extern int vc_read_history(uint32_t, void __user *);
11037 +extern int vc_read_monitor(uint32_t, void __user *);
11038 +
11039 +#ifdef CONFIG_COMPAT
11040 +
11041 +extern int vc_read_history_x32(uint32_t, void __user *);
11042 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11043 +
11044 +#endif  /* CONFIG_COMPAT */
11045 +
11046 +#endif /* __KERNEL__ */
11047 +#endif /* _VX_DEBUG_CMD_H */
11048 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/debug.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/debug.h
11049 --- linux-2.6.32/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11050 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/debug.h    2009-12-03 20:04:56.000000000 +0100
11051 @@ -0,0 +1,127 @@
11052 +#ifndef _VX_DEBUG_H
11053 +#define _VX_DEBUG_H
11054 +
11055 +
11056 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11057 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11058 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11059 +
11060 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11061 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11062 +#define VXF_DEV                "%p[%lu,%d:%d]"
11063 +
11064 +
11065 +#define vxd_path(p)                                            \
11066 +       ({ static char _buffer[PATH_MAX];                       \
11067 +          d_path(p, _buffer, sizeof(_buffer)); })
11068 +
11069 +#define vxd_cond_path(n)                                       \
11070 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11071 +
11072 +
11073 +#ifdef CONFIG_VSERVER_DEBUG
11074 +
11075 +extern unsigned int vx_debug_switch;
11076 +extern unsigned int vx_debug_xid;
11077 +extern unsigned int vx_debug_nid;
11078 +extern unsigned int vx_debug_tag;
11079 +extern unsigned int vx_debug_net;
11080 +extern unsigned int vx_debug_limit;
11081 +extern unsigned int vx_debug_cres;
11082 +extern unsigned int vx_debug_dlim;
11083 +extern unsigned int vx_debug_quota;
11084 +extern unsigned int vx_debug_cvirt;
11085 +extern unsigned int vx_debug_space;
11086 +extern unsigned int vx_debug_misc;
11087 +
11088 +
11089 +#define VX_LOGLEVEL    "vxD: "
11090 +#define VX_PROC_FMT    "%p: "
11091 +#define VX_PROCESS     current
11092 +
11093 +#define vxdprintk(c, f, x...)                                  \
11094 +       do {                                                    \
11095 +               if (c)                                          \
11096 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11097 +                               VX_PROCESS , ##x);              \
11098 +       } while (0)
11099 +
11100 +#define vxlprintk(c, f, x...)                                  \
11101 +       do {                                                    \
11102 +               if (c)                                          \
11103 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11104 +       } while (0)
11105 +
11106 +#define vxfprintk(c, f, x...)                                  \
11107 +       do {                                                    \
11108 +               if (c)                                          \
11109 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11110 +       } while (0)
11111 +
11112 +
11113 +struct vx_info;
11114 +
11115 +void dump_vx_info(struct vx_info *, int);
11116 +void dump_vx_info_inactive(int);
11117 +
11118 +#else  /* CONFIG_VSERVER_DEBUG */
11119 +
11120 +#define vx_debug_switch 0
11121 +#define vx_debug_xid   0
11122 +#define vx_debug_nid   0
11123 +#define vx_debug_tag   0
11124 +#define vx_debug_net   0
11125 +#define vx_debug_limit 0
11126 +#define vx_debug_cres  0
11127 +#define vx_debug_dlim  0
11128 +#define vx_debug_cvirt 0
11129 +
11130 +#define vxdprintk(x...) do { } while (0)
11131 +#define vxlprintk(x...) do { } while (0)
11132 +#define vxfprintk(x...) do { } while (0)
11133 +
11134 +#endif /* CONFIG_VSERVER_DEBUG */
11135 +
11136 +
11137 +#ifdef CONFIG_VSERVER_WARN
11138 +
11139 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11140 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11141 +#define VX_WARN_XID    "[xid #%u] "
11142 +#define VX_WARN_NID    "[nid #%u] "
11143 +#define VX_WARN_TAG    "[tag #%u] "
11144 +
11145 +#define vxwprintk(c, f, x...)                                  \
11146 +       do {                                                    \
11147 +               if (c)                                          \
11148 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11149 +       } while (0)
11150 +
11151 +#else  /* CONFIG_VSERVER_WARN */
11152 +
11153 +#define vxwprintk(x...) do { } while (0)
11154 +
11155 +#endif /* CONFIG_VSERVER_WARN */
11156 +
11157 +#define vxwprintk_task(c, f, x...)                             \
11158 +       vxwprintk(c, VX_WARN_TASK f,                            \
11159 +               current->comm, current->pid,                    \
11160 +               current->xid, current->nid, current->tag, ##x)
11161 +#define vxwprintk_xid(c, f, x...)                              \
11162 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11163 +#define vxwprintk_nid(c, f, x...)                              \
11164 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11165 +#define vxwprintk_tag(c, f, x...)                              \
11166 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11167 +
11168 +#ifdef CONFIG_VSERVER_DEBUG
11169 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11170 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11171 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11172 +#else
11173 +#define vxd_assert_lock(l)     do { } while (0)
11174 +#define vxd_assert(c, f, x...) do { } while (0)
11175 +#endif
11176 +
11177 +
11178 +#endif /* _VX_DEBUG_H */
11179 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/device_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/device_cmd.h
11180 --- linux-2.6.32/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11181 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/device_cmd.h       2009-12-03 20:04:56.000000000 +0100
11182 @@ -0,0 +1,44 @@
11183 +#ifndef _VX_DEVICE_CMD_H
11184 +#define _VX_DEVICE_CMD_H
11185 +
11186 +
11187 +/*  device vserver commands */
11188 +
11189 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11190 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11191 +
11192 +struct vcmd_set_mapping_v0 {
11193 +       const char __user *device;
11194 +       const char __user *target;
11195 +       uint32_t flags;
11196 +};
11197 +
11198 +
11199 +#ifdef __KERNEL__
11200 +
11201 +#ifdef CONFIG_COMPAT
11202 +
11203 +#include <asm/compat.h>
11204 +
11205 +struct vcmd_set_mapping_v0_x32 {
11206 +       compat_uptr_t device_ptr;
11207 +       compat_uptr_t target_ptr;
11208 +       uint32_t flags;
11209 +};
11210 +
11211 +#endif /* CONFIG_COMPAT */
11212 +
11213 +#include <linux/compiler.h>
11214 +
11215 +extern int vc_set_mapping(struct vx_info *, void __user *);
11216 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11217 +
11218 +#ifdef CONFIG_COMPAT
11219 +
11220 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11221 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11222 +
11223 +#endif /* CONFIG_COMPAT */
11224 +
11225 +#endif /* __KERNEL__ */
11226 +#endif /* _VX_DEVICE_CMD_H */
11227 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/device_def.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/device_def.h
11228 --- linux-2.6.32/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11229 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/device_def.h       2009-12-03 20:04:56.000000000 +0100
11230 @@ -0,0 +1,17 @@
11231 +#ifndef _VX_DEVICE_DEF_H
11232 +#define _VX_DEVICE_DEF_H
11233 +
11234 +#include <linux/types.h>
11235 +
11236 +struct vx_dmap_target {
11237 +       dev_t target;
11238 +       uint32_t flags;
11239 +};
11240 +
11241 +struct _vx_device {
11242 +#ifdef CONFIG_VSERVER_DEVICE
11243 +       struct vx_dmap_target targets[2];
11244 +#endif
11245 +};
11246 +
11247 +#endif /* _VX_DEVICE_DEF_H */
11248 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/device.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/device.h
11249 --- linux-2.6.32/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11250 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/device.h   2009-12-03 20:04:56.000000000 +0100
11251 @@ -0,0 +1,15 @@
11252 +#ifndef _VX_DEVICE_H
11253 +#define _VX_DEVICE_H
11254 +
11255 +
11256 +#define DATTR_CREATE   0x00000001
11257 +#define DATTR_OPEN     0x00000002
11258 +
11259 +#define DATTR_REMAP    0x00000010
11260 +
11261 +#define DATTR_MASK     0x00000013
11262 +
11263 +
11264 +#else  /* _VX_DEVICE_H */
11265 +#warning duplicate inclusion
11266 +#endif /* _VX_DEVICE_H */
11267 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/dlimit_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/dlimit_cmd.h
11268 --- linux-2.6.32/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11269 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/dlimit_cmd.h       2009-12-03 20:04:56.000000000 +0100
11270 @@ -0,0 +1,109 @@
11271 +#ifndef _VX_DLIMIT_CMD_H
11272 +#define _VX_DLIMIT_CMD_H
11273 +
11274 +
11275 +/*  dlimit vserver commands */
11276 +
11277 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11278 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11279 +
11280 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11281 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11282 +
11283 +struct vcmd_ctx_dlimit_base_v0 {
11284 +       const char __user *name;
11285 +       uint32_t flags;
11286 +};
11287 +
11288 +struct vcmd_ctx_dlimit_v0 {
11289 +       const char __user *name;
11290 +       uint32_t space_used;                    /* used space in kbytes */
11291 +       uint32_t space_total;                   /* maximum space in kbytes */
11292 +       uint32_t inodes_used;                   /* used inodes */
11293 +       uint32_t inodes_total;                  /* maximum inodes */
11294 +       uint32_t reserved;                      /* reserved for root in % */
11295 +       uint32_t flags;
11296 +};
11297 +
11298 +#define CDLIM_UNSET            ((uint32_t)0UL)
11299 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11300 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11301 +
11302 +#define DLIME_UNIT     0
11303 +#define DLIME_KILO     1
11304 +#define DLIME_MEGA     2
11305 +#define DLIME_GIGA     3
11306 +
11307 +#define DLIMF_SHIFT    0x10
11308 +
11309 +#define DLIMS_USED     0
11310 +#define DLIMS_TOTAL    2
11311 +
11312 +static inline
11313 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11314 +{
11315 +       int exp = (flags & DLIMF_SHIFT) ?
11316 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11317 +       return val << (10LL * exp);
11318 +}
11319 +
11320 +static inline
11321 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11322 +{
11323 +       int exp = 0;
11324 +
11325 +       if (*flags & DLIMF_SHIFT) {
11326 +               while (val > (1LL << 32) && (exp < 3)) {
11327 +                       val >>= 10LL;
11328 +                       exp++;
11329 +               }
11330 +               *flags &= ~(DLIME_GIGA << shift);
11331 +               *flags |= exp << shift;
11332 +       } else
11333 +               val >>= 10LL;
11334 +       return val;
11335 +}
11336 +
11337 +#ifdef __KERNEL__
11338 +
11339 +#ifdef CONFIG_COMPAT
11340 +
11341 +#include <asm/compat.h>
11342 +
11343 +struct vcmd_ctx_dlimit_base_v0_x32 {
11344 +       compat_uptr_t name_ptr;
11345 +       uint32_t flags;
11346 +};
11347 +
11348 +struct vcmd_ctx_dlimit_v0_x32 {
11349 +       compat_uptr_t name_ptr;
11350 +       uint32_t space_used;                    /* used space in kbytes */
11351 +       uint32_t space_total;                   /* maximum space in kbytes */
11352 +       uint32_t inodes_used;                   /* used inodes */
11353 +       uint32_t inodes_total;                  /* maximum inodes */
11354 +       uint32_t reserved;                      /* reserved for root in % */
11355 +       uint32_t flags;
11356 +};
11357 +
11358 +#endif /* CONFIG_COMPAT */
11359 +
11360 +#include <linux/compiler.h>
11361 +
11362 +extern int vc_add_dlimit(uint32_t, void __user *);
11363 +extern int vc_rem_dlimit(uint32_t, void __user *);
11364 +
11365 +extern int vc_set_dlimit(uint32_t, void __user *);
11366 +extern int vc_get_dlimit(uint32_t, void __user *);
11367 +
11368 +#ifdef CONFIG_COMPAT
11369 +
11370 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11371 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11372 +
11373 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11374 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11375 +
11376 +#endif /* CONFIG_COMPAT */
11377 +
11378 +#endif /* __KERNEL__ */
11379 +#endif /* _VX_DLIMIT_CMD_H */
11380 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/dlimit.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/dlimit.h
11381 --- linux-2.6.32/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11382 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/dlimit.h   2009-12-03 20:04:56.000000000 +0100
11383 @@ -0,0 +1,54 @@
11384 +#ifndef _VX_DLIMIT_H
11385 +#define _VX_DLIMIT_H
11386 +
11387 +#include "switch.h"
11388 +
11389 +
11390 +#ifdef __KERNEL__
11391 +
11392 +/*      keep in sync with CDLIM_INFINITY       */
11393 +
11394 +#define DLIM_INFINITY          (~0ULL)
11395 +
11396 +#include <linux/spinlock.h>
11397 +#include <linux/rcupdate.h>
11398 +
11399 +struct super_block;
11400 +
11401 +struct dl_info {
11402 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11403 +       struct rcu_head dl_rcu;                 /* the rcu head */
11404 +       tag_t dl_tag;                           /* context tag */
11405 +       atomic_t dl_usecnt;                     /* usage count */
11406 +       atomic_t dl_refcnt;                     /* reference count */
11407 +
11408 +       struct super_block *dl_sb;              /* associated superblock */
11409 +
11410 +       spinlock_t dl_lock;                     /* protect the values */
11411 +
11412 +       unsigned long long dl_space_used;       /* used space in bytes */
11413 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11414 +       unsigned long dl_inodes_used;           /* used inodes */
11415 +       unsigned long dl_inodes_total;          /* maximum inodes */
11416 +
11417 +       unsigned int dl_nrlmult;                /* non root limit mult */
11418 +};
11419 +
11420 +struct rcu_head;
11421 +
11422 +extern void rcu_free_dl_info(struct rcu_head *);
11423 +extern void unhash_dl_info(struct dl_info *);
11424 +
11425 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11426 +
11427 +
11428 +struct kstatfs;
11429 +
11430 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11431 +
11432 +typedef uint64_t dlsize_t;
11433 +
11434 +#endif /* __KERNEL__ */
11435 +#else  /* _VX_DLIMIT_H */
11436 +#warning duplicate inclusion
11437 +#endif /* _VX_DLIMIT_H */
11438 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/global.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/global.h
11439 --- linux-2.6.32/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11440 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/global.h   2009-12-03 20:04:56.000000000 +0100
11441 @@ -0,0 +1,19 @@
11442 +#ifndef _VX_GLOBAL_H
11443 +#define _VX_GLOBAL_H
11444 +
11445 +
11446 +extern atomic_t vx_global_ctotal;
11447 +extern atomic_t vx_global_cactive;
11448 +
11449 +extern atomic_t nx_global_ctotal;
11450 +extern atomic_t nx_global_cactive;
11451 +
11452 +extern atomic_t vs_global_nsproxy;
11453 +extern atomic_t vs_global_fs;
11454 +extern atomic_t vs_global_mnt_ns;
11455 +extern atomic_t vs_global_uts_ns;
11456 +extern atomic_t vs_global_user_ns;
11457 +extern atomic_t vs_global_pid_ns;
11458 +
11459 +
11460 +#endif /* _VX_GLOBAL_H */
11461 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/history.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/history.h
11462 --- linux-2.6.32/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11463 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/history.h  2009-12-03 20:04:56.000000000 +0100
11464 @@ -0,0 +1,197 @@
11465 +#ifndef _VX_HISTORY_H
11466 +#define _VX_HISTORY_H
11467 +
11468 +
11469 +enum {
11470 +       VXH_UNUSED = 0,
11471 +       VXH_THROW_OOPS = 1,
11472 +
11473 +       VXH_GET_VX_INFO,
11474 +       VXH_PUT_VX_INFO,
11475 +       VXH_INIT_VX_INFO,
11476 +       VXH_SET_VX_INFO,
11477 +       VXH_CLR_VX_INFO,
11478 +       VXH_CLAIM_VX_INFO,
11479 +       VXH_RELEASE_VX_INFO,
11480 +       VXH_ALLOC_VX_INFO,
11481 +       VXH_DEALLOC_VX_INFO,
11482 +       VXH_HASH_VX_INFO,
11483 +       VXH_UNHASH_VX_INFO,
11484 +       VXH_LOC_VX_INFO,
11485 +       VXH_LOOKUP_VX_INFO,
11486 +       VXH_CREATE_VX_INFO,
11487 +};
11488 +
11489 +struct _vxhe_vxi {
11490 +       struct vx_info *ptr;
11491 +       unsigned xid;
11492 +       unsigned usecnt;
11493 +       unsigned tasks;
11494 +};
11495 +
11496 +struct _vxhe_set_clr {
11497 +       void *data;
11498 +};
11499 +
11500 +struct _vxhe_loc_lookup {
11501 +       unsigned arg;
11502 +};
11503 +
11504 +struct _vx_hist_entry {
11505 +       void *loc;
11506 +       unsigned short seq;
11507 +       unsigned short type;
11508 +       struct _vxhe_vxi vxi;
11509 +       union {
11510 +               struct _vxhe_set_clr sc;
11511 +               struct _vxhe_loc_lookup ll;
11512 +       };
11513 +};
11514 +
11515 +#ifdef CONFIG_VSERVER_HISTORY
11516 +
11517 +extern unsigned volatile int vxh_active;
11518 +
11519 +struct _vx_hist_entry *vxh_advance(void *loc);
11520 +
11521 +
11522 +static inline
11523 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11524 +{
11525 +       entry->vxi.ptr = vxi;
11526 +       if (vxi) {
11527 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11528 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11529 +               entry->vxi.xid = vxi->vx_id;
11530 +       }
11531 +}
11532 +
11533 +
11534 +#define        __HERE__ current_text_addr()
11535 +
11536 +#define __VXH_BODY(__type, __data, __here)     \
11537 +       struct _vx_hist_entry *entry;           \
11538 +                                               \
11539 +       preempt_disable();                      \
11540 +       entry = vxh_advance(__here);            \
11541 +       __data;                                 \
11542 +       entry->type = __type;                   \
11543 +       preempt_enable();
11544 +
11545 +
11546 +       /* pass vxi only */
11547 +
11548 +#define __VXH_SMPL                             \
11549 +       __vxh_copy_vxi(entry, vxi)
11550 +
11551 +static inline
11552 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11553 +{
11554 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11555 +}
11556 +
11557 +       /* pass vxi and data (void *) */
11558 +
11559 +#define __VXH_DATA                             \
11560 +       __vxh_copy_vxi(entry, vxi);             \
11561 +       entry->sc.data = data
11562 +
11563 +static inline
11564 +void   __vxh_data(struct vx_info *vxi, void *data,
11565 +                       int __type, void *__here)
11566 +{
11567 +       __VXH_BODY(__type, __VXH_DATA, __here)
11568 +}
11569 +
11570 +       /* pass vxi and arg (long) */
11571 +
11572 +#define __VXH_LONG                             \
11573 +       __vxh_copy_vxi(entry, vxi);             \
11574 +       entry->ll.arg = arg
11575 +
11576 +static inline
11577 +void   __vxh_long(struct vx_info *vxi, long arg,
11578 +                       int __type, void *__here)
11579 +{
11580 +       __VXH_BODY(__type, __VXH_LONG, __here)
11581 +}
11582 +
11583 +
11584 +static inline
11585 +void   __vxh_throw_oops(void *__here)
11586 +{
11587 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11588 +       /* prevent further acquisition */
11589 +       vxh_active = 0;
11590 +}
11591 +
11592 +
11593 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11594 +
11595 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11596 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11597 +
11598 +#define __vxh_init_vx_info(v, d, h) \
11599 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11600 +#define __vxh_set_vx_info(v, d, h) \
11601 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11602 +#define __vxh_clr_vx_info(v, d, h) \
11603 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11604 +
11605 +#define __vxh_claim_vx_info(v, d, h) \
11606 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11607 +#define __vxh_release_vx_info(v, d, h) \
11608 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11609 +
11610 +#define vxh_alloc_vx_info(v) \
11611 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11612 +#define vxh_dealloc_vx_info(v) \
11613 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11614 +
11615 +#define vxh_hash_vx_info(v) \
11616 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11617 +#define vxh_unhash_vx_info(v) \
11618 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11619 +
11620 +#define vxh_loc_vx_info(v, l) \
11621 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11622 +#define vxh_lookup_vx_info(v, l) \
11623 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11624 +#define vxh_create_vx_info(v, l) \
11625 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11626 +
11627 +extern void vxh_dump_history(void);
11628 +
11629 +
11630 +#else  /* CONFIG_VSERVER_HISTORY */
11631 +
11632 +#define        __HERE__        0
11633 +
11634 +#define vxh_throw_oops()               do { } while (0)
11635 +
11636 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11637 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11638 +
11639 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11640 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11641 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11642 +
11643 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11644 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11645 +
11646 +#define vxh_alloc_vx_info(v)           do { } while (0)
11647 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11648 +
11649 +#define vxh_hash_vx_info(v)            do { } while (0)
11650 +#define vxh_unhash_vx_info(v)          do { } while (0)
11651 +
11652 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11653 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11654 +#define vxh_create_vx_info(v, l)       do { } while (0)
11655 +
11656 +#define vxh_dump_history()             do { } while (0)
11657 +
11658 +
11659 +#endif /* CONFIG_VSERVER_HISTORY */
11660 +
11661 +#endif /* _VX_HISTORY_H */
11662 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/inode_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/inode_cmd.h
11663 --- linux-2.6.32/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11664 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/inode_cmd.h        2009-12-03 20:04:56.000000000 +0100
11665 @@ -0,0 +1,59 @@
11666 +#ifndef _VX_INODE_CMD_H
11667 +#define _VX_INODE_CMD_H
11668 +
11669 +
11670 +/*  inode vserver commands */
11671 +
11672 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11673 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11674 +
11675 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11676 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11677 +
11678 +struct vcmd_ctx_iattr_v1 {
11679 +       const char __user *name;
11680 +       uint32_t tag;
11681 +       uint32_t flags;
11682 +       uint32_t mask;
11683 +};
11684 +
11685 +struct vcmd_ctx_fiattr_v0 {
11686 +       uint32_t tag;
11687 +       uint32_t flags;
11688 +       uint32_t mask;
11689 +};
11690 +
11691 +
11692 +#ifdef __KERNEL__
11693 +
11694 +
11695 +#ifdef CONFIG_COMPAT
11696 +
11697 +#include <asm/compat.h>
11698 +
11699 +struct vcmd_ctx_iattr_v1_x32 {
11700 +       compat_uptr_t name_ptr;
11701 +       uint32_t tag;
11702 +       uint32_t flags;
11703 +       uint32_t mask;
11704 +};
11705 +
11706 +#endif /* CONFIG_COMPAT */
11707 +
11708 +#include <linux/compiler.h>
11709 +
11710 +extern int vc_get_iattr(void __user *);
11711 +extern int vc_set_iattr(void __user *);
11712 +
11713 +extern int vc_fget_iattr(uint32_t, void __user *);
11714 +extern int vc_fset_iattr(uint32_t, void __user *);
11715 +
11716 +#ifdef CONFIG_COMPAT
11717 +
11718 +extern int vc_get_iattr_x32(void __user *);
11719 +extern int vc_set_iattr_x32(void __user *);
11720 +
11721 +#endif /* CONFIG_COMPAT */
11722 +
11723 +#endif /* __KERNEL__ */
11724 +#endif /* _VX_INODE_CMD_H */
11725 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/inode.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/inode.h
11726 --- linux-2.6.32/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11727 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/inode.h    2009-12-03 20:04:56.000000000 +0100
11728 @@ -0,0 +1,39 @@
11729 +#ifndef _VX_INODE_H
11730 +#define _VX_INODE_H
11731 +
11732 +
11733 +#define IATTR_TAG      0x01000000
11734 +
11735 +#define IATTR_ADMIN    0x00000001
11736 +#define IATTR_WATCH    0x00000002
11737 +#define IATTR_HIDE     0x00000004
11738 +#define IATTR_FLAGS    0x00000007
11739 +
11740 +#define IATTR_BARRIER  0x00010000
11741 +#define IATTR_IXUNLINK 0x00020000
11742 +#define IATTR_IMMUTABLE 0x00040000
11743 +#define IATTR_COW      0x00080000
11744 +
11745 +#ifdef __KERNEL__
11746 +
11747 +
11748 +#ifdef CONFIG_VSERVER_PROC_SECURE
11749 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11750 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11751 +#else
11752 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11753 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11754 +#endif
11755 +
11756 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11757 +
11758 +#endif /* __KERNEL__ */
11759 +
11760 +/* inode ioctls */
11761 +
11762 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11763 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11764 +
11765 +#else  /* _VX_INODE_H */
11766 +#warning duplicate inclusion
11767 +#endif /* _VX_INODE_H */
11768 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/Kbuild linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/Kbuild
11769 --- linux-2.6.32/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11770 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/Kbuild     2009-12-03 20:04:56.000000000 +0100
11771 @@ -0,0 +1,8 @@
11772 +
11773 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11774 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11775 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11776 +       debug_cmd.h device_cmd.h
11777 +
11778 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11779 +
11780 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/limit_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit_cmd.h
11781 --- linux-2.6.32/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11782 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit_cmd.h        2009-12-03 20:04:56.000000000 +0100
11783 @@ -0,0 +1,71 @@
11784 +#ifndef _VX_LIMIT_CMD_H
11785 +#define _VX_LIMIT_CMD_H
11786 +
11787 +
11788 +/*  rlimit vserver commands */
11789 +
11790 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11791 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11792 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11793 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11794 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11795 +
11796 +struct vcmd_ctx_rlimit_v0 {
11797 +       uint32_t id;
11798 +       uint64_t minimum;
11799 +       uint64_t softlimit;
11800 +       uint64_t maximum;
11801 +};
11802 +
11803 +struct vcmd_ctx_rlimit_mask_v0 {
11804 +       uint32_t minimum;
11805 +       uint32_t softlimit;
11806 +       uint32_t maximum;
11807 +};
11808 +
11809 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11810 +
11811 +struct vcmd_rlimit_stat_v0 {
11812 +       uint32_t id;
11813 +       uint32_t hits;
11814 +       uint64_t value;
11815 +       uint64_t minimum;
11816 +       uint64_t maximum;
11817 +};
11818 +
11819 +#define CRLIM_UNSET            (0ULL)
11820 +#define CRLIM_INFINITY         (~0ULL)
11821 +#define CRLIM_KEEP             (~1ULL)
11822 +
11823 +#ifdef __KERNEL__
11824 +
11825 +#ifdef CONFIG_IA32_EMULATION
11826 +
11827 +struct vcmd_ctx_rlimit_v0_x32 {
11828 +       uint32_t id;
11829 +       uint64_t minimum;
11830 +       uint64_t softlimit;
11831 +       uint64_t maximum;
11832 +} __attribute__ ((packed));
11833 +
11834 +#endif /* CONFIG_IA32_EMULATION */
11835 +
11836 +#include <linux/compiler.h>
11837 +
11838 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11839 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11840 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11841 +extern int vc_reset_hits(struct vx_info *, void __user *);
11842 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11843 +
11844 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11845 +
11846 +#ifdef CONFIG_IA32_EMULATION
11847 +
11848 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11849 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11850 +
11851 +#endif /* CONFIG_IA32_EMULATION */
11852 +
11853 +#endif /* __KERNEL__ */
11854 +#endif /* _VX_LIMIT_CMD_H */
11855 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/limit_def.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit_def.h
11856 --- linux-2.6.32/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11857 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit_def.h        2009-12-03 20:04:56.000000000 +0100
11858 @@ -0,0 +1,47 @@
11859 +#ifndef _VX_LIMIT_DEF_H
11860 +#define _VX_LIMIT_DEF_H
11861 +
11862 +#include <asm/atomic.h>
11863 +#include <asm/resource.h>
11864 +
11865 +#include "limit.h"
11866 +
11867 +
11868 +struct _vx_res_limit {
11869 +       rlim_t soft;            /* Context soft limit */
11870 +       rlim_t hard;            /* Context hard limit */
11871 +
11872 +       rlim_atomic_t rcur;     /* Current value */
11873 +       rlim_t rmin;            /* Context minimum */
11874 +       rlim_t rmax;            /* Context maximum */
11875 +
11876 +       atomic_t lhit;          /* Limit hits */
11877 +};
11878 +
11879 +/* context sub struct */
11880 +
11881 +struct _vx_limit {
11882 +       struct _vx_res_limit res[NUM_LIMITS];
11883 +};
11884 +
11885 +#ifdef CONFIG_VSERVER_DEBUG
11886 +
11887 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11888 +{
11889 +       int i;
11890 +
11891 +       printk("\t_vx_limit:");
11892 +       for (i = 0; i < NUM_LIMITS; i++) {
11893 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11894 +                       i, (unsigned long)__rlim_get(limit, i),
11895 +                       (unsigned long)__rlim_rmin(limit, i),
11896 +                       (unsigned long)__rlim_rmax(limit, i),
11897 +                       (long)__rlim_soft(limit, i),
11898 +                       (long)__rlim_hard(limit, i),
11899 +                       atomic_read(&__rlim_lhit(limit, i)));
11900 +       }
11901 +}
11902 +
11903 +#endif
11904 +
11905 +#endif /* _VX_LIMIT_DEF_H */
11906 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/limit.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit.h
11907 --- linux-2.6.32/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11908 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit.h    2009-12-03 20:04:56.000000000 +0100
11909 @@ -0,0 +1,70 @@
11910 +#ifndef _VX_LIMIT_H
11911 +#define _VX_LIMIT_H
11912 +
11913 +#define VLIMIT_NSOCK   16
11914 +#define VLIMIT_OPENFD  17
11915 +#define VLIMIT_ANON    18
11916 +#define VLIMIT_SHMEM   19
11917 +#define VLIMIT_SEMARY  20
11918 +#define VLIMIT_NSEMS   21
11919 +#define VLIMIT_DENTRY  22
11920 +#define VLIMIT_MAPPED  23
11921 +
11922 +
11923 +#ifdef __KERNEL__
11924 +
11925 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11926 +
11927 +/*     keep in sync with CRLIM_INFINITY */
11928 +
11929 +#define        VLIM_INFINITY   (~0ULL)
11930 +
11931 +#include <asm/atomic.h>
11932 +#include <asm/resource.h>
11933 +
11934 +#ifndef RLIM_INFINITY
11935 +#warning RLIM_INFINITY is undefined
11936 +#endif
11937 +
11938 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11939 +
11940 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11941 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11942 +
11943 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11944 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11945 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11946 +
11947 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11948 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11949 +
11950 +typedef atomic_long_t rlim_atomic_t;
11951 +typedef unsigned long rlim_t;
11952 +
11953 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11954 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11955 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11956 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11957 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11958 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11959 +
11960 +
11961 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11962 +#define        VX_VLIM(r) ((long long)(long)(r))
11963 +#define        VX_RLIM(v) ((rlim_t)(v))
11964 +#else
11965 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11966 +               ? VLIM_INFINITY : (long long)(r))
11967 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11968 +               ? RLIM_INFINITY : (rlim_t)(v))
11969 +#endif
11970 +
11971 +struct sysinfo;
11972 +
11973 +void vx_vsi_meminfo(struct sysinfo *);
11974 +void vx_vsi_swapinfo(struct sysinfo *);
11975 +
11976 +#define NUM_LIMITS     24
11977 +
11978 +#endif /* __KERNEL__ */
11979 +#endif /* _VX_LIMIT_H */
11980 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/limit_int.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit_int.h
11981 --- linux-2.6.32/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11982 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/limit_int.h        2009-12-03 20:04:56.000000000 +0100
11983 @@ -0,0 +1,198 @@
11984 +#ifndef _VX_LIMIT_INT_H
11985 +#define _VX_LIMIT_INT_H
11986 +
11987 +#include "context.h"
11988 +
11989 +#ifdef __KERNEL__
11990 +
11991 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11992 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11993 +
11994 +extern const char *vlimit_name[NUM_LIMITS];
11995 +
11996 +static inline void __vx_acc_cres(struct vx_info *vxi,
11997 +       int res, int dir, void *_data, char *_file, int _line)
11998 +{
11999 +       if (VXD_RCRES_COND(res))
12000 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12001 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12002 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12003 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12004 +       if (!vxi)
12005 +               return;
12006 +
12007 +       if (dir > 0)
12008 +               __rlim_inc(&vxi->limit, res);
12009 +       else
12010 +               __rlim_dec(&vxi->limit, res);
12011 +}
12012 +
12013 +static inline void __vx_add_cres(struct vx_info *vxi,
12014 +       int res, int amount, void *_data, char *_file, int _line)
12015 +{
12016 +       if (VXD_RCRES_COND(res))
12017 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12018 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12019 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12020 +                       amount, _data, _file, _line);
12021 +       if (amount == 0)
12022 +               return;
12023 +       if (!vxi)
12024 +               return;
12025 +       __rlim_add(&vxi->limit, res, amount);
12026 +}
12027 +
12028 +static inline
12029 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12030 +{
12031 +       int cond = (value > __rlim_rmax(limit, res));
12032 +
12033 +       if (cond)
12034 +               __rlim_rmax(limit, res) = value;
12035 +       return cond;
12036 +}
12037 +
12038 +static inline
12039 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12040 +{
12041 +       int cond = (value < __rlim_rmin(limit, res));
12042 +
12043 +       if (cond)
12044 +               __rlim_rmin(limit, res) = value;
12045 +       return cond;
12046 +}
12047 +
12048 +static inline
12049 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12050 +{
12051 +       if (!__vx_cres_adjust_max(limit, res, value))
12052 +               __vx_cres_adjust_min(limit, res, value);
12053 +}
12054 +
12055 +
12056 +/*     return values:
12057 +        +1 ... no limit hit
12058 +        -1 ... over soft limit
12059 +         0 ... over hard limit         */
12060 +
12061 +static inline int __vx_cres_avail(struct vx_info *vxi,
12062 +       int res, int num, char *_file, int _line)
12063 +{
12064 +       struct _vx_limit *limit;
12065 +       rlim_t value;
12066 +
12067 +       if (VXD_RLIMIT_COND(res))
12068 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12069 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12070 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12071 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12072 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12073 +                       num, _file, _line);
12074 +       if (!vxi)
12075 +               return 1;
12076 +
12077 +       limit = &vxi->limit;
12078 +       value = __rlim_get(limit, res);
12079 +
12080 +       if (!__vx_cres_adjust_max(limit, res, value))
12081 +               __vx_cres_adjust_min(limit, res, value);
12082 +
12083 +       if (num == 0)
12084 +               return 1;
12085 +
12086 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12087 +               return -1;
12088 +       if (value + num <= __rlim_soft(limit, res))
12089 +               return -1;
12090 +
12091 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12092 +               return 1;
12093 +       if (value + num <= __rlim_hard(limit, res))
12094 +               return 1;
12095 +
12096 +       __rlim_hit(limit, res);
12097 +       return 0;
12098 +}
12099 +
12100 +
12101 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12102 +
12103 +static inline
12104 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12105 +{
12106 +       rlim_t value, sum = 0;
12107 +       int res;
12108 +
12109 +       while ((res = *array++)) {
12110 +               value = __rlim_get(limit, res);
12111 +               __vx_cres_fixup(limit, res, value);
12112 +               sum += value;
12113 +       }
12114 +       return sum;
12115 +}
12116 +
12117 +static inline
12118 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12119 +{
12120 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12121 +       int res = *array;
12122 +
12123 +       if (value == __rlim_get(limit, res))
12124 +               return value;
12125 +
12126 +       __rlim_set(limit, res, value);
12127 +       /* now adjust min/max */
12128 +       if (!__vx_cres_adjust_max(limit, res, value))
12129 +               __vx_cres_adjust_min(limit, res, value);
12130 +
12131 +       return value;
12132 +}
12133 +
12134 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12135 +       const int *array, int num, char *_file, int _line)
12136 +{
12137 +       struct _vx_limit *limit;
12138 +       rlim_t value = 0;
12139 +       int res;
12140 +
12141 +       if (num == 0)
12142 +               return 1;
12143 +       if (!vxi)
12144 +               return 1;
12145 +
12146 +       limit = &vxi->limit;
12147 +       res = *array;
12148 +       value = __vx_cres_array_sum(limit, array + 1);
12149 +
12150 +       __rlim_set(limit, res, value);
12151 +       __vx_cres_fixup(limit, res, value);
12152 +
12153 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12154 +}
12155 +
12156 +
12157 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12158 +{
12159 +       rlim_t value;
12160 +       int res;
12161 +
12162 +       /* complex resources first */
12163 +       if ((id < 0) || (id == RLIMIT_RSS))
12164 +               __vx_cres_array_fixup(limit, VLA_RSS);
12165 +
12166 +       for (res = 0; res < NUM_LIMITS; res++) {
12167 +               if ((id > 0) && (res != id))
12168 +                       continue;
12169 +
12170 +               value = __rlim_get(limit, res);
12171 +               __vx_cres_fixup(limit, res, value);
12172 +
12173 +               /* not supposed to happen, maybe warn? */
12174 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12175 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12176 +       }
12177 +}
12178 +
12179 +
12180 +#endif /* __KERNEL__ */
12181 +#endif /* _VX_LIMIT_INT_H */
12182 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/monitor.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/monitor.h
12183 --- linux-2.6.32/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12184 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/monitor.h  2009-12-03 20:04:56.000000000 +0100
12185 @@ -0,0 +1,96 @@
12186 +#ifndef _VX_MONITOR_H
12187 +#define _VX_MONITOR_H
12188 +
12189 +#include <linux/types.h>
12190 +
12191 +enum {
12192 +       VXM_UNUSED = 0,
12193 +
12194 +       VXM_SYNC = 0x10,
12195 +
12196 +       VXM_UPDATE = 0x20,
12197 +       VXM_UPDATE_1,
12198 +       VXM_UPDATE_2,
12199 +
12200 +       VXM_RQINFO_1 = 0x24,
12201 +       VXM_RQINFO_2,
12202 +
12203 +       VXM_ACTIVATE = 0x40,
12204 +       VXM_DEACTIVATE,
12205 +       VXM_IDLE,
12206 +
12207 +       VXM_HOLD = 0x44,
12208 +       VXM_UNHOLD,
12209 +
12210 +       VXM_MIGRATE = 0x48,
12211 +       VXM_RESCHED,
12212 +
12213 +       /* all other bits are flags */
12214 +       VXM_SCHED = 0x80,
12215 +};
12216 +
12217 +struct _vxm_update_1 {
12218 +       uint32_t tokens_max;
12219 +       uint32_t fill_rate;
12220 +       uint32_t interval;
12221 +};
12222 +
12223 +struct _vxm_update_2 {
12224 +       uint32_t tokens_min;
12225 +       uint32_t fill_rate;
12226 +       uint32_t interval;
12227 +};
12228 +
12229 +struct _vxm_rqinfo_1 {
12230 +       uint16_t running;
12231 +       uint16_t onhold;
12232 +       uint16_t iowait;
12233 +       uint16_t uintr;
12234 +       uint32_t idle_tokens;
12235 +};
12236 +
12237 +struct _vxm_rqinfo_2 {
12238 +       uint32_t norm_time;
12239 +       uint32_t idle_time;
12240 +       uint32_t idle_skip;
12241 +};
12242 +
12243 +struct _vxm_sched {
12244 +       uint32_t tokens;
12245 +       uint32_t norm_time;
12246 +       uint32_t idle_time;
12247 +};
12248 +
12249 +struct _vxm_task {
12250 +       uint16_t pid;
12251 +       uint16_t state;
12252 +};
12253 +
12254 +struct _vxm_event {
12255 +       uint32_t jif;
12256 +       union {
12257 +               uint32_t seq;
12258 +               uint32_t sec;
12259 +       };
12260 +       union {
12261 +               uint32_t tokens;
12262 +               uint32_t nsec;
12263 +               struct _vxm_task tsk;
12264 +       };
12265 +};
12266 +
12267 +struct _vx_mon_entry {
12268 +       uint16_t type;
12269 +       uint16_t xid;
12270 +       union {
12271 +               struct _vxm_event ev;
12272 +               struct _vxm_sched sd;
12273 +               struct _vxm_update_1 u1;
12274 +               struct _vxm_update_2 u2;
12275 +               struct _vxm_rqinfo_1 q1;
12276 +               struct _vxm_rqinfo_2 q2;
12277 +       };
12278 +};
12279 +
12280 +
12281 +#endif /* _VX_MONITOR_H */
12282 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/network_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/network_cmd.h
12283 --- linux-2.6.32/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12284 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/network_cmd.h      2009-12-03 20:04:56.000000000 +0100
12285 @@ -0,0 +1,150 @@
12286 +#ifndef _VX_NETWORK_CMD_H
12287 +#define _VX_NETWORK_CMD_H
12288 +
12289 +
12290 +/* vinfo commands */
12291 +
12292 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12293 +
12294 +#ifdef __KERNEL__
12295 +extern int vc_task_nid(uint32_t);
12296 +
12297 +#endif /* __KERNEL__ */
12298 +
12299 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12300 +
12301 +struct vcmd_nx_info_v0 {
12302 +       uint32_t nid;
12303 +       /* more to come */
12304 +};
12305 +
12306 +#ifdef __KERNEL__
12307 +extern int vc_nx_info(struct nx_info *, void __user *);
12308 +
12309 +#endif /* __KERNEL__ */
12310 +
12311 +#include <linux/in.h>
12312 +#include <linux/in6.h>
12313 +
12314 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12315 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12316 +
12317 +struct  vcmd_net_create {
12318 +       uint64_t flagword;
12319 +};
12320 +
12321 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12322 +
12323 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12324 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12325 +
12326 +struct vcmd_net_addr_v0 {
12327 +       uint16_t type;
12328 +       uint16_t count;
12329 +       struct in_addr ip[4];
12330 +       struct in_addr mask[4];
12331 +};
12332 +
12333 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12334 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12335 +
12336 +struct vcmd_net_addr_ipv4_v1 {
12337 +       uint16_t type;
12338 +       uint16_t flags;
12339 +       struct in_addr ip;
12340 +       struct in_addr mask;
12341 +};
12342 +
12343 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12344 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12345 +
12346 +struct vcmd_net_addr_ipv6_v1 {
12347 +       uint16_t type;
12348 +       uint16_t flags;
12349 +       uint32_t prefix;
12350 +       struct in6_addr ip;
12351 +       struct in6_addr mask;
12352 +};
12353 +
12354 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12355 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12356 +
12357 +struct vcmd_match_ipv4_v0 {
12358 +       uint16_t type;
12359 +       uint16_t flags;
12360 +       uint16_t parent;
12361 +       uint16_t prefix;
12362 +       struct in_addr ip;
12363 +       struct in_addr ip2;
12364 +       struct in_addr mask;
12365 +};
12366 +
12367 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12368 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12369 +
12370 +struct vcmd_match_ipv6_v0 {
12371 +       uint16_t type;
12372 +       uint16_t flags;
12373 +       uint16_t parent;
12374 +       uint16_t prefix;
12375 +       struct in6_addr ip;
12376 +       struct in6_addr ip2;
12377 +       struct in6_addr mask;
12378 +};
12379 +
12380 +
12381 +#ifdef __KERNEL__
12382 +extern int vc_net_create(uint32_t, void __user *);
12383 +extern int vc_net_migrate(struct nx_info *, void __user *);
12384 +
12385 +extern int vc_net_add(struct nx_info *, void __user *);
12386 +extern int vc_net_remove(struct nx_info *, void __user *);
12387 +
12388 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12389 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12390 +
12391 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12392 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12393 +
12394 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12395 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12396 +
12397 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12398 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12399 +
12400 +#endif /* __KERNEL__ */
12401 +
12402 +
12403 +/* flag commands */
12404 +
12405 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12406 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12407 +
12408 +struct vcmd_net_flags_v0 {
12409 +       uint64_t flagword;
12410 +       uint64_t mask;
12411 +};
12412 +
12413 +#ifdef __KERNEL__
12414 +extern int vc_get_nflags(struct nx_info *, void __user *);
12415 +extern int vc_set_nflags(struct nx_info *, void __user *);
12416 +
12417 +#endif /* __KERNEL__ */
12418 +
12419 +
12420 +/* network caps commands */
12421 +
12422 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12423 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12424 +
12425 +struct vcmd_net_caps_v0 {
12426 +       uint64_t ncaps;
12427 +       uint64_t cmask;
12428 +};
12429 +
12430 +#ifdef __KERNEL__
12431 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12432 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12433 +
12434 +#endif /* __KERNEL__ */
12435 +#endif /* _VX_CONTEXT_CMD_H */
12436 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/network.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/network.h
12437 --- linux-2.6.32/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12438 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/network.h  2009-12-03 20:04:56.000000000 +0100
12439 @@ -0,0 +1,146 @@
12440 +#ifndef _VX_NETWORK_H
12441 +#define _VX_NETWORK_H
12442 +
12443 +#include <linux/types.h>
12444 +
12445 +
12446 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12447 +
12448 +
12449 +/* network flags */
12450 +
12451 +#define NXF_INFO_PRIVATE       0x00000008
12452 +
12453 +#define NXF_SINGLE_IP          0x00000100
12454 +#define NXF_LBACK_REMAP                0x00000200
12455 +#define NXF_LBACK_ALLOW                0x00000400
12456 +
12457 +#define NXF_HIDE_NETIF         0x02000000
12458 +#define NXF_HIDE_LBACK         0x04000000
12459 +
12460 +#define NXF_STATE_SETUP                (1ULL << 32)
12461 +#define NXF_STATE_ADMIN                (1ULL << 34)
12462 +
12463 +#define NXF_SC_HELPER          (1ULL << 36)
12464 +#define NXF_PERSISTENT         (1ULL << 38)
12465 +
12466 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12467 +
12468 +
12469 +#define        NXF_INIT_SET            (__nxf_init_set())
12470 +
12471 +static inline uint64_t __nxf_init_set(void) {
12472 +       return    NXF_STATE_ADMIN
12473 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12474 +               | NXF_LBACK_REMAP
12475 +               | NXF_HIDE_LBACK
12476 +#endif
12477 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12478 +               | NXF_SINGLE_IP
12479 +#endif
12480 +               | NXF_HIDE_NETIF;
12481 +}
12482 +
12483 +
12484 +/* network caps */
12485 +
12486 +#define NXC_TUN_CREATE         0x00000001
12487 +
12488 +#define NXC_RAW_ICMP           0x00000100
12489 +
12490 +
12491 +/* address types */
12492 +
12493 +#define NXA_TYPE_IPV4          0x0001
12494 +#define NXA_TYPE_IPV6          0x0002
12495 +
12496 +#define NXA_TYPE_NONE          0x0000
12497 +#define NXA_TYPE_ANY           0x00FF
12498 +
12499 +#define NXA_TYPE_ADDR          0x0010
12500 +#define NXA_TYPE_MASK          0x0020
12501 +#define NXA_TYPE_RANGE         0x0040
12502 +
12503 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12504 +
12505 +#define NXA_MOD_BCAST          0x0100
12506 +#define NXA_MOD_LBACK          0x0200
12507 +
12508 +#define NXA_LOOPBACK           0x1000
12509 +
12510 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12511 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12512 +
12513 +#ifdef __KERNEL__
12514 +
12515 +#include <linux/list.h>
12516 +#include <linux/spinlock.h>
12517 +#include <linux/rcupdate.h>
12518 +#include <linux/in.h>
12519 +#include <linux/in6.h>
12520 +#include <asm/atomic.h>
12521 +
12522 +struct nx_addr_v4 {
12523 +       struct nx_addr_v4 *next;
12524 +       struct in_addr ip[2];
12525 +       struct in_addr mask;
12526 +       uint16_t type;
12527 +       uint16_t flags;
12528 +};
12529 +
12530 +struct nx_addr_v6 {
12531 +       struct nx_addr_v6 *next;
12532 +       struct in6_addr ip;
12533 +       struct in6_addr mask;
12534 +       uint32_t prefix;
12535 +       uint16_t type;
12536 +       uint16_t flags;
12537 +};
12538 +
12539 +struct nx_info {
12540 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12541 +       nid_t nx_id;                    /* vnet id */
12542 +       atomic_t nx_usecnt;             /* usage count */
12543 +       atomic_t nx_tasks;              /* tasks count */
12544 +       int nx_state;                   /* context state */
12545 +
12546 +       uint64_t nx_flags;              /* network flag word */
12547 +       uint64_t nx_ncaps;              /* network capabilities */
12548 +
12549 +       struct in_addr v4_lback;        /* Loopback address */
12550 +       struct in_addr v4_bcast;        /* Broadcast address */
12551 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12552 +#ifdef CONFIG_IPV6
12553 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12554 +#endif
12555 +       char nx_name[65];               /* network context name */
12556 +};
12557 +
12558 +
12559 +/* status flags */
12560 +
12561 +#define NXS_HASHED      0x0001
12562 +#define NXS_SHUTDOWN    0x0100
12563 +#define NXS_RELEASED    0x8000
12564 +
12565 +extern struct nx_info *lookup_nx_info(int);
12566 +
12567 +extern int get_nid_list(int, unsigned int *, int);
12568 +extern int nid_is_hashed(nid_t);
12569 +
12570 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12571 +
12572 +extern long vs_net_change(struct nx_info *, unsigned int);
12573 +
12574 +struct sock;
12575 +
12576 +
12577 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12578 +#ifdef  CONFIG_IPV6
12579 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12580 +#else
12581 +#define NX_IPV6(n)     (0)
12582 +#endif
12583 +
12584 +#endif /* __KERNEL__ */
12585 +#endif /* _VX_NETWORK_H */
12586 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/percpu.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/percpu.h
12587 --- linux-2.6.32/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12588 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/percpu.h   2009-12-03 20:04:56.000000000 +0100
12589 @@ -0,0 +1,14 @@
12590 +#ifndef _VX_PERCPU_H
12591 +#define _VX_PERCPU_H
12592 +
12593 +#include "cvirt_def.h"
12594 +#include "sched_def.h"
12595 +
12596 +struct _vx_percpu {
12597 +       struct _vx_cvirt_pc cvirt;
12598 +       struct _vx_sched_pc sched;
12599 +};
12600 +
12601 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12602 +
12603 +#endif /* _VX_PERCPU_H */
12604 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/pid.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/pid.h
12605 --- linux-2.6.32/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12606 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/pid.h      2009-12-03 20:04:56.000000000 +0100
12607 @@ -0,0 +1,51 @@
12608 +#ifndef _VSERVER_PID_H
12609 +#define _VSERVER_PID_H
12610 +
12611 +/* pid faking stuff */
12612 +
12613 +#define vx_info_map_pid(v, p) \
12614 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12615 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12616 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12617 +#define vx_map_tgid(p) vx_map_pid(p)
12618 +
12619 +static inline int __vx_info_map_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_map_tgid: %p/%llx: %d -> %d",
12625 +                       vxi, (long long)vxi->vx_flags, pid,
12626 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12627 +                       func, file, line);
12628 +               if (pid == 0)
12629 +                       return 0;
12630 +               if (pid == vxi->vx_initpid)
12631 +                       return 1;
12632 +       }
12633 +       return pid;
12634 +}
12635 +
12636 +#define vx_info_rmap_pid(v, p) \
12637 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12638 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12639 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12640 +
12641 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12642 +       const char *func, const char *file, int line)
12643 +{
12644 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12645 +               vxfprintk(VXD_CBIT(cvirt, 2),
12646 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12647 +                       vxi, (long long)vxi->vx_flags, pid,
12648 +                       (pid == 1) ? vxi->vx_initpid : pid,
12649 +                       func, file, line);
12650 +               if ((pid == 1) && vxi->vx_initpid)
12651 +                       return vxi->vx_initpid;
12652 +               if (pid == vxi->vx_initpid)
12653 +                       return ~0U;
12654 +       }
12655 +       return pid;
12656 +}
12657 +
12658 +#endif
12659 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/sched_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/sched_cmd.h
12660 --- linux-2.6.32/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12661 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/sched_cmd.h        2009-12-03 20:04:56.000000000 +0100
12662 @@ -0,0 +1,108 @@
12663 +#ifndef _VX_SCHED_CMD_H
12664 +#define _VX_SCHED_CMD_H
12665 +
12666 +
12667 +/*  sched vserver commands */
12668 +
12669 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12670 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12671 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12672 +
12673 +struct vcmd_set_sched_v2 {
12674 +       int32_t fill_rate;
12675 +       int32_t interval;
12676 +       int32_t tokens;
12677 +       int32_t tokens_min;
12678 +       int32_t tokens_max;
12679 +       uint64_t cpu_mask;
12680 +};
12681 +
12682 +struct vcmd_set_sched_v3 {
12683 +       uint32_t set_mask;
12684 +       int32_t fill_rate;
12685 +       int32_t interval;
12686 +       int32_t tokens;
12687 +       int32_t tokens_min;
12688 +       int32_t tokens_max;
12689 +       int32_t priority_bias;
12690 +};
12691 +
12692 +struct vcmd_set_sched_v4 {
12693 +       uint32_t set_mask;
12694 +       int32_t fill_rate;
12695 +       int32_t interval;
12696 +       int32_t tokens;
12697 +       int32_t tokens_min;
12698 +       int32_t tokens_max;
12699 +       int32_t prio_bias;
12700 +       int32_t cpu_id;
12701 +       int32_t bucket_id;
12702 +};
12703 +
12704 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12705 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12706 +
12707 +struct vcmd_sched_v5 {
12708 +       uint32_t mask;
12709 +       int32_t cpu_id;
12710 +       int32_t bucket_id;
12711 +       int32_t fill_rate[2];
12712 +       int32_t interval[2];
12713 +       int32_t tokens;
12714 +       int32_t tokens_min;
12715 +       int32_t tokens_max;
12716 +       int32_t prio_bias;
12717 +};
12718 +
12719 +#define VXSM_FILL_RATE         0x0001
12720 +#define VXSM_INTERVAL          0x0002
12721 +#define VXSM_FILL_RATE2                0x0004
12722 +#define VXSM_INTERVAL2         0x0008
12723 +#define VXSM_TOKENS            0x0010
12724 +#define VXSM_TOKENS_MIN                0x0020
12725 +#define VXSM_TOKENS_MAX                0x0040
12726 +#define VXSM_PRIO_BIAS         0x0100
12727 +
12728 +#define VXSM_IDLE_TIME         0x0200
12729 +#define VXSM_FORCE             0x0400
12730 +
12731 +#define        VXSM_V3_MASK            0x0173
12732 +#define        VXSM_SET_MASK           0x01FF
12733 +
12734 +#define VXSM_CPU_ID            0x1000
12735 +#define VXSM_BUCKET_ID         0x2000
12736 +
12737 +#define VXSM_MSEC              0x4000
12738 +
12739 +#define SCHED_KEEP             (-2)    /* only for v2 */
12740 +
12741 +#ifdef __KERNEL__
12742 +
12743 +#include <linux/compiler.h>
12744 +
12745 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12746 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12747 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12748 +extern int vc_set_sched(struct vx_info *, void __user *);
12749 +extern int vc_get_sched(struct vx_info *, void __user *);
12750 +
12751 +#endif /* __KERNEL__ */
12752 +
12753 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12754 +
12755 +struct vcmd_sched_info {
12756 +       int32_t cpu_id;
12757 +       int32_t bucket_id;
12758 +       uint64_t user_msec;
12759 +       uint64_t sys_msec;
12760 +       uint64_t hold_msec;
12761 +       uint32_t token_usec;
12762 +       int32_t vavavoom;
12763 +};
12764 +
12765 +#ifdef __KERNEL__
12766 +
12767 +extern int vc_sched_info(struct vx_info *, void __user *);
12768 +
12769 +#endif /* __KERNEL__ */
12770 +#endif /* _VX_SCHED_CMD_H */
12771 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/sched_def.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/sched_def.h
12772 --- linux-2.6.32/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12773 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/sched_def.h        2009-12-03 20:04:56.000000000 +0100
12774 @@ -0,0 +1,68 @@
12775 +#ifndef _VX_SCHED_DEF_H
12776 +#define _VX_SCHED_DEF_H
12777 +
12778 +#include <linux/spinlock.h>
12779 +#include <linux/jiffies.h>
12780 +#include <linux/cpumask.h>
12781 +#include <asm/atomic.h>
12782 +#include <asm/param.h>
12783 +
12784 +
12785 +/* context sub struct */
12786 +
12787 +struct _vx_sched {
12788 +       spinlock_t tokens_lock;         /* lock for token bucket */
12789 +
12790 +       int tokens;                     /* number of CPU tokens */
12791 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12792 +       int interval[2];                /* Divisor:   per Y jiffies   */
12793 +       int tokens_min;                 /* Limit:     minimum for unhold */
12794 +       int tokens_max;                 /* Limit:     no more than N tokens */
12795 +
12796 +       int prio_bias;                  /* bias offset for priority */
12797 +
12798 +       unsigned update_mask;           /* which features should be updated */
12799 +       cpumask_t update;               /* CPUs which should update */
12800 +};
12801 +
12802 +struct _vx_sched_pc {
12803 +       int tokens;                     /* number of CPU tokens */
12804 +       int flags;                      /* bucket flags */
12805 +
12806 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12807 +       int interval[2];                /* Divisor:   per Y jiffies   */
12808 +       int tokens_min;                 /* Limit:     minimum for unhold */
12809 +       int tokens_max;                 /* Limit:     no more than N tokens */
12810 +
12811 +       int prio_bias;                  /* bias offset for priority */
12812 +       int vavavoom;                   /* last calculated vavavoom */
12813 +
12814 +       unsigned long norm_time;        /* last time accounted */
12815 +       unsigned long idle_time;        /* non linear time for fair sched */
12816 +       unsigned long token_time;       /* token time for accounting */
12817 +       unsigned long onhold;           /* jiffies when put on hold */
12818 +
12819 +       uint64_t user_ticks;            /* token tick events */
12820 +       uint64_t sys_ticks;             /* token tick events */
12821 +       uint64_t hold_ticks;            /* token ticks paused */
12822 +};
12823 +
12824 +
12825 +#define VXSF_ONHOLD    0x0001
12826 +#define VXSF_IDLE_TIME 0x0100
12827 +
12828 +#ifdef CONFIG_VSERVER_DEBUG
12829 +
12830 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12831 +{
12832 +       printk("\t_vx_sched:\n");
12833 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12834 +               sched->fill_rate[0], sched->interval[0],
12835 +               sched->fill_rate[1], sched->interval[1],
12836 +               sched->tokens_min, sched->tokens_max);
12837 +       printk("\t priority = %4d\n", sched->prio_bias);
12838 +}
12839 +
12840 +#endif
12841 +
12842 +#endif /* _VX_SCHED_DEF_H */
12843 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/sched.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/sched.h
12844 --- linux-2.6.32/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12845 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/sched.h    2009-12-03 20:04:56.000000000 +0100
12846 @@ -0,0 +1,26 @@
12847 +#ifndef _VX_SCHED_H
12848 +#define _VX_SCHED_H
12849 +
12850 +
12851 +#ifdef __KERNEL__
12852 +
12853 +struct timespec;
12854 +
12855 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12856 +
12857 +
12858 +struct vx_info;
12859 +
12860 +void vx_update_load(struct vx_info *);
12861 +
12862 +
12863 +int vx_tokens_recalc(struct _vx_sched_pc *,
12864 +       unsigned long *, unsigned long *, int [2]);
12865 +
12866 +void vx_update_sched_param(struct _vx_sched *sched,
12867 +       struct _vx_sched_pc *sched_pc);
12868 +
12869 +#endif /* __KERNEL__ */
12870 +#else  /* _VX_SCHED_H */
12871 +#warning duplicate inclusion
12872 +#endif /* _VX_SCHED_H */
12873 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/signal_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/signal_cmd.h
12874 --- linux-2.6.32/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12875 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/signal_cmd.h       2009-12-03 20:04:56.000000000 +0100
12876 @@ -0,0 +1,43 @@
12877 +#ifndef _VX_SIGNAL_CMD_H
12878 +#define _VX_SIGNAL_CMD_H
12879 +
12880 +
12881 +/*  signalling vserver commands */
12882 +
12883 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12884 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12885 +
12886 +struct vcmd_ctx_kill_v0 {
12887 +       int32_t pid;
12888 +       int32_t sig;
12889 +};
12890 +
12891 +struct vcmd_wait_exit_v0 {
12892 +       int32_t reboot_cmd;
12893 +       int32_t exit_code;
12894 +};
12895 +
12896 +#ifdef __KERNEL__
12897 +
12898 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12899 +extern int vc_wait_exit(struct vx_info *, void __user *);
12900 +
12901 +#endif /* __KERNEL__ */
12902 +
12903 +/*  process alteration commands */
12904 +
12905 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12906 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12907 +
12908 +struct vcmd_pflags_v0 {
12909 +       uint32_t flagword;
12910 +       uint32_t mask;
12911 +};
12912 +
12913 +#ifdef __KERNEL__
12914 +
12915 +extern int vc_get_pflags(uint32_t pid, void __user *);
12916 +extern int vc_set_pflags(uint32_t pid, void __user *);
12917 +
12918 +#endif /* __KERNEL__ */
12919 +#endif /* _VX_SIGNAL_CMD_H */
12920 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/signal.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/signal.h
12921 --- linux-2.6.32/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12922 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/signal.h   2009-12-03 20:04:56.000000000 +0100
12923 @@ -0,0 +1,14 @@
12924 +#ifndef _VX_SIGNAL_H
12925 +#define _VX_SIGNAL_H
12926 +
12927 +
12928 +#ifdef __KERNEL__
12929 +
12930 +struct vx_info;
12931 +
12932 +int vx_info_kill(struct vx_info *, int, int);
12933 +
12934 +#endif /* __KERNEL__ */
12935 +#else  /* _VX_SIGNAL_H */
12936 +#warning duplicate inclusion
12937 +#endif /* _VX_SIGNAL_H */
12938 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/space_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/space_cmd.h
12939 --- linux-2.6.32/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12940 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/space_cmd.h        2009-12-03 20:04:56.000000000 +0100
12941 @@ -0,0 +1,38 @@
12942 +#ifndef _VX_SPACE_CMD_H
12943 +#define _VX_SPACE_CMD_H
12944 +
12945 +
12946 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12947 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12948 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12949 +
12950 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12951 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12952 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12953 +
12954 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12955 +
12956 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12957 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12958 +
12959 +
12960 +struct vcmd_space_mask_v1 {
12961 +       uint64_t mask;
12962 +};
12963 +
12964 +struct vcmd_space_mask_v2 {
12965 +       uint64_t mask;
12966 +       uint32_t index;
12967 +};
12968 +
12969 +
12970 +#ifdef __KERNEL__
12971 +
12972 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12973 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12974 +extern int vc_enter_space(struct vx_info *, void __user *);
12975 +extern int vc_set_space(struct vx_info *, void __user *);
12976 +extern int vc_get_space_mask(void __user *, int);
12977 +
12978 +#endif /* __KERNEL__ */
12979 +#endif /* _VX_SPACE_CMD_H */
12980 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/space.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/space.h
12981 --- linux-2.6.32/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12982 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/space.h    2009-12-03 20:04:56.000000000 +0100
12983 @@ -0,0 +1,12 @@
12984 +#ifndef _VX_SPACE_H
12985 +#define _VX_SPACE_H
12986 +
12987 +#include <linux/types.h>
12988 +
12989 +struct vx_info;
12990 +
12991 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12992 +
12993 +#else  /* _VX_SPACE_H */
12994 +#warning duplicate inclusion
12995 +#endif /* _VX_SPACE_H */
12996 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/switch.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/switch.h
12997 --- linux-2.6.32/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
12998 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/switch.h   2009-12-03 20:04:56.000000000 +0100
12999 @@ -0,0 +1,98 @@
13000 +#ifndef _VX_SWITCH_H
13001 +#define _VX_SWITCH_H
13002 +
13003 +#include <linux/types.h>
13004 +
13005 +
13006 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13007 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13008 +#define VC_VERSION(c)          ((c) & 0xFFF)
13009 +
13010 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13011 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13012 +
13013 +/*
13014 +
13015 +  Syscall Matrix V2.8
13016 +
13017 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13018 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13019 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13020 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13021 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13022 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13023 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13024 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13025 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13026 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13027 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13028 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13029 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13030 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13031 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13032 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13033 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13034 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13035 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13036 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13037 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13038 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13039 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13040 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13041 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13042 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13043 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13044 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13045 +
13046 +*/
13047 +
13048 +#define VC_CAT_VERSION         0
13049 +
13050 +#define VC_CAT_VSETUP          1
13051 +#define VC_CAT_VHOST           2
13052 +
13053 +#define VC_CAT_DEVICE          6
13054 +
13055 +#define VC_CAT_VPROC           9
13056 +#define VC_CAT_PROCALT         10
13057 +#define VC_CAT_PROCMIG         11
13058 +#define VC_CAT_PROCTRL         12
13059 +
13060 +#define VC_CAT_SCHED           14
13061 +#define VC_CAT_MEMCTRL         20
13062 +
13063 +#define VC_CAT_VNET            25
13064 +#define VC_CAT_NETALT          26
13065 +#define VC_CAT_NETMIG          27
13066 +#define VC_CAT_NETCTRL         28
13067 +
13068 +#define VC_CAT_TAGMIG          35
13069 +#define VC_CAT_DLIMIT          36
13070 +#define VC_CAT_INODE           38
13071 +
13072 +#define VC_CAT_VSTAT           40
13073 +#define VC_CAT_VINFO           46
13074 +#define VC_CAT_EVENT           48
13075 +
13076 +#define VC_CAT_FLAGS           52
13077 +#define VC_CAT_VSPACE          54
13078 +#define VC_CAT_DEBUG           56
13079 +#define VC_CAT_RLIMIT          60
13080 +
13081 +#define VC_CAT_SYSTEST         61
13082 +#define VC_CAT_COMPAT          63
13083 +
13084 +/*  query version */
13085 +
13086 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13087 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13088 +
13089 +
13090 +#ifdef __KERNEL__
13091 +
13092 +#include <linux/errno.h>
13093 +
13094 +#endif /* __KERNEL__ */
13095 +
13096 +#endif /* _VX_SWITCH_H */
13097 +
13098 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/tag_cmd.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/tag_cmd.h
13099 --- linux-2.6.32/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13100 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/tag_cmd.h  2009-12-03 20:04:56.000000000 +0100
13101 @@ -0,0 +1,22 @@
13102 +#ifndef _VX_TAG_CMD_H
13103 +#define _VX_TAG_CMD_H
13104 +
13105 +
13106 +/* vinfo commands */
13107 +
13108 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13109 +
13110 +#ifdef __KERNEL__
13111 +extern int vc_task_tag(uint32_t);
13112 +
13113 +#endif /* __KERNEL__ */
13114 +
13115 +/* context commands */
13116 +
13117 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13118 +
13119 +#ifdef __KERNEL__
13120 +extern int vc_tag_migrate(uint32_t);
13121 +
13122 +#endif /* __KERNEL__ */
13123 +#endif /* _VX_TAG_CMD_H */
13124 diff -NurpP --minimal linux-2.6.32/include/linux/vserver/tag.h linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/tag.h
13125 --- linux-2.6.32/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13126 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vserver/tag.h      2009-12-03 20:04:56.000000000 +0100
13127 @@ -0,0 +1,143 @@
13128 +#ifndef _DX_TAG_H
13129 +#define _DX_TAG_H
13130 +
13131 +#include <linux/types.h>
13132 +
13133 +
13134 +#define DX_TAG(in)     (IS_TAGGED(in))
13135 +
13136 +
13137 +#ifdef CONFIG_TAG_NFSD
13138 +#define DX_TAG_NFSD    1
13139 +#else
13140 +#define DX_TAG_NFSD    0
13141 +#endif
13142 +
13143 +
13144 +#ifdef CONFIG_TAGGING_NONE
13145 +
13146 +#define MAX_UID                0xFFFFFFFF
13147 +#define MAX_GID                0xFFFFFFFF
13148 +
13149 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13150 +
13151 +#define TAGINO_UID(cond, uid, tag)     (uid)
13152 +#define TAGINO_GID(cond, gid, tag)     (gid)
13153 +
13154 +#endif
13155 +
13156 +
13157 +#ifdef CONFIG_TAGGING_GID16
13158 +
13159 +#define MAX_UID                0xFFFFFFFF
13160 +#define MAX_GID                0x0000FFFF
13161 +
13162 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13163 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13164 +
13165 +#define TAGINO_UID(cond, uid, tag)     (uid)
13166 +#define TAGINO_GID(cond, gid, tag)     \
13167 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13168 +
13169 +#endif
13170 +
13171 +
13172 +#ifdef CONFIG_TAGGING_ID24
13173 +
13174 +#define MAX_UID                0x00FFFFFF
13175 +#define MAX_GID                0x00FFFFFF
13176 +
13177 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13178 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13179 +
13180 +#define TAGINO_UID(cond, uid, tag)     \
13181 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13182 +#define TAGINO_GID(cond, gid, tag)     \
13183 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13184 +
13185 +#endif
13186 +
13187 +
13188 +#ifdef CONFIG_TAGGING_UID16
13189 +
13190 +#define MAX_UID                0x0000FFFF
13191 +#define MAX_GID                0xFFFFFFFF
13192 +
13193 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13194 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13195 +
13196 +#define TAGINO_UID(cond, uid, tag)     \
13197 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13198 +#define TAGINO_GID(cond, gid, tag)     (gid)
13199 +
13200 +#endif
13201 +
13202 +
13203 +#ifdef CONFIG_TAGGING_INTERN
13204 +
13205 +#define MAX_UID                0xFFFFFFFF
13206 +#define MAX_GID                0xFFFFFFFF
13207 +
13208 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13209 +       ((cond) ? (tag) : 0)
13210 +
13211 +#define TAGINO_UID(cond, uid, tag)     (uid)
13212 +#define TAGINO_GID(cond, gid, tag)     (gid)
13213 +
13214 +#endif
13215 +
13216 +
13217 +#ifndef CONFIG_TAGGING_NONE
13218 +#define dx_current_fstag(sb)   \
13219 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13220 +#else
13221 +#define dx_current_fstag(sb)   (0)
13222 +#endif
13223 +
13224 +#ifndef CONFIG_TAGGING_INTERN
13225 +#define TAGINO_TAG(cond, tag)  (0)
13226 +#else
13227 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13228 +#endif
13229 +
13230 +#define INOTAG_UID(cond, uid, gid)     \
13231 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13232 +#define INOTAG_GID(cond, uid, gid)     \
13233 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13234 +
13235 +
13236 +static inline uid_t dx_map_uid(uid_t uid)
13237 +{
13238 +       if ((uid > MAX_UID) && (uid != -1))
13239 +               uid = -2;
13240 +       return (uid & MAX_UID);
13241 +}
13242 +
13243 +static inline gid_t dx_map_gid(gid_t gid)
13244 +{
13245 +       if ((gid > MAX_GID) && (gid != -1))
13246 +               gid = -2;
13247 +       return (gid & MAX_GID);
13248 +}
13249 +
13250 +struct peer_tag {
13251 +       int32_t xid;
13252 +       int32_t nid;
13253 +};
13254 +
13255 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13256 +
13257 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13258 +                unsigned long *flags);
13259 +
13260 +#ifdef CONFIG_PROPAGATE
13261 +
13262 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13263 +
13264 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13265 +
13266 +#else
13267 +#define dx_propagate_tag(n, i) do { } while (0)
13268 +#endif
13269 +
13270 +#endif /* _DX_TAG_H */
13271 diff -NurpP --minimal linux-2.6.32/include/linux/vs_inet6.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_inet6.h
13272 --- linux-2.6.32/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13273 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_inet6.h 2009-12-03 20:04:56.000000000 +0100
13274 @@ -0,0 +1,246 @@
13275 +#ifndef _VS_INET6_H
13276 +#define _VS_INET6_H
13277 +
13278 +#include "vserver/base.h"
13279 +#include "vserver/network.h"
13280 +#include "vserver/debug.h"
13281 +
13282 +#include <net/ipv6.h>
13283 +
13284 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13285 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13286 +
13287 +
13288 +#ifdef CONFIG_IPV6
13289 +
13290 +static inline
13291 +int v6_addr_match(struct nx_addr_v6 *nxa,
13292 +       const struct in6_addr *addr, uint16_t mask)
13293 +{
13294 +       int ret = 0;
13295 +
13296 +       switch (nxa->type & mask) {
13297 +       case NXA_TYPE_MASK:
13298 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13299 +               break;
13300 +       case NXA_TYPE_ADDR:
13301 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13302 +               break;
13303 +       case NXA_TYPE_ANY:
13304 +               ret = 1;
13305 +               break;
13306 +       }
13307 +       vxdprintk(VXD_CBIT(net, 0),
13308 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13309 +               nxa, NXAV6(nxa), addr, mask, ret);
13310 +       return ret;
13311 +}
13312 +
13313 +static inline
13314 +int v6_addr_in_nx_info(struct nx_info *nxi,
13315 +       const struct in6_addr *addr, uint16_t mask)
13316 +{
13317 +       struct nx_addr_v6 *nxa;
13318 +       int ret = 1;
13319 +
13320 +       if (!nxi)
13321 +               goto out;
13322 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13323 +               if (v6_addr_match(nxa, addr, mask))
13324 +                       goto out;
13325 +       ret = 0;
13326 +out:
13327 +       vxdprintk(VXD_CBIT(net, 0),
13328 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13329 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13330 +       return ret;
13331 +}
13332 +
13333 +static inline
13334 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13335 +{
13336 +       /* FIXME: needs full range checks */
13337 +       return v6_addr_match(nxa, &addr->ip, mask);
13338 +}
13339 +
13340 +static inline
13341 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13342 +{
13343 +       struct nx_addr_v6 *ptr;
13344 +
13345 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13346 +               if (v6_nx_addr_match(ptr, nxa, mask))
13347 +                       return 1;
13348 +       return 0;
13349 +}
13350 +
13351 +
13352 +/*
13353 + *     Check if a given address matches for a socket
13354 + *
13355 + *     nxi:            the socket's nx_info if any
13356 + *     addr:           to be verified address
13357 + */
13358 +static inline
13359 +int v6_sock_addr_match (
13360 +       struct nx_info *nxi,
13361 +       struct inet_sock *inet,
13362 +       struct in6_addr *addr)
13363 +{
13364 +       struct sock *sk = &inet->sk;
13365 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13366 +
13367 +       if (!ipv6_addr_any(addr) &&
13368 +               ipv6_addr_equal(saddr, addr))
13369 +               return 1;
13370 +       if (ipv6_addr_any(saddr))
13371 +               return v6_addr_in_nx_info(nxi, addr, -1);
13372 +       return 0;
13373 +}
13374 +
13375 +/*
13376 + *     check if address is covered by socket
13377 + *
13378 + *     sk:     the socket to check against
13379 + *     addr:   the address in question (must be != 0)
13380 + */
13381 +
13382 +static inline
13383 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13384 +{
13385 +       struct nx_info *nxi = sk->sk_nx_info;
13386 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13387 +
13388 +       vxdprintk(VXD_CBIT(net, 5),
13389 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13390 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13391 +               (sk->sk_socket?sk->sk_socket->flags:0));
13392 +
13393 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13394 +               return v6_addr_match(nxa, saddr, -1);
13395 +       } else if (nxi) {               /* match against nx_info */
13396 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13397 +       } else {                        /* unrestricted any socket */
13398 +               return 1;
13399 +       }
13400 +}
13401 +
13402 +
13403 +/* inet related checks and helpers */
13404 +
13405 +
13406 +struct in_ifaddr;
13407 +struct net_device;
13408 +struct sock;
13409 +
13410 +
13411 +#include <linux/netdevice.h>
13412 +#include <linux/inetdevice.h>
13413 +#include <net/inet_timewait_sock.h>
13414 +
13415 +
13416 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13417 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13418 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13419 +
13420 +
13421 +
13422 +static inline
13423 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13424 +{
13425 +       if (!nxi)
13426 +               return 1;
13427 +       if (!ifa)
13428 +               return 0;
13429 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13430 +}
13431 +
13432 +static inline
13433 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13434 +{
13435 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13436 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13437 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13438 +
13439 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13440 +               return 1;
13441 +       if (v6_ifa_in_nx_info(ifa, nxi))
13442 +               return 1;
13443 +       return 0;
13444 +}
13445 +
13446 +
13447 +struct nx_v6_sock_addr {
13448 +       struct in6_addr saddr;  /* Address used for validation */
13449 +       struct in6_addr baddr;  /* Address used for socket bind */
13450 +};
13451 +
13452 +static inline
13453 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13454 +       struct nx_v6_sock_addr *nsa)
13455 +{
13456 +       // struct sock *sk = &inet->sk;
13457 +       // struct nx_info *nxi = sk->sk_nx_info;
13458 +       struct in6_addr saddr = addr->sin6_addr;
13459 +       struct in6_addr baddr = saddr;
13460 +
13461 +       nsa->saddr = saddr;
13462 +       nsa->baddr = baddr;
13463 +       return 0;
13464 +}
13465 +
13466 +static inline
13467 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13468 +{
13469 +       // struct sock *sk = &inet->sk;
13470 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13471 +
13472 +       // *saddr = nsa->baddr;
13473 +       // inet->saddr = nsa->baddr;
13474 +}
13475 +
13476 +static inline
13477 +int nx_info_has_v6(struct nx_info *nxi)
13478 +{
13479 +       if (!nxi)
13480 +               return 1;
13481 +       if (NX_IPV6(nxi))
13482 +               return 1;
13483 +       return 0;
13484 +}
13485 +
13486 +#else /* CONFIG_IPV6 */
13487 +
13488 +static inline
13489 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13490 +{
13491 +       return 1;
13492 +}
13493 +
13494 +
13495 +static inline
13496 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13497 +{
13498 +       return 1;
13499 +}
13500 +
13501 +static inline
13502 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13503 +{
13504 +       return 1;
13505 +}
13506 +
13507 +static inline
13508 +int nx_info_has_v6(struct nx_info *nxi)
13509 +{
13510 +       return 0;
13511 +}
13512 +
13513 +#endif /* CONFIG_IPV6 */
13514 +
13515 +#define current_nx_info_has_v6() \
13516 +       nx_info_has_v6(current_nx_info())
13517 +
13518 +#else
13519 +#warning duplicate inclusion
13520 +#endif
13521 diff -NurpP --minimal linux-2.6.32/include/linux/vs_inet.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_inet.h
13522 --- linux-2.6.32/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13523 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_inet.h  2009-12-03 20:04:56.000000000 +0100
13524 @@ -0,0 +1,342 @@
13525 +#ifndef _VS_INET_H
13526 +#define _VS_INET_H
13527 +
13528 +#include "vserver/base.h"
13529 +#include "vserver/network.h"
13530 +#include "vserver/debug.h"
13531 +
13532 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13533 +
13534 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13535 +                       NIPQUAD((a)->mask), (a)->type
13536 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13537 +
13538 +
13539 +static inline
13540 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13541 +{
13542 +       __be32 ip = nxa->ip[0].s_addr;
13543 +       __be32 mask = nxa->mask.s_addr;
13544 +       __be32 bcast = ip | ~mask;
13545 +       int ret = 0;
13546 +
13547 +       switch (nxa->type & tmask) {
13548 +       case NXA_TYPE_MASK:
13549 +               ret = (ip == (addr & mask));
13550 +               break;
13551 +       case NXA_TYPE_ADDR:
13552 +               ret = 3;
13553 +               if (addr == ip)
13554 +                       break;
13555 +               /* fall through to broadcast */
13556 +       case NXA_MOD_BCAST:
13557 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13558 +               break;
13559 +       case NXA_TYPE_RANGE:
13560 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13561 +                       (nxa->ip[1].s_addr > addr));
13562 +               break;
13563 +       case NXA_TYPE_ANY:
13564 +               ret = 2;
13565 +               break;
13566 +       }
13567 +
13568 +       vxdprintk(VXD_CBIT(net, 0),
13569 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13570 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13571 +       return ret;
13572 +}
13573 +
13574 +static inline
13575 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13576 +{
13577 +       struct nx_addr_v4 *nxa;
13578 +       int ret = 1;
13579 +
13580 +       if (!nxi)
13581 +               goto out;
13582 +
13583 +       ret = 2;
13584 +       /* allow 127.0.0.1 when remapping lback */
13585 +       if ((tmask & NXA_LOOPBACK) &&
13586 +               (addr == IPI_LOOPBACK) &&
13587 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13588 +               goto out;
13589 +       ret = 3;
13590 +       /* check for lback address */
13591 +       if ((tmask & NXA_MOD_LBACK) &&
13592 +               (nxi->v4_lback.s_addr == addr))
13593 +               goto out;
13594 +       ret = 4;
13595 +       /* check for broadcast address */
13596 +       if ((tmask & NXA_MOD_BCAST) &&
13597 +               (nxi->v4_bcast.s_addr == addr))
13598 +               goto out;
13599 +       ret = 5;
13600 +       /* check for v4 addresses */
13601 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13602 +               if (v4_addr_match(nxa, addr, tmask))
13603 +                       goto out;
13604 +       ret = 0;
13605 +out:
13606 +       vxdprintk(VXD_CBIT(net, 0),
13607 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13608 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13609 +       return ret;
13610 +}
13611 +
13612 +static inline
13613 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13614 +{
13615 +       /* FIXME: needs full range checks */
13616 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13617 +}
13618 +
13619 +static inline
13620 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13621 +{
13622 +       struct nx_addr_v4 *ptr;
13623 +
13624 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13625 +               if (v4_nx_addr_match(ptr, nxa, mask))
13626 +                       return 1;
13627 +       return 0;
13628 +}
13629 +
13630 +#include <net/inet_sock.h>
13631 +
13632 +/*
13633 + *     Check if a given address matches for a socket
13634 + *
13635 + *     nxi:            the socket's nx_info if any
13636 + *     addr:           to be verified address
13637 + */
13638 +static inline
13639 +int v4_sock_addr_match (
13640 +       struct nx_info *nxi,
13641 +       struct inet_sock *inet,
13642 +       __be32 addr)
13643 +{
13644 +       __be32 saddr = inet->rcv_saddr;
13645 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13646 +
13647 +       if (addr && (saddr == addr || bcast == addr))
13648 +               return 1;
13649 +       if (!saddr)
13650 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13651 +       return 0;
13652 +}
13653 +
13654 +
13655 +/* inet related checks and helpers */
13656 +
13657 +
13658 +struct in_ifaddr;
13659 +struct net_device;
13660 +struct sock;
13661 +
13662 +#ifdef CONFIG_INET
13663 +
13664 +#include <linux/netdevice.h>
13665 +#include <linux/inetdevice.h>
13666 +#include <net/inet_sock.h>
13667 +#include <net/inet_timewait_sock.h>
13668 +
13669 +
13670 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13671 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13672 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13673 +
13674 +
13675 +/*
13676 + *     check if address is covered by socket
13677 + *
13678 + *     sk:     the socket to check against
13679 + *     addr:   the address in question (must be != 0)
13680 + */
13681 +
13682 +static inline
13683 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13684 +{
13685 +       struct nx_info *nxi = sk->sk_nx_info;
13686 +       __be32 saddr = inet_rcv_saddr(sk);
13687 +
13688 +       vxdprintk(VXD_CBIT(net, 5),
13689 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13690 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13691 +               (sk->sk_socket?sk->sk_socket->flags:0));
13692 +
13693 +       if (saddr) {            /* direct address match */
13694 +               return v4_addr_match(nxa, saddr, -1);
13695 +       } else if (nxi) {       /* match against nx_info */
13696 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13697 +       } else {                /* unrestricted any socket */
13698 +               return 1;
13699 +       }
13700 +}
13701 +
13702 +
13703 +
13704 +static inline
13705 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13706 +{
13707 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13708 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13709 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13710 +
13711 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13712 +               return 1;
13713 +       if (dev_in_nx_info(dev, nxi))
13714 +               return 1;
13715 +       return 0;
13716 +}
13717 +
13718 +
13719 +static inline
13720 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13721 +{
13722 +       if (!nxi)
13723 +               return 1;
13724 +       if (!ifa)
13725 +               return 0;
13726 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13727 +}
13728 +
13729 +static inline
13730 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13731 +{
13732 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13733 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13734 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13735 +
13736 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13737 +               return 1;
13738 +       if (v4_ifa_in_nx_info(ifa, nxi))
13739 +               return 1;
13740 +       return 0;
13741 +}
13742 +
13743 +
13744 +struct nx_v4_sock_addr {
13745 +       __be32 saddr;   /* Address used for validation */
13746 +       __be32 baddr;   /* Address used for socket bind */
13747 +};
13748 +
13749 +static inline
13750 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13751 +       struct nx_v4_sock_addr *nsa)
13752 +{
13753 +       struct sock *sk = &inet->sk;
13754 +       struct nx_info *nxi = sk->sk_nx_info;
13755 +       __be32 saddr = addr->sin_addr.s_addr;
13756 +       __be32 baddr = saddr;
13757 +
13758 +       vxdprintk(VXD_CBIT(net, 3),
13759 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13760 +               sk, sk->sk_nx_info, sk->sk_socket,
13761 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13762 +               NIPQUAD(saddr));
13763 +
13764 +       if (nxi) {
13765 +               if (saddr == INADDR_ANY) {
13766 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13767 +                               baddr = nxi->v4.ip[0].s_addr;
13768 +               } else if (saddr == IPI_LOOPBACK) {
13769 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13770 +                               baddr = nxi->v4_lback.s_addr;
13771 +               } else {        /* normal address bind */
13772 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13773 +                               return -EADDRNOTAVAIL;
13774 +               }
13775 +       }
13776 +
13777 +       vxdprintk(VXD_CBIT(net, 3),
13778 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13779 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13780 +
13781 +       nsa->saddr = saddr;
13782 +       nsa->baddr = baddr;
13783 +       return 0;
13784 +}
13785 +
13786 +static inline
13787 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13788 +{
13789 +       inet->saddr = nsa->baddr;
13790 +       inet->rcv_saddr = nsa->baddr;
13791 +}
13792 +
13793 +
13794 +/*
13795 + *      helper to simplify inet_lookup_listener
13796 + *
13797 + *      nxi:   the socket's nx_info if any
13798 + *      addr:  to be verified address
13799 + *      saddr: socket address
13800 + */
13801 +static inline int v4_inet_addr_match (
13802 +       struct nx_info *nxi,
13803 +       __be32 addr,
13804 +       __be32 saddr)
13805 +{
13806 +       if (addr && (saddr == addr))
13807 +               return 1;
13808 +       if (!saddr)
13809 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13810 +       return 0;
13811 +}
13812 +
13813 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13814 +{
13815 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13816 +               (addr == nxi->v4_lback.s_addr))
13817 +               return IPI_LOOPBACK;
13818 +       return addr;
13819 +}
13820 +
13821 +static inline
13822 +int nx_info_has_v4(struct nx_info *nxi)
13823 +{
13824 +       if (!nxi)
13825 +               return 1;
13826 +       if (NX_IPV4(nxi))
13827 +               return 1;
13828 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13829 +               return 1;
13830 +       return 0;
13831 +}
13832 +
13833 +#else /* CONFIG_INET */
13834 +
13835 +static inline
13836 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13837 +{
13838 +       return 1;
13839 +}
13840 +
13841 +static inline
13842 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13843 +{
13844 +       return 1;
13845 +}
13846 +
13847 +static inline
13848 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13849 +{
13850 +       return 1;
13851 +}
13852 +
13853 +static inline
13854 +int nx_info_has_v4(struct nx_info *nxi)
13855 +{
13856 +       return 0;
13857 +}
13858 +
13859 +#endif /* CONFIG_INET */
13860 +
13861 +#define current_nx_info_has_v4() \
13862 +       nx_info_has_v4(current_nx_info())
13863 +
13864 +#else
13865 +// #warning duplicate inclusion
13866 +#endif
13867 diff -NurpP --minimal linux-2.6.32/include/linux/vs_limit.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_limit.h
13868 --- linux-2.6.32/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13869 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_limit.h 2009-12-03 20:04:56.000000000 +0100
13870 @@ -0,0 +1,140 @@
13871 +#ifndef _VS_LIMIT_H
13872 +#define _VS_LIMIT_H
13873 +
13874 +#include "vserver/limit.h"
13875 +#include "vserver/base.h"
13876 +#include "vserver/context.h"
13877 +#include "vserver/debug.h"
13878 +#include "vserver/context.h"
13879 +#include "vserver/limit_int.h"
13880 +
13881 +
13882 +#define vx_acc_cres(v, d, p, r) \
13883 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13884 +
13885 +#define vx_acc_cres_cond(x, d, p, r) \
13886 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13887 +       r, d, p, __FILE__, __LINE__)
13888 +
13889 +
13890 +#define vx_add_cres(v, a, p, r) \
13891 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13892 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13893 +
13894 +#define vx_add_cres_cond(x, a, p, r) \
13895 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13896 +       r, a, p, __FILE__, __LINE__)
13897 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13898 +
13899 +
13900 +/* process and file limits */
13901 +
13902 +#define vx_nproc_inc(p) \
13903 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13904 +
13905 +#define vx_nproc_dec(p) \
13906 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13907 +
13908 +#define vx_files_inc(f) \
13909 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13910 +
13911 +#define vx_files_dec(f) \
13912 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13913 +
13914 +#define vx_locks_inc(l) \
13915 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13916 +
13917 +#define vx_locks_dec(l) \
13918 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13919 +
13920 +#define vx_openfd_inc(f) \
13921 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13922 +
13923 +#define vx_openfd_dec(f) \
13924 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13925 +
13926 +
13927 +#define vx_cres_avail(v, n, r) \
13928 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13929 +
13930 +
13931 +#define vx_nproc_avail(n) \
13932 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13933 +
13934 +#define vx_files_avail(n) \
13935 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13936 +
13937 +#define vx_locks_avail(n) \
13938 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13939 +
13940 +#define vx_openfd_avail(n) \
13941 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13942 +
13943 +
13944 +/* dentry limits */
13945 +
13946 +#define vx_dentry_inc(d) do {                                          \
13947 +       if (atomic_read(&d->d_count) == 1)                              \
13948 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13949 +       } while (0)
13950 +
13951 +#define vx_dentry_dec(d) do {                                          \
13952 +       if (atomic_read(&d->d_count) == 0)                              \
13953 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13954 +       } while (0)
13955 +
13956 +#define vx_dentry_avail(n) \
13957 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13958 +
13959 +
13960 +/* socket limits */
13961 +
13962 +#define vx_sock_inc(s) \
13963 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13964 +
13965 +#define vx_sock_dec(s) \
13966 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13967 +
13968 +#define vx_sock_avail(n) \
13969 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13970 +
13971 +
13972 +/* ipc resource limits */
13973 +
13974 +#define vx_ipcmsg_add(v, u, a) \
13975 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13976 +
13977 +#define vx_ipcmsg_sub(v, u, a) \
13978 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13979 +
13980 +#define vx_ipcmsg_avail(v, a) \
13981 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13982 +
13983 +
13984 +#define vx_ipcshm_add(v, k, a) \
13985 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13986 +
13987 +#define vx_ipcshm_sub(v, k, a) \
13988 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13989 +
13990 +#define vx_ipcshm_avail(v, a) \
13991 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13992 +
13993 +
13994 +#define vx_semary_inc(a) \
13995 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
13996 +
13997 +#define vx_semary_dec(a) \
13998 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
13999 +
14000 +
14001 +#define vx_nsems_add(a,n) \
14002 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14003 +
14004 +#define vx_nsems_sub(a,n) \
14005 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
14006 +
14007 +
14008 +#else
14009 +#warning duplicate inclusion
14010 +#endif
14011 diff -NurpP --minimal linux-2.6.32/include/linux/vs_memory.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_memory.h
14012 --- linux-2.6.32/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
14013 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_memory.h        2009-12-03 20:04:56.000000000 +0100
14014 @@ -0,0 +1,159 @@
14015 +#ifndef _VS_MEMORY_H
14016 +#define _VS_MEMORY_H
14017 +
14018 +#include "vserver/limit.h"
14019 +#include "vserver/base.h"
14020 +#include "vserver/context.h"
14021 +#include "vserver/debug.h"
14022 +#include "vserver/context.h"
14023 +#include "vserver/limit_int.h"
14024 +
14025 +
14026 +#define __acc_add_long(a, v)   (*(v) += (a))
14027 +#define __acc_inc_long(v)      (++*(v))
14028 +#define __acc_dec_long(v)      (--*(v))
14029 +
14030 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14031 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14032 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14033 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14034 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14035 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14036 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14037 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14038 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14039 +
14040 +
14041 +#define vx_acc_page(m, d, v, r) do {                                   \
14042 +       if ((d) > 0)                                                    \
14043 +               __acc_inc_long(&(m)->v);                                \
14044 +       else                                                            \
14045 +               __acc_dec_long(&(m)->v);                                \
14046 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14047 +} while (0)
14048 +
14049 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14050 +       if ((d) > 0)                                                    \
14051 +               __acc_inc_atomic(&(m)->v);                              \
14052 +       else                                                            \
14053 +               __acc_dec_atomic(&(m)->v);                              \
14054 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14055 +} while (0)
14056 +
14057 +
14058 +#define vx_acc_pages(m, p, v, r) do {                                  \
14059 +       unsigned long __p = (p);                                        \
14060 +       __acc_add_long(__p, &(m)->v);                                   \
14061 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14062 +} while (0)
14063 +
14064 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14065 +       unsigned long __p = (p);                                        \
14066 +       __acc_add_atomic(__p, &(m)->v);                                 \
14067 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14068 +} while (0)
14069 +
14070 +
14071 +
14072 +#define vx_acc_vmpage(m, d) \
14073 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14074 +#define vx_acc_vmlpage(m, d) \
14075 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14076 +#define vx_acc_file_rsspage(m, d) \
14077 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14078 +#define vx_acc_anon_rsspage(m, d) \
14079 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14080 +
14081 +#define vx_acc_vmpages(m, p) \
14082 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14083 +#define vx_acc_vmlpages(m, p) \
14084 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14085 +#define vx_acc_file_rsspages(m, p) \
14086 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14087 +#define vx_acc_anon_rsspages(m, p) \
14088 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14089 +
14090 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14091 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14092 +
14093 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14094 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14095 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14096 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14097 +
14098 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14099 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14100 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14101 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14102 +
14103 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14104 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14105 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14106 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14107 +
14108 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14109 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14110 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14111 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14112 +
14113 +
14114 +#define vx_pages_avail(m, p, r) \
14115 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14116 +
14117 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14118 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14119 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14120 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14121 +
14122 +#define vx_rss_avail(m, p) \
14123 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14124 +
14125 +
14126 +enum {
14127 +       VXPT_UNKNOWN = 0,
14128 +       VXPT_ANON,
14129 +       VXPT_NONE,
14130 +       VXPT_FILE,
14131 +       VXPT_SWAP,
14132 +       VXPT_WRITE
14133 +};
14134 +
14135 +#if 0
14136 +#define        vx_page_fault(mm, vma, type, ret)
14137 +#else
14138 +
14139 +static inline
14140 +void __vx_page_fault(struct mm_struct *mm,
14141 +       struct vm_area_struct *vma, int type, int ret)
14142 +{
14143 +       struct vx_info *vxi = mm->mm_vx_info;
14144 +       int what;
14145 +/*
14146 +       static char *page_type[6] =
14147 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14148 +       static char *page_what[4] =
14149 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14150 +*/
14151 +
14152 +       if (!vxi)
14153 +               return;
14154 +
14155 +       what = (ret & 0x3);
14156 +
14157 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14158 +               type, what, ret, page_type[type], page_what[what]);
14159 +*/
14160 +       if (ret & VM_FAULT_WRITE)
14161 +               what |= 0x4;
14162 +       atomic_inc(&vxi->cacct.page[type][what]);
14163 +}
14164 +
14165 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14166 +#endif
14167 +
14168 +
14169 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14170 +
14171 +#else
14172 +#warning duplicate inclusion
14173 +#endif
14174 diff -NurpP --minimal linux-2.6.32/include/linux/vs_network.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_network.h
14175 --- linux-2.6.32/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
14176 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_network.h       2009-12-03 20:04:56.000000000 +0100
14177 @@ -0,0 +1,169 @@
14178 +#ifndef _NX_VS_NETWORK_H
14179 +#define _NX_VS_NETWORK_H
14180 +
14181 +#include "vserver/context.h"
14182 +#include "vserver/network.h"
14183 +#include "vserver/base.h"
14184 +#include "vserver/check.h"
14185 +#include "vserver/debug.h"
14186 +
14187 +#include <linux/sched.h>
14188 +
14189 +
14190 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14191 +
14192 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14193 +       const char *_file, int _line)
14194 +{
14195 +       if (!nxi)
14196 +               return NULL;
14197 +
14198 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14199 +               nxi, nxi ? nxi->nx_id : 0,
14200 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14201 +               _file, _line);
14202 +
14203 +       atomic_inc(&nxi->nx_usecnt);
14204 +       return nxi;
14205 +}
14206 +
14207 +
14208 +extern void free_nx_info(struct nx_info *);
14209 +
14210 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14211 +
14212 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14213 +{
14214 +       if (!nxi)
14215 +               return;
14216 +
14217 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14218 +               nxi, nxi ? nxi->nx_id : 0,
14219 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14220 +               _file, _line);
14221 +
14222 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14223 +               free_nx_info(nxi);
14224 +}
14225 +
14226 +
14227 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14228 +
14229 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14230 +               const char *_file, int _line)
14231 +{
14232 +       if (nxi) {
14233 +               vxlprintk(VXD_CBIT(nid, 3),
14234 +                       "init_nx_info(%p[#%d.%d])",
14235 +                       nxi, nxi ? nxi->nx_id : 0,
14236 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14237 +                       _file, _line);
14238 +
14239 +               atomic_inc(&nxi->nx_usecnt);
14240 +       }
14241 +       *nxp = nxi;
14242 +}
14243 +
14244 +
14245 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14246 +
14247 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14248 +       const char *_file, int _line)
14249 +{
14250 +       struct nx_info *nxo;
14251 +
14252 +       if (!nxi)
14253 +               return;
14254 +
14255 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14256 +               nxi, nxi ? nxi->nx_id : 0,
14257 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14258 +               _file, _line);
14259 +
14260 +       atomic_inc(&nxi->nx_usecnt);
14261 +       nxo = xchg(nxp, nxi);
14262 +       BUG_ON(nxo);
14263 +}
14264 +
14265 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14266 +
14267 +static inline void __clr_nx_info(struct nx_info **nxp,
14268 +       const char *_file, int _line)
14269 +{
14270 +       struct nx_info *nxo;
14271 +
14272 +       nxo = xchg(nxp, NULL);
14273 +       if (!nxo)
14274 +               return;
14275 +
14276 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14277 +               nxo, nxo ? nxo->nx_id : 0,
14278 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14279 +               _file, _line);
14280 +
14281 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14282 +               free_nx_info(nxo);
14283 +}
14284 +
14285 +
14286 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14287 +
14288 +static inline void __claim_nx_info(struct nx_info *nxi,
14289 +       struct task_struct *task, const char *_file, int _line)
14290 +{
14291 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14292 +               nxi, nxi ? nxi->nx_id : 0,
14293 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14294 +               nxi?atomic_read(&nxi->nx_tasks):0,
14295 +               task, _file, _line);
14296 +
14297 +       atomic_inc(&nxi->nx_tasks);
14298 +}
14299 +
14300 +
14301 +extern void unhash_nx_info(struct nx_info *);
14302 +
14303 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14304 +
14305 +static inline void __release_nx_info(struct nx_info *nxi,
14306 +       struct task_struct *task, const char *_file, int _line)
14307 +{
14308 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14309 +               nxi, nxi ? nxi->nx_id : 0,
14310 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14311 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14312 +               task, _file, _line);
14313 +
14314 +       might_sleep();
14315 +
14316 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14317 +               unhash_nx_info(nxi);
14318 +}
14319 +
14320 +
14321 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14322 +
14323 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14324 +       const char *_file, int _line)
14325 +{
14326 +       struct nx_info *nxi;
14327 +
14328 +       task_lock(p);
14329 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14330 +               p, _file, _line);
14331 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14332 +       task_unlock(p);
14333 +       return nxi;
14334 +}
14335 +
14336 +
14337 +static inline void exit_nx_info(struct task_struct *p)
14338 +{
14339 +       if (p->nx_info)
14340 +               release_nx_info(p->nx_info, p);
14341 +}
14342 +
14343 +
14344 +#else
14345 +#warning duplicate inclusion
14346 +#endif
14347 diff -NurpP --minimal linux-2.6.32/include/linux/vs_pid.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_pid.h
14348 --- linux-2.6.32/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14349 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_pid.h   2009-12-03 20:04:56.000000000 +0100
14350 @@ -0,0 +1,95 @@
14351 +#ifndef _VS_PID_H
14352 +#define _VS_PID_H
14353 +
14354 +#include "vserver/base.h"
14355 +#include "vserver/check.h"
14356 +#include "vserver/context.h"
14357 +#include "vserver/debug.h"
14358 +#include "vserver/pid.h"
14359 +#include <linux/pid_namespace.h>
14360 +
14361 +
14362 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14363 +
14364 +static inline
14365 +int vx_proc_task_visible(struct task_struct *task)
14366 +{
14367 +       if ((task->pid == 1) &&
14368 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14369 +               /* show a blend through init */
14370 +               goto visible;
14371 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14372 +               goto visible;
14373 +       return 0;
14374 +visible:
14375 +       return 1;
14376 +}
14377 +
14378 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14379 +
14380 +#if 0
14381 +
14382 +static inline
14383 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14384 +{
14385 +       struct task_struct *task = find_task_by_real_pid(pid);
14386 +
14387 +       if (task && !vx_proc_task_visible(task)) {
14388 +               vxdprintk(VXD_CBIT(misc, 6),
14389 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14390 +                       task, task->xid, task->pid,
14391 +                       current, current->xid, current->pid);
14392 +               task = NULL;
14393 +       }
14394 +       return task;
14395 +}
14396 +
14397 +#endif
14398 +
14399 +static inline
14400 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14401 +{
14402 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14403 +
14404 +       if (task && !vx_proc_task_visible(task)) {
14405 +               vxdprintk(VXD_CBIT(misc, 6),
14406 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14407 +                       task, task->xid, task->pid,
14408 +                       current, current->xid, current->pid);
14409 +               put_task_struct(task);
14410 +               task = NULL;
14411 +       }
14412 +       return task;
14413 +}
14414 +
14415 +#if 0
14416 +
14417 +static inline
14418 +struct task_struct *vx_child_reaper(struct task_struct *p)
14419 +{
14420 +       struct vx_info *vxi = p->vx_info;
14421 +       struct task_struct *reaper = child_reaper(p);
14422 +
14423 +       if (!vxi)
14424 +               goto out;
14425 +
14426 +       BUG_ON(!p->vx_info->vx_reaper);
14427 +
14428 +       /* child reaper for the guest reaper */
14429 +       if (vxi->vx_reaper == p)
14430 +               goto out;
14431 +
14432 +       reaper = vxi->vx_reaper;
14433 +out:
14434 +       vxdprintk(VXD_CBIT(xid, 7),
14435 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14436 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14437 +       return reaper;
14438 +}
14439 +
14440 +#endif
14441 +
14442 +
14443 +#else
14444 +#warning duplicate inclusion
14445 +#endif
14446 diff -NurpP --minimal linux-2.6.32/include/linux/vs_sched.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_sched.h
14447 --- linux-2.6.32/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14448 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_sched.h 2009-12-03 20:04:56.000000000 +0100
14449 @@ -0,0 +1,110 @@
14450 +#ifndef _VS_SCHED_H
14451 +#define _VS_SCHED_H
14452 +
14453 +#include "vserver/base.h"
14454 +#include "vserver/context.h"
14455 +#include "vserver/sched.h"
14456 +
14457 +
14458 +#define VAVAVOOM_RATIO          50
14459 +
14460 +#define MAX_PRIO_BIAS           20
14461 +#define MIN_PRIO_BIAS          -20
14462 +
14463 +
14464 +#ifdef CONFIG_VSERVER_HARDCPU
14465 +
14466 +/*
14467 + * effective_prio - return the priority that is based on the static
14468 + * priority but is modified by bonuses/penalties.
14469 + *
14470 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14471 + * into a -4 ... 0 ... +4 bonus/penalty range.
14472 + *
14473 + * Additionally, we scale another amount based on the number of
14474 + * CPU tokens currently held by the context, if the process is
14475 + * part of a context (and the appropriate SCHED flag is set).
14476 + * This ranges from -5 ... 0 ... +15, quadratically.
14477 + *
14478 + * So, the total bonus is -9 .. 0 .. +19
14479 + * We use ~50% of the full 0...39 priority range so that:
14480 + *
14481 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14482 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14483 + *    unless that context is far exceeding its CPU allocation.
14484 + *
14485 + * Both properties are important to certain workloads.
14486 + */
14487 +static inline
14488 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14489 +{
14490 +       int vavavoom, max;
14491 +
14492 +       /* lots of tokens = lots of vavavoom
14493 +        *      no tokens = no vavavoom      */
14494 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14495 +               max = sched_pc->tokens_max;
14496 +               vavavoom = max - vavavoom;
14497 +               max = max * max;
14498 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14499 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14500 +               return vavavoom;
14501 +       }
14502 +       return 0;
14503 +}
14504 +
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 +       struct _vx_sched_pc *sched_pc;
14511 +
14512 +       if (!vxi)
14513 +               return prio;
14514 +
14515 +       sched_pc = &vx_cpu(vxi, sched_pc);
14516 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14517 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14518 +
14519 +               sched_pc->vavavoom = vavavoom;
14520 +               prio += vavavoom;
14521 +       }
14522 +       prio += sched_pc->prio_bias;
14523 +       return prio;
14524 +}
14525 +
14526 +#else /* !CONFIG_VSERVER_HARDCPU */
14527 +
14528 +static inline
14529 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14530 +{
14531 +       struct vx_info *vxi = p->vx_info;
14532 +
14533 +       if (vxi)
14534 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14535 +       return prio;
14536 +}
14537 +
14538 +#endif /* CONFIG_VSERVER_HARDCPU */
14539 +
14540 +
14541 +static inline void vx_account_user(struct vx_info *vxi,
14542 +       cputime_t cputime, int nice)
14543 +{
14544 +       if (!vxi)
14545 +               return;
14546 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14547 +}
14548 +
14549 +static inline void vx_account_system(struct vx_info *vxi,
14550 +       cputime_t cputime, int idle)
14551 +{
14552 +       if (!vxi)
14553 +               return;
14554 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14555 +}
14556 +
14557 +#else
14558 +#warning duplicate inclusion
14559 +#endif
14560 diff -NurpP --minimal linux-2.6.32/include/linux/vs_socket.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_socket.h
14561 --- linux-2.6.32/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14562 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_socket.h        2009-12-03 20:04:56.000000000 +0100
14563 @@ -0,0 +1,67 @@
14564 +#ifndef _VS_SOCKET_H
14565 +#define _VS_SOCKET_H
14566 +
14567 +#include "vserver/debug.h"
14568 +#include "vserver/base.h"
14569 +#include "vserver/cacct.h"
14570 +#include "vserver/context.h"
14571 +#include "vserver/tag.h"
14572 +
14573 +
14574 +/* socket accounting */
14575 +
14576 +#include <linux/socket.h>
14577 +
14578 +static inline int vx_sock_type(int family)
14579 +{
14580 +       switch (family) {
14581 +       case PF_UNSPEC:
14582 +               return VXA_SOCK_UNSPEC;
14583 +       case PF_UNIX:
14584 +               return VXA_SOCK_UNIX;
14585 +       case PF_INET:
14586 +               return VXA_SOCK_INET;
14587 +       case PF_INET6:
14588 +               return VXA_SOCK_INET6;
14589 +       case PF_PACKET:
14590 +               return VXA_SOCK_PACKET;
14591 +       default:
14592 +               return VXA_SOCK_OTHER;
14593 +       }
14594 +}
14595 +
14596 +#define vx_acc_sock(v, f, p, s) \
14597 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14598 +
14599 +static inline void __vx_acc_sock(struct vx_info *vxi,
14600 +       int family, int pos, int size, char *file, int line)
14601 +{
14602 +       if (vxi) {
14603 +               int type = vx_sock_type(family);
14604 +
14605 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14606 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14607 +       }
14608 +}
14609 +
14610 +#define vx_sock_recv(sk, s) \
14611 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14612 +#define vx_sock_send(sk, s) \
14613 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14614 +#define vx_sock_fail(sk, s) \
14615 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14616 +
14617 +
14618 +#define sock_vx_init(s) do {           \
14619 +       (s)->sk_xid = 0;                \
14620 +       (s)->sk_vx_info = NULL;         \
14621 +       } while (0)
14622 +
14623 +#define sock_nx_init(s) do {           \
14624 +       (s)->sk_nid = 0;                \
14625 +       (s)->sk_nx_info = NULL;         \
14626 +       } while (0)
14627 +
14628 +#else
14629 +#warning duplicate inclusion
14630 +#endif
14631 diff -NurpP --minimal linux-2.6.32/include/linux/vs_tag.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_tag.h
14632 --- linux-2.6.32/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14633 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_tag.h   2009-12-03 20:04:56.000000000 +0100
14634 @@ -0,0 +1,47 @@
14635 +#ifndef _VS_TAG_H
14636 +#define _VS_TAG_H
14637 +
14638 +#include <linux/vserver/tag.h>
14639 +
14640 +/* check conditions */
14641 +
14642 +#define DX_ADMIN       0x0001
14643 +#define DX_WATCH       0x0002
14644 +#define DX_HOSTID      0x0008
14645 +
14646 +#define DX_IDENT       0x0010
14647 +
14648 +#define DX_ARG_MASK    0x0010
14649 +
14650 +
14651 +#define dx_task_tag(t) ((t)->tag)
14652 +
14653 +#define dx_current_tag() dx_task_tag(current)
14654 +
14655 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14656 +
14657 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14658 +
14659 +
14660 +/*
14661 + * check current context for ADMIN/WATCH and
14662 + * optionally against supplied argument
14663 + */
14664 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14665 +{
14666 +       if (mode & DX_ARG_MASK) {
14667 +               if ((mode & DX_IDENT) && (id == cid))
14668 +                       return 1;
14669 +       }
14670 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14671 +               ((mode & DX_WATCH) && (cid == 1)) ||
14672 +               ((mode & DX_HOSTID) && (id == 0)));
14673 +}
14674 +
14675 +struct inode;
14676 +int dx_permission(const struct inode *inode, int mask);
14677 +
14678 +
14679 +#else
14680 +#warning duplicate inclusion
14681 +#endif
14682 diff -NurpP --minimal linux-2.6.32/include/linux/vs_time.h linux-2.6.32-vs2.3.0.36.26/include/linux/vs_time.h
14683 --- linux-2.6.32/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14684 +++ linux-2.6.32-vs2.3.0.36.26/include/linux/vs_time.h  2009-12-03 20:04:56.000000000 +0100
14685 @@ -0,0 +1,19 @@
14686 +#ifndef _VS_TIME_H
14687 +#define _VS_TIME_H
14688 +
14689 +
14690 +/* time faking stuff */
14691 +
14692 +#ifdef CONFIG_VSERVER_VTIME
14693 +
14694 +extern void vx_gettimeofday(struct timeval *tv);
14695 +extern int vx_settimeofday(struct timespec *ts);
14696 +
14697 +#else
14698 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14699 +#define        vx_settimeofday(t)      do_settimeofday(t)
14700 +#endif
14701 +
14702 +#else
14703 +#warning duplicate inclusion
14704 +#endif
14705 diff -NurpP --minimal linux-2.6.32/include/net/addrconf.h linux-2.6.32-vs2.3.0.36.26/include/net/addrconf.h
14706 --- linux-2.6.32/include/net/addrconf.h 2009-12-03 20:02:57.000000000 +0100
14707 +++ linux-2.6.32-vs2.3.0.36.26/include/net/addrconf.h   2009-12-03 20:04:56.000000000 +0100
14708 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14709                                                struct net_device *dev,
14710                                                const struct in6_addr *daddr,
14711                                                unsigned int srcprefs,
14712 -                                              struct in6_addr *saddr);
14713 +                                              struct in6_addr *saddr,
14714 +                                              struct nx_info *nxi);
14715  extern int                     ipv6_get_lladdr(struct net_device *dev,
14716                                                 struct in6_addr *addr,
14717                                                 unsigned char banned_flags);
14718 diff -NurpP --minimal linux-2.6.32/include/net/af_unix.h linux-2.6.32-vs2.3.0.36.26/include/net/af_unix.h
14719 --- linux-2.6.32/include/net/af_unix.h  2008-12-25 00:26:37.000000000 +0100
14720 +++ linux-2.6.32-vs2.3.0.36.26/include/net/af_unix.h    2009-12-03 20:04:56.000000000 +0100
14721 @@ -4,6 +4,7 @@
14722  #include <linux/socket.h>
14723  #include <linux/un.h>
14724  #include <linux/mutex.h>
14725 +#include <linux/vs_base.h>
14726  #include <net/sock.h>
14727  
14728  extern void unix_inflight(struct file *fp);
14729 diff -NurpP --minimal linux-2.6.32/include/net/inet_timewait_sock.h linux-2.6.32-vs2.3.0.36.26/include/net/inet_timewait_sock.h
14730 --- linux-2.6.32/include/net/inet_timewait_sock.h       2009-12-03 20:02:57.000000000 +0100
14731 +++ linux-2.6.32-vs2.3.0.36.26/include/net/inet_timewait_sock.h 2009-12-03 20:04:56.000000000 +0100
14732 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14733  #define tw_hash                        __tw_common.skc_hash
14734  #define tw_prot                        __tw_common.skc_prot
14735  #define tw_net                 __tw_common.skc_net
14736 +#define tw_xid                 __tw_common.skc_xid
14737 +#define tw_vx_info             __tw_common.skc_vx_info
14738 +#define tw_nid                 __tw_common.skc_nid
14739 +#define tw_nx_info             __tw_common.skc_nx_info
14740         int                     tw_timeout;
14741         volatile unsigned char  tw_substate;
14742         /* 3 bits hole, try to pack */
14743 diff -NurpP --minimal linux-2.6.32/include/net/route.h linux-2.6.32-vs2.3.0.36.26/include/net/route.h
14744 --- linux-2.6.32/include/net/route.h    2009-09-10 15:26:27.000000000 +0200
14745 +++ linux-2.6.32-vs2.3.0.36.26/include/net/route.h      2009-12-03 20:04:56.000000000 +0100
14746 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14747                 dst_release(&rt->u.dst);
14748  }
14749  
14750 +#include <linux/vs_base.h>
14751 +#include <linux/vs_inet.h>
14752 +
14753  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14754  
14755  extern const __u8 ip_tos2prio[16];
14756 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14757         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14758  }
14759  
14760 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14761 +       struct rtable **, struct flowi *);
14762 +
14763  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14764                                    __be32 src, u32 tos, int oif, u8 protocol,
14765                                    __be16 sport, __be16 dport, struct sock *sk,
14766 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14767  
14768         int err;
14769         struct net *net = sock_net(sk);
14770 +       struct nx_info *nx_info = current_nx_info();
14771  
14772         if (inet_sk(sk)->transparent)
14773                 fl.flags |= FLOWI_FLAG_ANYSRC;
14774  
14775 -       if (!dst || !src) {
14776 +       if (sk)
14777 +               nx_info = sk->sk_nx_info;
14778 +
14779 +       vxdprintk(VXD_CBIT(net, 4),
14780 +               "ip_route_connect(%p) %p,%p;%lx",
14781 +               sk, nx_info, sk->sk_socket,
14782 +               (sk->sk_socket?sk->sk_socket->flags:0));
14783 +
14784 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14785 +       if (err)
14786 +               return err;
14787 +
14788 +       if (!fl.fl4_dst || !fl.fl4_src) {
14789                 err = __ip_route_output_key(net, rp, &fl);
14790                 if (err)
14791                         return err;
14792 diff -NurpP --minimal linux-2.6.32/include/net/sock.h linux-2.6.32-vs2.3.0.36.26/include/net/sock.h
14793 --- linux-2.6.32/include/net/sock.h     2009-12-03 20:02:57.000000000 +0100
14794 +++ linux-2.6.32-vs2.3.0.36.26/include/net/sock.h       2009-12-03 20:04:56.000000000 +0100
14795 @@ -139,6 +139,10 @@ struct sock_common {
14796  #ifdef CONFIG_NET_NS
14797         struct net              *skc_net;
14798  #endif
14799 +       xid_t                   skc_xid;
14800 +       struct vx_info          *skc_vx_info;
14801 +       nid_t                   skc_nid;
14802 +       struct nx_info          *skc_nx_info;
14803  };
14804  
14805  /**
14806 @@ -225,6 +229,10 @@ struct sock {
14807  #define sk_bind_node           __sk_common.skc_bind_node
14808  #define sk_prot                        __sk_common.skc_prot
14809  #define sk_net                 __sk_common.skc_net
14810 +#define sk_xid                 __sk_common.skc_xid
14811 +#define sk_vx_info             __sk_common.skc_vx_info
14812 +#define sk_nid                 __sk_common.skc_nid
14813 +#define sk_nx_info             __sk_common.skc_nx_info
14814         kmemcheck_bitfield_begin(flags);
14815         unsigned int            sk_shutdown  : 2,
14816                                 sk_no_check  : 2,
14817 diff -NurpP --minimal linux-2.6.32/init/Kconfig linux-2.6.32-vs2.3.0.36.26/init/Kconfig
14818 --- linux-2.6.32/init/Kconfig   2009-12-03 20:02:57.000000000 +0100
14819 +++ linux-2.6.32-vs2.3.0.36.26/init/Kconfig     2009-12-03 20:04:56.000000000 +0100
14820 @@ -477,6 +477,19 @@ config CGROUP_SCHED
14821  
14822  endchoice
14823  
14824 +config CFS_HARD_LIMITS
14825 +       bool "Hard Limits for CFS Group Scheduler"
14826 +       depends on EXPERIMENTAL
14827 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14828 +       default n
14829 +       help
14830 +         This option enables hard limiting of CPU time obtained by
14831 +         a fair task group. Use this if you want to throttle a group of tasks
14832 +         based on its CPU usage. For more details refer to
14833 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14834 +
14835 +         Say N if unsure.
14836 +
14837  menuconfig CGROUPS
14838         boolean "Control Group support"
14839         help
14840 diff -NurpP --minimal linux-2.6.32/init/main.c linux-2.6.32-vs2.3.0.36.26/init/main.c
14841 --- linux-2.6.32/init/main.c    2009-12-03 20:02:57.000000000 +0100
14842 +++ linux-2.6.32-vs2.3.0.36.26/init/main.c      2009-12-03 20:04:56.000000000 +0100
14843 @@ -70,6 +70,7 @@
14844  #include <linux/sfi.h>
14845  #include <linux/shmem_fs.h>
14846  #include <trace/boot.h>
14847 +#include <linux/vserver/percpu.h>
14848  
14849  #include <asm/io.h>
14850  #include <asm/bugs.h>
14851 diff -NurpP --minimal linux-2.6.32/ipc/mqueue.c linux-2.6.32-vs2.3.0.36.26/ipc/mqueue.c
14852 --- linux-2.6.32/ipc/mqueue.c   2009-12-03 20:02:57.000000000 +0100
14853 +++ linux-2.6.32-vs2.3.0.36.26/ipc/mqueue.c     2009-12-03 20:04:56.000000000 +0100
14854 @@ -33,6 +33,8 @@
14855  #include <linux/pid.h>
14856  #include <linux/ipc_namespace.h>
14857  #include <linux/ima.h>
14858 +#include <linux/vs_context.h>
14859 +#include <linux/vs_limit.h>
14860  
14861  #include <net/sock.h>
14862  #include "util.h"
14863 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14864         struct sigevent notify;
14865         struct pid* notify_owner;
14866         struct user_struct *user;       /* user who created, for accounting */
14867 +       struct vx_info *vxi;
14868         struct sock *notify_sock;
14869         struct sk_buff *notify_cookie;
14870  
14871 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14872                 if (S_ISREG(mode)) {
14873                         struct mqueue_inode_info *info;
14874                         struct task_struct *p = current;
14875 +                       struct vx_info *vxi = p->vx_info;
14876                         unsigned long mq_bytes, mq_msg_tblsz;
14877  
14878                         inode->i_fop = &mqueue_file_operations;
14879 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14880                         info->notify_owner = NULL;
14881                         info->qsize = 0;
14882                         info->user = NULL;      /* set when all is ok */
14883 +                       info->vxi = NULL;
14884                         memset(&info->attr, 0, sizeof(info->attr));
14885                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14886                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14887 @@ -153,22 +158,26 @@ static struct inode *mqueue_get_inode(st
14888                         spin_lock(&mq_lock);
14889                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14890                             u->mq_bytes + mq_bytes >
14891 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14892 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14893 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14894                                 spin_unlock(&mq_lock);
14895                                 goto out_inode;
14896                         }
14897                         u->mq_bytes += mq_bytes;
14898 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14899                         spin_unlock(&mq_lock);
14900  
14901                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14902                         if (!info->messages) {
14903                                 spin_lock(&mq_lock);
14904                                 u->mq_bytes -= mq_bytes;
14905 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14906                                 spin_unlock(&mq_lock);
14907                                 goto out_inode;
14908                         }
14909                         /* all is ok */
14910                         info->user = get_uid(u);
14911 +                       info->vxi = get_vx_info(vxi);
14912                 } else if (S_ISDIR(mode)) {
14913                         inc_nlink(inode);
14914                         /* Some things misbehave if size == 0 on a directory */
14915 @@ -269,8 +278,11 @@ static void mqueue_delete_inode(struct i
14916                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14917         user = info->user;
14918         if (user) {
14919 +               struct vx_info *vxi = info->vxi;
14920 +
14921                 spin_lock(&mq_lock);
14922                 user->mq_bytes -= mq_bytes;
14923 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14924                 /*
14925                  * get_ns_from_inode() ensures that the
14926                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14927 @@ -280,6 +292,7 @@ static void mqueue_delete_inode(struct i
14928                 if (ipc_ns)
14929                         ipc_ns->mq_queues_count--;
14930                 spin_unlock(&mq_lock);
14931 +               put_vx_info(vxi);
14932                 free_uid(user);
14933         }
14934         if (ipc_ns)
14935 diff -NurpP --minimal linux-2.6.32/ipc/msg.c linux-2.6.32-vs2.3.0.36.26/ipc/msg.c
14936 --- linux-2.6.32/ipc/msg.c      2009-03-24 14:22:44.000000000 +0100
14937 +++ linux-2.6.32-vs2.3.0.36.26/ipc/msg.c        2009-12-03 20:04:56.000000000 +0100
14938 @@ -38,6 +38,7 @@
14939  #include <linux/rwsem.h>
14940  #include <linux/nsproxy.h>
14941  #include <linux/ipc_namespace.h>
14942 +#include <linux/vs_base.h>
14943  
14944  #include <asm/current.h>
14945  #include <asm/uaccess.h>
14946 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14947  
14948         msq->q_perm.mode = msgflg & S_IRWXUGO;
14949         msq->q_perm.key = key;
14950 +       msq->q_perm.xid = vx_current_xid();
14951  
14952         msq->q_perm.security = NULL;
14953         retval = security_msg_queue_alloc(msq);
14954 diff -NurpP --minimal linux-2.6.32/ipc/namespace.c linux-2.6.32-vs2.3.0.36.26/ipc/namespace.c
14955 --- linux-2.6.32/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
14956 +++ linux-2.6.32-vs2.3.0.36.26/ipc/namespace.c  2009-12-03 20:04:56.000000000 +0100
14957 @@ -11,6 +11,8 @@
14958  #include <linux/slab.h>
14959  #include <linux/fs.h>
14960  #include <linux/mount.h>
14961 +#include <linux/vs_base.h>
14962 +#include <linux/vserver/global.h>
14963  
14964  #include "util.h"
14965  
14966 diff -NurpP --minimal linux-2.6.32/ipc/sem.c linux-2.6.32-vs2.3.0.36.26/ipc/sem.c
14967 --- linux-2.6.32/ipc/sem.c      2009-09-10 15:26:27.000000000 +0200
14968 +++ linux-2.6.32-vs2.3.0.36.26/ipc/sem.c        2009-12-03 20:04:56.000000000 +0100
14969 @@ -83,6 +83,8 @@
14970  #include <linux/rwsem.h>
14971  #include <linux/nsproxy.h>
14972  #include <linux/ipc_namespace.h>
14973 +#include <linux/vs_base.h>
14974 +#include <linux/vs_limit.h>
14975  
14976  #include <asm/uaccess.h>
14977  #include "util.h"
14978 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
14979  
14980         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14981         sma->sem_perm.key = key;
14982 +       sma->sem_perm.xid = vx_current_xid();
14983  
14984         sma->sem_perm.security = NULL;
14985         retval = security_sem_alloc(sma);
14986 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
14987                 return id;
14988         }
14989         ns->used_sems += nsems;
14990 +       /* FIXME: obsoleted? */
14991 +       vx_semary_inc(sma);
14992 +       vx_nsems_add(sma, nsems);
14993  
14994         sma->sem_base = (struct sem *) &sma[1];
14995         INIT_LIST_HEAD(&sma->sem_pending);
14996 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
14997         sem_unlock(sma);
14998  
14999         ns->used_sems -= sma->sem_nsems;
15000 +       /* FIXME: obsoleted? */
15001 +       vx_nsems_sub(sma, sma->sem_nsems);
15002 +       vx_semary_dec(sma);
15003         security_sem_free(sma);
15004         ipc_rcu_putref(sma);
15005  }
15006 diff -NurpP --minimal linux-2.6.32/ipc/shm.c linux-2.6.32-vs2.3.0.36.26/ipc/shm.c
15007 --- linux-2.6.32/ipc/shm.c      2009-12-03 20:02:57.000000000 +0100
15008 +++ linux-2.6.32-vs2.3.0.36.26/ipc/shm.c        2009-12-03 20:04:56.000000000 +0100
15009 @@ -40,6 +40,8 @@
15010  #include <linux/mount.h>
15011  #include <linux/ipc_namespace.h>
15012  #include <linux/ima.h>
15013 +#include <linux/vs_context.h>
15014 +#include <linux/vs_limit.h>
15015  
15016  #include <asm/uaccess.h>
15017  
15018 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
15019   */
15020  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15021  {
15022 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15023 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15024 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15025 +
15026 +       vx_ipcshm_sub(vxi, shp, numpages);
15027 +       ns->shm_tot -= numpages;
15028 +
15029         shm_rmid(ns, shp);
15030         shm_unlock(shp);
15031         if (!is_file_hugepages(shp->shm_file))
15032 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
15033                                                 shp->mlock_user);
15034         fput (shp->shm_file);
15035         security_shm_free(shp);
15036 +       put_vx_info(vxi);
15037         ipc_rcu_putref(shp);
15038  }
15039  
15040 @@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
15041         if (ns->shm_tot + numpages > ns->shm_ctlall)
15042                 return -ENOSPC;
15043  
15044 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15045 +               return -ENOSPC;
15046 +
15047         shp = ipc_rcu_alloc(sizeof(*shp));
15048         if (!shp)
15049                 return -ENOMEM;
15050  
15051         shp->shm_perm.key = key;
15052 +       shp->shm_perm.xid = vx_current_xid();
15053         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15054         shp->mlock_user = NULL;
15055  
15056 @@ -407,6 +419,7 @@ static int newseg(struct ipc_namespace *
15057         ns->shm_tot += numpages;
15058         error = shp->shm_perm.id;
15059         shm_unlock(shp);
15060 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15061         return error;
15062  
15063  no_id:
15064 diff -NurpP --minimal linux-2.6.32/kernel/capability.c linux-2.6.32-vs2.3.0.36.26/kernel/capability.c
15065 --- linux-2.6.32/kernel/capability.c    2009-03-24 14:22:44.000000000 +0100
15066 +++ linux-2.6.32-vs2.3.0.36.26/kernel/capability.c      2009-12-03 20:04:56.000000000 +0100
15067 @@ -14,6 +14,7 @@
15068  #include <linux/security.h>
15069  #include <linux/syscalls.h>
15070  #include <linux/pid_namespace.h>
15071 +#include <linux/vs_context.h>
15072  #include <asm/uaccess.h>
15073  #include "cred-internals.h"
15074  
15075 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15076         return 0;
15077  }
15078  
15079 +
15080  /*
15081   * The only thing that can change the capabilities of the current
15082   * process is the current process. As such, we can't be in this code
15083 @@ -289,6 +291,8 @@ error:
15084         return ret;
15085  }
15086  
15087 +#include <linux/vserver/base.h>
15088 +
15089  /**
15090   * capable - Determine if the current task has a superior capability in effect
15091   * @cap: The capability to be tested for
15092 @@ -301,6 +305,9 @@ error:
15093   */
15094  int capable(int cap)
15095  {
15096 +       /* here for now so we don't require task locking */
15097 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15098 +               return 0;
15099         if (unlikely(!cap_valid(cap))) {
15100                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15101                 BUG();
15102 diff -NurpP --minimal linux-2.6.32/kernel/compat.c linux-2.6.32-vs2.3.0.36.26/kernel/compat.c
15103 --- linux-2.6.32/kernel/compat.c        2009-09-10 15:26:27.000000000 +0200
15104 +++ linux-2.6.32-vs2.3.0.36.26/kernel/compat.c  2009-12-03 20:04:56.000000000 +0100
15105 @@ -902,7 +902,7 @@ asmlinkage long compat_sys_time(compat_t
15106         compat_time_t i;
15107         struct timeval tv;
15108  
15109 -       do_gettimeofday(&tv);
15110 +       vx_gettimeofday(&tv);
15111         i = tv.tv_sec;
15112  
15113         if (tloc) {
15114 @@ -927,7 +927,7 @@ asmlinkage long compat_sys_stime(compat_
15115         if (err)
15116                 return err;
15117  
15118 -       do_settimeofday(&tv);
15119 +       vx_settimeofday(&tv);
15120         return 0;
15121  }
15122  
15123 diff -NurpP --minimal linux-2.6.32/kernel/exit.c linux-2.6.32-vs2.3.0.36.26/kernel/exit.c
15124 --- linux-2.6.32/kernel/exit.c  2009-12-03 20:02:57.000000000 +0100
15125 +++ linux-2.6.32-vs2.3.0.36.26/kernel/exit.c    2009-12-03 20:04:56.000000000 +0100
15126 @@ -48,6 +48,10 @@
15127  #include <linux/fs_struct.h>
15128  #include <linux/init_task.h>
15129  #include <linux/perf_event.h>
15130 +#include <linux/vs_limit.h>
15131 +#include <linux/vs_context.h>
15132 +#include <linux/vs_network.h>
15133 +#include <linux/vs_pid.h>
15134  #include <trace/events/sched.h>
15135  
15136  #include <asm/uaccess.h>
15137 @@ -488,9 +492,11 @@ static void close_files(struct files_str
15138                                         filp_close(file, files);
15139                                         cond_resched();
15140                                 }
15141 +                               vx_openfd_dec(i);
15142                         }
15143                         i++;
15144                         set >>= 1;
15145 +                       cond_resched();
15146                 }
15147         }
15148  }
15149 @@ -1011,11 +1017,16 @@ NORET_TYPE void do_exit(long code)
15150  
15151         validate_creds_for_do_exit(tsk);
15152  
15153 +       /* needs to stay after exit_notify() */
15154 +       exit_vx_info(tsk, code);
15155 +       exit_nx_info(tsk);
15156 +
15157         preempt_disable();
15158         exit_rcu();
15159         /* causes final put_task_struct in finish_task_switch(). */
15160         tsk->state = TASK_DEAD;
15161         schedule();
15162 +       printk("bad task: %p [%lx]\n", current, current->state);
15163         BUG();
15164         /* Avoid "noreturn function does return".  */
15165         for (;;)
15166 diff -NurpP --minimal linux-2.6.32/kernel/fork.c linux-2.6.32-vs2.3.0.36.26/kernel/fork.c
15167 --- linux-2.6.32/kernel/fork.c  2009-12-03 20:02:57.000000000 +0100
15168 +++ linux-2.6.32-vs2.3.0.36.26/kernel/fork.c    2009-12-03 20:04:56.000000000 +0100
15169 @@ -64,6 +64,10 @@
15170  #include <linux/magic.h>
15171  #include <linux/perf_event.h>
15172  #include <linux/posix-timers.h>
15173 +#include <linux/vs_context.h>
15174 +#include <linux/vs_network.h>
15175 +#include <linux/vs_limit.h>
15176 +#include <linux/vs_memory.h>
15177  
15178  #include <asm/pgtable.h>
15179  #include <asm/pgalloc.h>
15180 @@ -151,6 +155,8 @@ void free_task(struct task_struct *tsk)
15181         account_kernel_stack(tsk->stack, -1);
15182         free_thread_info(tsk->stack);
15183         rt_mutex_debug_task_free(tsk);
15184 +       clr_vx_info(&tsk->vx_info);
15185 +       clr_nx_info(&tsk->nx_info);
15186         ftrace_graph_exit_task(tsk);
15187         free_task_struct(tsk);
15188  }
15189 @@ -296,6 +302,8 @@ static int dup_mmap(struct mm_struct *mm
15190         mm->free_area_cache = oldmm->mmap_base;
15191         mm->cached_hole_size = ~0UL;
15192         mm->map_count = 0;
15193 +       __set_mm_counter(mm, file_rss, 0);
15194 +       __set_mm_counter(mm, anon_rss, 0);
15195         cpumask_clear(mm_cpumask(mm));
15196         mm->mm_rb = RB_ROOT;
15197         rb_link = &mm->mm_rb.rb_node;
15198 @@ -310,7 +318,7 @@ static int dup_mmap(struct mm_struct *mm
15199  
15200                 if (mpnt->vm_flags & VM_DONTCOPY) {
15201                         long pages = vma_pages(mpnt);
15202 -                       mm->total_vm -= pages;
15203 +                       vx_vmpages_sub(mm, pages);
15204                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15205                                                                 -pages);
15206                         continue;
15207 @@ -452,8 +460,8 @@ static struct mm_struct * mm_init(struct
15208                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15209         mm->core_state = NULL;
15210         mm->nr_ptes = 0;
15211 -       set_mm_counter(mm, file_rss, 0);
15212 -       set_mm_counter(mm, anon_rss, 0);
15213 +       __set_mm_counter(mm, file_rss, 0);
15214 +       __set_mm_counter(mm, anon_rss, 0);
15215         spin_lock_init(&mm->page_table_lock);
15216         mm->free_area_cache = TASK_UNMAPPED_BASE;
15217         mm->cached_hole_size = ~0UL;
15218 @@ -463,6 +471,7 @@ static struct mm_struct * mm_init(struct
15219         if (likely(!mm_alloc_pgd(mm))) {
15220                 mm->def_flags = 0;
15221                 mmu_notifier_mm_init(mm);
15222 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15223                 return mm;
15224         }
15225  
15226 @@ -496,6 +505,7 @@ void __mmdrop(struct mm_struct *mm)
15227         mm_free_pgd(mm);
15228         destroy_context(mm);
15229         mmu_notifier_mm_destroy(mm);
15230 +       clr_vx_info(&mm->mm_vx_info);
15231         free_mm(mm);
15232  }
15233  EXPORT_SYMBOL_GPL(__mmdrop);
15234 @@ -631,6 +641,7 @@ struct mm_struct *dup_mm(struct task_str
15235                 goto fail_nomem;
15236  
15237         memcpy(mm, oldmm, sizeof(*mm));
15238 +       mm->mm_vx_info = NULL;
15239  
15240         /* Initializing for Swap token stuff */
15241         mm->token_priority = 0;
15242 @@ -669,6 +680,7 @@ fail_nocontext:
15243          * If init_new_context() failed, we cannot use mmput() to free the mm
15244          * because it calls destroy_context()
15245          */
15246 +       clr_vx_info(&mm->mm_vx_info);
15247         mm_free_pgd(mm);
15248         free_mm(mm);
15249         return NULL;
15250 @@ -980,6 +992,8 @@ static struct task_struct *copy_process(
15251         int retval;
15252         struct task_struct *p;
15253         int cgroup_callbacks_done = 0;
15254 +       struct vx_info *vxi;
15255 +       struct nx_info *nxi;
15256  
15257         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15258                 return ERR_PTR(-EINVAL);
15259 @@ -1026,12 +1040,28 @@ static struct task_struct *copy_process(
15260         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15261         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15262  #endif
15263 +       init_vx_info(&p->vx_info, current_vx_info());
15264 +       init_nx_info(&p->nx_info, current_nx_info());
15265 +
15266 +       /* check vserver memory */
15267 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15268 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15269 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15270 +               else
15271 +                       goto bad_fork_free;
15272 +       }
15273 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15274 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15275 +                       goto bad_fork_cleanup_vm;
15276 +       }
15277         retval = -EAGAIN;
15278 +       if (!vx_nproc_avail(1))
15279 +               goto bad_fork_cleanup_vm;
15280         if (atomic_read(&p->real_cred->user->processes) >=
15281                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15282                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15283                     p->real_cred->user != INIT_USER)
15284 -                       goto bad_fork_free;
15285 +                       goto bad_fork_cleanup_vm;
15286         }
15287  
15288         retval = copy_creds(p, clone_flags);
15289 @@ -1300,6 +1330,18 @@ static struct task_struct *copy_process(
15290  
15291         total_forks++;
15292         spin_unlock(&current->sighand->siglock);
15293 +
15294 +       /* p is copy of current */
15295 +       vxi = p->vx_info;
15296 +       if (vxi) {
15297 +               claim_vx_info(vxi, p);
15298 +               atomic_inc(&vxi->cvirt.nr_threads);
15299 +               atomic_inc(&vxi->cvirt.total_forks);
15300 +               vx_nproc_inc(p);
15301 +       }
15302 +       nxi = p->nx_info;
15303 +       if (nxi)
15304 +               claim_nx_info(nxi, p);
15305         write_unlock_irq(&tasklist_lock);
15306         proc_fork_connector(p);
15307         cgroup_post_fork(p);
15308 @@ -1341,6 +1383,9 @@ bad_fork_cleanup_cgroup:
15309  bad_fork_cleanup_count:
15310         atomic_dec(&p->cred->user->processes);
15311         exit_creds(p);
15312 +bad_fork_cleanup_vm:
15313 +       if (p->mm && !(clone_flags & CLONE_VM))
15314 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15315  bad_fork_free:
15316         free_task(p);
15317  fork_out:
15318 diff -NurpP --minimal linux-2.6.32/kernel/kthread.c linux-2.6.32-vs2.3.0.36.26/kernel/kthread.c
15319 --- linux-2.6.32/kernel/kthread.c       2009-12-03 20:02:58.000000000 +0100
15320 +++ linux-2.6.32-vs2.3.0.36.26/kernel/kthread.c 2009-12-03 20:04:56.000000000 +0100
15321 @@ -14,6 +14,7 @@
15322  #include <linux/file.h>
15323  #include <linux/module.h>
15324  #include <linux/mutex.h>
15325 +#include <linux/vs_pid.h>
15326  #include <trace/events/sched.h>
15327  
15328  static DEFINE_SPINLOCK(kthread_create_lock);
15329 diff -NurpP --minimal linux-2.6.32/kernel/Makefile linux-2.6.32-vs2.3.0.36.26/kernel/Makefile
15330 --- linux-2.6.32/kernel/Makefile        2009-12-03 20:02:57.000000000 +0100
15331 +++ linux-2.6.32-vs2.3.0.36.26/kernel/Makefile  2009-12-03 20:04:56.000000000 +0100
15332 @@ -23,6 +23,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15333  CFLAGS_REMOVE_sched_clock.o = -pg
15334  endif
15335  
15336 +obj-y += vserver/
15337  obj-$(CONFIG_FREEZER) += freezer.o
15338  obj-$(CONFIG_PROFILING) += profile.o
15339  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15340 diff -NurpP --minimal linux-2.6.32/kernel/nsproxy.c linux-2.6.32-vs2.3.0.36.26/kernel/nsproxy.c
15341 --- linux-2.6.32/kernel/nsproxy.c       2009-09-10 15:26:28.000000000 +0200
15342 +++ linux-2.6.32-vs2.3.0.36.26/kernel/nsproxy.c 2009-12-03 20:04:56.000000000 +0100
15343 @@ -19,6 +19,8 @@
15344  #include <linux/mnt_namespace.h>
15345  #include <linux/utsname.h>
15346  #include <linux/pid_namespace.h>
15347 +#include <linux/vserver/global.h>
15348 +#include <linux/vserver/debug.h>
15349  #include <net/net_namespace.h>
15350  #include <linux/ipc_namespace.h>
15351  
15352 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15353         struct nsproxy *nsproxy;
15354  
15355         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15356 -       if (nsproxy)
15357 +       if (nsproxy) {
15358                 atomic_set(&nsproxy->count, 1);
15359 +               atomic_inc(&vs_global_nsproxy);
15360 +       }
15361 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15362         return nsproxy;
15363  }
15364  
15365 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15366   * Return the newly created nsproxy.  Do not attach this to the task,
15367   * leave it to the caller to do proper locking and attach it to task.
15368   */
15369 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15370 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15371 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15372 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15373  {
15374         struct nsproxy *new_nsp;
15375         int err;
15376  
15377 +       vxdprintk(VXD_CBIT(space, 4),
15378 +               "unshare_namespaces(0x%08lx,%p,%p)",
15379 +               flags, orig, new_fs);
15380 +
15381         new_nsp = create_nsproxy();
15382         if (!new_nsp)
15383                 return ERR_PTR(-ENOMEM);
15384  
15385 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15386 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15387         if (IS_ERR(new_nsp->mnt_ns)) {
15388                 err = PTR_ERR(new_nsp->mnt_ns);
15389                 goto out_ns;
15390         }
15391  
15392 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15393 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15394         if (IS_ERR(new_nsp->uts_ns)) {
15395                 err = PTR_ERR(new_nsp->uts_ns);
15396                 goto out_uts;
15397         }
15398  
15399 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15400 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15401         if (IS_ERR(new_nsp->ipc_ns)) {
15402                 err = PTR_ERR(new_nsp->ipc_ns);
15403                 goto out_ipc;
15404         }
15405  
15406 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15407 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15408         if (IS_ERR(new_nsp->pid_ns)) {
15409                 err = PTR_ERR(new_nsp->pid_ns);
15410                 goto out_pid;
15411         }
15412  
15413 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15414 +       /* disabled now?
15415 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15416 +       if (IS_ERR(new_nsp->user_ns)) {
15417 +               err = PTR_ERR(new_nsp->user_ns);
15418 +               goto out_user;
15419 +       } */
15420 +
15421 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15422         if (IS_ERR(new_nsp->net_ns)) {
15423                 err = PTR_ERR(new_nsp->net_ns);
15424                 goto out_net;
15425 @@ -100,6 +116,38 @@ out_ns:
15426         return ERR_PTR(err);
15427  }
15428  
15429 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15430 +                       struct fs_struct *new_fs)
15431 +{
15432 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15433 +}
15434 +
15435 +/*
15436 + * copies the nsproxy, setting refcount to 1, and grabbing a
15437 + * reference to all contained namespaces.
15438 + */
15439 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15440 +{
15441 +       struct nsproxy *ns = create_nsproxy();
15442 +
15443 +       if (ns) {
15444 +               memcpy(ns, orig, sizeof(struct nsproxy));
15445 +               atomic_set(&ns->count, 1);
15446 +
15447 +               if (ns->mnt_ns)
15448 +                       get_mnt_ns(ns->mnt_ns);
15449 +               if (ns->uts_ns)
15450 +                       get_uts_ns(ns->uts_ns);
15451 +               if (ns->ipc_ns)
15452 +                       get_ipc_ns(ns->ipc_ns);
15453 +               if (ns->pid_ns)
15454 +                       get_pid_ns(ns->pid_ns);
15455 +               if (ns->net_ns)
15456 +                       get_net(ns->net_ns);
15457 +       }
15458 +       return ns;
15459 +}
15460 +
15461  /*
15462   * called from clone.  This now handles copy for nsproxy and all
15463   * namespaces therein.
15464 @@ -107,9 +155,12 @@ out_ns:
15465  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15466  {
15467         struct nsproxy *old_ns = tsk->nsproxy;
15468 -       struct nsproxy *new_ns;
15469 +       struct nsproxy *new_ns = NULL;
15470         int err = 0;
15471  
15472 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15473 +               flags, tsk, old_ns);
15474 +
15475         if (!old_ns)
15476                 return 0;
15477  
15478 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15479                                 CLONE_NEWPID | CLONE_NEWNET)))
15480                 return 0;
15481  
15482 -       if (!capable(CAP_SYS_ADMIN)) {
15483 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15484                 err = -EPERM;
15485                 goto out;
15486         }
15487 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15488  
15489  out:
15490         put_nsproxy(old_ns);
15491 +       vxdprintk(VXD_CBIT(space, 3),
15492 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15493 +               flags, tsk, old_ns, err, new_ns);
15494         return err;
15495  }
15496  
15497 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15498                 put_ipc_ns(ns->ipc_ns);
15499         if (ns->pid_ns)
15500                 put_pid_ns(ns->pid_ns);
15501 -       put_net(ns->net_ns);
15502 +       if (ns->net_ns)
15503 +               put_net(ns->net_ns);
15504 +       atomic_dec(&vs_global_nsproxy);
15505         kmem_cache_free(nsproxy_cachep, ns);
15506  }
15507  
15508 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15509  {
15510         int err = 0;
15511  
15512 +       vxdprintk(VXD_CBIT(space, 4),
15513 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15514 +               unshare_flags, current->nsproxy);
15515 +
15516         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15517                                CLONE_NEWNET)))
15518                 return 0;
15519  
15520 -       if (!capable(CAP_SYS_ADMIN))
15521 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15522                 return -EPERM;
15523  
15524         *new_nsp = create_new_namespaces(unshare_flags, current,
15525 diff -NurpP --minimal linux-2.6.32/kernel/pid.c linux-2.6.32-vs2.3.0.36.26/kernel/pid.c
15526 --- linux-2.6.32/kernel/pid.c   2009-12-03 20:02:58.000000000 +0100
15527 +++ linux-2.6.32-vs2.3.0.36.26/kernel/pid.c     2009-12-03 20:04:56.000000000 +0100
15528 @@ -36,6 +36,7 @@
15529  #include <linux/pid_namespace.h>
15530  #include <linux/init_task.h>
15531  #include <linux/syscalls.h>
15532 +#include <linux/vs_pid.h>
15533  
15534  #define pid_hashfn(nr, ns)     \
15535         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15536 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15537  
15538  struct pid *find_vpid(int nr)
15539  {
15540 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15541 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15542  }
15543  EXPORT_SYMBOL_GPL(find_vpid);
15544  
15545 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15546  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15547  {
15548         struct task_struct *result = NULL;
15549 +
15550 +       if (type == PIDTYPE_REALPID)
15551 +               type = PIDTYPE_PID;
15552         if (pid) {
15553                 struct hlist_node *first;
15554                 first = rcu_dereference(pid->tasks[type].first);
15555 @@ -380,7 +384,7 @@ EXPORT_SYMBOL(pid_task);
15556   */
15557  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15558  {
15559 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15560 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15561  }
15562  
15563  struct task_struct *find_task_by_vpid(pid_t vnr)
15564 @@ -422,7 +426,7 @@ struct pid *find_get_pid(pid_t nr)
15565  }
15566  EXPORT_SYMBOL_GPL(find_get_pid);
15567  
15568 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15569 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15570  {
15571         struct upid *upid;
15572         pid_t nr = 0;
15573 @@ -435,6 +439,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15574         return nr;
15575  }
15576  
15577 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15578 +{
15579 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15580 +}
15581 +
15582  pid_t pid_vnr(struct pid *pid)
15583  {
15584         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15585 diff -NurpP --minimal linux-2.6.32/kernel/pid_namespace.c linux-2.6.32-vs2.3.0.36.26/kernel/pid_namespace.c
15586 --- linux-2.6.32/kernel/pid_namespace.c 2009-12-03 20:02:58.000000000 +0100
15587 +++ linux-2.6.32-vs2.3.0.36.26/kernel/pid_namespace.c   2009-12-03 20:04:56.000000000 +0100
15588 @@ -13,6 +13,7 @@
15589  #include <linux/syscalls.h>
15590  #include <linux/err.h>
15591  #include <linux/acct.h>
15592 +#include <linux/vserver/global.h>
15593  
15594  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15595  
15596 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15597                 goto out_free_map;
15598  
15599         kref_init(&ns->kref);
15600 +       atomic_inc(&vs_global_pid_ns);
15601         ns->level = level;
15602         ns->parent = get_pid_ns(parent_pid_ns);
15603  
15604 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15605  
15606         for (i = 0; i < PIDMAP_ENTRIES; i++)
15607                 kfree(ns->pidmap[i].page);
15608 +       atomic_dec(&vs_global_pid_ns);
15609         kmem_cache_free(pid_ns_cachep, ns);
15610  }
15611  
15612 diff -NurpP --minimal linux-2.6.32/kernel/posix-timers.c linux-2.6.32-vs2.3.0.36.26/kernel/posix-timers.c
15613 --- linux-2.6.32/kernel/posix-timers.c  2009-12-03 20:02:58.000000000 +0100
15614 +++ linux-2.6.32-vs2.3.0.36.26/kernel/posix-timers.c    2009-12-03 20:04:56.000000000 +0100
15615 @@ -46,6 +46,7 @@
15616  #include <linux/wait.h>
15617  #include <linux/workqueue.h>
15618  #include <linux/module.h>
15619 +#include <linux/vs_context.h>
15620  
15621  /*
15622   * Management arrays for POSIX timers.  Timers are kept in slab memory
15623 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15624  {
15625         struct task_struct *task;
15626         int shared, ret = -1;
15627 +
15628         /*
15629          * FIXME: if ->sigq is queued we can race with
15630          * dequeue_signal()->do_schedule_next_timer().
15631 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15632         rcu_read_lock();
15633         task = pid_task(timr->it_pid, PIDTYPE_PID);
15634         if (task) {
15635 +               struct vx_info_save vxis;
15636 +               struct vx_info *vxi;
15637 +
15638 +               vxi = get_vx_info(task->vx_info);
15639 +               enter_vx_info(vxi, &vxis);
15640                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15641                 ret = send_sigqueue(timr->sigq, task, shared);
15642 +               leave_vx_info(&vxis);
15643 +               put_vx_info(vxi);
15644         }
15645         rcu_read_unlock();
15646 +
15647         /* If we failed to send the signal the timer stops. */
15648         return ret > 0;
15649  }
15650 diff -NurpP --minimal linux-2.6.32/kernel/printk.c linux-2.6.32-vs2.3.0.36.26/kernel/printk.c
15651 --- linux-2.6.32/kernel/printk.c        2009-12-03 20:02:58.000000000 +0100
15652 +++ linux-2.6.32-vs2.3.0.36.26/kernel/printk.c  2009-12-03 20:04:56.000000000 +0100
15653 @@ -33,6 +33,7 @@
15654  #include <linux/bootmem.h>
15655  #include <linux/syscalls.h>
15656  #include <linux/kexec.h>
15657 +#include <linux/vs_cvirt.h>
15658  
15659  #include <asm/uaccess.h>
15660  
15661 @@ -276,18 +277,13 @@ int do_syslog(int type, char __user *buf
15662         unsigned i, j, limit, count;
15663         int do_clear = 0;
15664         char c;
15665 -       int error = 0;
15666 +       int error;
15667  
15668         error = security_syslog(type);
15669         if (error)
15670                 return error;
15671  
15672 -       switch (type) {
15673 -       case 0:         /* Close log */
15674 -               break;
15675 -       case 1:         /* Open log */
15676 -               break;
15677 -       case 2:         /* Read from log */
15678 +       if ((type >= 2) && (type <= 4)) {
15679                 error = -EINVAL;
15680                 if (!buf || len < 0)
15681                         goto out;
15682 @@ -298,6 +294,16 @@ int do_syslog(int type, char __user *buf
15683                         error = -EFAULT;
15684                         goto out;
15685                 }
15686 +       }
15687 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15688 +               return vx_do_syslog(type, buf, len);
15689 +
15690 +       switch (type) {
15691 +       case 0:         /* Close log */
15692 +               break;
15693 +       case 1:         /* Open log */
15694 +               break;
15695 +       case 2:         /* Read from log */
15696                 error = wait_event_interruptible(log_wait,
15697                                                         (log_start - log_end));
15698                 if (error)
15699 @@ -322,16 +328,6 @@ int do_syslog(int type, char __user *buf
15700                 do_clear = 1;
15701                 /* FALL THRU */
15702         case 3:         /* Read last kernel messages */
15703 -               error = -EINVAL;
15704 -               if (!buf || len < 0)
15705 -                       goto out;
15706 -               error = 0;
15707 -               if (!len)
15708 -                       goto out;
15709 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15710 -                       error = -EFAULT;
15711 -                       goto out;
15712 -               }
15713                 count = len;
15714                 if (count > log_buf_len)
15715                         count = log_buf_len;
15716 diff -NurpP --minimal linux-2.6.32/kernel/ptrace.c linux-2.6.32-vs2.3.0.36.26/kernel/ptrace.c
15717 --- linux-2.6.32/kernel/ptrace.c        2009-12-03 20:02:58.000000000 +0100
15718 +++ linux-2.6.32-vs2.3.0.36.26/kernel/ptrace.c  2009-12-03 20:04:56.000000000 +0100
15719 @@ -22,6 +22,7 @@
15720  #include <linux/pid_namespace.h>
15721  #include <linux/syscalls.h>
15722  #include <linux/uaccess.h>
15723 +#include <linux/vs_context.h>
15724  
15725  
15726  /*
15727 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15728                 dumpable = get_dumpable(task->mm);
15729         if (!dumpable && !capable(CAP_SYS_PTRACE))
15730                 return -EPERM;
15731 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15732 +               return -EPERM;
15733 +       if (!vx_check(task->xid, VS_IDENT) &&
15734 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15735 +               return -EACCES;
15736  
15737         return security_ptrace_access_check(task, mode);
15738  }
15739 @@ -621,6 +627,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15740                 goto out;
15741         }
15742  
15743 +       ret = -EPERM;
15744 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15745 +               goto out_put_task_struct;
15746 +
15747         if (request == PTRACE_ATTACH) {
15748                 ret = ptrace_attach(child);
15749                 /*
15750 diff -NurpP --minimal linux-2.6.32/kernel/sched.c linux-2.6.32-vs2.3.0.36.26/kernel/sched.c
15751 --- linux-2.6.32/kernel/sched.c 2009-12-03 20:02:58.000000000 +0100
15752 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sched.c   2009-12-03 20:04:56.000000000 +0100
15753 @@ -71,6 +71,8 @@
15754  #include <linux/debugfs.h>
15755  #include <linux/ctype.h>
15756  #include <linux/ftrace.h>
15757 +#include <linux/vs_sched.h>
15758 +#include <linux/vs_cvirt.h>
15759  
15760  #include <asm/tlb.h>
15761  #include <asm/irq_regs.h>
15762 @@ -237,6 +239,15 @@ static DEFINE_MUTEX(sched_domains_mutex)
15763  
15764  #include <linux/cgroup.h>
15765  
15766 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
15767 +struct cfs_bandwidth {
15768 +       spinlock_t              cfs_runtime_lock;
15769 +       ktime_t                 cfs_period;
15770 +       u64                     cfs_runtime;
15771 +       struct hrtimer          cfs_period_timer;
15772 +};
15773 +#endif
15774 +
15775  struct cfs_rq;
15776  
15777  static LIST_HEAD(task_groups);
15778 @@ -257,6 +268,9 @@ struct task_group {
15779         /* runqueue "owned" by this group on each cpu */
15780         struct cfs_rq **cfs_rq;
15781         unsigned long shares;
15782 +#ifdef CONFIG_CFS_HARD_LIMITS
15783 +       struct cfs_bandwidth cfs_bandwidth;
15784 +#endif
15785  #endif
15786  
15787  #ifdef CONFIG_RT_GROUP_SCHED
15788 @@ -446,6 +460,19 @@ struct cfs_rq {
15789         unsigned long rq_weight;
15790  #endif
15791  #endif
15792 +#ifdef CONFIG_CFS_HARD_LIMITS
15793 +       /* set when the group is throttled  on this cpu */
15794 +       int cfs_throttled;
15795 +
15796 +       /* runtime currently consumed by the group on this rq */
15797 +       u64 cfs_time;
15798 +
15799 +       /* runtime available to the group on this rq */
15800 +       u64 cfs_runtime;
15801 +
15802 +       /* Protects the cfs runtime related fields of this cfs_rq */
15803 +       spinlock_t cfs_runtime_lock;
15804 +#endif
15805  };
15806  
15807  /* Real-Time classes' related field in a runqueue: */
15808 @@ -1607,6 +1634,7 @@ static void update_group_shares_cpu(stru
15809         }
15810  }
15811  
15812 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
15813  /*
15814   * Re-compute the task group their per cpu shares over the given domain.
15815   * This needs to be done in a bottom-up fashion because the rq weight of a
15816 @@ -1634,8 +1662,10 @@ static int tg_shares_up(struct task_grou
15817                  * If there are currently no tasks on the cpu pretend there
15818                  * is one of average load so that when a new task gets to
15819                  * run here it will not get delayed by group starvation.
15820 +                * Also if the group is throttled on this cpu, pretend that
15821 +                * it has no tasks.
15822                  */
15823 -               if (!weight)
15824 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
15825                         weight = NICE_0_LOAD;
15826  
15827                 rq_weight += weight;
15828 @@ -1811,6 +1841,175 @@ static void cfs_rq_set_shares(struct cfs
15829  
15830  static void calc_load_account_active(struct rq *this_rq);
15831  
15832 +
15833 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
15834 +
15835 +#ifdef CONFIG_SMP
15836 +static inline const struct cpumask *sched_bw_period_mask(void)
15837 +{
15838 +       return cpu_rq(smp_processor_id())->rd->span;
15839 +}
15840 +#else /* !CONFIG_SMP */
15841 +static inline const struct cpumask *sched_bw_period_mask(void)
15842 +{
15843 +       return cpu_online_mask;
15844 +}
15845 +#endif /* CONFIG_SMP */
15846 +
15847 +#else
15848 +static inline const struct cpumask *sched_bw_period_mask(void)
15849 +{
15850 +       return cpu_online_mask;
15851 +}
15852 +
15853 +#endif
15854 +
15855 +#ifdef CONFIG_FAIR_GROUP_SCHED
15856 +#ifdef CONFIG_CFS_HARD_LIMITS
15857 +
15858 +/*
15859 + * Runtime allowed for a cfs group before it is hard limited.
15860 + * default: Infinite which means no hard limiting.
15861 + */
15862 +u64 sched_cfs_runtime = RUNTIME_INF;
15863 +
15864 +/*
15865 + * period over which we hard limit the cfs group's bandwidth.
15866 + * default: 0.5s
15867 + */
15868 +u64 sched_cfs_period = 500000;
15869 +
15870 +static inline u64 global_cfs_period(void)
15871 +{
15872 +       return sched_cfs_period * NSEC_PER_USEC;
15873 +}
15874 +
15875 +static inline u64 global_cfs_runtime(void)
15876 +{
15877 +       return RUNTIME_INF;
15878 +}
15879 +
15880 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b);
15881 +
15882 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15883 +{
15884 +       spin_lock(&cfs_rq->cfs_runtime_lock);
15885 +}
15886 +
15887 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15888 +{
15889 +       spin_unlock(&cfs_rq->cfs_runtime_lock);
15890 +}
15891 +
15892 +/*
15893 + * Refresh the runtimes of the throttled groups.
15894 + * But nothing much to do now, will populate this in later patches.
15895 + */
15896 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
15897 +{
15898 +       struct cfs_bandwidth *cfs_b =
15899 +               container_of(timer, struct cfs_bandwidth, cfs_period_timer);
15900 +
15901 +       do_sched_cfs_period_timer(cfs_b);
15902 +       hrtimer_add_expires_ns(timer, ktime_to_ns(cfs_b->cfs_period));
15903 +       return HRTIMER_RESTART;
15904 +}
15905 +
15906 +/*
15907 + * TODO: Check if this kind of timer setup is sufficient for cfs or
15908 + * should we do what rt is doing.
15909 + */
15910 +static void start_cfs_bandwidth(struct task_group *tg)
15911 +{
15912 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15913 +
15914 +       /*
15915 +        * Timer isn't setup for groups with infinite runtime
15916 +        */
15917 +       if (cfs_b->cfs_runtime == RUNTIME_INF)
15918 +               return;
15919 +
15920 +       if (hrtimer_active(&cfs_b->cfs_period_timer))
15921 +               return;
15922 +
15923 +       hrtimer_start_range_ns(&cfs_b->cfs_period_timer, cfs_b->cfs_period,
15924 +                       0, HRTIMER_MODE_REL);
15925 +}
15926 +
15927 +static void init_cfs_bandwidth(struct task_group *tg)
15928 +{
15929 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15930 +
15931 +       cfs_b->cfs_period = ns_to_ktime(global_cfs_period());
15932 +       cfs_b->cfs_runtime = global_cfs_runtime();
15933 +
15934 +       spin_lock_init(&cfs_b->cfs_runtime_lock);
15935 +
15936 +       hrtimer_init(&cfs_b->cfs_period_timer,
15937 +                       CLOCK_MONOTONIC, HRTIMER_MODE_REL);
15938 +       cfs_b->cfs_period_timer.function = &sched_cfs_period_timer;
15939 +}
15940 +
15941 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15942 +{
15943 +       hrtimer_cancel(&tg->cfs_bandwidth.cfs_period_timer);
15944 +}
15945 +
15946 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15947 +{
15948 +       cfs_rq->cfs_time = 0;
15949 +       cfs_rq->cfs_throttled = 0;
15950 +       cfs_rq->cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
15951 +       spin_lock_init(&cfs_rq->cfs_runtime_lock);
15952 +}
15953 +
15954 +#else /* !CONFIG_CFS_HARD_LIMITS */
15955 +
15956 +static void init_cfs_bandwidth(struct task_group *tg)
15957 +{
15958 +       return;
15959 +}
15960 +
15961 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15962 +{
15963 +       return;
15964 +}
15965 +
15966 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15967 +{
15968 +       return;
15969 +}
15970 +
15971 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15972 +{
15973 +       return;
15974 +}
15975 +
15976 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15977 +{
15978 +       return;
15979 +}
15980 +
15981 +#endif /* CONFIG_CFS_HARD_LIMITS */
15982 +#else /* !CONFIG_FAIR_GROUP_SCHED */
15983 +
15984 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15985 +{
15986 +       return;
15987 +}
15988 +
15989 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15990 +{
15991 +       return;
15992 +}
15993 +
15994 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
15995 +{
15996 +       return 0;
15997 +}
15998 +
15999 +#endif /* CONFIG_FAIR_GROUP_SCHED */
16000 +
16001  #include "sched_stats.h"
16002  #include "sched_idletask.c"
16003  #include "sched_fair.c"
16004 @@ -2965,9 +3164,17 @@ EXPORT_SYMBOL(avenrun);
16005   */
16006  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16007  {
16008 -       loads[0] = (avenrun[0] + offset) << shift;
16009 -       loads[1] = (avenrun[1] + offset) << shift;
16010 -       loads[2] = (avenrun[2] + offset) << shift;
16011 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16012 +               struct vx_info *vxi = current_vx_info();
16013 +
16014 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16015 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16016 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16017 +       } else {
16018 +               loads[0] = (avenrun[0] + offset) << shift;
16019 +               loads[1] = (avenrun[1] + offset) << shift;
16020 +               loads[2] = (avenrun[2] + offset) << shift;
16021 +       }
16022  }
16023  
16024  static unsigned long
16025 @@ -5006,16 +5213,19 @@ void account_user_time(struct task_struc
16026                        cputime_t cputime_scaled)
16027  {
16028         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16029 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16030         cputime64_t tmp;
16031 +       int nice = (TASK_NICE(p) > 0);
16032  
16033         /* Add user time to process. */
16034         p->utime = cputime_add(p->utime, cputime);
16035         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16036 +       vx_account_user(vxi, cputime, nice);
16037         account_group_user_time(p, cputime);
16038  
16039         /* Add user time to cpustat. */
16040         tmp = cputime_to_cputime64(cputime);
16041 -       if (TASK_NICE(p) > 0)
16042 +       if (nice)
16043                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16044         else
16045                 cpustat->user = cputime64_add(cpustat->user, tmp);
16046 @@ -5061,6 +5271,7 @@ void account_system_time(struct task_str
16047                          cputime_t cputime, cputime_t cputime_scaled)
16048  {
16049         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16050 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16051         cputime64_t tmp;
16052  
16053         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16054 @@ -5071,6 +5282,7 @@ void account_system_time(struct task_str
16055         /* Add system time to process. */
16056         p->stime = cputime_add(p->stime, cputime);
16057         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16058 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16059         account_group_system_time(p, cputime);
16060  
16061         /* Add system time to cpustat. */
16062 @@ -6106,7 +6318,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16063                 nice = 19;
16064  
16065         if (increment < 0 && !can_nice(current, nice))
16066 -               return -EPERM;
16067 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16068  
16069         retval = security_task_setnice(current, nice);
16070         if (retval)
16071 @@ -9164,6 +9376,32 @@ static int update_sched_domains(struct n
16072  }
16073  #endif
16074  
16075 +#ifdef CONFIG_SMP
16076 +static void disable_runtime(struct rq *rq)
16077 +{
16078 +       unsigned long flags;
16079 +
16080 +       spin_lock_irqsave(&rq->lock, flags);
16081 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16082 +       disable_runtime_cfs(rq);
16083 +#endif
16084 +       disable_runtime_rt(rq);
16085 +       spin_unlock_irqrestore(&rq->lock, flags);
16086 +}
16087 +
16088 +static void enable_runtime(struct rq *rq)
16089 +{
16090 +       unsigned long flags;
16091 +
16092 +       spin_lock_irqsave(&rq->lock, flags);
16093 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16094 +       enable_runtime_cfs(rq);
16095 +#endif
16096 +       enable_runtime_rt(rq);
16097 +       spin_unlock_irqrestore(&rq->lock, flags);
16098 +}
16099 +#endif
16100 +
16101  static int update_runtime(struct notifier_block *nfb,
16102                                 unsigned long action, void *hcpu)
16103  {
16104 @@ -9296,6 +9534,7 @@ static void init_tg_cfs_entry(struct tas
16105         struct rq *rq = cpu_rq(cpu);
16106         tg->cfs_rq[cpu] = cfs_rq;
16107         init_cfs_rq(cfs_rq, rq);
16108 +       init_cfs_hard_limits(cfs_rq, tg);
16109         cfs_rq->tg = tg;
16110         if (add)
16111                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16112 @@ -9425,6 +9664,10 @@ void __init sched_init(void)
16113  #endif /* CONFIG_USER_SCHED */
16114  #endif /* CONFIG_RT_GROUP_SCHED */
16115  
16116 +#ifdef CONFIG_FAIR_GROUP_SCHED
16117 +       init_cfs_bandwidth(&init_task_group);
16118 +#endif
16119 +
16120  #ifdef CONFIG_GROUP_SCHED
16121         list_add(&init_task_group.list, &task_groups);
16122         INIT_LIST_HEAD(&init_task_group.children);
16123 @@ -9451,6 +9694,7 @@ void __init sched_init(void)
16124                 init_cfs_rq(&rq->cfs, rq);
16125                 init_rt_rq(&rq->rt, rq);
16126  #ifdef CONFIG_FAIR_GROUP_SCHED
16127 +               init_cfs_hard_limits(&rq->cfs, &init_task_group);
16128                 init_task_group.shares = init_task_group_load;
16129                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16130  #ifdef CONFIG_CGROUP_SCHED
16131 @@ -9726,6 +9970,7 @@ static void free_fair_sched_group(struct
16132  {
16133         int i;
16134  
16135 +       destroy_cfs_bandwidth(tg);
16136         for_each_possible_cpu(i) {
16137                 if (tg->cfs_rq)
16138                         kfree(tg->cfs_rq[i]);
16139 @@ -9752,6 +9997,7 @@ int alloc_fair_sched_group(struct task_g
16140         if (!tg->se)
16141                 goto err;
16142  
16143 +       init_cfs_bandwidth(tg);
16144         tg->shares = NICE_0_LOAD;
16145  
16146         for_each_possible_cpu(i) {
16147 @@ -10475,6 +10721,100 @@ static u64 cpu_shares_read_u64(struct cg
16148  
16149         return (u64) tg->shares;
16150  }
16151 +
16152 +#ifdef CONFIG_CFS_HARD_LIMITS
16153 +
16154 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16155 +               u64 cfs_period, u64 cfs_runtime)
16156 +{
16157 +       int i;
16158 +
16159 +       spin_lock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16160 +       tg->cfs_bandwidth.cfs_period = ns_to_ktime(cfs_period);
16161 +       tg->cfs_bandwidth.cfs_runtime = cfs_runtime;
16162 +
16163 +       for_each_possible_cpu(i) {
16164 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16165 +
16166 +               cfs_rq_runtime_lock(cfs_rq);
16167 +               cfs_rq->cfs_runtime = cfs_runtime;
16168 +               cfs_rq_runtime_unlock(cfs_rq);
16169 +       }
16170 +
16171 +       start_cfs_bandwidth(tg);
16172 +       spin_unlock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16173 +       return 0;
16174 +}
16175 +
16176 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16177 +{
16178 +       u64 cfs_runtime, cfs_period;
16179 +
16180 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16181 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16182 +       if (cfs_runtime_us < 0)
16183 +               cfs_runtime = RUNTIME_INF;
16184 +
16185 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16186 +}
16187 +
16188 +long tg_get_cfs_runtime(struct task_group *tg)
16189 +{
16190 +       u64 cfs_runtime_us;
16191 +
16192 +       if (tg->cfs_bandwidth.cfs_runtime == RUNTIME_INF)
16193 +               return -1;
16194 +
16195 +       cfs_runtime_us = tg->cfs_bandwidth.cfs_runtime;
16196 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16197 +       return cfs_runtime_us;
16198 +}
16199 +
16200 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16201 +{
16202 +       u64 cfs_runtime, cfs_period;
16203 +
16204 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
16205 +       cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16206 +
16207 +       if (cfs_period == 0)
16208 +               return -EINVAL;
16209 +
16210 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16211 +}
16212 +
16213 +long tg_get_cfs_period(struct task_group *tg)
16214 +{
16215 +       u64 cfs_period_us;
16216 +
16217 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16218 +       do_div(cfs_period_us, NSEC_PER_USEC);
16219 +       return cfs_period_us;
16220 +}
16221 +
16222 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
16223 +{
16224 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
16225 +}
16226 +
16227 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
16228 +                               s64 cfs_runtime_us)
16229 +{
16230 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
16231 +}
16232 +
16233 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
16234 +{
16235 +       return tg_get_cfs_period(cgroup_tg(cgrp));
16236 +}
16237 +
16238 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
16239 +                               u64 cfs_period_us)
16240 +{
16241 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
16242 +}
16243 +
16244 +#endif /* CONFIG_CFS_HARD_LIMITS */
16245  #endif /* CONFIG_FAIR_GROUP_SCHED */
16246  
16247  #ifdef CONFIG_RT_GROUP_SCHED
16248 @@ -10508,6 +10848,18 @@ static struct cftype cpu_files[] = {
16249                 .read_u64 = cpu_shares_read_u64,
16250                 .write_u64 = cpu_shares_write_u64,
16251         },
16252 +#ifdef CONFIG_CFS_HARD_LIMITS
16253 +       {
16254 +               .name = "cfs_runtime_us",
16255 +               .read_s64 = cpu_cfs_runtime_read_s64,
16256 +               .write_s64 = cpu_cfs_runtime_write_s64,
16257 +       },
16258 +       {
16259 +               .name = "cfs_period_us",
16260 +               .read_u64 = cpu_cfs_period_read_u64,
16261 +               .write_u64 = cpu_cfs_period_write_u64,
16262 +       },
16263 +#endif /* CONFIG_CFS_HARD_LIMITS */
16264  #endif
16265  #ifdef CONFIG_RT_GROUP_SCHED
16266         {
16267 diff -NurpP --minimal linux-2.6.32/kernel/sched_debug.c linux-2.6.32-vs2.3.0.36.26/kernel/sched_debug.c
16268 --- linux-2.6.32/kernel/sched_debug.c   2009-12-03 20:02:58.000000000 +0100
16269 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sched_debug.c     2009-12-03 20:04:56.000000000 +0100
16270 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
16271         PN(se->wait_max);
16272         PN(se->wait_sum);
16273         P(se->wait_count);
16274 +#ifdef CONFIG_CFS_HARD_LIMITS
16275 +       PN(se->throttle_max);
16276 +       PN(se->throttle_sum);
16277 +       P(se->throttle_count);
16278 +#endif
16279  #endif
16280         P(se->load.weight);
16281  #undef PN
16282 @@ -214,6 +219,16 @@ void print_cfs_rq(struct seq_file *m, in
16283  #ifdef CONFIG_SMP
16284         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
16285  #endif
16286 +#ifdef CONFIG_CFS_HARD_LIMITS
16287 +       spin_lock_irqsave(&rq->lock, flags);
16288 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
16289 +                       cfs_rq->cfs_throttled);
16290 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
16291 +                       SPLIT_NS(cfs_rq->cfs_time));
16292 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
16293 +                       SPLIT_NS(cfs_rq->cfs_runtime));
16294 +       spin_unlock_irqrestore(&rq->lock, flags);
16295 +#endif /* CONFIG_CFS_HARD_LIMITS */
16296         print_cfs_group_stats(m, cpu, cfs_rq->tg);
16297  #endif
16298  }
16299 @@ -310,7 +325,7 @@ static int sched_debug_show(struct seq_f
16300         u64 now = ktime_to_ns(ktime_get());
16301         int cpu;
16302  
16303 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
16304 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
16305                 init_utsname()->release,
16306                 (int)strcspn(init_utsname()->version, " "),
16307                 init_utsname()->version);
16308 diff -NurpP --minimal linux-2.6.32/kernel/sched_fair.c linux-2.6.32-vs2.3.0.36.26/kernel/sched_fair.c
16309 --- linux-2.6.32/kernel/sched_fair.c    2009-12-03 20:02:58.000000000 +0100
16310 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sched_fair.c      2009-12-03 20:04:56.000000000 +0100
16311 @@ -189,7 +189,308 @@ find_matching_se(struct sched_entity **s
16312         }
16313  }
16314  
16315 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
16316 +#ifdef CONFIG_CFS_HARD_LIMITS
16317 +
16318 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
16319 +                       struct sched_entity *se)
16320 +{
16321 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
16322 +}
16323 +
16324 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
16325 +                       struct sched_entity *se)
16326 +{
16327 +       schedstat_set(se->throttle_max, max(se->throttle_max,
16328 +                       rq_of(cfs_rq)->clock - se->throttle_start));
16329 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
16330 +       schedstat_set(se->throttle_sum, se->throttle_sum +
16331 +                       rq_of(cfs_rq)->clock - se->throttle_start);
16332 +       schedstat_set(se->throttle_start, 0);
16333 +}
16334 +
16335 +static inline
16336 +struct cfs_rq *sched_cfs_period_cfs_rq(struct cfs_bandwidth *cfs_b, int cpu)
16337 +{
16338 +       return container_of(cfs_b, struct task_group,
16339 +                       cfs_bandwidth)->cfs_rq[cpu];
16340 +}
16341 +
16342 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16343 +{
16344 +       return cfs_rq->cfs_throttled;
16345 +}
16346 +
16347 +#ifdef CONFIG_SMP
16348 +/*
16349 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
16350 + */
16351 +static void disable_runtime_cfs(struct rq *rq)
16352 +{
16353 +       struct root_domain *rd = rq->rd;
16354 +       struct cfs_rq *cfs_rq;
16355 +
16356 +       if (unlikely(!scheduler_running))
16357 +               return;
16358 +
16359 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16360 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16361 +               s64 want;
16362 +               int i;
16363 +
16364 +               spin_lock(&cfs_b->cfs_runtime_lock);
16365 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16366 +
16367 +               /*
16368 +                * Either we're all are infinity and nobody needs to borrow,
16369 +                * or we're already disabled and this have nothing to do, or
16370 +                * we have exactly the right amount of runtime to take out.
16371 +                */
16372 +                if (cfs_rq->cfs_runtime == RUNTIME_INF ||
16373 +                               cfs_rq->cfs_runtime == cfs_b->cfs_runtime)
16374 +                       goto balanced;
16375 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16376 +
16377 +               /*
16378 +                * Calculate the difference between what we started out with
16379 +                * and what we current have, that's the amount of runtime
16380 +                * we lend and now have to reclaim.
16381 +                */
16382 +                want = cfs_b->cfs_runtime - cfs_rq->cfs_runtime;
16383 +
16384 +               /*
16385 +                * Greedy reclaim, take back as much as possible.
16386 +                */
16387 +               for_each_cpu(i, rd->span) {
16388 +                       struct cfs_rq *iter = sched_cfs_period_cfs_rq(cfs_b, i);
16389 +                       s64 diff;
16390 +
16391 +                       /*
16392 +                        * Can't reclaim from ourselves or disabled runqueues.
16393 +                        */
16394 +                       if (iter == cfs_rq || iter->cfs_runtime == RUNTIME_INF)
16395 +                               continue;
16396 +
16397 +                       spin_lock(&iter->cfs_runtime_lock);
16398 +                       if (want > 0) {
16399 +                               diff = min_t(s64, iter->cfs_runtime, want);
16400 +                               iter->cfs_runtime -= diff;
16401 +                               want -= diff;
16402 +                       } else {
16403 +                               iter->cfs_runtime -= want;
16404 +                               want -= want;
16405 +                       }
16406 +
16407 +                       spin_unlock(&iter->cfs_runtime_lock);
16408 +                       if (!want)
16409 +                               break;
16410 +               }
16411 +
16412 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16413 +               /*
16414 +                * We cannot be left wanting - that would mean some
16415 +                * runtime leaked out of the system.
16416 +                */
16417 +               BUG_ON(want);
16418 +balanced:
16419 +               /*
16420 +                * Disable all the borrow logic by pretending we have infinite
16421 +                * runtime - in which case borrowing doesn't make sense.
16422 +                */
16423 +                cfs_rq->cfs_runtime = RUNTIME_INF;
16424 +                spin_unlock(&cfs_rq->cfs_runtime_lock);
16425 +                spin_unlock(&cfs_b->cfs_runtime_lock);
16426 +       }
16427 +}
16428 +
16429 +static void enable_runtime_cfs(struct rq *rq)
16430 +{
16431 +       struct cfs_rq *cfs_rq;
16432 +
16433 +       if (unlikely(!scheduler_running))
16434 +               return;
16435 +
16436 +       /*
16437 +        * Reset each runqueue's bandwidth settings
16438 +        */
16439 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16440 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16441 +
16442 +               spin_lock(&cfs_b->cfs_runtime_lock);
16443 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16444 +               cfs_rq->cfs_runtime = cfs_b->cfs_runtime;
16445 +               cfs_rq->cfs_time = 0;
16446 +               cfs_rq->cfs_throttled = 0;
16447 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16448 +               spin_unlock(&cfs_b->cfs_runtime_lock);
16449 +       }
16450 +}
16451 +
16452 +/*
16453 + * Ran out of runtime, check if we can borrow some from others
16454 + * instead of getting throttled right away.
16455 + */
16456 +static void do_cfs_balance_runtime(struct cfs_rq *cfs_rq)
16457 +{
16458 +       struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16459 +       const struct cpumask *span = sched_bw_period_mask();
16460 +       int i, weight;
16461 +       u64 cfs_period;
16462 +
16463 +       weight = cpumask_weight(span);
16464 +       spin_lock(&cfs_b->cfs_runtime_lock);
16465 +       cfs_period = ktime_to_ns(cfs_b->cfs_period);
16466 +
16467 +       for_each_cpu(i, span) {
16468 +               struct cfs_rq *borrow_cfs_rq =
16469 +                               sched_cfs_period_cfs_rq(cfs_b, i);
16470 +               s64 diff;
16471 +
16472 +               if (borrow_cfs_rq == cfs_rq)
16473 +                       continue;
16474 +
16475 +               cfs_rq_runtime_lock(borrow_cfs_rq);
16476 +               if (borrow_cfs_rq->cfs_runtime == RUNTIME_INF) {
16477 +                       cfs_rq_runtime_unlock(borrow_cfs_rq);
16478 +                       continue;
16479 +               }
16480 +
16481 +               diff = borrow_cfs_rq->cfs_runtime - borrow_cfs_rq->cfs_time;
16482 +               if (diff > 0) {
16483 +                       diff = div_u64((u64)diff, weight);
16484 +                       if (cfs_rq->cfs_runtime + diff > cfs_period)
16485 +                               diff = cfs_period - cfs_rq->cfs_runtime;
16486 +                       borrow_cfs_rq->cfs_runtime -= diff;
16487 +                       cfs_rq->cfs_runtime += diff;
16488 +                       if (cfs_rq->cfs_runtime == cfs_period) {
16489 +                               cfs_rq_runtime_unlock(borrow_cfs_rq);
16490 +                               break;
16491 +                       }
16492 +               }
16493 +               cfs_rq_runtime_unlock(borrow_cfs_rq);
16494 +       }
16495 +       spin_unlock(&cfs_b->cfs_runtime_lock);
16496 +}
16497 +
16498 +/*
16499 + * Called with rq->runtime_lock held.
16500 + */
16501 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16502 +{
16503 +       cfs_rq_runtime_unlock(cfs_rq);
16504 +       do_cfs_balance_runtime(cfs_rq);
16505 +       cfs_rq_runtime_lock(cfs_rq);
16506 +}
16507 +
16508 +#else /* !CONFIG_SMP */
16509 +
16510 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16511 +{
16512 +       return;
16513 +}
16514 +#endif /* CONFIG_SMP */
16515 +
16516 +/*
16517 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
16518 + * throttled mark the current task for reschedling.
16519 + */
16520 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
16521 +       struct task_struct *tsk_curr, unsigned long delta_exec)
16522 +{
16523 +       struct cfs_rq *cfs_rq;
16524 +
16525 +       cfs_rq = group_cfs_rq(se);
16526 +
16527 +       if (cfs_rq->cfs_runtime == RUNTIME_INF)
16528 +               return;
16529 +
16530 +       cfs_rq->cfs_time += delta_exec;
16531 +
16532 +       if (cfs_rq_throttled(cfs_rq))
16533 +               return;
16534 +
16535 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime)
16536 +               cfs_balance_runtime(cfs_rq);
16537 +
16538 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime) {
16539 +               cfs_rq->cfs_throttled = 1;
16540 +               update_stats_throttle_start(cfs_rq, se);
16541 +               resched_task(tsk_curr);
16542 +       }
16543 +}
16544 +
16545 +static inline void update_curr_group(struct sched_entity *curr,
16546 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16547 +{
16548 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
16549 +}
16550 +
16551 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16552 +               struct sched_entity *se, int wakeup);
16553 +
16554 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
16555 +{
16556 +       for_each_sched_entity(se) {
16557 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16558 +
16559 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
16560 +                               !gcfs_rq->nr_running)
16561 +                       break;
16562 +               enqueue_entity_locked(cfs_rq_of(se), se, 0);
16563 +       }
16564 +}
16565 +
16566 +/*
16567 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
16568 + * refresh runtimes of the representative cfs_rq of this
16569 + * tg on all cpus. Enqueue any throttled entity back.
16570 + */
16571 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b)
16572 +{
16573 +       int i;
16574 +       const struct cpumask *span = sched_bw_period_mask();
16575 +       unsigned long flags;
16576 +
16577 +       for_each_cpu(i, span) {
16578 +               struct rq *rq = cpu_rq(i);
16579 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
16580 +               struct sched_entity *se = cfs_rq->tg->se[i];
16581 +
16582 +               spin_lock_irqsave(&rq->lock, flags);
16583 +               cfs_rq_runtime_lock(cfs_rq);
16584 +               cfs_rq->cfs_time = 0;
16585 +               if (cfs_rq_throttled(cfs_rq)) {
16586 +                       update_rq_clock(rq);
16587 +                       update_stats_throttle_end(cfs_rq, se);
16588 +                       cfs_rq->cfs_throttled = 0;
16589 +                       enqueue_throttled_entity(rq, se);
16590 +               }
16591 +               cfs_rq_runtime_unlock(cfs_rq);
16592 +               spin_unlock_irqrestore(&rq->lock, flags);
16593 +       }
16594 +}
16595 +
16596 +#else
16597 +
16598 +static inline void update_curr_group(struct sched_entity *curr,
16599 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16600 +{
16601 +       return;
16602 +}
16603 +
16604 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16605 +{
16606 +       return 0;
16607 +}
16608 +
16609 +#endif /* CONFIG_CFS_HARD_LIMITS */
16610 +
16611 +#else  /* CONFIG_FAIR_GROUP_SCHED */
16612 +
16613 +static inline void update_curr_group(struct sched_entity *curr,
16614 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16615 +{
16616 +       return;
16617 +}
16618  
16619  static inline struct task_struct *task_of(struct sched_entity *se)
16620  {
16621 @@ -251,7 +552,6 @@ find_matching_se(struct sched_entity **s
16622  
16623  #endif /* CONFIG_FAIR_GROUP_SCHED */
16624  
16625 -
16626  /**************************************************************
16627   * Scheduling class tree data structure manipulation methods:
16628   */
16629 @@ -489,14 +789,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
16630         update_min_vruntime(cfs_rq);
16631  }
16632  
16633 -static void update_curr(struct cfs_rq *cfs_rq)
16634 +static void update_curr_task(struct sched_entity *curr,
16635 +               unsigned long delta_exec)
16636 +{
16637 +       struct task_struct *curtask = task_of(curr);
16638 +
16639 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16640 +       cpuacct_charge(curtask, delta_exec);
16641 +       account_group_exec_runtime(curtask, delta_exec);
16642 +}
16643 +
16644 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
16645  {
16646         struct sched_entity *curr = cfs_rq->curr;
16647 -       u64 now = rq_of(cfs_rq)->clock;
16648 +       struct rq *rq = rq_of(cfs_rq);
16649 +       u64 now = rq->clock;
16650         unsigned long delta_exec;
16651  
16652         if (unlikely(!curr))
16653 -               return;
16654 +               return 1;
16655  
16656         /*
16657          * Get the amount of time the current task was running
16658 @@ -505,20 +816,47 @@ static void update_curr(struct cfs_rq *c
16659          */
16660         delta_exec = (unsigned long)(now - curr->exec_start);
16661         if (!delta_exec)
16662 -               return;
16663 +               return 1;
16664  
16665         __update_curr(cfs_rq, curr, delta_exec);
16666         curr->exec_start = now;
16667 +       *delta = delta_exec;
16668 +       return 0;
16669 +}
16670  
16671 -       if (entity_is_task(curr)) {
16672 -               struct task_struct *curtask = task_of(curr);
16673 +static void update_curr(struct cfs_rq *cfs_rq)
16674 +{
16675 +       struct sched_entity *curr = cfs_rq->curr;
16676 +       struct rq *rq = rq_of(cfs_rq);
16677 +       unsigned long delta_exec;
16678  
16679 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16680 -               cpuacct_charge(curtask, delta_exec);
16681 -               account_group_exec_runtime(curtask, delta_exec);
16682 +       if (update_curr_common(cfs_rq, &delta_exec))
16683 +               return ;
16684 +
16685 +       if (entity_is_task(curr))
16686 +               update_curr_task(curr, delta_exec);
16687 +       else {
16688 +               cfs_rq_runtime_lock(group_cfs_rq(curr));
16689 +               update_curr_group(curr, delta_exec, rq->curr);
16690 +               cfs_rq_runtime_unlock(group_cfs_rq(curr));
16691         }
16692  }
16693  
16694 +static void update_curr_locked(struct cfs_rq *cfs_rq)
16695 +{
16696 +       struct sched_entity *curr = cfs_rq->curr;
16697 +       struct rq *rq = rq_of(cfs_rq);
16698 +       unsigned long delta_exec;
16699 +
16700 +       if (update_curr_common(cfs_rq, &delta_exec))
16701 +               return ;
16702 +
16703 +       if (entity_is_task(curr))
16704 +               update_curr_task(curr, delta_exec);
16705 +       else
16706 +               update_curr_group(curr, delta_exec, rq->curr);
16707 +}
16708 +
16709  static inline void
16710  update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
16711  {
16712 @@ -740,13 +1078,9 @@ place_entity(struct cfs_rq *cfs_rq, stru
16713         se->vruntime = vruntime;
16714  }
16715  
16716 -static void
16717 -enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
16718 +static void enqueue_entity_common(struct cfs_rq *cfs_rq,
16719 +               struct sched_entity *se, int wakeup)
16720  {
16721 -       /*
16722 -        * Update run-time statistics of the 'current'.
16723 -        */
16724 -       update_curr(cfs_rq);
16725         account_entity_enqueue(cfs_rq, se);
16726  
16727         if (wakeup) {
16728 @@ -758,6 +1092,29 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16729         check_spread(cfs_rq, se);
16730         if (se != cfs_rq->curr)
16731                 __enqueue_entity(cfs_rq, se);
16732 +
16733 +       if (entity_is_task(se))
16734 +               vx_activate_task(task_of(se));
16735 +}
16736 +
16737 +static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16738 +               int wakeup)
16739 +{
16740 +       /*
16741 +        * Update run-time statistics of the 'current'.
16742 +        */
16743 +       update_curr(cfs_rq);
16744 +       enqueue_entity_common(cfs_rq, se, wakeup);
16745 +}
16746 +
16747 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16748 +               struct sched_entity *se, int wakeup)
16749 +{
16750 +       /*
16751 +        * Update run-time statistics of the 'current'.
16752 +        */
16753 +       update_curr_locked(cfs_rq);
16754 +       enqueue_entity_common(cfs_rq, se, wakeup);
16755  }
16756  
16757  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
16758 @@ -801,6 +1158,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16759  
16760         if (se != cfs_rq->curr)
16761                 __dequeue_entity(cfs_rq, se);
16762 +       if (entity_is_task(se))
16763 +               vx_deactivate_task(task_of(se));
16764         account_entity_dequeue(cfs_rq, se);
16765         update_min_vruntime(cfs_rq);
16766  }
16767 @@ -897,6 +1256,32 @@ static struct sched_entity *pick_next_en
16768         return se;
16769  }
16770  
16771 +/*
16772 + * Called from put_prev_entity()
16773 + * If a group entity (@se) is found to be throttled, it will not be put back
16774 + * on @cfs_rq, which is equivalent to dequeing it.
16775 + */
16776 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
16777 +               struct sched_entity *se)
16778 +{
16779 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16780 +
16781 +       if (entity_is_task(se))
16782 +               return 0;
16783 +
16784 +       cfs_rq_runtime_lock(gcfs_rq);
16785 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running) {
16786 +               cfs_rq_runtime_unlock(gcfs_rq);
16787 +               return 0;
16788 +       }
16789 +
16790 +       __clear_buddies(cfs_rq, se);
16791 +       account_entity_dequeue(cfs_rq, se);
16792 +       cfs_rq->curr = NULL;
16793 +       cfs_rq_runtime_unlock(gcfs_rq);
16794 +       return 1;
16795 +}
16796 +
16797  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
16798  {
16799         /*
16800 @@ -908,6 +1293,8 @@ static void put_prev_entity(struct cfs_r
16801  
16802         check_spread(cfs_rq, prev);
16803         if (prev->on_rq) {
16804 +               if (dequeue_throttled_entity(cfs_rq, prev))
16805 +                       return;
16806                 update_stats_wait_start(cfs_rq, prev);
16807                 /* Put 'current' back into the tree. */
16808                 __enqueue_entity(cfs_rq, prev);
16809 @@ -1004,10 +1391,28 @@ static inline void hrtick_update(struct 
16810  }
16811  #endif
16812  
16813 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16814 +                int wakeup)
16815 +{
16816 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16817 +       int ret = 0;
16818 +
16819 +       cfs_rq_runtime_lock(gcfs_rq);
16820 +       if (cfs_rq_throttled(gcfs_rq)) {
16821 +               ret = 1;
16822 +               goto out;
16823 +       }
16824 +       enqueue_entity_locked(cfs_rq, se, wakeup);
16825 +out:
16826 +       cfs_rq_runtime_unlock(gcfs_rq);
16827 +       return ret;
16828 +}
16829 +
16830  /*
16831   * The enqueue_task method is called before nr_running is
16832   * increased. Here we update the fair scheduling stats and
16833   * then put the task into the rbtree:
16834 + * Don't enqueue a throttled entity further into the hierarchy.
16835   */
16836  static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
16837  {
16838 @@ -1017,11 +1422,15 @@ static void enqueue_task_fair(struct rq 
16839         for_each_sched_entity(se) {
16840                 if (se->on_rq)
16841                         break;
16842 +
16843                 cfs_rq = cfs_rq_of(se);
16844 -               enqueue_entity(cfs_rq, se, wakeup);
16845 +               if (entity_is_task(se))
16846 +                       enqueue_entity(cfs_rq, se, wakeup);
16847 +               else
16848 +                       if (enqueue_group_entity(cfs_rq, se, wakeup))
16849 +                               break;
16850                 wakeup = 1;
16851         }
16852 -
16853         hrtick_update(rq);
16854  }
16855  
16856 @@ -1041,6 +1450,17 @@ static void dequeue_task_fair(struct rq 
16857                 /* Don't dequeue parent if it has other entities besides us */
16858                 if (cfs_rq->load.weight)
16859                         break;
16860 +
16861 +               /*
16862 +                * If this cfs_rq is throttled, then it is already
16863 +                * dequeued.
16864 +                */
16865 +               cfs_rq_runtime_lock(cfs_rq);
16866 +               if (cfs_rq_throttled(cfs_rq)) {
16867 +                       cfs_rq_runtime_unlock(cfs_rq);
16868 +                       break;
16869 +               }
16870 +               cfs_rq_runtime_unlock(cfs_rq);
16871                 sleep = 1;
16872         }
16873  
16874 @@ -1788,9 +2208,10 @@ load_balance_fair(struct rq *this_rq, in
16875                 u64 rem_load, moved_load;
16876  
16877                 /*
16878 -                * empty group
16879 +                * empty group or throttled group
16880                  */
16881 -               if (!busiest_cfs_rq->task_weight)
16882 +               if (!busiest_cfs_rq->task_weight ||
16883 +                               cfs_rq_throttled(busiest_cfs_rq))
16884                         continue;
16885  
16886                 rem_load = (u64)rem_load_move * busiest_weight;
16887 @@ -1839,6 +2260,12 @@ move_one_task_fair(struct rq *this_rq, i
16888  
16889         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
16890                 /*
16891 +                * Don't move task from a throttled cfs_rq
16892 +                */
16893 +               if (cfs_rq_throttled(busy_cfs_rq))
16894 +                       continue;
16895 +
16896 +               /*
16897                  * pass busy_cfs_rq argument into
16898                  * load_balance_[start|next]_fair iterators
16899                  */
16900 diff -NurpP --minimal linux-2.6.32/kernel/sched_rt.c linux-2.6.32-vs2.3.0.36.26/kernel/sched_rt.c
16901 --- linux-2.6.32/kernel/sched_rt.c      2009-12-03 20:02:58.000000000 +0100
16902 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sched_rt.c        2009-12-03 20:04:56.000000000 +0100
16903 @@ -235,18 +235,6 @@ static int rt_se_boosted(struct sched_rt
16904         return p->prio != p->normal_prio;
16905  }
16906  
16907 -#ifdef CONFIG_SMP
16908 -static inline const struct cpumask *sched_rt_period_mask(void)
16909 -{
16910 -       return cpu_rq(smp_processor_id())->rd->span;
16911 -}
16912 -#else
16913 -static inline const struct cpumask *sched_rt_period_mask(void)
16914 -{
16915 -       return cpu_online_mask;
16916 -}
16917 -#endif
16918 -
16919  static inline
16920  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16921  {
16922 @@ -296,11 +284,6 @@ static inline int rt_rq_throttled(struct
16923         return rt_rq->rt_throttled;
16924  }
16925  
16926 -static inline const struct cpumask *sched_rt_period_mask(void)
16927 -{
16928 -       return cpu_online_mask;
16929 -}
16930 -
16931  static inline
16932  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16933  {
16934 @@ -373,7 +356,7 @@ next:
16935  /*
16936   * Ensure this RQ takes back all the runtime it lend to its neighbours.
16937   */
16938 -static void __disable_runtime(struct rq *rq)
16939 +static void disable_runtime_rt(struct rq *rq)
16940  {
16941         struct root_domain *rd = rq->rd;
16942         struct rt_rq *rt_rq;
16943 @@ -450,16 +433,7 @@ balanced:
16944         }
16945  }
16946  
16947 -static void disable_runtime(struct rq *rq)
16948 -{
16949 -       unsigned long flags;
16950 -
16951 -       spin_lock_irqsave(&rq->lock, flags);
16952 -       __disable_runtime(rq);
16953 -       spin_unlock_irqrestore(&rq->lock, flags);
16954 -}
16955 -
16956 -static void __enable_runtime(struct rq *rq)
16957 +static void enable_runtime_rt(struct rq *rq)
16958  {
16959         struct rt_rq *rt_rq;
16960  
16961 @@ -482,15 +456,6 @@ static void __enable_runtime(struct rq *
16962         }
16963  }
16964  
16965 -static void enable_runtime(struct rq *rq)
16966 -{
16967 -       unsigned long flags;
16968 -
16969 -       spin_lock_irqsave(&rq->lock, flags);
16970 -       __enable_runtime(rq);
16971 -       spin_unlock_irqrestore(&rq->lock, flags);
16972 -}
16973 -
16974  static int balance_runtime(struct rt_rq *rt_rq)
16975  {
16976         int more = 0;
16977 @@ -518,7 +483,7 @@ static int do_sched_rt_period_timer(stru
16978         if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
16979                 return 1;
16980  
16981 -       span = sched_rt_period_mask();
16982 +       span = sched_bw_period_mask();
16983         for_each_cpu(i, span) {
16984                 int enqueue = 0;
16985                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
16986 @@ -1564,7 +1529,7 @@ static void rq_online_rt(struct rq *rq)
16987         if (rq->rt.overloaded)
16988                 rt_set_overload(rq);
16989  
16990 -       __enable_runtime(rq);
16991 +       enable_runtime_rt(rq);
16992  
16993         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
16994  }
16995 @@ -1575,7 +1540,7 @@ static void rq_offline_rt(struct rq *rq)
16996         if (rq->rt.overloaded)
16997                 rt_clear_overload(rq);
16998  
16999 -       __disable_runtime(rq);
17000 +       disable_runtime_rt(rq);
17001  
17002         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
17003  }
17004 diff -NurpP --minimal linux-2.6.32/kernel/signal.c linux-2.6.32-vs2.3.0.36.26/kernel/signal.c
17005 --- linux-2.6.32/kernel/signal.c        2009-12-03 20:02:58.000000000 +0100
17006 +++ linux-2.6.32-vs2.3.0.36.26/kernel/signal.c  2009-12-03 20:04:56.000000000 +0100
17007 @@ -27,6 +27,8 @@
17008  #include <linux/freezer.h>
17009  #include <linux/pid_namespace.h>
17010  #include <linux/nsproxy.h>
17011 +#include <linux/vs_context.h>
17012 +#include <linux/vs_pid.h>
17013  #include <trace/events/sched.h>
17014  
17015  #include <asm/param.h>
17016 @@ -598,6 +600,14 @@ static int check_kill_permission(int sig
17017         if (!valid_signal(sig))
17018                 return -EINVAL;
17019  
17020 +       if ((info != SEND_SIG_NOINFO) &&
17021 +               (is_si_special(info) || !SI_FROMUSER(info)))
17022 +               goto skip;
17023 +
17024 +       vxdprintk(VXD_CBIT(misc, 7),
17025 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17026 +               sig, info, t, vx_task_xid(t), t->pid);
17027 +
17028         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
17029                 return 0;
17030  
17031 @@ -625,6 +635,20 @@ static int check_kill_permission(int sig
17032                 }
17033         }
17034  
17035 +       error = -EPERM;
17036 +       if (t->pid == 1 && current->xid)
17037 +               return error;
17038 +
17039 +       error = -ESRCH;
17040 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17041 +                 loops, maybe ENOENT or EACCES? */
17042 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17043 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17044 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17045 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17046 +               return error;
17047 +       }
17048 +skip:
17049         return security_task_kill(t, info, sig, 0);
17050  }
17051  
17052 @@ -1112,7 +1136,7 @@ int kill_pid_info(int sig, struct siginf
17053         rcu_read_lock();
17054  retry:
17055         p = pid_task(pid, PIDTYPE_PID);
17056 -       if (p) {
17057 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17058                 error = group_send_sig_info(sig, info, p);
17059                 if (unlikely(error == -ESRCH))
17060                         /*
17061 @@ -1151,7 +1175,7 @@ int kill_pid_info_as_uid(int sig, struct
17062  
17063         read_lock(&tasklist_lock);
17064         p = pid_task(pid, PIDTYPE_PID);
17065 -       if (!p) {
17066 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17067                 ret = -ESRCH;
17068                 goto out_unlock;
17069         }
17070 @@ -1205,8 +1229,10 @@ static int kill_something_info(int sig, 
17071                 struct task_struct * p;
17072  
17073                 for_each_process(p) {
17074 -                       if (task_pid_vnr(p) > 1 &&
17075 -                                       !same_thread_group(p, current)) {
17076 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17077 +                               task_pid_vnr(p) > 1 &&
17078 +                               !same_thread_group(p, current) &&
17079 +                               !vx_current_initpid(p->pid)) {
17080                                 int err = group_send_sig_info(sig, info, p);
17081                                 ++count;
17082                                 if (err != -EPERM)
17083 @@ -1871,6 +1897,11 @@ relock:
17084                                 !sig_kernel_only(signr))
17085                         continue;
17086  
17087 +               /* virtual init is protected against user signals */
17088 +               if ((info->si_code == SI_USER) &&
17089 +                       vx_current_initpid(current->pid))
17090 +                       continue;
17091 +
17092                 if (sig_kernel_stop(signr)) {
17093                         /*
17094                          * The default action is to stop all threads in
17095 diff -NurpP --minimal linux-2.6.32/kernel/softirq.c linux-2.6.32-vs2.3.0.36.26/kernel/softirq.c
17096 --- linux-2.6.32/kernel/softirq.c       2009-12-03 20:02:58.000000000 +0100
17097 +++ linux-2.6.32-vs2.3.0.36.26/kernel/softirq.c 2009-12-03 20:04:56.000000000 +0100
17098 @@ -24,6 +24,7 @@
17099  #include <linux/ftrace.h>
17100  #include <linux/smp.h>
17101  #include <linux/tick.h>
17102 +#include <linux/vs_context.h>
17103  
17104  #define CREATE_TRACE_POINTS
17105  #include <trace/events/irq.h>
17106 diff -NurpP --minimal linux-2.6.32/kernel/sys.c linux-2.6.32-vs2.3.0.36.26/kernel/sys.c
17107 --- linux-2.6.32/kernel/sys.c   2009-12-03 20:02:58.000000000 +0100
17108 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sys.c     2009-12-03 20:04:56.000000000 +0100
17109 @@ -41,6 +41,7 @@
17110  #include <linux/syscalls.h>
17111  #include <linux/kprobes.h>
17112  #include <linux/user_namespace.h>
17113 +#include <linux/vs_pid.h>
17114  
17115  #include <asm/uaccess.h>
17116  #include <asm/io.h>
17117 @@ -130,7 +131,10 @@ static int set_one_prio(struct task_stru
17118                 goto out;
17119         }
17120         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17121 -               error = -EACCES;
17122 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17123 +                       error = 0;
17124 +               else
17125 +                       error = -EACCES;
17126                 goto out;
17127         }
17128         no_nice = security_task_setnice(p, niceval);
17129 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17130                         else
17131                                 pgrp = task_pgrp(current);
17132                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17133 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17134 +                                       continue;
17135                                 error = set_one_prio(p, niceval, error);
17136                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17137                         break;
17138 @@ -240,6 +246,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17139                         else
17140                                 pgrp = task_pgrp(current);
17141                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17142 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17143 +                                       continue;
17144                                 niceval = 20 - task_nice(p);
17145                                 if (niceval > retval)
17146                                         retval = niceval;
17147 @@ -349,6 +357,9 @@ void kernel_power_off(void)
17148         machine_power_off();
17149  }
17150  EXPORT_SYMBOL_GPL(kernel_power_off);
17151 +
17152 +long vs_reboot(unsigned int, void __user *);
17153 +
17154  /*
17155   * Reboot system call: for obvious reasons only root may call it,
17156   * and even root needs to set up some magic numbers in the registers
17157 @@ -381,6 +392,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17158         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17159                 cmd = LINUX_REBOOT_CMD_HALT;
17160  
17161 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17162 +               return vs_reboot(cmd, arg);
17163 +
17164         lock_kernel();
17165         switch (cmd) {
17166         case LINUX_REBOOT_CMD_RESTART:
17167 @@ -1133,7 +1147,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17168         int errno;
17169         char tmp[__NEW_UTS_LEN];
17170  
17171 -       if (!capable(CAP_SYS_ADMIN))
17172 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17173                 return -EPERM;
17174         if (len < 0 || len > __NEW_UTS_LEN)
17175                 return -EINVAL;
17176 @@ -1182,7 +1196,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17177         int errno;
17178         char tmp[__NEW_UTS_LEN];
17179  
17180 -       if (!capable(CAP_SYS_ADMIN))
17181 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17182                 return -EPERM;
17183         if (len < 0 || len > __NEW_UTS_LEN)
17184                 return -EINVAL;
17185 @@ -1251,7 +1265,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17186                 return -EINVAL;
17187         old_rlim = current->signal->rlim + resource;
17188         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17189 -           !capable(CAP_SYS_RESOURCE))
17190 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17191                 return -EPERM;
17192         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17193                 return -EPERM;
17194 diff -NurpP --minimal linux-2.6.32/kernel/sysctl.c linux-2.6.32-vs2.3.0.36.26/kernel/sysctl.c
17195 --- linux-2.6.32/kernel/sysctl.c        2009-12-03 20:02:58.000000000 +0100
17196 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sysctl.c  2009-12-03 20:04:56.000000000 +0100
17197 @@ -124,6 +124,7 @@ static int ngroups_max = NGROUPS_MAX;
17198  extern char modprobe_path[];
17199  extern int modules_disabled;
17200  #endif
17201 +extern char vshelper_path[];
17202  #ifdef CONFIG_CHR_DEV_SG
17203  extern int sg_big_buff;
17204  #endif
17205 @@ -593,6 +594,15 @@ static struct ctl_table kern_table[] = {
17206                 .strategy       = &sysctl_string,
17207         },
17208  #endif
17209 +       {
17210 +               .ctl_name       = KERN_VSHELPER,
17211 +               .procname       = "vshelper",
17212 +               .data           = &vshelper_path,
17213 +               .maxlen         = 256,
17214 +               .mode           = 0644,
17215 +               .proc_handler   = &proc_dostring,
17216 +               .strategy       = &sysctl_string,
17217 +       },
17218  #ifdef CONFIG_CHR_DEV_SG
17219         {
17220                 .ctl_name       = KERN_SG_BIG_BUFF,
17221 diff -NurpP --minimal linux-2.6.32/kernel/sysctl_check.c linux-2.6.32-vs2.3.0.36.26/kernel/sysctl_check.c
17222 --- linux-2.6.32/kernel/sysctl_check.c  2009-12-03 20:02:58.000000000 +0100
17223 +++ linux-2.6.32-vs2.3.0.36.26/kernel/sysctl_check.c    2009-12-03 20:04:56.000000000 +0100
17224 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17225  
17226         { KERN_PANIC,                   "panic" },
17227         { KERN_REALROOTDEV,             "real-root-dev" },
17228 +       { KERN_VSHELPER,                "vshelper", },
17229  
17230         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17231         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17232 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
17233         {}
17234  };
17235  
17236 +static struct trans_ctl_table trans_vserver_table[] = {
17237 +       { 1,    "debug_switch" },
17238 +       { 2,    "debug_xid" },
17239 +       { 3,    "debug_nid" },
17240 +       { 4,    "debug_tag" },
17241 +       { 5,    "debug_net" },
17242 +       { 6,    "debug_limit" },
17243 +       { 7,    "debug_cres" },
17244 +       { 8,    "debug_dlim" },
17245 +       { 9,    "debug_quota" },
17246 +       { 10,   "debug_cvirt" },
17247 +       { 11,   "debug_space" },
17248 +       { 12,   "debug_misc" },
17249 +       {}
17250 +};
17251 +
17252  static const struct trans_ctl_table trans_root_table[] = {
17253         { CTL_KERN,     "kernel",       trans_kern_table },
17254         { CTL_VM,       "vm",           trans_vm_table },
17255 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
17256         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17257         { CTL_PM,       "pm",           trans_pm_table },
17258         { CTL_FRV,      "frv",          trans_frv_table },
17259 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17260         {}
17261  };
17262  
17263 diff -NurpP --minimal linux-2.6.32/kernel/time.c linux-2.6.32-vs2.3.0.36.26/kernel/time.c
17264 --- linux-2.6.32/kernel/time.c  2009-12-03 20:02:58.000000000 +0100
17265 +++ linux-2.6.32-vs2.3.0.36.26/kernel/time.c    2009-12-03 20:04:56.000000000 +0100
17266 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
17267  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17268  {
17269         time_t i = get_seconds();
17270 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17271  
17272         if (tloc) {
17273                 if (put_user(i,tloc))
17274 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17275         if (err)
17276                 return err;
17277  
17278 -       do_settimeofday(&tv);
17279 +       vx_settimeofday(&tv);
17280         return 0;
17281  }
17282  
17283 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17284  {
17285         if (likely(tv != NULL)) {
17286                 struct timeval ktv;
17287 -               do_gettimeofday(&ktv);
17288 +               vx_gettimeofday(&ktv);
17289                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17290                         return -EFAULT;
17291         }
17292 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
17293                 /* SMP safe, again the code in arch/foo/time.c should
17294                  * globally block out interrupts when it runs.
17295                  */
17296 -               return do_settimeofday(tv);
17297 +               return vx_settimeofday(tv);
17298         }
17299         return 0;
17300  }
17301 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
17302  {
17303         struct timeval x;
17304  
17305 -       do_gettimeofday(&x);
17306 +       vx_gettimeofday(&x);
17307         tv->tv_sec = x.tv_sec;
17308         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17309  }
17310 diff -NurpP --minimal linux-2.6.32/kernel/timer.c linux-2.6.32-vs2.3.0.36.26/kernel/timer.c
17311 --- linux-2.6.32/kernel/timer.c 2009-12-03 20:02:58.000000000 +0100
17312 +++ linux-2.6.32-vs2.3.0.36.26/kernel/timer.c   2009-12-03 20:04:56.000000000 +0100
17313 @@ -39,6 +39,10 @@
17314  #include <linux/kallsyms.h>
17315  #include <linux/perf_event.h>
17316  #include <linux/sched.h>
17317 +#include <linux/vs_base.h>
17318 +#include <linux/vs_cvirt.h>
17319 +#include <linux/vs_pid.h>
17320 +#include <linux/vserver/sched.h>
17321  
17322  #include <asm/uaccess.h>
17323  #include <asm/unistd.h>
17324 @@ -1255,12 +1259,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17325  
17326  #endif
17327  
17328 -#ifndef __alpha__
17329 -
17330 -/*
17331 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17332 - * should be moved into arch/i386 instead?
17333 - */
17334  
17335  /**
17336   * sys_getpid - return the thread group id of the current process
17337 @@ -1289,10 +1287,23 @@ SYSCALL_DEFINE0(getppid)
17338         rcu_read_lock();
17339         pid = task_tgid_vnr(current->real_parent);
17340         rcu_read_unlock();
17341 +       return vx_map_pid(pid);
17342 +}
17343  
17344 -       return pid;
17345 +#ifdef __alpha__
17346 +
17347 +/*
17348 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17349 + */
17350 +
17351 +asmlinkage long do_getxpid(long *ppid)
17352 +{
17353 +       *ppid = sys_getppid();
17354 +       return sys_getpid();
17355  }
17356  
17357 +#else /* _alpha_ */
17358 +
17359  SYSCALL_DEFINE0(getuid)
17360  {
17361         /* Only we change this so SMP safe */
17362 diff -NurpP --minimal linux-2.6.32/kernel/user.c linux-2.6.32-vs2.3.0.36.26/kernel/user.c
17363 --- linux-2.6.32/kernel/user.c  2009-12-03 20:02:58.000000000 +0100
17364 +++ linux-2.6.32-vs2.3.0.36.26/kernel/user.c    2009-12-03 20:04:56.000000000 +0100
17365 @@ -251,10 +251,10 @@ static struct kobj_type uids_ktype = {
17366   *
17367   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
17368   */
17369 -static int uids_user_create(struct user_struct *up)
17370 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17371  {
17372         struct kobject *kobj = &up->kobj;
17373 -       int error;
17374 +       int error = 0;
17375  
17376         memset(kobj, 0, sizeof(struct kobject));
17377         if (up->user_ns != &init_user_ns)
17378 @@ -282,7 +282,7 @@ int __init uids_sysfs_init(void)
17379         if (!uids_kset)
17380                 return -ENOMEM;
17381  
17382 -       return uids_user_create(&root_user);
17383 +       return uids_user_create(NULL, &root_user);
17384  }
17385  
17386  /* delayed work function to remove sysfs directory for a user and free up
17387 @@ -353,7 +353,8 @@ static struct user_struct *uid_hash_find
17388  }
17389  
17390  int uids_sysfs_init(void) { return 0; }
17391 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17392 +static inline int uids_user_create(struct user_namespace *ns,
17393 +       struct user_struct *up) { return 0; }
17394  static inline void uids_mutex_lock(void) { }
17395  static inline void uids_mutex_unlock(void) { }
17396  
17397 @@ -450,7 +451,7 @@ struct user_struct *alloc_uid(struct use
17398  
17399                 new->user_ns = get_user_ns(ns);
17400  
17401 -               if (uids_user_create(new))
17402 +               if (uids_user_create(ns, new))
17403                         goto out_destoy_sched;
17404  
17405                 /*
17406 diff -NurpP --minimal linux-2.6.32/kernel/user_namespace.c linux-2.6.32-vs2.3.0.36.26/kernel/user_namespace.c
17407 --- linux-2.6.32/kernel/user_namespace.c        2009-03-24 14:22:45.000000000 +0100
17408 +++ linux-2.6.32-vs2.3.0.36.26/kernel/user_namespace.c  2009-12-03 20:04:56.000000000 +0100
17409 @@ -10,6 +10,7 @@
17410  #include <linux/slab.h>
17411  #include <linux/user_namespace.h>
17412  #include <linux/cred.h>
17413 +#include <linux/vserver/global.h>
17414  
17415  /*
17416   * Create a new user namespace, deriving the creator from the user in the
17417 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17418                 return -ENOMEM;
17419  
17420         kref_init(&ns->kref);
17421 +       atomic_inc(&vs_global_user_ns);
17422  
17423         for (n = 0; n < UIDHASH_SZ; ++n)
17424                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17425 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17426         struct user_namespace *ns =
17427                 container_of(kref, struct user_namespace, kref);
17428  
17429 +       /* FIXME: maybe move into destroyer? */
17430 +       atomic_dec(&vs_global_user_ns);
17431         INIT_WORK(&ns->destroyer, free_user_ns_work);
17432         schedule_work(&ns->destroyer);
17433  }
17434 diff -NurpP --minimal linux-2.6.32/kernel/utsname.c linux-2.6.32-vs2.3.0.36.26/kernel/utsname.c
17435 --- linux-2.6.32/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
17436 +++ linux-2.6.32-vs2.3.0.36.26/kernel/utsname.c 2009-12-03 20:04:56.000000000 +0100
17437 @@ -14,14 +14,17 @@
17438  #include <linux/utsname.h>
17439  #include <linux/err.h>
17440  #include <linux/slab.h>
17441 +#include <linux/vserver/global.h>
17442  
17443  static struct uts_namespace *create_uts_ns(void)
17444  {
17445         struct uts_namespace *uts_ns;
17446  
17447         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17448 -       if (uts_ns)
17449 +       if (uts_ns) {
17450                 kref_init(&uts_ns->kref);
17451 +               atomic_inc(&vs_global_uts_ns);
17452 +       }
17453         return uts_ns;
17454  }
17455  
17456 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
17457         struct uts_namespace *ns;
17458  
17459         ns = container_of(kref, struct uts_namespace, kref);
17460 +       atomic_dec(&vs_global_uts_ns);
17461         kfree(ns);
17462  }
17463 diff -NurpP --minimal linux-2.6.32/kernel/vserver/cacct.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cacct.c
17464 --- linux-2.6.32/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
17465 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cacct.c   2009-12-03 20:04:56.000000000 +0100
17466 @@ -0,0 +1,42 @@
17467 +/*
17468 + *  linux/kernel/vserver/cacct.c
17469 + *
17470 + *  Virtual Server: Context Accounting
17471 + *
17472 + *  Copyright (C) 2006-2007 Herbert Pötzl
17473 + *
17474 + *  V0.01  added accounting stats
17475 + *
17476 + */
17477 +
17478 +#include <linux/types.h>
17479 +#include <linux/vs_context.h>
17480 +#include <linux/vserver/cacct_cmd.h>
17481 +#include <linux/vserver/cacct_int.h>
17482 +
17483 +#include <asm/errno.h>
17484 +#include <asm/uaccess.h>
17485 +
17486 +
17487 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17488 +{
17489 +       struct vcmd_sock_stat_v0 vc_data;
17490 +       int j, field;
17491 +
17492 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17493 +               return -EFAULT;
17494 +
17495 +       field = vc_data.field;
17496 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17497 +               return -EINVAL;
17498 +
17499 +       for (j = 0; j < 3; j++) {
17500 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17501 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17502 +       }
17503 +
17504 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17505 +               return -EFAULT;
17506 +       return 0;
17507 +}
17508 +
17509 diff -NurpP --minimal linux-2.6.32/kernel/vserver/cacct_init.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cacct_init.h
17510 --- linux-2.6.32/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
17511 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cacct_init.h      2009-12-03 20:04:56.000000000 +0100
17512 @@ -0,0 +1,25 @@
17513 +
17514 +
17515 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17516 +{
17517 +       int i, j;
17518 +
17519 +
17520 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17521 +               for (j = 0; j < 3; j++) {
17522 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17523 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17524 +               }
17525 +       }
17526 +       for (i = 0; i < 8; i++)
17527 +               atomic_set(&cacct->slab[i], 0);
17528 +       for (i = 0; i < 5; i++)
17529 +               for (j = 0; j < 4; j++)
17530 +                       atomic_set(&cacct->page[i][j], 0);
17531 +}
17532 +
17533 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17534 +{
17535 +       return;
17536 +}
17537 +
17538 diff -NurpP --minimal linux-2.6.32/kernel/vserver/cacct_proc.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cacct_proc.h
17539 --- linux-2.6.32/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
17540 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cacct_proc.h      2009-12-03 20:04:56.000000000 +0100
17541 @@ -0,0 +1,53 @@
17542 +#ifndef _VX_CACCT_PROC_H
17543 +#define _VX_CACCT_PROC_H
17544 +
17545 +#include <linux/vserver/cacct_int.h>
17546 +
17547 +
17548 +#define VX_SOCKA_TOP   \
17549 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17550 +
17551 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17552 +{
17553 +       int i, j, length = 0;
17554 +       static char *type[VXA_SOCK_SIZE] = {
17555 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17556 +       };
17557 +
17558 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17559 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17560 +               length += sprintf(buffer + length, "%s:", type[i]);
17561 +               for (j = 0; j < 3; j++) {
17562 +                       length += sprintf(buffer + length,
17563 +                               "\t%10lu/%-10lu",
17564 +                               vx_sock_count(cacct, i, j),
17565 +                               vx_sock_total(cacct, i, j));
17566 +               }
17567 +               buffer[length++] = '\n';
17568 +       }
17569 +
17570 +       length += sprintf(buffer + length, "\n");
17571 +       length += sprintf(buffer + length,
17572 +               "slab:\t %8u %8u %8u %8u\n",
17573 +               atomic_read(&cacct->slab[1]),
17574 +               atomic_read(&cacct->slab[4]),
17575 +               atomic_read(&cacct->slab[0]),
17576 +               atomic_read(&cacct->slab[2]));
17577 +
17578 +       length += sprintf(buffer + length, "\n");
17579 +       for (i = 0; i < 5; i++) {
17580 +               length += sprintf(buffer + length,
17581 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17582 +                       atomic_read(&cacct->page[i][0]),
17583 +                       atomic_read(&cacct->page[i][1]),
17584 +                       atomic_read(&cacct->page[i][2]),
17585 +                       atomic_read(&cacct->page[i][3]),
17586 +                       atomic_read(&cacct->page[i][4]),
17587 +                       atomic_read(&cacct->page[i][5]),
17588 +                       atomic_read(&cacct->page[i][6]),
17589 +                       atomic_read(&cacct->page[i][7]));
17590 +       }
17591 +       return length;
17592 +}
17593 +
17594 +#endif /* _VX_CACCT_PROC_H */
17595 diff -NurpP --minimal linux-2.6.32/kernel/vserver/context.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/context.c
17596 --- linux-2.6.32/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
17597 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/context.c 2009-12-03 20:04:56.000000000 +0100
17598 @@ -0,0 +1,1057 @@
17599 +/*
17600 + *  linux/kernel/vserver/context.c
17601 + *
17602 + *  Virtual Server: Context Support
17603 + *
17604 + *  Copyright (C) 2003-2007  Herbert Pötzl
17605 + *
17606 + *  V0.01  context helper
17607 + *  V0.02  vx_ctx_kill syscall command
17608 + *  V0.03  replaced context_info calls
17609 + *  V0.04  redesign of struct (de)alloc
17610 + *  V0.05  rlimit basic implementation
17611 + *  V0.06  task_xid and info commands
17612 + *  V0.07  context flags and caps
17613 + *  V0.08  switch to RCU based hash
17614 + *  V0.09  revert to non RCU for now
17615 + *  V0.10  and back to working RCU hash
17616 + *  V0.11  and back to locking again
17617 + *  V0.12  referenced context store
17618 + *  V0.13  separate per cpu data
17619 + *  V0.14  changed vcmds to vxi arg
17620 + *  V0.15  added context stat
17621 + *  V0.16  have __create claim() the vxi
17622 + *  V0.17  removed older and legacy stuff
17623 + *
17624 + */
17625 +
17626 +#include <linux/slab.h>
17627 +#include <linux/types.h>
17628 +#include <linux/security.h>
17629 +#include <linux/pid_namespace.h>
17630 +
17631 +#include <linux/vserver/context.h>
17632 +#include <linux/vserver/network.h>
17633 +#include <linux/vserver/debug.h>
17634 +#include <linux/vserver/limit.h>
17635 +#include <linux/vserver/limit_int.h>
17636 +#include <linux/vserver/space.h>
17637 +#include <linux/init_task.h>
17638 +#include <linux/fs_struct.h>
17639 +
17640 +#include <linux/vs_context.h>
17641 +#include <linux/vs_limit.h>
17642 +#include <linux/vs_pid.h>
17643 +#include <linux/vserver/context_cmd.h>
17644 +
17645 +#include "cvirt_init.h"
17646 +#include "cacct_init.h"
17647 +#include "limit_init.h"
17648 +#include "sched_init.h"
17649 +
17650 +
17651 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17652 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17653 +
17654 +
17655 +/*     now inactive context structures */
17656 +
17657 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17658 +
17659 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17660 +
17661 +
17662 +/*     __alloc_vx_info()
17663 +
17664 +       * allocate an initialized vx_info struct
17665 +       * doesn't make it visible (hash)                        */
17666 +
17667 +static struct vx_info *__alloc_vx_info(xid_t xid)
17668 +{
17669 +       struct vx_info *new = NULL;
17670 +       int cpu, index;
17671 +
17672 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17673 +
17674 +       /* would this benefit from a slab cache? */
17675 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17676 +       if (!new)
17677 +               return 0;
17678 +
17679 +       memset(new, 0, sizeof(struct vx_info));
17680 +#ifdef CONFIG_SMP
17681 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17682 +       if (!new->ptr_pc)
17683 +               goto error;
17684 +#endif
17685 +       new->vx_id = xid;
17686 +       INIT_HLIST_NODE(&new->vx_hlist);
17687 +       atomic_set(&new->vx_usecnt, 0);
17688 +       atomic_set(&new->vx_tasks, 0);
17689 +       new->vx_parent = NULL;
17690 +       new->vx_state = 0;
17691 +       init_waitqueue_head(&new->vx_wait);
17692 +
17693 +       /* prepare reaper */
17694 +       get_task_struct(init_pid_ns.child_reaper);
17695 +       new->vx_reaper = init_pid_ns.child_reaper;
17696 +       new->vx_badness_bias = 0;
17697 +
17698 +       /* rest of init goes here */
17699 +       vx_info_init_limit(&new->limit);
17700 +       vx_info_init_sched(&new->sched);
17701 +       vx_info_init_cvirt(&new->cvirt);
17702 +       vx_info_init_cacct(&new->cacct);
17703 +
17704 +       /* per cpu data structures */
17705 +       for_each_possible_cpu(cpu) {
17706 +               vx_info_init_sched_pc(
17707 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17708 +               vx_info_init_cvirt_pc(
17709 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17710 +       }
17711 +
17712 +       new->vx_flags = VXF_INIT_SET;
17713 +       cap_set_init_eff(new->vx_bcaps);
17714 +       new->vx_ccaps = 0;
17715 +       new->vx_umask = 0;
17716 +
17717 +       new->reboot_cmd = 0;
17718 +       new->exit_code = 0;
17719 +
17720 +       // preconfig fs entries
17721 +       for (index = 0; index < VX_SPACES; index++) {
17722 +               write_lock(&init_fs.lock);
17723 +               init_fs.users++;
17724 +               write_unlock(&init_fs.lock);
17725 +               new->vx_fs[index] = &init_fs;
17726 +       }
17727 +
17728 +       vxdprintk(VXD_CBIT(xid, 0),
17729 +               "alloc_vx_info(%d) = %p", xid, new);
17730 +       vxh_alloc_vx_info(new);
17731 +       atomic_inc(&vx_global_ctotal);
17732 +       return new;
17733 +#ifdef CONFIG_SMP
17734 +error:
17735 +       kfree(new);
17736 +       return 0;
17737 +#endif
17738 +}
17739 +
17740 +/*     __dealloc_vx_info()
17741 +
17742 +       * final disposal of vx_info                             */
17743 +
17744 +static void __dealloc_vx_info(struct vx_info *vxi)
17745 +{
17746 +       struct vx_info_save vxis;
17747 +       int cpu;
17748 +
17749 +       vxdprintk(VXD_CBIT(xid, 0),
17750 +               "dealloc_vx_info(%p)", vxi);
17751 +       vxh_dealloc_vx_info(vxi);
17752 +
17753 +#ifdef CONFIG_VSERVER_WARN
17754 +       enter_vx_info(vxi, &vxis);
17755 +       vx_info_exit_limit(&vxi->limit);
17756 +       vx_info_exit_sched(&vxi->sched);
17757 +       vx_info_exit_cvirt(&vxi->cvirt);
17758 +       vx_info_exit_cacct(&vxi->cacct);
17759 +
17760 +       for_each_possible_cpu(cpu) {
17761 +               vx_info_exit_sched_pc(
17762 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17763 +               vx_info_exit_cvirt_pc(
17764 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17765 +       }
17766 +       leave_vx_info(&vxis);
17767 +#endif
17768 +
17769 +       vxi->vx_id = -1;
17770 +       vxi->vx_state |= VXS_RELEASED;
17771 +
17772 +#ifdef CONFIG_SMP
17773 +       free_percpu(vxi->ptr_pc);
17774 +#endif
17775 +       kfree(vxi);
17776 +       atomic_dec(&vx_global_ctotal);
17777 +}
17778 +
17779 +static void __shutdown_vx_info(struct vx_info *vxi)
17780 +{
17781 +       struct nsproxy *nsproxy;
17782 +       struct fs_struct *fs;
17783 +       int index, kill;
17784 +
17785 +       might_sleep();
17786 +
17787 +       vxi->vx_state |= VXS_SHUTDOWN;
17788 +       vs_state_change(vxi, VSC_SHUTDOWN);
17789 +
17790 +       for (index = 0; index < VX_SPACES; index++) {
17791 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17792 +               if (nsproxy)
17793 +                       put_nsproxy(nsproxy);
17794 +
17795 +               fs = xchg(&vxi->vx_fs[index], NULL);
17796 +               write_lock(&fs->lock);
17797 +               kill = !--fs->users;
17798 +               write_unlock(&fs->lock);
17799 +               if (kill)
17800 +                       free_fs_struct(fs);
17801 +       }
17802 +}
17803 +
17804 +/* exported stuff */
17805 +
17806 +void free_vx_info(struct vx_info *vxi)
17807 +{
17808 +       unsigned long flags;
17809 +       unsigned index;
17810 +
17811 +       /* check for reference counts first */
17812 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17813 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17814 +
17815 +       /* context must not be hashed */
17816 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17817 +
17818 +       /* context shutdown is mandatory */
17819 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17820 +
17821 +       /* nsproxy and fs check */
17822 +       for (index = 0; index < VX_SPACES; index++) {
17823 +               BUG_ON(vxi->vx_nsproxy[index]);
17824 +               BUG_ON(vxi->vx_fs[index]);
17825 +       }
17826 +
17827 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17828 +       hlist_del(&vxi->vx_hlist);
17829 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17830 +
17831 +       __dealloc_vx_info(vxi);
17832 +}
17833 +
17834 +
17835 +/*     hash table for vx_info hash */
17836 +
17837 +#define VX_HASH_SIZE   13
17838 +
17839 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17840 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17841 +
17842 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17843 +
17844 +
17845 +static inline unsigned int __hashval(xid_t xid)
17846 +{
17847 +       return (xid % VX_HASH_SIZE);
17848 +}
17849 +
17850 +
17851 +
17852 +/*     __hash_vx_info()
17853 +
17854 +       * add the vxi to the global hash table
17855 +       * requires the hash_lock to be held                     */
17856 +
17857 +static inline void __hash_vx_info(struct vx_info *vxi)
17858 +{
17859 +       struct hlist_head *head;
17860 +
17861 +       vxd_assert_lock(&vx_info_hash_lock);
17862 +       vxdprintk(VXD_CBIT(xid, 4),
17863 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17864 +       vxh_hash_vx_info(vxi);
17865 +
17866 +       /* context must not be hashed */
17867 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17868 +
17869 +       vxi->vx_state |= VXS_HASHED;
17870 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17871 +       hlist_add_head(&vxi->vx_hlist, head);
17872 +       atomic_inc(&vx_global_cactive);
17873 +}
17874 +
17875 +/*     __unhash_vx_info()
17876 +
17877 +       * remove the vxi from the global hash table
17878 +       * requires the hash_lock to be held                     */
17879 +
17880 +static inline void __unhash_vx_info(struct vx_info *vxi)
17881 +{
17882 +       unsigned long flags;
17883 +
17884 +       vxd_assert_lock(&vx_info_hash_lock);
17885 +       vxdprintk(VXD_CBIT(xid, 4),
17886 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17887 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17888 +       vxh_unhash_vx_info(vxi);
17889 +
17890 +       /* context must be hashed */
17891 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17892 +       /* but without tasks */
17893 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17894 +
17895 +       vxi->vx_state &= ~VXS_HASHED;
17896 +       hlist_del_init(&vxi->vx_hlist);
17897 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17898 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17899 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17900 +       atomic_dec(&vx_global_cactive);
17901 +}
17902 +
17903 +
17904 +/*     __lookup_vx_info()
17905 +
17906 +       * requires the hash_lock to be held
17907 +       * doesn't increment the vx_refcnt                       */
17908 +
17909 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17910 +{
17911 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17912 +       struct hlist_node *pos;
17913 +       struct vx_info *vxi;
17914 +
17915 +       vxd_assert_lock(&vx_info_hash_lock);
17916 +       hlist_for_each(pos, head) {
17917 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17918 +
17919 +               if (vxi->vx_id == xid)
17920 +                       goto found;
17921 +       }
17922 +       vxi = NULL;
17923 +found:
17924 +       vxdprintk(VXD_CBIT(xid, 0),
17925 +               "__lookup_vx_info(#%u): %p[#%u]",
17926 +               xid, vxi, vxi ? vxi->vx_id : 0);
17927 +       vxh_lookup_vx_info(vxi, xid);
17928 +       return vxi;
17929 +}
17930 +
17931 +
17932 +/*     __create_vx_info()
17933 +
17934 +       * create the requested context
17935 +       * get(), claim() and hash it                            */
17936 +
17937 +static struct vx_info *__create_vx_info(int id)
17938 +{
17939 +       struct vx_info *new, *vxi = NULL;
17940 +
17941 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17942 +
17943 +       if (!(new = __alloc_vx_info(id)))
17944 +               return ERR_PTR(-ENOMEM);
17945 +
17946 +       /* required to make dynamic xids unique */
17947 +       spin_lock(&vx_info_hash_lock);
17948 +
17949 +       /* static context requested */
17950 +       if ((vxi = __lookup_vx_info(id))) {
17951 +               vxdprintk(VXD_CBIT(xid, 0),
17952 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17953 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17954 +                       vxi = ERR_PTR(-EBUSY);
17955 +               else
17956 +                       vxi = ERR_PTR(-EEXIST);
17957 +               goto out_unlock;
17958 +       }
17959 +       /* new context */
17960 +       vxdprintk(VXD_CBIT(xid, 0),
17961 +               "create_vx_info(%d) = %p (new)", id, new);
17962 +       claim_vx_info(new, NULL);
17963 +       __hash_vx_info(get_vx_info(new));
17964 +       vxi = new, new = NULL;
17965 +
17966 +out_unlock:
17967 +       spin_unlock(&vx_info_hash_lock);
17968 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17969 +       if (new)
17970 +               __dealloc_vx_info(new);
17971 +       return vxi;
17972 +}
17973 +
17974 +
17975 +/*     exported stuff                                          */
17976 +
17977 +
17978 +void unhash_vx_info(struct vx_info *vxi)
17979 +{
17980 +       __shutdown_vx_info(vxi);
17981 +       spin_lock(&vx_info_hash_lock);
17982 +       __unhash_vx_info(vxi);
17983 +       spin_unlock(&vx_info_hash_lock);
17984 +       __wakeup_vx_info(vxi);
17985 +}
17986 +
17987 +
17988 +/*     lookup_vx_info()
17989 +
17990 +       * search for a vx_info and get() it
17991 +       * negative id means current                             */
17992 +
17993 +struct vx_info *lookup_vx_info(int id)
17994 +{
17995 +       struct vx_info *vxi = NULL;
17996 +
17997 +       if (id < 0) {
17998 +               vxi = get_vx_info(current_vx_info());
17999 +       } else if (id > 1) {
18000 +               spin_lock(&vx_info_hash_lock);
18001 +               vxi = get_vx_info(__lookup_vx_info(id));
18002 +               spin_unlock(&vx_info_hash_lock);
18003 +       }
18004 +       return vxi;
18005 +}
18006 +
18007 +/*     xid_is_hashed()
18008 +
18009 +       * verify that xid is still hashed                       */
18010 +
18011 +int xid_is_hashed(xid_t xid)
18012 +{
18013 +       int hashed;
18014 +
18015 +       spin_lock(&vx_info_hash_lock);
18016 +       hashed = (__lookup_vx_info(xid) != NULL);
18017 +       spin_unlock(&vx_info_hash_lock);
18018 +       return hashed;
18019 +}
18020 +
18021 +#ifdef CONFIG_PROC_FS
18022 +
18023 +/*     get_xid_list()
18024 +
18025 +       * get a subset of hashed xids for proc
18026 +       * assumes size is at least one                          */
18027 +
18028 +int get_xid_list(int index, unsigned int *xids, int size)
18029 +{
18030 +       int hindex, nr_xids = 0;
18031 +
18032 +       /* only show current and children */
18033 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18034 +               if (index > 0)
18035 +                       return 0;
18036 +               xids[nr_xids] = vx_current_xid();
18037 +               return 1;
18038 +       }
18039 +
18040 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18041 +               struct hlist_head *head = &vx_info_hash[hindex];
18042 +               struct hlist_node *pos;
18043 +
18044 +               spin_lock(&vx_info_hash_lock);
18045 +               hlist_for_each(pos, head) {
18046 +                       struct vx_info *vxi;
18047 +
18048 +                       if (--index > 0)
18049 +                               continue;
18050 +
18051 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18052 +                       xids[nr_xids] = vxi->vx_id;
18053 +                       if (++nr_xids >= size) {
18054 +                               spin_unlock(&vx_info_hash_lock);
18055 +                               goto out;
18056 +                       }
18057 +               }
18058 +               /* keep the lock time short */
18059 +               spin_unlock(&vx_info_hash_lock);
18060 +       }
18061 +out:
18062 +       return nr_xids;
18063 +}
18064 +#endif
18065 +
18066 +#ifdef CONFIG_VSERVER_DEBUG
18067 +
18068 +void   dump_vx_info_inactive(int level)
18069 +{
18070 +       struct hlist_node *entry, *next;
18071 +
18072 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18073 +               struct vx_info *vxi =
18074 +                       list_entry(entry, struct vx_info, vx_hlist);
18075 +
18076 +               dump_vx_info(vxi, level);
18077 +       }
18078 +}
18079 +
18080 +#endif
18081 +
18082 +#if 0
18083 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18084 +{
18085 +       struct user_struct *new_user, *old_user;
18086 +
18087 +       if (!p || !vxi)
18088 +               BUG();
18089 +
18090 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18091 +               return -EACCES;
18092 +
18093 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18094 +       if (!new_user)
18095 +               return -ENOMEM;
18096 +
18097 +       old_user = p->user;
18098 +       if (new_user != old_user) {
18099 +               atomic_inc(&new_user->processes);
18100 +               atomic_dec(&old_user->processes);
18101 +               p->user = new_user;
18102 +       }
18103 +       free_uid(old_user);
18104 +       return 0;
18105 +}
18106 +#endif
18107 +
18108 +#if 0
18109 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18110 +{
18111 +       // p->cap_effective &= vxi->vx_cap_bset;
18112 +       p->cap_effective =
18113 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18114 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18115 +       p->cap_inheritable =
18116 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18117 +       // p->cap_permitted &= vxi->vx_cap_bset;
18118 +       p->cap_permitted =
18119 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18120 +}
18121 +#endif
18122 +
18123 +
18124 +#include <linux/file.h>
18125 +#include <linux/fdtable.h>
18126 +
18127 +static int vx_openfd_task(struct task_struct *tsk)
18128 +{
18129 +       struct files_struct *files = tsk->files;
18130 +       struct fdtable *fdt;
18131 +       const unsigned long *bptr;
18132 +       int count, total;
18133 +
18134 +       /* no rcu_read_lock() because of spin_lock() */
18135 +       spin_lock(&files->file_lock);
18136 +       fdt = files_fdtable(files);
18137 +       bptr = fdt->open_fds->fds_bits;
18138 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18139 +       for (total = 0; count > 0; count--) {
18140 +               if (*bptr)
18141 +                       total += hweight_long(*bptr);
18142 +               bptr++;
18143 +       }
18144 +       spin_unlock(&files->file_lock);
18145 +       return total;
18146 +}
18147 +
18148 +
18149 +/*     for *space compatibility */
18150 +
18151 +asmlinkage long sys_unshare(unsigned long);
18152 +
18153 +/*
18154 + *     migrate task to new context
18155 + *     gets vxi, puts old_vxi on change
18156 + *     optionally unshares namespaces (hack)
18157 + */
18158 +
18159 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18160 +{
18161 +       struct vx_info *old_vxi;
18162 +       int ret = 0;
18163 +
18164 +       if (!p || !vxi)
18165 +               BUG();
18166 +
18167 +       vxdprintk(VXD_CBIT(xid, 5),
18168 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18169 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18170 +
18171 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18172 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18173 +               return -EACCES;
18174 +
18175 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18176 +               return -EFAULT;
18177 +
18178 +       old_vxi = task_get_vx_info(p);
18179 +       if (old_vxi == vxi)
18180 +               goto out;
18181 +
18182 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18183 +       {
18184 +               int openfd;
18185 +
18186 +               task_lock(p);
18187 +               openfd = vx_openfd_task(p);
18188 +
18189 +               if (old_vxi) {
18190 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18191 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18192 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18193 +                       /* FIXME: what about the struct files here? */
18194 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18195 +                       /* account for the executable */
18196 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18197 +               }
18198 +               atomic_inc(&vxi->cvirt.nr_threads);
18199 +               atomic_inc(&vxi->cvirt.nr_running);
18200 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18201 +               /* FIXME: what about the struct files here? */
18202 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18203 +               /* account for the executable */
18204 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18205 +
18206 +               if (old_vxi) {
18207 +                       release_vx_info(old_vxi, p);
18208 +                       clr_vx_info(&p->vx_info);
18209 +               }
18210 +               claim_vx_info(vxi, p);
18211 +               set_vx_info(&p->vx_info, vxi);
18212 +               p->xid = vxi->vx_id;
18213 +
18214 +               vxdprintk(VXD_CBIT(xid, 5),
18215 +                       "moved task %p into vxi:%p[#%d]",
18216 +                       p, vxi, vxi->vx_id);
18217 +
18218 +               // vx_mask_cap_bset(vxi, p);
18219 +               task_unlock(p);
18220 +
18221 +               /* hack for *spaces to provide compatibility */
18222 +               if (unshare) {
18223 +                       struct nsproxy *old_nsp, *new_nsp;
18224 +
18225 +                       ret = unshare_nsproxy_namespaces(
18226 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18227 +                               &new_nsp, NULL);
18228 +                       if (ret)
18229 +                               goto out;
18230 +
18231 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18232 +                       vx_set_space(vxi,
18233 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18234 +                       put_nsproxy(old_nsp);
18235 +               }
18236 +       }
18237 +out:
18238 +       put_vx_info(old_vxi);
18239 +       return ret;
18240 +}
18241 +
18242 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18243 +{
18244 +       struct task_struct *old_reaper;
18245 +
18246 +       if (!vxi)
18247 +               return -EINVAL;
18248 +
18249 +       vxdprintk(VXD_CBIT(xid, 6),
18250 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18251 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18252 +
18253 +       old_reaper = vxi->vx_reaper;
18254 +       if (old_reaper == p)
18255 +               return 0;
18256 +
18257 +       /* set new child reaper */
18258 +       get_task_struct(p);
18259 +       vxi->vx_reaper = p;
18260 +       put_task_struct(old_reaper);
18261 +       return 0;
18262 +}
18263 +
18264 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18265 +{
18266 +       if (!vxi)
18267 +               return -EINVAL;
18268 +
18269 +       vxdprintk(VXD_CBIT(xid, 6),
18270 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18271 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18272 +
18273 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18274 +       // vxi->vx_initpid = p->tgid;
18275 +       vxi->vx_initpid = p->pid;
18276 +       return 0;
18277 +}
18278 +
18279 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18280 +{
18281 +       vxdprintk(VXD_CBIT(xid, 6),
18282 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18283 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18284 +
18285 +       vxi->exit_code = code;
18286 +       vxi->vx_initpid = 0;
18287 +}
18288 +
18289 +
18290 +void vx_set_persistent(struct vx_info *vxi)
18291 +{
18292 +       vxdprintk(VXD_CBIT(xid, 6),
18293 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18294 +
18295 +       get_vx_info(vxi);
18296 +       claim_vx_info(vxi, NULL);
18297 +}
18298 +
18299 +void vx_clear_persistent(struct vx_info *vxi)
18300 +{
18301 +       vxdprintk(VXD_CBIT(xid, 6),
18302 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18303 +
18304 +       release_vx_info(vxi, NULL);
18305 +       put_vx_info(vxi);
18306 +}
18307 +
18308 +void vx_update_persistent(struct vx_info *vxi)
18309 +{
18310 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18311 +               vx_set_persistent(vxi);
18312 +       else
18313 +               vx_clear_persistent(vxi);
18314 +}
18315 +
18316 +
18317 +/*     task must be current or locked          */
18318 +
18319 +void   exit_vx_info(struct task_struct *p, int code)
18320 +{
18321 +       struct vx_info *vxi = p->vx_info;
18322 +
18323 +       if (vxi) {
18324 +               atomic_dec(&vxi->cvirt.nr_threads);
18325 +               vx_nproc_dec(p);
18326 +
18327 +               vxi->exit_code = code;
18328 +               release_vx_info(vxi, p);
18329 +       }
18330 +}
18331 +
18332 +void   exit_vx_info_early(struct task_struct *p, int code)
18333 +{
18334 +       struct vx_info *vxi = p->vx_info;
18335 +
18336 +       if (vxi) {
18337 +               if (vxi->vx_initpid == p->pid)
18338 +                       vx_exit_init(vxi, p, code);
18339 +               if (vxi->vx_reaper == p)
18340 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18341 +       }
18342 +}
18343 +
18344 +
18345 +/* vserver syscall commands below here */
18346 +
18347 +/* taks xid and vx_info functions */
18348 +
18349 +#include <asm/uaccess.h>
18350 +
18351 +
18352 +int vc_task_xid(uint32_t id)
18353 +{
18354 +       xid_t xid;
18355 +
18356 +       if (id) {
18357 +               struct task_struct *tsk;
18358 +
18359 +               read_lock(&tasklist_lock);
18360 +               tsk = find_task_by_real_pid(id);
18361 +               xid = (tsk) ? tsk->xid : -ESRCH;
18362 +               read_unlock(&tasklist_lock);
18363 +       } else
18364 +               xid = vx_current_xid();
18365 +       return xid;
18366 +}
18367 +
18368 +
18369 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18370 +{
18371 +       struct vcmd_vx_info_v0 vc_data;
18372 +
18373 +       vc_data.xid = vxi->vx_id;
18374 +       vc_data.initpid = vxi->vx_initpid;
18375 +
18376 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18377 +               return -EFAULT;
18378 +       return 0;
18379 +}
18380 +
18381 +
18382 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18383 +{
18384 +       struct vcmd_ctx_stat_v0 vc_data;
18385 +
18386 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18387 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18388 +
18389 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18390 +               return -EFAULT;
18391 +       return 0;
18392 +}
18393 +
18394 +
18395 +/* context functions */
18396 +
18397 +int vc_ctx_create(uint32_t xid, void __user *data)
18398 +{
18399 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18400 +       struct vx_info *new_vxi;
18401 +       int ret;
18402 +
18403 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18404 +               return -EFAULT;
18405 +
18406 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18407 +               return -EINVAL;
18408 +
18409 +       new_vxi = __create_vx_info(xid);
18410 +       if (IS_ERR(new_vxi))
18411 +               return PTR_ERR(new_vxi);
18412 +
18413 +       /* initial flags */
18414 +       new_vxi->vx_flags = vc_data.flagword;
18415 +
18416 +       ret = -ENOEXEC;
18417 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18418 +               goto out;
18419 +
18420 +       ret = vx_migrate_task(current, new_vxi, (!data));
18421 +       if (ret)
18422 +               goto out;
18423 +
18424 +       /* return context id on success */
18425 +       ret = new_vxi->vx_id;
18426 +
18427 +       /* get a reference for persistent contexts */
18428 +       if ((vc_data.flagword & VXF_PERSISTENT))
18429 +               vx_set_persistent(new_vxi);
18430 +out:
18431 +       release_vx_info(new_vxi, NULL);
18432 +       put_vx_info(new_vxi);
18433 +       return ret;
18434 +}
18435 +
18436 +
18437 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18438 +{
18439 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18440 +       int ret;
18441 +
18442 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18443 +               return -EFAULT;
18444 +
18445 +       ret = vx_migrate_task(current, vxi, 0);
18446 +       if (ret)
18447 +               return ret;
18448 +       if (vc_data.flagword & VXM_SET_INIT)
18449 +               ret = vx_set_init(vxi, current);
18450 +       if (ret)
18451 +               return ret;
18452 +       if (vc_data.flagword & VXM_SET_REAPER)
18453 +               ret = vx_set_reaper(vxi, current);
18454 +       return ret;
18455 +}
18456 +
18457 +
18458 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18459 +{
18460 +       struct vcmd_ctx_flags_v0 vc_data;
18461 +
18462 +       vc_data.flagword = vxi->vx_flags;
18463 +
18464 +       /* special STATE flag handling */
18465 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18466 +
18467 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18468 +               return -EFAULT;
18469 +       return 0;
18470 +}
18471 +
18472 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18473 +{
18474 +       struct vcmd_ctx_flags_v0 vc_data;
18475 +       uint64_t mask, trigger;
18476 +
18477 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18478 +               return -EFAULT;
18479 +
18480 +       /* special STATE flag handling */
18481 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18482 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18483 +
18484 +       if (vxi == current_vx_info()) {
18485 +               /* if (trigger & VXF_STATE_SETUP)
18486 +                       vx_mask_cap_bset(vxi, current); */
18487 +               if (trigger & VXF_STATE_INIT) {
18488 +                       int ret;
18489 +
18490 +                       ret = vx_set_init(vxi, current);
18491 +                       if (ret)
18492 +                               return ret;
18493 +                       ret = vx_set_reaper(vxi, current);
18494 +                       if (ret)
18495 +                               return ret;
18496 +               }
18497 +       }
18498 +
18499 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18500 +               vc_data.flagword, mask);
18501 +       if (trigger & VXF_PERSISTENT)
18502 +               vx_update_persistent(vxi);
18503 +
18504 +       return 0;
18505 +}
18506 +
18507 +
18508 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18509 +{
18510 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18511 +
18512 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18513 +       return v;
18514 +}
18515 +
18516 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18517 +{
18518 +       kernel_cap_t c = __cap_empty_set;
18519 +
18520 +       c.cap[0] = v & 0xFFFFFFFF;
18521 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18522 +
18523 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18524 +       return c;
18525 +}
18526 +
18527 +
18528 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18529 +{
18530 +       if (bcaps)
18531 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18532 +       if (ccaps)
18533 +               *ccaps = vxi->vx_ccaps;
18534 +
18535 +       return 0;
18536 +}
18537 +
18538 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18539 +{
18540 +       struct vcmd_ctx_caps_v1 vc_data;
18541 +       int ret;
18542 +
18543 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18544 +       if (ret)
18545 +               return ret;
18546 +       vc_data.cmask = ~0ULL;
18547 +
18548 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18549 +               return -EFAULT;
18550 +       return 0;
18551 +}
18552 +
18553 +static int do_set_caps(struct vx_info *vxi,
18554 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18555 +{
18556 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18557 +
18558 +#if 0
18559 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18560 +               bcaps, bmask, ccaps, cmask);
18561 +#endif
18562 +       vxi->vx_bcaps = cap_t_from_caps(
18563 +               vs_mask_flags(bcold, bcaps, bmask));
18564 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18565 +
18566 +       return 0;
18567 +}
18568 +
18569 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18570 +{
18571 +       struct vcmd_ctx_caps_v1 vc_data;
18572 +
18573 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18574 +               return -EFAULT;
18575 +
18576 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18577 +}
18578 +
18579 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18580 +{
18581 +       struct vcmd_bcaps vc_data;
18582 +       int ret;
18583 +
18584 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18585 +       if (ret)
18586 +               return ret;
18587 +       vc_data.bmask = ~0ULL;
18588 +
18589 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18590 +               return -EFAULT;
18591 +       return 0;
18592 +}
18593 +
18594 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18595 +{
18596 +       struct vcmd_bcaps vc_data;
18597 +
18598 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18599 +               return -EFAULT;
18600 +
18601 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18602 +}
18603 +
18604 +
18605 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18606 +{
18607 +       struct vcmd_umask vc_data;
18608 +
18609 +       vc_data.umask = vxi->vx_umask;
18610 +       vc_data.mask = ~0ULL;
18611 +
18612 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18613 +               return -EFAULT;
18614 +       return 0;
18615 +}
18616 +
18617 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18618 +{
18619 +       struct vcmd_umask vc_data;
18620 +
18621 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18622 +               return -EFAULT;
18623 +
18624 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18625 +               vc_data.umask, vc_data.mask);
18626 +       return 0;
18627 +}
18628 +
18629 +
18630 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18631 +{
18632 +       struct vcmd_badness_v0 vc_data;
18633 +
18634 +       vc_data.bias = vxi->vx_badness_bias;
18635 +
18636 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18637 +               return -EFAULT;
18638 +       return 0;
18639 +}
18640 +
18641 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18642 +{
18643 +       struct vcmd_badness_v0 vc_data;
18644 +
18645 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18646 +               return -EFAULT;
18647 +
18648 +       vxi->vx_badness_bias = vc_data.bias;
18649 +       return 0;
18650 +}
18651 +
18652 +#include <linux/module.h>
18653 +
18654 +EXPORT_SYMBOL_GPL(free_vx_info);
18655 +
18656 diff -NurpP --minimal linux-2.6.32/kernel/vserver/cvirt.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cvirt.c
18657 --- linux-2.6.32/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
18658 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cvirt.c   2009-12-03 20:04:56.000000000 +0100
18659 @@ -0,0 +1,304 @@
18660 +/*
18661 + *  linux/kernel/vserver/cvirt.c
18662 + *
18663 + *  Virtual Server: Context Virtualization
18664 + *
18665 + *  Copyright (C) 2004-2007  Herbert Pötzl
18666 + *
18667 + *  V0.01  broken out from limit.c
18668 + *  V0.02  added utsname stuff
18669 + *  V0.03  changed vcmds to vxi arg
18670 + *
18671 + */
18672 +
18673 +#include <linux/types.h>
18674 +#include <linux/utsname.h>
18675 +#include <linux/vs_cvirt.h>
18676 +#include <linux/vserver/switch.h>
18677 +#include <linux/vserver/cvirt_cmd.h>
18678 +
18679 +#include <asm/uaccess.h>
18680 +
18681 +
18682 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18683 +{
18684 +       struct vx_info *vxi = current_vx_info();
18685 +
18686 +       set_normalized_timespec(uptime,
18687 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18688 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18689 +       if (!idle)
18690 +               return;
18691 +       set_normalized_timespec(idle,
18692 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18693 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18694 +       return;
18695 +}
18696 +
18697 +uint64_t vx_idle_jiffies(void)
18698 +{
18699 +       return init_task.utime + init_task.stime;
18700 +}
18701 +
18702 +
18703 +
18704 +static inline uint32_t __update_loadavg(uint32_t load,
18705 +       int wsize, int delta, int n)
18706 +{
18707 +       unsigned long long calc, prev;
18708 +
18709 +       /* just set it to n */
18710 +       if (unlikely(delta >= wsize))
18711 +               return (n << FSHIFT);
18712 +
18713 +       calc = delta * n;
18714 +       calc <<= FSHIFT;
18715 +       prev = (wsize - delta);
18716 +       prev *= load;
18717 +       calc += prev;
18718 +       do_div(calc, wsize);
18719 +       return calc;
18720 +}
18721 +
18722 +
18723 +void vx_update_load(struct vx_info *vxi)
18724 +{
18725 +       uint32_t now, last, delta;
18726 +       unsigned int nr_running, nr_uninterruptible;
18727 +       unsigned int total;
18728 +       unsigned long flags;
18729 +
18730 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18731 +
18732 +       now = jiffies;
18733 +       last = vxi->cvirt.load_last;
18734 +       delta = now - last;
18735 +
18736 +       if (delta < 5*HZ)
18737 +               goto out;
18738 +
18739 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18740 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18741 +       total = nr_running + nr_uninterruptible;
18742 +
18743 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18744 +               60*HZ, delta, total);
18745 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18746 +               5*60*HZ, delta, total);
18747 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18748 +               15*60*HZ, delta, total);
18749 +
18750 +       vxi->cvirt.load_last = now;
18751 +out:
18752 +       atomic_inc(&vxi->cvirt.load_updates);
18753 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18754 +}
18755 +
18756 +
18757 +/*
18758 + * Commands to do_syslog:
18759 + *
18760 + *      0 -- Close the log.  Currently a NOP.
18761 + *      1 -- Open the log. Currently a NOP.
18762 + *      2 -- Read from the log.
18763 + *      3 -- Read all messages remaining in the ring buffer.
18764 + *      4 -- Read and clear all messages remaining in the ring buffer
18765 + *      5 -- Clear ring buffer.
18766 + *      6 -- Disable printk's to console
18767 + *      7 -- Enable printk's to console
18768 + *      8 -- Set level of messages printed to console
18769 + *      9 -- Return number of unread characters in the log buffer
18770 + *     10 -- Return size of the log buffer
18771 + */
18772 +int vx_do_syslog(int type, char __user *buf, int len)
18773 +{
18774 +       int error = 0;
18775 +       int do_clear = 0;
18776 +       struct vx_info *vxi = current_vx_info();
18777 +       struct _vx_syslog *log;
18778 +
18779 +       if (!vxi)
18780 +               return -EINVAL;
18781 +       log = &vxi->cvirt.syslog;
18782 +
18783 +       switch (type) {
18784 +       case 0:         /* Close log */
18785 +       case 1:         /* Open log */
18786 +               break;
18787 +       case 2:         /* Read from log */
18788 +               error = wait_event_interruptible(log->log_wait,
18789 +                       (log->log_start - log->log_end));
18790 +               if (error)
18791 +                       break;
18792 +               spin_lock_irq(&log->logbuf_lock);
18793 +               spin_unlock_irq(&log->logbuf_lock);
18794 +               break;
18795 +       case 4:         /* Read/clear last kernel messages */
18796 +               do_clear = 1;
18797 +               /* fall through */
18798 +       case 3:         /* Read last kernel messages */
18799 +               return 0;
18800 +
18801 +       case 5:         /* Clear ring buffer */
18802 +               return 0;
18803 +
18804 +       case 6:         /* Disable logging to console */
18805 +       case 7:         /* Enable logging to console */
18806 +       case 8:         /* Set level of messages printed to console */
18807 +               break;
18808 +
18809 +       case 9:         /* Number of chars in the log buffer */
18810 +               return 0;
18811 +       case 10:        /* Size of the log buffer */
18812 +               return 0;
18813 +       default:
18814 +               error = -EINVAL;
18815 +               break;
18816 +       }
18817 +       return error;
18818 +}
18819 +
18820 +
18821 +/* virtual host info names */
18822 +
18823 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18824 +{
18825 +       struct nsproxy *nsproxy;
18826 +       struct uts_namespace *uts;
18827 +
18828 +       if (id == VHIN_CONTEXT)
18829 +               return vxi->vx_name;
18830 +
18831 +       nsproxy = vxi->vx_nsproxy[0];
18832 +       if (!nsproxy)
18833 +               return NULL;
18834 +
18835 +       uts = nsproxy->uts_ns;
18836 +       if (!uts)
18837 +               return NULL;
18838 +
18839 +       switch (id) {
18840 +       case VHIN_SYSNAME:
18841 +               return uts->name.sysname;
18842 +       case VHIN_NODENAME:
18843 +               return uts->name.nodename;
18844 +       case VHIN_RELEASE:
18845 +               return uts->name.release;
18846 +       case VHIN_VERSION:
18847 +               return uts->name.version;
18848 +       case VHIN_MACHINE:
18849 +               return uts->name.machine;
18850 +       case VHIN_DOMAINNAME:
18851 +               return uts->name.domainname;
18852 +       default:
18853 +               return NULL;
18854 +       }
18855 +       return NULL;
18856 +}
18857 +
18858 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18859 +{
18860 +       struct vcmd_vhi_name_v0 vc_data;
18861 +       char *name;
18862 +
18863 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18864 +               return -EFAULT;
18865 +
18866 +       name = vx_vhi_name(vxi, vc_data.field);
18867 +       if (!name)
18868 +               return -EINVAL;
18869 +
18870 +       memcpy(name, vc_data.name, 65);
18871 +       return 0;
18872 +}
18873 +
18874 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18875 +{
18876 +       struct vcmd_vhi_name_v0 vc_data;
18877 +       char *name;
18878 +
18879 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18880 +               return -EFAULT;
18881 +
18882 +       name = vx_vhi_name(vxi, vc_data.field);
18883 +       if (!name)
18884 +               return -EINVAL;
18885 +
18886 +       memcpy(vc_data.name, name, 65);
18887 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18888 +               return -EFAULT;
18889 +       return 0;
18890 +}
18891 +
18892 +
18893 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18894 +{
18895 +       struct vcmd_virt_stat_v0 vc_data;
18896 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18897 +       struct timespec uptime;
18898 +
18899 +       do_posix_clock_monotonic_gettime(&uptime);
18900 +       set_normalized_timespec(&uptime,
18901 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18902 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18903 +
18904 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18905 +       vc_data.uptime = timespec_to_ns(&uptime);
18906 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18907 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18908 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18909 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18910 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18911 +       vc_data.load[0] = cvirt->load[0];
18912 +       vc_data.load[1] = cvirt->load[1];
18913 +       vc_data.load[2] = cvirt->load[2];
18914 +
18915 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18916 +               return -EFAULT;
18917 +       return 0;
18918 +}
18919 +
18920 +
18921 +#ifdef CONFIG_VSERVER_VTIME
18922 +
18923 +/* virtualized time base */
18924 +
18925 +void vx_gettimeofday(struct timeval *tv)
18926 +{
18927 +       struct vx_info *vxi;
18928 +
18929 +       do_gettimeofday(tv);
18930 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18931 +               return;
18932 +
18933 +       vxi = current_vx_info();
18934 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
18935 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
18936 +
18937 +       if (tv->tv_usec >= USEC_PER_SEC) {
18938 +               tv->tv_sec++;
18939 +               tv->tv_usec -= USEC_PER_SEC;
18940 +       } else if (tv->tv_usec < 0) {
18941 +               tv->tv_sec--;
18942 +               tv->tv_usec += USEC_PER_SEC;
18943 +       }
18944 +}
18945 +
18946 +int vx_settimeofday(struct timespec *ts)
18947 +{
18948 +       struct timeval tv;
18949 +       struct vx_info *vxi;
18950 +
18951 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18952 +               return do_settimeofday(ts);
18953 +
18954 +       do_gettimeofday(&tv);
18955 +       vxi = current_vx_info();
18956 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
18957 +       vxi->cvirt.bias_tv.tv_usec =
18958 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18959 +       return 0;
18960 +}
18961 +
18962 +#endif
18963 +
18964 diff -NurpP --minimal linux-2.6.32/kernel/vserver/cvirt_init.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cvirt_init.h
18965 --- linux-2.6.32/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
18966 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cvirt_init.h      2009-12-03 20:04:56.000000000 +0100
18967 @@ -0,0 +1,69 @@
18968 +
18969 +
18970 +extern uint64_t vx_idle_jiffies(void);
18971 +
18972 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18973 +{
18974 +       uint64_t idle_jiffies = vx_idle_jiffies();
18975 +       uint64_t nsuptime;
18976 +
18977 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18978 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18979 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18980 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18981 +       cvirt->bias_tv.tv_sec = 0;
18982 +       cvirt->bias_tv.tv_usec = 0;
18983 +
18984 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18985 +       atomic_set(&cvirt->nr_threads, 0);
18986 +       atomic_set(&cvirt->nr_running, 0);
18987 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18988 +       atomic_set(&cvirt->nr_onhold, 0);
18989 +
18990 +       spin_lock_init(&cvirt->load_lock);
18991 +       cvirt->load_last = jiffies;
18992 +       atomic_set(&cvirt->load_updates, 0);
18993 +       cvirt->load[0] = 0;
18994 +       cvirt->load[1] = 0;
18995 +       cvirt->load[2] = 0;
18996 +       atomic_set(&cvirt->total_forks, 0);
18997 +
18998 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18999 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19000 +       cvirt->syslog.log_start = 0;
19001 +       cvirt->syslog.log_end = 0;
19002 +       cvirt->syslog.con_start = 0;
19003 +       cvirt->syslog.logged_chars = 0;
19004 +}
19005 +
19006 +static inline
19007 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19008 +{
19009 +       // cvirt_pc->cpustat = { 0 };
19010 +}
19011 +
19012 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19013 +{
19014 +       int value;
19015 +
19016 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19017 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19018 +               cvirt, value);
19019 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19020 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19021 +               cvirt, value);
19022 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19023 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19024 +               cvirt, value);
19025 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19026 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19027 +               cvirt, value);
19028 +       return;
19029 +}
19030 +
19031 +static inline
19032 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19033 +{
19034 +       return;
19035 +}
19036 +
19037 diff -NurpP --minimal linux-2.6.32/kernel/vserver/cvirt_proc.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cvirt_proc.h
19038 --- linux-2.6.32/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
19039 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/cvirt_proc.h      2009-12-03 20:04:56.000000000 +0100
19040 @@ -0,0 +1,135 @@
19041 +#ifndef _VX_CVIRT_PROC_H
19042 +#define _VX_CVIRT_PROC_H
19043 +
19044 +#include <linux/nsproxy.h>
19045 +#include <linux/mnt_namespace.h>
19046 +#include <linux/ipc_namespace.h>
19047 +#include <linux/utsname.h>
19048 +#include <linux/ipc.h>
19049 +
19050 +
19051 +static inline
19052 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19053 +{
19054 +       struct mnt_namespace *ns;
19055 +       struct uts_namespace *uts;
19056 +       struct ipc_namespace *ipc;
19057 +       struct path path;
19058 +       char *pstr, *root;
19059 +       int length = 0;
19060 +
19061 +       if (!nsproxy)
19062 +               goto out;
19063 +
19064 +       length += sprintf(buffer + length,
19065 +               "NSProxy:\t%p [%p,%p,%p]\n",
19066 +               nsproxy, nsproxy->mnt_ns,
19067 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19068 +
19069 +       ns = nsproxy->mnt_ns;
19070 +       if (!ns)
19071 +               goto skip_ns;
19072 +
19073 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19074 +       if (!pstr)
19075 +               goto skip_ns;
19076 +
19077 +       path.mnt = ns->root;
19078 +       path.dentry = ns->root->mnt_root;
19079 +       root = d_path(&path, pstr, PATH_MAX - 2);
19080 +       length += sprintf(buffer + length,
19081 +               "Namespace:\t%p [#%u]\n"
19082 +               "RootPath:\t%s\n",
19083 +               ns, atomic_read(&ns->count),
19084 +               root);
19085 +       kfree(pstr);
19086 +skip_ns:
19087 +
19088 +       uts = nsproxy->uts_ns;
19089 +       if (!uts)
19090 +               goto skip_uts;
19091 +
19092 +       length += sprintf(buffer + length,
19093 +               "SysName:\t%.*s\n"
19094 +               "NodeName:\t%.*s\n"
19095 +               "Release:\t%.*s\n"
19096 +               "Version:\t%.*s\n"
19097 +               "Machine:\t%.*s\n"
19098 +               "DomainName:\t%.*s\n",
19099 +               __NEW_UTS_LEN, uts->name.sysname,
19100 +               __NEW_UTS_LEN, uts->name.nodename,
19101 +               __NEW_UTS_LEN, uts->name.release,
19102 +               __NEW_UTS_LEN, uts->name.version,
19103 +               __NEW_UTS_LEN, uts->name.machine,
19104 +               __NEW_UTS_LEN, uts->name.domainname);
19105 +skip_uts:
19106 +
19107 +       ipc = nsproxy->ipc_ns;
19108 +       if (!ipc)
19109 +               goto skip_ipc;
19110 +
19111 +       length += sprintf(buffer + length,
19112 +               "SEMS:\t\t%d %d %d %d  %d\n"
19113 +               "MSG:\t\t%d %d %d\n"
19114 +               "SHM:\t\t%lu %lu  %d %d\n",
19115 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19116 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19117 +               ipc->used_sems,
19118 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19119 +               (unsigned long)ipc->shm_ctlmax,
19120 +               (unsigned long)ipc->shm_ctlall,
19121 +               ipc->shm_ctlmni, ipc->shm_tot);
19122 +skip_ipc:
19123 +out:
19124 +       return length;
19125 +}
19126 +
19127 +
19128 +#include <linux/sched.h>
19129 +
19130 +#define LOAD_INT(x) ((x) >> FSHIFT)
19131 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19132 +
19133 +static inline
19134 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19135 +{
19136 +       int length = 0;
19137 +       int a, b, c;
19138 +
19139 +       length += sprintf(buffer + length,
19140 +               "BiasUptime:\t%lu.%02lu\n",
19141 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19142 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19143 +
19144 +       a = cvirt->load[0] + (FIXED_1 / 200);
19145 +       b = cvirt->load[1] + (FIXED_1 / 200);
19146 +       c = cvirt->load[2] + (FIXED_1 / 200);
19147 +       length += sprintf(buffer + length,
19148 +               "nr_threads:\t%d\n"
19149 +               "nr_running:\t%d\n"
19150 +               "nr_unintr:\t%d\n"
19151 +               "nr_onhold:\t%d\n"
19152 +               "load_updates:\t%d\n"
19153 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19154 +               "total_forks:\t%d\n",
19155 +               atomic_read(&cvirt->nr_threads),
19156 +               atomic_read(&cvirt->nr_running),
19157 +               atomic_read(&cvirt->nr_uninterruptible),
19158 +               atomic_read(&cvirt->nr_onhold),
19159 +               atomic_read(&cvirt->load_updates),
19160 +               LOAD_INT(a), LOAD_FRAC(a),
19161 +               LOAD_INT(b), LOAD_FRAC(b),
19162 +               LOAD_INT(c), LOAD_FRAC(c),
19163 +               atomic_read(&cvirt->total_forks));
19164 +       return length;
19165 +}
19166 +
19167 +static inline
19168 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19169 +       char *buffer, int cpu)
19170 +{
19171 +       int length = 0;
19172 +       return length;
19173 +}
19174 +
19175 +#endif /* _VX_CVIRT_PROC_H */
19176 diff -NurpP --minimal linux-2.6.32/kernel/vserver/debug.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/debug.c
19177 --- linux-2.6.32/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
19178 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/debug.c   2009-12-03 20:04:56.000000000 +0100
19179 @@ -0,0 +1,32 @@
19180 +/*
19181 + *  kernel/vserver/debug.c
19182 + *
19183 + *  Copyright (C) 2005-2007 Herbert Pötzl
19184 + *
19185 + *  V0.01  vx_info dump support
19186 + *
19187 + */
19188 +
19189 +#include <linux/module.h>
19190 +
19191 +#include <linux/vserver/context.h>
19192 +
19193 +
19194 +void   dump_vx_info(struct vx_info *vxi, int level)
19195 +{
19196 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19197 +               atomic_read(&vxi->vx_usecnt),
19198 +               atomic_read(&vxi->vx_tasks),
19199 +               vxi->vx_state);
19200 +       if (level > 0) {
19201 +               __dump_vx_limit(&vxi->limit);
19202 +               __dump_vx_sched(&vxi->sched);
19203 +               __dump_vx_cvirt(&vxi->cvirt);
19204 +               __dump_vx_cacct(&vxi->cacct);
19205 +       }
19206 +       printk("---\n");
19207 +}
19208 +
19209 +
19210 +EXPORT_SYMBOL_GPL(dump_vx_info);
19211 +
19212 diff -NurpP --minimal linux-2.6.32/kernel/vserver/device.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/device.c
19213 --- linux-2.6.32/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
19214 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/device.c  2009-12-03 20:04:56.000000000 +0100
19215 @@ -0,0 +1,443 @@
19216 +/*
19217 + *  linux/kernel/vserver/device.c
19218 + *
19219 + *  Linux-VServer: Device Support
19220 + *
19221 + *  Copyright (C) 2006  Herbert Pötzl
19222 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19223 + *
19224 + *  V0.01  device mapping basics
19225 + *  V0.02  added defaults
19226 + *
19227 + */
19228 +
19229 +#include <linux/slab.h>
19230 +#include <linux/rcupdate.h>
19231 +#include <linux/fs.h>
19232 +#include <linux/namei.h>
19233 +#include <linux/hash.h>
19234 +
19235 +#include <asm/errno.h>
19236 +#include <asm/uaccess.h>
19237 +#include <linux/vserver/base.h>
19238 +#include <linux/vserver/debug.h>
19239 +#include <linux/vserver/context.h>
19240 +#include <linux/vserver/device.h>
19241 +#include <linux/vserver/device_cmd.h>
19242 +
19243 +
19244 +#define DMAP_HASH_BITS 4
19245 +
19246 +
19247 +struct vs_mapping {
19248 +       union {
19249 +               struct hlist_node hlist;
19250 +               struct list_head list;
19251 +       } u;
19252 +#define dm_hlist       u.hlist
19253 +#define dm_list                u.list
19254 +       xid_t xid;
19255 +       dev_t device;
19256 +       struct vx_dmap_target target;
19257 +};
19258 +
19259 +
19260 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19261 +
19262 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19263 +
19264 +static struct vx_dmap_target dmap_defaults[2] = {
19265 +       { .flags = DATTR_OPEN },
19266 +       { .flags = DATTR_OPEN },
19267 +};
19268 +
19269 +
19270 +struct kmem_cache *dmap_cachep __read_mostly;
19271 +
19272 +int __init dmap_cache_init(void)
19273 +{
19274 +       dmap_cachep = kmem_cache_create("dmap_cache",
19275 +               sizeof(struct vs_mapping), 0,
19276 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19277 +       return 0;
19278 +}
19279 +
19280 +__initcall(dmap_cache_init);
19281 +
19282 +
19283 +static inline unsigned int __hashval(dev_t dev, int bits)
19284 +{
19285 +       return hash_long((unsigned long)dev, bits);
19286 +}
19287 +
19288 +
19289 +/*     __hash_mapping()
19290 + *     add the mapping to the hash table
19291 + */
19292 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19293 +{
19294 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19295 +       struct hlist_head *head, *hash = dmap_main_hash;
19296 +       int device = vdm->device;
19297 +
19298 +       spin_lock(hash_lock);
19299 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19300 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19301 +
19302 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19303 +       hlist_add_head(&vdm->dm_hlist, head);
19304 +       spin_unlock(hash_lock);
19305 +}
19306 +
19307 +
19308 +static inline int __mode_to_default(umode_t mode)
19309 +{
19310 +       switch (mode) {
19311 +       case S_IFBLK:
19312 +               return 0;
19313 +       case S_IFCHR:
19314 +               return 1;
19315 +       default:
19316 +               BUG();
19317 +       }
19318 +}
19319 +
19320 +
19321 +/*     __set_default()
19322 + *     set a default
19323 + */
19324 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19325 +       struct vx_dmap_target *vdmt)
19326 +{
19327 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19328 +       spin_lock(hash_lock);
19329 +
19330 +       if (vxi)
19331 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19332 +       else
19333 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19334 +
19335 +
19336 +       spin_unlock(hash_lock);
19337 +
19338 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19339 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19340 +}
19341 +
19342 +
19343 +/*     __remove_default()
19344 + *     remove a default
19345 + */
19346 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19347 +{
19348 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19349 +       spin_lock(hash_lock);
19350 +
19351 +       if (vxi)
19352 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19353 +       else    /* remove == reset */
19354 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19355 +
19356 +       spin_unlock(hash_lock);
19357 +       return 0;
19358 +}
19359 +
19360 +
19361 +/*     __find_mapping()
19362 + *     find a mapping in the hash table
19363 + *
19364 + *     caller must hold hash_lock
19365 + */
19366 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19367 +       struct vs_mapping **local, struct vs_mapping **global)
19368 +{
19369 +       struct hlist_head *hash = dmap_main_hash;
19370 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19371 +       struct hlist_node *pos;
19372 +       struct vs_mapping *vdm;
19373 +
19374 +       *local = NULL;
19375 +       if (global)
19376 +               *global = NULL;
19377 +
19378 +       hlist_for_each(pos, head) {
19379 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19380 +
19381 +               if ((vdm->device == device) &&
19382 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19383 +                       if (vdm->xid == xid) {
19384 +                               *local = vdm;
19385 +                               return 1;
19386 +                       } else if (global && vdm->xid == 0)
19387 +                               *global = vdm;
19388 +               }
19389 +       }
19390 +
19391 +       if (global && *global)
19392 +               return 0;
19393 +       else
19394 +               return -ENOENT;
19395 +}
19396 +
19397 +
19398 +/*     __lookup_mapping()
19399 + *     find a mapping and store the result in target and flags
19400 + */
19401 +static inline int __lookup_mapping(struct vx_info *vxi,
19402 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19403 +{
19404 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19405 +       struct vs_mapping *vdm, *global;
19406 +       struct vx_dmap_target *vdmt;
19407 +       int ret = 0;
19408 +       xid_t xid = vxi->vx_id;
19409 +       int index;
19410 +
19411 +       spin_lock(hash_lock);
19412 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19413 +               ret = 1;
19414 +               vdmt = &vdm->target;
19415 +               goto found;
19416 +       }
19417 +
19418 +       index = __mode_to_default(mode);
19419 +       if (vxi && vxi->dmap.targets[index].flags) {
19420 +               ret = 2;
19421 +               vdmt = &vxi->dmap.targets[index];
19422 +       } else if (global) {
19423 +               ret = 3;
19424 +               vdmt = &global->target;
19425 +               goto found;
19426 +       } else {
19427 +               ret = 4;
19428 +               vdmt = &dmap_defaults[index];
19429 +       }
19430 +
19431 +found:
19432 +       if (target && (vdmt->flags & DATTR_REMAP))
19433 +               *target = vdmt->target;
19434 +       else if (target)
19435 +               *target = device;
19436 +       if (flags)
19437 +               *flags = vdmt->flags;
19438 +
19439 +       spin_unlock(hash_lock);
19440 +
19441 +       return ret;
19442 +}
19443 +
19444 +
19445 +/*     __remove_mapping()
19446 + *     remove a mapping from the hash table
19447 + */
19448 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19449 +       umode_t mode)
19450 +{
19451 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19452 +       struct vs_mapping *vdm = NULL;
19453 +       int ret = 0;
19454 +
19455 +       spin_lock(hash_lock);
19456 +
19457 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19458 +               NULL);
19459 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19460 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19461 +       if (ret < 0)
19462 +               goto out;
19463 +       hlist_del(&vdm->dm_hlist);
19464 +
19465 +out:
19466 +       spin_unlock(hash_lock);
19467 +       if (vdm)
19468 +               kmem_cache_free(dmap_cachep, vdm);
19469 +       return ret;
19470 +}
19471 +
19472 +
19473 +
19474 +int vs_map_device(struct vx_info *vxi,
19475 +       dev_t device, dev_t *target, umode_t mode)
19476 +{
19477 +       int ret, flags = DATTR_MASK;
19478 +
19479 +       if (!vxi) {
19480 +               if (target)
19481 +                       *target = device;
19482 +               goto out;
19483 +       }
19484 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19485 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19486 +               device, target ? *target : 0, flags, mode, ret);
19487 +out:
19488 +       return (flags & DATTR_MASK);
19489 +}
19490 +
19491 +
19492 +
19493 +static int do_set_mapping(struct vx_info *vxi,
19494 +       dev_t device, dev_t target, int flags, umode_t mode)
19495 +{
19496 +       if (device) {
19497 +               struct vs_mapping *new;
19498 +
19499 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19500 +               if (!new)
19501 +                       return -ENOMEM;
19502 +
19503 +               INIT_HLIST_NODE(&new->dm_hlist);
19504 +               new->device = device;
19505 +               new->target.target = target;
19506 +               new->target.flags = flags | mode;
19507 +               new->xid = (vxi ? vxi->vx_id : 0);
19508 +
19509 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19510 +               __hash_mapping(vxi, new);
19511 +       } else {
19512 +               struct vx_dmap_target new = {
19513 +                       .target = target,
19514 +                       .flags = flags | mode,
19515 +               };
19516 +               __set_default(vxi, mode, &new);
19517 +       }
19518 +       return 0;
19519 +}
19520 +
19521 +
19522 +static int do_unset_mapping(struct vx_info *vxi,
19523 +       dev_t device, dev_t target, int flags, umode_t mode)
19524 +{
19525 +       int ret = -EINVAL;
19526 +
19527 +       if (device) {
19528 +               ret = __remove_mapping(vxi, device, mode);
19529 +               if (ret < 0)
19530 +                       goto out;
19531 +       } else {
19532 +               ret = __remove_default(vxi, mode);
19533 +               if (ret < 0)
19534 +                       goto out;
19535 +       }
19536 +
19537 +out:
19538 +       return ret;
19539 +}
19540 +
19541 +
19542 +static inline int __user_device(const char __user *name, dev_t *dev,
19543 +       umode_t *mode)
19544 +{
19545 +       struct nameidata nd;
19546 +       int ret;
19547 +
19548 +       if (!name) {
19549 +               *dev = 0;
19550 +               return 0;
19551 +       }
19552 +       ret = user_lpath(name, &nd.path);
19553 +       if (ret)
19554 +               return ret;
19555 +       if (nd.path.dentry->d_inode) {
19556 +               *dev = nd.path.dentry->d_inode->i_rdev;
19557 +               *mode = nd.path.dentry->d_inode->i_mode;
19558 +       }
19559 +       path_put(&nd.path);
19560 +       return 0;
19561 +}
19562 +
19563 +static inline int __mapping_mode(dev_t device, dev_t target,
19564 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19565 +{
19566 +       if (device)
19567 +               *mode = device_mode & S_IFMT;
19568 +       else if (target)
19569 +               *mode = target_mode & S_IFMT;
19570 +       else
19571 +               return -EINVAL;
19572 +
19573 +       /* if both given, device and target mode have to match */
19574 +       if (device && target &&
19575 +               ((device_mode ^ target_mode) & S_IFMT))
19576 +               return -EINVAL;
19577 +       return 0;
19578 +}
19579 +
19580 +
19581 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19582 +       const char __user *target_path, int flags, int set)
19583 +{
19584 +       dev_t device = ~0, target = ~0;
19585 +       umode_t device_mode = 0, target_mode = 0, mode;
19586 +       int ret;
19587 +
19588 +       ret = __user_device(device_path, &device, &device_mode);
19589 +       if (ret)
19590 +               return ret;
19591 +       ret = __user_device(target_path, &target, &target_mode);
19592 +       if (ret)
19593 +               return ret;
19594 +
19595 +       ret = __mapping_mode(device, target,
19596 +               device_mode, target_mode, &mode);
19597 +       if (ret)
19598 +               return ret;
19599 +
19600 +       if (set)
19601 +               return do_set_mapping(vxi, device, target,
19602 +                       flags, mode);
19603 +       else
19604 +               return do_unset_mapping(vxi, device, target,
19605 +                       flags, mode);
19606 +}
19607 +
19608 +
19609 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19610 +{
19611 +       struct vcmd_set_mapping_v0 vc_data;
19612 +
19613 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19614 +               return -EFAULT;
19615 +
19616 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19617 +               vc_data.flags, 1);
19618 +}
19619 +
19620 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19621 +{
19622 +       struct vcmd_set_mapping_v0 vc_data;
19623 +
19624 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19625 +               return -EFAULT;
19626 +
19627 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19628 +               vc_data.flags, 0);
19629 +}
19630 +
19631 +
19632 +#ifdef CONFIG_COMPAT
19633 +
19634 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19635 +{
19636 +       struct vcmd_set_mapping_v0_x32 vc_data;
19637 +
19638 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19639 +               return -EFAULT;
19640 +
19641 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19642 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19643 +}
19644 +
19645 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19646 +{
19647 +       struct vcmd_set_mapping_v0_x32 vc_data;
19648 +
19649 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19650 +               return -EFAULT;
19651 +
19652 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19653 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19654 +}
19655 +
19656 +#endif /* CONFIG_COMPAT */
19657 +
19658 +
19659 diff -NurpP --minimal linux-2.6.32/kernel/vserver/dlimit.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/dlimit.c
19660 --- linux-2.6.32/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
19661 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/dlimit.c  2009-12-03 20:04:56.000000000 +0100
19662 @@ -0,0 +1,529 @@
19663 +/*
19664 + *  linux/kernel/vserver/dlimit.c
19665 + *
19666 + *  Virtual Server: Context Disk Limits
19667 + *
19668 + *  Copyright (C) 2004-2009  Herbert Pötzl
19669 + *
19670 + *  V0.01  initial version
19671 + *  V0.02  compat32 splitup
19672 + *  V0.03  extended interface
19673 + *
19674 + */
19675 +
19676 +#include <linux/statfs.h>
19677 +#include <linux/sched.h>
19678 +#include <linux/namei.h>
19679 +#include <linux/vs_tag.h>
19680 +#include <linux/vs_dlimit.h>
19681 +#include <linux/vserver/dlimit_cmd.h>
19682 +
19683 +#include <asm/uaccess.h>
19684 +
19685 +/*     __alloc_dl_info()
19686 +
19687 +       * allocate an initialized dl_info struct
19688 +       * doesn't make it visible (hash)                        */
19689 +
19690 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19691 +{
19692 +       struct dl_info *new = NULL;
19693 +
19694 +       vxdprintk(VXD_CBIT(dlim, 5),
19695 +               "alloc_dl_info(%p,%d)*", sb, tag);
19696 +
19697 +       /* would this benefit from a slab cache? */
19698 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19699 +       if (!new)
19700 +               return 0;
19701 +
19702 +       memset(new, 0, sizeof(struct dl_info));
19703 +       new->dl_tag = tag;
19704 +       new->dl_sb = sb;
19705 +       INIT_RCU_HEAD(&new->dl_rcu);
19706 +       INIT_HLIST_NODE(&new->dl_hlist);
19707 +       spin_lock_init(&new->dl_lock);
19708 +       atomic_set(&new->dl_refcnt, 0);
19709 +       atomic_set(&new->dl_usecnt, 0);
19710 +
19711 +       /* rest of init goes here */
19712 +
19713 +       vxdprintk(VXD_CBIT(dlim, 4),
19714 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19715 +       return new;
19716 +}
19717 +
19718 +/*     __dealloc_dl_info()
19719 +
19720 +       * final disposal of dl_info                             */
19721 +
19722 +static void __dealloc_dl_info(struct dl_info *dli)
19723 +{
19724 +       vxdprintk(VXD_CBIT(dlim, 4),
19725 +               "dealloc_dl_info(%p)", dli);
19726 +
19727 +       dli->dl_hlist.next = LIST_POISON1;
19728 +       dli->dl_tag = -1;
19729 +       dli->dl_sb = 0;
19730 +
19731 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19732 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19733 +
19734 +       kfree(dli);
19735 +}
19736 +
19737 +
19738 +/*     hash table for dl_info hash */
19739 +
19740 +#define DL_HASH_SIZE   13
19741 +
19742 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19743 +
19744 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19745 +
19746 +
19747 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19748 +{
19749 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19750 +}
19751 +
19752 +
19753 +
19754 +/*     __hash_dl_info()
19755 +
19756 +       * add the dli to the global hash table
19757 +       * requires the hash_lock to be held                     */
19758 +
19759 +static inline void __hash_dl_info(struct dl_info *dli)
19760 +{
19761 +       struct hlist_head *head;
19762 +
19763 +       vxdprintk(VXD_CBIT(dlim, 6),
19764 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19765 +       get_dl_info(dli);
19766 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19767 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19768 +}
19769 +
19770 +/*     __unhash_dl_info()
19771 +
19772 +       * remove the dli from the global hash table
19773 +       * requires the hash_lock to be held                     */
19774 +
19775 +static inline void __unhash_dl_info(struct dl_info *dli)
19776 +{
19777 +       vxdprintk(VXD_CBIT(dlim, 6),
19778 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19779 +       hlist_del_rcu(&dli->dl_hlist);
19780 +       put_dl_info(dli);
19781 +}
19782 +
19783 +
19784 +/*     __lookup_dl_info()
19785 +
19786 +       * requires the rcu_read_lock()
19787 +       * doesn't increment the dl_refcnt                       */
19788 +
19789 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19790 +{
19791 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19792 +       struct hlist_node *pos;
19793 +       struct dl_info *dli;
19794 +
19795 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19796 +
19797 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19798 +                       return dli;
19799 +               }
19800 +       }
19801 +       return NULL;
19802 +}
19803 +
19804 +
19805 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19806 +{
19807 +       struct dl_info *dli;
19808 +
19809 +       rcu_read_lock();
19810 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19811 +       vxdprintk(VXD_CBIT(dlim, 7),
19812 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19813 +       rcu_read_unlock();
19814 +       return dli;
19815 +}
19816 +
19817 +void rcu_free_dl_info(struct rcu_head *head)
19818 +{
19819 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19820 +       int usecnt, refcnt;
19821 +
19822 +       BUG_ON(!dli || !head);
19823 +
19824 +       usecnt = atomic_read(&dli->dl_usecnt);
19825 +       BUG_ON(usecnt < 0);
19826 +
19827 +       refcnt = atomic_read(&dli->dl_refcnt);
19828 +       BUG_ON(refcnt < 0);
19829 +
19830 +       vxdprintk(VXD_CBIT(dlim, 3),
19831 +               "rcu_free_dl_info(%p)", dli);
19832 +       if (!usecnt)
19833 +               __dealloc_dl_info(dli);
19834 +       else
19835 +               printk("!!! rcu didn't free\n");
19836 +}
19837 +
19838 +
19839 +
19840 +
19841 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19842 +       uint32_t flags, int add)
19843 +{
19844 +       struct path path;
19845 +       int ret;
19846 +
19847 +       ret = user_lpath(name, &path);
19848 +       if (!ret) {
19849 +               struct super_block *sb;
19850 +               struct dl_info *dli;
19851 +
19852 +               ret = -EINVAL;
19853 +               if (!path.dentry->d_inode)
19854 +                       goto out_release;
19855 +               if (!(sb = path.dentry->d_inode->i_sb))
19856 +                       goto out_release;
19857 +
19858 +               if (add) {
19859 +                       dli = __alloc_dl_info(sb, id);
19860 +                       spin_lock(&dl_info_hash_lock);
19861 +
19862 +                       ret = -EEXIST;
19863 +                       if (__lookup_dl_info(sb, id))
19864 +                               goto out_unlock;
19865 +                       __hash_dl_info(dli);
19866 +                       dli = NULL;
19867 +               } else {
19868 +                       spin_lock(&dl_info_hash_lock);
19869 +                       dli = __lookup_dl_info(sb, id);
19870 +
19871 +                       ret = -ESRCH;
19872 +                       if (!dli)
19873 +                               goto out_unlock;
19874 +                       __unhash_dl_info(dli);
19875 +               }
19876 +               ret = 0;
19877 +       out_unlock:
19878 +               spin_unlock(&dl_info_hash_lock);
19879 +               if (add && dli)
19880 +                       __dealloc_dl_info(dli);
19881 +       out_release:
19882 +               path_put(&path);
19883 +       }
19884 +       return ret;
19885 +}
19886 +
19887 +int vc_add_dlimit(uint32_t id, void __user *data)
19888 +{
19889 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19890 +
19891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19892 +               return -EFAULT;
19893 +
19894 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19895 +}
19896 +
19897 +int vc_rem_dlimit(uint32_t id, void __user *data)
19898 +{
19899 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19900 +
19901 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19902 +               return -EFAULT;
19903 +
19904 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19905 +}
19906 +
19907 +#ifdef CONFIG_COMPAT
19908 +
19909 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19910 +{
19911 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19912 +
19913 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19914 +               return -EFAULT;
19915 +
19916 +       return do_addrem_dlimit(id,
19917 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19918 +}
19919 +
19920 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19921 +{
19922 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19923 +
19924 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19925 +               return -EFAULT;
19926 +
19927 +       return do_addrem_dlimit(id,
19928 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19929 +}
19930 +
19931 +#endif /* CONFIG_COMPAT */
19932 +
19933 +
19934 +static inline
19935 +int do_set_dlimit(uint32_t id, const char __user *name,
19936 +       uint32_t space_used, uint32_t space_total,
19937 +       uint32_t inodes_used, uint32_t inodes_total,
19938 +       uint32_t reserved, uint32_t flags)
19939 +{
19940 +       struct path path;
19941 +       int ret;
19942 +
19943 +       ret = user_lpath(name, &path);
19944 +       if (!ret) {
19945 +               struct super_block *sb;
19946 +               struct dl_info *dli;
19947 +
19948 +               ret = -EINVAL;
19949 +               if (!path.dentry->d_inode)
19950 +                       goto out_release;
19951 +               if (!(sb = path.dentry->d_inode->i_sb))
19952 +                       goto out_release;
19953 +
19954 +               /* sanity checks */
19955 +               if ((reserved != CDLIM_KEEP &&
19956 +                       reserved > 100) ||
19957 +                       (inodes_used != CDLIM_KEEP &&
19958 +                       inodes_used > inodes_total) ||
19959 +                       (space_used != CDLIM_KEEP &&
19960 +                       space_used > space_total))
19961 +                       goto out_release;
19962 +
19963 +               ret = -ESRCH;
19964 +               dli = locate_dl_info(sb, id);
19965 +               if (!dli)
19966 +                       goto out_release;
19967 +
19968 +               spin_lock(&dli->dl_lock);
19969 +
19970 +               if (inodes_used != CDLIM_KEEP)
19971 +                       dli->dl_inodes_used = inodes_used;
19972 +               if (inodes_total != CDLIM_KEEP)
19973 +                       dli->dl_inodes_total = inodes_total;
19974 +               if (space_used != CDLIM_KEEP)
19975 +                       dli->dl_space_used = dlimit_space_32to64(
19976 +                               space_used, flags, DLIMS_USED);
19977 +
19978 +               if (space_total == CDLIM_INFINITY)
19979 +                       dli->dl_space_total = DLIM_INFINITY;
19980 +               else if (space_total != CDLIM_KEEP)
19981 +                       dli->dl_space_total = dlimit_space_32to64(
19982 +                               space_total, flags, DLIMS_TOTAL);
19983 +
19984 +               if (reserved != CDLIM_KEEP)
19985 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19986 +
19987 +               spin_unlock(&dli->dl_lock);
19988 +
19989 +               put_dl_info(dli);
19990 +               ret = 0;
19991 +
19992 +       out_release:
19993 +               path_put(&path);
19994 +       }
19995 +       return ret;
19996 +}
19997 +
19998 +int vc_set_dlimit(uint32_t id, void __user *data)
19999 +{
20000 +       struct vcmd_ctx_dlimit_v0 vc_data;
20001 +
20002 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20003 +               return -EFAULT;
20004 +
20005 +       return do_set_dlimit(id, vc_data.name,
20006 +               vc_data.space_used, vc_data.space_total,
20007 +               vc_data.inodes_used, vc_data.inodes_total,
20008 +               vc_data.reserved, vc_data.flags);
20009 +}
20010 +
20011 +#ifdef CONFIG_COMPAT
20012 +
20013 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20014 +{
20015 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20016 +
20017 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20018 +               return -EFAULT;
20019 +
20020 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20021 +               vc_data.space_used, vc_data.space_total,
20022 +               vc_data.inodes_used, vc_data.inodes_total,
20023 +               vc_data.reserved, vc_data.flags);
20024 +}
20025 +
20026 +#endif /* CONFIG_COMPAT */
20027 +
20028 +
20029 +static inline
20030 +int do_get_dlimit(uint32_t id, const char __user *name,
20031 +       uint32_t *space_used, uint32_t *space_total,
20032 +       uint32_t *inodes_used, uint32_t *inodes_total,
20033 +       uint32_t *reserved, uint32_t *flags)
20034 +{
20035 +       struct path path;
20036 +       int ret;
20037 +
20038 +       ret = user_lpath(name, &path);
20039 +       if (!ret) {
20040 +               struct super_block *sb;
20041 +               struct dl_info *dli;
20042 +
20043 +               ret = -EINVAL;
20044 +               if (!path.dentry->d_inode)
20045 +                       goto out_release;
20046 +               if (!(sb = path.dentry->d_inode->i_sb))
20047 +                       goto out_release;
20048 +
20049 +               ret = -ESRCH;
20050 +               dli = locate_dl_info(sb, id);
20051 +               if (!dli)
20052 +                       goto out_release;
20053 +
20054 +               spin_lock(&dli->dl_lock);
20055 +               *inodes_used = dli->dl_inodes_used;
20056 +               *inodes_total = dli->dl_inodes_total;
20057 +
20058 +               *space_used = dlimit_space_64to32(
20059 +                       dli->dl_space_used, flags, DLIMS_USED);
20060 +
20061 +               if (dli->dl_space_total == DLIM_INFINITY)
20062 +                       *space_total = CDLIM_INFINITY;
20063 +               else
20064 +                       *space_total = dlimit_space_64to32(
20065 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20066 +
20067 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20068 +               spin_unlock(&dli->dl_lock);
20069 +
20070 +               put_dl_info(dli);
20071 +               ret = -EFAULT;
20072 +
20073 +               ret = 0;
20074 +       out_release:
20075 +               path_put(&path);
20076 +       }
20077 +       return ret;
20078 +}
20079 +
20080 +
20081 +int vc_get_dlimit(uint32_t id, void __user *data)
20082 +{
20083 +       struct vcmd_ctx_dlimit_v0 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, vc_data.name,
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 +#ifdef CONFIG_COMPAT
20102 +
20103 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20104 +{
20105 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20106 +       int ret;
20107 +
20108 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20109 +               return -EFAULT;
20110 +
20111 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20112 +               &vc_data.space_used, &vc_data.space_total,
20113 +               &vc_data.inodes_used, &vc_data.inodes_total,
20114 +               &vc_data.reserved, &vc_data.flags);
20115 +       if (ret)
20116 +               return ret;
20117 +
20118 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20119 +               return -EFAULT;
20120 +       return 0;
20121 +}
20122 +
20123 +#endif /* CONFIG_COMPAT */
20124 +
20125 +
20126 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20127 +{
20128 +       struct dl_info *dli;
20129 +       __u64 blimit, bfree, bavail;
20130 +       __u32 ifree;
20131 +
20132 +       dli = locate_dl_info(sb, dx_current_tag());
20133 +       if (!dli)
20134 +               return;
20135 +
20136 +       spin_lock(&dli->dl_lock);
20137 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20138 +               goto no_ilim;
20139 +
20140 +       /* reduce max inodes available to limit */
20141 +       if (buf->f_files > dli->dl_inodes_total)
20142 +               buf->f_files = dli->dl_inodes_total;
20143 +
20144 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20145 +       /* reduce free inodes to min */
20146 +       if (ifree < buf->f_ffree)
20147 +               buf->f_ffree = ifree;
20148 +
20149 +no_ilim:
20150 +       if (dli->dl_space_total == DLIM_INFINITY)
20151 +               goto no_blim;
20152 +
20153 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20154 +
20155 +       if (dli->dl_space_total < dli->dl_space_used)
20156 +               bfree = 0;
20157 +       else
20158 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20159 +                       >> sb->s_blocksize_bits;
20160 +
20161 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20162 +       if (bavail < dli->dl_space_used)
20163 +               bavail = 0;
20164 +       else
20165 +               bavail = (bavail - dli->dl_space_used)
20166 +                       >> sb->s_blocksize_bits;
20167 +
20168 +       /* reduce max space available to limit */
20169 +       if (buf->f_blocks > blimit)
20170 +               buf->f_blocks = blimit;
20171 +
20172 +       /* reduce free space to min */
20173 +       if (bfree < buf->f_bfree)
20174 +               buf->f_bfree = bfree;
20175 +
20176 +       /* reduce avail space to min */
20177 +       if (bavail < buf->f_bavail)
20178 +               buf->f_bavail = bavail;
20179 +
20180 +no_blim:
20181 +       spin_unlock(&dli->dl_lock);
20182 +       put_dl_info(dli);
20183 +
20184 +       return;
20185 +}
20186 +
20187 +#include <linux/module.h>
20188 +
20189 +EXPORT_SYMBOL_GPL(locate_dl_info);
20190 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20191 +
20192 diff -NurpP --minimal linux-2.6.32/kernel/vserver/helper.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/helper.c
20193 --- linux-2.6.32/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
20194 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/helper.c  2009-12-03 20:04:56.000000000 +0100
20195 @@ -0,0 +1,199 @@
20196 +/*
20197 + *  linux/kernel/vserver/helper.c
20198 + *
20199 + *  Virtual Context Support
20200 + *
20201 + *  Copyright (C) 2004-2007  Herbert Pötzl
20202 + *
20203 + *  V0.01  basic helper
20204 + *
20205 + */
20206 +
20207 +#include <linux/kmod.h>
20208 +#include <linux/reboot.h>
20209 +#include <linux/vs_context.h>
20210 +#include <linux/vs_network.h>
20211 +#include <linux/vserver/signal.h>
20212 +
20213 +
20214 +char vshelper_path[255] = "/sbin/vshelper";
20215 +
20216 +
20217 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20218 +{
20219 +       int ret;
20220 +
20221 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20222 +               printk( KERN_WARNING
20223 +                       "%s: (%s %s) returned %s with %d\n",
20224 +                       name, argv[1], argv[2],
20225 +                       sync ? "sync" : "async", ret);
20226 +       }
20227 +       vxdprintk(VXD_CBIT(switch, 4),
20228 +               "%s: (%s %s) returned %s with %d",
20229 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20230 +       return ret;
20231 +}
20232 +
20233 +/*
20234 + *      vshelper path is set via /proc/sys
20235 + *      invoked by vserver sys_reboot(), with
20236 + *      the following arguments
20237 + *
20238 + *      argv [0] = vshelper_path;
20239 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20240 + *      argv [2] = context identifier
20241 + *
20242 + *      envp [*] = type-specific parameters
20243 + */
20244 +
20245 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20246 +{
20247 +       char id_buf[8], cmd_buf[16];
20248 +       char uid_buf[16], pid_buf[16];
20249 +       int ret;
20250 +
20251 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20252 +       char *envp[] = {"HOME=/", "TERM=linux",
20253 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20254 +                       uid_buf, pid_buf, cmd_buf, 0};
20255 +
20256 +       if (vx_info_state(vxi, VXS_HELPER))
20257 +               return -EAGAIN;
20258 +       vxi->vx_state |= VXS_HELPER;
20259 +
20260 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20261 +
20262 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20263 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20264 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20265 +
20266 +       switch (cmd) {
20267 +       case LINUX_REBOOT_CMD_RESTART:
20268 +               argv[1] = "restart";
20269 +               break;
20270 +
20271 +       case LINUX_REBOOT_CMD_HALT:
20272 +               argv[1] = "halt";
20273 +               break;
20274 +
20275 +       case LINUX_REBOOT_CMD_POWER_OFF:
20276 +               argv[1] = "poweroff";
20277 +               break;
20278 +
20279 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20280 +               argv[1] = "swsusp";
20281 +               break;
20282 +
20283 +       default:
20284 +               vxi->vx_state &= ~VXS_HELPER;
20285 +               return 0;
20286 +       }
20287 +
20288 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20289 +       vxi->vx_state &= ~VXS_HELPER;
20290 +       __wakeup_vx_info(vxi);
20291 +       return (ret) ? -EPERM : 0;
20292 +}
20293 +
20294 +
20295 +long vs_reboot(unsigned int cmd, void __user *arg)
20296 +{
20297 +       struct vx_info *vxi = current_vx_info();
20298 +       long ret = 0;
20299 +
20300 +       vxdprintk(VXD_CBIT(misc, 5),
20301 +               "vs_reboot(%p[#%d],%d)",
20302 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20303 +
20304 +       ret = vs_reboot_helper(vxi, cmd, arg);
20305 +       if (ret)
20306 +               return ret;
20307 +
20308 +       vxi->reboot_cmd = cmd;
20309 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20310 +               switch (cmd) {
20311 +               case LINUX_REBOOT_CMD_RESTART:
20312 +               case LINUX_REBOOT_CMD_HALT:
20313 +               case LINUX_REBOOT_CMD_POWER_OFF:
20314 +                       vx_info_kill(vxi, 0, SIGKILL);
20315 +                       vx_info_kill(vxi, 1, SIGKILL);
20316 +               default:
20317 +                       break;
20318 +               }
20319 +       }
20320 +       return 0;
20321 +}
20322 +
20323 +
20324 +/*
20325 + *      argv [0] = vshelper_path;
20326 + *      argv [1] = action: "startup", "shutdown"
20327 + *      argv [2] = context identifier
20328 + *
20329 + *      envp [*] = type-specific parameters
20330 + */
20331 +
20332 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20333 +{
20334 +       char id_buf[8], cmd_buf[16];
20335 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20336 +       char *envp[] = {"HOME=/", "TERM=linux",
20337 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20338 +
20339 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20340 +               return 0;
20341 +
20342 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20343 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20344 +
20345 +       switch (cmd) {
20346 +       case VSC_STARTUP:
20347 +               argv[1] = "startup";
20348 +               break;
20349 +       case VSC_SHUTDOWN:
20350 +               argv[1] = "shutdown";
20351 +               break;
20352 +       default:
20353 +               return 0;
20354 +       }
20355 +
20356 +       return do_vshelper(vshelper_path, argv, envp, 1);
20357 +}
20358 +
20359 +
20360 +/*
20361 + *      argv [0] = vshelper_path;
20362 + *      argv [1] = action: "netup", "netdown"
20363 + *      argv [2] = context identifier
20364 + *
20365 + *      envp [*] = type-specific parameters
20366 + */
20367 +
20368 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20369 +{
20370 +       char id_buf[8], cmd_buf[16];
20371 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20372 +       char *envp[] = {"HOME=/", "TERM=linux",
20373 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20374 +
20375 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20376 +               return 0;
20377 +
20378 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20379 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20380 +
20381 +       switch (cmd) {
20382 +       case VSC_NETUP:
20383 +               argv[1] = "netup";
20384 +               break;
20385 +       case VSC_NETDOWN:
20386 +               argv[1] = "netdown";
20387 +               break;
20388 +       default:
20389 +               return 0;
20390 +       }
20391 +
20392 +       return do_vshelper(vshelper_path, argv, envp, 1);
20393 +}
20394 +
20395 diff -NurpP --minimal linux-2.6.32/kernel/vserver/history.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/history.c
20396 --- linux-2.6.32/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
20397 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/history.c 2009-12-03 20:04:56.000000000 +0100
20398 @@ -0,0 +1,258 @@
20399 +/*
20400 + *  kernel/vserver/history.c
20401 + *
20402 + *  Virtual Context History Backtrace
20403 + *
20404 + *  Copyright (C) 2004-2007  Herbert Pötzl
20405 + *
20406 + *  V0.01  basic structure
20407 + *  V0.02  hash/unhash and trace
20408 + *  V0.03  preemption fixes
20409 + *
20410 + */
20411 +
20412 +#include <linux/module.h>
20413 +#include <asm/uaccess.h>
20414 +
20415 +#include <linux/vserver/context.h>
20416 +#include <linux/vserver/debug.h>
20417 +#include <linux/vserver/debug_cmd.h>
20418 +#include <linux/vserver/history.h>
20419 +
20420 +
20421 +#ifdef CONFIG_VSERVER_HISTORY
20422 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20423 +#else
20424 +#define VXH_SIZE       64
20425 +#endif
20426 +
20427 +struct _vx_history {
20428 +       unsigned int counter;
20429 +
20430 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20431 +};
20432 +
20433 +
20434 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20435 +
20436 +unsigned volatile int vxh_active = 1;
20437 +
20438 +static atomic_t sequence = ATOMIC_INIT(0);
20439 +
20440 +
20441 +/*     vxh_advance()
20442 +
20443 +       * requires disabled preemption                          */
20444 +
20445 +struct _vx_hist_entry *vxh_advance(void *loc)
20446 +{
20447 +       unsigned int cpu = smp_processor_id();
20448 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20449 +       struct _vx_hist_entry *entry;
20450 +       unsigned int index;
20451 +
20452 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20453 +       entry = &hist->entry[index];
20454 +
20455 +       entry->seq = atomic_inc_return(&sequence);
20456 +       entry->loc = loc;
20457 +       return entry;
20458 +}
20459 +
20460 +EXPORT_SYMBOL_GPL(vxh_advance);
20461 +
20462 +
20463 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20464 +
20465 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20466 +
20467 +
20468 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20469 +
20470 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20471 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20472 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20473 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20474 +
20475 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20476 +{
20477 +       switch (e->type) {
20478 +       case VXH_THROW_OOPS:
20479 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20480 +               break;
20481 +
20482 +       case VXH_GET_VX_INFO:
20483 +       case VXH_PUT_VX_INFO:
20484 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20485 +                       VXH_LOC_ARGS(e),
20486 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20487 +                       VXH_VXI_ARGS(e));
20488 +               break;
20489 +
20490 +       case VXH_INIT_VX_INFO:
20491 +       case VXH_SET_VX_INFO:
20492 +       case VXH_CLR_VX_INFO:
20493 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20494 +                       VXH_LOC_ARGS(e),
20495 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20496 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20497 +                       VXH_VXI_ARGS(e), e->sc.data);
20498 +               break;
20499 +
20500 +       case VXH_CLAIM_VX_INFO:
20501 +       case VXH_RELEASE_VX_INFO:
20502 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20503 +                       VXH_LOC_ARGS(e),
20504 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20505 +                       VXH_VXI_ARGS(e), e->sc.data);
20506 +               break;
20507 +
20508 +       case VXH_ALLOC_VX_INFO:
20509 +       case VXH_DEALLOC_VX_INFO:
20510 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20511 +                       VXH_LOC_ARGS(e),
20512 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20513 +                       VXH_VXI_ARGS(e));
20514 +               break;
20515 +
20516 +       case VXH_HASH_VX_INFO:
20517 +       case VXH_UNHASH_VX_INFO:
20518 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20519 +                       VXH_LOC_ARGS(e),
20520 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20521 +                       VXH_VXI_ARGS(e));
20522 +               break;
20523 +
20524 +       case VXH_LOC_VX_INFO:
20525 +       case VXH_LOOKUP_VX_INFO:
20526 +       case VXH_CREATE_VX_INFO:
20527 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20528 +                       VXH_LOC_ARGS(e),
20529 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20530 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20531 +                       e->ll.arg, VXH_VXI_ARGS(e));
20532 +               break;
20533 +       }
20534 +}
20535 +
20536 +static void __vxh_dump_history(void)
20537 +{
20538 +       unsigned int i, cpu;
20539 +
20540 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20541 +               atomic_read(&sequence), NR_CPUS);
20542 +
20543 +       for (i = 0; i < VXH_SIZE; i++) {
20544 +               for_each_online_cpu(cpu) {
20545 +                       struct _vx_history *hist =
20546 +                               &per_cpu(vx_history_buffer, cpu);
20547 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20548 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20549 +
20550 +                       vxh_dump_entry(entry, cpu);
20551 +               }
20552 +       }
20553 +}
20554 +
20555 +void   vxh_dump_history(void)
20556 +{
20557 +       vxh_active = 0;
20558 +#ifdef CONFIG_SMP
20559 +       local_irq_enable();
20560 +       smp_send_stop();
20561 +       local_irq_disable();
20562 +#endif
20563 +       __vxh_dump_history();
20564 +}
20565 +
20566 +
20567 +/* vserver syscall commands below here */
20568 +
20569 +
20570 +int vc_dump_history(uint32_t id)
20571 +{
20572 +       vxh_active = 0;
20573 +       __vxh_dump_history();
20574 +       vxh_active = 1;
20575 +
20576 +       return 0;
20577 +}
20578 +
20579 +
20580 +int do_read_history(struct __user _vx_hist_entry *data,
20581 +       int cpu, uint32_t *index, uint32_t *count)
20582 +{
20583 +       int pos, ret = 0;
20584 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20585 +       int end = hist->counter;
20586 +       int start = end - VXH_SIZE + 2;
20587 +       int idx = *index;
20588 +
20589 +       /* special case: get current pos */
20590 +       if (!*count) {
20591 +               *index = end;
20592 +               return 0;
20593 +       }
20594 +
20595 +       /* have we lost some data? */
20596 +       if (idx < start)
20597 +               idx = start;
20598 +
20599 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20600 +               struct _vx_hist_entry *entry =
20601 +                       &hist->entry[idx % VXH_SIZE];
20602 +
20603 +               /* send entry to userspace */
20604 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20605 +               if (ret)
20606 +                       break;
20607 +       }
20608 +       /* save new index and count */
20609 +       *index = idx;
20610 +       *count = pos;
20611 +       return ret ? ret : (*index < end);
20612 +}
20613 +
20614 +int vc_read_history(uint32_t id, void __user *data)
20615 +{
20616 +       struct vcmd_read_history_v0 vc_data;
20617 +       int ret;
20618 +
20619 +       if (id >= NR_CPUS)
20620 +               return -EINVAL;
20621 +
20622 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20623 +               return -EFAULT;
20624 +
20625 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20626 +               id, &vc_data.index, &vc_data.count);
20627 +
20628 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20629 +               return -EFAULT;
20630 +       return ret;
20631 +}
20632 +
20633 +#ifdef CONFIG_COMPAT
20634 +
20635 +int vc_read_history_x32(uint32_t id, void __user *data)
20636 +{
20637 +       struct vcmd_read_history_v0_x32 vc_data;
20638 +       int ret;
20639 +
20640 +       if (id >= NR_CPUS)
20641 +               return -EINVAL;
20642 +
20643 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20644 +               return -EFAULT;
20645 +
20646 +       ret = do_read_history((struct __user _vx_hist_entry *)
20647 +               compat_ptr(vc_data.data_ptr),
20648 +               id, &vc_data.index, &vc_data.count);
20649 +
20650 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20651 +               return -EFAULT;
20652 +       return ret;
20653 +}
20654 +
20655 +#endif /* CONFIG_COMPAT */
20656 +
20657 diff -NurpP --minimal linux-2.6.32/kernel/vserver/inet.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/inet.c
20658 --- linux-2.6.32/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
20659 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/inet.c    2009-12-03 20:04:56.000000000 +0100
20660 @@ -0,0 +1,225 @@
20661 +
20662 +#include <linux/in.h>
20663 +#include <linux/inetdevice.h>
20664 +#include <linux/vs_inet.h>
20665 +#include <linux/vs_inet6.h>
20666 +#include <linux/vserver/debug.h>
20667 +#include <net/route.h>
20668 +#include <net/addrconf.h>
20669 +
20670 +
20671 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20672 +{
20673 +       int ret = 0;
20674 +
20675 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20676 +               ret = 1;
20677 +       else {
20678 +               struct nx_addr_v4 *ptr;
20679 +
20680 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20681 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20682 +                               ret = 1;
20683 +                               break;
20684 +                       }
20685 +               }
20686 +       }
20687 +
20688 +       vxdprintk(VXD_CBIT(net, 2),
20689 +               "nx_v4_addr_conflict(%p,%p): %d",
20690 +               nxi1, nxi2, ret);
20691 +
20692 +       return ret;
20693 +}
20694 +
20695 +
20696 +#ifdef CONFIG_IPV6
20697 +
20698 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20699 +{
20700 +       int ret = 0;
20701 +
20702 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20703 +               ret = 1;
20704 +       else {
20705 +               struct nx_addr_v6 *ptr;
20706 +
20707 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20708 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20709 +                               ret = 1;
20710 +                               break;
20711 +                       }
20712 +               }
20713 +       }
20714 +
20715 +       vxdprintk(VXD_CBIT(net, 2),
20716 +               "nx_v6_addr_conflict(%p,%p): %d",
20717 +               nxi1, nxi2, ret);
20718 +
20719 +       return ret;
20720 +}
20721 +
20722 +#endif
20723 +
20724 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20725 +{
20726 +       struct in_device *in_dev;
20727 +       struct in_ifaddr **ifap;
20728 +       struct in_ifaddr *ifa;
20729 +       int ret = 0;
20730 +
20731 +       if (!dev)
20732 +               goto out;
20733 +       in_dev = in_dev_get(dev);
20734 +       if (!in_dev)
20735 +               goto out;
20736 +
20737 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20738 +               ifap = &ifa->ifa_next) {
20739 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20740 +                       ret = 1;
20741 +                       break;
20742 +               }
20743 +       }
20744 +       in_dev_put(in_dev);
20745 +out:
20746 +       return ret;
20747 +}
20748 +
20749 +
20750 +#ifdef CONFIG_IPV6
20751 +
20752 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20753 +{
20754 +       struct inet6_dev *in_dev;
20755 +       struct inet6_ifaddr **ifap;
20756 +       struct inet6_ifaddr *ifa;
20757 +       int ret = 0;
20758 +
20759 +       if (!dev)
20760 +               goto out;
20761 +       in_dev = in6_dev_get(dev);
20762 +       if (!in_dev)
20763 +               goto out;
20764 +
20765 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20766 +               ifap = &ifa->if_next) {
20767 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20768 +                       ret = 1;
20769 +                       break;
20770 +               }
20771 +       }
20772 +       in6_dev_put(in_dev);
20773 +out:
20774 +       return ret;
20775 +}
20776 +
20777 +#endif
20778 +
20779 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20780 +{
20781 +       int ret = 1;
20782 +
20783 +       if (!nxi)
20784 +               goto out;
20785 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20786 +               goto out;
20787 +#ifdef CONFIG_IPV6
20788 +       ret = 2;
20789 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20790 +               goto out;
20791 +#endif
20792 +       ret = 0;
20793 +out:
20794 +       vxdprintk(VXD_CBIT(net, 3),
20795 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20796 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20797 +       return ret;
20798 +}
20799 +
20800 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20801 +       struct rtable **rp, struct flowi *fl)
20802 +{
20803 +       if (!nxi)
20804 +               return 0;
20805 +
20806 +       /* FIXME: handle lback only case */
20807 +       if (!NX_IPV4(nxi))
20808 +               return -EPERM;
20809 +
20810 +       vxdprintk(VXD_CBIT(net, 4),
20811 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20812 +               nxi, nxi ? nxi->nx_id : 0,
20813 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20814 +
20815 +       /* single IP is unconditional */
20816 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20817 +               (fl->fl4_src == INADDR_ANY))
20818 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20819 +
20820 +       if (fl->fl4_src == INADDR_ANY) {
20821 +               struct nx_addr_v4 *ptr;
20822 +               __be32 found = 0;
20823 +               int err;
20824 +
20825 +               err = __ip_route_output_key(net, rp, fl);
20826 +               if (!err) {
20827 +                       found = (*rp)->rt_src;
20828 +                       ip_rt_put(*rp);
20829 +                       vxdprintk(VXD_CBIT(net, 4),
20830 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20831 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20832 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20833 +                               goto found;
20834 +               }
20835 +
20836 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20837 +                       __be32 primary = ptr->ip[0].s_addr;
20838 +                       __be32 mask = ptr->mask.s_addr;
20839 +                       __be32 neta = primary & mask;
20840 +
20841 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20842 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20843 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20844 +                               NIPQUAD(mask), NIPQUAD(neta));
20845 +                       if ((found & mask) != neta)
20846 +                               continue;
20847 +
20848 +                       fl->fl4_src = primary;
20849 +                       err = __ip_route_output_key(net, rp, fl);
20850 +                       vxdprintk(VXD_CBIT(net, 4),
20851 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20852 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20853 +                       if (!err) {
20854 +                               found = (*rp)->rt_src;
20855 +                               ip_rt_put(*rp);
20856 +                               if (found == primary)
20857 +                                       goto found;
20858 +                       }
20859 +               }
20860 +               /* still no source ip? */
20861 +               found = ipv4_is_loopback(fl->fl4_dst)
20862 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20863 +       found:
20864 +               /* assign src ip to flow */
20865 +               fl->fl4_src = found;
20866 +
20867 +       } else {
20868 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20869 +                       return -EPERM;
20870 +       }
20871 +
20872 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20873 +               if (ipv4_is_loopback(fl->fl4_dst))
20874 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20875 +               if (ipv4_is_loopback(fl->fl4_src))
20876 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20877 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20878 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20879 +               return -EPERM;
20880 +
20881 +       return 0;
20882 +}
20883 +
20884 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20885 +
20886 diff -NurpP --minimal linux-2.6.32/kernel/vserver/init.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/init.c
20887 --- linux-2.6.32/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
20888 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/init.c    2009-12-03 20:04:56.000000000 +0100
20889 @@ -0,0 +1,45 @@
20890 +/*
20891 + *  linux/kernel/init.c
20892 + *
20893 + *  Virtual Server Init
20894 + *
20895 + *  Copyright (C) 2004-2007  Herbert Pötzl
20896 + *
20897 + *  V0.01  basic structure
20898 + *
20899 + */
20900 +
20901 +#include <linux/init.h>
20902 +
20903 +int    vserver_register_sysctl(void);
20904 +void   vserver_unregister_sysctl(void);
20905 +
20906 +
20907 +static int __init init_vserver(void)
20908 +{
20909 +       int ret = 0;
20910 +
20911 +#ifdef CONFIG_VSERVER_DEBUG
20912 +       vserver_register_sysctl();
20913 +#endif
20914 +       return ret;
20915 +}
20916 +
20917 +
20918 +static void __exit exit_vserver(void)
20919 +{
20920 +
20921 +#ifdef CONFIG_VSERVER_DEBUG
20922 +       vserver_unregister_sysctl();
20923 +#endif
20924 +       return;
20925 +}
20926 +
20927 +/* FIXME: GFP_ZONETYPES gone
20928 +long vx_slab[GFP_ZONETYPES]; */
20929 +long vx_area;
20930 +
20931 +
20932 +module_init(init_vserver);
20933 +module_exit(exit_vserver);
20934 +
20935 diff -NurpP --minimal linux-2.6.32/kernel/vserver/inode.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/inode.c
20936 --- linux-2.6.32/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
20937 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/inode.c   2009-12-03 20:04:56.000000000 +0100
20938 @@ -0,0 +1,433 @@
20939 +/*
20940 + *  linux/kernel/vserver/inode.c
20941 + *
20942 + *  Virtual Server: File System Support
20943 + *
20944 + *  Copyright (C) 2004-2007  Herbert Pötzl
20945 + *
20946 + *  V0.01  separated from vcontext V0.05
20947 + *  V0.02  moved to tag (instead of xid)
20948 + *
20949 + */
20950 +
20951 +#include <linux/tty.h>
20952 +#include <linux/proc_fs.h>
20953 +#include <linux/devpts_fs.h>
20954 +#include <linux/fs.h>
20955 +#include <linux/file.h>
20956 +#include <linux/mount.h>
20957 +#include <linux/parser.h>
20958 +#include <linux/namei.h>
20959 +#include <linux/vserver/inode.h>
20960 +#include <linux/vserver/inode_cmd.h>
20961 +#include <linux/vs_base.h>
20962 +#include <linux/vs_tag.h>
20963 +
20964 +#include <asm/uaccess.h>
20965 +
20966 +
20967 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20968 +{
20969 +       struct proc_dir_entry *entry;
20970 +
20971 +       if (!in || !in->i_sb)
20972 +               return -ESRCH;
20973 +
20974 +       *flags = IATTR_TAG
20975 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
20976 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20977 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20978 +               | (IS_COW(in) ? IATTR_COW : 0);
20979 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
20980 +
20981 +       if (S_ISDIR(in->i_mode))
20982 +               *mask |= IATTR_BARRIER;
20983 +
20984 +       if (IS_TAGGED(in)) {
20985 +               *tag = in->i_tag;
20986 +               *mask |= IATTR_TAG;
20987 +       }
20988 +
20989 +       switch (in->i_sb->s_magic) {
20990 +       case PROC_SUPER_MAGIC:
20991 +               entry = PROC_I(in)->pde;
20992 +
20993 +               /* check for specific inodes? */
20994 +               if (entry)
20995 +                       *mask |= IATTR_FLAGS;
20996 +               if (entry)
20997 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20998 +               else
20999 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21000 +               break;
21001 +
21002 +       case DEVPTS_SUPER_MAGIC:
21003 +               *tag = in->i_tag;
21004 +               *mask |= IATTR_TAG;
21005 +               break;
21006 +
21007 +       default:
21008 +               break;
21009 +       }
21010 +       return 0;
21011 +}
21012 +
21013 +int vc_get_iattr(void __user *data)
21014 +{
21015 +       struct path path;
21016 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21017 +       int ret;
21018 +
21019 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21020 +               return -EFAULT;
21021 +
21022 +       ret = user_lpath(vc_data.name, &path);
21023 +       if (!ret) {
21024 +               ret = __vc_get_iattr(path.dentry->d_inode,
21025 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21026 +               path_put(&path);
21027 +       }
21028 +       if (ret)
21029 +               return ret;
21030 +
21031 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21032 +               ret = -EFAULT;
21033 +       return ret;
21034 +}
21035 +
21036 +#ifdef CONFIG_COMPAT
21037 +
21038 +int vc_get_iattr_x32(void __user *data)
21039 +{
21040 +       struct path path;
21041 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21042 +       int ret;
21043 +
21044 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21045 +               return -EFAULT;
21046 +
21047 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21048 +       if (!ret) {
21049 +               ret = __vc_get_iattr(path.dentry->d_inode,
21050 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21051 +               path_put(&path);
21052 +       }
21053 +       if (ret)
21054 +               return ret;
21055 +
21056 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21057 +               ret = -EFAULT;
21058 +       return ret;
21059 +}
21060 +
21061 +#endif /* CONFIG_COMPAT */
21062 +
21063 +
21064 +int vc_fget_iattr(uint32_t fd, void __user *data)
21065 +{
21066 +       struct file *filp;
21067 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21068 +       int ret;
21069 +
21070 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21071 +               return -EFAULT;
21072 +
21073 +       filp = fget(fd);
21074 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21075 +               return -EBADF;
21076 +
21077 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21078 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21079 +
21080 +       fput(filp);
21081 +
21082 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21083 +               ret = -EFAULT;
21084 +       return ret;
21085 +}
21086 +
21087 +
21088 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21089 +{
21090 +       struct inode *in = de->d_inode;
21091 +       int error = 0, is_proc = 0, has_tag = 0;
21092 +       struct iattr attr = { 0 };
21093 +
21094 +       if (!in || !in->i_sb)
21095 +               return -ESRCH;
21096 +
21097 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21098 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21099 +               return -EINVAL;
21100 +
21101 +       has_tag = IS_TAGGED(in) ||
21102 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21103 +       if ((*mask & IATTR_TAG) && !has_tag)
21104 +               return -EINVAL;
21105 +
21106 +       mutex_lock(&in->i_mutex);
21107 +       if (*mask & IATTR_TAG) {
21108 +               attr.ia_tag = *tag;
21109 +               attr.ia_valid |= ATTR_TAG;
21110 +       }
21111 +
21112 +       if (*mask & IATTR_FLAGS) {
21113 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21114 +               unsigned int iflags = PROC_I(in)->vx_flags;
21115 +
21116 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21117 +                       | (*flags & IATTR_FLAGS);
21118 +               PROC_I(in)->vx_flags = iflags;
21119 +               if (entry)
21120 +                       entry->vx_flags = iflags;
21121 +       }
21122 +
21123 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21124 +               IATTR_BARRIER | IATTR_COW)) {
21125 +               int iflags = in->i_flags;
21126 +               int vflags = in->i_vflags;
21127 +
21128 +               if (*mask & IATTR_IMMUTABLE) {
21129 +                       if (*flags & IATTR_IMMUTABLE)
21130 +                               iflags |= S_IMMUTABLE;
21131 +                       else
21132 +                               iflags &= ~S_IMMUTABLE;
21133 +               }
21134 +               if (*mask & IATTR_IXUNLINK) {
21135 +                       if (*flags & IATTR_IXUNLINK)
21136 +                               iflags |= S_IXUNLINK;
21137 +                       else
21138 +                               iflags &= ~S_IXUNLINK;
21139 +               }
21140 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21141 +                       if (*flags & IATTR_BARRIER)
21142 +                               vflags |= V_BARRIER;
21143 +                       else
21144 +                               vflags &= ~V_BARRIER;
21145 +               }
21146 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21147 +                       if (*flags & IATTR_COW)
21148 +                               vflags |= V_COW;
21149 +                       else
21150 +                               vflags &= ~V_COW;
21151 +               }
21152 +               if (in->i_op && in->i_op->sync_flags) {
21153 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21154 +                       if (error)
21155 +                               goto out;
21156 +               }
21157 +       }
21158 +
21159 +       if (attr.ia_valid) {
21160 +               if (in->i_op && in->i_op->setattr)
21161 +                       error = in->i_op->setattr(de, &attr);
21162 +               else {
21163 +                       error = inode_change_ok(in, &attr);
21164 +                       if (!error)
21165 +                               error = inode_setattr(in, &attr);
21166 +               }
21167 +       }
21168 +
21169 +out:
21170 +       mutex_unlock(&in->i_mutex);
21171 +       return error;
21172 +}
21173 +
21174 +int vc_set_iattr(void __user *data)
21175 +{
21176 +       struct path path;
21177 +       struct vcmd_ctx_iattr_v1 vc_data;
21178 +       int ret;
21179 +
21180 +       if (!capable(CAP_LINUX_IMMUTABLE))
21181 +               return -EPERM;
21182 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21183 +               return -EFAULT;
21184 +
21185 +       ret = user_lpath(vc_data.name, &path);
21186 +       if (!ret) {
21187 +               ret = __vc_set_iattr(path.dentry,
21188 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21189 +               path_put(&path);
21190 +       }
21191 +
21192 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21193 +               ret = -EFAULT;
21194 +       return ret;
21195 +}
21196 +
21197 +#ifdef CONFIG_COMPAT
21198 +
21199 +int vc_set_iattr_x32(void __user *data)
21200 +{
21201 +       struct path path;
21202 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21203 +       int ret;
21204 +
21205 +       if (!capable(CAP_LINUX_IMMUTABLE))
21206 +               return -EPERM;
21207 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21208 +               return -EFAULT;
21209 +
21210 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21211 +       if (!ret) {
21212 +               ret = __vc_set_iattr(path.dentry,
21213 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21214 +               path_put(&path);
21215 +       }
21216 +
21217 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21218 +               ret = -EFAULT;
21219 +       return ret;
21220 +}
21221 +
21222 +#endif /* CONFIG_COMPAT */
21223 +
21224 +int vc_fset_iattr(uint32_t fd, void __user *data)
21225 +{
21226 +       struct file *filp;
21227 +       struct vcmd_ctx_fiattr_v0 vc_data;
21228 +       int ret;
21229 +
21230 +       if (!capable(CAP_LINUX_IMMUTABLE))
21231 +               return -EPERM;
21232 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21233 +               return -EFAULT;
21234 +
21235 +       filp = fget(fd);
21236 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21237 +               return -EBADF;
21238 +
21239 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21240 +               &vc_data.flags, &vc_data.mask);
21241 +
21242 +       fput(filp);
21243 +
21244 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21245 +               return -EFAULT;
21246 +       return ret;
21247 +}
21248 +
21249 +
21250 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21251 +
21252 +static match_table_t tokens = {
21253 +       {Opt_notagcheck, "notagcheck"},
21254 +#ifdef CONFIG_PROPAGATE
21255 +       {Opt_notag, "notag"},
21256 +       {Opt_tag, "tag"},
21257 +       {Opt_tagid, "tagid=%u"},
21258 +#endif
21259 +       {Opt_err, NULL}
21260 +};
21261 +
21262 +
21263 +static void __dx_parse_remove(char *string, char *opt)
21264 +{
21265 +       char *p = strstr(string, opt);
21266 +       char *q = p;
21267 +
21268 +       if (p) {
21269 +               while (*q != '\0' && *q != ',')
21270 +                       q++;
21271 +               while (*q)
21272 +                       *p++ = *q++;
21273 +               while (*p)
21274 +                       *p++ = '\0';
21275 +       }
21276 +}
21277 +
21278 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21279 +                unsigned long *flags)
21280 +{
21281 +       int set = 0;
21282 +       substring_t args[MAX_OPT_ARGS];
21283 +       int token, option = 0;
21284 +       char *s, *p, *opts;
21285 +
21286 +       if (!string)
21287 +               return 0;
21288 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21289 +       if (!s)
21290 +               return 0;
21291 +
21292 +       opts = s;
21293 +       while ((p = strsep(&opts, ",")) != NULL) {
21294 +               token = match_token(p, tokens, args);
21295 +
21296 +               vxdprintk(VXD_CBIT(tag, 7),
21297 +                       "dx_parse_tag(»%s«): %d:#%d",
21298 +                       p, token, option);
21299 +
21300 +               switch (token) {
21301 +#ifdef CONFIG_PROPAGATE
21302 +               case Opt_tag:
21303 +                       if (tag)
21304 +                               *tag = 0;
21305 +                       if (remove)
21306 +                               __dx_parse_remove(s, "tag");
21307 +                       *mnt_flags |= MNT_TAGID;
21308 +                       set |= MNT_TAGID;
21309 +                       break;
21310 +               case Opt_notag:
21311 +                       if (remove)
21312 +                               __dx_parse_remove(s, "notag");
21313 +                       *mnt_flags |= MNT_NOTAG;
21314 +                       set |= MNT_NOTAG;
21315 +                       break;
21316 +               case Opt_tagid:
21317 +                       if (tag && !match_int(args, &option))
21318 +                               *tag = option;
21319 +                       if (remove)
21320 +                               __dx_parse_remove(s, "tagid");
21321 +                       *mnt_flags |= MNT_TAGID;
21322 +                       set |= MNT_TAGID;
21323 +                       break;
21324 +#endif
21325 +               case Opt_notagcheck:
21326 +                       if (remove)
21327 +                               __dx_parse_remove(s, "notagcheck");
21328 +                       *flags |= MS_NOTAGCHECK;
21329 +                       set |= MS_NOTAGCHECK;
21330 +                       break;
21331 +               }
21332 +       }
21333 +       if (set)
21334 +               strcpy(string, s);
21335 +       kfree(s);
21336 +       return set;
21337 +}
21338 +
21339 +#ifdef CONFIG_PROPAGATE
21340 +
21341 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21342 +{
21343 +       tag_t new_tag = 0;
21344 +       struct vfsmount *mnt;
21345 +       int propagate;
21346 +
21347 +       if (!nd)
21348 +               return;
21349 +       mnt = nd->path.mnt;
21350 +       if (!mnt)
21351 +               return;
21352 +
21353 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21354 +       if (propagate)
21355 +               new_tag = mnt->mnt_tag;
21356 +
21357 +       vxdprintk(VXD_CBIT(tag, 7),
21358 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21359 +               inode, inode->i_ino, inode->i_tag,
21360 +               new_tag, (propagate) ? 1 : 0);
21361 +
21362 +       if (propagate)
21363 +               inode->i_tag = new_tag;
21364 +}
21365 +
21366 +#include <linux/module.h>
21367 +
21368 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21369 +
21370 +#endif /* CONFIG_PROPAGATE */
21371 +
21372 diff -NurpP --minimal linux-2.6.32/kernel/vserver/Kconfig linux-2.6.32-vs2.3.0.36.26/kernel/vserver/Kconfig
21373 --- linux-2.6.32/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
21374 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/Kconfig   2009-12-03 20:04:56.000000000 +0100
21375 @@ -0,0 +1,251 @@
21376 +#
21377 +# Linux VServer configuration
21378 +#
21379 +
21380 +menu "Linux VServer"
21381 +
21382 +config VSERVER_AUTO_LBACK
21383 +       bool    "Automatically Assign Loopback IP"
21384 +       default y
21385 +       help
21386 +         Automatically assign a guest specific loopback
21387 +         IP and add it to the kernel network stack on
21388 +         startup.
21389 +
21390 +config VSERVER_AUTO_SINGLE
21391 +       bool    "Automatic Single IP Special Casing"
21392 +       depends on EXPERIMENTAL
21393 +       default y
21394 +       help
21395 +         This allows network contexts with a single IP to
21396 +         automatically remap 0.0.0.0 bindings to that IP,
21397 +         avoiding further network checks and improving
21398 +         performance.
21399 +
21400 +         (note: such guests do not allow to change the ip
21401 +          on the fly and do not show loopback addresses)
21402 +
21403 +config VSERVER_COWBL
21404 +       bool    "Enable COW Immutable Link Breaking"
21405 +       default y
21406 +       help
21407 +         This enables the COW (Copy-On-Write) link break code.
21408 +         It allows you to treat unified files like normal files
21409 +         when writing to them (which will implicitely break the
21410 +         link and create a copy of the unified file)
21411 +
21412 +config VSERVER_VTIME
21413 +       bool    "Enable Virtualized Guest Time"
21414 +       depends on EXPERIMENTAL
21415 +       default n
21416 +       help
21417 +         This enables per guest time offsets to allow for
21418 +         adjusting the system clock individually per guest.
21419 +         this adds some overhead to the time functions and
21420 +         therefore should not be enabled without good reason.
21421 +
21422 +config VSERVER_DEVICE
21423 +       bool    "Enable Guest Device Mapping"
21424 +       depends on EXPERIMENTAL
21425 +       default n
21426 +       help
21427 +         This enables generic device remapping.
21428 +
21429 +config VSERVER_PROC_SECURE
21430 +       bool    "Enable Proc Security"
21431 +       depends on PROC_FS
21432 +       default y
21433 +       help
21434 +         This configures ProcFS security to initially hide
21435 +         non-process entries for all contexts except the main and
21436 +         spectator context (i.e. for all guests), which is a secure
21437 +         default.
21438 +
21439 +         (note: on 1.2x the entries were visible by default)
21440 +
21441 +config VSERVER_HARDCPU
21442 +       bool    "Enable Hard CPU Limits"
21443 +       default y
21444 +       help
21445 +         Activate the Hard CPU Limits
21446 +
21447 +         This will compile in code that allows the Token Bucket
21448 +         Scheduler to put processes on hold when a context's
21449 +         tokens are depleted (provided that its per-context
21450 +         sched_hard flag is set).
21451 +
21452 +         Processes belonging to that context will not be able
21453 +         to consume CPU resources again until a per-context
21454 +         configured minimum of tokens has been reached.
21455 +
21456 +config VSERVER_IDLETIME
21457 +       bool    "Avoid idle CPUs by skipping Time"
21458 +       depends on VSERVER_HARDCPU
21459 +       default y
21460 +       help
21461 +         This option allows the scheduler to artificially
21462 +         advance time (per cpu) when otherwise the idle
21463 +         task would be scheduled, thus keeping the cpu
21464 +         busy and sharing the available resources among
21465 +         certain contexts.
21466 +
21467 +config VSERVER_IDLELIMIT
21468 +       bool    "Limit the IDLE task"
21469 +       depends on VSERVER_HARDCPU
21470 +       default n
21471 +       help
21472 +         Limit the idle slices, so the the next context
21473 +         will be scheduled as soon as possible.
21474 +
21475 +         This might improve interactivity and latency, but
21476 +         will also marginally increase scheduling overhead.
21477 +
21478 +choice
21479 +       prompt  "Persistent Inode Tagging"
21480 +       default TAGGING_ID24
21481 +       help
21482 +         This adds persistent context information to filesystems
21483 +         mounted with the tagxid option. Tagging is a requirement
21484 +         for per-context disk limits and per-context quota.
21485 +
21486 +
21487 +config TAGGING_NONE
21488 +       bool    "Disabled"
21489 +       help
21490 +         do not store per-context information in inodes.
21491 +
21492 +config TAGGING_UID16
21493 +       bool    "UID16/GID32"
21494 +       help
21495 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21496 +
21497 +config TAGGING_GID16
21498 +       bool    "UID32/GID16"
21499 +       help
21500 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21501 +
21502 +config TAGGING_ID24
21503 +       bool    "UID24/GID24"
21504 +       help
21505 +         uses the upper 8bit from UID and GID for XID tagging
21506 +         which leaves 24bit for UID/GID each, which should be
21507 +         more than sufficient for normal use.
21508 +
21509 +config TAGGING_INTERN
21510 +       bool    "UID32/GID32"
21511 +       help
21512 +         this uses otherwise reserved inode fields in the on
21513 +         disk representation, which limits the use to a few
21514 +         filesystems (currently ext2 and ext3)
21515 +
21516 +endchoice
21517 +
21518 +config TAG_NFSD
21519 +       bool    "Tag NFSD User Auth and Files"
21520 +       default n
21521 +       help
21522 +         Enable this if you do want the in-kernel NFS
21523 +         Server to use the tagging specified above.
21524 +         (will require patched clients too)
21525 +
21526 +config VSERVER_PRIVACY
21527 +       bool    "Honor Privacy Aspects of Guests"
21528 +       default n
21529 +       help
21530 +         When enabled, most context checks will disallow
21531 +         access to structures assigned to a specific context,
21532 +         like ptys or loop devices.
21533 +
21534 +config VSERVER_CONTEXTS
21535 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21536 +       range 1 65533
21537 +       default "768"   if 64BIT
21538 +       default "256"
21539 +       help
21540 +         This setting will optimize certain data structures
21541 +         and memory allocations according to the expected
21542 +         maximum.
21543 +
21544 +         note: this is not a strict upper limit.
21545 +
21546 +config VSERVER_WARN
21547 +       bool    "VServer Warnings"
21548 +       default y
21549 +       help
21550 +         This enables various runtime warnings, which will
21551 +         notify about potential manipulation attempts or
21552 +         resource shortage. It is generally considered to
21553 +         be a good idea to have that enabled.
21554 +
21555 +config VSERVER_DEBUG
21556 +       bool    "VServer Debugging Code"
21557 +       default n
21558 +       help
21559 +         Set this to yes if you want to be able to activate
21560 +         debugging output at runtime. It adds a very small
21561 +         overhead to all vserver related functions and
21562 +         increases the kernel size by about 20k.
21563 +
21564 +config VSERVER_HISTORY
21565 +       bool    "VServer History Tracing"
21566 +       depends on VSERVER_DEBUG
21567 +       default n
21568 +       help
21569 +         Set this to yes if you want to record the history of
21570 +         linux-vserver activities, so they can be replayed in
21571 +         the event of a kernel panic or oops.
21572 +
21573 +config VSERVER_HISTORY_SIZE
21574 +       int     "Per-CPU History Size (32-65536)"
21575 +       depends on VSERVER_HISTORY
21576 +       range 32 65536
21577 +       default 64
21578 +       help
21579 +         This allows you to specify the number of entries in
21580 +         the per-CPU history buffer.
21581 +
21582 +config VSERVER_MONITOR
21583 +       bool    "VServer Scheduling Monitor"
21584 +       depends on VSERVER_DISABLED
21585 +       default n
21586 +       help
21587 +         Set this to yes if you want to record the scheduling
21588 +         decisions, so that they can be relayed to userspace
21589 +         for detailed analysis.
21590 +
21591 +config VSERVER_MONITOR_SIZE
21592 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21593 +       depends on VSERVER_MONITOR
21594 +       range 32 65536
21595 +       default 1024
21596 +       help
21597 +         This allows you to specify the number of entries in
21598 +         the per-CPU scheduling monitor buffer.
21599 +
21600 +config VSERVER_MONITOR_SYNC
21601 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21602 +       depends on VSERVER_MONITOR
21603 +       range 0 65536
21604 +       default 256
21605 +       help
21606 +         This allows you to specify the interval in ticks
21607 +         when a time sync entry is inserted.
21608 +
21609 +endmenu
21610 +
21611 +
21612 +config VSERVER
21613 +       bool
21614 +       default y
21615 +       select NAMESPACES
21616 +       select UTS_NS
21617 +       select IPC_NS
21618 +       select USER_NS
21619 +       select SYSVIPC
21620 +
21621 +config VSERVER_SECURITY
21622 +       bool
21623 +       depends on SECURITY
21624 +       default y
21625 +       select SECURITY_CAPABILITIES
21626 +
21627 diff -NurpP --minimal linux-2.6.32/kernel/vserver/limit.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/limit.c
21628 --- linux-2.6.32/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
21629 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/limit.c   2009-12-03 20:04:56.000000000 +0100
21630 @@ -0,0 +1,333 @@
21631 +/*
21632 + *  linux/kernel/vserver/limit.c
21633 + *
21634 + *  Virtual Server: Context Limits
21635 + *
21636 + *  Copyright (C) 2004-2007  Herbert Pötzl
21637 + *
21638 + *  V0.01  broken out from vcontext V0.05
21639 + *  V0.02  changed vcmds to vxi arg
21640 + *
21641 + */
21642 +
21643 +#include <linux/sched.h>
21644 +#include <linux/module.h>
21645 +#include <linux/vs_limit.h>
21646 +#include <linux/vserver/limit.h>
21647 +#include <linux/vserver/limit_cmd.h>
21648 +
21649 +#include <asm/uaccess.h>
21650 +
21651 +
21652 +const char *vlimit_name[NUM_LIMITS] = {
21653 +       [RLIMIT_CPU]            = "CPU",
21654 +       [RLIMIT_RSS]            = "RSS",
21655 +       [RLIMIT_NPROC]          = "NPROC",
21656 +       [RLIMIT_NOFILE]         = "NOFILE",
21657 +       [RLIMIT_MEMLOCK]        = "VML",
21658 +       [RLIMIT_AS]             = "VM",
21659 +       [RLIMIT_LOCKS]          = "LOCKS",
21660 +       [RLIMIT_SIGPENDING]     = "SIGP",
21661 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21662 +
21663 +       [VLIMIT_NSOCK]          = "NSOCK",
21664 +       [VLIMIT_OPENFD]         = "OPENFD",
21665 +       [VLIMIT_ANON]           = "ANON",
21666 +       [VLIMIT_SHMEM]          = "SHMEM",
21667 +       [VLIMIT_DENTRY]         = "DENTRY",
21668 +};
21669 +
21670 +EXPORT_SYMBOL_GPL(vlimit_name);
21671 +
21672 +#define MASK_ENTRY(x)  (1 << (x))
21673 +
21674 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21675 +               /* minimum */
21676 +       0
21677 +       ,       /* softlimit */
21678 +       MASK_ENTRY( RLIMIT_RSS          ) |
21679 +       MASK_ENTRY( VLIMIT_ANON         ) |
21680 +       0
21681 +       ,       /* maximum */
21682 +       MASK_ENTRY( RLIMIT_RSS          ) |
21683 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21684 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21685 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21686 +       MASK_ENTRY( RLIMIT_AS           ) |
21687 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21688 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21689 +
21690 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21691 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21692 +       MASK_ENTRY( VLIMIT_ANON         ) |
21693 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21694 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21695 +       0
21696 +};
21697 +               /* accounting only */
21698 +uint32_t account_mask =
21699 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21700 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21701 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21702 +       0;
21703 +
21704 +
21705 +static int is_valid_vlimit(int id)
21706 +{
21707 +       uint32_t mask = vlimit_mask.minimum |
21708 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21709 +       return mask & (1 << id);
21710 +}
21711 +
21712 +static int is_accounted_vlimit(int id)
21713 +{
21714 +       if (is_valid_vlimit(id))
21715 +               return 1;
21716 +       return account_mask & (1 << id);
21717 +}
21718 +
21719 +
21720 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21721 +{
21722 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21723 +       return VX_VLIM(limit);
21724 +}
21725 +
21726 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21727 +{
21728 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21729 +       return VX_VLIM(limit);
21730 +}
21731 +
21732 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21733 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21734 +{
21735 +       if (!is_valid_vlimit(id))
21736 +               return -EINVAL;
21737 +
21738 +       if (minimum)
21739 +               *minimum = CRLIM_UNSET;
21740 +       if (softlimit)
21741 +               *softlimit = vc_get_soft(vxi, id);
21742 +       if (maximum)
21743 +               *maximum = vc_get_hard(vxi, id);
21744 +       return 0;
21745 +}
21746 +
21747 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21748 +{
21749 +       struct vcmd_ctx_rlimit_v0 vc_data;
21750 +       int ret;
21751 +
21752 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21753 +               return -EFAULT;
21754 +
21755 +       ret = do_get_rlimit(vxi, vc_data.id,
21756 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21757 +       if (ret)
21758 +               return ret;
21759 +
21760 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21761 +               return -EFAULT;
21762 +       return 0;
21763 +}
21764 +
21765 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21766 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21767 +{
21768 +       if (!is_valid_vlimit(id))
21769 +               return -EINVAL;
21770 +
21771 +       if (maximum != CRLIM_KEEP)
21772 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21773 +       if (softlimit != CRLIM_KEEP)
21774 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21775 +
21776 +       /* clamp soft limit */
21777 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21778 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21779 +
21780 +       return 0;
21781 +}
21782 +
21783 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21784 +{
21785 +       struct vcmd_ctx_rlimit_v0 vc_data;
21786 +
21787 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21788 +               return -EFAULT;
21789 +
21790 +       return do_set_rlimit(vxi, vc_data.id,
21791 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21792 +}
21793 +
21794 +#ifdef CONFIG_IA32_EMULATION
21795 +
21796 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21797 +{
21798 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21799 +
21800 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21801 +               return -EFAULT;
21802 +
21803 +       return do_set_rlimit(vxi, vc_data.id,
21804 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21805 +}
21806 +
21807 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21808 +{
21809 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21810 +       int ret;
21811 +
21812 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21813 +               return -EFAULT;
21814 +
21815 +       ret = do_get_rlimit(vxi, vc_data.id,
21816 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21817 +       if (ret)
21818 +               return ret;
21819 +
21820 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21821 +               return -EFAULT;
21822 +       return 0;
21823 +}
21824 +
21825 +#endif /* CONFIG_IA32_EMULATION */
21826 +
21827 +
21828 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21829 +{
21830 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21831 +               return -EFAULT;
21832 +       return 0;
21833 +}
21834 +
21835 +
21836 +static inline void vx_reset_hits(struct _vx_limit *limit)
21837 +{
21838 +       int lim;
21839 +
21840 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21841 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21842 +       }
21843 +}
21844 +
21845 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21846 +{
21847 +       vx_reset_hits(&vxi->limit);
21848 +       return 0;
21849 +}
21850 +
21851 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21852 +{
21853 +       rlim_t value;
21854 +       int lim;
21855 +
21856 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21857 +               value = __rlim_get(limit, lim);
21858 +               __rlim_rmax(limit, lim) = value;
21859 +               __rlim_rmin(limit, lim) = value;
21860 +       }
21861 +}
21862 +
21863 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21864 +{
21865 +       vx_reset_minmax(&vxi->limit);
21866 +       return 0;
21867 +}
21868 +
21869 +
21870 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21871 +{
21872 +       struct vcmd_rlimit_stat_v0 vc_data;
21873 +       struct _vx_limit *limit = &vxi->limit;
21874 +       int id;
21875 +
21876 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21877 +               return -EFAULT;
21878 +
21879 +       id = vc_data.id;
21880 +       if (!is_accounted_vlimit(id))
21881 +               return -EINVAL;
21882 +
21883 +       vx_limit_fixup(limit, id);
21884 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21885 +       vc_data.value = __rlim_get(limit, id);
21886 +       vc_data.minimum = __rlim_rmin(limit, id);
21887 +       vc_data.maximum = __rlim_rmax(limit, id);
21888 +
21889 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21890 +               return -EFAULT;
21891 +       return 0;
21892 +}
21893 +
21894 +
21895 +void vx_vsi_meminfo(struct sysinfo *val)
21896 +{
21897 +       struct vx_info *vxi = current_vx_info();
21898 +       unsigned long totalram, freeram;
21899 +       rlim_t v;
21900 +
21901 +       /* we blindly accept the max */
21902 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21903 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21904 +
21905 +       /* total minus used equals free */
21906 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21907 +       freeram = (v < totalram) ? totalram - v : 0;
21908 +
21909 +       val->totalram = totalram;
21910 +       val->freeram = freeram;
21911 +       val->bufferram = 0;
21912 +       val->totalhigh = 0;
21913 +       val->freehigh = 0;
21914 +       return;
21915 +}
21916 +
21917 +void vx_vsi_swapinfo(struct sysinfo *val)
21918 +{
21919 +       struct vx_info *vxi = current_vx_info();
21920 +       unsigned long totalswap, freeswap;
21921 +       rlim_t v, w;
21922 +
21923 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21924 +       if (v == RLIM_INFINITY) {
21925 +               val->freeswap = val->totalswap;
21926 +               return;
21927 +       }
21928 +
21929 +       /* we blindly accept the max */
21930 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21931 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21932 +
21933 +       /* currently 'used' swap */
21934 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21935 +       w -= (w > v) ? v : w;
21936 +
21937 +       /* total minus used equals free */
21938 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21939 +
21940 +       val->totalswap = totalswap;
21941 +       val->freeswap = freeswap;
21942 +       return;
21943 +}
21944 +
21945 +
21946 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21947 +{
21948 +       struct vx_info *vxi = mm->mm_vx_info;
21949 +       unsigned long points;
21950 +       rlim_t v, w;
21951 +
21952 +       if (!vxi)
21953 +               return 0;
21954 +
21955 +       points = vxi->vx_badness_bias;
21956 +
21957 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21958 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21959 +       points += (v > w) ? (v - w) : 0;
21960 +
21961 +       return points;
21962 +}
21963 +
21964 diff -NurpP --minimal linux-2.6.32/kernel/vserver/limit_init.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/limit_init.h
21965 --- linux-2.6.32/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
21966 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/limit_init.h      2009-12-03 20:04:56.000000000 +0100
21967 @@ -0,0 +1,31 @@
21968 +
21969 +
21970 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21971 +{
21972 +       int lim;
21973 +
21974 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21975 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21976 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21977 +               __rlim_set(limit, lim, 0);
21978 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21979 +               __rlim_rmin(limit, lim) = 0;
21980 +               __rlim_rmax(limit, lim) = 0;
21981 +       }
21982 +}
21983 +
21984 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21985 +{
21986 +       rlim_t value;
21987 +       int lim;
21988 +
21989 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21990 +               if ((1 << lim) & VLIM_NOCHECK)
21991 +                       continue;
21992 +               value = __rlim_get(limit, lim);
21993 +               vxwprintk_xid(value,
21994 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21995 +                       limit, vlimit_name[lim], lim, (long)value);
21996 +       }
21997 +}
21998 +
21999 diff -NurpP --minimal linux-2.6.32/kernel/vserver/limit_proc.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/limit_proc.h
22000 --- linux-2.6.32/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
22001 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/limit_proc.h      2009-12-03 20:04:56.000000000 +0100
22002 @@ -0,0 +1,57 @@
22003 +#ifndef _VX_LIMIT_PROC_H
22004 +#define _VX_LIMIT_PROC_H
22005 +
22006 +#include <linux/vserver/limit_int.h>
22007 +
22008 +
22009 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22010 +#define VX_LIMIT_TOP   \
22011 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22012 +
22013 +#define VX_LIMIT_ARG(r)                                \
22014 +       (unsigned long)__rlim_get(limit, r),    \
22015 +       (unsigned long)__rlim_rmin(limit, r),   \
22016 +       (unsigned long)__rlim_rmax(limit, r),   \
22017 +       VX_VLIM(__rlim_soft(limit, r)),         \
22018 +       VX_VLIM(__rlim_hard(limit, r)),         \
22019 +       atomic_read(&__rlim_lhit(limit, r))
22020 +
22021 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22022 +{
22023 +       vx_limit_fixup(limit, -1);
22024 +       return sprintf(buffer, VX_LIMIT_TOP
22025 +               "PROC"  VX_LIMIT_FMT
22026 +               "VM"    VX_LIMIT_FMT
22027 +               "VML"   VX_LIMIT_FMT
22028 +               "RSS"   VX_LIMIT_FMT
22029 +               "ANON"  VX_LIMIT_FMT
22030 +               "RMAP"  VX_LIMIT_FMT
22031 +               "FILES" VX_LIMIT_FMT
22032 +               "OFD"   VX_LIMIT_FMT
22033 +               "LOCKS" VX_LIMIT_FMT
22034 +               "SOCK"  VX_LIMIT_FMT
22035 +               "MSGQ"  VX_LIMIT_FMT
22036 +               "SHM"   VX_LIMIT_FMT
22037 +               "SEMA"  VX_LIMIT_FMT
22038 +               "SEMS"  VX_LIMIT_FMT
22039 +               "DENT"  VX_LIMIT_FMT,
22040 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22041 +               VX_LIMIT_ARG(RLIMIT_AS),
22042 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22043 +               VX_LIMIT_ARG(RLIMIT_RSS),
22044 +               VX_LIMIT_ARG(VLIMIT_ANON),
22045 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22046 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22047 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22048 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22049 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22050 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22051 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22052 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22053 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22054 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22055 +}
22056 +
22057 +#endif /* _VX_LIMIT_PROC_H */
22058 +
22059 +
22060 diff -NurpP --minimal linux-2.6.32/kernel/vserver/Makefile linux-2.6.32-vs2.3.0.36.26/kernel/vserver/Makefile
22061 --- linux-2.6.32/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
22062 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/Makefile  2009-12-03 20:04:56.000000000 +0100
22063 @@ -0,0 +1,18 @@
22064 +#
22065 +# Makefile for the Linux vserver routines.
22066 +#
22067 +
22068 +
22069 +obj-y          += vserver.o
22070 +
22071 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
22072 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
22073 +                  dlimit.o tag.o
22074 +
22075 +vserver-$(CONFIG_INET) += inet.o
22076 +vserver-$(CONFIG_PROC_FS) += proc.o
22077 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
22078 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
22079 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
22080 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
22081 +
22082 diff -NurpP --minimal linux-2.6.32/kernel/vserver/monitor.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/monitor.c
22083 --- linux-2.6.32/kernel/vserver/monitor.c       1970-01-01 01:00:00.000000000 +0100
22084 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/monitor.c 2009-12-03 20:04:56.000000000 +0100
22085 @@ -0,0 +1,138 @@
22086 +/*
22087 + *  kernel/vserver/monitor.c
22088 + *
22089 + *  Virtual Context Scheduler Monitor
22090 + *
22091 + *  Copyright (C) 2006-2007 Herbert Pötzl
22092 + *
22093 + *  V0.01  basic design
22094 + *
22095 + */
22096 +
22097 +#include <linux/module.h>
22098 +#include <linux/jiffies.h>
22099 +#include <asm/uaccess.h>
22100 +#include <asm/atomic.h>
22101 +
22102 +#include <linux/vserver/monitor.h>
22103 +#include <linux/vserver/debug_cmd.h>
22104 +
22105 +
22106 +#ifdef CONFIG_VSERVER_MONITOR
22107 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22108 +#else
22109 +#define VXM_SIZE       64
22110 +#endif
22111 +
22112 +struct _vx_monitor {
22113 +       unsigned int counter;
22114 +
22115 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22116 +};
22117 +
22118 +
22119 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22120 +
22121 +unsigned volatile int vxm_active = 1;
22122 +
22123 +static atomic_t sequence = ATOMIC_INIT(0);
22124 +
22125 +
22126 +/*     vxm_advance()
22127 +
22128 +       * requires disabled preemption                          */
22129 +
22130 +struct _vx_mon_entry *vxm_advance(int cpu)
22131 +{
22132 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22133 +       struct _vx_mon_entry *entry;
22134 +       unsigned int index;
22135 +
22136 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22137 +       entry = &mon->entry[index];
22138 +
22139 +       entry->ev.seq = atomic_inc_return(&sequence);
22140 +       entry->ev.jif = jiffies;
22141 +       return entry;
22142 +}
22143 +
22144 +EXPORT_SYMBOL_GPL(vxm_advance);
22145 +
22146 +
22147 +int do_read_monitor(struct __user _vx_mon_entry *data,
22148 +       int cpu, uint32_t *index, uint32_t *count)
22149 +{
22150 +       int pos, ret = 0;
22151 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22152 +       int end = mon->counter;
22153 +       int start = end - VXM_SIZE + 2;
22154 +       int idx = *index;
22155 +
22156 +       /* special case: get current pos */
22157 +       if (!*count) {
22158 +               *index = end;
22159 +               return 0;
22160 +       }
22161 +
22162 +       /* have we lost some data? */
22163 +       if (idx < start)
22164 +               idx = start;
22165 +
22166 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22167 +               struct _vx_mon_entry *entry =
22168 +                       &mon->entry[idx % VXM_SIZE];
22169 +
22170 +               /* send entry to userspace */
22171 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22172 +               if (ret)
22173 +                       break;
22174 +       }
22175 +       /* save new index and count */
22176 +       *index = idx;
22177 +       *count = pos;
22178 +       return ret ? ret : (*index < end);
22179 +}
22180 +
22181 +int vc_read_monitor(uint32_t id, void __user *data)
22182 +{
22183 +       struct vcmd_read_monitor_v0 vc_data;
22184 +       int ret;
22185 +
22186 +       if (id >= NR_CPUS)
22187 +               return -EINVAL;
22188 +
22189 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22190 +               return -EFAULT;
22191 +
22192 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22193 +               id, &vc_data.index, &vc_data.count);
22194 +
22195 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22196 +               return -EFAULT;
22197 +       return ret;
22198 +}
22199 +
22200 +#ifdef CONFIG_COMPAT
22201 +
22202 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22203 +{
22204 +       struct vcmd_read_monitor_v0_x32 vc_data;
22205 +       int ret;
22206 +
22207 +       if (id >= NR_CPUS)
22208 +               return -EINVAL;
22209 +
22210 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22211 +               return -EFAULT;
22212 +
22213 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22214 +               compat_ptr(vc_data.data_ptr),
22215 +               id, &vc_data.index, &vc_data.count);
22216 +
22217 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22218 +               return -EFAULT;
22219 +       return ret;
22220 +}
22221 +
22222 +#endif /* CONFIG_COMPAT */
22223 +
22224 diff -NurpP --minimal linux-2.6.32/kernel/vserver/network.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/network.c
22225 --- linux-2.6.32/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
22226 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/network.c 2009-12-03 20:04:56.000000000 +0100
22227 @@ -0,0 +1,864 @@
22228 +/*
22229 + *  linux/kernel/vserver/network.c
22230 + *
22231 + *  Virtual Server: Network Support
22232 + *
22233 + *  Copyright (C) 2003-2007  Herbert Pötzl
22234 + *
22235 + *  V0.01  broken out from vcontext V0.05
22236 + *  V0.02  cleaned up implementation
22237 + *  V0.03  added equiv nx commands
22238 + *  V0.04  switch to RCU based hash
22239 + *  V0.05  and back to locking again
22240 + *  V0.06  changed vcmds to nxi arg
22241 + *  V0.07  have __create claim() the nxi
22242 + *
22243 + */
22244 +
22245 +#include <linux/err.h>
22246 +#include <linux/slab.h>
22247 +#include <linux/rcupdate.h>
22248 +
22249 +#include <linux/vs_network.h>
22250 +#include <linux/vs_pid.h>
22251 +#include <linux/vserver/network_cmd.h>
22252 +
22253 +
22254 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22255 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22256 +
22257 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22258 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22259 +
22260 +
22261 +static int __init init_network(void)
22262 +{
22263 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22264 +               sizeof(struct nx_addr_v4), 0,
22265 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22266 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22267 +               sizeof(struct nx_addr_v6), 0,
22268 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22269 +       return 0;
22270 +}
22271 +
22272 +
22273 +/*     __alloc_nx_addr_v4()                                    */
22274 +
22275 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22276 +{
22277 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22278 +               nx_addr_v4_cachep, GFP_KERNEL);
22279 +
22280 +       if (!IS_ERR(nxa))
22281 +               memset(nxa, 0, sizeof(*nxa));
22282 +       return nxa;
22283 +}
22284 +
22285 +/*     __dealloc_nx_addr_v4()                                  */
22286 +
22287 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22288 +{
22289 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22290 +}
22291 +
22292 +/*     __dealloc_nx_addr_v4_all()                              */
22293 +
22294 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22295 +{
22296 +       while (nxa) {
22297 +               struct nx_addr_v4 *next = nxa->next;
22298 +
22299 +               __dealloc_nx_addr_v4(nxa);
22300 +               nxa = next;
22301 +       }
22302 +}
22303 +
22304 +
22305 +#ifdef CONFIG_IPV6
22306 +
22307 +/*     __alloc_nx_addr_v6()                                    */
22308 +
22309 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22310 +{
22311 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22312 +               nx_addr_v6_cachep, GFP_KERNEL);
22313 +
22314 +       if (!IS_ERR(nxa))
22315 +               memset(nxa, 0, sizeof(*nxa));
22316 +       return nxa;
22317 +}
22318 +
22319 +/*     __dealloc_nx_addr_v6()                                  */
22320 +
22321 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22322 +{
22323 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22324 +}
22325 +
22326 +/*     __dealloc_nx_addr_v6_all()                              */
22327 +
22328 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22329 +{
22330 +       while (nxa) {
22331 +               struct nx_addr_v6 *next = nxa->next;
22332 +
22333 +               __dealloc_nx_addr_v6(nxa);
22334 +               nxa = next;
22335 +       }
22336 +}
22337 +
22338 +#endif /* CONFIG_IPV6 */
22339 +
22340 +/*     __alloc_nx_info()
22341 +
22342 +       * allocate an initialized nx_info struct
22343 +       * doesn't make it visible (hash)                        */
22344 +
22345 +static struct nx_info *__alloc_nx_info(nid_t nid)
22346 +{
22347 +       struct nx_info *new = NULL;
22348 +
22349 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22350 +
22351 +       /* would this benefit from a slab cache? */
22352 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22353 +       if (!new)
22354 +               return 0;
22355 +
22356 +       memset(new, 0, sizeof(struct nx_info));
22357 +       new->nx_id = nid;
22358 +       INIT_HLIST_NODE(&new->nx_hlist);
22359 +       atomic_set(&new->nx_usecnt, 0);
22360 +       atomic_set(&new->nx_tasks, 0);
22361 +       new->nx_state = 0;
22362 +
22363 +       new->nx_flags = NXF_INIT_SET;
22364 +
22365 +       /* rest of init goes here */
22366 +
22367 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22368 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22369 +
22370 +       vxdprintk(VXD_CBIT(nid, 0),
22371 +               "alloc_nx_info(%d) = %p", nid, new);
22372 +       atomic_inc(&nx_global_ctotal);
22373 +       return new;
22374 +}
22375 +
22376 +/*     __dealloc_nx_info()
22377 +
22378 +       * final disposal of nx_info                             */
22379 +
22380 +static void __dealloc_nx_info(struct nx_info *nxi)
22381 +{
22382 +       vxdprintk(VXD_CBIT(nid, 0),
22383 +               "dealloc_nx_info(%p)", nxi);
22384 +
22385 +       nxi->nx_hlist.next = LIST_POISON1;
22386 +       nxi->nx_id = -1;
22387 +
22388 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22389 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22390 +
22391 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22392 +
22393 +       nxi->nx_state |= NXS_RELEASED;
22394 +       kfree(nxi);
22395 +       atomic_dec(&nx_global_ctotal);
22396 +}
22397 +
22398 +static void __shutdown_nx_info(struct nx_info *nxi)
22399 +{
22400 +       nxi->nx_state |= NXS_SHUTDOWN;
22401 +       vs_net_change(nxi, VSC_NETDOWN);
22402 +}
22403 +
22404 +/*     exported stuff                                          */
22405 +
22406 +void free_nx_info(struct nx_info *nxi)
22407 +{
22408 +       /* context shutdown is mandatory */
22409 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22410 +
22411 +       /* context must not be hashed */
22412 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22413 +
22414 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22415 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22416 +
22417 +       __dealloc_nx_info(nxi);
22418 +}
22419 +
22420 +
22421 +void __nx_set_lback(struct nx_info *nxi)
22422 +{
22423 +       int nid = nxi->nx_id;
22424 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22425 +
22426 +       nxi->v4_lback.s_addr = lback;
22427 +}
22428 +
22429 +extern int __nx_inet_add_lback(__be32 addr);
22430 +extern int __nx_inet_del_lback(__be32 addr);
22431 +
22432 +
22433 +/*     hash table for nx_info hash */
22434 +
22435 +#define NX_HASH_SIZE   13
22436 +
22437 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22438 +
22439 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22440 +
22441 +
22442 +static inline unsigned int __hashval(nid_t nid)
22443 +{
22444 +       return (nid % NX_HASH_SIZE);
22445 +}
22446 +
22447 +
22448 +
22449 +/*     __hash_nx_info()
22450 +
22451 +       * add the nxi to the global hash table
22452 +       * requires the hash_lock to be held                     */
22453 +
22454 +static inline void __hash_nx_info(struct nx_info *nxi)
22455 +{
22456 +       struct hlist_head *head;
22457 +
22458 +       vxd_assert_lock(&nx_info_hash_lock);
22459 +       vxdprintk(VXD_CBIT(nid, 4),
22460 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22461 +
22462 +       /* context must not be hashed */
22463 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22464 +
22465 +       nxi->nx_state |= NXS_HASHED;
22466 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22467 +       hlist_add_head(&nxi->nx_hlist, head);
22468 +       atomic_inc(&nx_global_cactive);
22469 +}
22470 +
22471 +/*     __unhash_nx_info()
22472 +
22473 +       * remove the nxi from the global hash table
22474 +       * requires the hash_lock to be held                     */
22475 +
22476 +static inline void __unhash_nx_info(struct nx_info *nxi)
22477 +{
22478 +       vxd_assert_lock(&nx_info_hash_lock);
22479 +       vxdprintk(VXD_CBIT(nid, 4),
22480 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22481 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22482 +
22483 +       /* context must be hashed */
22484 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22485 +       /* but without tasks */
22486 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22487 +
22488 +       nxi->nx_state &= ~NXS_HASHED;
22489 +       hlist_del(&nxi->nx_hlist);
22490 +       atomic_dec(&nx_global_cactive);
22491 +}
22492 +
22493 +
22494 +/*     __lookup_nx_info()
22495 +
22496 +       * requires the hash_lock to be held
22497 +       * doesn't increment the nx_refcnt                       */
22498 +
22499 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22500 +{
22501 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22502 +       struct hlist_node *pos;
22503 +       struct nx_info *nxi;
22504 +
22505 +       vxd_assert_lock(&nx_info_hash_lock);
22506 +       hlist_for_each(pos, head) {
22507 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22508 +
22509 +               if (nxi->nx_id == nid)
22510 +                       goto found;
22511 +       }
22512 +       nxi = NULL;
22513 +found:
22514 +       vxdprintk(VXD_CBIT(nid, 0),
22515 +               "__lookup_nx_info(#%u): %p[#%u]",
22516 +               nid, nxi, nxi ? nxi->nx_id : 0);
22517 +       return nxi;
22518 +}
22519 +
22520 +
22521 +/*     __create_nx_info()
22522 +
22523 +       * create the requested context
22524 +       * get(), claim() and hash it                            */
22525 +
22526 +static struct nx_info *__create_nx_info(int id)
22527 +{
22528 +       struct nx_info *new, *nxi = NULL;
22529 +
22530 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22531 +
22532 +       if (!(new = __alloc_nx_info(id)))
22533 +               return ERR_PTR(-ENOMEM);
22534 +
22535 +       /* required to make dynamic xids unique */
22536 +       spin_lock(&nx_info_hash_lock);
22537 +
22538 +       /* static context requested */
22539 +       if ((nxi = __lookup_nx_info(id))) {
22540 +               vxdprintk(VXD_CBIT(nid, 0),
22541 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22542 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22543 +                       nxi = ERR_PTR(-EBUSY);
22544 +               else
22545 +                       nxi = ERR_PTR(-EEXIST);
22546 +               goto out_unlock;
22547 +       }
22548 +       /* new context */
22549 +       vxdprintk(VXD_CBIT(nid, 0),
22550 +               "create_nx_info(%d) = %p (new)", id, new);
22551 +       claim_nx_info(new, NULL);
22552 +       __nx_set_lback(new);
22553 +       __hash_nx_info(get_nx_info(new));
22554 +       nxi = new, new = NULL;
22555 +
22556 +out_unlock:
22557 +       spin_unlock(&nx_info_hash_lock);
22558 +       if (new)
22559 +               __dealloc_nx_info(new);
22560 +       return nxi;
22561 +}
22562 +
22563 +
22564 +
22565 +/*     exported stuff                                          */
22566 +
22567 +
22568 +void unhash_nx_info(struct nx_info *nxi)
22569 +{
22570 +       __shutdown_nx_info(nxi);
22571 +       spin_lock(&nx_info_hash_lock);
22572 +       __unhash_nx_info(nxi);
22573 +       spin_unlock(&nx_info_hash_lock);
22574 +}
22575 +
22576 +/*     lookup_nx_info()
22577 +
22578 +       * search for a nx_info and get() it
22579 +       * negative id means current                             */
22580 +
22581 +struct nx_info *lookup_nx_info(int id)
22582 +{
22583 +       struct nx_info *nxi = NULL;
22584 +
22585 +       if (id < 0) {
22586 +               nxi = get_nx_info(current_nx_info());
22587 +       } else if (id > 1) {
22588 +               spin_lock(&nx_info_hash_lock);
22589 +               nxi = get_nx_info(__lookup_nx_info(id));
22590 +               spin_unlock(&nx_info_hash_lock);
22591 +       }
22592 +       return nxi;
22593 +}
22594 +
22595 +/*     nid_is_hashed()
22596 +
22597 +       * verify that nid is still hashed                       */
22598 +
22599 +int nid_is_hashed(nid_t nid)
22600 +{
22601 +       int hashed;
22602 +
22603 +       spin_lock(&nx_info_hash_lock);
22604 +       hashed = (__lookup_nx_info(nid) != NULL);
22605 +       spin_unlock(&nx_info_hash_lock);
22606 +       return hashed;
22607 +}
22608 +
22609 +
22610 +#ifdef CONFIG_PROC_FS
22611 +
22612 +/*     get_nid_list()
22613 +
22614 +       * get a subset of hashed nids for proc
22615 +       * assumes size is at least one                          */
22616 +
22617 +int get_nid_list(int index, unsigned int *nids, int size)
22618 +{
22619 +       int hindex, nr_nids = 0;
22620 +
22621 +       /* only show current and children */
22622 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22623 +               if (index > 0)
22624 +                       return 0;
22625 +               nids[nr_nids] = nx_current_nid();
22626 +               return 1;
22627 +       }
22628 +
22629 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22630 +               struct hlist_head *head = &nx_info_hash[hindex];
22631 +               struct hlist_node *pos;
22632 +
22633 +               spin_lock(&nx_info_hash_lock);
22634 +               hlist_for_each(pos, head) {
22635 +                       struct nx_info *nxi;
22636 +
22637 +                       if (--index > 0)
22638 +                               continue;
22639 +
22640 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22641 +                       nids[nr_nids] = nxi->nx_id;
22642 +                       if (++nr_nids >= size) {
22643 +                               spin_unlock(&nx_info_hash_lock);
22644 +                               goto out;
22645 +                       }
22646 +               }
22647 +               /* keep the lock time short */
22648 +               spin_unlock(&nx_info_hash_lock);
22649 +       }
22650 +out:
22651 +       return nr_nids;
22652 +}
22653 +#endif
22654 +
22655 +
22656 +/*
22657 + *     migrate task to new network
22658 + *     gets nxi, puts old_nxi on change
22659 + */
22660 +
22661 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22662 +{
22663 +       struct nx_info *old_nxi;
22664 +       int ret = 0;
22665 +
22666 +       if (!p || !nxi)
22667 +               BUG();
22668 +
22669 +       vxdprintk(VXD_CBIT(nid, 5),
22670 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22671 +               p, nxi, nxi->nx_id,
22672 +               atomic_read(&nxi->nx_usecnt),
22673 +               atomic_read(&nxi->nx_tasks));
22674 +
22675 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22676 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22677 +               return -EACCES;
22678 +
22679 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22680 +               return -EFAULT;
22681 +
22682 +       /* maybe disallow this completely? */
22683 +       old_nxi = task_get_nx_info(p);
22684 +       if (old_nxi == nxi)
22685 +               goto out;
22686 +
22687 +       task_lock(p);
22688 +       if (old_nxi)
22689 +               clr_nx_info(&p->nx_info);
22690 +       claim_nx_info(nxi, p);
22691 +       set_nx_info(&p->nx_info, nxi);
22692 +       p->nid = nxi->nx_id;
22693 +       task_unlock(p);
22694 +
22695 +       vxdprintk(VXD_CBIT(nid, 5),
22696 +               "moved task %p into nxi:%p[#%d]",
22697 +               p, nxi, nxi->nx_id);
22698 +
22699 +       if (old_nxi)
22700 +               release_nx_info(old_nxi, p);
22701 +       ret = 0;
22702 +out:
22703 +       put_nx_info(old_nxi);
22704 +       return ret;
22705 +}
22706 +
22707 +
22708 +void nx_set_persistent(struct nx_info *nxi)
22709 +{
22710 +       vxdprintk(VXD_CBIT(nid, 6),
22711 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22712 +
22713 +       get_nx_info(nxi);
22714 +       claim_nx_info(nxi, NULL);
22715 +}
22716 +
22717 +void nx_clear_persistent(struct nx_info *nxi)
22718 +{
22719 +       vxdprintk(VXD_CBIT(nid, 6),
22720 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22721 +
22722 +       release_nx_info(nxi, NULL);
22723 +       put_nx_info(nxi);
22724 +}
22725 +
22726 +void nx_update_persistent(struct nx_info *nxi)
22727 +{
22728 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22729 +               nx_set_persistent(nxi);
22730 +       else
22731 +               nx_clear_persistent(nxi);
22732 +}
22733 +
22734 +/* vserver syscall commands below here */
22735 +
22736 +/* taks nid and nx_info functions */
22737 +
22738 +#include <asm/uaccess.h>
22739 +
22740 +
22741 +int vc_task_nid(uint32_t id)
22742 +{
22743 +       nid_t nid;
22744 +
22745 +       if (id) {
22746 +               struct task_struct *tsk;
22747 +
22748 +               read_lock(&tasklist_lock);
22749 +               tsk = find_task_by_real_pid(id);
22750 +               nid = (tsk) ? tsk->nid : -ESRCH;
22751 +               read_unlock(&tasklist_lock);
22752 +       } else
22753 +               nid = nx_current_nid();
22754 +       return nid;
22755 +}
22756 +
22757 +
22758 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22759 +{
22760 +       struct vcmd_nx_info_v0 vc_data;
22761 +
22762 +       vc_data.nid = nxi->nx_id;
22763 +
22764 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22765 +               return -EFAULT;
22766 +       return 0;
22767 +}
22768 +
22769 +
22770 +/* network functions */
22771 +
22772 +int vc_net_create(uint32_t nid, void __user *data)
22773 +{
22774 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22775 +       struct nx_info *new_nxi;
22776 +       int ret;
22777 +
22778 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22779 +               return -EFAULT;
22780 +
22781 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22782 +               return -EINVAL;
22783 +
22784 +       new_nxi = __create_nx_info(nid);
22785 +       if (IS_ERR(new_nxi))
22786 +               return PTR_ERR(new_nxi);
22787 +
22788 +       /* initial flags */
22789 +       new_nxi->nx_flags = vc_data.flagword;
22790 +
22791 +       ret = -ENOEXEC;
22792 +       if (vs_net_change(new_nxi, VSC_NETUP))
22793 +               goto out;
22794 +
22795 +       ret = nx_migrate_task(current, new_nxi);
22796 +       if (ret)
22797 +               goto out;
22798 +
22799 +       /* return context id on success */
22800 +       ret = new_nxi->nx_id;
22801 +
22802 +       /* get a reference for persistent contexts */
22803 +       if ((vc_data.flagword & NXF_PERSISTENT))
22804 +               nx_set_persistent(new_nxi);
22805 +out:
22806 +       release_nx_info(new_nxi, NULL);
22807 +       put_nx_info(new_nxi);
22808 +       return ret;
22809 +}
22810 +
22811 +
22812 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22813 +{
22814 +       return nx_migrate_task(current, nxi);
22815 +}
22816 +
22817 +
22818 +
22819 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22820 +       uint16_t type, uint16_t flags)
22821 +{
22822 +       struct nx_addr_v4 *nxa = &nxi->v4;
22823 +
22824 +       if (NX_IPV4(nxi)) {
22825 +               /* locate last entry */
22826 +               for (; nxa->next; nxa = nxa->next);
22827 +               nxa->next = __alloc_nx_addr_v4();
22828 +               nxa = nxa->next;
22829 +
22830 +               if (IS_ERR(nxa))
22831 +                       return PTR_ERR(nxa);
22832 +       }
22833 +
22834 +       if (nxi->v4.next)
22835 +               /* remove single ip for ip list */
22836 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22837 +
22838 +       nxa->ip[0].s_addr = ip;
22839 +       nxa->ip[1].s_addr = ip2;
22840 +       nxa->mask.s_addr = mask;
22841 +       nxa->type = type;
22842 +       nxa->flags = flags;
22843 +       return 0;
22844 +}
22845 +
22846 +
22847 +int vc_net_add(struct nx_info *nxi, void __user *data)
22848 +{
22849 +       struct vcmd_net_addr_v0 vc_data;
22850 +       int index, ret = 0;
22851 +
22852 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22853 +               return -EFAULT;
22854 +
22855 +       switch (vc_data.type) {
22856 +       case NXA_TYPE_IPV4:
22857 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22858 +                       return -EINVAL;
22859 +
22860 +               index = 0;
22861 +               while (index < vc_data.count) {
22862 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22863 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22864 +                       if (ret)
22865 +                               return ret;
22866 +                       index++;
22867 +               }
22868 +               ret = index;
22869 +               break;
22870 +
22871 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22872 +               nxi->v4_bcast = vc_data.ip[0];
22873 +               ret = 1;
22874 +               break;
22875 +
22876 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22877 +               nxi->v4_lback = vc_data.ip[0];
22878 +               ret = 1;
22879 +               break;
22880 +
22881 +       default:
22882 +               ret = -EINVAL;
22883 +               break;
22884 +       }
22885 +       return ret;
22886 +}
22887 +
22888 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22889 +{
22890 +       struct vcmd_net_addr_v0 vc_data;
22891 +
22892 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22893 +               return -EFAULT;
22894 +
22895 +       switch (vc_data.type) {
22896 +       case NXA_TYPE_ANY:
22897 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22898 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22899 +               break;
22900 +
22901 +       default:
22902 +               return -EINVAL;
22903 +       }
22904 +       return 0;
22905 +}
22906 +
22907 +
22908 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22909 +{
22910 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22911 +
22912 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22913 +               return -EFAULT;
22914 +
22915 +       switch (vc_data.type) {
22916 +       case NXA_TYPE_ADDR:
22917 +       case NXA_TYPE_RANGE:
22918 +       case NXA_TYPE_MASK:
22919 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22920 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22921 +
22922 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22923 +               nxi->v4_bcast = vc_data.ip;
22924 +               break;
22925 +
22926 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22927 +               nxi->v4_lback = vc_data.ip;
22928 +               break;
22929 +
22930 +       default:
22931 +               return -EINVAL;
22932 +       }
22933 +       return 0;
22934 +}
22935 +
22936 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22937 +{
22938 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22939 +
22940 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22941 +               return -EFAULT;
22942 +
22943 +       switch (vc_data.type) {
22944 +/*     case NXA_TYPE_ADDR:
22945 +               break;          */
22946 +
22947 +       case NXA_TYPE_ANY:
22948 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22949 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22950 +               break;
22951 +
22952 +       default:
22953 +               return -EINVAL;
22954 +       }
22955 +       return 0;
22956 +}
22957 +
22958 +
22959 +#ifdef CONFIG_IPV6
22960 +
22961 +int do_add_v6_addr(struct nx_info *nxi,
22962 +       struct in6_addr *ip, struct in6_addr *mask,
22963 +       uint32_t prefix, uint16_t type, uint16_t flags)
22964 +{
22965 +       struct nx_addr_v6 *nxa = &nxi->v6;
22966 +
22967 +       if (NX_IPV6(nxi)) {
22968 +               /* locate last entry */
22969 +               for (; nxa->next; nxa = nxa->next);
22970 +               nxa->next = __alloc_nx_addr_v6();
22971 +               nxa = nxa->next;
22972 +
22973 +               if (IS_ERR(nxa))
22974 +                       return PTR_ERR(nxa);
22975 +       }
22976 +
22977 +       nxa->ip = *ip;
22978 +       nxa->mask = *mask;
22979 +       nxa->prefix = prefix;
22980 +       nxa->type = type;
22981 +       nxa->flags = flags;
22982 +       return 0;
22983 +}
22984 +
22985 +
22986 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22987 +{
22988 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22989 +
22990 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22991 +               return -EFAULT;
22992 +
22993 +       switch (vc_data.type) {
22994 +       case NXA_TYPE_ADDR:
22995 +       case NXA_TYPE_MASK:
22996 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22997 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22998 +       default:
22999 +               return -EINVAL;
23000 +       }
23001 +       return 0;
23002 +}
23003 +
23004 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23005 +{
23006 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23007 +
23008 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23009 +               return -EFAULT;
23010 +
23011 +       switch (vc_data.type) {
23012 +       case NXA_TYPE_ANY:
23013 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23014 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23015 +               break;
23016 +
23017 +       default:
23018 +               return -EINVAL;
23019 +       }
23020 +       return 0;
23021 +}
23022 +
23023 +#endif /* CONFIG_IPV6 */
23024 +
23025 +
23026 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23027 +{
23028 +       struct vcmd_net_flags_v0 vc_data;
23029 +
23030 +       vc_data.flagword = nxi->nx_flags;
23031 +
23032 +       /* special STATE flag handling */
23033 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23034 +
23035 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23036 +               return -EFAULT;
23037 +       return 0;
23038 +}
23039 +
23040 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23041 +{
23042 +       struct vcmd_net_flags_v0 vc_data;
23043 +       uint64_t mask, trigger;
23044 +
23045 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23046 +               return -EFAULT;
23047 +
23048 +       /* special STATE flag handling */
23049 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23050 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23051 +
23052 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23053 +               vc_data.flagword, mask);
23054 +       if (trigger & NXF_PERSISTENT)
23055 +               nx_update_persistent(nxi);
23056 +
23057 +       return 0;
23058 +}
23059 +
23060 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23061 +{
23062 +       struct vcmd_net_caps_v0 vc_data;
23063 +
23064 +       vc_data.ncaps = nxi->nx_ncaps;
23065 +       vc_data.cmask = ~0ULL;
23066 +
23067 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23068 +               return -EFAULT;
23069 +       return 0;
23070 +}
23071 +
23072 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23073 +{
23074 +       struct vcmd_net_caps_v0 vc_data;
23075 +
23076 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23077 +               return -EFAULT;
23078 +
23079 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23080 +               vc_data.ncaps, vc_data.cmask);
23081 +       return 0;
23082 +}
23083 +
23084 +
23085 +#include <linux/module.h>
23086 +
23087 +module_init(init_network);
23088 +
23089 +EXPORT_SYMBOL_GPL(free_nx_info);
23090 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23091 +
23092 diff -NurpP --minimal linux-2.6.32/kernel/vserver/proc.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/proc.c
23093 --- linux-2.6.32/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
23094 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/proc.c    2009-12-03 20:04:56.000000000 +0100
23095 @@ -0,0 +1,1098 @@
23096 +/*
23097 + *  linux/kernel/vserver/proc.c
23098 + *
23099 + *  Virtual Context Support
23100 + *
23101 + *  Copyright (C) 2003-2007  Herbert Pötzl
23102 + *
23103 + *  V0.01  basic structure
23104 + *  V0.02  adaptation vs1.3.0
23105 + *  V0.03  proc permissions
23106 + *  V0.04  locking/generic
23107 + *  V0.05  next generation procfs
23108 + *  V0.06  inode validation
23109 + *  V0.07  generic rewrite vid
23110 + *  V0.08  remove inode type
23111 + *
23112 + */
23113 +
23114 +#include <linux/proc_fs.h>
23115 +#include <linux/fs_struct.h>
23116 +#include <linux/mount.h>
23117 +#include <asm/unistd.h>
23118 +
23119 +#include <linux/vs_context.h>
23120 +#include <linux/vs_network.h>
23121 +#include <linux/vs_cvirt.h>
23122 +
23123 +#include <linux/in.h>
23124 +#include <linux/inetdevice.h>
23125 +#include <linux/vs_inet.h>
23126 +#include <linux/vs_inet6.h>
23127 +
23128 +#include <linux/vserver/global.h>
23129 +
23130 +#include "cvirt_proc.h"
23131 +#include "cacct_proc.h"
23132 +#include "limit_proc.h"
23133 +#include "sched_proc.h"
23134 +#include "vci_config.h"
23135 +
23136 +
23137 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23138 +{
23139 +       unsigned __capi;
23140 +
23141 +       CAP_FOR_EACH_U32(__capi) {
23142 +               buffer += sprintf(buffer, "%08x",
23143 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23144 +       }
23145 +       return buffer;
23146 +}
23147 +
23148 +
23149 +static struct proc_dir_entry *proc_virtual;
23150 +
23151 +static struct proc_dir_entry *proc_virtnet;
23152 +
23153 +
23154 +/* first the actual feeds */
23155 +
23156 +
23157 +static int proc_vci(char *buffer)
23158 +{
23159 +       return sprintf(buffer,
23160 +               "VCIVersion:\t%04x:%04x\n"
23161 +               "VCISyscall:\t%d\n"
23162 +               "VCIKernel:\t%08x\n",
23163 +               VCI_VERSION >> 16,
23164 +               VCI_VERSION & 0xFFFF,
23165 +               __NR_vserver,
23166 +               vci_kernel_config());
23167 +}
23168 +
23169 +static int proc_virtual_info(char *buffer)
23170 +{
23171 +       return proc_vci(buffer);
23172 +}
23173 +
23174 +static int proc_virtual_status(char *buffer)
23175 +{
23176 +       return sprintf(buffer,
23177 +               "#CTotal:\t%d\n"
23178 +               "#CActive:\t%d\n"
23179 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23180 +               "#InitTask:\t%d\t%d %d\n",
23181 +               atomic_read(&vx_global_ctotal),
23182 +               atomic_read(&vx_global_cactive),
23183 +               atomic_read(&vs_global_nsproxy),
23184 +               atomic_read(&vs_global_fs),
23185 +               atomic_read(&vs_global_mnt_ns),
23186 +               atomic_read(&vs_global_uts_ns),
23187 +               atomic_read(&nr_ipc_ns),
23188 +               atomic_read(&vs_global_user_ns),
23189 +               atomic_read(&vs_global_pid_ns),
23190 +               atomic_read(&init_task.usage),
23191 +               atomic_read(&init_task.nsproxy->count),
23192 +               init_task.fs->users);
23193 +}
23194 +
23195 +
23196 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23197 +{
23198 +       int length;
23199 +
23200 +       length = sprintf(buffer,
23201 +               "ID:\t%d\n"
23202 +               "Info:\t%p\n"
23203 +               "Init:\t%d\n"
23204 +               "OOM:\t%lld\n",
23205 +               vxi->vx_id,
23206 +               vxi,
23207 +               vxi->vx_initpid,
23208 +               vxi->vx_badness_bias);
23209 +       return length;
23210 +}
23211 +
23212 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23213 +{
23214 +       char *orig = buffer;
23215 +
23216 +       buffer += sprintf(buffer,
23217 +               "UseCnt:\t%d\n"
23218 +               "Tasks:\t%d\n"
23219 +               "Flags:\t%016llx\n",
23220 +               atomic_read(&vxi->vx_usecnt),
23221 +               atomic_read(&vxi->vx_tasks),
23222 +               (unsigned long long)vxi->vx_flags);
23223 +
23224 +       buffer += sprintf(buffer, "BCaps:\t");
23225 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23226 +       buffer += sprintf(buffer, "\n");
23227 +
23228 +       buffer += sprintf(buffer,
23229 +               "CCaps:\t%016llx\n"
23230 +               "Spaces:\t%08lx %08lx\n",
23231 +               (unsigned long long)vxi->vx_ccaps,
23232 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23233 +       return buffer - orig;
23234 +}
23235 +
23236 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23237 +{
23238 +       return vx_info_proc_limit(&vxi->limit, buffer);
23239 +}
23240 +
23241 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23242 +{
23243 +       int cpu, length;
23244 +
23245 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23246 +       for_each_online_cpu(cpu) {
23247 +               length += vx_info_proc_sched_pc(
23248 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23249 +                       buffer + length, cpu);
23250 +       }
23251 +       return length;
23252 +}
23253 +
23254 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23255 +{
23256 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23257 +}
23258 +
23259 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23260 +{
23261 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23262 +}
23263 +
23264 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23265 +{
23266 +       int cpu, length;
23267 +
23268 +       vx_update_load(vxi);
23269 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23270 +       for_each_online_cpu(cpu) {
23271 +               length += vx_info_proc_cvirt_pc(
23272 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23273 +                       buffer + length, cpu);
23274 +       }
23275 +       return length;
23276 +}
23277 +
23278 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23279 +{
23280 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23281 +}
23282 +
23283 +
23284 +static int proc_virtnet_info(char *buffer)
23285 +{
23286 +       return proc_vci(buffer);
23287 +}
23288 +
23289 +static int proc_virtnet_status(char *buffer)
23290 +{
23291 +       return sprintf(buffer,
23292 +               "#CTotal:\t%d\n"
23293 +               "#CActive:\t%d\n",
23294 +               atomic_read(&nx_global_ctotal),
23295 +               atomic_read(&nx_global_cactive));
23296 +}
23297 +
23298 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23299 +{
23300 +       struct nx_addr_v4 *v4a;
23301 +#ifdef CONFIG_IPV6
23302 +       struct nx_addr_v6 *v6a;
23303 +#endif
23304 +       int length, i;
23305 +
23306 +       length = sprintf(buffer,
23307 +               "ID:\t%d\n"
23308 +               "Info:\t%p\n"
23309 +               "Bcast:\t" NIPQUAD_FMT "\n"
23310 +               "Lback:\t" NIPQUAD_FMT "\n",
23311 +               nxi->nx_id,
23312 +               nxi,
23313 +               NIPQUAD(nxi->v4_bcast.s_addr),
23314 +               NIPQUAD(nxi->v4_lback.s_addr));
23315 +
23316 +       if (!NX_IPV4(nxi))
23317 +               goto skip_v4;
23318 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23319 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23320 +                       i, NXAV4(v4a));
23321 +skip_v4:
23322 +#ifdef CONFIG_IPV6
23323 +       if (!NX_IPV6(nxi))
23324 +               goto skip_v6;
23325 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23326 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23327 +                       i, NXAV6(v6a));
23328 +skip_v6:
23329 +#endif
23330 +       return length;
23331 +}
23332 +
23333 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23334 +{
23335 +       int length;
23336 +
23337 +       length = sprintf(buffer,
23338 +               "UseCnt:\t%d\n"
23339 +               "Tasks:\t%d\n"
23340 +               "Flags:\t%016llx\n"
23341 +               "NCaps:\t%016llx\n",
23342 +               atomic_read(&nxi->nx_usecnt),
23343 +               atomic_read(&nxi->nx_tasks),
23344 +               (unsigned long long)nxi->nx_flags,
23345 +               (unsigned long long)nxi->nx_ncaps);
23346 +       return length;
23347 +}
23348 +
23349 +
23350 +
23351 +/* here the inode helpers */
23352 +
23353 +struct vs_entry {
23354 +       int len;
23355 +       char *name;
23356 +       mode_t mode;
23357 +       struct inode_operations *iop;
23358 +       struct file_operations *fop;
23359 +       union proc_op op;
23360 +};
23361 +
23362 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23363 +{
23364 +       struct inode *inode = new_inode(sb);
23365 +
23366 +       if (!inode)
23367 +               goto out;
23368 +
23369 +       inode->i_mode = p->mode;
23370 +       if (p->iop)
23371 +               inode->i_op = p->iop;
23372 +       if (p->fop)
23373 +               inode->i_fop = p->fop;
23374 +
23375 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23376 +       inode->i_flags |= S_IMMUTABLE;
23377 +
23378 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23379 +
23380 +       inode->i_uid = 0;
23381 +       inode->i_gid = 0;
23382 +       inode->i_tag = 0;
23383 +out:
23384 +       return inode;
23385 +}
23386 +
23387 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23388 +       struct dentry *dentry, int id, void *ptr)
23389 +{
23390 +       struct vs_entry *p = ptr;
23391 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23392 +       struct dentry *error = ERR_PTR(-EINVAL);
23393 +
23394 +       if (!inode)
23395 +               goto out;
23396 +
23397 +       PROC_I(inode)->op = p->op;
23398 +       PROC_I(inode)->fd = id;
23399 +       d_add(dentry, inode);
23400 +       error = NULL;
23401 +out:
23402 +       return error;
23403 +}
23404 +
23405 +/* Lookups */
23406 +
23407 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23408 +
23409 +/*
23410 + * Fill a directory entry.
23411 + *
23412 + * If possible create the dcache entry and derive our inode number and
23413 + * file type from dcache entry.
23414 + *
23415 + * Since all of the proc inode numbers are dynamically generated, the inode
23416 + * numbers do not exist until the inode is cache.  This means creating the
23417 + * the dcache entry in readdir is necessary to keep the inode numbers
23418 + * reported by readdir in sync with the inode numbers reported
23419 + * by stat.
23420 + */
23421 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23422 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23423 +{
23424 +       struct dentry *child, *dir = filp->f_dentry;
23425 +       struct inode *inode;
23426 +       struct qstr qname;
23427 +       ino_t ino = 0;
23428 +       unsigned type = DT_UNKNOWN;
23429 +
23430 +       qname.name = name;
23431 +       qname.len  = len;
23432 +       qname.hash = full_name_hash(name, len);
23433 +
23434 +       child = d_lookup(dir, &qname);
23435 +       if (!child) {
23436 +               struct dentry *new;
23437 +               new = d_alloc(dir, &qname);
23438 +               if (new) {
23439 +                       child = instantiate(dir->d_inode, new, id, ptr);
23440 +                       if (child)
23441 +                               dput(new);
23442 +                       else
23443 +                               child = new;
23444 +               }
23445 +       }
23446 +       if (!child || IS_ERR(child) || !child->d_inode)
23447 +               goto end_instantiate;
23448 +       inode = child->d_inode;
23449 +       if (inode) {
23450 +               ino = inode->i_ino;
23451 +               type = inode->i_mode >> 12;
23452 +       }
23453 +       dput(child);
23454 +end_instantiate:
23455 +       if (!ino)
23456 +               ino = find_inode_number(dir, &qname);
23457 +       if (!ino)
23458 +               ino = 1;
23459 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23460 +}
23461 +
23462 +
23463 +
23464 +/* get and revalidate vx_info/xid */
23465 +
23466 +static inline
23467 +struct vx_info *get_proc_vx_info(struct inode *inode)
23468 +{
23469 +       return lookup_vx_info(PROC_I(inode)->fd);
23470 +}
23471 +
23472 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23473 +{
23474 +       struct inode *inode = dentry->d_inode;
23475 +       xid_t xid = PROC_I(inode)->fd;
23476 +
23477 +       if (!xid || xid_is_hashed(xid))
23478 +               return 1;
23479 +       d_drop(dentry);
23480 +       return 0;
23481 +}
23482 +
23483 +
23484 +/* get and revalidate nx_info/nid */
23485 +
23486 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23487 +{
23488 +       struct inode *inode = dentry->d_inode;
23489 +       nid_t nid = PROC_I(inode)->fd;
23490 +
23491 +       if (!nid || nid_is_hashed(nid))
23492 +               return 1;
23493 +       d_drop(dentry);
23494 +       return 0;
23495 +}
23496 +
23497 +
23498 +
23499 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23500 +
23501 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23502 +                         size_t count, loff_t *ppos)
23503 +{
23504 +       struct inode *inode = file->f_dentry->d_inode;
23505 +       unsigned long page;
23506 +       ssize_t length = 0;
23507 +
23508 +       if (count > PROC_BLOCK_SIZE)
23509 +               count = PROC_BLOCK_SIZE;
23510 +
23511 +       /* fade that out as soon as stable */
23512 +       WARN_ON(PROC_I(inode)->fd);
23513 +
23514 +       if (!(page = __get_free_page(GFP_KERNEL)))
23515 +               return -ENOMEM;
23516 +
23517 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23518 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23519 +
23520 +       if (length >= 0)
23521 +               length = simple_read_from_buffer(buf, count, ppos,
23522 +                       (char *)page, length);
23523 +
23524 +       free_page(page);
23525 +       return length;
23526 +}
23527 +
23528 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23529 +                         size_t count, loff_t *ppos)
23530 +{
23531 +       struct inode *inode = file->f_dentry->d_inode;
23532 +       struct vx_info *vxi = NULL;
23533 +       xid_t xid = PROC_I(inode)->fd;
23534 +       unsigned long page;
23535 +       ssize_t length = 0;
23536 +
23537 +       if (count > PROC_BLOCK_SIZE)
23538 +               count = PROC_BLOCK_SIZE;
23539 +
23540 +       /* fade that out as soon as stable */
23541 +       WARN_ON(!xid);
23542 +       vxi = lookup_vx_info(xid);
23543 +       if (!vxi)
23544 +               goto out;
23545 +
23546 +       length = -ENOMEM;
23547 +       if (!(page = __get_free_page(GFP_KERNEL)))
23548 +               goto out_put;
23549 +
23550 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23551 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23552 +
23553 +       if (length >= 0)
23554 +               length = simple_read_from_buffer(buf, count, ppos,
23555 +                       (char *)page, length);
23556 +
23557 +       free_page(page);
23558 +out_put:
23559 +       put_vx_info(vxi);
23560 +out:
23561 +       return length;
23562 +}
23563 +
23564 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23565 +                         size_t count, loff_t *ppos)
23566 +{
23567 +       struct inode *inode = file->f_dentry->d_inode;
23568 +       struct nx_info *nxi = NULL;
23569 +       nid_t nid = PROC_I(inode)->fd;
23570 +       unsigned long page;
23571 +       ssize_t length = 0;
23572 +
23573 +       if (count > PROC_BLOCK_SIZE)
23574 +               count = PROC_BLOCK_SIZE;
23575 +
23576 +       /* fade that out as soon as stable */
23577 +       WARN_ON(!nid);
23578 +       nxi = lookup_nx_info(nid);
23579 +       if (!nxi)
23580 +               goto out;
23581 +
23582 +       length = -ENOMEM;
23583 +       if (!(page = __get_free_page(GFP_KERNEL)))
23584 +               goto out_put;
23585 +
23586 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23587 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23588 +
23589 +       if (length >= 0)
23590 +               length = simple_read_from_buffer(buf, count, ppos,
23591 +                       (char *)page, length);
23592 +
23593 +       free_page(page);
23594 +out_put:
23595 +       put_nx_info(nxi);
23596 +out:
23597 +       return length;
23598 +}
23599 +
23600 +
23601 +
23602 +/* here comes the lower level */
23603 +
23604 +
23605 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23606 +       .len  = sizeof(NAME) - 1,       \
23607 +       .name = (NAME),                 \
23608 +       .mode = MODE,                   \
23609 +       .iop  = IOP,                    \
23610 +       .fop  = FOP,                    \
23611 +       .op   = OP,                     \
23612 +}
23613 +
23614 +
23615 +#define DIR(NAME, MODE, OTYPE)                         \
23616 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23617 +               &proc_ ## OTYPE ## _inode_operations,   \
23618 +               &proc_ ## OTYPE ## _file_operations, { } )
23619 +
23620 +#define INF(NAME, MODE, OTYPE)                         \
23621 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23622 +               &proc_vs_info_file_operations,          \
23623 +               { .proc_vs_read = &proc_##OTYPE } )
23624 +
23625 +#define VINF(NAME, MODE, OTYPE)                                \
23626 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23627 +               &proc_vx_info_file_operations,          \
23628 +               { .proc_vxi_read = &proc_##OTYPE } )
23629 +
23630 +#define NINF(NAME, MODE, OTYPE)                                \
23631 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23632 +               &proc_nx_info_file_operations,          \
23633 +               { .proc_nxi_read = &proc_##OTYPE } )
23634 +
23635 +
23636 +static struct file_operations proc_vs_info_file_operations = {
23637 +       .read =         proc_vs_info_read,
23638 +};
23639 +
23640 +static struct file_operations proc_vx_info_file_operations = {
23641 +       .read =         proc_vx_info_read,
23642 +};
23643 +
23644 +static struct dentry_operations proc_xid_dentry_operations = {
23645 +       .d_revalidate = proc_xid_revalidate,
23646 +};
23647 +
23648 +static struct vs_entry vx_base_stuff[] = {
23649 +       VINF("info",    S_IRUGO, vxi_info),
23650 +       VINF("status",  S_IRUGO, vxi_status),
23651 +       VINF("limit",   S_IRUGO, vxi_limit),
23652 +       VINF("sched",   S_IRUGO, vxi_sched),
23653 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23654 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23655 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23656 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23657 +       {}
23658 +};
23659 +
23660 +
23661 +
23662 +
23663 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23664 +       struct dentry *dentry, int id, void *ptr)
23665 +{
23666 +       dentry->d_op = &proc_xid_dentry_operations;
23667 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23668 +}
23669 +
23670 +static struct dentry *proc_xid_lookup(struct inode *dir,
23671 +       struct dentry *dentry, struct nameidata *nd)
23672 +{
23673 +       struct vs_entry *p = vx_base_stuff;
23674 +       struct dentry *error = ERR_PTR(-ENOENT);
23675 +
23676 +       for (; p->name; p++) {
23677 +               if (p->len != dentry->d_name.len)
23678 +                       continue;
23679 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23680 +                       break;
23681 +       }
23682 +       if (!p->name)
23683 +               goto out;
23684 +
23685 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23686 +out:
23687 +       return error;
23688 +}
23689 +
23690 +static int proc_xid_readdir(struct file *filp,
23691 +       void *dirent, filldir_t filldir)
23692 +{
23693 +       struct dentry *dentry = filp->f_dentry;
23694 +       struct inode *inode = dentry->d_inode;
23695 +       struct vs_entry *p = vx_base_stuff;
23696 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23697 +       int pos, index;
23698 +       u64 ino;
23699 +
23700 +       pos = filp->f_pos;
23701 +       switch (pos) {
23702 +       case 0:
23703 +               ino = inode->i_ino;
23704 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23705 +                       goto out;
23706 +               pos++;
23707 +               /* fall through */
23708 +       case 1:
23709 +               ino = parent_ino(dentry);
23710 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23711 +                       goto out;
23712 +               pos++;
23713 +               /* fall through */
23714 +       default:
23715 +               index = pos - 2;
23716 +               if (index >= size)
23717 +                       goto out;
23718 +               for (p += index; p->name; p++) {
23719 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23720 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23721 +                               goto out;
23722 +                       pos++;
23723 +               }
23724 +       }
23725 +out:
23726 +       filp->f_pos = pos;
23727 +       return 1;
23728 +}
23729 +
23730 +
23731 +
23732 +static struct file_operations proc_nx_info_file_operations = {
23733 +       .read =         proc_nx_info_read,
23734 +};
23735 +
23736 +static struct dentry_operations proc_nid_dentry_operations = {
23737 +       .d_revalidate = proc_nid_revalidate,
23738 +};
23739 +
23740 +static struct vs_entry nx_base_stuff[] = {
23741 +       NINF("info",    S_IRUGO, nxi_info),
23742 +       NINF("status",  S_IRUGO, nxi_status),
23743 +       {}
23744 +};
23745 +
23746 +
23747 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23748 +       struct dentry *dentry, int id, void *ptr)
23749 +{
23750 +       dentry->d_op = &proc_nid_dentry_operations;
23751 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23752 +}
23753 +
23754 +static struct dentry *proc_nid_lookup(struct inode *dir,
23755 +       struct dentry *dentry, struct nameidata *nd)
23756 +{
23757 +       struct vs_entry *p = nx_base_stuff;
23758 +       struct dentry *error = ERR_PTR(-ENOENT);
23759 +
23760 +       for (; p->name; p++) {
23761 +               if (p->len != dentry->d_name.len)
23762 +                       continue;
23763 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23764 +                       break;
23765 +       }
23766 +       if (!p->name)
23767 +               goto out;
23768 +
23769 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23770 +out:
23771 +       return error;
23772 +}
23773 +
23774 +static int proc_nid_readdir(struct file *filp,
23775 +       void *dirent, filldir_t filldir)
23776 +{
23777 +       struct dentry *dentry = filp->f_dentry;
23778 +       struct inode *inode = dentry->d_inode;
23779 +       struct vs_entry *p = nx_base_stuff;
23780 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23781 +       int pos, index;
23782 +       u64 ino;
23783 +
23784 +       pos = filp->f_pos;
23785 +       switch (pos) {
23786 +       case 0:
23787 +               ino = inode->i_ino;
23788 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23789 +                       goto out;
23790 +               pos++;
23791 +               /* fall through */
23792 +       case 1:
23793 +               ino = parent_ino(dentry);
23794 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23795 +                       goto out;
23796 +               pos++;
23797 +               /* fall through */
23798 +       default:
23799 +               index = pos - 2;
23800 +               if (index >= size)
23801 +                       goto out;
23802 +               for (p += index; p->name; p++) {
23803 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23804 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23805 +                               goto out;
23806 +                       pos++;
23807 +               }
23808 +       }
23809 +out:
23810 +       filp->f_pos = pos;
23811 +       return 1;
23812 +}
23813 +
23814 +
23815 +#define MAX_MULBY10    ((~0U - 9) / 10)
23816 +
23817 +static inline int atovid(const char *str, int len)
23818 +{
23819 +       int vid, c;
23820 +
23821 +       vid = 0;
23822 +       while (len-- > 0) {
23823 +               c = *str - '0';
23824 +               str++;
23825 +               if (c > 9)
23826 +                       return -1;
23827 +               if (vid >= MAX_MULBY10)
23828 +                       return -1;
23829 +               vid *= 10;
23830 +               vid += c;
23831 +               if (!vid)
23832 +                       return -1;
23833 +       }
23834 +       return vid;
23835 +}
23836 +
23837 +/* now the upper level (virtual) */
23838 +
23839 +
23840 +static struct file_operations proc_xid_file_operations = {
23841 +       .read =         generic_read_dir,
23842 +       .readdir =      proc_xid_readdir,
23843 +};
23844 +
23845 +static struct inode_operations proc_xid_inode_operations = {
23846 +       .lookup =       proc_xid_lookup,
23847 +};
23848 +
23849 +static struct vs_entry vx_virtual_stuff[] = {
23850 +       INF("info",     S_IRUGO, virtual_info),
23851 +       INF("status",   S_IRUGO, virtual_status),
23852 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23853 +};
23854 +
23855 +
23856 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23857 +       struct dentry *dentry, struct nameidata *nd)
23858 +{
23859 +       struct vs_entry *p = vx_virtual_stuff;
23860 +       struct dentry *error = ERR_PTR(-ENOENT);
23861 +       int id = 0;
23862 +
23863 +       for (; p->name; p++) {
23864 +               if (p->len != dentry->d_name.len)
23865 +                       continue;
23866 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23867 +                       break;
23868 +       }
23869 +       if (p->name)
23870 +               goto instantiate;
23871 +
23872 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23873 +       if ((id < 0) || !xid_is_hashed(id))
23874 +               goto out;
23875 +
23876 +instantiate:
23877 +       error = proc_xid_instantiate(dir, dentry, id, p);
23878 +out:
23879 +       return error;
23880 +}
23881 +
23882 +static struct file_operations proc_nid_file_operations = {
23883 +       .read =         generic_read_dir,
23884 +       .readdir =      proc_nid_readdir,
23885 +};
23886 +
23887 +static struct inode_operations proc_nid_inode_operations = {
23888 +       .lookup =       proc_nid_lookup,
23889 +};
23890 +
23891 +static struct vs_entry nx_virtnet_stuff[] = {
23892 +       INF("info",     S_IRUGO, virtnet_info),
23893 +       INF("status",   S_IRUGO, virtnet_status),
23894 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23895 +};
23896 +
23897 +
23898 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23899 +       struct dentry *dentry, struct nameidata *nd)
23900 +{
23901 +       struct vs_entry *p = nx_virtnet_stuff;
23902 +       struct dentry *error = ERR_PTR(-ENOENT);
23903 +       int id = 0;
23904 +
23905 +       for (; p->name; p++) {
23906 +               if (p->len != dentry->d_name.len)
23907 +                       continue;
23908 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23909 +                       break;
23910 +       }
23911 +       if (p->name)
23912 +               goto instantiate;
23913 +
23914 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23915 +       if ((id < 0) || !nid_is_hashed(id))
23916 +               goto out;
23917 +
23918 +instantiate:
23919 +       error = proc_nid_instantiate(dir, dentry, id, p);
23920 +out:
23921 +       return error;
23922 +}
23923 +
23924 +
23925 +#define PROC_MAXVIDS 32
23926 +
23927 +int proc_virtual_readdir(struct file *filp,
23928 +       void *dirent, filldir_t filldir)
23929 +{
23930 +       struct dentry *dentry = filp->f_dentry;
23931 +       struct inode *inode = dentry->d_inode;
23932 +       struct vs_entry *p = vx_virtual_stuff;
23933 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23934 +       int pos, index;
23935 +       unsigned int xid_array[PROC_MAXVIDS];
23936 +       char buf[PROC_NUMBUF];
23937 +       unsigned int nr_xids, i;
23938 +       u64 ino;
23939 +
23940 +       pos = filp->f_pos;
23941 +       switch (pos) {
23942 +       case 0:
23943 +               ino = inode->i_ino;
23944 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23945 +                       goto out;
23946 +               pos++;
23947 +               /* fall through */
23948 +       case 1:
23949 +               ino = parent_ino(dentry);
23950 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23951 +                       goto out;
23952 +               pos++;
23953 +               /* fall through */
23954 +       default:
23955 +               index = pos - 2;
23956 +               if (index >= size)
23957 +                       goto entries;
23958 +               for (p += index; p->name; p++) {
23959 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23960 +                               vs_proc_instantiate, 0, p))
23961 +                               goto out;
23962 +                       pos++;
23963 +               }
23964 +       entries:
23965 +               index = pos - size;
23966 +               p = &vx_virtual_stuff[size - 1];
23967 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23968 +               for (i = 0; i < nr_xids; i++) {
23969 +                       int n, xid = xid_array[i];
23970 +                       unsigned int j = PROC_NUMBUF;
23971 +
23972 +                       n = xid;
23973 +                       do
23974 +                               buf[--j] = '0' + (n % 10);
23975 +                       while (n /= 10);
23976 +
23977 +                       if (proc_fill_cache(filp, dirent, filldir,
23978 +                               buf + j, PROC_NUMBUF - j,
23979 +                               vs_proc_instantiate, xid, p))
23980 +                               goto out;
23981 +                       pos++;
23982 +               }
23983 +       }
23984 +out:
23985 +       filp->f_pos = pos;
23986 +       return 0;
23987 +}
23988 +
23989 +static int proc_virtual_getattr(struct vfsmount *mnt,
23990 +       struct dentry *dentry, struct kstat *stat)
23991 +{
23992 +       struct inode *inode = dentry->d_inode;
23993 +
23994 +       generic_fillattr(inode, stat);
23995 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23996 +       return 0;
23997 +}
23998 +
23999 +static struct file_operations proc_virtual_dir_operations = {
24000 +       .read =         generic_read_dir,
24001 +       .readdir =      proc_virtual_readdir,
24002 +};
24003 +
24004 +static struct inode_operations proc_virtual_dir_inode_operations = {
24005 +       .getattr =      proc_virtual_getattr,
24006 +       .lookup =       proc_virtual_lookup,
24007 +};
24008 +
24009 +
24010 +
24011 +
24012 +
24013 +int proc_virtnet_readdir(struct file *filp,
24014 +       void *dirent, filldir_t filldir)
24015 +{
24016 +       struct dentry *dentry = filp->f_dentry;
24017 +       struct inode *inode = dentry->d_inode;
24018 +       struct vs_entry *p = nx_virtnet_stuff;
24019 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24020 +       int pos, index;
24021 +       unsigned int nid_array[PROC_MAXVIDS];
24022 +       char buf[PROC_NUMBUF];
24023 +       unsigned int nr_nids, i;
24024 +       u64 ino;
24025 +
24026 +       pos = filp->f_pos;
24027 +       switch (pos) {
24028 +       case 0:
24029 +               ino = inode->i_ino;
24030 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24031 +                       goto out;
24032 +               pos++;
24033 +               /* fall through */
24034 +       case 1:
24035 +               ino = parent_ino(dentry);
24036 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24037 +                       goto out;
24038 +               pos++;
24039 +               /* fall through */
24040 +       default:
24041 +               index = pos - 2;
24042 +               if (index >= size)
24043 +                       goto entries;
24044 +               for (p += index; p->name; p++) {
24045 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24046 +                               vs_proc_instantiate, 0, p))
24047 +                               goto out;
24048 +                       pos++;
24049 +               }
24050 +       entries:
24051 +               index = pos - size;
24052 +               p = &nx_virtnet_stuff[size - 1];
24053 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24054 +               for (i = 0; i < nr_nids; i++) {
24055 +                       int n, nid = nid_array[i];
24056 +                       unsigned int j = PROC_NUMBUF;
24057 +
24058 +                       n = nid;
24059 +                       do
24060 +                               buf[--j] = '0' + (n % 10);
24061 +                       while (n /= 10);
24062 +
24063 +                       if (proc_fill_cache(filp, dirent, filldir,
24064 +                               buf + j, PROC_NUMBUF - j,
24065 +                               vs_proc_instantiate, nid, p))
24066 +                               goto out;
24067 +                       pos++;
24068 +               }
24069 +       }
24070 +out:
24071 +       filp->f_pos = pos;
24072 +       return 0;
24073 +}
24074 +
24075 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24076 +       struct dentry *dentry, struct kstat *stat)
24077 +{
24078 +       struct inode *inode = dentry->d_inode;
24079 +
24080 +       generic_fillattr(inode, stat);
24081 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24082 +       return 0;
24083 +}
24084 +
24085 +static struct file_operations proc_virtnet_dir_operations = {
24086 +       .read =         generic_read_dir,
24087 +       .readdir =      proc_virtnet_readdir,
24088 +};
24089 +
24090 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24091 +       .getattr =      proc_virtnet_getattr,
24092 +       .lookup =       proc_virtnet_lookup,
24093 +};
24094 +
24095 +
24096 +
24097 +void proc_vx_init(void)
24098 +{
24099 +       struct proc_dir_entry *ent;
24100 +
24101 +       ent = proc_mkdir("virtual", 0);
24102 +       if (ent) {
24103 +               ent->proc_fops = &proc_virtual_dir_operations;
24104 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24105 +       }
24106 +       proc_virtual = ent;
24107 +
24108 +       ent = proc_mkdir("virtnet", 0);
24109 +       if (ent) {
24110 +               ent->proc_fops = &proc_virtnet_dir_operations;
24111 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24112 +       }
24113 +       proc_virtnet = ent;
24114 +}
24115 +
24116 +
24117 +
24118 +
24119 +/* per pid info */
24120 +
24121 +
24122 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24123 +{
24124 +       struct vx_info *vxi;
24125 +       char *orig = buffer;
24126 +
24127 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24128 +
24129 +       vxi = task_get_vx_info(p);
24130 +       if (!vxi)
24131 +               goto out;
24132 +
24133 +       buffer += sprintf(buffer, "BCaps:\t");
24134 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24135 +       buffer += sprintf(buffer, "\n");
24136 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24137 +               (unsigned long long)vxi->vx_ccaps);
24138 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24139 +               (unsigned long long)vxi->vx_flags);
24140 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24141 +
24142 +       put_vx_info(vxi);
24143 +out:
24144 +       return buffer - orig;
24145 +}
24146 +
24147 +
24148 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24149 +{
24150 +       struct nx_info *nxi;
24151 +       struct nx_addr_v4 *v4a;
24152 +#ifdef CONFIG_IPV6
24153 +       struct nx_addr_v6 *v6a;
24154 +#endif
24155 +       char *orig = buffer;
24156 +       int i;
24157 +
24158 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24159 +
24160 +       nxi = task_get_nx_info(p);
24161 +       if (!nxi)
24162 +               goto out;
24163 +
24164 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24165 +               (unsigned long long)nxi->nx_ncaps);
24166 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24167 +               (unsigned long long)nxi->nx_flags);
24168 +
24169 +       buffer += sprintf(buffer,
24170 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24171 +               NIPQUAD(nxi->v4_bcast.s_addr));
24172 +       buffer += sprintf (buffer,
24173 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24174 +               NIPQUAD(nxi->v4_lback.s_addr));
24175 +       if (!NX_IPV4(nxi))
24176 +               goto skip_v4;
24177 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24178 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24179 +                       i, NXAV4(v4a));
24180 +skip_v4:
24181 +#ifdef CONFIG_IPV6
24182 +       if (!NX_IPV6(nxi))
24183 +               goto skip_v6;
24184 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24185 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24186 +                       i, NXAV6(v6a));
24187 +skip_v6:
24188 +#endif
24189 +       put_nx_info(nxi);
24190 +out:
24191 +       return buffer - orig;
24192 +}
24193 +
24194 diff -NurpP --minimal linux-2.6.32/kernel/vserver/sched.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sched.c
24195 --- linux-2.6.32/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
24196 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sched.c   2009-12-03 20:04:56.000000000 +0100
24197 @@ -0,0 +1,414 @@
24198 +/*
24199 + *  linux/kernel/vserver/sched.c
24200 + *
24201 + *  Virtual Server: Scheduler Support
24202 + *
24203 + *  Copyright (C) 2004-2007  Herbert Pötzl
24204 + *
24205 + *  V0.01  adapted Sam Vilains version to 2.6.3
24206 + *  V0.02  removed legacy interface
24207 + *  V0.03  changed vcmds to vxi arg
24208 + *  V0.04  removed older and legacy interfaces
24209 + *
24210 + */
24211 +
24212 +#include <linux/vs_context.h>
24213 +#include <linux/vs_sched.h>
24214 +#include <linux/vserver/sched_cmd.h>
24215 +
24216 +#include <asm/uaccess.h>
24217 +
24218 +
24219 +#define vxd_check_range(val, min, max) do {            \
24220 +       vxlprintk((val < min) || (val > max),           \
24221 +               "check_range(%ld,%ld,%ld)",             \
24222 +               (long)val, (long)min, (long)max,        \
24223 +               __FILE__, __LINE__);                    \
24224 +       } while (0)
24225 +
24226 +
24227 +void vx_update_sched_param(struct _vx_sched *sched,
24228 +       struct _vx_sched_pc *sched_pc)
24229 +{
24230 +       unsigned int set_mask = sched->update_mask;
24231 +
24232 +       if (set_mask & VXSM_FILL_RATE)
24233 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24234 +       if (set_mask & VXSM_INTERVAL)
24235 +               sched_pc->interval[0] = sched->interval[0];
24236 +       if (set_mask & VXSM_FILL_RATE2)
24237 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24238 +       if (set_mask & VXSM_INTERVAL2)
24239 +               sched_pc->interval[1] = sched->interval[1];
24240 +       if (set_mask & VXSM_TOKENS)
24241 +               sched_pc->tokens = sched->tokens;
24242 +       if (set_mask & VXSM_TOKENS_MIN)
24243 +               sched_pc->tokens_min = sched->tokens_min;
24244 +       if (set_mask & VXSM_TOKENS_MAX)
24245 +               sched_pc->tokens_max = sched->tokens_max;
24246 +       if (set_mask & VXSM_PRIO_BIAS)
24247 +               sched_pc->prio_bias = sched->prio_bias;
24248 +
24249 +       if (set_mask & VXSM_IDLE_TIME)
24250 +               sched_pc->flags |= VXSF_IDLE_TIME;
24251 +       else
24252 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24253 +
24254 +       /* reset time */
24255 +       sched_pc->norm_time = jiffies;
24256 +}
24257 +
24258 +
24259 +/*
24260 + * recalculate the context's scheduling tokens
24261 + *
24262 + * ret > 0 : number of tokens available
24263 + * ret < 0 : on hold, check delta_min[]
24264 + *          -1 only jiffies
24265 + *          -2 also idle time
24266 + *
24267 + */
24268 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24269 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24270 +{
24271 +       long delta;
24272 +       long tokens = 0;
24273 +       int flags = sched_pc->flags;
24274 +
24275 +       /* how much time did pass? */
24276 +       delta = *norm_time - sched_pc->norm_time;
24277 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24278 +       vxd_check_range(delta, 0, INT_MAX);
24279 +
24280 +       if (delta >= sched_pc->interval[0]) {
24281 +               long tokens, integral;
24282 +
24283 +               /* calc integral token part */
24284 +               tokens = delta / sched_pc->interval[0];
24285 +               integral = tokens * sched_pc->interval[0];
24286 +               tokens *= sched_pc->fill_rate[0];
24287 +#ifdef CONFIG_VSERVER_HARDCPU
24288 +               delta_min[0] = delta - integral;
24289 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24290 +#endif
24291 +               /* advance time */
24292 +               sched_pc->norm_time += delta;
24293 +
24294 +               /* add tokens */
24295 +               sched_pc->tokens += tokens;
24296 +               sched_pc->token_time += tokens;
24297 +       } else
24298 +               delta_min[0] = delta;
24299 +
24300 +#ifdef CONFIG_VSERVER_IDLETIME
24301 +       if (!(flags & VXSF_IDLE_TIME))
24302 +               goto skip_idle;
24303 +
24304 +       /* how much was the idle skip? */
24305 +       delta = *idle_time - sched_pc->idle_time;
24306 +       vxd_check_range(delta, 0, INT_MAX);
24307 +
24308 +       if (delta >= sched_pc->interval[1]) {
24309 +               long tokens, integral;
24310 +
24311 +               /* calc fair share token part */
24312 +               tokens = delta / sched_pc->interval[1];
24313 +               integral = tokens * sched_pc->interval[1];
24314 +               tokens *= sched_pc->fill_rate[1];
24315 +               delta_min[1] = delta - integral;
24316 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24317 +
24318 +               /* advance idle time */
24319 +               sched_pc->idle_time += integral;
24320 +
24321 +               /* add tokens */
24322 +               sched_pc->tokens += tokens;
24323 +               sched_pc->token_time += tokens;
24324 +       } else
24325 +               delta_min[1] = delta;
24326 +skip_idle:
24327 +#endif
24328 +
24329 +       /* clip at maximum */
24330 +       if (sched_pc->tokens > sched_pc->tokens_max)
24331 +               sched_pc->tokens = sched_pc->tokens_max;
24332 +       tokens = sched_pc->tokens;
24333 +
24334 +       if ((flags & VXSF_ONHOLD)) {
24335 +               /* can we unhold? */
24336 +               if (tokens >= sched_pc->tokens_min) {
24337 +                       flags &= ~VXSF_ONHOLD;
24338 +                       sched_pc->hold_ticks +=
24339 +                               *norm_time - sched_pc->onhold;
24340 +               } else
24341 +                       goto on_hold;
24342 +       } else {
24343 +               /* put on hold? */
24344 +               if (tokens <= 0) {
24345 +                       flags |= VXSF_ONHOLD;
24346 +                       sched_pc->onhold = *norm_time;
24347 +                       goto on_hold;
24348 +               }
24349 +       }
24350 +       sched_pc->flags = flags;
24351 +       return tokens;
24352 +
24353 +on_hold:
24354 +       tokens = sched_pc->tokens_min - tokens;
24355 +       sched_pc->flags = flags;
24356 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24357 +
24358 +#ifdef CONFIG_VSERVER_HARDCPU
24359 +       /* next interval? */
24360 +       if (!sched_pc->fill_rate[0])
24361 +               delta_min[0] = HZ;
24362 +       else if (tokens > sched_pc->fill_rate[0])
24363 +               delta_min[0] += sched_pc->interval[0] *
24364 +                       tokens / sched_pc->fill_rate[0];
24365 +       else
24366 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24367 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24368 +
24369 +#ifdef CONFIG_VSERVER_IDLETIME
24370 +       if (!(flags & VXSF_IDLE_TIME))
24371 +               return -1;
24372 +
24373 +       /* next interval? */
24374 +       if (!sched_pc->fill_rate[1])
24375 +               delta_min[1] = HZ;
24376 +       else if (tokens > sched_pc->fill_rate[1])
24377 +               delta_min[1] += sched_pc->interval[1] *
24378 +                       tokens / sched_pc->fill_rate[1];
24379 +       else
24380 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24381 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24382 +
24383 +       return -2;
24384 +#else
24385 +       return -1;
24386 +#endif /* CONFIG_VSERVER_IDLETIME */
24387 +#else
24388 +       return 0;
24389 +#endif /* CONFIG_VSERVER_HARDCPU */
24390 +}
24391 +
24392 +static inline unsigned long msec_to_ticks(unsigned long msec)
24393 +{
24394 +       return msecs_to_jiffies(msec);
24395 +}
24396 +
24397 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24398 +{
24399 +       return jiffies_to_msecs(ticks);
24400 +}
24401 +
24402 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24403 +{
24404 +       return jiffies_to_usecs(ticks);
24405 +}
24406 +
24407 +
24408 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24409 +{
24410 +       unsigned int set_mask = data->mask;
24411 +       unsigned int update_mask;
24412 +       int i, cpu;
24413 +
24414 +       /* Sanity check data values */
24415 +       if (data->tokens_max <= 0)
24416 +               data->tokens_max = HZ;
24417 +       if (data->tokens_min < 0)
24418 +               data->tokens_min = HZ / 3;
24419 +       if (data->tokens_min >= data->tokens_max)
24420 +               data->tokens_min = data->tokens_max;
24421 +
24422 +       if (data->prio_bias > MAX_PRIO_BIAS)
24423 +               data->prio_bias = MAX_PRIO_BIAS;
24424 +       if (data->prio_bias < MIN_PRIO_BIAS)
24425 +               data->prio_bias = MIN_PRIO_BIAS;
24426 +
24427 +       spin_lock(&vxi->sched.tokens_lock);
24428 +
24429 +       /* sync up on delayed updates */
24430 +       for_each_cpu_mask(cpu, vxi->sched.update)
24431 +               vx_update_sched_param(&vxi->sched,
24432 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24433 +
24434 +       if (set_mask & VXSM_FILL_RATE)
24435 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24436 +       if (set_mask & VXSM_FILL_RATE2)
24437 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24438 +       if (set_mask & VXSM_INTERVAL)
24439 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24440 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24441 +       if (set_mask & VXSM_INTERVAL2)
24442 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24443 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24444 +       if (set_mask & VXSM_TOKENS)
24445 +               vxi->sched.tokens = data->tokens;
24446 +       if (set_mask & VXSM_TOKENS_MIN)
24447 +               vxi->sched.tokens_min = data->tokens_min;
24448 +       if (set_mask & VXSM_TOKENS_MAX)
24449 +               vxi->sched.tokens_max = data->tokens_max;
24450 +       if (set_mask & VXSM_PRIO_BIAS)
24451 +               vxi->sched.prio_bias = data->prio_bias;
24452 +
24453 +       /* Sanity check rate/interval */
24454 +       for (i = 0; i < 2; i++) {
24455 +               if (data->fill_rate[i] < 0)
24456 +                       data->fill_rate[i] = 0;
24457 +               if (data->interval[i] <= 0)
24458 +                       data->interval[i] = HZ;
24459 +       }
24460 +
24461 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24462 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24463 +       vxi->sched.update_mask = update_mask;
24464 +
24465 +#ifdef CONFIG_SMP
24466 +       rmb();
24467 +       if (set_mask & VXSM_CPU_ID) {
24468 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24469 +               cpus_and(vxi->sched.update, cpu_online_map,
24470 +                       vxi->sched.update);
24471 +       } else
24472 +               vxi->sched.update = cpu_online_map;
24473 +
24474 +       /* forced reload? */
24475 +       if (set_mask & VXSM_FORCE) {
24476 +               for_each_cpu_mask(cpu, vxi->sched.update)
24477 +                       vx_update_sched_param(&vxi->sched,
24478 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24479 +               vxi->sched.update = CPU_MASK_NONE;
24480 +       }
24481 +#else
24482 +       /* on UP we update immediately */
24483 +       vx_update_sched_param(&vxi->sched,
24484 +               &vx_per_cpu(vxi, sched_pc, 0));
24485 +#endif
24486 +
24487 +       spin_unlock(&vxi->sched.tokens_lock);
24488 +       return 0;
24489 +}
24490 +
24491 +
24492 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24493 +#define COPY_PRI(C) C(prio_bias)
24494 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24495 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24496 +                   C(fill_rate[1]); C(interval[1]);
24497 +
24498 +#define COPY_VALUE(name) vc_data.name = data->name
24499 +
24500 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24501 +{
24502 +       struct vcmd_sched_v5 vc_data;
24503 +
24504 +       vc_data.mask = data->set_mask;
24505 +       COPY_IDS(COPY_VALUE);
24506 +       COPY_PRI(COPY_VALUE);
24507 +       COPY_TOK(COPY_VALUE);
24508 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24509 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24510 +       return do_set_sched(vxi, &vc_data);
24511 +}
24512 +
24513 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24514 +{
24515 +       struct vcmd_set_sched_v4 vc_data;
24516 +
24517 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24518 +               return -EFAULT;
24519 +
24520 +       return do_set_sched_v4(vxi, &vc_data);
24521 +}
24522 +
24523 +       /* latest interface is v5 */
24524 +
24525 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24526 +{
24527 +       struct vcmd_sched_v5 vc_data;
24528 +
24529 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24530 +               return -EFAULT;
24531 +
24532 +       return do_set_sched(vxi, &vc_data);
24533 +}
24534 +
24535 +
24536 +#define COPY_PRI(C) C(prio_bias)
24537 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24538 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24539 +                   C(fill_rate[1]); C(interval[1]);
24540 +
24541 +#define COPY_VALUE(name) vc_data.name = data->name
24542 +
24543 +
24544 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24545 +{
24546 +       struct vcmd_sched_v5 vc_data;
24547 +
24548 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24549 +               return -EFAULT;
24550 +
24551 +       if (vc_data.mask & VXSM_CPU_ID) {
24552 +               int cpu = vc_data.cpu_id;
24553 +               struct _vx_sched_pc *data;
24554 +
24555 +               if (!cpu_possible(cpu))
24556 +                       return -EINVAL;
24557 +
24558 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24559 +               COPY_TOK(COPY_VALUE);
24560 +               COPY_PRI(COPY_VALUE);
24561 +               COPY_FRI(COPY_VALUE);
24562 +
24563 +               if (data->flags & VXSF_IDLE_TIME)
24564 +                       vc_data.mask |= VXSM_IDLE_TIME;
24565 +       } else {
24566 +               struct _vx_sched *data = &vxi->sched;
24567 +
24568 +               COPY_TOK(COPY_VALUE);
24569 +               COPY_PRI(COPY_VALUE);
24570 +               COPY_FRI(COPY_VALUE);
24571 +       }
24572 +
24573 +       if (vc_data.mask & VXSM_MSEC) {
24574 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24575 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24576 +       }
24577 +
24578 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24579 +               return -EFAULT;
24580 +       return 0;
24581 +}
24582 +
24583 +
24584 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24585 +{
24586 +       struct vcmd_sched_info vc_data;
24587 +       int cpu;
24588 +
24589 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24590 +               return -EFAULT;
24591 +
24592 +       cpu = vc_data.cpu_id;
24593 +       if (!cpu_possible(cpu))
24594 +               return -EINVAL;
24595 +
24596 +       if (vxi) {
24597 +               struct _vx_sched_pc *sched_pc =
24598 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24599 +
24600 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24601 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24602 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24603 +               vc_data.vavavoom = sched_pc->vavavoom;
24604 +       }
24605 +       vc_data.token_usec = ticks_to_usec(1);
24606 +
24607 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24608 +               return -EFAULT;
24609 +       return 0;
24610 +}
24611 +
24612 diff -NurpP --minimal linux-2.6.32/kernel/vserver/sched_init.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sched_init.h
24613 --- linux-2.6.32/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
24614 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sched_init.h      2009-12-03 20:04:56.000000000 +0100
24615 @@ -0,0 +1,50 @@
24616 +
24617 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24618 +{
24619 +       static struct lock_class_key tokens_lock_key;
24620 +
24621 +       /* scheduling; hard code starting values as constants */
24622 +       sched->fill_rate[0]     = 1;
24623 +       sched->interval[0]      = 4;
24624 +       sched->fill_rate[1]     = 1;
24625 +       sched->interval[1]      = 8;
24626 +       sched->tokens           = HZ >> 2;
24627 +       sched->tokens_min       = HZ >> 4;
24628 +       sched->tokens_max       = HZ >> 1;
24629 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24630 +       sched->prio_bias        = 0;
24631 +
24632 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24633 +}
24634 +
24635 +static inline
24636 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24637 +{
24638 +       sched_pc->fill_rate[0]  = 1;
24639 +       sched_pc->interval[0]   = 4;
24640 +       sched_pc->fill_rate[1]  = 1;
24641 +       sched_pc->interval[1]   = 8;
24642 +       sched_pc->tokens        = HZ >> 2;
24643 +       sched_pc->tokens_min    = HZ >> 4;
24644 +       sched_pc->tokens_max    = HZ >> 1;
24645 +       sched_pc->prio_bias     = 0;
24646 +       sched_pc->vavavoom      = 0;
24647 +       sched_pc->token_time    = 0;
24648 +       sched_pc->idle_time     = 0;
24649 +       sched_pc->norm_time     = jiffies;
24650 +
24651 +       sched_pc->user_ticks = 0;
24652 +       sched_pc->sys_ticks = 0;
24653 +       sched_pc->hold_ticks = 0;
24654 +}
24655 +
24656 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24657 +{
24658 +       return;
24659 +}
24660 +
24661 +static inline
24662 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24663 +{
24664 +       return;
24665 +}
24666 diff -NurpP --minimal linux-2.6.32/kernel/vserver/sched_proc.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sched_proc.h
24667 --- linux-2.6.32/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
24668 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sched_proc.h      2009-12-03 20:04:56.000000000 +0100
24669 @@ -0,0 +1,57 @@
24670 +#ifndef _VX_SCHED_PROC_H
24671 +#define _VX_SCHED_PROC_H
24672 +
24673 +
24674 +static inline
24675 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24676 +{
24677 +       int length = 0;
24678 +
24679 +       length += sprintf(buffer,
24680 +               "FillRate:\t%8d,%d\n"
24681 +               "Interval:\t%8d,%d\n"
24682 +               "TokensMin:\t%8d\n"
24683 +               "TokensMax:\t%8d\n"
24684 +               "PrioBias:\t%8d\n",
24685 +               sched->fill_rate[0],
24686 +               sched->fill_rate[1],
24687 +               sched->interval[0],
24688 +               sched->interval[1],
24689 +               sched->tokens_min,
24690 +               sched->tokens_max,
24691 +               sched->prio_bias);
24692 +       return length;
24693 +}
24694 +
24695 +static inline
24696 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24697 +       char *buffer, int cpu)
24698 +{
24699 +       int length = 0;
24700 +
24701 +       length += sprintf(buffer + length,
24702 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24703 +               (unsigned long long)sched_pc->user_ticks,
24704 +               (unsigned long long)sched_pc->sys_ticks,
24705 +               (unsigned long long)sched_pc->hold_ticks,
24706 +               sched_pc->token_time,
24707 +               sched_pc->idle_time);
24708 +       length += sprintf(buffer + length,
24709 +               " %c%c %d %d %d %d/%d %d/%d",
24710 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24711 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24712 +               sched_pc->tokens,
24713 +               sched_pc->tokens_min,
24714 +               sched_pc->tokens_max,
24715 +               sched_pc->fill_rate[0],
24716 +               sched_pc->interval[0],
24717 +               sched_pc->fill_rate[1],
24718 +               sched_pc->interval[1]);
24719 +       length += sprintf(buffer + length,
24720 +               " %d %d\n",
24721 +               sched_pc->prio_bias,
24722 +               sched_pc->vavavoom);
24723 +       return length;
24724 +}
24725 +
24726 +#endif /* _VX_SCHED_PROC_H */
24727 diff -NurpP --minimal linux-2.6.32/kernel/vserver/signal.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/signal.c
24728 --- linux-2.6.32/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
24729 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/signal.c  2009-12-03 20:04:56.000000000 +0100
24730 @@ -0,0 +1,132 @@
24731 +/*
24732 + *  linux/kernel/vserver/signal.c
24733 + *
24734 + *  Virtual Server: Signal Support
24735 + *
24736 + *  Copyright (C) 2003-2007  Herbert Pötzl
24737 + *
24738 + *  V0.01  broken out from vcontext V0.05
24739 + *  V0.02  changed vcmds to vxi arg
24740 + *  V0.03  adjusted siginfo for kill
24741 + *
24742 + */
24743 +
24744 +#include <asm/uaccess.h>
24745 +
24746 +#include <linux/vs_context.h>
24747 +#include <linux/vs_pid.h>
24748 +#include <linux/vserver/signal_cmd.h>
24749 +
24750 +
24751 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24752 +{
24753 +       int retval, count = 0;
24754 +       struct task_struct *p;
24755 +       struct siginfo *sip = SEND_SIG_PRIV;
24756 +
24757 +       retval = -ESRCH;
24758 +       vxdprintk(VXD_CBIT(misc, 4),
24759 +               "vx_info_kill(%p[#%d],%d,%d)*",
24760 +               vxi, vxi->vx_id, pid, sig);
24761 +       read_lock(&tasklist_lock);
24762 +       switch (pid) {
24763 +       case  0:
24764 +       case -1:
24765 +               for_each_process(p) {
24766 +                       int err = 0;
24767 +
24768 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24769 +                               (pid && vxi->vx_initpid == p->pid))
24770 +                               continue;
24771 +
24772 +                       err = group_send_sig_info(sig, sip, p);
24773 +                       ++count;
24774 +                       if (err != -EPERM)
24775 +                               retval = err;
24776 +               }
24777 +               break;
24778 +
24779 +       case 1:
24780 +               if (vxi->vx_initpid) {
24781 +                       pid = vxi->vx_initpid;
24782 +                       /* for now, only SIGINT to private init ... */
24783 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24784 +                               /* ... as long as there are tasks left */
24785 +                               (atomic_read(&vxi->vx_tasks) > 1))
24786 +                               sig = SIGINT;
24787 +               }
24788 +               /* fallthrough */
24789 +       default:
24790 +               p = find_task_by_real_pid(pid);
24791 +               if (p) {
24792 +                       if (vx_task_xid(p) == vxi->vx_id)
24793 +                               retval = group_send_sig_info(sig, sip, p);
24794 +               }
24795 +               break;
24796 +       }
24797 +       read_unlock(&tasklist_lock);
24798 +       vxdprintk(VXD_CBIT(misc, 4),
24799 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24800 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24801 +       return retval;
24802 +}
24803 +
24804 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24805 +{
24806 +       struct vcmd_ctx_kill_v0 vc_data;
24807 +
24808 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24809 +               return -EFAULT;
24810 +
24811 +       /* special check to allow guest shutdown */
24812 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24813 +               /* forbid killall pid=0 when init is present */
24814 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24815 +               (vc_data.pid > 1)))
24816 +               return -EACCES;
24817 +
24818 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24819 +}
24820 +
24821 +
24822 +static int __wait_exit(struct vx_info *vxi)
24823 +{
24824 +       DECLARE_WAITQUEUE(wait, current);
24825 +       int ret = 0;
24826 +
24827 +       add_wait_queue(&vxi->vx_wait, &wait);
24828 +       set_current_state(TASK_INTERRUPTIBLE);
24829 +
24830 +wait:
24831 +       if (vx_info_state(vxi,
24832 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24833 +               goto out;
24834 +       if (signal_pending(current)) {
24835 +               ret = -ERESTARTSYS;
24836 +               goto out;
24837 +       }
24838 +       schedule();
24839 +       goto wait;
24840 +
24841 +out:
24842 +       set_current_state(TASK_RUNNING);
24843 +       remove_wait_queue(&vxi->vx_wait, &wait);
24844 +       return ret;
24845 +}
24846 +
24847 +
24848 +
24849 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24850 +{
24851 +       struct vcmd_wait_exit_v0 vc_data;
24852 +       int ret;
24853 +
24854 +       ret = __wait_exit(vxi);
24855 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24856 +       vc_data.exit_code = vxi->exit_code;
24857 +
24858 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24859 +               ret = -EFAULT;
24860 +       return ret;
24861 +}
24862 +
24863 diff -NurpP --minimal linux-2.6.32/kernel/vserver/space.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/space.c
24864 --- linux-2.6.32/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
24865 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/space.c   2009-12-03 20:04:56.000000000 +0100
24866 @@ -0,0 +1,375 @@
24867 +/*
24868 + *  linux/kernel/vserver/space.c
24869 + *
24870 + *  Virtual Server: Context Space Support
24871 + *
24872 + *  Copyright (C) 2003-2007  Herbert Pötzl
24873 + *
24874 + *  V0.01  broken out from context.c 0.07
24875 + *  V0.02  added task locking for namespace
24876 + *  V0.03  broken out vx_enter_namespace
24877 + *  V0.04  added *space support and commands
24878 + *
24879 + */
24880 +
24881 +#include <linux/utsname.h>
24882 +#include <linux/nsproxy.h>
24883 +#include <linux/err.h>
24884 +#include <linux/fs_struct.h>
24885 +#include <asm/uaccess.h>
24886 +
24887 +#include <linux/vs_context.h>
24888 +#include <linux/vserver/space.h>
24889 +#include <linux/vserver/space_cmd.h>
24890 +
24891 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24892 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24893 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24894 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24895 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24896 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24897 +
24898 +
24899 +/* namespace functions */
24900 +
24901 +#include <linux/mnt_namespace.h>
24902 +#include <linux/user_namespace.h>
24903 +#include <linux/pid_namespace.h>
24904 +#include <linux/ipc_namespace.h>
24905 +#include <net/net_namespace.h>
24906 +
24907 +
24908 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24909 +       .mask = CLONE_FS |
24910 +               CLONE_NEWNS |
24911 +               CLONE_NEWUTS |
24912 +               CLONE_NEWIPC |
24913 +               CLONE_NEWUSER |
24914 +               0
24915 +};
24916 +
24917 +static const struct vcmd_space_mask_v1 space_mask = {
24918 +       .mask = CLONE_FS |
24919 +               CLONE_NEWNS |
24920 +               CLONE_NEWUTS |
24921 +               CLONE_NEWIPC |
24922 +               CLONE_NEWUSER |
24923 +#ifdef CONFIG_PID_NS
24924 +               CLONE_NEWPID |
24925 +#endif
24926 +#ifdef CONFIG_NET_NS
24927 +               CLONE_NEWNET |
24928 +#endif
24929 +               0
24930 +};
24931 +
24932 +static const struct vcmd_space_mask_v1 default_space_mask = {
24933 +       .mask = CLONE_FS |
24934 +               CLONE_NEWNS |
24935 +               CLONE_NEWUTS |
24936 +               CLONE_NEWIPC |
24937 +               CLONE_NEWUSER |
24938 +#ifdef CONFIG_PID_NS
24939 +//             CLONE_NEWPID |
24940 +#endif
24941 +               0
24942 +};
24943 +
24944 +/*
24945 + *     build a new nsproxy mix
24946 + *      assumes that both proxies are 'const'
24947 + *     does not touch nsproxy refcounts
24948 + *     will hold a reference on the result.
24949 + */
24950 +
24951 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24952 +       struct nsproxy *new_nsproxy, unsigned long mask)
24953 +{
24954 +       struct mnt_namespace *old_ns;
24955 +       struct uts_namespace *old_uts;
24956 +       struct ipc_namespace *old_ipc;
24957 +#ifdef CONFIG_PID_NS
24958 +       struct pid_namespace *old_pid;
24959 +#endif
24960 +#ifdef CONFIG_NET_NS
24961 +       struct net *old_net;
24962 +#endif
24963 +       struct nsproxy *nsproxy;
24964 +
24965 +       nsproxy = copy_nsproxy(old_nsproxy);
24966 +       if (!nsproxy)
24967 +               goto out;
24968 +
24969 +       if (mask & CLONE_NEWNS) {
24970 +               old_ns = nsproxy->mnt_ns;
24971 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24972 +               if (nsproxy->mnt_ns)
24973 +                       get_mnt_ns(nsproxy->mnt_ns);
24974 +       } else
24975 +               old_ns = NULL;
24976 +
24977 +       if (mask & CLONE_NEWUTS) {
24978 +               old_uts = nsproxy->uts_ns;
24979 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24980 +               if (nsproxy->uts_ns)
24981 +                       get_uts_ns(nsproxy->uts_ns);
24982 +       } else
24983 +               old_uts = NULL;
24984 +
24985 +       if (mask & CLONE_NEWIPC) {
24986 +               old_ipc = nsproxy->ipc_ns;
24987 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24988 +               if (nsproxy->ipc_ns)
24989 +                       get_ipc_ns(nsproxy->ipc_ns);
24990 +       } else
24991 +               old_ipc = NULL;
24992 +
24993 +#ifdef CONFIG_PID_NS
24994 +       if (mask & CLONE_NEWPID) {
24995 +               old_pid = nsproxy->pid_ns;
24996 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24997 +               if (nsproxy->pid_ns)
24998 +                       get_pid_ns(nsproxy->pid_ns);
24999 +       } else
25000 +               old_pid = NULL;
25001 +#endif
25002 +#ifdef CONFIG_NET_NS
25003 +       if (mask & CLONE_NEWNET) {
25004 +               old_net = nsproxy->net_ns;
25005 +               nsproxy->net_ns = new_nsproxy->net_ns;
25006 +               if (nsproxy->net_ns)
25007 +                       get_net(nsproxy->net_ns);
25008 +       } else
25009 +               old_net = NULL;
25010 +#endif
25011 +       if (old_ns)
25012 +               put_mnt_ns(old_ns);
25013 +       if (old_uts)
25014 +               put_uts_ns(old_uts);
25015 +       if (old_ipc)
25016 +               put_ipc_ns(old_ipc);
25017 +#ifdef CONFIG_PID_NS
25018 +       if (old_pid)
25019 +               put_pid_ns(old_pid);
25020 +#endif
25021 +#ifdef CONFIG_NET_NS
25022 +       if (old_net)
25023 +               put_net(old_net);
25024 +#endif
25025 +out:
25026 +       return nsproxy;
25027 +}
25028 +
25029 +
25030 +/*
25031 + *     merge two nsproxy structs into a new one.
25032 + *     will hold a reference on the result.
25033 + */
25034 +
25035 +static inline
25036 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25037 +       struct nsproxy *proxy, unsigned long mask)
25038 +{
25039 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25040 +
25041 +       if (!proxy)
25042 +               return NULL;
25043 +
25044 +       if (mask) {
25045 +               /* vs_mix_nsproxy returns with reference */
25046 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25047 +                       proxy, mask);
25048 +       }
25049 +       get_nsproxy(proxy);
25050 +       return proxy;
25051 +}
25052 +
25053 +
25054 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25055 +{
25056 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25057 +       struct fs_struct *fs_cur, *fs = NULL;
25058 +       int ret, kill = 0;
25059 +
25060 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
25061 +               vxi, vxi->vx_id, mask, index);
25062 +
25063 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25064 +               return -EACCES;
25065 +
25066 +       if (!mask)
25067 +               mask = vxi->vx_nsmask[index];
25068 +
25069 +       if ((mask & vxi->vx_nsmask[index]) != mask)
25070 +               return -EINVAL;
25071 +
25072 +       if (mask & CLONE_FS) {
25073 +               fs = copy_fs_struct(vxi->vx_fs[index]);
25074 +               if (!fs)
25075 +                       return -ENOMEM;
25076 +       }
25077 +       proxy = vxi->vx_nsproxy[index];
25078 +
25079 +       vxdprintk(VXD_CBIT(space, 9),
25080 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
25081 +               vxi, vxi->vx_id, mask, index, proxy, fs);
25082 +
25083 +       task_lock(current);
25084 +       fs_cur = current->fs;
25085 +
25086 +       if (mask & CLONE_FS) {
25087 +               write_lock(&fs_cur->lock);
25088 +               current->fs = fs;
25089 +               kill = !--fs_cur->users;
25090 +               write_unlock(&fs_cur->lock);
25091 +       }
25092 +
25093 +       proxy_cur = current->nsproxy;
25094 +       get_nsproxy(proxy_cur);
25095 +       task_unlock(current);
25096 +
25097 +       if (kill)
25098 +               free_fs_struct(fs_cur);
25099 +
25100 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25101 +       if (IS_ERR(proxy_new)) {
25102 +               ret = PTR_ERR(proxy_new);
25103 +               goto out_put;
25104 +       }
25105 +
25106 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25107 +       ret = 0;
25108 +
25109 +       if (proxy_new)
25110 +               put_nsproxy(proxy_new);
25111 +out_put:
25112 +       if (proxy_cur)
25113 +               put_nsproxy(proxy_cur);
25114 +       return ret;
25115 +}
25116 +
25117 +
25118 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25119 +{
25120 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25121 +       struct fs_struct *fs_vxi, *fs;
25122 +       int ret, kill = 0;
25123 +
25124 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
25125 +               vxi, vxi->vx_id, mask, index);
25126 +#if 0
25127 +       if (!mask)
25128 +               mask = default_space_mask.mask;
25129 +#endif
25130 +       if ((mask & space_mask.mask) != mask)
25131 +               return -EINVAL;
25132 +
25133 +       proxy_vxi = vxi->vx_nsproxy[index];
25134 +       fs_vxi = vxi->vx_fs[index];
25135 +
25136 +       if (mask & CLONE_FS) {
25137 +               fs = copy_fs_struct(current->fs);
25138 +               if (!fs)
25139 +                       return -ENOMEM;
25140 +       }
25141 +
25142 +       task_lock(current);
25143 +
25144 +       if (mask & CLONE_FS) {
25145 +               write_lock(&fs_vxi->lock);
25146 +               vxi->vx_fs[index] = fs;
25147 +               kill = !--fs_vxi->users;
25148 +               write_unlock(&fs_vxi->lock);
25149 +       }
25150 +
25151 +       proxy_cur = current->nsproxy;
25152 +       get_nsproxy(proxy_cur);
25153 +       task_unlock(current);
25154 +
25155 +       if (kill)
25156 +               free_fs_struct(fs_vxi);
25157 +
25158 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25159 +       if (IS_ERR(proxy_new)) {
25160 +               ret = PTR_ERR(proxy_new);
25161 +               goto out_put;
25162 +       }
25163 +
25164 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25165 +       vxi->vx_nsmask[index] |= mask;
25166 +       ret = 0;
25167 +
25168 +       if (proxy_new)
25169 +               put_nsproxy(proxy_new);
25170 +out_put:
25171 +       if (proxy_cur)
25172 +               put_nsproxy(proxy_cur);
25173 +       return ret;
25174 +}
25175 +
25176 +
25177 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25178 +{
25179 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25180 +
25181 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25182 +               return -EFAULT;
25183 +
25184 +       return vx_enter_space(vxi, vc_data.mask, 0);
25185 +}
25186 +
25187 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25188 +{
25189 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25190 +
25191 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25192 +               return -EFAULT;
25193 +
25194 +       if (vc_data.index >= VX_SPACES)
25195 +               return -EINVAL;
25196 +
25197 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25198 +}
25199 +
25200 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25201 +{
25202 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25203 +
25204 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25205 +               return -EFAULT;
25206 +
25207 +       return vx_set_space(vxi, vc_data.mask, 0);
25208 +}
25209 +
25210 +int vc_set_space(struct vx_info *vxi, void __user *data)
25211 +{
25212 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25213 +
25214 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25215 +               return -EFAULT;
25216 +
25217 +       if (vc_data.index >= VX_SPACES)
25218 +               return -EINVAL;
25219 +
25220 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25221 +}
25222 +
25223 +int vc_get_space_mask(void __user *data, int type)
25224 +{
25225 +       const struct vcmd_space_mask_v1 *mask;
25226 +
25227 +       if (type == 0)
25228 +               mask = &space_mask_v0;
25229 +       else if (type == 1)
25230 +               mask = &space_mask;
25231 +       else
25232 +               mask = &default_space_mask;
25233 +
25234 +       vxdprintk(VXD_CBIT(space, 10),
25235 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25236 +
25237 +       if (copy_to_user(data, mask, sizeof(*mask)))
25238 +               return -EFAULT;
25239 +       return 0;
25240 +}
25241 +
25242 diff -NurpP --minimal linux-2.6.32/kernel/vserver/switch.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/switch.c
25243 --- linux-2.6.32/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
25244 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/switch.c  2009-12-03 20:04:56.000000000 +0100
25245 @@ -0,0 +1,546 @@
25246 +/*
25247 + *  linux/kernel/vserver/switch.c
25248 + *
25249 + *  Virtual Server: Syscall Switch
25250 + *
25251 + *  Copyright (C) 2003-2007  Herbert Pötzl
25252 + *
25253 + *  V0.01  syscall switch
25254 + *  V0.02  added signal to context
25255 + *  V0.03  added rlimit functions
25256 + *  V0.04  added iattr, task/xid functions
25257 + *  V0.05  added debug/history stuff
25258 + *  V0.06  added compat32 layer
25259 + *  V0.07  vcmd args and perms
25260 + *  V0.08  added status commands
25261 + *  V0.09  added tag commands
25262 + *  V0.10  added oom bias
25263 + *  V0.11  added device commands
25264 + *
25265 + */
25266 +
25267 +#include <linux/vs_context.h>
25268 +#include <linux/vs_network.h>
25269 +#include <linux/vserver/switch.h>
25270 +
25271 +#include "vci_config.h"
25272 +
25273 +
25274 +static inline
25275 +int vc_get_version(uint32_t id)
25276 +{
25277 +       return VCI_VERSION;
25278 +}
25279 +
25280 +static inline
25281 +int vc_get_vci(uint32_t id)
25282 +{
25283 +       return vci_kernel_config();
25284 +}
25285 +
25286 +#include <linux/vserver/context_cmd.h>
25287 +#include <linux/vserver/cvirt_cmd.h>
25288 +#include <linux/vserver/cacct_cmd.h>
25289 +#include <linux/vserver/limit_cmd.h>
25290 +#include <linux/vserver/network_cmd.h>
25291 +#include <linux/vserver/sched_cmd.h>
25292 +#include <linux/vserver/debug_cmd.h>
25293 +#include <linux/vserver/inode_cmd.h>
25294 +#include <linux/vserver/dlimit_cmd.h>
25295 +#include <linux/vserver/signal_cmd.h>
25296 +#include <linux/vserver/space_cmd.h>
25297 +#include <linux/vserver/tag_cmd.h>
25298 +#include <linux/vserver/device_cmd.h>
25299 +
25300 +#include <linux/vserver/inode.h>
25301 +#include <linux/vserver/dlimit.h>
25302 +
25303 +
25304 +#ifdef CONFIG_COMPAT
25305 +#define __COMPAT(name, id, data, compat)       \
25306 +       (compat) ? name ## _x32(id, data) : name(id, data)
25307 +#define __COMPAT_NO_ID(name, data, compat)     \
25308 +       (compat) ? name ## _x32(data) : name(data)
25309 +#else
25310 +#define __COMPAT(name, id, data, compat)       \
25311 +       name(id, data)
25312 +#define __COMPAT_NO_ID(name, data, compat)     \
25313 +       name(data)
25314 +#endif
25315 +
25316 +
25317 +static inline
25318 +long do_vcmd(uint32_t cmd, uint32_t id,
25319 +       struct vx_info *vxi, struct nx_info *nxi,
25320 +       void __user *data, int compat)
25321 +{
25322 +       switch (cmd) {
25323 +
25324 +       case VCMD_get_version:
25325 +               return vc_get_version(id);
25326 +       case VCMD_get_vci:
25327 +               return vc_get_vci(id);
25328 +
25329 +       case VCMD_task_xid:
25330 +               return vc_task_xid(id);
25331 +       case VCMD_vx_info:
25332 +               return vc_vx_info(vxi, data);
25333 +
25334 +       case VCMD_task_nid:
25335 +               return vc_task_nid(id);
25336 +       case VCMD_nx_info:
25337 +               return vc_nx_info(nxi, data);
25338 +
25339 +       case VCMD_task_tag:
25340 +               return vc_task_tag(id);
25341 +
25342 +       case VCMD_set_space_v1:
25343 +               return vc_set_space_v1(vxi, data);
25344 +       /* this is version 2 */
25345 +       case VCMD_set_space:
25346 +               return vc_set_space(vxi, data);
25347 +
25348 +       case VCMD_get_space_mask_v0:
25349 +               return vc_get_space_mask(data, 0);
25350 +       /* this is version 1 */
25351 +       case VCMD_get_space_mask:
25352 +               return vc_get_space_mask(data, 1);
25353 +
25354 +       case VCMD_get_space_default:
25355 +               return vc_get_space_mask(data, -1);
25356 +
25357 +#ifdef CONFIG_IA32_EMULATION
25358 +       case VCMD_get_rlimit:
25359 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25360 +       case VCMD_set_rlimit:
25361 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25362 +#else
25363 +       case VCMD_get_rlimit:
25364 +               return vc_get_rlimit(vxi, data);
25365 +       case VCMD_set_rlimit:
25366 +               return vc_set_rlimit(vxi, data);
25367 +#endif
25368 +       case VCMD_get_rlimit_mask:
25369 +               return vc_get_rlimit_mask(id, data);
25370 +       case VCMD_reset_hits:
25371 +               return vc_reset_hits(vxi, data);
25372 +       case VCMD_reset_minmax:
25373 +               return vc_reset_minmax(vxi, data);
25374 +
25375 +       case VCMD_get_vhi_name:
25376 +               return vc_get_vhi_name(vxi, data);
25377 +       case VCMD_set_vhi_name:
25378 +               return vc_set_vhi_name(vxi, data);
25379 +
25380 +       case VCMD_ctx_stat:
25381 +               return vc_ctx_stat(vxi, data);
25382 +       case VCMD_virt_stat:
25383 +               return vc_virt_stat(vxi, data);
25384 +       case VCMD_sock_stat:
25385 +               return vc_sock_stat(vxi, data);
25386 +       case VCMD_rlimit_stat:
25387 +               return vc_rlimit_stat(vxi, data);
25388 +
25389 +       case VCMD_set_cflags:
25390 +               return vc_set_cflags(vxi, data);
25391 +       case VCMD_get_cflags:
25392 +               return vc_get_cflags(vxi, data);
25393 +
25394 +       /* this is version 1 */
25395 +       case VCMD_set_ccaps:
25396 +               return vc_set_ccaps(vxi, data);
25397 +       /* this is version 1 */
25398 +       case VCMD_get_ccaps:
25399 +               return vc_get_ccaps(vxi, data);
25400 +       case VCMD_set_bcaps:
25401 +               return vc_set_bcaps(vxi, data);
25402 +       case VCMD_get_bcaps:
25403 +               return vc_get_bcaps(vxi, data);
25404 +
25405 +       case VCMD_set_badness:
25406 +               return vc_set_badness(vxi, data);
25407 +       case VCMD_get_badness:
25408 +               return vc_get_badness(vxi, data);
25409 +
25410 +       case VCMD_set_nflags:
25411 +               return vc_set_nflags(nxi, data);
25412 +       case VCMD_get_nflags:
25413 +               return vc_get_nflags(nxi, data);
25414 +
25415 +       case VCMD_set_ncaps:
25416 +               return vc_set_ncaps(nxi, data);
25417 +       case VCMD_get_ncaps:
25418 +               return vc_get_ncaps(nxi, data);
25419 +
25420 +       case VCMD_set_sched_v4:
25421 +               return vc_set_sched_v4(vxi, data);
25422 +       /* this is version 5 */
25423 +       case VCMD_set_sched:
25424 +               return vc_set_sched(vxi, data);
25425 +       case VCMD_get_sched:
25426 +               return vc_get_sched(vxi, data);
25427 +       case VCMD_sched_info:
25428 +               return vc_sched_info(vxi, data);
25429 +
25430 +       case VCMD_add_dlimit:
25431 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25432 +       case VCMD_rem_dlimit:
25433 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25434 +       case VCMD_set_dlimit:
25435 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25436 +       case VCMD_get_dlimit:
25437 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25438 +
25439 +       case VCMD_ctx_kill:
25440 +               return vc_ctx_kill(vxi, data);
25441 +
25442 +       case VCMD_wait_exit:
25443 +               return vc_wait_exit(vxi, data);
25444 +
25445 +       case VCMD_get_iattr:
25446 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25447 +       case VCMD_set_iattr:
25448 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25449 +
25450 +       case VCMD_fget_iattr:
25451 +               return vc_fget_iattr(id, data);
25452 +       case VCMD_fset_iattr:
25453 +               return vc_fset_iattr(id, data);
25454 +
25455 +       case VCMD_enter_space_v0:
25456 +               return vc_enter_space_v1(vxi, NULL);
25457 +       case VCMD_enter_space_v1:
25458 +               return vc_enter_space_v1(vxi, data);
25459 +       /* this is version 2 */
25460 +       case VCMD_enter_space:
25461 +               return vc_enter_space(vxi, data);
25462 +
25463 +       case VCMD_ctx_create_v0:
25464 +               return vc_ctx_create(id, NULL);
25465 +       case VCMD_ctx_create:
25466 +               return vc_ctx_create(id, data);
25467 +       case VCMD_ctx_migrate_v0:
25468 +               return vc_ctx_migrate(vxi, NULL);
25469 +       case VCMD_ctx_migrate:
25470 +               return vc_ctx_migrate(vxi, data);
25471 +
25472 +       case VCMD_net_create_v0:
25473 +               return vc_net_create(id, NULL);
25474 +       case VCMD_net_create:
25475 +               return vc_net_create(id, data);
25476 +       case VCMD_net_migrate:
25477 +               return vc_net_migrate(nxi, data);
25478 +
25479 +       case VCMD_tag_migrate:
25480 +               return vc_tag_migrate(id);
25481 +
25482 +       case VCMD_net_add:
25483 +               return vc_net_add(nxi, data);
25484 +       case VCMD_net_remove:
25485 +               return vc_net_remove(nxi, data);
25486 +
25487 +       case VCMD_net_add_ipv4:
25488 +               return vc_net_add_ipv4(nxi, data);
25489 +       case VCMD_net_remove_ipv4:
25490 +               return vc_net_remove_ipv4(nxi, data);
25491 +#ifdef CONFIG_IPV6
25492 +       case VCMD_net_add_ipv6:
25493 +               return vc_net_add_ipv6(nxi, data);
25494 +       case VCMD_net_remove_ipv6:
25495 +               return vc_net_remove_ipv6(nxi, data);
25496 +#endif
25497 +/*     case VCMD_add_match_ipv4:
25498 +               return vc_add_match_ipv4(nxi, data);
25499 +       case VCMD_get_match_ipv4:
25500 +               return vc_get_match_ipv4(nxi, data);
25501 +#ifdef CONFIG_IPV6
25502 +       case VCMD_add_match_ipv6:
25503 +               return vc_add_match_ipv6(nxi, data);
25504 +       case VCMD_get_match_ipv6:
25505 +               return vc_get_match_ipv6(nxi, data);
25506 +#endif */
25507 +
25508 +#ifdef CONFIG_VSERVER_DEVICE
25509 +       case VCMD_set_mapping:
25510 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25511 +       case VCMD_unset_mapping:
25512 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25513 +#endif
25514 +#ifdef CONFIG_VSERVER_HISTORY
25515 +       case VCMD_dump_history:
25516 +               return vc_dump_history(id);
25517 +       case VCMD_read_history:
25518 +               return __COMPAT(vc_read_history, id, data, compat);
25519 +#endif
25520 +#ifdef CONFIG_VSERVER_MONITOR
25521 +       case VCMD_read_monitor:
25522 +               return __COMPAT(vc_read_monitor, id, data, compat);
25523 +#endif
25524 +       default:
25525 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25526 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25527 +       }
25528 +       return -ENOSYS;
25529 +}
25530 +
25531 +
25532 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25533 +       case VCMD_ ## vcmd: perm = _perm;               \
25534 +               args = _args; flags = _flags; break
25535 +
25536 +
25537 +#define VCA_NONE       0x00
25538 +#define VCA_VXI                0x01
25539 +#define VCA_NXI                0x02
25540 +
25541 +#define VCF_NONE       0x00
25542 +#define VCF_INFO       0x01
25543 +#define VCF_ADMIN      0x02
25544 +#define VCF_ARES       0x06    /* includes admin */
25545 +#define VCF_SETUP      0x08
25546 +
25547 +#define VCF_ZIDOK      0x10    /* zero id okay */
25548 +
25549 +
25550 +static inline
25551 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25552 +{
25553 +       long ret;
25554 +       int permit = -1, state = 0;
25555 +       int perm = -1, args = 0, flags = 0;
25556 +       struct vx_info *vxi = NULL;
25557 +       struct nx_info *nxi = NULL;
25558 +
25559 +       switch (cmd) {
25560 +       /* unpriviledged commands */
25561 +       __VCMD(get_version,      0, VCA_NONE,   0);
25562 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25563 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25564 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25565 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25566 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25567 +
25568 +       /* info commands */
25569 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25570 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25571 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25572 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25573 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25574 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25575 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25576 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25577 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25578 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25579 +
25580 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25581 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25582 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25583 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25584 +
25585 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25586 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25587 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25588 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25589 +
25590 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25591 +
25592 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25593 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25594 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25595 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25596 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25597 +
25598 +       /* lower admin commands */
25599 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25600 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25601 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25602 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25603 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25604 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25605 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25606 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25607 +
25608 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25609 +       __VCMD(net_create,       5, VCA_NONE,   0);
25610 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25611 +
25612 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25613 +
25614 +       /* higher admin commands */
25615 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25616 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25617 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25618 +
25619 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25620 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25621 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25622 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25623 +
25624 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25625 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25626 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25627 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25628 +
25629 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25630 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25631 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25632 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25633 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25634 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25635 +#ifdef CONFIG_IPV6
25636 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25637 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25638 +#endif
25639 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25640 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25641 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25642 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25643 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25644 +
25645 +#ifdef CONFIG_VSERVER_DEVICE
25646 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25647 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25648 +#endif
25649 +       /* debug level admin commands */
25650 +#ifdef CONFIG_VSERVER_HISTORY
25651 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25652 +       __VCMD(read_history,     9, VCA_NONE,   0);
25653 +#endif
25654 +#ifdef CONFIG_VSERVER_MONITOR
25655 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25656 +#endif
25657 +
25658 +       default:
25659 +               perm = -1;
25660 +       }
25661 +
25662 +       vxdprintk(VXD_CBIT(switch, 0),
25663 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25664 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25665 +               VC_VERSION(cmd), id, data, compat,
25666 +               perm, args, flags);
25667 +
25668 +       ret = -ENOSYS;
25669 +       if (perm < 0)
25670 +               goto out;
25671 +
25672 +       state = 1;
25673 +       if (!capable(CAP_CONTEXT))
25674 +               goto out;
25675 +
25676 +       state = 2;
25677 +       /* moved here from the individual commands */
25678 +       ret = -EPERM;
25679 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25680 +               goto out;
25681 +
25682 +       state = 3;
25683 +       /* vcmd involves resource management  */
25684 +       ret = -EPERM;
25685 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25686 +               goto out;
25687 +
25688 +       state = 4;
25689 +       /* various legacy exceptions */
25690 +       switch (cmd) {
25691 +       /* will go away when spectator is a cap */
25692 +       case VCMD_ctx_migrate_v0:
25693 +       case VCMD_ctx_migrate:
25694 +               if (id == 1) {
25695 +                       current->xid = 1;
25696 +                       ret = 1;
25697 +                       goto out;
25698 +               }
25699 +               break;
25700 +
25701 +       /* will go away when spectator is a cap */
25702 +       case VCMD_net_migrate:
25703 +               if (id == 1) {
25704 +                       current->nid = 1;
25705 +                       ret = 1;
25706 +                       goto out;
25707 +               }
25708 +               break;
25709 +       }
25710 +
25711 +       /* vcmds are fine by default */
25712 +       permit = 1;
25713 +
25714 +       /* admin type vcmds require admin ... */
25715 +       if (flags & VCF_ADMIN)
25716 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25717 +
25718 +       /* ... but setup type vcmds override that */
25719 +       if (!permit && (flags & VCF_SETUP))
25720 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25721 +
25722 +       state = 5;
25723 +       ret = -EPERM;
25724 +       if (!permit)
25725 +               goto out;
25726 +
25727 +       state = 6;
25728 +       if (!id && (flags & VCF_ZIDOK))
25729 +               goto skip_id;
25730 +
25731 +       ret = -ESRCH;
25732 +       if (args & VCA_VXI) {
25733 +               vxi = lookup_vx_info(id);
25734 +               if (!vxi)
25735 +                       goto out;
25736 +
25737 +               if ((flags & VCF_ADMIN) &&
25738 +                       /* special case kill for shutdown */
25739 +                       (cmd != VCMD_ctx_kill) &&
25740 +                       /* can context be administrated? */
25741 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25742 +                       ret = -EACCES;
25743 +                       goto out_vxi;
25744 +               }
25745 +       }
25746 +       state = 7;
25747 +       if (args & VCA_NXI) {
25748 +               nxi = lookup_nx_info(id);
25749 +               if (!nxi)
25750 +                       goto out_vxi;
25751 +
25752 +               if ((flags & VCF_ADMIN) &&
25753 +                       /* can context be administrated? */
25754 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25755 +                       ret = -EACCES;
25756 +                       goto out_nxi;
25757 +               }
25758 +       }
25759 +skip_id:
25760 +       state = 8;
25761 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25762 +
25763 +out_nxi:
25764 +       if ((args & VCA_NXI) && nxi)
25765 +               put_nx_info(nxi);
25766 +out_vxi:
25767 +       if ((args & VCA_VXI) && vxi)
25768 +               put_vx_info(vxi);
25769 +out:
25770 +       vxdprintk(VXD_CBIT(switch, 1),
25771 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25772 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25773 +               VC_VERSION(cmd), ret, ret, state, permit);
25774 +       return ret;
25775 +}
25776 +
25777 +asmlinkage long
25778 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25779 +{
25780 +       return do_vserver(cmd, id, data, 0);
25781 +}
25782 +
25783 +#ifdef CONFIG_COMPAT
25784 +
25785 +asmlinkage long
25786 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25787 +{
25788 +       return do_vserver(cmd, id, data, 1);
25789 +}
25790 +
25791 +#endif /* CONFIG_COMPAT */
25792 diff -NurpP --minimal linux-2.6.32/kernel/vserver/sysctl.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sysctl.c
25793 --- linux-2.6.32/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
25794 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/sysctl.c  2009-12-03 20:04:56.000000000 +0100
25795 @@ -0,0 +1,244 @@
25796 +/*
25797 + *  kernel/vserver/sysctl.c
25798 + *
25799 + *  Virtual Context Support
25800 + *
25801 + *  Copyright (C) 2004-2007  Herbert Pötzl
25802 + *
25803 + *  V0.01  basic structure
25804 + *
25805 + */
25806 +
25807 +#include <linux/module.h>
25808 +#include <linux/ctype.h>
25809 +#include <linux/sysctl.h>
25810 +#include <linux/parser.h>
25811 +#include <asm/uaccess.h>
25812 +
25813 +
25814 +enum {
25815 +       CTL_DEBUG_ERROR         = 0,
25816 +       CTL_DEBUG_SWITCH        = 1,
25817 +       CTL_DEBUG_XID,
25818 +       CTL_DEBUG_NID,
25819 +       CTL_DEBUG_TAG,
25820 +       CTL_DEBUG_NET,
25821 +       CTL_DEBUG_LIMIT,
25822 +       CTL_DEBUG_CRES,
25823 +       CTL_DEBUG_DLIM,
25824 +       CTL_DEBUG_QUOTA,
25825 +       CTL_DEBUG_CVIRT,
25826 +       CTL_DEBUG_SPACE,
25827 +       CTL_DEBUG_MISC,
25828 +};
25829 +
25830 +
25831 +unsigned int vx_debug_switch   = 0;
25832 +unsigned int vx_debug_xid      = 0;
25833 +unsigned int vx_debug_nid      = 0;
25834 +unsigned int vx_debug_tag      = 0;
25835 +unsigned int vx_debug_net      = 0;
25836 +unsigned int vx_debug_limit    = 0;
25837 +unsigned int vx_debug_cres     = 0;
25838 +unsigned int vx_debug_dlim     = 0;
25839 +unsigned int vx_debug_quota    = 0;
25840 +unsigned int vx_debug_cvirt    = 0;
25841 +unsigned int vx_debug_space    = 0;
25842 +unsigned int vx_debug_misc     = 0;
25843 +
25844 +
25845 +static struct ctl_table_header *vserver_table_header;
25846 +static ctl_table vserver_root_table[];
25847 +
25848 +
25849 +void vserver_register_sysctl(void)
25850 +{
25851 +       if (!vserver_table_header) {
25852 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25853 +       }
25854 +
25855 +}
25856 +
25857 +void vserver_unregister_sysctl(void)
25858 +{
25859 +       if (vserver_table_header) {
25860 +               unregister_sysctl_table(vserver_table_header);
25861 +               vserver_table_header = NULL;
25862 +       }
25863 +}
25864 +
25865 +
25866 +static int proc_dodebug(ctl_table *table, int write,
25867 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25868 +{
25869 +       char            tmpbuf[20], *p, c;
25870 +       unsigned int    value;
25871 +       size_t          left, len;
25872 +
25873 +       if ((*ppos && !write) || !*lenp) {
25874 +               *lenp = 0;
25875 +               return 0;
25876 +       }
25877 +
25878 +       left = *lenp;
25879 +
25880 +       if (write) {
25881 +               if (!access_ok(VERIFY_READ, buffer, left))
25882 +                       return -EFAULT;
25883 +               p = (char *)buffer;
25884 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25885 +                       left--, p++;
25886 +               if (!left)
25887 +                       goto done;
25888 +
25889 +               if (left > sizeof(tmpbuf) - 1)
25890 +                       return -EINVAL;
25891 +               if (copy_from_user(tmpbuf, p, left))
25892 +                       return -EFAULT;
25893 +               tmpbuf[left] = '\0';
25894 +
25895 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25896 +                       value = 10 * value + (*p - '0');
25897 +               if (*p && !isspace(*p))
25898 +                       return -EINVAL;
25899 +               while (left && isspace(*p))
25900 +                       left--, p++;
25901 +               *(unsigned int *)table->data = value;
25902 +       } else {
25903 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25904 +                       return -EFAULT;
25905 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25906 +               if (len > left)
25907 +                       len = left;
25908 +               if (__copy_to_user(buffer, tmpbuf, len))
25909 +                       return -EFAULT;
25910 +               if ((left -= len) > 0) {
25911 +                       if (put_user('\n', (char *)buffer + len))
25912 +                               return -EFAULT;
25913 +                       left--;
25914 +               }
25915 +       }
25916 +
25917 +done:
25918 +       *lenp -= left;
25919 +       *ppos += *lenp;
25920 +       return 0;
25921 +}
25922 +
25923 +static int zero;
25924 +
25925 +#define        CTL_ENTRY(ctl, name)                            \
25926 +       {                                               \
25927 +               .ctl_name       = ctl,                  \
25928 +               .procname       = #name,                \
25929 +               .data           = &vx_ ## name,         \
25930 +               .maxlen         = sizeof(int),          \
25931 +               .mode           = 0644,                 \
25932 +               .proc_handler   = &proc_dodebug,        \
25933 +               .strategy       = &sysctl_intvec,       \
25934 +               .extra1         = &zero,                \
25935 +       }
25936 +
25937 +static ctl_table vserver_debug_table[] = {
25938 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25939 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25940 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25941 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25942 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25943 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25944 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25945 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25946 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25947 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25948 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25949 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25950 +       { .ctl_name = 0 }
25951 +};
25952 +
25953 +static ctl_table vserver_root_table[] = {
25954 +       {
25955 +               .ctl_name       = CTL_VSERVER,
25956 +               .procname       = "vserver",
25957 +               .mode           = 0555,
25958 +               .child          = vserver_debug_table
25959 +       },
25960 +       { .ctl_name = 0 }
25961 +};
25962 +
25963 +
25964 +static match_table_t tokens = {
25965 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25966 +       { CTL_DEBUG_XID,        "xid=%x"        },
25967 +       { CTL_DEBUG_NID,        "nid=%x"        },
25968 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25969 +       { CTL_DEBUG_NET,        "net=%x"        },
25970 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25971 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25972 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25973 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25974 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25975 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25976 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25977 +       { CTL_DEBUG_ERROR,      NULL            }
25978 +};
25979 +
25980 +#define        HANDLE_CASE(id, name, val)                              \
25981 +       case CTL_DEBUG_ ## id:                                  \
25982 +               vx_debug_ ## name = val;                        \
25983 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25984 +               break
25985 +
25986 +
25987 +static int __init vs_debug_setup(char *str)
25988 +{
25989 +       char *p;
25990 +       int token;
25991 +
25992 +       printk("vs_debug_setup(%s)\n", str);
25993 +       while ((p = strsep(&str, ",")) != NULL) {
25994 +               substring_t args[MAX_OPT_ARGS];
25995 +               unsigned int value;
25996 +
25997 +               if (!*p)
25998 +                       continue;
25999 +
26000 +               token = match_token(p, tokens, args);
26001 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26002 +
26003 +               switch (token) {
26004 +               HANDLE_CASE(SWITCH, switch, value);
26005 +               HANDLE_CASE(XID,    xid,    value);
26006 +               HANDLE_CASE(NID,    nid,    value);
26007 +               HANDLE_CASE(TAG,    tag,    value);
26008 +               HANDLE_CASE(NET,    net,    value);
26009 +               HANDLE_CASE(LIMIT,  limit,  value);
26010 +               HANDLE_CASE(CRES,   cres,   value);
26011 +               HANDLE_CASE(DLIM,   dlim,   value);
26012 +               HANDLE_CASE(QUOTA,  quota,  value);
26013 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26014 +               HANDLE_CASE(SPACE,  space,  value);
26015 +               HANDLE_CASE(MISC,   misc,   value);
26016 +               default:
26017 +                       return -EINVAL;
26018 +                       break;
26019 +               }
26020 +       }
26021 +       return 1;
26022 +}
26023 +
26024 +__setup("vsdebug=", vs_debug_setup);
26025 +
26026 +
26027 +
26028 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26029 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26030 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26031 +EXPORT_SYMBOL_GPL(vx_debug_net);
26032 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26033 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26034 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26035 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26036 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26037 +EXPORT_SYMBOL_GPL(vx_debug_space);
26038 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26039 +
26040 diff -NurpP --minimal linux-2.6.32/kernel/vserver/tag.c linux-2.6.32-vs2.3.0.36.26/kernel/vserver/tag.c
26041 --- linux-2.6.32/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
26042 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/tag.c     2009-12-03 20:04:56.000000000 +0100
26043 @@ -0,0 +1,63 @@
26044 +/*
26045 + *  linux/kernel/vserver/tag.c
26046 + *
26047 + *  Virtual Server: Shallow Tag Space
26048 + *
26049 + *  Copyright (C) 2007  Herbert Pötzl
26050 + *
26051 + *  V0.01  basic implementation
26052 + *
26053 + */
26054 +
26055 +#include <linux/sched.h>
26056 +#include <linux/vserver/debug.h>
26057 +#include <linux/vs_pid.h>
26058 +#include <linux/vs_tag.h>
26059 +
26060 +#include <linux/vserver/tag_cmd.h>
26061 +
26062 +
26063 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26064 +{
26065 +       if (!p)
26066 +               BUG();
26067 +
26068 +       vxdprintk(VXD_CBIT(tag, 5),
26069 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26070 +
26071 +       task_lock(p);
26072 +       p->tag = tag;
26073 +       task_unlock(p);
26074 +
26075 +       vxdprintk(VXD_CBIT(tag, 5),
26076 +               "moved task %p into [#%d]", p, tag);
26077 +       return 0;
26078 +}
26079 +
26080 +/* vserver syscall commands below here */
26081 +
26082 +/* taks xid and vx_info functions */
26083 +
26084 +
26085 +int vc_task_tag(uint32_t id)
26086 +{
26087 +       tag_t tag;
26088 +
26089 +       if (id) {
26090 +               struct task_struct *tsk;
26091 +               read_lock(&tasklist_lock);
26092 +               tsk = find_task_by_real_pid(id);
26093 +               tag = (tsk) ? tsk->tag : -ESRCH;
26094 +               read_unlock(&tasklist_lock);
26095 +       } else
26096 +               tag = dx_current_tag();
26097 +       return tag;
26098 +}
26099 +
26100 +
26101 +int vc_tag_migrate(uint32_t tag)
26102 +{
26103 +       return dx_migrate_task(current, tag & 0xFFFF);
26104 +}
26105 +
26106 +
26107 diff -NurpP --minimal linux-2.6.32/kernel/vserver/vci_config.h linux-2.6.32-vs2.3.0.36.26/kernel/vserver/vci_config.h
26108 --- linux-2.6.32/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
26109 +++ linux-2.6.32-vs2.3.0.36.26/kernel/vserver/vci_config.h      2009-12-03 20:04:56.000000000 +0100
26110 @@ -0,0 +1,81 @@
26111 +
26112 +/*  interface version */
26113 +
26114 +#define VCI_VERSION            0x00020305
26115 +
26116 +
26117 +enum {
26118 +       VCI_KCBIT_NO_DYNAMIC = 0,
26119 +
26120 +       VCI_KCBIT_PROC_SECURE = 4,
26121 +       VCI_KCBIT_HARDCPU = 5,
26122 +       VCI_KCBIT_IDLELIMIT = 6,
26123 +       VCI_KCBIT_IDLETIME = 7,
26124 +
26125 +       VCI_KCBIT_COWBL = 8,
26126 +       VCI_KCBIT_FULLCOWBL = 9,
26127 +       VCI_KCBIT_SPACES = 10,
26128 +       VCI_KCBIT_NETV2 = 11,
26129 +
26130 +       VCI_KCBIT_DEBUG = 16,
26131 +       VCI_KCBIT_HISTORY = 20,
26132 +       VCI_KCBIT_TAGGED = 24,
26133 +       VCI_KCBIT_PPTAG = 28,
26134 +
26135 +       VCI_KCBIT_MORE = 31,
26136 +};
26137 +
26138 +
26139 +static inline uint32_t vci_kernel_config(void)
26140 +{
26141 +       return
26142 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26143 +
26144 +       /* configured features */
26145 +#ifdef CONFIG_VSERVER_PROC_SECURE
26146 +       (1 << VCI_KCBIT_PROC_SECURE) |
26147 +#endif
26148 +#ifdef CONFIG_VSERVER_HARDCPU
26149 +       (1 << VCI_KCBIT_HARDCPU) |
26150 +#endif
26151 +#ifdef CONFIG_VSERVER_IDLELIMIT
26152 +       (1 << VCI_KCBIT_IDLELIMIT) |
26153 +#endif
26154 +#ifdef CONFIG_VSERVER_IDLETIME
26155 +       (1 << VCI_KCBIT_IDLETIME) |
26156 +#endif
26157 +#ifdef CONFIG_VSERVER_COWBL
26158 +       (1 << VCI_KCBIT_COWBL) |
26159 +       (1 << VCI_KCBIT_FULLCOWBL) |
26160 +#endif
26161 +       (1 << VCI_KCBIT_SPACES) |
26162 +       (1 << VCI_KCBIT_NETV2) |
26163 +
26164 +       /* debug options */
26165 +#ifdef CONFIG_VSERVER_DEBUG
26166 +       (1 << VCI_KCBIT_DEBUG) |
26167 +#endif
26168 +#ifdef CONFIG_VSERVER_HISTORY
26169 +       (1 << VCI_KCBIT_HISTORY) |
26170 +#endif
26171 +
26172 +       /* inode context tagging */
26173 +#if    defined(CONFIG_TAGGING_NONE)
26174 +       (0 << VCI_KCBIT_TAGGED) |
26175 +#elif  defined(CONFIG_TAGGING_UID16)
26176 +       (1 << VCI_KCBIT_TAGGED) |
26177 +#elif  defined(CONFIG_TAGGING_GID16)
26178 +       (2 << VCI_KCBIT_TAGGED) |
26179 +#elif  defined(CONFIG_TAGGING_ID24)
26180 +       (3 << VCI_KCBIT_TAGGED) |
26181 +#elif  defined(CONFIG_TAGGING_INTERN)
26182 +       (4 << VCI_KCBIT_TAGGED) |
26183 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26184 +       (5 << VCI_KCBIT_TAGGED) |
26185 +#else
26186 +       (7 << VCI_KCBIT_TAGGED) |
26187 +#endif
26188 +       (1 << VCI_KCBIT_PPTAG) |
26189 +       0;
26190 +}
26191 +
26192 diff -NurpP --minimal linux-2.6.32/mm/allocpercpu.c linux-2.6.32-vs2.3.0.36.26/mm/allocpercpu.c
26193 --- linux-2.6.32/mm/allocpercpu.c       2009-12-03 20:02:58.000000000 +0100
26194 +++ linux-2.6.32-vs2.3.0.36.26/mm/allocpercpu.c 2009-12-03 20:04:56.000000000 +0100
26195 @@ -160,12 +160,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
26196  
26197  void __init setup_per_cpu_areas(void)
26198  {
26199 -       unsigned long size, i;
26200 +       unsigned long size, vspc, i;
26201         char *ptr;
26202         unsigned long nr_possible_cpus = num_possible_cpus();
26203  
26204 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
26205 +
26206         /* Copy section for each CPU (we discard the original) */
26207 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
26208 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
26209         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
26210  
26211         for_each_possible_cpu(i) {
26212 diff -NurpP --minimal linux-2.6.32/mm/filemap_xip.c linux-2.6.32-vs2.3.0.36.26/mm/filemap_xip.c
26213 --- linux-2.6.32/mm/filemap_xip.c       2009-12-03 20:02:58.000000000 +0100
26214 +++ linux-2.6.32-vs2.3.0.36.26/mm/filemap_xip.c 2009-12-03 20:04:56.000000000 +0100
26215 @@ -17,6 +17,7 @@
26216  #include <linux/sched.h>
26217  #include <linux/seqlock.h>
26218  #include <linux/mutex.h>
26219 +#include <linux/vs_memory.h>
26220  #include <asm/tlbflush.h>
26221  #include <asm/io.h>
26222  
26223 diff -NurpP --minimal linux-2.6.32/mm/fremap.c linux-2.6.32-vs2.3.0.36.26/mm/fremap.c
26224 --- linux-2.6.32/mm/fremap.c    2009-03-24 14:22:45.000000000 +0100
26225 +++ linux-2.6.32-vs2.3.0.36.26/mm/fremap.c      2009-12-03 20:04:56.000000000 +0100
26226 @@ -16,6 +16,7 @@
26227  #include <linux/module.h>
26228  #include <linux/syscalls.h>
26229  #include <linux/mmu_notifier.h>
26230 +#include <linux/vs_memory.h>
26231  
26232  #include <asm/mmu_context.h>
26233  #include <asm/cacheflush.h>
26234 diff -NurpP --minimal linux-2.6.32/mm/hugetlb.c linux-2.6.32-vs2.3.0.36.26/mm/hugetlb.c
26235 --- linux-2.6.32/mm/hugetlb.c   2009-12-03 20:02:58.000000000 +0100
26236 +++ linux-2.6.32-vs2.3.0.36.26/mm/hugetlb.c     2009-12-03 20:04:56.000000000 +0100
26237 @@ -24,6 +24,7 @@
26238  #include <asm/io.h>
26239  
26240  #include <linux/hugetlb.h>
26241 +#include <linux/vs_memory.h>
26242  #include "internal.h"
26243  
26244  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26245 diff -NurpP --minimal linux-2.6.32/mm/memory.c linux-2.6.32-vs2.3.0.36.26/mm/memory.c
26246 --- linux-2.6.32/mm/memory.c    2009-12-03 20:02:58.000000000 +0100
26247 +++ linux-2.6.32-vs2.3.0.36.26/mm/memory.c      2009-12-03 20:04:56.000000000 +0100
26248 @@ -56,6 +56,7 @@
26249  #include <linux/kallsyms.h>
26250  #include <linux/swapops.h>
26251  #include <linux/elf.h>
26252 +// #include <linux/vs_memory.h>
26253  
26254  #include <asm/io.h>
26255  #include <asm/pgalloc.h>
26256 @@ -647,6 +648,9 @@ static int copy_pte_range(struct mm_stru
26257         int progress = 0;
26258         int rss[2];
26259  
26260 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26261 +               return -ENOMEM;
26262 +
26263  again:
26264         rss[1] = rss[0] = 0;
26265         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26266 @@ -2645,6 +2649,8 @@ static int do_anonymous_page(struct mm_s
26267         /* Allocate our own private page. */
26268         pte_unmap(page_table);
26269  
26270 +       if (!vx_rss_avail(mm, 1))
26271 +               goto oom;
26272         if (unlikely(anon_vma_prepare(vma)))
26273                 goto oom;
26274         page = alloc_zeroed_user_highpage_movable(vma, address);
26275 @@ -2936,6 +2942,7 @@ static inline int handle_pte_fault(struc
26276  {
26277         pte_t entry;
26278         spinlock_t *ptl;
26279 +       int ret = 0, type = VXPT_UNKNOWN;
26280  
26281         entry = *pte;
26282         if (!pte_present(entry)) {
26283 @@ -2960,9 +2967,12 @@ static inline int handle_pte_fault(struc
26284         if (unlikely(!pte_same(*pte, entry)))
26285                 goto unlock;
26286         if (flags & FAULT_FLAG_WRITE) {
26287 -               if (!pte_write(entry))
26288 -                       return do_wp_page(mm, vma, address,
26289 +               if (!pte_write(entry)) {
26290 +                       ret = do_wp_page(mm, vma, address,
26291                                         pte, pmd, ptl, entry);
26292 +                       type = VXPT_WRITE;
26293 +                       goto out;
26294 +               }
26295                 entry = pte_mkdirty(entry);
26296         }
26297         entry = pte_mkyoung(entry);
26298 @@ -2980,7 +2990,10 @@ static inline int handle_pte_fault(struc
26299         }
26300  unlock:
26301         pte_unmap_unlock(pte, ptl);
26302 -       return 0;
26303 +       ret = 0;
26304 +out:
26305 +       vx_page_fault(mm, vma, type, ret);
26306 +       return ret;
26307  }
26308  
26309  /*
26310 diff -NurpP --minimal linux-2.6.32/mm/mlock.c linux-2.6.32-vs2.3.0.36.26/mm/mlock.c
26311 --- linux-2.6.32/mm/mlock.c     2009-12-03 20:02:58.000000000 +0100
26312 +++ linux-2.6.32-vs2.3.0.36.26/mm/mlock.c       2009-12-03 20:04:56.000000000 +0100
26313 @@ -18,6 +18,7 @@
26314  #include <linux/rmap.h>
26315  #include <linux/mmzone.h>
26316  #include <linux/hugetlb.h>
26317 +#include <linux/vs_memory.h>
26318  
26319  #include "internal.h"
26320  
26321 @@ -401,7 +402,7 @@ success:
26322         nr_pages = (end - start) >> PAGE_SHIFT;
26323         if (!lock)
26324                 nr_pages = -nr_pages;
26325 -       mm->locked_vm += nr_pages;
26326 +       vx_vmlocked_add(mm, nr_pages);
26327  
26328         /*
26329          * vm_flags is protected by the mmap_sem held in write mode.
26330 @@ -474,7 +475,7 @@ static int do_mlock(unsigned long start,
26331  
26332  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26333  {
26334 -       unsigned long locked;
26335 +       unsigned long locked, grow;
26336         unsigned long lock_limit;
26337         int error = -ENOMEM;
26338  
26339 @@ -487,8 +488,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26340         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26341         start &= PAGE_MASK;
26342  
26343 -       locked = len >> PAGE_SHIFT;
26344 -       locked += current->mm->locked_vm;
26345 +       grow = len >> PAGE_SHIFT;
26346 +       if (!vx_vmlocked_avail(current->mm, grow))
26347 +               goto out;
26348 +       locked = current->mm->locked_vm + grow;
26349  
26350         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26351         lock_limit >>= PAGE_SHIFT;
26352 @@ -496,6 +499,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26353         /* check against resource limits */
26354         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26355                 error = do_mlock(start, len, 1);
26356 +out:
26357         up_write(&current->mm->mmap_sem);
26358         return error;
26359  }
26360 @@ -557,6 +561,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26361         lock_limit >>= PAGE_SHIFT;
26362  
26363         ret = -ENOMEM;
26364 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26365 +               goto out;
26366         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26367             capable(CAP_IPC_LOCK))
26368                 ret = do_mlockall(flags);
26369 @@ -631,8 +637,10 @@ int account_locked_memory(struct mm_stru
26370         if (lim < vm)
26371                 goto out;
26372  
26373 -       mm->total_vm  += pgsz;
26374 -       mm->locked_vm += pgsz;
26375 +       // mm->total_vm  += pgsz;
26376 +       vx_vmpages_add(mm, pgsz);
26377 +       // mm->locked_vm += pgsz;
26378 +       vx_vmlocked_add(mm, pgsz);
26379  
26380         error = 0;
26381   out:
26382 @@ -646,8 +654,10 @@ void refund_locked_memory(struct mm_stru
26383  
26384         down_write(&mm->mmap_sem);
26385  
26386 -       mm->total_vm  -= pgsz;
26387 -       mm->locked_vm -= pgsz;
26388 +       // mm->total_vm  -= pgsz;
26389 +       vx_vmpages_sub(mm, pgsz);
26390 +       // mm->locked_vm -= pgsz;
26391 +       vx_vmlocked_sub(mm, pgsz);
26392  
26393         up_write(&mm->mmap_sem);
26394  }
26395 diff -NurpP --minimal linux-2.6.32/mm/mmap.c linux-2.6.32-vs2.3.0.36.26/mm/mmap.c
26396 --- linux-2.6.32/mm/mmap.c      2009-12-03 20:02:58.000000000 +0100
26397 +++ linux-2.6.32-vs2.3.0.36.26/mm/mmap.c        2009-12-03 20:04:56.000000000 +0100
26398 @@ -1236,7 +1236,8 @@ munmap_back:
26399  out:
26400         perf_event_mmap(vma);
26401  
26402 -       mm->total_vm += len >> PAGE_SHIFT;
26403 +       // mm->total_vm += len >> PAGE_SHIFT;
26404 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26405         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26406         if (vm_flags & VM_LOCKED) {
26407                 /*
26408 @@ -1245,7 +1246,8 @@ out:
26409                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
26410                 if (nr_pages < 0)
26411                         return nr_pages;        /* vma gone! */
26412 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26413 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26414 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
26415         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26416                 make_pages_present(addr, addr + len);
26417         return addr;
26418 @@ -1592,9 +1594,9 @@ static int acct_stack_growth(struct vm_a
26419                 return -ENOMEM;
26420  
26421         /* Ok, everything looks good - let it rip */
26422 -       mm->total_vm += grow;
26423 +       vx_vmpages_add(mm, grow);
26424         if (vma->vm_flags & VM_LOCKED)
26425 -               mm->locked_vm += grow;
26426 +               vx_vmlocked_add(mm, grow);
26427         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26428         return 0;
26429  }
26430 @@ -1769,7 +1771,8 @@ static void remove_vma_list(struct mm_st
26431         do {
26432                 long nrpages = vma_pages(vma);
26433  
26434 -               mm->total_vm -= nrpages;
26435 +               // mm->total_vm -= nrpages;
26436 +               vx_vmpages_sub(mm, nrpages);
26437                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26438                 vma = remove_vma(vma);
26439         } while (vma);
26440 @@ -1941,7 +1944,8 @@ int do_munmap(struct mm_struct *mm, unsi
26441                 struct vm_area_struct *tmp = vma;
26442                 while (tmp && tmp->vm_start < end) {
26443                         if (tmp->vm_flags & VM_LOCKED) {
26444 -                               mm->locked_vm -= vma_pages(tmp);
26445 +                               // mm->locked_vm -= vma_pages(tmp);
26446 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
26447                                 munlock_vma_pages_all(tmp);
26448                         }
26449                         tmp = tmp->vm_next;
26450 @@ -2030,6 +2034,8 @@ unsigned long do_brk(unsigned long addr,
26451                 lock_limit >>= PAGE_SHIFT;
26452                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26453                         return -EAGAIN;
26454 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26455 +                       return -ENOMEM;
26456         }
26457  
26458         /*
26459 @@ -2056,7 +2062,8 @@ unsigned long do_brk(unsigned long addr,
26460         if (mm->map_count > sysctl_max_map_count)
26461                 return -ENOMEM;
26462  
26463 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26464 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26465 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26466                 return -ENOMEM;
26467  
26468         /* Can we just expand an old private anonymous mapping? */
26469 @@ -2082,10 +2089,13 @@ unsigned long do_brk(unsigned long addr,
26470         vma->vm_page_prot = vm_get_page_prot(flags);
26471         vma_link(mm, vma, prev, rb_link, rb_parent);
26472  out:
26473 -       mm->total_vm += len >> PAGE_SHIFT;
26474 +       // mm->total_vm += len >> PAGE_SHIFT;
26475 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26476 +
26477         if (flags & VM_LOCKED) {
26478                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26479 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26480 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26481 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26482         }
26483         return addr;
26484  }
26485 @@ -2129,6 +2139,11 @@ void exit_mmap(struct mm_struct *mm)
26486         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26487         tlb_finish_mmu(tlb, 0, end);
26488  
26489 +       set_mm_counter(mm, file_rss, 0);
26490 +       set_mm_counter(mm, anon_rss, 0);
26491 +       vx_vmpages_sub(mm, mm->total_vm);
26492 +       vx_vmlocked_sub(mm, mm->locked_vm);
26493 +
26494         /*
26495          * Walk the list again, actually closing and freeing it,
26496          * with preemption enabled, without holding any MM locks.
26497 @@ -2168,7 +2183,8 @@ int insert_vm_struct(struct mm_struct * 
26498         if (__vma && __vma->vm_start < vma->vm_end)
26499                 return -ENOMEM;
26500         if ((vma->vm_flags & VM_ACCOUNT) &&
26501 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26502 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26503 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26504                 return -ENOMEM;
26505         vma_link(mm, vma, prev, rb_link, rb_parent);
26506         return 0;
26507 @@ -2244,6 +2260,8 @@ int may_expand_vm(struct mm_struct *mm, 
26508  
26509         if (cur + npages > lim)
26510                 return 0;
26511 +       if (!vx_vmpages_avail(mm, npages))
26512 +               return 0;
26513         return 1;
26514  }
26515  
26516 @@ -2321,7 +2339,7 @@ int install_special_mapping(struct mm_st
26517                 return -ENOMEM;
26518         }
26519  
26520 -       mm->total_vm += len >> PAGE_SHIFT;
26521 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26522  
26523         perf_event_mmap(vma);
26524  
26525 diff -NurpP --minimal linux-2.6.32/mm/mremap.c linux-2.6.32-vs2.3.0.36.26/mm/mremap.c
26526 --- linux-2.6.32/mm/mremap.c    2009-12-03 20:02:58.000000000 +0100
26527 +++ linux-2.6.32-vs2.3.0.36.26/mm/mremap.c      2009-12-03 20:04:56.000000000 +0100
26528 @@ -20,6 +20,7 @@
26529  #include <linux/security.h>
26530  #include <linux/syscalls.h>
26531  #include <linux/mmu_notifier.h>
26532 +#include <linux/vs_memory.h>
26533  
26534  #include <asm/uaccess.h>
26535  #include <asm/cacheflush.h>
26536 @@ -234,7 +235,7 @@ static unsigned long move_vma(struct vm_
26537          * If this were a serious issue, we'd add a flag to do_munmap().
26538          */
26539         hiwater_vm = mm->hiwater_vm;
26540 -       mm->total_vm += new_len >> PAGE_SHIFT;
26541 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26542         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26543  
26544         if (do_munmap(mm, old_addr, old_len) < 0) {
26545 @@ -252,7 +253,7 @@ static unsigned long move_vma(struct vm_
26546         }
26547  
26548         if (vm_flags & VM_LOCKED) {
26549 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26550 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26551                 if (new_len > old_len)
26552                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26553                                                        new_addr + new_len);
26554 @@ -363,6 +364,9 @@ unsigned long do_mremap(unsigned long ad
26555                 ret = -EAGAIN;
26556                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26557                         goto out;
26558 +               if (!vx_vmlocked_avail(current->mm,
26559 +                       (new_len - old_len) >> PAGE_SHIFT))
26560 +                       goto out;
26561         }
26562         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26563                 ret = -ENOMEM;
26564 @@ -391,10 +395,12 @@ unsigned long do_mremap(unsigned long ad
26565                         vma_adjust(vma, vma->vm_start,
26566                                 addr + new_len, vma->vm_pgoff, NULL);
26567  
26568 -                       mm->total_vm += pages;
26569 +                       // mm->total_vm += pages;
26570 +                       vx_vmpages_add(mm, pages);
26571                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26572                         if (vma->vm_flags & VM_LOCKED) {
26573 -                               mm->locked_vm += pages;
26574 +                               // mm->locked_vm += pages;
26575 +                               vx_vmlocked_add(mm, pages);
26576                                 mlock_vma_pages_range(vma, addr + old_len,
26577                                                    addr + new_len);
26578                         }
26579 diff -NurpP --minimal linux-2.6.32/mm/nommu.c linux-2.6.32-vs2.3.0.36.26/mm/nommu.c
26580 --- linux-2.6.32/mm/nommu.c     2009-12-03 20:02:58.000000000 +0100
26581 +++ linux-2.6.32-vs2.3.0.36.26/mm/nommu.c       2009-12-03 20:04:56.000000000 +0100
26582 @@ -1346,7 +1346,7 @@ unsigned long do_mmap_pgoff(struct file 
26583         /* okay... we have a mapping; now we have to register it */
26584         result = vma->vm_start;
26585  
26586 -       current->mm->total_vm += len >> PAGE_SHIFT;
26587 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26588  
26589  share:
26590         add_vma_to_mm(current->mm, vma);
26591 @@ -1606,7 +1606,7 @@ void exit_mmap(struct mm_struct *mm)
26592  
26593         kenter("");
26594  
26595 -       mm->total_vm = 0;
26596 +       vx_vmpages_sub(mm, mm->total_vm);
26597  
26598         while ((vma = mm->mmap)) {
26599                 mm->mmap = vma->vm_next;
26600 diff -NurpP --minimal linux-2.6.32/mm/oom_kill.c linux-2.6.32-vs2.3.0.36.26/mm/oom_kill.c
26601 --- linux-2.6.32/mm/oom_kill.c  2009-12-03 20:02:58.000000000 +0100
26602 +++ linux-2.6.32-vs2.3.0.36.26/mm/oom_kill.c    2009-12-03 20:04:56.000000000 +0100
26603 @@ -27,6 +27,8 @@
26604  #include <linux/notifier.h>
26605  #include <linux/memcontrol.h>
26606  #include <linux/security.h>
26607 +#include <linux/vs_memory.h>
26608 +#include <linux/vs_context.h>
26609  
26610  int sysctl_panic_on_oom;
26611  int sysctl_oom_kill_allocating_task;
26612 @@ -186,9 +188,21 @@ unsigned long badness(struct task_struct
26613                         points >>= -(oom_adj);
26614         }
26615  
26616 +       /*
26617 +        * add points for context badness and
26618 +        * reduce badness for processes belonging to
26619 +        * a different context
26620 +        */
26621 +
26622 +       points += vx_badness(p, mm);
26623 +
26624 +       if ((vx_current_xid() > 1) &&
26625 +               vx_current_xid() != vx_task_xid(p))
26626 +               points /= 16;
26627 +
26628  #ifdef DEBUG
26629 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26630 -       p->pid, p->comm, points);
26631 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26632 +               task_pid_nr(p), p->xid, p->comm, points);
26633  #endif
26634         return points;
26635  }
26636 @@ -242,8 +256,8 @@ static struct task_struct *select_bad_pr
26637                  */
26638                 if (!p->mm)
26639                         continue;
26640 -               /* skip the init task */
26641 -               if (is_global_init(p))
26642 +               /* skip the init task, global and per guest */
26643 +               if (task_is_init(p))
26644                         continue;
26645                 if (mem && !task_in_mem_cgroup(p, mem))
26646                         continue;
26647 @@ -357,8 +371,8 @@ static void __oom_kill_task(struct task_
26648         }
26649  
26650         if (verbose)
26651 -               printk(KERN_ERR "Killed process %d (%s)\n",
26652 -                               task_pid_nr(p), p->comm);
26653 +               printk(KERN_ERR "Killed process %s(%d:#%u)\n",
26654 +                       p->comm, task_pid_nr(p), p->xid);
26655  
26656         /*
26657          * We give our sacrificial lamb high priority and access to
26658 @@ -419,8 +433,8 @@ static int oom_kill_process(struct task_
26659                 return 0;
26660         }
26661  
26662 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26663 -                                       message, task_pid_nr(p), p->comm, points);
26664 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
26665 +               message, p->comm, task_pid_nr(p), p->xid, points);
26666  
26667         /* Try to kill a child first */
26668         list_for_each_entry(c, &p->children, sibling) {
26669 diff -NurpP --minimal linux-2.6.32/mm/page_alloc.c linux-2.6.32-vs2.3.0.36.26/mm/page_alloc.c
26670 --- linux-2.6.32/mm/page_alloc.c        2009-12-03 20:02:58.000000000 +0100
26671 +++ linux-2.6.32-vs2.3.0.36.26/mm/page_alloc.c  2009-12-03 20:04:56.000000000 +0100
26672 @@ -48,6 +48,8 @@
26673  #include <linux/page_cgroup.h>
26674  #include <linux/debugobjects.h>
26675  #include <linux/kmemleak.h>
26676 +#include <linux/vs_base.h>
26677 +#include <linux/vs_limit.h>
26678  #include <trace/events/kmem.h>
26679  
26680  #include <asm/tlbflush.h>
26681 @@ -2130,6 +2132,9 @@ void si_meminfo(struct sysinfo *val)
26682         val->totalhigh = totalhigh_pages;
26683         val->freehigh = nr_free_highpages();
26684         val->mem_unit = PAGE_SIZE;
26685 +
26686 +       if (vx_flags(VXF_VIRT_MEM, 0))
26687 +               vx_vsi_meminfo(val);
26688  }
26689  
26690  EXPORT_SYMBOL(si_meminfo);
26691 @@ -2150,6 +2155,9 @@ void si_meminfo_node(struct sysinfo *val
26692         val->freehigh = 0;
26693  #endif
26694         val->mem_unit = PAGE_SIZE;
26695 +
26696 +       if (vx_flags(VXF_VIRT_MEM, 0))
26697 +               vx_vsi_meminfo(val);
26698  }
26699  #endif
26700  
26701 diff -NurpP --minimal linux-2.6.32/mm/rmap.c linux-2.6.32-vs2.3.0.36.26/mm/rmap.c
26702 --- linux-2.6.32/mm/rmap.c      2009-12-03 20:02:58.000000000 +0100
26703 +++ linux-2.6.32-vs2.3.0.36.26/mm/rmap.c        2009-12-03 20:04:56.000000000 +0100
26704 @@ -55,6 +55,7 @@
26705  #include <linux/memcontrol.h>
26706  #include <linux/mmu_notifier.h>
26707  #include <linux/migrate.h>
26708 +#include <linux/vs_memory.h>
26709  
26710  #include <asm/tlbflush.h>
26711  
26712 diff -NurpP --minimal linux-2.6.32/mm/shmem.c linux-2.6.32-vs2.3.0.36.26/mm/shmem.c
26713 --- linux-2.6.32/mm/shmem.c     2009-12-03 20:02:58.000000000 +0100
26714 +++ linux-2.6.32-vs2.3.0.36.26/mm/shmem.c       2009-12-03 20:04:56.000000000 +0100
26715 @@ -1781,7 +1781,7 @@ static int shmem_statfs(struct dentry *d
26716  {
26717         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26718  
26719 -       buf->f_type = TMPFS_MAGIC;
26720 +       buf->f_type = TMPFS_SUPER_MAGIC;
26721         buf->f_bsize = PAGE_CACHE_SIZE;
26722         buf->f_namelen = NAME_MAX;
26723         spin_lock(&sbinfo->stat_lock);
26724 @@ -2346,7 +2346,7 @@ int shmem_fill_super(struct super_block 
26725         sb->s_maxbytes = SHMEM_MAX_BYTES;
26726         sb->s_blocksize = PAGE_CACHE_SIZE;
26727         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26728 -       sb->s_magic = TMPFS_MAGIC;
26729 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26730         sb->s_op = &shmem_ops;
26731         sb->s_time_gran = 1;
26732  #ifdef CONFIG_TMPFS_POSIX_ACL
26733 diff -NurpP --minimal linux-2.6.32/mm/slab.c linux-2.6.32-vs2.3.0.36.26/mm/slab.c
26734 --- linux-2.6.32/mm/slab.c      2009-12-03 20:02:58.000000000 +0100
26735 +++ linux-2.6.32-vs2.3.0.36.26/mm/slab.c        2009-12-03 20:04:56.000000000 +0100
26736 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
26737  #define STATS_INC_FREEMISS(x)  do { } while (0)
26738  #endif
26739  
26740 +#include "slab_vs.h"
26741 +
26742  #if DEBUG
26743  
26744  /*
26745 @@ -3253,6 +3255,7 @@ retry:
26746  
26747         obj = slab_get_obj(cachep, slabp, nodeid);
26748         check_slabp(cachep, slabp);
26749 +       vx_slab_alloc(cachep, flags);
26750         l3->free_objects--;
26751         /* move slabp to correct slabp list: */
26752         list_del(&slabp->list);
26753 @@ -3329,6 +3332,7 @@ __cache_alloc_node(struct kmem_cache *ca
26754         /* ___cache_alloc_node can fall back to other nodes */
26755         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26756    out:
26757 +       vx_slab_alloc(cachep, flags);
26758         local_irq_restore(save_flags);
26759         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26760         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26761 @@ -3515,6 +3519,7 @@ static inline void __cache_free(struct k
26762         check_irq_off();
26763         kmemleak_free_recursive(objp, cachep->flags);
26764         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26765 +       vx_slab_free(cachep);
26766  
26767         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26768  
26769 diff -NurpP --minimal linux-2.6.32/mm/slab_vs.h linux-2.6.32-vs2.3.0.36.26/mm/slab_vs.h
26770 --- linux-2.6.32/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
26771 +++ linux-2.6.32-vs2.3.0.36.26/mm/slab_vs.h     2009-12-03 20:04:56.000000000 +0100
26772 @@ -0,0 +1,29 @@
26773 +
26774 +#include <linux/vserver/context.h>
26775 +
26776 +#include <linux/vs_context.h>
26777 +
26778 +static inline
26779 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26780 +{
26781 +       int what = gfp_zone(cachep->gfpflags);
26782 +       struct vx_info *vxi = current_vx_info();
26783 +
26784 +       if (!vxi)
26785 +               return;
26786 +
26787 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26788 +}
26789 +
26790 +static inline
26791 +void vx_slab_free(struct kmem_cache *cachep)
26792 +{
26793 +       int what = gfp_zone(cachep->gfpflags);
26794 +       struct vx_info *vxi = current_vx_info();
26795 +
26796 +       if (!vxi)
26797 +               return;
26798 +
26799 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26800 +}
26801 +
26802 diff -NurpP --minimal linux-2.6.32/mm/swapfile.c linux-2.6.32-vs2.3.0.36.26/mm/swapfile.c
26803 --- linux-2.6.32/mm/swapfile.c  2009-12-03 20:02:58.000000000 +0100
26804 +++ linux-2.6.32-vs2.3.0.36.26/mm/swapfile.c    2009-12-03 20:04:56.000000000 +0100
26805 @@ -34,6 +34,8 @@
26806  #include <asm/tlbflush.h>
26807  #include <linux/swapops.h>
26808  #include <linux/page_cgroup.h>
26809 +#include <linux/vs_base.h>
26810 +#include <linux/vs_memory.h>
26811  
26812  static DEFINE_SPINLOCK(swap_lock);
26813  static unsigned int nr_swapfiles;
26814 @@ -1680,6 +1682,8 @@ static void *swap_next(struct seq_file *
26815         if (v == SEQ_START_TOKEN)
26816                 ptr = swap_info;
26817         else {
26818 +               if (vx_flags(VXF_VIRT_MEM, 0))
26819 +                       return NULL;
26820                 ptr = v;
26821                 ptr++;
26822         }
26823 @@ -1707,6 +1711,16 @@ static int swap_show(struct seq_file *sw
26824  
26825         if (ptr == SEQ_START_TOKEN) {
26826                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26827 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26828 +                       struct sysinfo si;
26829 +
26830 +                       vx_vsi_swapinfo(&si);
26831 +                       if (si.totalswap < (1 << 10))
26832 +                               return 0;
26833 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26834 +                               "hdv0", "partition", si.totalswap >> 10,
26835 +                               (si.totalswap - si.freeswap) >> 10, -1);
26836 +               }
26837                 return 0;
26838         }
26839  
26840 @@ -2064,6 +2078,8 @@ void si_swapinfo(struct sysinfo *val)
26841         val->freeswap = nr_swap_pages + nr_to_be_unused;
26842         val->totalswap = total_swap_pages + nr_to_be_unused;
26843         spin_unlock(&swap_lock);
26844 +       if (vx_flags(VXF_VIRT_MEM, 0))
26845 +               vx_vsi_swapinfo(val);
26846  }
26847  
26848  /*
26849 diff -NurpP --minimal linux-2.6.32/net/core/dev.c linux-2.6.32-vs2.3.0.36.26/net/core/dev.c
26850 --- linux-2.6.32/net/core/dev.c 2009-12-03 20:02:59.000000000 +0100
26851 +++ linux-2.6.32-vs2.3.0.36.26/net/core/dev.c   2009-12-03 20:04:56.000000000 +0100
26852 @@ -126,6 +126,7 @@
26853  #include <linux/in.h>
26854  #include <linux/jhash.h>
26855  #include <linux/random.h>
26856 +#include <linux/vs_inet.h>
26857  #include <trace/events/napi.h>
26858  
26859  #include "net-sysfs.h"
26860 @@ -591,7 +592,8 @@ struct net_device *__dev_get_by_name(str
26861         hlist_for_each(p, dev_name_hash(net, name)) {
26862                 struct net_device *dev
26863                         = hlist_entry(p, struct net_device, name_hlist);
26864 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26865 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26866 +                   nx_dev_visible(current_nx_info(), dev))
26867                         return dev;
26868         }
26869         return NULL;
26870 @@ -642,7 +644,8 @@ struct net_device *__dev_get_by_index(st
26871         hlist_for_each(p, dev_index_hash(net, ifindex)) {
26872                 struct net_device *dev
26873                         = hlist_entry(p, struct net_device, index_hlist);
26874 -               if (dev->ifindex == ifindex)
26875 +               if ((dev->ifindex == ifindex) &&
26876 +                   nx_dev_visible(current_nx_info(), dev))
26877                         return dev;
26878         }
26879         return NULL;
26880 @@ -695,10 +698,12 @@ struct net_device *dev_getbyhwaddr(struc
26881  
26882         ASSERT_RTNL();
26883  
26884 -       for_each_netdev(net, dev)
26885 +       for_each_netdev(net, dev) {
26886                 if (dev->type == type &&
26887 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
26888 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
26889 +                   nx_dev_visible(current_nx_info(), dev))
26890                         return dev;
26891 +       }
26892  
26893         return NULL;
26894  }
26895 @@ -709,9 +714,11 @@ struct net_device *__dev_getfirstbyhwtyp
26896         struct net_device *dev;
26897  
26898         ASSERT_RTNL();
26899 -       for_each_netdev(net, dev)
26900 -               if (dev->type == type)
26901 +       for_each_netdev(net, dev) {
26902 +               if ((dev->type == type) &&
26903 +                   nx_dev_visible(current_nx_info(), dev))
26904                         return dev;
26905 +       }
26906  
26907         return NULL;
26908  }
26909 @@ -830,6 +837,8 @@ static int __dev_alloc_name(struct net *
26910                                 continue;
26911                         if (i < 0 || i >= max_netdevices)
26912                                 continue;
26913 +                       if (!nx_dev_visible(current_nx_info(), d))
26914 +                               continue;
26915  
26916                         /*  avoid cases where sscanf is not exact inverse of printf */
26917                         snprintf(buf, IFNAMSIZ, name, i);
26918 @@ -2984,6 +2993,8 @@ static int dev_ifconf(struct net *net, c
26919  
26920         total = 0;
26921         for_each_netdev(net, dev) {
26922 +               if (!nx_dev_visible(current_nx_info(), dev))
26923 +                       continue;
26924                 for (i = 0; i < NPROTO; i++) {
26925                         if (gifconf_list[i]) {
26926                                 int done;
26927 @@ -3052,6 +3063,9 @@ static void dev_seq_printf_stats(struct 
26928  {
26929         const struct net_device_stats *stats = dev_get_stats(dev);
26930  
26931 +       if (!nx_dev_visible(current_nx_info(), dev))
26932 +               return;
26933 +
26934         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26935                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26936                    dev->name, stats->rx_bytes, stats->rx_packets,
26937 @@ -5313,6 +5327,15 @@ int dev_change_net_namespace(struct net_
26938                 goto out;
26939  #endif
26940  
26941 +#ifdef CONFIG_SYSFS
26942 +       /* Don't allow real devices to be moved when sysfs
26943 +        * is enabled.
26944 +        */
26945 +       err = -EINVAL;
26946 +       if (dev->dev.parent)
26947 +               goto out;
26948 +#endif
26949 +
26950         /* Ensure the device has been registrered */
26951         err = -EINVAL;
26952         if (dev->reg_state != NETREG_REGISTERED)
26953 diff -NurpP --minimal linux-2.6.32/net/core/rtnetlink.c linux-2.6.32-vs2.3.0.36.26/net/core/rtnetlink.c
26954 --- linux-2.6.32/net/core/rtnetlink.c   2009-12-03 20:02:59.000000000 +0100
26955 +++ linux-2.6.32-vs2.3.0.36.26/net/core/rtnetlink.c     2009-12-03 20:04:56.000000000 +0100
26956 @@ -688,6 +688,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26957  
26958         idx = 0;
26959         for_each_netdev(net, dev) {
26960 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26961 +                       continue;
26962                 if (idx < s_idx)
26963                         goto cont;
26964                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26965 @@ -1222,6 +1224,9 @@ void rtmsg_ifinfo(int type, struct net_d
26966         struct sk_buff *skb;
26967         int err = -ENOBUFS;
26968  
26969 +       if (!nx_dev_visible(current_nx_info(), dev))
26970 +               return;
26971 +
26972         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26973         if (skb == NULL)
26974                 goto errout;
26975 diff -NurpP --minimal linux-2.6.32/net/core/sock.c linux-2.6.32-vs2.3.0.36.26/net/core/sock.c
26976 --- linux-2.6.32/net/core/sock.c        2009-12-03 20:02:59.000000000 +0100
26977 +++ linux-2.6.32-vs2.3.0.36.26/net/core/sock.c  2009-12-03 20:04:56.000000000 +0100
26978 @@ -125,6 +125,10 @@
26979  #include <linux/ipsec.h>
26980  
26981  #include <linux/filter.h>
26982 +#include <linux/vs_socket.h>
26983 +#include <linux/vs_limit.h>
26984 +#include <linux/vs_context.h>
26985 +#include <linux/vs_network.h>
26986  
26987  #ifdef CONFIG_INET
26988  #include <net/tcp.h>
26989 @@ -984,6 +988,8 @@ static struct sock *sk_prot_alloc(struct
26990                 if (!try_module_get(prot->owner))
26991                         goto out_free_sec;
26992         }
26993 +               sock_vx_init(sk);
26994 +               sock_nx_init(sk);
26995  
26996         return sk;
26997  
26998 @@ -1063,6 +1069,11 @@ static void __sk_free(struct sock *sk)
26999                        __func__, atomic_read(&sk->sk_omem_alloc));
27000  
27001         put_net(sock_net(sk));
27002 +       vx_sock_dec(sk);
27003 +       clr_vx_info(&sk->sk_vx_info);
27004 +       sk->sk_xid = -1;
27005 +       clr_nx_info(&sk->sk_nx_info);
27006 +       sk->sk_nid = -1;
27007         sk_prot_free(sk->sk_prot_creator, sk);
27008  }
27009  
27010 @@ -1110,6 +1121,8 @@ struct sock *sk_clone(const struct sock 
27011  
27012                 /* SANITY */
27013                 get_net(sock_net(newsk));
27014 +               sock_vx_init(newsk);
27015 +               sock_nx_init(newsk);
27016                 sk_node_init(&newsk->sk_node);
27017                 sock_lock_init(newsk);
27018                 bh_lock_sock(newsk);
27019 @@ -1164,6 +1177,12 @@ struct sock *sk_clone(const struct sock 
27020                 smp_wmb();
27021                 atomic_set(&newsk->sk_refcnt, 2);
27022  
27023 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
27024 +               newsk->sk_xid = sk->sk_xid;
27025 +               vx_sock_inc(newsk);
27026 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
27027 +               newsk->sk_nid = sk->sk_nid;
27028 +
27029                 /*
27030                  * Increment the counter in the same struct proto as the master
27031                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
27032 @@ -1882,6 +1901,12 @@ void sock_init_data(struct socket *sock,
27033  
27034         sk->sk_stamp = ktime_set(-1L, 0);
27035  
27036 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
27037 +       sk->sk_xid = vx_current_xid();
27038 +       vx_sock_inc(sk);
27039 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
27040 +       sk->sk_nid = nx_current_nid();
27041 +
27042         /*
27043          * Before updating sk_refcnt, we must commit prior changes to memory
27044          * (Documentation/RCU/rculist_nulls.txt for details)
27045 diff -NurpP --minimal linux-2.6.32/net/ipv4/af_inet.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/af_inet.c
27046 --- linux-2.6.32/net/ipv4/af_inet.c     2009-12-03 20:02:59.000000000 +0100
27047 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/af_inet.c       2009-12-03 20:04:56.000000000 +0100
27048 @@ -115,6 +115,7 @@
27049  #ifdef CONFIG_IP_MROUTE
27050  #include <linux/mroute.h>
27051  #endif
27052 +#include <linux/vs_limit.h>
27053  
27054  
27055  /* The inetsw table contains everything that inet_create needs to
27056 @@ -325,9 +326,12 @@ lookup_protocol:
27057         }
27058  
27059         err = -EPERM;
27060 +       if ((protocol == IPPROTO_ICMP) &&
27061 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27062 +               goto override;
27063         if (answer->capability > 0 && !capable(answer->capability))
27064                 goto out_rcu_unlock;
27065 -
27066 +override:
27067         err = -EAFNOSUPPORT;
27068         if (!inet_netns_ok(net, protocol))
27069                 goto out_rcu_unlock;
27070 @@ -447,6 +451,7 @@ int inet_bind(struct socket *sock, struc
27071         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
27072         struct sock *sk = sock->sk;
27073         struct inet_sock *inet = inet_sk(sk);
27074 +       struct nx_v4_sock_addr nsa;
27075         unsigned short snum;
27076         int chk_addr_ret;
27077         int err;
27078 @@ -460,7 +465,11 @@ int inet_bind(struct socket *sock, struc
27079         if (addr_len < sizeof(struct sockaddr_in))
27080                 goto out;
27081  
27082 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27083 +       err = v4_map_sock_addr(inet, addr, &nsa);
27084 +       if (err)
27085 +               goto out;
27086 +
27087 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27088  
27089         /* Not specified by any standard per-se, however it breaks too
27090          * many applications when removed.  It is unfortunate since
27091 @@ -472,7 +481,7 @@ int inet_bind(struct socket *sock, struc
27092         err = -EADDRNOTAVAIL;
27093         if (!sysctl_ip_nonlocal_bind &&
27094             !(inet->freebind || inet->transparent) &&
27095 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
27096 +           nsa.saddr != htonl(INADDR_ANY) &&
27097             chk_addr_ret != RTN_LOCAL &&
27098             chk_addr_ret != RTN_MULTICAST &&
27099             chk_addr_ret != RTN_BROADCAST)
27100 @@ -497,7 +506,7 @@ int inet_bind(struct socket *sock, struc
27101         if (sk->sk_state != TCP_CLOSE || inet->num)
27102                 goto out_release_sock;
27103  
27104 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27105 +       v4_set_sock_addr(inet, &nsa);
27106         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27107                 inet->saddr = 0;  /* Use device */
27108  
27109 @@ -694,11 +703,13 @@ int inet_getname(struct socket *sock, st
27110                      peer == 1))
27111                         return -ENOTCONN;
27112                 sin->sin_port = inet->dport;
27113 -               sin->sin_addr.s_addr = inet->daddr;
27114 +               sin->sin_addr.s_addr =
27115 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27116         } else {
27117                 __be32 addr = inet->rcv_saddr;
27118                 if (!addr)
27119                         addr = inet->saddr;
27120 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
27121                 sin->sin_port = inet->sport;
27122                 sin->sin_addr.s_addr = addr;
27123         }
27124 diff -NurpP --minimal linux-2.6.32/net/ipv4/devinet.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/devinet.c
27125 --- linux-2.6.32/net/ipv4/devinet.c     2009-12-03 20:02:59.000000000 +0100
27126 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/devinet.c       2009-12-03 20:04:56.000000000 +0100
27127 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
27128         return in_dev;
27129  }
27130  
27131 +
27132  /* Called only from RTNL semaphored context. No locks. */
27133  
27134  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
27135 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
27136                 *colon = ':';
27137  
27138         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
27139 +               struct nx_info *nxi = current_nx_info();
27140 +
27141                 if (tryaddrmatch) {
27142                         /* Matthias Andree */
27143                         /* compare label and address (4.4BSD style) */
27144 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
27145                            This is checked above. */
27146                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27147                              ifap = &ifa->ifa_next) {
27148 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27149 +                                       continue;
27150                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
27151                                     sin_orig.sin_addr.s_addr ==
27152                                                         ifa->ifa_address) {
27153 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
27154                    comparing just the label */
27155                 if (!ifa) {
27156                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27157 -                            ifap = &ifa->ifa_next)
27158 +                            ifap = &ifa->ifa_next) {
27159 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27160 +                                       continue;
27161                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
27162                                         break;
27163 +                       }
27164                 }
27165         }
27166  
27167 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
27168                 goto out;
27169  
27170         for (; ifa; ifa = ifa->ifa_next) {
27171 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
27172 +                       continue;
27173                 if (!buf) {
27174                         done += sizeof(ifr);
27175                         continue;
27176 @@ -1174,6 +1184,7 @@ static int inet_dump_ifaddr(struct sk_bu
27177         struct net_device *dev;
27178         struct in_device *in_dev;
27179         struct in_ifaddr *ifa;
27180 +       struct sock *sk = skb->sk;
27181         int s_ip_idx, s_idx = cb->args[0];
27182  
27183         s_ip_idx = ip_idx = cb->args[1];
27184 @@ -1188,6 +1199,8 @@ static int inet_dump_ifaddr(struct sk_bu
27185  
27186                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
27187                      ifa = ifa->ifa_next, ip_idx++) {
27188 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
27189 +                               continue;
27190                         if (ip_idx < s_ip_idx)
27191                                 continue;
27192                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27193 diff -NurpP --minimal linux-2.6.32/net/ipv4/fib_hash.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/fib_hash.c
27194 --- linux-2.6.32/net/ipv4/fib_hash.c    2009-09-10 15:26:29.000000000 +0200
27195 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/fib_hash.c      2009-12-03 20:04:56.000000000 +0100
27196 @@ -1021,7 +1021,7 @@ static int fib_seq_show(struct seq_file 
27197         prefix  = f->fn_key;
27198         mask    = FZ_MASK(iter->zone);
27199         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27200 -       if (fi)
27201 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
27202                 seq_printf(seq,
27203                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
27204                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27205 diff -NurpP --minimal linux-2.6.32/net/ipv4/inet_connection_sock.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/inet_connection_sock.c
27206 --- linux-2.6.32/net/ipv4/inet_connection_sock.c        2009-12-03 20:02:59.000000000 +0100
27207 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/inet_connection_sock.c  2009-12-03 20:04:56.000000000 +0100
27208 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
27209  }
27210  EXPORT_SYMBOL(inet_get_local_port_range);
27211  
27212 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27213 +{
27214 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
27215 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
27216 +
27217 +       if (inet_v6_ipv6only(sk2))
27218 +               return 0;
27219 +
27220 +       if (sk1_rcv_saddr &&
27221 +           sk2_rcv_saddr &&
27222 +           sk1_rcv_saddr == sk2_rcv_saddr)
27223 +               return 1;
27224 +
27225 +       if (sk1_rcv_saddr &&
27226 +           !sk2_rcv_saddr &&
27227 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
27228 +               return 1;
27229 +
27230 +       if (sk2_rcv_saddr &&
27231 +           !sk1_rcv_saddr &&
27232 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
27233 +               return 1;
27234 +
27235 +       if (!sk1_rcv_saddr &&
27236 +           !sk2_rcv_saddr &&
27237 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
27238 +               return 1;
27239 +
27240 +       return 0;
27241 +}
27242 +
27243  int inet_csk_bind_conflict(const struct sock *sk,
27244                            const struct inet_bind_bucket *tb)
27245  {
27246 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27247         struct sock *sk2;
27248         struct hlist_node *node;
27249         int reuse = sk->sk_reuse;
27250 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
27251                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27252                         if (!reuse || !sk2->sk_reuse ||
27253                             sk2->sk_state == TCP_LISTEN) {
27254 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27255 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27256 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27257 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27258                                         break;
27259                         }
27260                 }
27261 diff -NurpP --minimal linux-2.6.32/net/ipv4/inet_diag.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/inet_diag.c
27262 --- linux-2.6.32/net/ipv4/inet_diag.c   2009-09-10 15:26:29.000000000 +0200
27263 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/inet_diag.c     2009-12-03 20:04:56.000000000 +0100
27264 @@ -32,6 +32,8 @@
27265  #include <linux/stddef.h>
27266  
27267  #include <linux/inet_diag.h>
27268 +#include <linux/vs_network.h>
27269 +#include <linux/vs_inet.h>
27270  
27271  static const struct inet_diag_handler **inet_diag_table;
27272  
27273 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
27274  
27275         r->id.idiag_sport = inet->sport;
27276         r->id.idiag_dport = inet->dport;
27277 -       r->id.idiag_src[0] = inet->rcv_saddr;
27278 -       r->id.idiag_dst[0] = inet->daddr;
27279 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27280 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27281  
27282  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27283         if (r->idiag_family == AF_INET6) {
27284 @@ -204,8 +206,8 @@ static int inet_twsk_diag_fill(struct in
27285         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27286         r->id.idiag_sport     = tw->tw_sport;
27287         r->id.idiag_dport     = tw->tw_dport;
27288 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27289 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27290 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27291 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27292         r->idiag_state        = tw->tw_substate;
27293         r->idiag_timer        = 3;
27294         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27295 @@ -262,6 +264,7 @@ static int inet_diag_get_exact(struct sk
27296         err = -EINVAL;
27297  
27298         if (req->idiag_family == AF_INET) {
27299 +               /* TODO: lback */
27300                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27301                                  req->id.idiag_dport, req->id.idiag_src[0],
27302                                  req->id.idiag_sport, req->id.idiag_if);
27303 @@ -504,6 +507,7 @@ static int inet_csk_diag_dump(struct soc
27304                 } else
27305  #endif
27306                 {
27307 +                       /* TODO: lback */
27308                         entry.saddr = &inet->rcv_saddr;
27309                         entry.daddr = &inet->daddr;
27310                 }
27311 @@ -540,6 +544,7 @@ static int inet_twsk_diag_dump(struct in
27312                 } else
27313  #endif
27314                 {
27315 +                       /* TODO: lback */
27316                         entry.saddr = &tw->tw_rcv_saddr;
27317                         entry.daddr = &tw->tw_daddr;
27318                 }
27319 @@ -586,8 +591,8 @@ static int inet_diag_fill_req(struct sk_
27320  
27321         r->id.idiag_sport = inet->sport;
27322         r->id.idiag_dport = ireq->rmt_port;
27323 -       r->id.idiag_src[0] = ireq->loc_addr;
27324 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27325 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27326 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27327         r->idiag_expires = jiffies_to_msecs(tmo);
27328         r->idiag_rqueue = 0;
27329         r->idiag_wqueue = 0;
27330 @@ -657,6 +662,7 @@ static int inet_diag_dump_reqs(struct sk
27331                                 continue;
27332  
27333                         if (bc) {
27334 +                               /* TODO: lback */
27335                                 entry.saddr =
27336  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27337                                         (entry.family == AF_INET6) ?
27338 @@ -727,6 +733,8 @@ static int inet_diag_dump(struct sk_buff
27339                         sk_nulls_for_each(sk, node, &ilb->head) {
27340                                 struct inet_sock *inet = inet_sk(sk);
27341  
27342 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27343 +                                       continue;
27344                                 if (num < s_num) {
27345                                         num++;
27346                                         continue;
27347 @@ -793,6 +801,8 @@ skip_listen_ht:
27348                 sk_nulls_for_each(sk, node, &head->chain) {
27349                         struct inet_sock *inet = inet_sk(sk);
27350  
27351 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27352 +                               continue;
27353                         if (num < s_num)
27354                                 goto next_normal;
27355                         if (!(r->idiag_states & (1 << sk->sk_state)))
27356 @@ -817,6 +827,8 @@ next_normal:
27357                         inet_twsk_for_each(tw, node,
27358                                     &head->twchain) {
27359  
27360 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27361 +                                       continue;
27362                                 if (num < s_num)
27363                                         goto next_dying;
27364                                 if (r->id.idiag_sport != tw->tw_sport &&
27365 diff -NurpP --minimal linux-2.6.32/net/ipv4/inet_hashtables.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/inet_hashtables.c
27366 --- linux-2.6.32/net/ipv4/inet_hashtables.c     2009-06-11 17:13:29.000000000 +0200
27367 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/inet_hashtables.c       2009-12-03 20:04:56.000000000 +0100
27368 @@ -21,6 +21,7 @@
27369  
27370  #include <net/inet_connection_sock.h>
27371  #include <net/inet_hashtables.h>
27372 +#include <net/route.h>
27373  #include <net/ip.h>
27374  
27375  /*
27376 @@ -134,6 +135,11 @@ static inline int compute_score(struct s
27377                         if (rcv_saddr != daddr)
27378                                 return -1;
27379                         score += 2;
27380 +               } else {
27381 +                       /* block non nx_info ips */
27382 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27383 +                               daddr, NXA_MASK_BIND))
27384 +                               return -1;
27385                 }
27386                 if (sk->sk_bound_dev_if) {
27387                         if (sk->sk_bound_dev_if != dif)
27388 @@ -151,7 +157,6 @@ static inline int compute_score(struct s
27389   * wildcarded during the search since they can never be otherwise.
27390   */
27391  
27392 -
27393  struct sock *__inet_lookup_listener(struct net *net,
27394                                     struct inet_hashinfo *hashinfo,
27395                                     const __be32 daddr, const unsigned short hnum,
27396 @@ -174,6 +179,7 @@ begin:
27397                         hiscore = score;
27398                 }
27399         }
27400 +
27401         /*
27402          * if the nulls value we got at the end of this lookup is
27403          * not the expected one, we must restart lookup.
27404 diff -NurpP --minimal linux-2.6.32/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/netfilter/nf_nat_helper.c
27405 --- linux-2.6.32/net/ipv4/netfilter/nf_nat_helper.c     2009-12-03 20:02:59.000000000 +0100
27406 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/netfilter/nf_nat_helper.c       2009-12-03 20:04:56.000000000 +0100
27407 @@ -19,6 +19,7 @@
27408  #include <net/route.h>
27409  
27410  #include <linux/netfilter_ipv4.h>
27411 +#include <net/route.h>
27412  #include <net/netfilter/nf_conntrack.h>
27413  #include <net/netfilter/nf_conntrack_helper.h>
27414  #include <net/netfilter/nf_conntrack_ecache.h>
27415 diff -NurpP --minimal linux-2.6.32/net/ipv4/netfilter.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/netfilter.c
27416 --- linux-2.6.32/net/ipv4/netfilter.c   2009-09-10 15:26:29.000000000 +0200
27417 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/netfilter.c     2009-12-03 20:04:56.000000000 +0100
27418 @@ -4,7 +4,7 @@
27419  #include <linux/netfilter_ipv4.h>
27420  #include <linux/ip.h>
27421  #include <linux/skbuff.h>
27422 -#include <net/route.h>
27423 +// #include <net/route.h>
27424  #include <net/xfrm.h>
27425  #include <net/ip.h>
27426  #include <net/netfilter/nf_queue.h>
27427 diff -NurpP --minimal linux-2.6.32/net/ipv4/raw.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/raw.c
27428 --- linux-2.6.32/net/ipv4/raw.c 2009-12-03 20:02:59.000000000 +0100
27429 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/raw.c   2009-12-03 20:04:56.000000000 +0100
27430 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27431  
27432                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27433                     !(inet->daddr && inet->daddr != raddr)              &&
27434 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27435 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27436                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27437                         goto found; /* gotcha */
27438         }
27439 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
27440                 icmp_out_count(net, ((struct icmphdr *)
27441                         skb_transport_header(skb))->type);
27442  
27443 +       err = -EPERM;
27444 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27445 +               sk->sk_nx_info &&
27446 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27447 +               goto error_free;
27448 +
27449         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27450                       dst_output);
27451         if (err > 0)
27452 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
27453                 }
27454  
27455                 security_sk_classify_flow(sk, &fl);
27456 +               if (sk->sk_nx_info) {
27457 +                       err = ip_v4_find_src(sock_net(sk),
27458 +                               sk->sk_nx_info, &rt, &fl);
27459 +
27460 +                       if (err)
27461 +                               goto done;
27462 +               }
27463                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27464         }
27465         if (err)
27466 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
27467  {
27468         struct inet_sock *inet = inet_sk(sk);
27469         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27470 +       struct nx_v4_sock_addr nsa = { 0 };
27471         int ret = -EINVAL;
27472         int chk_addr_ret;
27473  
27474         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27475                 goto out;
27476 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27477 +       v4_map_sock_addr(inet, addr, &nsa);
27478 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27479         ret = -EADDRNOTAVAIL;
27480 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27481 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27482             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27483                 goto out;
27484 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27485 +       v4_set_sock_addr(inet, &nsa);
27486         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27487                 inet->saddr = 0;  /* Use device */
27488         sk_dst_reset(sk);
27489 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
27490         /* Copy the address. */
27491         if (sin) {
27492                 sin->sin_family = AF_INET;
27493 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27494 +               sin->sin_addr.s_addr =
27495 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27496                 sin->sin_port = 0;
27497                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27498         }
27499 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
27500                 struct hlist_node *node;
27501  
27502                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27503 -                       if (sock_net(sk) == seq_file_net(seq))
27504 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27505 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27506                                 goto found;
27507         }
27508         sk = NULL;
27509 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
27510                 sk = sk_next(sk);
27511  try_again:
27512                 ;
27513 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27514 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27515 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27516  
27517         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27518                 sk = sk_head(&state->h->ht[state->bucket]);
27519 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
27520  
27521         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27522                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27523 -               i, src, srcp, dest, destp, sp->sk_state,
27524 +               i,
27525 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27526 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27527 +               sp->sk_state,
27528                 sk_wmem_alloc_get(sp),
27529                 sk_rmem_alloc_get(sp),
27530                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27531 diff -NurpP --minimal linux-2.6.32/net/ipv4/tcp.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/tcp.c
27532 --- linux-2.6.32/net/ipv4/tcp.c 2009-12-03 20:02:59.000000000 +0100
27533 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/tcp.c   2009-12-03 20:04:56.000000000 +0100
27534 @@ -264,6 +264,7 @@
27535  #include <linux/cache.h>
27536  #include <linux/err.h>
27537  #include <linux/crypto.h>
27538 +#include <linux/in.h>
27539  
27540  #include <net/icmp.h>
27541  #include <net/tcp.h>
27542 diff -NurpP --minimal linux-2.6.32/net/ipv4/tcp_ipv4.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/tcp_ipv4.c
27543 --- linux-2.6.32/net/ipv4/tcp_ipv4.c    2009-12-03 20:03:00.000000000 +0100
27544 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/tcp_ipv4.c      2009-12-03 20:04:56.000000000 +0100
27545 @@ -1925,6 +1925,12 @@ static void *listening_get_next(struct s
27546                 req = req->dl_next;
27547                 while (1) {
27548                         while (req) {
27549 +                               vxdprintk(VXD_CBIT(net, 6),
27550 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27551 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27552 +                               if (req->sk &&
27553 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27554 +                                       continue;
27555                                 if (req->rsk_ops->family == st->family) {
27556                                         cur = req;
27557                                         goto out;
27558 @@ -1949,6 +1955,10 @@ get_req:
27559         }
27560  get_sk:
27561         sk_nulls_for_each_from(sk, node) {
27562 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27563 +                       sk, sk->sk_nid, nx_current_nid());
27564 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27565 +                       continue;
27566                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27567                         cur = sk;
27568                         goto out;
27569 @@ -2012,6 +2022,11 @@ static void *established_get_first(struc
27570  
27571                 spin_lock_bh(lock);
27572                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27573 +                       vxdprintk(VXD_CBIT(net, 6),
27574 +                               "sk,egf: %p [#%d] (from %d)",
27575 +                               sk, sk->sk_nid, nx_current_nid());
27576 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27577 +                               continue;
27578                         if (sk->sk_family != st->family ||
27579                             !net_eq(sock_net(sk), net)) {
27580                                 continue;
27581 @@ -2022,6 +2037,11 @@ static void *established_get_first(struc
27582                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27583                 inet_twsk_for_each(tw, node,
27584                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27585 +                       vxdprintk(VXD_CBIT(net, 6),
27586 +                               "tw: %p [#%d] (from %d)",
27587 +                               tw, tw->tw_nid, nx_current_nid());
27588 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27589 +                               continue;
27590                         if (tw->tw_family != st->family ||
27591                             !net_eq(twsk_net(tw), net)) {
27592                                 continue;
27593 @@ -2050,7 +2070,9 @@ static void *established_get_next(struct
27594                 tw = cur;
27595                 tw = tw_next(tw);
27596  get_tw:
27597 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27598 +               while (tw && (tw->tw_family != st->family ||
27599 +                       !net_eq(twsk_net(tw), net) ||
27600 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27601                         tw = tw_next(tw);
27602                 }
27603                 if (tw) {
27604 @@ -2073,6 +2095,11 @@ get_tw:
27605                 sk = sk_nulls_next(sk);
27606  
27607         sk_nulls_for_each_from(sk, node) {
27608 +               vxdprintk(VXD_CBIT(net, 6),
27609 +                       "sk,egn: %p [#%d] (from %d)",
27610 +                       sk, sk->sk_nid, nx_current_nid());
27611 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27612 +                       continue;
27613                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27614                         goto found;
27615         }
27616 @@ -2224,9 +2251,9 @@ static void get_openreq4(struct sock *sk
27617         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27618                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27619                 i,
27620 -               ireq->loc_addr,
27621 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27622                 ntohs(inet_sk(sk)->sport),
27623 -               ireq->rmt_addr,
27624 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27625                 ntohs(ireq->rmt_port),
27626                 TCP_SYN_RECV,
27627                 0, 0, /* could print option size, but that is af dependent. */
27628 @@ -2269,7 +2296,10 @@ static void get_tcp4_sock(struct sock *s
27629  
27630         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27631                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27632 -               i, src, srcp, dest, destp, sk->sk_state,
27633 +               i,
27634 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27635 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27636 +               sk->sk_state,
27637                 tp->write_seq - tp->snd_una,
27638                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27639                                              (tp->rcv_nxt - tp->copied_seq),
27640 @@ -2305,7 +2335,10 @@ static void get_timewait4_sock(struct in
27641  
27642         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27643                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27644 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27645 +               i,
27646 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27647 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27648 +               tw->tw_substate, 0, 0,
27649                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27650                 atomic_read(&tw->tw_refcnt), tw, len);
27651  }
27652 diff -NurpP --minimal linux-2.6.32/net/ipv4/tcp_minisocks.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/tcp_minisocks.c
27653 --- linux-2.6.32/net/ipv4/tcp_minisocks.c       2009-12-03 20:03:00.000000000 +0100
27654 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/tcp_minisocks.c 2009-12-03 20:04:56.000000000 +0100
27655 @@ -26,6 +26,10 @@
27656  #include <net/inet_common.h>
27657  #include <net/xfrm.h>
27658  
27659 +#include <linux/vs_limit.h>
27660 +#include <linux/vs_socket.h>
27661 +#include <linux/vs_context.h>
27662 +
27663  #ifdef CONFIG_SYSCTL
27664  #define SYNC_INIT 0 /* let the user enable it */
27665  #else
27666 @@ -294,6 +298,11 @@ void tcp_time_wait(struct sock *sk, int 
27667                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27668                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27669  
27670 +               tw->tw_xid              = sk->sk_xid;
27671 +               tw->tw_vx_info          = NULL;
27672 +               tw->tw_nid              = sk->sk_nid;
27673 +               tw->tw_nx_info          = NULL;
27674 +
27675  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27676                 if (tw->tw_family == PF_INET6) {
27677                         struct ipv6_pinfo *np = inet6_sk(sk);
27678 diff -NurpP --minimal linux-2.6.32/net/ipv4/udp.c linux-2.6.32-vs2.3.0.36.26/net/ipv4/udp.c
27679 --- linux-2.6.32/net/ipv4/udp.c 2009-12-03 20:03:00.000000000 +0100
27680 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv4/udp.c   2009-12-03 20:04:56.000000000 +0100
27681 @@ -224,14 +224,7 @@ fail:
27682  }
27683  EXPORT_SYMBOL(udp_lib_get_port);
27684  
27685 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27686 -{
27687 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27688 -
27689 -       return  (!ipv6_only_sock(sk2)  &&
27690 -                (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27691 -                  inet1->rcv_saddr == inet2->rcv_saddr));
27692 -}
27693 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27694  
27695  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27696  {
27697 @@ -253,6 +246,11 @@ static inline int compute_score(struct s
27698                         if (inet->rcv_saddr != daddr)
27699                                 return -1;
27700                         score += 2;
27701 +               } else {
27702 +                       /* block non nx_info ips */
27703 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27704 +                               daddr, NXA_MASK_BIND))
27705 +                               return -1;
27706                 }
27707                 if (inet->daddr) {
27708                         if (inet->daddr != saddr)
27709 @@ -273,6 +271,7 @@ static inline int compute_score(struct s
27710         return score;
27711  }
27712  
27713 +
27714  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27715   * harder than this. -DaveM
27716   */
27717 @@ -294,6 +293,11 @@ begin:
27718         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27719                 score = compute_score(sk, net, saddr, hnum, sport,
27720                                       daddr, dport, dif);
27721 +               /* FIXME: disabled?
27722 +               if (score == 9) {
27723 +                       result = sk;
27724 +                       break;
27725 +               } else */
27726                 if (score > badness) {
27727                         result = sk;
27728                         badness = score;
27729 @@ -307,6 +311,7 @@ begin:
27730         if (get_nulls_value(node) != hash)
27731                 goto begin;
27732  
27733 +
27734         if (result) {
27735                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27736                         result = NULL;
27737 @@ -316,6 +321,7 @@ begin:
27738                         goto begin;
27739                 }
27740         }
27741 +
27742         rcu_read_unlock();
27743         return result;
27744  }
27745 @@ -358,7 +364,7 @@ static inline struct sock *udp_v4_mcast_
27746                     s->sk_hash != hnum                                  ||
27747                     (inet->daddr && inet->daddr != rmt_addr)            ||
27748                     (inet->dport != rmt_port && inet->dport)            ||
27749 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27750 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27751                     ipv6_only_sock(s)                                   ||
27752                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27753                         continue;
27754 @@ -707,8 +713,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27755                                                { .sport = inet->sport,
27756                                                  .dport = dport } } };
27757                 struct net *net = sock_net(sk);
27758 +               struct nx_info *nxi = sk->sk_nx_info;
27759  
27760                 security_sk_classify_flow(sk, &fl);
27761 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27762 +               if (err)
27763 +                       goto out;
27764 +
27765                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27766                 if (err) {
27767                         if (err == -ENETUNREACH)
27768 @@ -988,7 +999,8 @@ try_again:
27769         if (sin) {
27770                 sin->sin_family = AF_INET;
27771                 sin->sin_port = udp_hdr(skb)->source;
27772 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27773 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27774 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27775                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27776         }
27777         if (inet->cmsg_flags)
27778 @@ -1627,6 +1639,8 @@ static struct sock *udp_get_first(struct
27779                 sk_nulls_for_each(sk, node, &hslot->head) {
27780                         if (!net_eq(sock_net(sk), net))
27781                                 continue;
27782 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27783 +                               continue;
27784                         if (sk->sk_family == state->family)
27785                                 goto found;
27786                 }
27787 @@ -1644,7 +1658,9 @@ static struct sock *udp_get_next(struct 
27788  
27789         do {
27790                 sk = sk_nulls_next(sk);
27791 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27792 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27793 +               sk->sk_family != state->family ||
27794 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27795  
27796         if (!sk) {
27797                 if (state->bucket < UDP_HTABLE_SIZE)
27798 @@ -1751,7 +1767,10 @@ static void udp4_format_sock(struct sock
27799  
27800         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27801                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27802 -               bucket, src, srcp, dest, destp, sp->sk_state,
27803 +               bucket,
27804 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27805 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27806 +               sp->sk_state,
27807                 sk_wmem_alloc_get(sp),
27808                 sk_rmem_alloc_get(sp),
27809                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27810 diff -NurpP --minimal linux-2.6.32/net/ipv6/addrconf.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/addrconf.c
27811 --- linux-2.6.32/net/ipv6/addrconf.c    2009-12-03 20:03:00.000000000 +0100
27812 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/addrconf.c      2009-12-03 20:04:56.000000000 +0100
27813 @@ -86,6 +86,8 @@
27814  
27815  #include <linux/proc_fs.h>
27816  #include <linux/seq_file.h>
27817 +#include <linux/vs_network.h>
27818 +#include <linux/vs_inet6.h>
27819  
27820  /* Set to 3 to get tracing... */
27821  #define ACONF_DEBUG 2
27822 @@ -1119,7 +1121,7 @@ out:
27823  
27824  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27825                        const struct in6_addr *daddr, unsigned int prefs,
27826 -                      struct in6_addr *saddr)
27827 +                      struct in6_addr *saddr, struct nx_info *nxi)
27828  {
27829         struct ipv6_saddr_score scores[2],
27830                                 *score = &scores[0], *hiscore = &scores[1];
27831 @@ -1192,6 +1194,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27832                                                dev->name);
27833                                 continue;
27834                         }
27835 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27836 +                               continue;
27837  
27838                         score->rule = -1;
27839                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27840 @@ -3000,7 +3004,10 @@ static void if6_seq_stop(struct seq_file
27841  static int if6_seq_show(struct seq_file *seq, void *v)
27842  {
27843         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27844 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27845 +
27846 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27847 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27848 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27849                    &ifp->addr,
27850                    ifp->idev->dev->ifindex,
27851                    ifp->prefix_len,
27852 @@ -3497,6 +3504,12 @@ static int inet6_dump_addr(struct sk_buf
27853         struct ifmcaddr6 *ifmca;
27854         struct ifacaddr6 *ifaca;
27855         struct net *net = sock_net(skb->sk);
27856 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27857 +
27858 +       /* disable ipv6 on non v6 guests */
27859 +       if (nxi && !nx_info_has_v6(nxi))
27860 +               return skb->len;
27861 +
27862  
27863         s_idx = cb->args[0];
27864         s_ip_idx = ip_idx = cb->args[1];
27865 @@ -3518,6 +3531,8 @@ static int inet6_dump_addr(struct sk_buf
27866                              ifa = ifa->if_next, ip_idx++) {
27867                                 if (ip_idx < s_ip_idx)
27868                                         continue;
27869 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27870 +                                       continue;
27871                                 err = inet6_fill_ifaddr(skb, ifa,
27872                                                         NETLINK_CB(cb->skb).pid,
27873                                                         cb->nlh->nlmsg_seq,
27874 @@ -3531,6 +3546,8 @@ static int inet6_dump_addr(struct sk_buf
27875                              ifmca = ifmca->next, ip_idx++) {
27876                                 if (ip_idx < s_ip_idx)
27877                                         continue;
27878 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27879 +                                       continue;
27880                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27881                                                           NETLINK_CB(cb->skb).pid,
27882                                                           cb->nlh->nlmsg_seq,
27883 @@ -3544,6 +3561,8 @@ static int inet6_dump_addr(struct sk_buf
27884                              ifaca = ifaca->aca_next, ip_idx++) {
27885                                 if (ip_idx < s_ip_idx)
27886                                         continue;
27887 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27888 +                                       continue;
27889                                 err = inet6_fill_ifacaddr(skb, ifaca,
27890                                                           NETLINK_CB(cb->skb).pid,
27891                                                           cb->nlh->nlmsg_seq,
27892 @@ -3830,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
27893         int s_idx = cb->args[0];
27894         struct net_device *dev;
27895         struct inet6_dev *idev;
27896 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27897 +
27898 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27899 +       if (skb->sk && skb->sk->sk_vx_info)
27900 +               return skb->len; */
27901  
27902         read_lock(&dev_base_lock);
27903         idx = 0;
27904         for_each_netdev(net, dev) {
27905                 if (idx < s_idx)
27906                         goto cont;
27907 +               if (!v6_dev_in_nx_info(dev, nxi))
27908 +                       goto cont;
27909                 if ((idev = in6_dev_get(dev)) == NULL)
27910                         goto cont;
27911                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27912 diff -NurpP --minimal linux-2.6.32/net/ipv6/af_inet6.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/af_inet6.c
27913 --- linux-2.6.32/net/ipv6/af_inet6.c    2009-12-03 20:03:00.000000000 +0100
27914 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/af_inet6.c      2009-12-03 20:04:56.000000000 +0100
27915 @@ -41,6 +41,8 @@
27916  #include <linux/netdevice.h>
27917  #include <linux/icmpv6.h>
27918  #include <linux/netfilter_ipv6.h>
27919 +#include <linux/vs_inet.h>
27920 +#include <linux/vs_inet6.h>
27921  
27922  #include <net/ip.h>
27923  #include <net/ipv6.h>
27924 @@ -158,9 +160,12 @@ lookup_protocol:
27925         }
27926  
27927         err = -EPERM;
27928 +       if ((protocol == IPPROTO_ICMPV6) &&
27929 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27930 +               goto override;
27931         if (answer->capability > 0 && !capable(answer->capability))
27932                 goto out_rcu_unlock;
27933 -
27934 +override:
27935         sock->ops = answer->ops;
27936         answer_prot = answer->prot;
27937         answer_no_check = answer->no_check;
27938 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
27939         struct inet_sock *inet = inet_sk(sk);
27940         struct ipv6_pinfo *np = inet6_sk(sk);
27941         struct net *net = sock_net(sk);
27942 +       struct nx_v6_sock_addr nsa;
27943         __be32 v4addr = 0;
27944         unsigned short snum;
27945         int addr_type = 0;
27946 @@ -270,6 +276,11 @@ int inet6_bind(struct socket *sock, stru
27947  
27948         if (addr_len < SIN6_LEN_RFC2133)
27949                 return -EINVAL;
27950 +
27951 +       err = v6_map_sock_addr(inet, addr, &nsa);
27952 +       if (err)
27953 +               return err;
27954 +
27955         addr_type = ipv6_addr_type(&addr->sin6_addr);
27956         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27957                 return -EINVAL;
27958 @@ -301,6 +312,7 @@ int inet6_bind(struct socket *sock, stru
27959                 /* Reproduce AF_INET checks to make the bindings consitant */
27960                 v4addr = addr->sin6_addr.s6_addr32[3];
27961                 chk_addr_ret = inet_addr_type(net, v4addr);
27962 +
27963                 if (!sysctl_ip_nonlocal_bind &&
27964                     !(inet->freebind || inet->transparent) &&
27965                     v4addr != htonl(INADDR_ANY) &&
27966 @@ -310,6 +322,10 @@ int inet6_bind(struct socket *sock, stru
27967                         err = -EADDRNOTAVAIL;
27968                         goto out;
27969                 }
27970 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27971 +                       err = -EADDRNOTAVAIL;
27972 +                       goto out;
27973 +               }
27974         } else {
27975                 if (addr_type != IPV6_ADDR_ANY) {
27976                         struct net_device *dev = NULL;
27977 @@ -335,6 +351,11 @@ int inet6_bind(struct socket *sock, stru
27978                                 }
27979                         }
27980  
27981 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27982 +                               err = -EADDRNOTAVAIL;
27983 +                               goto out;
27984 +                       }
27985 +
27986                         /* ipv4 addr of the socket is invalid.  Only the
27987                          * unspecified and mapped address have a v4 equivalent.
27988                          */
27989 @@ -353,6 +374,8 @@ int inet6_bind(struct socket *sock, stru
27990                 }
27991         }
27992  
27993 +       v6_set_sock_addr(inet, &nsa);
27994 +
27995         inet->rcv_saddr = v4addr;
27996         inet->saddr = v4addr;
27997  
27998 @@ -448,9 +471,11 @@ int inet6_getname(struct socket *sock, s
27999                         return -ENOTCONN;
28000                 sin->sin6_port = inet->dport;
28001                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
28002 +               /* FIXME: remap lback? */
28003                 if (np->sndflow)
28004                         sin->sin6_flowinfo = np->flow_label;
28005         } else {
28006 +               /* FIXME: remap lback? */
28007                 if (ipv6_addr_any(&np->rcv_saddr))
28008                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
28009                 else
28010 diff -NurpP --minimal linux-2.6.32/net/ipv6/fib6_rules.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/fib6_rules.c
28011 --- linux-2.6.32/net/ipv6/fib6_rules.c  2009-09-10 15:26:30.000000000 +0200
28012 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/fib6_rules.c    2009-12-03 20:04:56.000000000 +0100
28013 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
28014                         if (ipv6_dev_get_saddr(net,
28015                                                ip6_dst_idev(&rt->u.dst)->dev,
28016                                                &flp->fl6_dst, srcprefs,
28017 -                                              &saddr))
28018 +                                              &saddr, NULL))
28019                                 goto again;
28020                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
28021                                                r->src.plen))
28022 diff -NurpP --minimal linux-2.6.32/net/ipv6/inet6_hashtables.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/inet6_hashtables.c
28023 --- linux-2.6.32/net/ipv6/inet6_hashtables.c    2009-03-24 14:22:46.000000000 +0100
28024 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/inet6_hashtables.c      2009-12-03 20:04:56.000000000 +0100
28025 @@ -16,6 +16,7 @@
28026  
28027  #include <linux/module.h>
28028  #include <linux/random.h>
28029 +#include <linux/vs_inet6.h>
28030  
28031  #include <net/inet_connection_sock.h>
28032  #include <net/inet_hashtables.h>
28033 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
28034         unsigned int slot = hash & (hashinfo->ehash_size - 1);
28035         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
28036  
28037 -
28038         rcu_read_lock();
28039  begin:
28040         sk_nulls_for_each_rcu(sk, node, &head->chain) {
28041 @@ -88,7 +88,7 @@ begin:
28042                                 sock_put(sk);
28043                                 goto begin;
28044                         }
28045 -               goto out;
28046 +                       goto out;
28047                 }
28048         }
28049         if (get_nulls_value(node) != slot)
28050 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
28051                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28052                                 return -1;
28053                         score++;
28054 +               } else {
28055 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28056 +                               return -1;
28057                 }
28058                 if (sk->sk_bound_dev_if) {
28059                         if (sk->sk_bound_dev_if != dif)
28060 diff -NurpP --minimal linux-2.6.32/net/ipv6/ip6_output.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/ip6_output.c
28061 --- linux-2.6.32/net/ipv6/ip6_output.c  2009-12-03 20:03:00.000000000 +0100
28062 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/ip6_output.c    2009-12-03 20:04:56.000000000 +0100
28063 @@ -934,7 +934,7 @@ static int ip6_dst_lookup_tail(struct so
28064                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
28065                                          &fl->fl6_dst,
28066                                          sk ? inet6_sk(sk)->srcprefs : 0,
28067 -                                        &fl->fl6_src);
28068 +                                        &fl->fl6_src, sk->sk_nx_info);
28069                 if (err)
28070                         goto out_err_release;
28071         }
28072 diff -NurpP --minimal linux-2.6.32/net/ipv6/Kconfig linux-2.6.32-vs2.3.0.36.26/net/ipv6/Kconfig
28073 --- linux-2.6.32/net/ipv6/Kconfig       2009-09-10 15:26:30.000000000 +0200
28074 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/Kconfig 2009-12-03 20:04:56.000000000 +0100
28075 @@ -4,8 +4,8 @@
28076  
28077  #   IPv6 as module will cause a CRASH if you try to unload it
28078  menuconfig IPV6
28079 -       tristate "The IPv6 protocol"
28080 -       default m
28081 +       bool "The IPv6 protocol"
28082 +       default n
28083         ---help---
28084           This is complemental support for the IP version 6.
28085           You will still be able to do traditional IPv4 networking as well.
28086 diff -NurpP --minimal linux-2.6.32/net/ipv6/ndisc.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/ndisc.c
28087 --- linux-2.6.32/net/ipv6/ndisc.c       2009-12-03 20:03:00.000000000 +0100
28088 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/ndisc.c 2009-12-03 20:04:56.000000000 +0100
28089 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
28090         } else {
28091                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
28092                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
28093 -                                      &tmpaddr))
28094 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
28095                         return;
28096                 src_addr = &tmpaddr;
28097         }
28098 diff -NurpP --minimal linux-2.6.32/net/ipv6/raw.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/raw.c
28099 --- linux-2.6.32/net/ipv6/raw.c 2009-12-03 20:03:00.000000000 +0100
28100 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/raw.c   2009-12-03 20:04:56.000000000 +0100
28101 @@ -29,6 +29,7 @@
28102  #include <linux/icmpv6.h>
28103  #include <linux/netfilter.h>
28104  #include <linux/netfilter_ipv6.h>
28105 +#include <linux/vs_inet6.h>
28106  #include <linux/skbuff.h>
28107  #include <asm/uaccess.h>
28108  #include <asm/ioctls.h>
28109 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
28110                         }
28111                 }
28112  
28113 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28114 +                       err = -EADDRNOTAVAIL;
28115 +                       if (dev)
28116 +                               dev_put(dev);
28117 +                       goto out;
28118 +               }
28119 +
28120                 /* ipv4 addr of the socket is invalid.  Only the
28121                  * unspecified and mapped address have a v4 equivalent.
28122                  */
28123 diff -NurpP --minimal linux-2.6.32/net/ipv6/route.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/route.c
28124 --- linux-2.6.32/net/ipv6/route.c       2009-12-03 20:03:00.000000000 +0100
28125 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/route.c 2009-12-03 20:04:56.000000000 +0100
28126 @@ -2257,7 +2257,8 @@ static int rt6_fill_node(struct net *net
28127                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
28128                 struct in6_addr saddr_buf;
28129                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
28130 -                                      dst, 0, &saddr_buf) == 0)
28131 +                       dst, 0, &saddr_buf,
28132 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
28133                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
28134         }
28135  
28136 diff -NurpP --minimal linux-2.6.32/net/ipv6/tcp_ipv6.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/tcp_ipv6.c
28137 --- linux-2.6.32/net/ipv6/tcp_ipv6.c    2009-12-03 20:03:00.000000000 +0100
28138 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/tcp_ipv6.c      2009-12-03 20:04:56.000000000 +0100
28139 @@ -68,6 +68,7 @@
28140  
28141  #include <linux/crypto.h>
28142  #include <linux/scatterlist.h>
28143 +#include <linux/vs_inet6.h>
28144  
28145  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
28146  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
28147 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
28148          *      connect() to INADDR_ANY means loopback (BSD'ism).
28149          */
28150  
28151 -       if(ipv6_addr_any(&usin->sin6_addr))
28152 -               usin->sin6_addr.s6_addr[15] = 0x1;
28153 +       if(ipv6_addr_any(&usin->sin6_addr)) {
28154 +               struct nx_info *nxi =  sk->sk_nx_info;
28155 +
28156 +               if (nxi && nx_info_has_v6(nxi))
28157 +                       /* FIXME: remap lback? */
28158 +                       usin->sin6_addr = nxi->v6.ip;
28159 +               else
28160 +                       usin->sin6_addr.s6_addr[15] = 0x1;
28161 +       }
28162  
28163         addr_type = ipv6_addr_type(&usin->sin6_addr);
28164  
28165 diff -NurpP --minimal linux-2.6.32/net/ipv6/udp.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/udp.c
28166 --- linux-2.6.32/net/ipv6/udp.c 2009-12-03 20:03:00.000000000 +0100
28167 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/udp.c   2009-12-03 20:04:56.000000000 +0100
28168 @@ -47,6 +47,7 @@
28169  
28170  #include <linux/proc_fs.h>
28171  #include <linux/seq_file.h>
28172 +#include <linux/vs_inet6.h>
28173  #include "udp_impl.h"
28174  
28175  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
28176 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
28177         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
28178  
28179         /* if both are mapped, treat as IPv4 */
28180 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
28181 -               return (!sk2_ipv6only &&
28182 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
28183 +               if (!sk2_ipv6only &&
28184                         (!sk_rcv_saddr || !sk2_rcv_saddr ||
28185 -                         sk_rcv_saddr == sk2_rcv_saddr));
28186 +                         sk_rcv_saddr == sk2_rcv_saddr))
28187 +                       goto vs_v4;
28188 +               else
28189 +                       return 0;
28190 +       }
28191  
28192         if (addr_type2 == IPV6_ADDR_ANY &&
28193             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
28194 -               return 1;
28195 +               goto vs;
28196  
28197         if (addr_type == IPV6_ADDR_ANY &&
28198             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
28199 -               return 1;
28200 +               goto vs;
28201  
28202         if (sk2_rcv_saddr6 &&
28203             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
28204 -               return 1;
28205 +               goto vs;
28206  
28207         return 0;
28208 +
28209 +vs_v4:
28210 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
28211 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28212 +       if (!sk2_rcv_saddr)
28213 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
28214 +       if (!sk_rcv_saddr)
28215 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
28216 +       return 1;
28217 +vs:
28218 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
28219 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28220 +       else if (addr_type2 == IPV6_ADDR_ANY)
28221 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
28222 +       else if (addr_type == IPV6_ADDR_ANY) {
28223 +               if (addr_type2 == IPV6_ADDR_MAPPED)
28224 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28225 +               else
28226 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
28227 +       }
28228 +       return 1;
28229  }
28230  
28231  int udp_v6_get_port(struct sock *sk, unsigned short snum)
28232 @@ -109,6 +135,10 @@ static inline int compute_score(struct s
28233                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28234                                 return -1;
28235                         score++;
28236 +               } else {
28237 +                       /* block non nx_info ips */
28238 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28239 +                               return -1;
28240                 }
28241                 if (!ipv6_addr_any(&np->daddr)) {
28242                         if (!ipv6_addr_equal(&np->daddr, saddr))
28243 diff -NurpP --minimal linux-2.6.32/net/ipv6/xfrm6_policy.c linux-2.6.32-vs2.3.0.36.26/net/ipv6/xfrm6_policy.c
28244 --- linux-2.6.32/net/ipv6/xfrm6_policy.c        2009-12-03 20:03:00.000000000 +0100
28245 +++ linux-2.6.32-vs2.3.0.36.26/net/ipv6/xfrm6_policy.c  2009-12-03 20:04:56.000000000 +0100
28246 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
28247         dev = ip6_dst_idev(dst)->dev;
28248         ipv6_dev_get_saddr(dev_net(dev), dev,
28249                            (struct in6_addr *)&daddr->a6, 0,
28250 -                          (struct in6_addr *)&saddr->a6);
28251 +                          (struct in6_addr *)&saddr->a6, NULL);
28252         dst_release(dst);
28253         return 0;
28254  }
28255 diff -NurpP --minimal linux-2.6.32/net/netlink/af_netlink.c linux-2.6.32-vs2.3.0.36.26/net/netlink/af_netlink.c
28256 --- linux-2.6.32/net/netlink/af_netlink.c       2009-12-03 20:03:01.000000000 +0100
28257 +++ linux-2.6.32-vs2.3.0.36.26/net/netlink/af_netlink.c 2009-12-03 20:04:56.000000000 +0100
28258 @@ -55,6 +55,9 @@
28259  #include <linux/types.h>
28260  #include <linux/audit.h>
28261  #include <linux/mutex.h>
28262 +#include <linux/vs_context.h>
28263 +#include <linux/vs_network.h>
28264 +#include <linux/vs_limit.h>
28265  
28266  #include <net/net_namespace.h>
28267  #include <net/sock.h>
28268 @@ -1899,6 +1902,8 @@ static struct sock *netlink_seq_socket_i
28269                         sk_for_each(s, node, &hash->table[j]) {
28270                                 if (sock_net(s) != seq_file_net(seq))
28271                                         continue;
28272 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28273 +                                       continue;
28274                                 if (off == pos) {
28275                                         iter->link = i;
28276                                         iter->hash_idx = j;
28277 @@ -1933,7 +1938,8 @@ static void *netlink_seq_next(struct seq
28278         s = v;
28279         do {
28280                 s = sk_next(s);
28281 -       } while (s && sock_net(s) != seq_file_net(seq));
28282 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
28283 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
28284         if (s)
28285                 return s;
28286  
28287 @@ -1945,7 +1951,8 @@ static void *netlink_seq_next(struct seq
28288  
28289                 for (; j <= hash->mask; j++) {
28290                         s = sk_head(&hash->table[j]);
28291 -                       while (s && sock_net(s) != seq_file_net(seq))
28292 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
28293 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
28294                                 s = sk_next(s);
28295                         if (s) {
28296                                 iter->link = i;
28297 diff -NurpP --minimal linux-2.6.32/net/sctp/ipv6.c linux-2.6.32-vs2.3.0.36.26/net/sctp/ipv6.c
28298 --- linux-2.6.32/net/sctp/ipv6.c        2009-12-03 20:03:01.000000000 +0100
28299 +++ linux-2.6.32-vs2.3.0.36.26/net/sctp/ipv6.c  2009-12-03 20:04:56.000000000 +0100
28300 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
28301                                    dst ? ip6_dst_idev(dst)->dev : NULL,
28302                                    &daddr->v6.sin6_addr,
28303                                    inet6_sk(&sk->inet.sk)->srcprefs,
28304 -                                  &saddr->v6.sin6_addr);
28305 +                                  &saddr->v6.sin6_addr,
28306 +                                  asoc->base.sk->sk_nx_info);
28307                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
28308                                   &saddr->v6.sin6_addr);
28309                 return;
28310 diff -NurpP --minimal linux-2.6.32/net/socket.c linux-2.6.32-vs2.3.0.36.26/net/socket.c
28311 --- linux-2.6.32/net/socket.c   2009-12-03 20:03:01.000000000 +0100
28312 +++ linux-2.6.32-vs2.3.0.36.26/net/socket.c     2009-12-03 20:04:56.000000000 +0100
28313 @@ -96,6 +96,10 @@
28314  
28315  #include <net/sock.h>
28316  #include <linux/netfilter.h>
28317 +#include <linux/vs_base.h>
28318 +#include <linux/vs_socket.h>
28319 +#include <linux/vs_inet.h>
28320 +#include <linux/vs_inet6.h>
28321  
28322  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28323  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28324 @@ -559,7 +563,7 @@ static inline int __sock_sendmsg(struct 
28325                                  struct msghdr *msg, size_t size)
28326  {
28327         struct sock_iocb *si = kiocb_to_siocb(iocb);
28328 -       int err;
28329 +       int err, len;
28330  
28331         si->sock = sock;
28332         si->scm = NULL;
28333 @@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
28334         if (err)
28335                 return err;
28336  
28337 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28338 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28339 +       if (sock->sk) {
28340 +               if (len == size)
28341 +                       vx_sock_send(sock->sk, size);
28342 +               else
28343 +                       vx_sock_fail(sock->sk, size);
28344 +       }
28345 +       vxdprintk(VXD_CBIT(net, 7),
28346 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28347 +               sock, sock->sk,
28348 +               (sock->sk)?sock->sk->sk_nx_info:0,
28349 +               (sock->sk)?sock->sk->sk_vx_info:0,
28350 +               (sock->sk)?sock->sk->sk_xid:0,
28351 +               (sock->sk)?sock->sk->sk_nid:0,
28352 +               (unsigned int)size, len);
28353 +       return len;
28354  }
28355  
28356  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28357 @@ -671,7 +690,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28358  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28359                                  struct msghdr *msg, size_t size, int flags)
28360  {
28361 -       int err;
28362 +       int err, len;
28363         struct sock_iocb *si = kiocb_to_siocb(iocb);
28364  
28365         si->sock = sock;
28366 @@ -684,7 +703,18 @@ static inline int __sock_recvmsg(struct 
28367         if (err)
28368                 return err;
28369  
28370 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28371 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28372 +       if ((len >= 0) && sock->sk)
28373 +               vx_sock_recv(sock->sk, len);
28374 +       vxdprintk(VXD_CBIT(net, 7),
28375 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28376 +               sock, sock->sk,
28377 +               (sock->sk)?sock->sk->sk_nx_info:0,
28378 +               (sock->sk)?sock->sk->sk_vx_info:0,
28379 +               (sock->sk)?sock->sk->sk_xid:0,
28380 +               (sock->sk)?sock->sk->sk_nid:0,
28381 +               (unsigned int)size, len);
28382 +       return len;
28383  }
28384  
28385  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28386 @@ -1155,6 +1185,13 @@ static int __sock_create(struct net *net
28387         if (type < 0 || type >= SOCK_MAX)
28388                 return -EINVAL;
28389  
28390 +       if (!nx_check(0, VS_ADMIN)) {
28391 +               if (family == PF_INET && !current_nx_info_has_v4())
28392 +                       return -EAFNOSUPPORT;
28393 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28394 +                       return -EAFNOSUPPORT;
28395 +       }
28396 +
28397         /* Compatibility.
28398  
28399            This uglymoron is moved from INET layer to here to avoid
28400 @@ -1287,6 +1324,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28401         if (retval < 0)
28402                 goto out;
28403  
28404 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28405         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28406         if (retval < 0)
28407                 goto out_release;
28408 @@ -1328,10 +1366,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28409         err = sock_create(family, type, protocol, &sock1);
28410         if (err < 0)
28411                 goto out;
28412 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28413  
28414         err = sock_create(family, type, protocol, &sock2);
28415         if (err < 0)
28416                 goto out_release_1;
28417 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28418  
28419         err = sock1->ops->socketpair(sock1, sock2);
28420         if (err < 0)
28421 diff -NurpP --minimal linux-2.6.32/net/sunrpc/auth.c linux-2.6.32-vs2.3.0.36.26/net/sunrpc/auth.c
28422 --- linux-2.6.32/net/sunrpc/auth.c      2009-12-03 20:03:01.000000000 +0100
28423 +++ linux-2.6.32-vs2.3.0.36.26/net/sunrpc/auth.c        2009-12-03 20:04:56.000000000 +0100
28424 @@ -14,6 +14,7 @@
28425  #include <linux/hash.h>
28426  #include <linux/sunrpc/clnt.h>
28427  #include <linux/spinlock.h>
28428 +#include <linux/vs_tag.h>
28429  
28430  #ifdef RPC_DEBUG
28431  # define RPCDBG_FACILITY       RPCDBG_AUTH
28432 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28433         memset(&acred, 0, sizeof(acred));
28434         acred.uid = cred->fsuid;
28435         acred.gid = cred->fsgid;
28436 +       acred.tag = dx_current_tag();
28437         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
28438  
28439         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
28440 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28441         struct auth_cred acred = {
28442                 .uid = 0,
28443                 .gid = 0,
28444 +               .tag = dx_current_tag(),
28445         };
28446         struct rpc_cred *ret;
28447  
28448 diff -NurpP --minimal linux-2.6.32/net/sunrpc/auth_unix.c linux-2.6.32-vs2.3.0.36.26/net/sunrpc/auth_unix.c
28449 --- linux-2.6.32/net/sunrpc/auth_unix.c 2008-12-25 00:26:37.000000000 +0100
28450 +++ linux-2.6.32-vs2.3.0.36.26/net/sunrpc/auth_unix.c   2009-12-03 20:04:56.000000000 +0100
28451 @@ -11,12 +11,14 @@
28452  #include <linux/module.h>
28453  #include <linux/sunrpc/clnt.h>
28454  #include <linux/sunrpc/auth.h>
28455 +#include <linux/vs_tag.h>
28456  
28457  #define NFS_NGROUPS    16
28458  
28459  struct unx_cred {
28460         struct rpc_cred         uc_base;
28461         gid_t                   uc_gid;
28462 +       tag_t                   uc_tag;
28463         gid_t                   uc_gids[NFS_NGROUPS];
28464  };
28465  #define uc_uid                 uc_base.cr_uid
28466 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28467                 groups = NFS_NGROUPS;
28468  
28469         cred->uc_gid = acred->gid;
28470 +       cred->uc_tag = acred->tag;
28471         for (i = 0; i < groups; i++)
28472                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28473         if (i < NFS_NGROUPS)
28474 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28475         unsigned int i;
28476  
28477  
28478 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28479 +       if (cred->uc_uid != acred->uid ||
28480 +               cred->uc_gid != acred->gid ||
28481 +               cred->uc_tag != acred->tag)
28482                 return 0;
28483  
28484         if (acred->group_info != NULL)
28485 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28486         struct rpc_clnt *clnt = task->tk_client;
28487         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28488         __be32          *base, *hold;
28489 -       int             i;
28490 +       int             i, tag;
28491  
28492         *p++ = htonl(RPC_AUTH_UNIX);
28493         base = p++;
28494 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28495          * Copy the UTS nodename captured when the client was created.
28496          */
28497         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28498 +       tag = task->tk_client->cl_tag;
28499  
28500 -       *p++ = htonl((u32) cred->uc_uid);
28501 -       *p++ = htonl((u32) cred->uc_gid);
28502 +       *p++ = htonl((u32) TAGINO_UID(tag,
28503 +               cred->uc_uid, cred->uc_tag));
28504 +       *p++ = htonl((u32) TAGINO_GID(tag,
28505 +               cred->uc_gid, cred->uc_tag));
28506         hold = p++;
28507         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28508                 *p++ = htonl((u32) cred->uc_gids[i]);
28509 diff -NurpP --minimal linux-2.6.32/net/sunrpc/clnt.c linux-2.6.32-vs2.3.0.36.26/net/sunrpc/clnt.c
28510 --- linux-2.6.32/net/sunrpc/clnt.c      2009-12-03 20:03:01.000000000 +0100
28511 +++ linux-2.6.32-vs2.3.0.36.26/net/sunrpc/clnt.c        2009-12-03 20:04:56.000000000 +0100
28512 @@ -33,6 +33,7 @@
28513  #include <linux/utsname.h>
28514  #include <linux/workqueue.h>
28515  #include <linux/in6.h>
28516 +#include <linux/vs_cvirt.h>
28517  
28518  #include <linux/sunrpc/clnt.h>
28519  #include <linux/sunrpc/rpc_pipe_fs.h>
28520 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28521         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28522                 clnt->cl_chatty = 1;
28523  
28524 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28525 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28526 +               clnt->cl_tag = 1; */
28527         return clnt;
28528  }
28529  EXPORT_SYMBOL_GPL(rpc_create);
28530 diff -NurpP --minimal linux-2.6.32/net/unix/af_unix.c linux-2.6.32-vs2.3.0.36.26/net/unix/af_unix.c
28531 --- linux-2.6.32/net/unix/af_unix.c     2009-12-03 20:03:01.000000000 +0100
28532 +++ linux-2.6.32-vs2.3.0.36.26/net/unix/af_unix.c       2009-12-03 20:04:56.000000000 +0100
28533 @@ -114,6 +114,8 @@
28534  #include <linux/mount.h>
28535  #include <net/checksum.h>
28536  #include <linux/security.h>
28537 +#include <linux/vs_context.h>
28538 +#include <linux/vs_limit.h>
28539  
28540  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28541  static DEFINE_SPINLOCK(unix_table_lock);
28542 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28543                 if (!net_eq(sock_net(s), net))
28544                         continue;
28545  
28546 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28547 +                       continue;
28548                 if (u->addr->len == len &&
28549                     !memcmp(u->addr->name, sunname, len))
28550                         goto found;
28551 @@ -2114,6 +2118,8 @@ static struct sock *unix_seq_idx(struct 
28552         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28553                 if (sock_net(s) != seq_file_net(seq))
28554                         continue;
28555 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28556 +                       continue;
28557                 if (off == pos)
28558                         return s;
28559                 ++off;
28560 @@ -2138,7 +2144,8 @@ static void *unix_seq_next(struct seq_fi
28561                 sk = first_unix_socket(&iter->i);
28562         else
28563                 sk = next_unix_socket(&iter->i, sk);
28564 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28565 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28566 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28567                 sk = next_unix_socket(&iter->i, sk);
28568         return sk;
28569  }
28570 diff -NurpP --minimal linux-2.6.32/net/x25/af_x25.c linux-2.6.32-vs2.3.0.36.26/net/x25/af_x25.c
28571 --- linux-2.6.32/net/x25/af_x25.c       2009-12-03 20:03:01.000000000 +0100
28572 +++ linux-2.6.32-vs2.3.0.36.26/net/x25/af_x25.c 2009-12-03 20:04:56.000000000 +0100
28573 @@ -519,7 +519,10 @@ static int x25_create(struct net *net, s
28574  
28575         x25 = x25_sk(sk);
28576  
28577 -       sock_init_data(sock, sk);
28578 +       sk->sk_socket = sock;
28579 +       sk->sk_type = sock->type;
28580 +       sk->sk_sleep = &sock->wait;
28581 +       sock->sk = sk;
28582  
28583         x25_init_timers(sk);
28584  
28585 diff -NurpP --minimal linux-2.6.32/scripts/checksyscalls.sh linux-2.6.32-vs2.3.0.36.26/scripts/checksyscalls.sh
28586 --- linux-2.6.32/scripts/checksyscalls.sh       2009-09-10 15:26:31.000000000 +0200
28587 +++ linux-2.6.32-vs2.3.0.36.26/scripts/checksyscalls.sh 2009-12-03 20:04:56.000000000 +0100
28588 @@ -194,7 +194,6 @@ cat << EOF
28589  #define __IGNORE_afs_syscall
28590  #define __IGNORE_getpmsg
28591  #define __IGNORE_putpmsg
28592 -#define __IGNORE_vserver
28593  EOF
28594  }
28595  
28596 diff -NurpP --minimal linux-2.6.32/security/commoncap.c linux-2.6.32-vs2.3.0.36.26/security/commoncap.c
28597 --- linux-2.6.32/security/commoncap.c   2009-12-03 20:03:02.000000000 +0100
28598 +++ linux-2.6.32-vs2.3.0.36.26/security/commoncap.c     2009-12-03 20:04:56.000000000 +0100
28599 @@ -27,6 +27,7 @@
28600  #include <linux/sched.h>
28601  #include <linux/prctl.h>
28602  #include <linux/securebits.h>
28603 +#include <linux/vs_context.h>
28604  
28605  /*
28606   * If a non-root user executes a setuid-root binary in
28607 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
28608  
28609  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28610  {
28611 -       NETLINK_CB(skb).eff_cap = current_cap();
28612 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
28613         return 0;
28614  }
28615  
28616 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
28617                 return -EPERM;
28618         return 0;
28619  }
28620 +
28621  EXPORT_SYMBOL(cap_netlink_recv);
28622  
28623  /**
28624 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
28625  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
28626                 int audit)
28627  {
28628 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28629 +       struct vx_info *vxi = tsk->vx_info;
28630 +
28631 +#if 0
28632 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28633 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28634 +               cap_raised(tsk->cap_effective, cap),
28635 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28636 +#endif
28637 +
28638 +       /* special case SETUP */
28639 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28640 +               /* FIXME: maybe use cred instead? */
28641 +               cap_raised(tsk->cred->cap_effective, cap))
28642 +               return 0;
28643 +
28644 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28645  }
28646  
28647  /**
28648 @@ -618,7 +635,7 @@ int cap_inode_setxattr(struct dentry *de
28649  
28650         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28651                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28652 -           !capable(CAP_SYS_ADMIN))
28653 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28654                 return -EPERM;
28655         return 0;
28656  }
28657 @@ -962,7 +979,8 @@ error:
28658   */
28659  int cap_syslog(int type)
28660  {
28661 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28662 +       if ((type != 3 && type != 10) &&
28663 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28664                 return -EPERM;
28665         return 0;
28666  }
28667 @@ -1014,3 +1032,4 @@ int cap_file_mmap(struct file *file, uns
28668         }
28669         return ret;
28670  }
28671 +
28672 diff -NurpP --minimal linux-2.6.32/security/selinux/hooks.c linux-2.6.32-vs2.3.0.36.26/security/selinux/hooks.c
28673 --- linux-2.6.32/security/selinux/hooks.c       2009-12-03 20:03:02.000000000 +0100
28674 +++ linux-2.6.32-vs2.3.0.36.26/security/selinux/hooks.c 2009-12-03 20:04:56.000000000 +0100
28675 @@ -64,7 +64,6 @@
28676  #include <linux/dccp.h>
28677  #include <linux/quota.h>
28678  #include <linux/un.h>          /* for Unix socket types */
28679 -#include <net/af_unix.h>       /* for Unix socket types */
28680  #include <linux/parser.h>
28681  #include <linux/nfs_mount.h>
28682  #include <net/ipv6.h>
28683 diff -NurpP --minimal linux-2.6.32/security/selinux/include/av_permissions.h linux-2.6.32-vs2.3.0.36.26/security/selinux/include/av_permissions.h
28684 --- linux-2.6.32/security/selinux/include/av_permissions.h      2009-12-03 20:03:02.000000000 +0100
28685 +++ linux-2.6.32-vs2.3.0.36.26/security/selinux/include/av_permissions.h        2009-12-03 20:04:56.000000000 +0100
28686 @@ -565,6 +565,7 @@
28687  #define CAPABILITY__SETFCAP                       0x80000000UL
28688  #define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
28689  #define CAPABILITY2__MAC_ADMIN                    0x00000002UL
28690 +#define CAPABILITY2__CONTEXT                      0x00000004UL
28691  #define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
28692  #define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
28693  #define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
28694 diff -NurpP --minimal linux-2.6.32/security/selinux/include/av_perm_to_string.h linux-2.6.32-vs2.3.0.36.26/security/selinux/include/av_perm_to_string.h
28695 --- linux-2.6.32/security/selinux/include/av_perm_to_string.h   2009-12-03 20:03:02.000000000 +0100
28696 +++ linux-2.6.32-vs2.3.0.36.26/security/selinux/include/av_perm_to_string.h     2009-12-03 20:04:56.000000000 +0100
28697 @@ -142,6 +142,7 @@
28698     S_(SECCLASS_CAPABILITY, CAPABILITY__SETFCAP, "setfcap")
28699     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_OVERRIDE, "mac_override")
28700     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_ADMIN, "mac_admin")
28701 +   S_(SECCLASS_CAPABILITY2, CAPABILITY2__CONTEXT, "context")
28702     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_READ, "nlmsg_read")
28703     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE, "nlmsg_write")
28704     S_(SECCLASS_NETLINK_FIREWALL_SOCKET, NETLINK_FIREWALL_SOCKET__NLMSG_READ, "nlmsg_read")
This page took 2.451409 seconds and 4 git commands to generate.