]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.3.patch
63fdeb802754a1392b95dbc9c369b8118c2d5d31
[packages/kernel.git] / linux-2.6-vs2.3.patch
1 diff -NurpP --minimal linux-2.6.27.25/arch/alpha/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/Kconfig
2 --- linux-2.6.27.25/arch/alpha/Kconfig  2008-10-13 14:51:51.000000000 +0200
3 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/Kconfig     2008-10-13 14:54:20.000000000 +0200
4 @@ -667,6 +667,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.27.25/arch/alpha/kernel/entry.S linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/entry.S
14 --- linux-2.6.27.25/arch/alpha/kernel/entry.S   2009-06-15 17:18:24.000000000 +0200
15 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/entry.S      2009-02-03 17:59:04.000000000 +0100
16 @@ -872,24 +872,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.27.25/arch/alpha/kernel/osf_sys.c linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.27.25/arch/alpha/kernel/osf_sys.c 2008-10-13 14:51:51.000000000 +0200
50 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/osf_sys.c    2008-10-13 14:54:20.000000000 +0200
51 @@ -888,7 +888,7 @@ osf_gettimeofday(struct timeval32 __user
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.27.25/arch/alpha/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.27.25/arch/alpha/kernel/ptrace.c  2008-07-13 23:51:29.000000000 +0200
62 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/ptrace.c     2008-10-13 14:54:20.000000000 +0200
63 @@ -15,6 +15,7 @@
64  #include <linux/slab.h>
65  #include <linux/security.h>
66  #include <linux/signal.h>
67 +#include <linux/vs_base.h>
68  
69  #include <asm/uaccess.h>
70  #include <asm/pgtable.h>
71 diff -NurpP --minimal linux-2.6.27.25/arch/alpha/kernel/systbls.S linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/systbls.S
72 --- linux-2.6.27.25/arch/alpha/kernel/systbls.S 2009-06-15 17:18:24.000000000 +0200
73 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/systbls.S    2009-02-03 17:59:04.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.27.25/arch/alpha/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/traps.c
84 --- linux-2.6.27.25/arch/alpha/kernel/traps.c   2008-07-13 23:51:29.000000000 +0200
85 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/kernel/traps.c      2008-10-13 14:54:20.000000000 +0200
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.27.25/arch/alpha/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/mm/fault.c
97 --- linux-2.6.27.25/arch/alpha/mm/fault.c       2008-07-13 23:51:29.000000000 +0200
98 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/alpha/mm/fault.c  2008-10-13 14:54:20.000000000 +0200
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.27.25/arch/arm/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/arm/Kconfig
111 --- linux-2.6.27.25/arch/arm/Kconfig    2008-10-13 14:51:51.000000000 +0200
112 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/arm/Kconfig       2008-10-13 14:54:20.000000000 +0200
113 @@ -1240,6 +1240,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.27.25/arch/arm/kernel/calls.S linux-2.6.27.25-vs2.3.0.36.6/arch/arm/kernel/calls.S
123 --- linux-2.6.27.25/arch/arm/kernel/calls.S     2009-06-15 17:18:24.000000000 +0200
124 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/arm/kernel/calls.S        2009-02-03 17:59:04.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.27.25/arch/arm/kernel/process.c linux-2.6.27.25-vs2.3.0.36.6/arch/arm/kernel/process.c
135 --- linux-2.6.27.25/arch/arm/kernel/process.c   2008-10-13 14:51:52.000000000 +0200
136 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/arm/kernel/process.c      2008-10-13 14:54:20.000000000 +0200
137 @@ -262,7 +262,8 @@ void __show_regs(struct pt_regs *regs)
138  void show_regs(struct pt_regs * regs)
139  {
140         printk("\n");
141 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
142 +       printk("Pid: %d[#%u], comm: %20s\n",
143 +               task_pid_nr(current), current->xid, current->comm);
144         __show_regs(regs);
145         __backtrace();
146  }
147 diff -NurpP --minimal linux-2.6.27.25/arch/arm/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/arm/kernel/traps.c
148 --- linux-2.6.27.25/arch/arm/kernel/traps.c     2008-10-13 14:51:52.000000000 +0200
149 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/arm/kernel/traps.c        2008-10-13 14:54:20.000000000 +0200
150 @@ -214,8 +214,8 @@ static void __die(const char *str, int e
151                str, err, ++die_counter);
152         print_modules();
153         __show_regs(regs);
154 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
155 -               tsk->comm, task_pid_nr(tsk), thread + 1);
156 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
157 +               tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
158  
159         if (!user_mode(regs) || in_interrupt()) {
160                 dump_mem("Stack: ", regs->ARM_sp,
161 diff -NurpP --minimal linux-2.6.27.25/arch/arm/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/arm/mm/fault.c
162 --- linux-2.6.27.25/arch/arm/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
163 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/arm/mm/fault.c    2008-10-13 14:54:20.000000000 +0200
164 @@ -292,7 +292,8 @@ do_page_fault(unsigned long addr, unsign
165                  * happened to us that made us unable to handle
166                  * the page fault gracefully.
167                  */
168 -               printk("VM: killing process %s\n", tsk->comm);
169 +               printk("VM: killing process %s(%d:#%u)\n",
170 +                       tsk->comm, task_pid_nr(tsk), tsk->xid);
171                 do_group_exit(SIGKILL);
172                 return 0;
173         }
174 diff -NurpP --minimal linux-2.6.27.25/arch/cris/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/cris/Kconfig
175 --- linux-2.6.27.25/arch/cris/Kconfig   2008-07-13 23:51:29.000000000 +0200
176 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/cris/Kconfig      2008-10-13 14:54:20.000000000 +0200
177 @@ -679,6 +679,8 @@ source "drivers/usb/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.27.25/arch/frv/kernel/kernel_thread.S linux-2.6.27.25-vs2.3.0.36.6/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.27.25/arch/frv/kernel/kernel_thread.S     2008-07-13 23:51:29.000000000 +0200
188 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/frv/kernel/kernel_thread.S        2008-10-13 14:54:20.000000000 +0200
189 @@ -37,7 +37,7 @@ kernel_thread:
190  
191         # start by forking the current process, but with shared VM
192         setlos.p        #__NR_clone,gr7         ; syscall number
193 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
194 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
195         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
196         setlo           #0xe4e4,gr9
197         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
198 diff -NurpP --minimal linux-2.6.27.25/arch/h8300/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/h8300/Kconfig
199 --- linux-2.6.27.25/arch/h8300/Kconfig  2008-10-13 14:51:55.000000000 +0200
200 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/h8300/Kconfig     2008-10-13 14:54:20.000000000 +0200
201 @@ -219,6 +219,8 @@ source "fs/Kconfig"
202  
203  source "arch/h8300/Kconfig.debug"
204  
205 +source "kernel/vserver/Kconfig"
206 +
207  source "security/Kconfig"
208  
209  source "crypto/Kconfig"
210 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/ia32/ia32_entry.S linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.27.25/arch/ia64/ia32/ia32_entry.S 2009-06-15 17:18:24.000000000 +0200
212 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/ia32/ia32_entry.S    2009-02-03 17:59:04.000000000 +0100
213 @@ -446,7 +446,7 @@ ia32_syscall_table:
214         data8 sys_tgkill        /* 270 */
215         data8 compat_sys_utimes
216         data8 sys32_fadvise64_64
217 -       data8 sys_ni_syscall
218 +       data8 sys32_vserver
219         data8 sys_ni_syscall
220         data8 sys_ni_syscall    /* 275 */
221         data8 sys_ni_syscall
222 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/ia32/sys_ia32.c linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/ia32/sys_ia32.c
223 --- linux-2.6.27.25/arch/ia64/ia32/sys_ia32.c   2008-10-13 14:51:55.000000000 +0200
224 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/ia32/sys_ia32.c      2008-10-13 14:54:20.000000000 +0200
225 @@ -1178,7 +1178,7 @@ sys32_gettimeofday (struct compat_timeva
226  {
227         if (tv) {
228                 struct timeval ktv;
229 -               do_gettimeofday(&ktv);
230 +               vx_gettimeofday(&ktv);
231                 if (put_tv32(tv, &ktv))
232                         return -EFAULT;
233         }
234 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/Kconfig
235 --- linux-2.6.27.25/arch/ia64/Kconfig   2009-06-15 17:18:24.000000000 +0200
236 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/Kconfig      2009-03-25 14:32:29.000000000 +0100
237 @@ -639,6 +639,8 @@ source "arch/ia64/hp/sim/Kconfig"
238  
239  source "arch/ia64/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/kernel/entry.S linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/entry.S
247 --- linux-2.6.27.25/arch/ia64/kernel/entry.S    2009-06-15 17:18:24.000000000 +0200
248 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/entry.S       2009-02-03 17:59:04.000000000 +0100
249 @@ -1647,7 +1647,7 @@ sys_call_table:
250         data8 sys_mq_notify
251         data8 sys_mq_getsetattr
252         data8 sys_kexec_load
253 -       data8 sys_ni_syscall                    // reserved for vserver
254 +       data8 sys_vserver
255         data8 sys_waitid                        // 1270
256         data8 sys_add_key
257         data8 sys_request_key
258 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/kernel/perfmon.c linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/perfmon.c
259 --- linux-2.6.27.25/arch/ia64/kernel/perfmon.c  2008-10-13 14:51:55.000000000 +0200
260 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/perfmon.c     2008-10-13 14:54:20.000000000 +0200
261 @@ -40,6 +40,7 @@
262  #include <linux/capability.h>
263  #include <linux/rcupdate.h>
264  #include <linux/completion.h>
265 +#include <linux/vs_memory.h>
266  
267  #include <asm/errno.h>
268  #include <asm/intrinsics.h>
269 @@ -2376,7 +2377,7 @@ pfm_smpl_buffer_alloc(struct task_struct
270          */
271         insert_vm_struct(mm, vma);
272  
273 -       mm->total_vm  += size >> PAGE_SHIFT;
274 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
275         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
276                                                         vma_pages(vma));
277         up_write(&task->mm->mmap_sem);
278 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/kernel/process.c linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/process.c
279 --- linux-2.6.27.25/arch/ia64/kernel/process.c  2008-10-13 14:51:55.000000000 +0200
280 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/process.c     2008-10-13 14:54:20.000000000 +0200
281 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
282         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
283  
284         print_modules();
285 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
286 -                       smp_processor_id(), current->comm);
287 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
288 +                       current->xid, smp_processor_id(), current->comm);
289         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
290                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
291                init_utsname()->release);
292 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/ptrace.c
293 --- linux-2.6.27.25/arch/ia64/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
294 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
295 @@ -22,6 +22,7 @@
296  #include <linux/signal.h>
297  #include <linux/regset.h>
298  #include <linux/elf.h>
299 +#include <linux/vs_base.h>
300  
301  #include <asm/pgtable.h>
302  #include <asm/processor.h>
303 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/traps.c
304 --- linux-2.6.27.25/arch/ia64/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
305 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
306 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
307         put_cpu();
308  
309         if (++die.lock_owner_depth < 3) {
310 -               printk("%s[%d]: %s %ld [%d]\n",
311 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
312 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
313 +                       current->comm, task_pid_nr(current), current->xid,
314 +                       str, err, ++die_counter);
315                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
316                     != NOTIFY_STOP)
317                         show_regs(regs);
318 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
319                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
320                                 last.time = current_jiffies + 5 * HZ;
321                                 printk(KERN_WARNING
322 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
323 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
324 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
325 +                                       current->comm, task_pid_nr(current), current->xid,
326 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
327                         }
328                 }
329         }
330 diff -NurpP --minimal linux-2.6.27.25/arch/ia64/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/mm/fault.c
331 --- linux-2.6.27.25/arch/ia64/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
332 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/ia64/mm/fault.c   2008-10-13 14:54:20.000000000 +0200
333 @@ -10,6 +10,7 @@
334  #include <linux/interrupt.h>
335  #include <linux/kprobes.h>
336  #include <linux/kdebug.h>
337 +#include <linux/vs_memory.h>
338  
339  #include <asm/pgtable.h>
340  #include <asm/processor.h>
341 diff -NurpP --minimal linux-2.6.27.25/arch/m32r/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/m32r/kernel/traps.c
342 --- linux-2.6.27.25/arch/m32r/kernel/traps.c    2008-10-13 14:51:55.000000000 +0200
343 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/m32r/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
344 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
345         } else {
346                 printk("SPI: %08lx\n", sp);
347         }
348 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
349 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
350 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
351 +               current->comm, task_pid_nr(current), current->xid,
352 +               0xffff & i, 4096+(unsigned long)current);
353  
354         /*
355          * When in-kernel, we also print out the stack and code at the
356 diff -NurpP --minimal linux-2.6.27.25/arch/m68k/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/m68k/Kconfig
357 --- linux-2.6.27.25/arch/m68k/Kconfig   2008-10-13 14:51:55.000000000 +0200
358 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/m68k/Kconfig      2008-10-13 14:54:20.000000000 +0200
359 @@ -633,6 +633,8 @@ source "fs/Kconfig"
360  
361  source "arch/m68k/Kconfig.debug"
362  
363 +source "kernel/vserver/Kconfig"
364 +
365  source "security/Kconfig"
366  
367  source "crypto/Kconfig"
368 diff -NurpP --minimal linux-2.6.27.25/arch/m68k/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/m68k/kernel/ptrace.c
369 --- linux-2.6.27.25/arch/m68k/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
370 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/m68k/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
371 @@ -18,6 +18,7 @@
372  #include <linux/ptrace.h>
373  #include <linux/user.h>
374  #include <linux/signal.h>
375 +#include <linux/vs_base.h>
376  
377  #include <asm/uaccess.h>
378  #include <asm/page.h>
379 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
380                 ret = ptrace_request(child, request, addr, data);
381                 break;
382         }
383 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
384 +               goto out_tsk;
385  
386         return ret;
387  out_eio:
388 diff -NurpP --minimal linux-2.6.27.25/arch/m68k/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/m68k/kernel/traps.c
389 --- linux-2.6.27.25/arch/m68k/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
390 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/m68k/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
391 @@ -909,8 +909,8 @@ void show_registers(struct pt_regs *regs
392         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
393                regs->d4, regs->d5, regs->a0, regs->a1);
394  
395 -       printk("Process %s (pid: %d, task=%p)\n",
396 -               current->comm, task_pid_nr(current), current);
397 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
398 +               current->comm, task_pid_nr(current), current->xid, current);
399         addr = (unsigned long)&fp->un;
400         printk("Frame format=%X ", regs->format);
401         switch (regs->format) {
402 diff -NurpP --minimal linux-2.6.27.25/arch/m68knommu/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/m68knommu/Kconfig
403 --- linux-2.6.27.25/arch/m68knommu/Kconfig      2009-06-15 17:18:24.000000000 +0200
404 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/m68knommu/Kconfig 2009-02-22 22:58:32.000000000 +0100
405 @@ -744,6 +744,8 @@ source "fs/Kconfig"
406  
407  source "arch/m68knommu/Kconfig.debug"
408  
409 +source "kernel/vserver/Kconfig"
410 +
411  source "security/Kconfig"
412  
413  source "crypto/Kconfig"
414 diff -NurpP --minimal linux-2.6.27.25/arch/m68knommu/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/m68knommu/kernel/traps.c
415 --- linux-2.6.27.25/arch/m68knommu/kernel/traps.c       2008-10-13 14:51:55.000000000 +0200
416 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/m68knommu/kernel/traps.c  2008-10-13 14:54:20.000000000 +0200
417 @@ -79,8 +79,9 @@ void die_if_kernel(char *str, struct pt_
418         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
419                fp->d4, fp->d5, fp->a0, fp->a1);
420  
421 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
422 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
423 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
424 +               current->comm, task_pid_nr(current), current->xid,
425 +               PAGE_SIZE+(unsigned long)current);
426         show_stack(NULL, (unsigned long *)(fp + 1));
427         add_taint(TAINT_DIE);
428         do_exit(SIGSEGV);
429 diff -NurpP --minimal linux-2.6.27.25/arch/mips/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/mips/Kconfig
430 --- linux-2.6.27.25/arch/mips/Kconfig   2009-06-15 17:18:24.000000000 +0200
431 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/Kconfig      2009-05-15 22:57:04.000000000 +0200
432 @@ -2032,6 +2032,8 @@ source "fs/Kconfig"
433  
434  source "arch/mips/Kconfig.debug"
435  
436 +source "kernel/vserver/Kconfig"
437 +
438  source "security/Kconfig"
439  
440  source "crypto/Kconfig"
441 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/linux32.c linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/linux32.c
442 --- linux-2.6.27.25/arch/mips/kernel/linux32.c  2009-06-15 17:18:24.000000000 +0200
443 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/linux32.c     2009-05-15 22:57:04.000000000 +0200
444 @@ -192,7 +192,7 @@ sys32_gettimeofday(struct compat_timeval
445  {
446         if (tv) {
447                 struct timeval ktv;
448 -               do_gettimeofday(&ktv);
449 +               vx_gettimeofday(&ktv);
450                 if (put_tv32(tv, &ktv))
451                         return -EFAULT;
452         }
453 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/ptrace.c
454 --- linux-2.6.27.25/arch/mips/kernel/ptrace.c   2008-10-13 14:51:56.000000000 +0200
455 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
456 @@ -25,6 +25,7 @@
457  #include <linux/security.h>
458  #include <linux/audit.h>
459  #include <linux/seccomp.h>
460 +#include <linux/vs_base.h>
461  
462  #include <asm/byteorder.h>
463  #include <asm/cpu.h>
464 @@ -171,6 +172,9 @@ long arch_ptrace(struct task_struct *chi
465  {
466         int ret;
467  
468 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
469 +               goto out;
470 +
471         switch (request) {
472         /* when I and D space are separate, these will need to be fixed. */
473         case PTRACE_PEEKTEXT: /* read word at location addr. */
474 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/scall32-o32.S linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall32-o32.S
475 --- linux-2.6.27.25/arch/mips/kernel/scall32-o32.S      2009-06-15 17:18:24.000000000 +0200
476 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall32-o32.S 2009-05-15 22:57:04.000000000 +0200
477 @@ -600,7 +600,7 @@ einval:     li      v0, -EINVAL
478         sys     sys_mq_timedreceive     5
479         sys     sys_mq_notify           2       /* 4275 */
480         sys     sys_mq_getsetattr       3
481 -       sys     sys_ni_syscall          0       /* sys_vserver */
482 +       sys     sys_vserver             3
483         sys     sys_waitid              5
484         sys     sys_ni_syscall          0       /* available, was setaltroot */
485         sys     sys_add_key             5       /* 4280 */
486 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/scall64-64.S linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall64-64.S
487 --- linux-2.6.27.25/arch/mips/kernel/scall64-64.S       2009-06-15 17:18:24.000000000 +0200
488 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall64-64.S  2009-05-15 22:57:04.000000000 +0200
489 @@ -434,7 +434,7 @@ sys_call_table:
490         PTR     sys_mq_timedreceive
491         PTR     sys_mq_notify
492         PTR     sys_mq_getsetattr               /* 5235 */
493 -       PTR     sys_ni_syscall                  /* sys_vserver */
494 +       PTR     sys_vserver
495         PTR     sys_waitid
496         PTR     sys_ni_syscall                  /* available, was setaltroot */
497         PTR     sys_add_key
498 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/scall64-n32.S linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall64-n32.S
499 --- linux-2.6.27.25/arch/mips/kernel/scall64-n32.S      2009-06-15 17:18:24.000000000 +0200
500 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall64-n32.S 2009-05-15 22:57:04.000000000 +0200
501 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
502         PTR     compat_sys_mq_timedreceive
503         PTR     compat_sys_mq_notify
504         PTR     compat_sys_mq_getsetattr
505 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
506 +       PTR     sys32_vserver                   /* 6240 */
507         PTR     compat_sys_waitid
508         PTR     sys_ni_syscall                  /* available, was setaltroot */
509         PTR     sys_add_key
510 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/scall64-o32.S linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall64-o32.S
511 --- linux-2.6.27.25/arch/mips/kernel/scall64-o32.S      2009-06-15 17:18:24.000000000 +0200
512 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/scall64-o32.S 2009-05-15 22:57:46.000000000 +0200
513 @@ -482,7 +482,7 @@ sys_call_table:
514         PTR     compat_sys_mq_timedreceive
515         PTR     compat_sys_mq_notify            /* 4275 */
516         PTR     compat_sys_mq_getsetattr
517 -       PTR     sys_ni_syscall                  /* sys_vserver */
518 +       PTR     sys32_vserver
519         PTR     sys_32_waitid
520         PTR     sys_ni_syscall                  /* available, was setaltroot */
521         PTR     sys_add_key                     /* 4280 */
522 diff -NurpP --minimal linux-2.6.27.25/arch/mips/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/traps.c
523 --- linux-2.6.27.25/arch/mips/kernel/traps.c    2008-10-13 14:51:56.000000000 +0200
524 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
525 @@ -328,9 +328,10 @@ void show_registers(const struct pt_regs
526  
527         __show_regs(regs);
528         print_modules();
529 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
530 -              current->comm, current->pid, current_thread_info(), current,
531 -             field, current_thread_info()->tp_value);
532 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
533 +               current->comm, task_pid_nr(current), current->xid,
534 +               current_thread_info(), current,
535 +               field, current_thread_info()->tp_value);
536         if (cpu_has_userlocal) {
537                 unsigned long tls;
538  
539 diff -NurpP --minimal linux-2.6.27.25/arch/mips/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/mips/mm/fault.c
540 --- linux-2.6.27.25/arch/mips/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
541 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/mips/mm/fault.c   2008-10-13 14:54:20.000000000 +0200
542 @@ -178,7 +178,8 @@ out_of_memory:
543                 down_read(&mm->mmap_sem);
544                 goto survive;
545         }
546 -       printk("VM: killing process %s\n", tsk->comm);
547 +       printk("VM: killing process %s(%d:#%u)\n",
548 +               tsk->comm, tsk->pid, tsk->xid);
549         if (user_mode(regs))
550                 do_group_exit(SIGKILL);
551         goto no_context;
552 diff -NurpP --minimal linux-2.6.27.25/arch/parisc/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/Kconfig
553 --- linux-2.6.27.25/arch/parisc/Kconfig 2008-10-13 14:51:56.000000000 +0200
554 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/Kconfig    2008-10-13 14:54:20.000000000 +0200
555 @@ -279,6 +279,8 @@ source "fs/Kconfig"
556  
557  source "arch/parisc/Kconfig.debug"
558  
559 +source "kernel/vserver/Kconfig"
560 +
561  source "security/Kconfig"
562  
563  source "crypto/Kconfig"
564 diff -NurpP --minimal linux-2.6.27.25/arch/parisc/kernel/syscall_table.S linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/kernel/syscall_table.S
565 --- linux-2.6.27.25/arch/parisc/kernel/syscall_table.S  2008-07-13 23:51:29.000000000 +0200
566 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/kernel/syscall_table.S     2008-10-13 14:54:20.000000000 +0200
567 @@ -361,7 +361,7 @@
568         ENTRY_COMP(mbind)               /* 260 */
569         ENTRY_COMP(get_mempolicy)
570         ENTRY_COMP(set_mempolicy)
571 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
572 +       ENTRY_DIFF(vserver)
573         ENTRY_SAME(add_key)
574         ENTRY_SAME(request_key)         /* 265 */
575         ENTRY_SAME(keyctl)
576 diff -NurpP --minimal linux-2.6.27.25/arch/parisc/kernel/sys_parisc32.c linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/kernel/sys_parisc32.c
577 --- linux-2.6.27.25/arch/parisc/kernel/sys_parisc32.c   2008-07-13 23:51:29.000000000 +0200
578 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/kernel/sys_parisc32.c      2008-10-13 14:54:20.000000000 +0200
579 @@ -203,11 +203,11 @@ static inline long get_ts32(struct times
580  asmlinkage int
581  sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
582  {
583 -    extern void do_gettimeofday(struct timeval *tv);
584 +    extern void vx_gettimeofday(struct timeval *tv);
585  
586      if (tv) {
587             struct timeval ktv;
588 -           do_gettimeofday(&ktv);
589 +           vx_gettimeofday(&ktv);
590             if (put_compat_timeval(tv, &ktv))
591                     return -EFAULT;
592      }
593 diff -NurpP --minimal linux-2.6.27.25/arch/parisc/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/kernel/traps.c
594 --- linux-2.6.27.25/arch/parisc/kernel/traps.c  2009-06-15 17:18:24.000000000 +0200
595 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/kernel/traps.c     2009-02-03 17:59:04.000000000 +0100
596 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
597                 if (err == 0)
598                         return; /* STFU */
599  
600 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
601 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
602 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
603 +                       current->comm, task_pid_nr(current), current->xid,
604 +                       str, err, regs->iaoq[0]);
605  #ifdef PRINT_USER_FAULTS
606                 /* XXX for debugging only */
607                 show_regs(regs);
608 @@ -269,8 +270,8 @@ KERN_CRIT "                     ||     |
609                 pdc_console_restart();
610         
611         if (err)
612 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
613 -                       current->comm, task_pid_nr(current), str, err);
614 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
615 +                       current->comm, task_pid_nr(current), current->xid, str, err);
616  
617         /* Wot's wrong wif bein' racy? */
618         if (current->thread.flags & PARISC_KERNEL_DEATH) {
619 diff -NurpP --minimal linux-2.6.27.25/arch/parisc/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/mm/fault.c
620 --- linux-2.6.27.25/arch/parisc/mm/fault.c      2008-07-13 23:51:29.000000000 +0200
621 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/parisc/mm/fault.c 2008-10-13 14:54:20.000000000 +0200
622 @@ -210,8 +210,9 @@ bad_area:
623  
624  #ifdef PRINT_USER_FAULTS
625                 printk(KERN_DEBUG "\n");
626 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
627 -                   task_pid_nr(tsk), tsk->comm, code, address);
628 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
629 +                   "command='%s' type=%lu address=0x%08lx\n",
630 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
631                 if (vma) {
632                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
633                                         vma->vm_start, vma->vm_end);
634 @@ -261,7 +262,8 @@ no_context:
635  
636    out_of_memory:
637         up_read(&mm->mmap_sem);
638 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
639 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
640 +               current->comm, current->pid, current->xid);
641         if (user_mode(regs))
642                 do_group_exit(SIGKILL);
643         goto no_context;
644 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/Kconfig
645 --- linux-2.6.27.25/arch/powerpc/Kconfig        2009-06-15 17:18:24.000000000 +0200
646 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/Kconfig   2009-02-03 17:59:04.000000000 +0100
647 @@ -836,6 +836,8 @@ source "lib/Kconfig"
648  
649  source "arch/powerpc/Kconfig.debug"
650  
651 +source "kernel/vserver/Kconfig"
652 +
653  source "security/Kconfig"
654  
655  config KEYS_COMPAT
656 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/kernel/irq.c linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/irq.c
657 --- linux-2.6.27.25/arch/powerpc/kernel/irq.c   2008-10-13 14:51:56.000000000 +0200
658 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/irq.c      2008-10-13 14:54:20.000000000 +0200
659 @@ -53,6 +53,7 @@
660  #include <linux/bootmem.h>
661  #include <linux/pci.h>
662  #include <linux/debugfs.h>
663 +#include <linux/vs_context.h>
664  
665  #include <asm/uaccess.h>
666  #include <asm/system.h>
667 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/kernel/process.c linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/process.c
668 --- linux-2.6.27.25/arch/powerpc/kernel/process.c       2008-10-13 14:51:56.000000000 +0200
669 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/process.c  2008-10-13 14:54:20.000000000 +0200
670 @@ -513,8 +513,9 @@ void show_regs(struct pt_regs * regs)
671  #else
672                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
673  #endif
674 -       printk("TASK = %p[%d] '%s' THREAD: %p",
675 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
676 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
677 +              current, task_pid_nr(current), current->xid,
678 +              current->comm, task_thread_info(current));
679  
680  #ifdef CONFIG_SMP
681         printk(" CPU: %d", raw_smp_processor_id());
682 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/kernel/sys_ppc32.c linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/sys_ppc32.c
683 --- linux-2.6.27.25/arch/powerpc/kernel/sys_ppc32.c     2008-10-13 14:51:56.000000000 +0200
684 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/sys_ppc32.c        2008-10-13 14:54:20.000000000 +0200
685 @@ -147,7 +147,7 @@ asmlinkage long compat_sys_gettimeofday(
686  {
687         if (tv) {
688                 struct timeval ktv;
689 -               do_gettimeofday(&ktv);
690 +               vx_gettimeofday(&ktv);
691                 if (put_tv32(tv, &ktv))
692                         return -EFAULT;
693         }
694 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/traps.c
695 --- linux-2.6.27.25/arch/powerpc/kernel/traps.c 2008-10-13 14:51:56.000000000 +0200
696 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/traps.c    2008-10-13 14:54:20.000000000 +0200
697 @@ -941,8 +941,9 @@ void nonrecoverable_exception(struct pt_
698  
699  void trace_syscall(struct pt_regs *regs)
700  {
701 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
702 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
703 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
704 +              current, task_pid_nr(current), current->xid,
705 +              regs->nip, regs->link, regs->gpr[0],
706                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
707  }
708  
709 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/kernel/vdso.c linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/vdso.c
710 --- linux-2.6.27.25/arch/powerpc/kernel/vdso.c  2008-10-13 14:51:56.000000000 +0200
711 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/kernel/vdso.c     2008-10-13 14:54:20.000000000 +0200
712 @@ -22,6 +22,7 @@
713  #include <linux/security.h>
714  #include <linux/bootmem.h>
715  #include <linux/lmb.h>
716 +#include <linux/vs_memory.h>
717  
718  #include <asm/pgtable.h>
719  #include <asm/system.h>
720 diff -NurpP --minimal linux-2.6.27.25/arch/powerpc/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/mm/fault.c
721 --- linux-2.6.27.25/arch/powerpc/mm/fault.c     2008-10-13 14:51:56.000000000 +0200
722 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/powerpc/mm/fault.c        2008-10-13 14:54:20.000000000 +0200
723 @@ -354,7 +354,8 @@ out_of_memory:
724                 down_read(&mm->mmap_sem);
725                 goto survive;
726         }
727 -       printk("VM: killing process %s\n", current->comm);
728 +       printk("VM: killing process %s(%d:#%u)\n",
729 +               current->comm, current->pid, current->xid);
730         if (user_mode(regs))
731                 do_group_exit(SIGKILL);
732         return SIGKILL;
733 diff -NurpP --minimal linux-2.6.27.25/arch/s390/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/s390/Kconfig
734 --- linux-2.6.27.25/arch/s390/Kconfig   2009-06-15 17:18:25.000000000 +0200
735 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/s390/Kconfig      2009-02-03 17:59:04.000000000 +0100
736 @@ -588,6 +588,8 @@ source "fs/Kconfig"
737  
738  source "arch/s390/Kconfig.debug"
739  
740 +source "kernel/vserver/Kconfig"
741 +
742  source "security/Kconfig"
743  
744  source "crypto/Kconfig"
745 diff -NurpP --minimal linux-2.6.27.25/arch/s390/kernel/compat_linux.c linux-2.6.27.25-vs2.3.0.36.6/arch/s390/kernel/compat_linux.c
746 --- linux-2.6.27.25/arch/s390/kernel/compat_linux.c     2008-07-13 23:51:29.000000000 +0200
747 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/s390/kernel/compat_linux.c        2008-10-13 14:54:20.000000000 +0200
748 @@ -566,7 +566,7 @@ asmlinkage long sys32_gettimeofday(struc
749  {
750         if (tv) {
751                 struct timeval ktv;
752 -               do_gettimeofday(&ktv);
753 +               vx_gettimeofday(&ktv);
754                 if (put_tv32(tv, &ktv))
755                         return -EFAULT;
756         }
757 diff -NurpP --minimal linux-2.6.27.25/arch/s390/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/s390/kernel/ptrace.c
758 --- linux-2.6.27.25/arch/s390/kernel/ptrace.c   2008-10-13 14:51:57.000000000 +0200
759 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/s390/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
760 @@ -35,6 +35,7 @@
761  #include <linux/signal.h>
762  #include <linux/elf.h>
763  #include <linux/regset.h>
764 +#include <linux/vs_base.h>
765  
766  #include <asm/segment.h>
767  #include <asm/page.h>
768 diff -NurpP --minimal linux-2.6.27.25/arch/s390/kernel/syscalls.S linux-2.6.27.25-vs2.3.0.36.6/arch/s390/kernel/syscalls.S
769 --- linux-2.6.27.25/arch/s390/kernel/syscalls.S 2009-06-15 17:18:25.000000000 +0200
770 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/s390/kernel/syscalls.S    2009-02-03 17:59:04.000000000 +0100
771 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
772  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
773  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
774  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
775 -NI_SYSCALL                                                     /* reserved for vserver */
776 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
777  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
778  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
779  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
780 diff -NurpP --minimal linux-2.6.27.25/arch/s390/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/s390/mm/fault.c
781 --- linux-2.6.27.25/arch/s390/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
782 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/s390/mm/fault.c   2008-10-13 14:54:20.000000000 +0200
783 @@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
784                 down_read(&mm->mmap_sem);
785                 return 1;
786         }
787 -       printk("VM: killing process %s\n", tsk->comm);
788 +       printk("VM: killing process %s(%d:#%u)\n",
789 +               tsk->comm, tsk->pid, tsk->xid);
790         if (regs->psw.mask & PSW_MASK_PSTATE)
791                 do_group_exit(SIGKILL);
792         do_no_context(regs, error_code, address);
793 diff -NurpP --minimal linux-2.6.27.25/arch/sh/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/sh/Kconfig
794 --- linux-2.6.27.25/arch/sh/Kconfig     2008-10-13 14:51:57.000000000 +0200
795 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sh/Kconfig        2008-10-13 14:54:20.000000000 +0200
796 @@ -747,6 +747,8 @@ source "fs/Kconfig"
797  
798  source "arch/sh/Kconfig.debug"
799  
800 +source "kernel/vserver/Kconfig"
801 +
802  source "security/Kconfig"
803  
804  source "crypto/Kconfig"
805 diff -NurpP --minimal linux-2.6.27.25/arch/sh/kernel/irq.c linux-2.6.27.25-vs2.3.0.36.6/arch/sh/kernel/irq.c
806 --- linux-2.6.27.25/arch/sh/kernel/irq.c        2008-10-13 14:51:57.000000000 +0200
807 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sh/kernel/irq.c   2008-10-13 14:54:20.000000000 +0200
808 @@ -11,6 +11,7 @@
809  #include <linux/module.h>
810  #include <linux/kernel_stat.h>
811  #include <linux/seq_file.h>
812 +#include <linux/vs_context.h>
813  #include <asm/processor.h>
814  #include <asm/machvec.h>
815  #include <asm/uaccess.h>
816 diff -NurpP --minimal linux-2.6.27.25/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.27.25-vs2.3.0.36.6/arch/sh/kernel/vsyscall/vsyscall.c
817 --- linux-2.6.27.25/arch/sh/kernel/vsyscall/vsyscall.c  2008-07-13 23:51:29.000000000 +0200
818 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sh/kernel/vsyscall/vsyscall.c     2008-10-13 14:54:20.000000000 +0200
819 @@ -19,6 +19,7 @@
820  #include <linux/elf.h>
821  #include <linux/sched.h>
822  #include <linux/err.h>
823 +#include <linux/vs_memory.h>
824  
825  /*
826   * Should the kernel map a VDSO page into processes and pass its
827 diff -NurpP --minimal linux-2.6.27.25/arch/sparc/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/Kconfig
828 --- linux-2.6.27.25/arch/sparc/Kconfig  2008-10-13 14:51:58.000000000 +0200
829 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/Kconfig     2008-10-13 14:54:20.000000000 +0200
830 @@ -305,6 +305,8 @@ source "fs/Kconfig"
831  
832  source "arch/sparc/Kconfig.debug"
833  
834 +source "kernel/vserver/Kconfig"
835 +
836  source "security/Kconfig"
837  
838  source "crypto/Kconfig"
839 diff -NurpP --minimal linux-2.6.27.25/arch/sparc/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/kernel/ptrace.c
840 --- linux-2.6.27.25/arch/sparc/kernel/ptrace.c  2008-10-13 14:51:58.000000000 +0200
841 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/kernel/ptrace.c     2008-10-13 14:54:20.000000000 +0200
842 @@ -22,6 +22,7 @@
843  #include <linux/regset.h>
844  #include <linux/elf.h>
845  #include <linux/tracehook.h>
846 +#include <linux/vs_base.h>
847  
848  #include <asm/pgtable.h>
849  #include <asm/system.h>
850 diff -NurpP --minimal linux-2.6.27.25/arch/sparc/kernel/systbls.S linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/kernel/systbls.S
851 --- linux-2.6.27.25/arch/sparc/kernel/systbls.S 2009-06-15 17:18:25.000000000 +0200
852 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/kernel/systbls.S    2009-02-03 17:59:04.000000000 +0100
853 @@ -70,7 +70,7 @@ sys_call_table:
854  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
855  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
856  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
857 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
858 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
859  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
860  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
861  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
862 diff -NurpP --minimal linux-2.6.27.25/arch/sparc/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/kernel/traps.c
863 --- linux-2.6.27.25/arch/sparc/kernel/traps.c   2008-10-13 14:51:58.000000000 +0200
864 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/kernel/traps.c      2008-10-13 14:54:20.000000000 +0200
865 @@ -95,7 +95,8 @@ void die_if_kernel(char *str, struct pt_
866  "              /_| \\__/ |_\\\n"
867  "                 \\__U_/\n");
868  
869 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
870 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
871 +               task_pid_nr(current), current->xid, str, ++die_counter);
872         show_regs(regs);
873         add_taint(TAINT_DIE);
874  
875 diff -NurpP --minimal linux-2.6.27.25/arch/sparc/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/mm/fault.c
876 --- linux-2.6.27.25/arch/sparc/mm/fault.c       2008-10-13 14:51:58.000000000 +0200
877 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc/mm/fault.c  2008-10-13 14:54:20.000000000 +0200
878 @@ -318,7 +318,8 @@ no_context:
879   */
880  out_of_memory:
881         up_read(&mm->mmap_sem);
882 -       printk("VM: killing process %s\n", tsk->comm);
883 +       printk("VM: killing process %s(%d:#%u)\n",
884 +               tsk->comm, tsk->pid, tsk->xid);
885         if (from_user)
886                 do_group_exit(SIGKILL);
887         goto no_context;
888 diff -NurpP --minimal linux-2.6.27.25/arch/sparc64/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/Kconfig
889 --- linux-2.6.27.25/arch/sparc64/Kconfig        2009-06-15 17:18:25.000000000 +0200
890 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/Kconfig   2009-02-22 22:58:32.000000000 +0100
891 @@ -404,6 +404,8 @@ source "fs/Kconfig"
892  
893  source "arch/sparc64/Kconfig.debug"
894  
895 +source "kernel/vserver/Kconfig"
896 +
897  source "security/Kconfig"
898  
899  source "crypto/Kconfig"
900 diff -NurpP --minimal linux-2.6.27.25/arch/sparc64/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/ptrace.c
901 --- linux-2.6.27.25/arch/sparc64/kernel/ptrace.c        2009-06-15 17:18:25.000000000 +0200
902 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/ptrace.c   2009-02-03 17:59:04.000000000 +0100
903 @@ -26,6 +26,7 @@
904  #include <linux/tracehook.h>
905  #include <linux/compat.h>
906  #include <linux/elf.h>
907 +#include <linux/vs_base.h>
908  
909  #include <asm/asi.h>
910  #include <asm/pgtable.h>
911 diff -NurpP --minimal linux-2.6.27.25/arch/sparc64/kernel/sys_sparc32.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/sys_sparc32.c
912 --- linux-2.6.27.25/arch/sparc64/kernel/sys_sparc32.c   2008-10-13 14:51:58.000000000 +0200
913 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/sys_sparc32.c      2008-10-13 14:54:20.000000000 +0200
914 @@ -532,7 +532,7 @@ asmlinkage long sys32_gettimeofday(struc
915  {
916         if (tv) {
917                 struct timeval ktv;
918 -               do_gettimeofday(&ktv);
919 +               vx_gettimeofday(&ktv);
920                 if (put_tv32(tv, &ktv))
921                         return -EFAULT;
922         }
923 diff -NurpP --minimal linux-2.6.27.25/arch/sparc64/kernel/systbls.S linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/systbls.S
924 --- linux-2.6.27.25/arch/sparc64/kernel/systbls.S       2009-06-15 17:18:25.000000000 +0200
925 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/systbls.S  2009-02-22 22:58:32.000000000 +0100
926 @@ -71,7 +71,7 @@ sys_call_table32:
927  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
928         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
929  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
930 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
931 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
932  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
933         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
934  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
935 @@ -145,7 +145,7 @@ sys_call_table:
936  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
937         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
938  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
939 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
940 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
941  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
942         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
943  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
944 diff -NurpP --minimal linux-2.6.27.25/arch/sparc64/kernel/traps.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/traps.c
945 --- linux-2.6.27.25/arch/sparc64/kernel/traps.c 2009-06-15 17:18:25.000000000 +0200
946 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/kernel/traps.c    2009-03-25 14:32:29.000000000 +0100
947 @@ -2201,7 +2201,8 @@ void die_if_kernel(char *str, struct pt_
948  "              /_| \\__/ |_\\\n"
949  "                 \\__U_/\n");
950  
951 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
952 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
953 +               task_pid_nr(current), current->xid, str, ++die_counter);
954         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
955         __asm__ __volatile__("flushw");
956         show_regs(regs);
957 diff -NurpP --minimal linux-2.6.27.25/arch/sparc64/mm/fault.c linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/mm/fault.c
958 --- linux-2.6.27.25/arch/sparc64/mm/fault.c     2008-10-13 14:51:58.000000000 +0200
959 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/sparc64/mm/fault.c        2008-10-13 14:54:20.000000000 +0200
960 @@ -452,7 +452,8 @@ handle_kernel_fault:
961  out_of_memory:
962         insn = get_fault_insn(regs, insn);
963         up_read(&mm->mmap_sem);
964 -       printk("VM: killing process %s\n", current->comm);
965 +       printk("VM: killing process %s(%d:#%u)\n",
966 +               current->comm, current->pid, current->xid);
967         if (!(regs->tstate & TSTATE_PRIV))
968                 do_group_exit(SIGKILL);
969         goto handle_kernel_fault;
970 diff -NurpP --minimal linux-2.6.27.25/arch/um/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/um/Kconfig
971 --- linux-2.6.27.25/arch/um/Kconfig     2008-07-13 23:51:29.000000000 +0200
972 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/um/Kconfig        2008-10-13 14:54:20.000000000 +0200
973 @@ -245,6 +245,8 @@ source "drivers/connector/Kconfig"
974  
975  source "fs/Kconfig"
976  
977 +source "kernel/vserver/Kconfig"
978 +
979  source "security/Kconfig"
980  
981  source "crypto/Kconfig"
982 diff -NurpP --minimal linux-2.6.27.25/arch/um/kernel/trap.c linux-2.6.27.25-vs2.3.0.36.6/arch/um/kernel/trap.c
983 --- linux-2.6.27.25/arch/um/kernel/trap.c       2008-07-13 23:51:29.000000000 +0200
984 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/um/kernel/trap.c  2008-10-13 14:54:20.000000000 +0200
985 @@ -215,7 +215,8 @@ unsigned long segv(struct faultinfo fi, 
986                 current->thread.arch.faultinfo = fi;
987                 force_sig_info(SIGBUS, &si, current);
988         } else if (err == -ENOMEM) {
989 -               printk(KERN_INFO "VM: killing process %s\n", current->comm);
990 +               printk(KERN_INFO "VM: killing process %s(%d:#%u)\n",
991 +                       current->comm, task_pid_nr(current), current->xid);
992                 do_exit(SIGKILL);
993         } else {
994                 BUG_ON(err != -EFAULT);
995 diff -NurpP --minimal linux-2.6.27.25/arch/x86/ia32/ia32entry.S linux-2.6.27.25-vs2.3.0.36.6/arch/x86/ia32/ia32entry.S
996 --- linux-2.6.27.25/arch/x86/ia32/ia32entry.S   2009-06-15 17:18:25.000000000 +0200
997 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/x86/ia32/ia32entry.S      2009-03-25 14:32:29.000000000 +0100
998 @@ -774,7 +774,7 @@ ia32_sys_call_table:
999         .quad sys_tgkill                /* 270 */
1000         .quad compat_sys_utimes
1001         .quad sys32_fadvise64_64
1002 -       .quad quiet_ni_syscall  /* sys_vserver */
1003 +       .quad sys32_vserver
1004         .quad sys_mbind
1005         .quad compat_sys_get_mempolicy  /* 275 */
1006         .quad sys_set_mempolicy
1007 diff -NurpP --minimal linux-2.6.27.25/arch/x86/Kconfig linux-2.6.27.25-vs2.3.0.36.6/arch/x86/Kconfig
1008 --- linux-2.6.27.25/arch/x86/Kconfig    2009-06-15 17:18:25.000000000 +0200
1009 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/x86/Kconfig       2009-02-22 22:58:32.000000000 +0100
1010 @@ -1811,6 +1811,8 @@ source "fs/Kconfig"
1011  
1012  source "arch/x86/Kconfig.debug"
1013  
1014 +source "kernel/vserver/Kconfig"
1015 +
1016  source "security/Kconfig"
1017  
1018  source "crypto/Kconfig"
1019 diff -NurpP --minimal linux-2.6.27.25/arch/x86/kernel/syscall_table_32.S linux-2.6.27.25-vs2.3.0.36.6/arch/x86/kernel/syscall_table_32.S
1020 --- linux-2.6.27.25/arch/x86/kernel/syscall_table_32.S  2009-06-15 17:18:26.000000000 +0200
1021 +++ linux-2.6.27.25-vs2.3.0.36.6/arch/x86/kernel/syscall_table_32.S     2009-02-03 17:59:04.000000000 +0100
1022 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1023         .long sys_tgkill        /* 270 */
1024         .long sys_utimes
1025         .long sys_fadvise64_64
1026 -       .long sys_ni_syscall    /* sys_vserver */
1027 +       .long sys_vserver
1028         .long sys_mbind
1029         .long sys_get_mempolicy
1030         .long sys_set_mempolicy
1031 diff -NurpP --minimal linux-2.6.27.25/Documentation/vserver/debug.txt linux-2.6.27.25-vs2.3.0.36.6/Documentation/vserver/debug.txt
1032 --- linux-2.6.27.25/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
1033 +++ linux-2.6.27.25-vs2.3.0.36.6/Documentation/vserver/debug.txt        2008-10-13 14:54:20.000000000 +0200
1034 @@ -0,0 +1,154 @@
1035 +
1036 +debug_cvirt:
1037 +
1038 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1039 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1040 +
1041 +debug_dlim:
1042 +
1043 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1044 +       "FREE  (%p,#%d)%c inode"
1045 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1046 +       "FREE  (%p,#%d)%c %lld bytes"
1047 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1048 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1049 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1050 +       "rcu_free_dl_info(%p)"
1051 + 4  10 "alloc_dl_info(%p,%d) = %p"
1052 +       "dealloc_dl_info(%p)"
1053 +       "get_dl_info(%p[#%d.%d])"
1054 +       "put_dl_info(%p[#%d.%d])"
1055 + 5  20 "alloc_dl_info(%p,%d)*"
1056 + 6  40 "__hash_dl_info: %p[#%d]"
1057 +       "__unhash_dl_info: %p[#%d]"
1058 + 7  80 "locate_dl_info(%p,#%d) = %p"
1059 +
1060 +debug_misc:
1061 +
1062 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1063 +       "new_dqhash: %p [#0x%08x]"
1064 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1065 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1066 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1067 +       "vroot_get_real_bdev not set"
1068 + 1   2 "cow_break_link(»%s«)"
1069 +       "temp copy Â»%s«"
1070 + 2   4 "dentry_open(new): %p"
1071 +       "dentry_open(old): %p"
1072 +       "lookup_create(new): %p"
1073 +       "old path Â»%s«"
1074 +       "path_lookup(old): %d"
1075 +       "vfs_create(new): %d"
1076 +       "vfs_rename: %d"
1077 +       "vfs_sendfile: %d"
1078 + 3   8 "fput(new_file=%p[#%d])"
1079 +       "fput(old_file=%p[#%d])"
1080 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1081 +       "vx_info_kill(%p[#%d],%d,%d)*"
1082 + 5  20 "vs_reboot(%p[#%d],%d)"
1083 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1084 +
1085 +debug_net:
1086 +
1087 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1088 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1089 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1090 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1091 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1092 + 6  40 "sk,egf: %p [#%d] (from %d)"
1093 +       "sk,egn: %p [#%d] (from %d)"
1094 +       "sk,req: %p [#%d] (from %d)"
1095 +       "sk: %p [#%d] (from %d)"
1096 +       "tw: %p [#%d] (from %d)"
1097 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1098 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1099 +
1100 +debug_nid:
1101 +
1102 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1103 +       "alloc_nx_info(%d) = %p"
1104 +       "create_nx_info(%d) (dynamic rejected)"
1105 +       "create_nx_info(%d) = %p (already there)"
1106 +       "create_nx_info(%d) = %p (new)"
1107 +       "dealloc_nx_info(%p)"
1108 + 1   2 "alloc_nx_info(%d)*"
1109 +       "create_nx_info(%d)*"
1110 + 2   4 "get_nx_info(%p[#%d.%d])"
1111 +       "put_nx_info(%p[#%d.%d])"
1112 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1113 +       "clr_nx_info(%p[#%d.%d])"
1114 +       "init_nx_info(%p[#%d.%d])"
1115 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1116 +       "set_nx_info(%p[#%d.%d])"
1117 + 4  10 "__hash_nx_info: %p[#%d]"
1118 +       "__nx_dynamic_id: [#%d]"
1119 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1120 + 5  20 "moved task %p into nxi:%p[#%d]"
1121 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1122 +       "task_get_nx_info(%p)"
1123 + 6  40 "nx_clear_persistent(%p[#%d])"
1124 +
1125 +debug_quota:
1126 +
1127 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1128 + 1   2 "quota_sync_dqh(%p,%d)"
1129 +       "sync_dquots(%p,%d)"
1130 +       "sync_dquots_dqh(%p,%d)"
1131 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1132 +
1133 +debug_switch:
1134 +
1135 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1136 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1137 + 4  10 "%s: (%s %s) returned %s with %d"
1138 +
1139 +debug_tag:
1140 +
1141 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1142 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1143 +
1144 +debug_xid:
1145 +
1146 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1147 +       "alloc_vx_info(%d) = %p"
1148 +       "alloc_vx_info(%d)*"
1149 +       "create_vx_info(%d) (dynamic rejected)"
1150 +       "create_vx_info(%d) = %p (already there)"
1151 +       "create_vx_info(%d) = %p (new)"
1152 +       "dealloc_vx_info(%p)"
1153 +       "loc_vx_info(%d) = %p (found)"
1154 +       "loc_vx_info(%d) = %p (new)"
1155 +       "loc_vx_info(%d) = %p (not available)"
1156 + 1   2 "create_vx_info(%d)*"
1157 +       "loc_vx_info(%d)*"
1158 + 2   4 "get_vx_info(%p[#%d.%d])"
1159 +       "put_vx_info(%p[#%d.%d])"
1160 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1161 +       "clr_vx_info(%p[#%d.%d])"
1162 +       "init_vx_info(%p[#%d.%d])"
1163 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1164 +       "set_vx_info(%p[#%d.%d])"
1165 + 4  10 "__hash_vx_info: %p[#%d]"
1166 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1167 +       "__vx_dynamic_id: [#%d]"
1168 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1169 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1170 +       "moved task %p into vxi:%p[#%d]"
1171 +       "task_get_vx_info(%p)"
1172 +       "vx_migrate_task(%p,%p[#%d.%d])"
1173 + 6  40 "vx_clear_persistent(%p[#%d])"
1174 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1175 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1176 +       "vx_set_persistent(%p[#%d])"
1177 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1178 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1179 +
1180 +
1181 +debug_limit:
1182 +
1183 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1184 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1185 +
1186 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1187 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1188 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1189 diff -NurpP --minimal linux-2.6.27.25/drivers/block/Kconfig linux-2.6.27.25-vs2.3.0.36.6/drivers/block/Kconfig
1190 --- linux-2.6.27.25/drivers/block/Kconfig       2008-10-13 14:51:59.000000000 +0200
1191 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/block/Kconfig  2008-10-13 14:54:20.000000000 +0200
1192 @@ -263,6 +263,13 @@ config BLK_DEV_CRYPTOLOOP
1193           instead, which can be configured to be on-disk compatible with the
1194           cryptoloop device.
1195  
1196 +config BLK_DEV_VROOT
1197 +       tristate "Virtual Root device support"
1198 +       depends on QUOTACTL
1199 +       ---help---
1200 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1201 +         partition within a virtual server without compromising security.
1202 +
1203  config BLK_DEV_NBD
1204         tristate "Network block device support"
1205         depends on NET
1206 diff -NurpP --minimal linux-2.6.27.25/drivers/block/loop.c linux-2.6.27.25-vs2.3.0.36.6/drivers/block/loop.c
1207 --- linux-2.6.27.25/drivers/block/loop.c        2008-07-13 23:51:29.000000000 +0200
1208 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/block/loop.c   2008-10-13 14:54:20.000000000 +0200
1209 @@ -76,6 +76,7 @@
1210  #include <linux/gfp.h>
1211  #include <linux/kthread.h>
1212  #include <linux/splice.h>
1213 +#include <linux/vs_context.h>
1214  
1215  #include <asm/uaccess.h>
1216  
1217 @@ -794,6 +795,7 @@ static int loop_set_fd(struct loop_devic
1218         lo->lo_blocksize = lo_blocksize;
1219         lo->lo_device = bdev;
1220         lo->lo_flags = lo_flags;
1221 +       lo->lo_xid = vx_current_xid();
1222         lo->lo_backing_file = file;
1223         lo->transfer = transfer_none;
1224         lo->ioctl = NULL;
1225 @@ -915,6 +917,7 @@ static int loop_clr_fd(struct loop_devic
1226         lo->lo_encrypt_key_size = 0;
1227         lo->lo_flags = 0;
1228         lo->lo_thread = NULL;
1229 +       lo->lo_xid = 0;
1230         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1231         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1232         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1233 @@ -938,7 +941,7 @@ loop_set_status(struct loop_device *lo, 
1234         struct loop_func_table *xfer;
1235  
1236         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
1237 -           !capable(CAP_SYS_ADMIN))
1238 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1239                 return -EPERM;
1240         if (lo->lo_state != Lo_bound)
1241                 return -ENXIO;
1242 @@ -1022,7 +1025,8 @@ loop_get_status(struct loop_device *lo, 
1243         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1244         info->lo_encrypt_type =
1245                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1246 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1247 +       if (lo->lo_encrypt_key_size &&
1248 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1249                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1250                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1251                        lo->lo_encrypt_key_size);
1252 @@ -1331,6 +1335,9 @@ static int lo_open(struct inode *inode, 
1253  {
1254         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1255  
1256 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1257 +               return -EACCES;
1258 +
1259         mutex_lock(&lo->lo_ctl_mutex);
1260         lo->lo_refcnt++;
1261         mutex_unlock(&lo->lo_ctl_mutex);
1262 diff -NurpP --minimal linux-2.6.27.25/drivers/block/Makefile linux-2.6.27.25-vs2.3.0.36.6/drivers/block/Makefile
1263 --- linux-2.6.27.25/drivers/block/Makefile      2008-10-13 14:51:59.000000000 +0200
1264 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/block/Makefile 2008-10-13 14:54:20.000000000 +0200
1265 @@ -30,5 +30,6 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1266  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1267  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1268  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1269 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1270  
1271  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1272 diff -NurpP --minimal linux-2.6.27.25/drivers/block/vroot.c linux-2.6.27.25-vs2.3.0.36.6/drivers/block/vroot.c
1273 --- linux-2.6.27.25/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
1274 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/block/vroot.c  2008-10-13 14:54:20.000000000 +0200
1275 @@ -0,0 +1,283 @@
1276 +/*
1277 + *  linux/drivers/block/vroot.c
1278 + *
1279 + *  written by Herbert Pötzl, 9/11/2002
1280 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1281 + *
1282 + *  based on the loop.c code by Theodore Ts'o.
1283 + *
1284 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1285 + * Redistribution of this file is permitted under the
1286 + * GNU General Public License.
1287 + *
1288 + */
1289 +
1290 +#include <linux/module.h>
1291 +#include <linux/moduleparam.h>
1292 +#include <linux/file.h>
1293 +#include <linux/major.h>
1294 +#include <linux/blkdev.h>
1295 +
1296 +#include <linux/vroot.h>
1297 +#include <linux/vs_context.h>
1298 +
1299 +
1300 +static int max_vroot = 8;
1301 +
1302 +static struct vroot_device *vroot_dev;
1303 +static struct gendisk **disks;
1304 +
1305 +
1306 +static int vroot_set_dev(
1307 +       struct vroot_device *vr,
1308 +       struct file *vr_file,
1309 +       struct block_device *bdev,
1310 +       unsigned int arg)
1311 +{
1312 +       struct block_device *real_bdev;
1313 +       struct file *file;
1314 +       struct inode *inode;
1315 +       int error;
1316 +
1317 +       error = -EBUSY;
1318 +       if (vr->vr_state != Vr_unbound)
1319 +               goto out;
1320 +
1321 +       error = -EBADF;
1322 +       file = fget(arg);
1323 +       if (!file)
1324 +               goto out;
1325 +
1326 +       error = -EINVAL;
1327 +       inode = file->f_dentry->d_inode;
1328 +
1329 +
1330 +       if (S_ISBLK(inode->i_mode)) {
1331 +               real_bdev = inode->i_bdev;
1332 +               vr->vr_device = real_bdev;
1333 +               __iget(real_bdev->bd_inode);
1334 +       } else
1335 +               goto out_fput;
1336 +
1337 +       vxdprintk(VXD_CBIT(misc, 0),
1338 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1339 +               vr->vr_number, VXD_DEV(real_bdev));
1340 +
1341 +       vr->vr_state = Vr_bound;
1342 +       error = 0;
1343 +
1344 + out_fput:
1345 +       fput(file);
1346 + out:
1347 +       return error;
1348 +}
1349 +
1350 +static int vroot_clr_dev(
1351 +       struct vroot_device *vr,
1352 +       struct file *vr_file,
1353 +       struct block_device *bdev)
1354 +{
1355 +       struct block_device *real_bdev;
1356 +
1357 +       if (vr->vr_state != Vr_bound)
1358 +               return -ENXIO;
1359 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1360 +               return -EBUSY;
1361 +
1362 +       real_bdev = vr->vr_device;
1363 +
1364 +       vxdprintk(VXD_CBIT(misc, 0),
1365 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1366 +               vr->vr_number, VXD_DEV(real_bdev));
1367 +
1368 +       bdput(real_bdev);
1369 +       vr->vr_state = Vr_unbound;
1370 +       vr->vr_device = NULL;
1371 +       return 0;
1372 +}
1373 +
1374 +
1375 +static int vr_ioctl(struct inode *inode, struct file *file,
1376 +       unsigned int cmd, unsigned long arg)
1377 +{
1378 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1379 +       int err;
1380 +
1381 +       down(&vr->vr_ctl_mutex);
1382 +       switch (cmd) {
1383 +       case VROOT_SET_DEV:
1384 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
1385 +               break;
1386 +       case VROOT_CLR_DEV:
1387 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
1388 +               break;
1389 +       default:
1390 +               err = -EINVAL;
1391 +               break;
1392 +       }
1393 +       up(&vr->vr_ctl_mutex);
1394 +       return err;
1395 +}
1396 +
1397 +static int vr_open(struct inode *inode, struct file *file)
1398 +{
1399 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1400 +
1401 +       down(&vr->vr_ctl_mutex);
1402 +       vr->vr_refcnt++;
1403 +       up(&vr->vr_ctl_mutex);
1404 +       return 0;
1405 +}
1406 +
1407 +static int vr_release(struct inode *inode, struct file *file)
1408 +{
1409 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1410 +
1411 +       down(&vr->vr_ctl_mutex);
1412 +       --vr->vr_refcnt;
1413 +       up(&vr->vr_ctl_mutex);
1414 +       return 0;
1415 +}
1416 +
1417 +static struct block_device_operations vr_fops = {
1418 +       .owner =        THIS_MODULE,
1419 +       .open =         vr_open,
1420 +       .release =      vr_release,
1421 +       .ioctl =        vr_ioctl,
1422 +};
1423 +
1424 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1425 +{
1426 +       struct inode *inode = bdev->bd_inode;
1427 +       struct vroot_device *vr;
1428 +       struct block_device *real_bdev;
1429 +       int minor = iminor(inode);
1430 +
1431 +       vr = &vroot_dev[minor];
1432 +       real_bdev = vr->vr_device;
1433 +
1434 +       vxdprintk(VXD_CBIT(misc, 0),
1435 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1436 +               vr->vr_number, VXD_DEV(real_bdev));
1437 +
1438 +       if (vr->vr_state != Vr_bound)
1439 +               return ERR_PTR(-ENXIO);
1440 +
1441 +       __iget(real_bdev->bd_inode);
1442 +       return real_bdev;
1443 +}
1444 +
1445 +/*
1446 + * And now the modules code and kernel interface.
1447 + */
1448 +
1449 +module_param(max_vroot, int, 0);
1450 +
1451 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1452 +MODULE_LICENSE("GPL");
1453 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1454 +
1455 +MODULE_AUTHOR ("Herbert Pötzl");
1456 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1457 +
1458 +
1459 +int __init vroot_init(void)
1460 +{
1461 +       int err, i;
1462 +
1463 +       if (max_vroot < 1 || max_vroot > 256) {
1464 +               max_vroot = MAX_VROOT_DEFAULT;
1465 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1466 +                       "(must be between 1 and 256), "
1467 +                       "using default (%d)\n", max_vroot);
1468 +       }
1469 +
1470 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1471 +               return -EIO;
1472 +
1473 +       err = -ENOMEM;
1474 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1475 +       if (!vroot_dev)
1476 +               goto out_mem1;
1477 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1478 +
1479 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1480 +       if (!disks)
1481 +               goto out_mem2;
1482 +
1483 +       for (i = 0; i < max_vroot; i++) {
1484 +               disks[i] = alloc_disk(1);
1485 +               if (!disks[i])
1486 +                       goto out_mem3;
1487 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1488 +               if (!disks[i]->queue)
1489 +                       goto out_mem3;
1490 +       }
1491 +
1492 +       for (i = 0; i < max_vroot; i++) {
1493 +               struct vroot_device *vr = &vroot_dev[i];
1494 +               struct gendisk *disk = disks[i];
1495 +
1496 +               memset(vr, 0, sizeof(*vr));
1497 +               init_MUTEX(&vr->vr_ctl_mutex);
1498 +               vr->vr_number = i;
1499 +               disk->major = VROOT_MAJOR;
1500 +               disk->first_minor = i;
1501 +               disk->fops = &vr_fops;
1502 +               sprintf(disk->disk_name, "vroot%d", i);
1503 +               disk->private_data = vr;
1504 +       }
1505 +
1506 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1507 +       if (err)
1508 +               goto out_mem3;
1509 +
1510 +       for (i = 0; i < max_vroot; i++)
1511 +               add_disk(disks[i]);
1512 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1513 +       return 0;
1514 +
1515 +out_mem3:
1516 +       while (i--)
1517 +               put_disk(disks[i]);
1518 +       kfree(disks);
1519 +out_mem2:
1520 +       kfree(vroot_dev);
1521 +out_mem1:
1522 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1523 +       printk(KERN_ERR "vroot: ran out of memory\n");
1524 +       return err;
1525 +}
1526 +
1527 +void vroot_exit(void)
1528 +{
1529 +       int i;
1530 +
1531 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1532 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1533 +
1534 +       for (i = 0; i < max_vroot; i++) {
1535 +               del_gendisk(disks[i]);
1536 +               put_disk(disks[i]);
1537 +       }
1538 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1539 +
1540 +       kfree(disks);
1541 +       kfree(vroot_dev);
1542 +}
1543 +
1544 +module_init(vroot_init);
1545 +module_exit(vroot_exit);
1546 +
1547 +#ifndef MODULE
1548 +
1549 +static int __init max_vroot_setup(char *str)
1550 +{
1551 +       max_vroot = simple_strtol(str, NULL, 0);
1552 +       return 1;
1553 +}
1554 +
1555 +__setup("max_vroot=", max_vroot_setup);
1556 +
1557 +#endif
1558 +
1559 diff -NurpP --minimal linux-2.6.27.25/drivers/char/sysrq.c linux-2.6.27.25-vs2.3.0.36.6/drivers/char/sysrq.c
1560 --- linux-2.6.27.25/drivers/char/sysrq.c        2008-10-13 14:51:59.000000000 +0200
1561 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/char/sysrq.c   2008-10-13 14:54:20.000000000 +0200
1562 @@ -37,6 +37,7 @@
1563  #include <linux/irq.h>
1564  #include <linux/hrtimer.h>
1565  #include <linux/oom.h>
1566 +#include <linux/vserver/debug.h>
1567  
1568  #include <asm/ptrace.h>
1569  #include <asm/irq_regs.h>
1570 @@ -351,6 +352,21 @@ static struct sysrq_key_op sysrq_unrt_op
1571         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1572  };
1573  
1574 +
1575 +#ifdef CONFIG_VSERVER_DEBUG
1576 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1577 +{
1578 +       dump_vx_info_inactive((key == 'x')?0:1);
1579 +}
1580 +
1581 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1582 +       .handler        = sysrq_handle_vxinfo,
1583 +       .help_msg       = "conteXt",
1584 +       .action_msg     = "Show Context Info",
1585 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1586 +};
1587 +#endif
1588 +
1589  /* Key Operations table and lock */
1590  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1591  
1592 @@ -404,7 +420,11 @@ static struct sysrq_key_op *sysrq_key_ta
1593         NULL,                           /* x */
1594         /* y: May be registered on sparc64 for global register dump */
1595         NULL,                           /* y */
1596 -       NULL                            /* z */
1597 +#ifdef CONFIG_VSERVER_DEBUG
1598 +       &sysrq_showvxinfo_op,           /* z */
1599 +#else
1600 +       NULL,                           /* z */
1601 +#endif
1602  };
1603  
1604  /* key2index calculation, -1 on invalid index */
1605 @@ -416,6 +436,8 @@ static int sysrq_key_table_key2index(int
1606                 retval = key - '0';
1607         else if ((key >= 'a') && (key <= 'z'))
1608                 retval = key + 10 - 'a';
1609 +       else if ((key >= 'A') && (key <= 'Z'))
1610 +               retval = key + 10 - 'A';
1611         else
1612                 retval = -1;
1613         return retval;
1614 diff -NurpP --minimal linux-2.6.27.25/drivers/char/tty_io.c linux-2.6.27.25-vs2.3.0.36.6/drivers/char/tty_io.c
1615 --- linux-2.6.27.25/drivers/char/tty_io.c       2009-06-15 17:18:27.000000000 +0200
1616 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/char/tty_io.c  2009-02-03 17:59:04.000000000 +0100
1617 @@ -106,6 +106,7 @@
1618  
1619  #include <linux/kmod.h>
1620  #include <linux/nsproxy.h>
1621 +#include <linux/vs_pid.h>
1622  
1623  #undef TTY_DEBUG_HANGUP
1624  
1625 @@ -2770,6 +2771,7 @@ static int tiocspgrp(struct tty_struct *
1626                 return -ENOTTY;
1627         if (get_user(pgrp_nr, p))
1628                 return -EFAULT;
1629 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1630         if (pgrp_nr < 0)
1631                 return -EINVAL;
1632         rcu_read_lock();
1633 diff -NurpP --minimal linux-2.6.27.25/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.27.25-vs2.3.0.36.6/drivers/infiniband/hw/ipath/ipath_user_pages.c
1634 --- linux-2.6.27.25/drivers/infiniband/hw/ipath/ipath_user_pages.c      2008-07-13 23:51:29.000000000 +0200
1635 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/infiniband/hw/ipath/ipath_user_pages.c 2008-10-13 14:54:20.000000000 +0200
1636 @@ -33,6 +33,7 @@
1637  
1638  #include <linux/mm.h>
1639  #include <linux/device.h>
1640 +#include <linux/vs_memory.h>
1641  
1642  #include "ipath_kernel.h"
1643  
1644 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
1645         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1646                 PAGE_SHIFT;
1647  
1648 -       if (num_pages > lock_limit) {
1649 +       if (num_pages > lock_limit ||
1650 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1651                 ret = -ENOMEM;
1652                 goto bail;
1653         }
1654 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
1655                         goto bail_release;
1656         }
1657  
1658 -       current->mm->locked_vm += num_pages;
1659 +       vx_vmlocked_add(current->mm, num_pages);
1660  
1661         ret = 0;
1662         goto bail;
1663 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
1664  
1665         __ipath_release_user_pages(p, num_pages, 1);
1666  
1667 -       current->mm->locked_vm -= num_pages;
1668 +       vx_vmlocked_sub(current->mm, num_pages);
1669  
1670         up_write(&current->mm->mmap_sem);
1671  }
1672 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
1673                 container_of(_work, struct ipath_user_pages_work, work);
1674  
1675         down_write(&work->mm->mmap_sem);
1676 -       work->mm->locked_vm -= work->num_pages;
1677 +       vx_vmlocked_sub(work->mm, work->num_pages);
1678         up_write(&work->mm->mmap_sem);
1679         mmput(work->mm);
1680         kfree(work);
1681 diff -NurpP --minimal linux-2.6.27.25/drivers/md/dm.c linux-2.6.27.25-vs2.3.0.36.6/drivers/md/dm.c
1682 --- linux-2.6.27.25/drivers/md/dm.c     2008-10-13 14:52:01.000000000 +0200
1683 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/md/dm.c        2008-10-13 14:54:20.000000000 +0200
1684 @@ -22,6 +22,7 @@
1685  #include <linux/hdreg.h>
1686  #include <linux/blktrace_api.h>
1687  #include <linux/smp_lock.h>
1688 +#include <linux/vs_base.h>
1689  
1690  #define DM_MSG_PREFIX "core"
1691  
1692 @@ -91,6 +92,7 @@ struct mapped_device {
1693         rwlock_t map_lock;
1694         atomic_t holders;
1695         atomic_t open_count;
1696 +       xid_t xid;
1697  
1698         unsigned long flags;
1699  
1700 @@ -252,6 +254,7 @@ static void __exit dm_exit(void)
1701  static int dm_blk_open(struct inode *inode, struct file *file)
1702  {
1703         struct mapped_device *md;
1704 +       int ret = -ENXIO;
1705  
1706         spin_lock(&_minor_lock);
1707  
1708 @@ -260,18 +263,19 @@ static int dm_blk_open(struct inode *ino
1709                 goto out;
1710  
1711         if (test_bit(DMF_FREEING, &md->flags) ||
1712 -           test_bit(DMF_DELETING, &md->flags)) {
1713 -               md = NULL;
1714 +           test_bit(DMF_DELETING, &md->flags))
1715 +               goto out;
1716 +
1717 +       ret = -EACCES;
1718 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1719                 goto out;
1720 -       }
1721  
1722         dm_get(md);
1723         atomic_inc(&md->open_count);
1724 -
1725 +       ret = 0;
1726  out:
1727         spin_unlock(&_minor_lock);
1728 -
1729 -       return md ? 0 : -ENXIO;
1730 +       return ret;
1731  }
1732  
1733  static int dm_blk_close(struct inode *inode, struct file *file)
1734 @@ -467,6 +471,14 @@ int dm_set_geometry(struct mapped_device
1735         return 0;
1736  }
1737  
1738 +/*
1739 + * Get the xid associated with a dm device
1740 + */
1741 +xid_t dm_get_xid(struct mapped_device *md)
1742 +{
1743 +       return md->xid;
1744 +}
1745 +
1746  /*-----------------------------------------------------------------
1747   * CRUD START:
1748   *   A more elegant soln is in the works that uses the queue
1749 @@ -1069,6 +1081,7 @@ static struct mapped_device *alloc_dev(i
1750         INIT_LIST_HEAD(&md->uevent_list);
1751         spin_lock_init(&md->uevent_lock);
1752  
1753 +       md->xid = vx_current_xid();
1754         md->queue = blk_alloc_queue(GFP_KERNEL);
1755         if (!md->queue)
1756                 goto bad_queue;
1757 diff -NurpP --minimal linux-2.6.27.25/drivers/md/dm.h linux-2.6.27.25-vs2.3.0.36.6/drivers/md/dm.h
1758 --- linux-2.6.27.25/drivers/md/dm.h     2008-10-13 14:52:01.000000000 +0200
1759 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/md/dm.h        2008-10-13 14:54:20.000000000 +0200
1760 @@ -66,6 +66,8 @@ void dm_put_target_type(struct target_ty
1761  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
1762                                         void *param), void *param);
1763  
1764 +xid_t dm_get_xid(struct mapped_device *md);
1765 +
1766  /*-----------------------------------------------------------------
1767   * Useful inlines.
1768   *---------------------------------------------------------------*/
1769 diff -NurpP --minimal linux-2.6.27.25/drivers/md/dm-ioctl.c linux-2.6.27.25-vs2.3.0.36.6/drivers/md/dm-ioctl.c
1770 --- linux-2.6.27.25/drivers/md/dm-ioctl.c       2009-06-15 17:18:28.000000000 +0200
1771 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/md/dm-ioctl.c  2009-03-25 14:32:29.000000000 +0100
1772 @@ -16,6 +16,7 @@
1773  #include <linux/dm-ioctl.h>
1774  #include <linux/hdreg.h>
1775  #include <linux/compat.h>
1776 +#include <linux/vs_context.h>
1777  
1778  #include <asm/uaccess.h>
1779  
1780 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1781         unsigned int h = hash_str(str);
1782  
1783         list_for_each_entry (hc, _name_buckets + h, name_list)
1784 -               if (!strcmp(hc->name, str)) {
1785 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1786 +                       !strcmp(hc->name, str)) {
1787                         dm_get(hc->md);
1788                         return hc;
1789                 }
1790 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1791         unsigned int h = hash_str(str);
1792  
1793         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1794 -               if (!strcmp(hc->uuid, str)) {
1795 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1796 +                       !strcmp(hc->uuid, str)) {
1797                         dm_get(hc->md);
1798                         return hc;
1799                 }
1800 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1801  
1802  static int remove_all(struct dm_ioctl *param, size_t param_size)
1803  {
1804 +       if (!vx_check(0, VS_ADMIN))
1805 +               return -EPERM;
1806 +
1807         dm_hash_remove_all(1);
1808         param->data_size = 0;
1809         return 0;
1810 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1811          */
1812         for (i = 0; i < NUM_BUCKETS; i++) {
1813                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1814 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1815 +                               continue;
1816                         needed += sizeof(struct dm_name_list);
1817                         needed += strlen(hc->name) + 1;
1818                         needed += ALIGN_MASK;
1819 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1820          */
1821         for (i = 0; i < NUM_BUCKETS; i++) {
1822                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1823 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1824 +                               continue;
1825                         if (old_nl)
1826                                 old_nl->next = (uint32_t) ((void *) nl -
1827                                                            (void *) old_nl);
1828 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
1829         if (!md)
1830                 goto out;
1831  
1832 -       mdptr = dm_get_mdptr(md);
1833 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1834 +               mdptr = dm_get_mdptr(md);
1835 +
1836         if (!mdptr)
1837                 dm_put(md);
1838 -
1839  out:
1840         return mdptr;
1841  }
1842 @@ -1407,8 +1418,8 @@ static int ctl_ioctl(uint command, struc
1843         ioctl_fn fn = NULL;
1844         size_t param_size;
1845  
1846 -       /* only root can play with this */
1847 -       if (!capable(CAP_SYS_ADMIN))
1848 +       /* only root and certain contexts can play with this */
1849 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1850                 return -EACCES;
1851  
1852         if (_IOC_TYPE(command) != DM_IOCTL)
1853 diff -NurpP --minimal linux-2.6.27.25/drivers/net/tun.c linux-2.6.27.25-vs2.3.0.36.6/drivers/net/tun.c
1854 --- linux-2.6.27.25/drivers/net/tun.c   2009-06-15 17:18:30.000000000 +0200
1855 +++ linux-2.6.27.25-vs2.3.0.36.6/drivers/net/tun.c      2009-02-22 22:58:32.000000000 +0100
1856 @@ -61,6 +61,7 @@
1857  #include <linux/crc32.h>
1858  #include <linux/nsproxy.h>
1859  #include <linux/virtio_net.h>
1860 +#include <linux/vs_network.h>
1861  #include <net/net_namespace.h>
1862  #include <net/netns/generic.h>
1863  
1864 @@ -93,6 +94,7 @@ struct tun_struct {
1865         int                     attached;
1866         uid_t                   owner;
1867         gid_t                   group;
1868 +       nid_t                   nid;
1869  
1870         wait_queue_head_t       read_wait;
1871         struct sk_buff_head     readq;
1872 @@ -681,6 +683,7 @@ static void tun_setup(struct net_device 
1873  
1874         tun->owner = -1;
1875         tun->group = -1;
1876 +       tun->nid = current->nid;
1877  
1878         dev->open = tun_net_open;
1879         dev->hard_start_xmit = tun_net_xmit;
1880 @@ -713,6 +716,9 @@ static int tun_set_iff(struct net *net, 
1881         tn = net_generic(net, tun_net_id);
1882         tun = tun_get_by_name(tn, ifr->ifr_name);
1883         if (tun) {
1884 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1885 +                       return -EPERM;
1886 +
1887                 if (tun->attached)
1888                         return -EBUSY;
1889  
1890 @@ -721,7 +727,7 @@ static int tun_set_iff(struct net *net, 
1891                       current->euid != tun->owner) ||
1892                      (tun->group != -1 &&
1893                       current->egid != tun->group)) &&
1894 -                    !capable(CAP_NET_ADMIN))
1895 +                    !cap_raised(current->cap_effective, CAP_NET_ADMIN))
1896                         return -EPERM;
1897         }
1898         else if (__dev_get_by_name(net, ifr->ifr_name))
1899 @@ -732,7 +738,7 @@ static int tun_set_iff(struct net *net, 
1900  
1901                 err = -EINVAL;
1902  
1903 -               if (!capable(CAP_NET_ADMIN))
1904 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1905                         return -EPERM;
1906  
1907                 /* Set dev type */
1908 @@ -972,6 +978,16 @@ static int tun_chr_ioctl(struct inode *i
1909                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1910                 break;
1911  
1912 +       case TUNSETNID:
1913 +               if (!capable(CAP_CONTEXT))
1914 +                       return -EPERM;
1915 +
1916 +               /* Set nid owner of the device */
1917 +               tun->nid = (nid_t) arg;
1918 +
1919 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1920 +               break;
1921 +
1922         case TUNSETLINK:
1923                 /* Only allow setting the type when the interface is down */
1924                 rtnl_lock();
1925 diff -NurpP --minimal linux-2.6.27.25/fs/attr.c linux-2.6.27.25-vs2.3.0.36.6/fs/attr.c
1926 --- linux-2.6.27.25/fs/attr.c   2008-10-13 14:52:05.000000000 +0200
1927 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/attr.c      2008-10-24 03:34:52.000000000 +0200
1928 @@ -14,6 +14,9 @@
1929  #include <linux/fcntl.h>
1930  #include <linux/quotaops.h>
1931  #include <linux/security.h>
1932 +#include <linux/proc_fs.h>
1933 +#include <linux/devpts_fs.h>
1934 +#include <linux/vs_tag.h>
1935  
1936  /* Taken over from the old code... */
1937  
1938 @@ -55,6 +58,10 @@ int inode_change_ok(struct inode *inode,
1939                 if (!is_owner_or_cap(inode))
1940                         goto error;
1941         }
1942 +
1943 +       if (dx_permission(inode, MAY_WRITE))
1944 +               goto error;
1945 +
1946  fine:
1947         retval = 0;
1948  error:
1949 @@ -78,6 +85,8 @@ int inode_setattr(struct inode * inode, 
1950                 inode->i_uid = attr->ia_uid;
1951         if (ia_valid & ATTR_GID)
1952                 inode->i_gid = attr->ia_gid;
1953 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1954 +               inode->i_tag = attr->ia_tag;
1955         if (ia_valid & ATTR_ATIME)
1956                 inode->i_atime = timespec_trunc(attr->ia_atime,
1957                                                 inode->i_sb->s_time_gran);
1958 @@ -172,7 +181,8 @@ int notify_change(struct dentry * dentry
1959                         error = security_inode_setattr(dentry, attr);
1960                 if (!error) {
1961                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
1962 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
1963 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
1964 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
1965                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
1966                         if (!error)
1967                                 error = inode_setattr(inode, attr);
1968 diff -NurpP --minimal linux-2.6.27.25/fs/binfmt_aout.c linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_aout.c
1969 --- linux-2.6.27.25/fs/binfmt_aout.c    2008-10-13 14:52:05.000000000 +0200
1970 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_aout.c       2008-10-13 14:54:20.000000000 +0200
1971 @@ -24,6 +24,7 @@
1972  #include <linux/binfmts.h>
1973  #include <linux/personality.h>
1974  #include <linux/init.h>
1975 +#include <linux/vs_memory.h>
1976  
1977  #include <asm/system.h>
1978  #include <asm/uaccess.h>
1979 diff -NurpP --minimal linux-2.6.27.25/fs/binfmt_elf.c linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_elf.c
1980 --- linux-2.6.27.25/fs/binfmt_elf.c     2009-06-15 17:18:31.000000000 +0200
1981 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_elf.c        2009-02-22 22:58:32.000000000 +0100
1982 @@ -38,6 +38,7 @@
1983  #include <linux/random.h>
1984  #include <linux/elf.h>
1985  #include <linux/utsname.h>
1986 +#include <linux/vs_memory.h>
1987  #include <asm/uaccess.h>
1988  #include <asm/param.h>
1989  #include <asm/page.h>
1990 diff -NurpP --minimal linux-2.6.27.25/fs/binfmt_flat.c linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_flat.c
1991 --- linux-2.6.27.25/fs/binfmt_flat.c    2008-10-13 14:52:05.000000000 +0200
1992 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_flat.c       2008-10-13 14:54:20.000000000 +0200
1993 @@ -35,6 +35,7 @@
1994  #include <linux/init.h>
1995  #include <linux/flat.h>
1996  #include <linux/syscalls.h>
1997 +#include <linux/vs_memory.h>
1998  
1999  #include <asm/byteorder.h>
2000  #include <asm/system.h>
2001 diff -NurpP --minimal linux-2.6.27.25/fs/binfmt_som.c linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_som.c
2002 --- linux-2.6.27.25/fs/binfmt_som.c     2008-10-13 14:52:05.000000000 +0200
2003 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/binfmt_som.c        2008-10-13 14:54:20.000000000 +0200
2004 @@ -28,6 +28,7 @@
2005  #include <linux/shm.h>
2006  #include <linux/personality.h>
2007  #include <linux/init.h>
2008 +#include <linux/vs_memory.h>
2009  
2010  #include <asm/uaccess.h>
2011  #include <asm/pgtable.h>
2012 diff -NurpP --minimal linux-2.6.27.25/fs/block_dev.c linux-2.6.27.25-vs2.3.0.36.6/fs/block_dev.c
2013 --- linux-2.6.27.25/fs/block_dev.c      2008-10-13 14:52:05.000000000 +0200
2014 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/block_dev.c 2008-10-13 14:54:20.000000000 +0200
2015 @@ -24,6 +24,7 @@
2016  #include <linux/uio.h>
2017  #include <linux/namei.h>
2018  #include <linux/log2.h>
2019 +#include <linux/vs_device.h>
2020  #include <asm/uaccess.h>
2021  #include "internal.h"
2022  
2023 @@ -389,6 +390,7 @@ struct block_device *bdget(dev_t dev)
2024                 bdev->bd_invalidated = 0;
2025                 inode->i_mode = S_IFBLK;
2026                 inode->i_rdev = dev;
2027 +               inode->i_mdev = dev;
2028                 inode->i_bdev = bdev;
2029                 inode->i_data.a_ops = &def_blk_aops;
2030                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2031 @@ -425,6 +427,11 @@ EXPORT_SYMBOL(bdput);
2032  static struct block_device *bd_acquire(struct inode *inode)
2033  {
2034         struct block_device *bdev;
2035 +       dev_t mdev;
2036 +
2037 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2038 +               return NULL;
2039 +       inode->i_mdev = mdev;
2040  
2041         spin_lock(&bdev_lock);
2042         bdev = inode->i_bdev;
2043 @@ -435,7 +442,7 @@ static struct block_device *bd_acquire(s
2044         }
2045         spin_unlock(&bdev_lock);
2046  
2047 -       bdev = bdget(inode->i_rdev);
2048 +       bdev = bdget(mdev);
2049         if (bdev) {
2050                 spin_lock(&bdev_lock);
2051                 if (!inode->i_bdev) {
2052 diff -NurpP --minimal linux-2.6.27.25/fs/char_dev.c linux-2.6.27.25-vs2.3.0.36.6/fs/char_dev.c
2053 --- linux-2.6.27.25/fs/char_dev.c       2008-10-13 14:52:05.000000000 +0200
2054 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/char_dev.c  2008-10-13 14:54:20.000000000 +0200
2055 @@ -21,6 +21,8 @@
2056  #include <linux/cdev.h>
2057  #include <linux/mutex.h>
2058  #include <linux/backing-dev.h>
2059 +#include <linux/vs_context.h>
2060 +#include <linux/vs_device.h>
2061  
2062  #ifdef CONFIG_KMOD
2063  #include <linux/kmod.h>
2064 @@ -361,14 +363,21 @@ static int chrdev_open(struct inode *ino
2065         struct cdev *p;
2066         struct cdev *new = NULL;
2067         int ret = 0;
2068 +       dev_t mdev;
2069 +
2070 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2071 +               return -EPERM;
2072 +       inode->i_mdev = mdev;
2073  
2074         spin_lock(&cdev_lock);
2075         p = inode->i_cdev;
2076         if (!p) {
2077                 struct kobject *kobj;
2078                 int idx;
2079 +
2080                 spin_unlock(&cdev_lock);
2081 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2082 +
2083 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2084                 if (!kobj)
2085                         return -ENXIO;
2086                 new = container_of(kobj, struct cdev, kobj);
2087 diff -NurpP --minimal linux-2.6.27.25/fs/dcache.c linux-2.6.27.25-vs2.3.0.36.6/fs/dcache.c
2088 --- linux-2.6.27.25/fs/dcache.c 2009-06-15 17:18:31.000000000 +0200
2089 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/dcache.c    2009-02-03 17:59:04.000000000 +0100
2090 @@ -32,6 +32,7 @@
2091  #include <linux/seqlock.h>
2092  #include <linux/swap.h>
2093  #include <linux/bootmem.h>
2094 +#include <linux/vs_limit.h>
2095  #include "internal.h"
2096  
2097  
2098 @@ -226,6 +227,8 @@ repeat:
2099                 return;
2100         }
2101  
2102 +       vx_dentry_dec(dentry);
2103 +
2104         /*
2105          * AV: ->d_delete() is _NOT_ allowed to block now.
2106          */
2107 @@ -317,6 +320,7 @@ static inline struct dentry * __dget_loc
2108  {
2109         atomic_inc(&dentry->d_count);
2110         dentry_lru_del_init(dentry);
2111 +       vx_dentry_inc(dentry);
2112         return dentry;
2113  }
2114  
2115 @@ -914,6 +918,9 @@ struct dentry *d_alloc(struct dentry * p
2116         struct dentry *dentry;
2117         char *dname;
2118  
2119 +       if (!vx_dentry_avail(1))
2120 +               return NULL;
2121 +
2122         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2123         if (!dentry)
2124                 return NULL;
2125 @@ -962,6 +969,7 @@ struct dentry *d_alloc(struct dentry * p
2126         if (parent)
2127                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2128         dentry_stat.nr_dentry++;
2129 +       vx_dentry_inc(dentry);
2130         spin_unlock(&dcache_lock);
2131  
2132         return dentry;
2133 @@ -1415,6 +1423,7 @@ struct dentry * __d_lookup(struct dentry
2134                 }
2135  
2136                 atomic_inc(&dentry->d_count);
2137 +               vx_dentry_inc(dentry);
2138                 found = dentry;
2139                 spin_unlock(&dentry->d_lock);
2140                 break;
2141 diff -NurpP --minimal linux-2.6.27.25/fs/devpts/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/devpts/inode.c
2142 --- linux-2.6.27.25/fs/devpts/inode.c   2008-10-13 14:52:05.000000000 +0200
2143 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/devpts/inode.c      2008-10-13 14:54:20.000000000 +0200
2144 @@ -19,15 +19,29 @@
2145  #include <linux/tty.h>
2146  #include <linux/mutex.h>
2147  #include <linux/idr.h>
2148 +#include <linux/magic.h>
2149  #include <linux/devpts_fs.h>
2150  #include <linux/parser.h>
2151  #include <linux/fsnotify.h>
2152  #include <linux/seq_file.h>
2153 -
2154 -#define DEVPTS_SUPER_MAGIC 0x1cd1
2155 +#include <linux/vs_base.h>
2156  
2157  #define DEVPTS_DEFAULT_MODE 0600
2158  
2159 +static int devpts_permission(struct inode *inode, int mask)
2160 +{
2161 +       int ret = -EACCES;
2162 +
2163 +       /* devpts is xid tagged */
2164 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2165 +               ret = generic_permission(inode, mask, NULL);
2166 +       return ret;
2167 +}
2168 +
2169 +static struct inode_operations devpts_file_inode_operations = {
2170 +       .permission     = devpts_permission,
2171 +};
2172 +
2173  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2174  static DEFINE_IDA(allocated_ptys);
2175  static DEFINE_MUTEX(allocated_ptys_lock);
2176 @@ -112,6 +126,25 @@ static int devpts_show_options(struct se
2177         return 0;
2178  }
2179  
2180 +static int devpts_filter(struct dentry *de)
2181 +{
2182 +       /* devpts is xid tagged */
2183 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2184 +}
2185 +
2186 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2187 +{
2188 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2189 +}
2190 +
2191 +static struct file_operations devpts_dir_operations = {
2192 +       .open           = dcache_dir_open,
2193 +       .release        = dcache_dir_close,
2194 +       .llseek         = dcache_dir_lseek,
2195 +       .read           = generic_read_dir,
2196 +       .readdir        = devpts_readdir,
2197 +};
2198 +
2199  static const struct super_operations devpts_sops = {
2200         .statfs         = simple_statfs,
2201         .remount_fs     = devpts_remount,
2202 @@ -138,8 +171,10 @@ devpts_fill_super(struct super_block *s,
2203         inode->i_uid = inode->i_gid = 0;
2204         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2205         inode->i_op = &simple_dir_inode_operations;
2206 -       inode->i_fop = &simple_dir_operations;
2207 +       inode->i_fop = &devpts_dir_operations;
2208         inode->i_nlink = 2;
2209 +       /* devpts is xid tagged */
2210 +       inode->i_tag = (tag_t)vx_current_xid();
2211  
2212         devpts_root = s->s_root = d_alloc_root(inode);
2213         if (s->s_root)
2214 @@ -232,6 +267,9 @@ int devpts_pty_new(struct tty_struct *tt
2215         inode->i_gid = config.setgid ? config.gid : current->fsgid;
2216         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2217         init_special_inode(inode, S_IFCHR|config.mode, device);
2218 +       /* devpts is xid tagged */
2219 +       inode->i_tag = (tag_t)vx_current_xid();
2220 +       inode->i_op = &devpts_file_inode_operations;
2221         inode->i_private = tty;
2222  
2223         dentry = get_node(number);
2224 diff -NurpP --minimal linux-2.6.27.25/fs/exec.c linux-2.6.27.25-vs2.3.0.36.6/fs/exec.c
2225 --- linux-2.6.27.25/fs/exec.c   2009-06-15 17:18:31.000000000 +0200
2226 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/exec.c      2009-05-15 22:57:04.000000000 +0200
2227 @@ -263,7 +263,9 @@ static int __bprm_mm_init(struct linux_b
2228                 goto err;
2229         }
2230  
2231 -       mm->stack_vm = mm->total_vm = 1;
2232 +       mm->total_vm = 0;
2233 +       vx_vmpages_inc(mm);
2234 +       mm->stack_vm = 1;
2235         up_write(&mm->mmap_sem);
2236  
2237         bprm->p = vma->vm_end - sizeof(void *);
2238 @@ -1459,7 +1461,7 @@ static int format_corename(char *corenam
2239                         /* UNIX time of coredump */
2240                         case 't': {
2241                                 struct timeval tv;
2242 -                               do_gettimeofday(&tv);
2243 +                               vx_gettimeofday(&tv);
2244                                 rc = snprintf(out_ptr, out_end - out_ptr,
2245                                               "%lu", tv.tv_sec);
2246                                 if (rc > out_end - out_ptr)
2247 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/balloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/balloc.c
2248 --- linux-2.6.27.25/fs/ext2/balloc.c    2009-06-15 17:18:31.000000000 +0200
2249 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/balloc.c       2009-02-03 17:59:04.000000000 +0100
2250 @@ -16,6 +16,8 @@
2251  #include <linux/sched.h>
2252  #include <linux/buffer_head.h>
2253  #include <linux/capability.h>
2254 +#include <linux/vs_dlimit.h>
2255 +#include <linux/vs_tag.h>
2256  
2257  /*
2258   * balloc.c contains the blocks allocation and deallocation routines
2259 @@ -569,6 +571,7 @@ do_more:
2260         }
2261  error_return:
2262         brelse(bitmap_bh);
2263 +       DLIMIT_FREE_BLOCK(inode, freed);
2264         release_blocks(sb, freed);
2265         DQUOT_FREE_BLOCK(inode, freed);
2266  }
2267 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2268                         start = 0;
2269                 end = EXT2_BLOCKS_PER_GROUP(sb);
2270         }
2271 -
2272         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2273  
2274  repeat:
2275 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2276                 *errp = -EDQUOT;
2277                 return 0;
2278         }
2279 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2280 +               *errp = -ENOSPC;
2281 +               DQUOT_FREE_BLOCK(inode, num);
2282 +               return 0;
2283 +       }
2284  
2285         sbi = EXT2_SB(sb);
2286         es = EXT2_SB(sb)->s_es;
2287 @@ -1409,6 +1416,7 @@ allocated:
2288  
2289         *errp = 0;
2290         brelse(bitmap_bh);
2291 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2292         DQUOT_FREE_BLOCK(inode, *count-num);
2293         *count = num;
2294         return ret_block;
2295 @@ -1419,8 +1427,10 @@ out:
2296         /*
2297          * Undo the block allocation
2298          */
2299 -       if (!performed_allocation)
2300 +       if (!performed_allocation) {
2301 +               DLIMIT_FREE_BLOCK(inode, *count);
2302                 DQUOT_FREE_BLOCK(inode, *count);
2303 +       }
2304         brelse(bitmap_bh);
2305         return 0;
2306  }
2307 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/ext2.h linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/ext2.h
2308 --- linux-2.6.27.25/fs/ext2/ext2.h      2008-07-13 23:51:29.000000000 +0200
2309 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/ext2.h 2008-10-13 14:54:20.000000000 +0200
2310 @@ -168,6 +168,7 @@ extern const struct file_operations ext2
2311  extern const struct address_space_operations ext2_aops;
2312  extern const struct address_space_operations ext2_aops_xip;
2313  extern const struct address_space_operations ext2_nobh_aops;
2314 +extern int ext2_sync_flags(struct inode *inode);
2315  
2316  /* namei.c */
2317  extern const struct inode_operations ext2_dir_inode_operations;
2318 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/file.c
2319 --- linux-2.6.27.25/fs/ext2/file.c      2008-07-13 23:51:29.000000000 +0200
2320 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/file.c 2008-10-13 14:54:20.000000000 +0200
2321 @@ -86,4 +86,5 @@ const struct inode_operations ext2_file_
2322  #endif
2323         .setattr        = ext2_setattr,
2324         .permission     = ext2_permission,
2325 +       .sync_flags     = ext2_sync_flags,
2326  };
2327 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/ialloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/ialloc.c
2328 --- linux-2.6.27.25/fs/ext2/ialloc.c    2008-07-13 23:51:29.000000000 +0200
2329 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/ialloc.c       2008-10-13 14:54:20.000000000 +0200
2330 @@ -17,6 +17,8 @@
2331  #include <linux/backing-dev.h>
2332  #include <linux/buffer_head.h>
2333  #include <linux/random.h>
2334 +#include <linux/vs_dlimit.h>
2335 +#include <linux/vs_tag.h>
2336  #include "ext2.h"
2337  #include "xattr.h"
2338  #include "acl.h"
2339 @@ -123,6 +125,7 @@ void ext2_free_inode (struct inode * ino
2340                 ext2_xattr_delete_inode(inode);
2341                 DQUOT_FREE_INODE(inode);
2342                 DQUOT_DROP(inode);
2343 +               DLIMIT_FREE_INODE(inode);
2344         }
2345  
2346         es = EXT2_SB(sb)->s_es;
2347 @@ -454,6 +457,11 @@ struct inode *ext2_new_inode(struct inod
2348         if (!inode)
2349                 return ERR_PTR(-ENOMEM);
2350  
2351 +       inode->i_tag = dx_current_fstag(sb);
2352 +       if (DLIMIT_ALLOC_INODE(inode)) {
2353 +               err = -ENOSPC;
2354 +               goto fail_dlim;
2355 +       }
2356         ei = EXT2_I(inode);
2357         sbi = EXT2_SB(sb);
2358         es = sbi->s_es;
2359 @@ -565,7 +573,8 @@ got:
2360         inode->i_blocks = 0;
2361         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
2362         memset(ei->i_data, 0, sizeof(ei->i_data));
2363 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
2364 +       ei->i_flags = EXT2_I(dir)->i_flags &
2365 +               ~(EXT2_BTREE_FL|EXT2_IXUNLINK_FL|EXT2_BARRIER_FL);
2366         if (S_ISLNK(mode))
2367                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
2368         /* dirsync is only applied to directories */
2369 @@ -610,12 +619,15 @@ fail_free_drop:
2370  
2371  fail_drop:
2372         DQUOT_DROP(inode);
2373 +       DLIMIT_FREE_INODE(inode);
2374         inode->i_flags |= S_NOQUOTA;
2375         inode->i_nlink = 0;
2376         iput(inode);
2377         return ERR_PTR(err);
2378  
2379  fail:
2380 +       DLIMIT_FREE_INODE(inode);
2381 +fail_dlim:
2382         make_bad_inode(inode);
2383         iput(inode);
2384         return ERR_PTR(err);
2385 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/inode.c
2386 --- linux-2.6.27.25/fs/ext2/inode.c     2008-10-13 14:52:05.000000000 +0200
2387 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/inode.c        2008-10-13 14:54:20.000000000 +0200
2388 @@ -31,6 +31,7 @@
2389  #include <linux/writeback.h>
2390  #include <linux/buffer_head.h>
2391  #include <linux/mpage.h>
2392 +#include <linux/vs_tag.h>
2393  #include "ext2.h"
2394  #include "acl.h"
2395  #include "xip.h"
2396 @@ -1011,7 +1012,7 @@ void ext2_truncate(struct inode *inode)
2397                 return;
2398         if (ext2_inode_is_fast_symlink(inode))
2399                 return;
2400 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2401 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2402                 return;
2403  
2404         blocksize = inode->i_sb->s_blocksize;
2405 @@ -1149,38 +1150,72 @@ void ext2_set_inode_flags(struct inode *
2406  {
2407         unsigned int flags = EXT2_I(inode)->i_flags;
2408  
2409 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2410 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2411 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2412 +
2413 +
2414 +       if (flags & EXT2_IMMUTABLE_FL)
2415 +               inode->i_flags |= S_IMMUTABLE;
2416 +       if (flags & EXT2_IXUNLINK_FL)
2417 +               inode->i_flags |= S_IXUNLINK;
2418 +
2419         if (flags & EXT2_SYNC_FL)
2420                 inode->i_flags |= S_SYNC;
2421         if (flags & EXT2_APPEND_FL)
2422                 inode->i_flags |= S_APPEND;
2423 -       if (flags & EXT2_IMMUTABLE_FL)
2424 -               inode->i_flags |= S_IMMUTABLE;
2425         if (flags & EXT2_NOATIME_FL)
2426                 inode->i_flags |= S_NOATIME;
2427         if (flags & EXT2_DIRSYNC_FL)
2428                 inode->i_flags |= S_DIRSYNC;
2429 +
2430 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2431 +
2432 +       if (flags & EXT2_BARRIER_FL)
2433 +               inode->i_vflags |= V_BARRIER;
2434 +       if (flags & EXT2_COW_FL)
2435 +               inode->i_vflags |= V_COW;
2436  }
2437  
2438  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2439  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2440  {
2441         unsigned int flags = ei->vfs_inode.i_flags;
2442 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2443 +
2444 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2445 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2446 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2447 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2448 +
2449 +       if (flags & S_IMMUTABLE)
2450 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2451 +       if (flags & S_IXUNLINK)
2452 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2453  
2454 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2455 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2456         if (flags & S_SYNC)
2457                 ei->i_flags |= EXT2_SYNC_FL;
2458         if (flags & S_APPEND)
2459                 ei->i_flags |= EXT2_APPEND_FL;
2460 -       if (flags & S_IMMUTABLE)
2461 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2462         if (flags & S_NOATIME)
2463                 ei->i_flags |= EXT2_NOATIME_FL;
2464         if (flags & S_DIRSYNC)
2465                 ei->i_flags |= EXT2_DIRSYNC_FL;
2466 +
2467 +       if (vflags & V_BARRIER)
2468 +               ei->i_flags |= EXT2_BARRIER_FL;
2469 +       if (vflags & V_COW)
2470 +               ei->i_flags |= EXT2_COW_FL;
2471  }
2472  
2473 +int ext2_sync_flags(struct inode *inode)
2474 +{
2475 +       ext2_get_inode_flags(EXT2_I(inode));
2476 +       inode->i_ctime = CURRENT_TIME;
2477 +       mark_inode_dirty(inode);
2478 +       return 0;
2479 +}
2480 +
2481 +
2482  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2483  {
2484         struct ext2_inode_info *ei;
2485 @@ -1188,6 +1223,8 @@ struct inode *ext2_iget (struct super_bl
2486         struct ext2_inode *raw_inode;
2487         struct inode *inode;
2488         long ret = -EIO;
2489 +       uid_t uid;
2490 +       gid_t gid;
2491         int n;
2492  
2493         inode = iget_locked(sb, ino);
2494 @@ -1210,12 +1247,17 @@ struct inode *ext2_iget (struct super_bl
2495         }
2496  
2497         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2498 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2499 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2500 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2501 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2502         if (!(test_opt (inode->i_sb, NO_UID32))) {
2503 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2504 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2505 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2506 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2507         }
2508 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2509 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2510 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2511 +               le16_to_cpu(raw_inode->i_raw_tag));
2512 +
2513         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2514         inode->i_size = le32_to_cpu(raw_inode->i_size);
2515         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2516 @@ -1311,8 +1353,8 @@ static int ext2_update_inode(struct inod
2517         struct ext2_inode_info *ei = EXT2_I(inode);
2518         struct super_block *sb = inode->i_sb;
2519         ino_t ino = inode->i_ino;
2520 -       uid_t uid = inode->i_uid;
2521 -       gid_t gid = inode->i_gid;
2522 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2523 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2524         struct buffer_head * bh;
2525         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2526         int n;
2527 @@ -1348,6 +1390,9 @@ static int ext2_update_inode(struct inod
2528                 raw_inode->i_uid_high = 0;
2529                 raw_inode->i_gid_high = 0;
2530         }
2531 +#ifdef CONFIG_TAGGING_INTERN
2532 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2533 +#endif
2534         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2535         raw_inode->i_size = cpu_to_le32(inode->i_size);
2536         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2537 @@ -1434,7 +1479,8 @@ int ext2_setattr(struct dentry *dentry, 
2538         if (error)
2539                 return error;
2540         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2541 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2542 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2543 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2544                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2545                 if (error)
2546                         return error;
2547 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/ioctl.c
2548 --- linux-2.6.27.25/fs/ext2/ioctl.c     2008-07-13 23:51:29.000000000 +0200
2549 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/ioctl.c        2008-10-13 14:54:20.000000000 +0200
2550 @@ -14,6 +14,7 @@
2551  #include <linux/compat.h>
2552  #include <linux/mount.h>
2553  #include <linux/smp_lock.h>
2554 +#include <linux/mount.h>
2555  #include <asm/current.h>
2556  #include <asm/uaccess.h>
2557  
2558 @@ -53,6 +54,11 @@ long ext2_ioctl(struct file *filp, unsig
2559                 if (!S_ISDIR(inode->i_mode))
2560                         flags &= ~EXT2_DIRSYNC_FL;
2561  
2562 +               if (IS_BARRIER(inode)) {
2563 +                       vxwprintk_task(1, "messing with the barrier.");
2564 +                       return -EACCES;
2565 +               }
2566 +
2567                 mutex_lock(&inode->i_mutex);
2568                 /* Is it quota file? Do not allow user to mess with it */
2569                 if (IS_NOQUOTA(inode)) {
2570 @@ -68,7 +74,9 @@ long ext2_ioctl(struct file *filp, unsig
2571                  *
2572                  * This test looks nicer. Thanks to Pauline Middelink
2573                  */
2574 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2575 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2576 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2577 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2578                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2579                                 mutex_unlock(&inode->i_mutex);
2580                                 ret = -EPERM;
2581 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/namei.c
2582 --- linux-2.6.27.25/fs/ext2/namei.c     2008-07-13 23:51:29.000000000 +0200
2583 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/namei.c        2008-10-13 14:54:20.000000000 +0200
2584 @@ -31,6 +31,7 @@
2585   */
2586  
2587  #include <linux/pagemap.h>
2588 +#include <linux/vs_tag.h>
2589  #include "ext2.h"
2590  #include "xattr.h"
2591  #include "acl.h"
2592 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
2593                 inode = ext2_iget(dir->i_sb, ino);
2594                 if (IS_ERR(inode))
2595                         return ERR_CAST(inode);
2596 +               dx_propagate_tag(nd, inode);
2597         }
2598         return d_splice_alias(inode, dentry);
2599  }
2600 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
2601  #endif
2602         .setattr        = ext2_setattr,
2603         .permission     = ext2_permission,
2604 +       .sync_flags     = ext2_sync_flags,
2605  };
2606  
2607  const struct inode_operations ext2_special_inode_operations = {
2608 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
2609  #endif
2610         .setattr        = ext2_setattr,
2611         .permission     = ext2_permission,
2612 +       .sync_flags     = ext2_sync_flags,
2613  };
2614 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/super.c
2615 --- linux-2.6.27.25/fs/ext2/super.c     2009-06-15 17:18:31.000000000 +0200
2616 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/super.c        2009-02-22 22:58:32.000000000 +0100
2617 @@ -390,7 +390,8 @@ enum {
2618         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2619         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2620         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2621 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2622 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2623 +       Opt_tag, Opt_notag, Opt_tagid
2624  };
2625  
2626  static match_table_t tokens = {
2627 @@ -418,6 +419,9 @@ static match_table_t tokens = {
2628         {Opt_acl, "acl"},
2629         {Opt_noacl, "noacl"},
2630         {Opt_xip, "xip"},
2631 +       {Opt_tag, "tag"},
2632 +       {Opt_notag, "notag"},
2633 +       {Opt_tagid, "tagid=%u"},
2634         {Opt_grpquota, "grpquota"},
2635         {Opt_ignore, "noquota"},
2636         {Opt_quota, "quota"},
2637 @@ -488,6 +492,20 @@ static int parse_options (char * options
2638                 case Opt_nouid32:
2639                         set_opt (sbi->s_mount_opt, NO_UID32);
2640                         break;
2641 +#ifndef CONFIG_TAGGING_NONE
2642 +               case Opt_tag:
2643 +                       set_opt (sbi->s_mount_opt, TAGGED);
2644 +                       break;
2645 +               case Opt_notag:
2646 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2647 +                       break;
2648 +#endif
2649 +#ifdef CONFIG_PROPAGATE
2650 +               case Opt_tagid:
2651 +                       /* use args[0] */
2652 +                       set_opt (sbi->s_mount_opt, TAGGED);
2653 +                       break;
2654 +#endif
2655                 case Opt_nocheck:
2656                         clear_opt (sbi->s_mount_opt, CHECK);
2657                         break;
2658 @@ -830,6 +848,8 @@ static int ext2_fill_super(struct super_
2659         if (!parse_options ((char *) data, sbi))
2660                 goto failed_mount;
2661  
2662 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2663 +               sb->s_flags |= MS_TAGGED;
2664         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2665                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2666                  MS_POSIXACL : 0);
2667 @@ -1162,6 +1182,13 @@ static int ext2_remount (struct super_bl
2668                 goto restore_opts;
2669         }
2670  
2671 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2672 +               !(sb->s_flags & MS_TAGGED)) {
2673 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2674 +                      sb->s_id);
2675 +               return -EINVAL;
2676 +       }
2677 +
2678         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2679                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2680  
2681 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/symlink.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/symlink.c
2682 --- linux-2.6.27.25/fs/ext2/symlink.c   2008-07-13 23:51:29.000000000 +0200
2683 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/symlink.c      2008-10-13 14:54:20.000000000 +0200
2684 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
2685         .listxattr      = ext2_listxattr,
2686         .removexattr    = generic_removexattr,
2687  #endif
2688 +       .sync_flags     = ext2_sync_flags,
2689  };
2690   
2691  const struct inode_operations ext2_fast_symlink_inode_operations = {
2692 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
2693         .listxattr      = ext2_listxattr,
2694         .removexattr    = generic_removexattr,
2695  #endif
2696 +       .sync_flags     = ext2_sync_flags,
2697  };
2698 diff -NurpP --minimal linux-2.6.27.25/fs/ext2/xattr.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/xattr.c
2699 --- linux-2.6.27.25/fs/ext2/xattr.c     2008-07-13 23:51:29.000000000 +0200
2700 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext2/xattr.c        2008-10-13 14:54:20.000000000 +0200
2701 @@ -60,6 +60,7 @@
2702  #include <linux/mbcache.h>
2703  #include <linux/quotaops.h>
2704  #include <linux/rwsem.h>
2705 +#include <linux/vs_dlimit.h>
2706  #include "ext2.h"
2707  #include "xattr.h"
2708  #include "acl.h"
2709 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
2710                                    the inode.  */
2711                                 ea_bdebug(new_bh, "reusing block");
2712  
2713 +                               error = -ENOSPC;
2714 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
2715 +                                       goto cleanup;
2716                                 error = -EDQUOT;
2717                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2718 +                                       DLIMIT_FREE_BLOCK(inode, 1);
2719                                         unlock_buffer(new_bh);
2720                                         goto cleanup;
2721                                 }
2722 @@ -731,6 +736,7 @@ ext2_xattr_set2(struct inode *inode, str
2723                         le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
2724                         if (ce)
2725                                 mb_cache_entry_release(ce);
2726 +                       DLIMIT_FREE_BLOCK(inode, 1);
2727                         DQUOT_FREE_BLOCK(inode, 1);
2728                         mark_buffer_dirty(old_bh);
2729                         ea_bdebug(old_bh, "refcount now=%d",
2730 @@ -794,6 +800,7 @@ ext2_xattr_delete_inode(struct inode *in
2731                 mark_buffer_dirty(bh);
2732                 if (IS_SYNC(inode))
2733                         sync_dirty_buffer(bh);
2734 +               DLIMIT_FREE_BLOCK(inode, 1);
2735                 DQUOT_FREE_BLOCK(inode, 1);
2736         }
2737         EXT2_I(inode)->i_file_acl = 0;
2738 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/balloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/balloc.c
2739 --- linux-2.6.27.25/fs/ext3/balloc.c    2009-06-15 17:18:31.000000000 +0200
2740 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/balloc.c       2009-02-03 17:59:04.000000000 +0100
2741 @@ -19,6 +19,8 @@
2742  #include <linux/ext3_jbd.h>
2743  #include <linux/quotaops.h>
2744  #include <linux/buffer_head.h>
2745 +#include <linux/vs_dlimit.h>
2746 +#include <linux/vs_tag.h>
2747  
2748  /*
2749   * balloc.c contains the blocks allocation and deallocation routines
2750 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2751                 return;
2752         }
2753         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2754 -       if (dquot_freed_blocks)
2755 +       if (dquot_freed_blocks) {
2756 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2757                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2758 +       }
2759         return;
2760  }
2761  
2762 @@ -1415,18 +1419,33 @@ out:
2763   *
2764   * Check if filesystem has at least 1 free block available for allocation.
2765   */
2766 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2767 +static int ext3_has_free_blocks(struct super_block *sb)
2768  {
2769 -       ext3_fsblk_t free_blocks, root_blocks;
2770 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2771 +       unsigned long long free_blocks, root_blocks;
2772 +       int cond;
2773  
2774         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2775         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2776 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2777 +
2778 +       vxdprintk(VXD_CBIT(dlim, 3),
2779 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2780 +               sb, free_blocks, root_blocks);
2781 +
2782 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2783 +
2784 +       cond = (free_blocks < root_blocks + 1 &&
2785 +               !capable(CAP_SYS_RESOURCE) &&
2786                 sbi->s_resuid != current->fsuid &&
2787 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2788 -               return 0;
2789 -       }
2790 -       return 1;
2791 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2792 +
2793 +       vxdprintk(VXD_CBIT(dlim, 3),
2794 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2795 +               sb, free_blocks, root_blocks,
2796 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2797 +               sbi->s_resuid, current->fsuid, cond?0:1);
2798 +
2799 +       return (cond ? 0 : 1);
2800  }
2801  
2802  /**
2803 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2804   */
2805  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2806  {
2807 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2808 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2809                 return 0;
2810  
2811         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2812 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2813                 *errp = -EDQUOT;
2814                 return 0;
2815         }
2816 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2817 +           goto out_dlimit;
2818  
2819         sbi = EXT3_SB(sb);
2820         es = EXT3_SB(sb)->s_es;
2821 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2822         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2823                 my_rsv = &block_i->rsv_window_node;
2824  
2825 -       if (!ext3_has_free_blocks(sbi)) {
2826 +       if (!ext3_has_free_blocks(sb)) {
2827                 *errp = -ENOSPC;
2828                 goto out;
2829         }
2830 @@ -1715,12 +1736,16 @@ allocated:
2831         *errp = 0;
2832         brelse(bitmap_bh);
2833         DQUOT_FREE_BLOCK(inode, *count-num);
2834 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2835         *count = num;
2836         return ret_block;
2837  
2838  io_error:
2839         *errp = -EIO;
2840  out:
2841 +       if (!performed_allocation)
2842 +               DLIMIT_FREE_BLOCK(inode, *count);
2843 +out_dlimit:
2844         if (fatal) {
2845                 *errp = fatal;
2846                 ext3_std_error(sb, fatal);
2847 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/file.c
2848 --- linux-2.6.27.25/fs/ext3/file.c      2008-07-13 23:51:29.000000000 +0200
2849 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/file.c 2008-10-13 14:54:20.000000000 +0200
2850 @@ -134,5 +134,6 @@ const struct inode_operations ext3_file_
2851         .removexattr    = generic_removexattr,
2852  #endif
2853         .permission     = ext3_permission,
2854 +       .sync_flags     = ext3_sync_flags,
2855  };
2856  
2857 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/ialloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/ialloc.c
2858 --- linux-2.6.27.25/fs/ext3/ialloc.c    2008-10-13 14:52:05.000000000 +0200
2859 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/ialloc.c       2008-10-13 14:54:20.000000000 +0200
2860 @@ -23,6 +23,8 @@
2861  #include <linux/buffer_head.h>
2862  #include <linux/random.h>
2863  #include <linux/bitops.h>
2864 +#include <linux/vs_dlimit.h>
2865 +#include <linux/vs_tag.h>
2866  
2867  #include <asm/byteorder.h>
2868  
2869 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
2870         ext3_xattr_delete_inode(handle, inode);
2871         DQUOT_FREE_INODE(inode);
2872         DQUOT_DROP(inode);
2873 +       DLIMIT_FREE_INODE(inode);
2874  
2875         is_directory = S_ISDIR(inode->i_mode);
2876  
2877 @@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
2878         inode = new_inode(sb);
2879         if (!inode)
2880                 return ERR_PTR(-ENOMEM);
2881 +
2882 +       inode->i_tag = dx_current_fstag(sb);
2883 +       if (DLIMIT_ALLOC_INODE(inode)) {
2884 +               err = -ENOSPC;
2885 +               goto out_dlimit;
2886 +       }
2887         ei = EXT3_I(inode);
2888  
2889         sbi = EXT3_SB(sb);
2890 @@ -559,7 +568,8 @@ got:
2891         ei->i_dir_start_lookup = 0;
2892         ei->i_disksize = 0;
2893  
2894 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
2895 +       ei->i_flags = EXT3_I(dir)->i_flags &
2896 +               ~(EXT3_INDEX_FL|EXT3_IXUNLINK_FL|EXT3_BARRIER_FL);
2897         if (S_ISLNK(mode))
2898                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
2899         /* dirsync only applies to directories */
2900 @@ -614,6 +624,8 @@ got:
2901  fail:
2902         ext3_std_error(sb, err);
2903  out:
2904 +       DLIMIT_FREE_INODE(inode);
2905 +out_dlimit:
2906         iput(inode);
2907         ret = ERR_PTR(err);
2908  really_out:
2909 @@ -625,6 +637,7 @@ fail_free_drop:
2910  
2911  fail_drop:
2912         DQUOT_DROP(inode);
2913 +       DLIMIT_FREE_INODE(inode);
2914         inode->i_flags |= S_NOQUOTA;
2915         inode->i_nlink = 0;
2916         iput(inode);
2917 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/inode.c
2918 --- linux-2.6.27.25/fs/ext3/inode.c     2009-06-15 17:18:31.000000000 +0200
2919 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/inode.c        2009-02-03 17:59:04.000000000 +0100
2920 @@ -36,6 +36,7 @@
2921  #include <linux/mpage.h>
2922  #include <linux/uio.h>
2923  #include <linux/bio.h>
2924 +#include <linux/vs_tag.h>
2925  #include "xattr.h"
2926  #include "acl.h"
2927  
2928 @@ -2272,7 +2273,7 @@ static void ext3_free_branches(handle_t 
2929  
2930  int ext3_can_truncate(struct inode *inode)
2931  {
2932 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2933 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2934                 return 0;
2935         if (S_ISREG(inode->i_mode))
2936                 return 1;
2937 @@ -2646,36 +2647,84 @@ void ext3_set_inode_flags(struct inode *
2938  {
2939         unsigned int flags = EXT3_I(inode)->i_flags;
2940  
2941 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2942 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2943 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2944 +
2945 +       if (flags & EXT3_IMMUTABLE_FL)
2946 +               inode->i_flags |= S_IMMUTABLE;
2947 +       if (flags & EXT3_IXUNLINK_FL)
2948 +               inode->i_flags |= S_IXUNLINK;
2949 +
2950         if (flags & EXT3_SYNC_FL)
2951                 inode->i_flags |= S_SYNC;
2952         if (flags & EXT3_APPEND_FL)
2953                 inode->i_flags |= S_APPEND;
2954 -       if (flags & EXT3_IMMUTABLE_FL)
2955 -               inode->i_flags |= S_IMMUTABLE;
2956         if (flags & EXT3_NOATIME_FL)
2957                 inode->i_flags |= S_NOATIME;
2958         if (flags & EXT3_DIRSYNC_FL)
2959                 inode->i_flags |= S_DIRSYNC;
2960 +
2961 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2962 +
2963 +       if (flags & EXT3_BARRIER_FL)
2964 +               inode->i_vflags |= V_BARRIER;
2965 +       if (flags & EXT3_COW_FL)
2966 +               inode->i_vflags |= V_COW;
2967  }
2968  
2969  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2970  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2971  {
2972         unsigned int flags = ei->vfs_inode.i_flags;
2973 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2974 +
2975 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2976 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2977 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2978 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2979 +
2980 +       if (flags & S_IMMUTABLE)
2981 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2982 +       if (flags & S_IXUNLINK)
2983 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2984  
2985 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2986 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2987         if (flags & S_SYNC)
2988                 ei->i_flags |= EXT3_SYNC_FL;
2989         if (flags & S_APPEND)
2990                 ei->i_flags |= EXT3_APPEND_FL;
2991 -       if (flags & S_IMMUTABLE)
2992 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2993         if (flags & S_NOATIME)
2994                 ei->i_flags |= EXT3_NOATIME_FL;
2995         if (flags & S_DIRSYNC)
2996                 ei->i_flags |= EXT3_DIRSYNC_FL;
2997 +
2998 +       if (vflags & V_BARRIER)
2999 +               ei->i_flags |= EXT3_BARRIER_FL;
3000 +       if (vflags & V_COW)
3001 +               ei->i_flags |= EXT3_COW_FL;
3002 +}
3003 +
3004 +int ext3_sync_flags(struct inode *inode)
3005 +{
3006 +       struct ext3_iloc iloc;
3007 +       handle_t *handle;
3008 +       int err;
3009 +
3010 +       handle = ext3_journal_start(inode, 1);
3011 +       if (IS_ERR(handle))
3012 +               return PTR_ERR(handle);
3013 +       if (IS_SYNC(inode))
3014 +               handle->h_sync = 1;
3015 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3016 +       if (err)
3017 +               goto flags_err;
3018 +
3019 +       ext3_get_inode_flags(EXT3_I(inode));
3020 +       inode->i_ctime = CURRENT_TIME;
3021 +
3022 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3023 +flags_err:
3024 +       ext3_journal_stop(handle);
3025 +       return err;
3026  }
3027  
3028  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3029 @@ -2687,6 +2736,8 @@ struct inode *ext3_iget(struct super_blo
3030         struct inode *inode;
3031         long ret;
3032         int block;
3033 +       uid_t uid;
3034 +       gid_t gid;
3035  
3036         inode = iget_locked(sb, ino);
3037         if (!inode)
3038 @@ -2707,12 +2758,17 @@ struct inode *ext3_iget(struct super_blo
3039         bh = iloc.bh;
3040         raw_inode = ext3_raw_inode(&iloc);
3041         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3042 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3043 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3044 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3045 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3046         if(!(test_opt (inode->i_sb, NO_UID32))) {
3047 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3048 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3049 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3050 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3051         }
3052 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3053 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3054 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3055 +               le16_to_cpu(raw_inode->i_raw_tag));
3056 +
3057         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3058         inode->i_size = le32_to_cpu(raw_inode->i_size);
3059         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3060 @@ -2841,6 +2897,8 @@ static int ext3_do_update_inode(handle_t
3061         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3062         struct ext3_inode_info *ei = EXT3_I(inode);
3063         struct buffer_head *bh = iloc->bh;
3064 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3065 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3066         int err = 0, rc, block;
3067  
3068         /* For fields not not tracking in the in-memory inode,
3069 @@ -2851,29 +2909,32 @@ static int ext3_do_update_inode(handle_t
3070         ext3_get_inode_flags(ei);
3071         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3072         if(!(test_opt(inode->i_sb, NO_UID32))) {
3073 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3074 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3075 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3076 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3077  /*
3078   * Fix up interoperability with old kernels. Otherwise, old inodes get
3079   * re-used with the upper 16 bits of the uid/gid intact
3080   */
3081                 if(!ei->i_dtime) {
3082                         raw_inode->i_uid_high =
3083 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3084 +                               cpu_to_le16(high_16_bits(uid));
3085                         raw_inode->i_gid_high =
3086 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3087 +                               cpu_to_le16(high_16_bits(gid));
3088                 } else {
3089                         raw_inode->i_uid_high = 0;
3090                         raw_inode->i_gid_high = 0;
3091                 }
3092         } else {
3093                 raw_inode->i_uid_low =
3094 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3095 +                       cpu_to_le16(fs_high2lowuid(uid));
3096                 raw_inode->i_gid_low =
3097 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3098 +                       cpu_to_le16(fs_high2lowgid(gid));
3099                 raw_inode->i_uid_high = 0;
3100                 raw_inode->i_gid_high = 0;
3101         }
3102 +#ifdef CONFIG_TAGGING_INTERN
3103 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3104 +#endif
3105         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3106         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3107         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3108 @@ -3026,7 +3087,8 @@ int ext3_setattr(struct dentry *dentry, 
3109                 return error;
3110  
3111         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3112 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3113 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3114 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3115                 handle_t *handle;
3116  
3117                 /* (user+group)*(old+new) structure, inode write (sb,
3118 @@ -3048,6 +3110,8 @@ int ext3_setattr(struct dentry *dentry, 
3119                         inode->i_uid = attr->ia_uid;
3120                 if (attr->ia_valid & ATTR_GID)
3121                         inode->i_gid = attr->ia_gid;
3122 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3123 +                       inode->i_tag = attr->ia_tag;
3124                 error = ext3_mark_inode_dirty(handle, inode);
3125                 ext3_journal_stop(handle);
3126         }
3127 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/ioctl.c
3128 --- linux-2.6.27.25/fs/ext3/ioctl.c     2008-07-13 23:51:29.000000000 +0200
3129 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/ioctl.c        2008-10-13 14:54:20.000000000 +0200
3130 @@ -8,6 +8,7 @@
3131   */
3132  
3133  #include <linux/fs.h>
3134 +#include <linux/mount.h>
3135  #include <linux/jbd.h>
3136  #include <linux/capability.h>
3137  #include <linux/ext3_fs.h>
3138 @@ -16,6 +17,7 @@
3139  #include <linux/time.h>
3140  #include <linux/compat.h>
3141  #include <linux/smp_lock.h>
3142 +#include <linux/vs_tag.h>
3143  #include <asm/uaccess.h>
3144  
3145  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
3146 @@ -56,6 +58,11 @@ int ext3_ioctl (struct inode * inode, st
3147                 if (!S_ISDIR(inode->i_mode))
3148                         flags &= ~EXT3_DIRSYNC_FL;
3149  
3150 +               if (IS_BARRIER(inode)) {
3151 +                       vxwprintk_task(1, "messing with the barrier.");
3152 +                       return -EACCES;
3153 +               }
3154 +
3155                 mutex_lock(&inode->i_mutex);
3156                 /* Is it quota file? Do not allow user to mess with it */
3157                 if (IS_NOQUOTA(inode)) {
3158 @@ -74,7 +81,9 @@ int ext3_ioctl (struct inode * inode, st
3159                  *
3160                  * This test looks nicer. Thanks to Pauline Middelink
3161                  */
3162 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3163 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3164 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3165 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3166                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3167                                 mutex_unlock(&inode->i_mutex);
3168                                 err = -EPERM;
3169 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/namei.c
3170 --- linux-2.6.27.25/fs/ext3/namei.c     2009-06-15 17:18:31.000000000 +0200
3171 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/namei.c        2009-02-03 18:03:38.000000000 +0100
3172 @@ -36,6 +36,7 @@
3173  #include <linux/quotaops.h>
3174  #include <linux/buffer_head.h>
3175  #include <linux/bio.h>
3176 +#include <linux/vs_tag.h>
3177  
3178  #include "namei.h"
3179  #include "xattr.h"
3180 @@ -912,6 +913,7 @@ restart:
3181                                 if (bh)
3182                                         ll_rw_block(READ_META, 1, &bh);
3183                         }
3184 +               dx_propagate_tag(nd, inode);
3185                 }
3186                 if ((bh = bh_use[ra_ptr++]) == NULL)
3187                         goto next;
3188 @@ -2433,6 +2435,7 @@ const struct inode_operations ext3_dir_i
3189         .removexattr    = generic_removexattr,
3190  #endif
3191         .permission     = ext3_permission,
3192 +       .sync_flags     = ext3_sync_flags,
3193  };
3194  
3195  const struct inode_operations ext3_special_inode_operations = {
3196 @@ -2444,4 +2447,5 @@ const struct inode_operations ext3_speci
3197         .removexattr    = generic_removexattr,
3198  #endif
3199         .permission     = ext3_permission,
3200 +       .sync_flags     = ext3_sync_flags,
3201  };
3202 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/super.c
3203 --- linux-2.6.27.25/fs/ext3/super.c     2009-06-15 17:18:31.000000000 +0200
3204 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/super.c        2009-02-03 17:59:04.000000000 +0100
3205 @@ -757,7 +757,7 @@ enum {
3206         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3207         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3208         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3209 -       Opt_grpquota
3210 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3211  };
3212  
3213  static match_table_t tokens = {
3214 @@ -808,6 +808,9 @@ static match_table_t tokens = {
3215         {Opt_usrquota, "usrquota"},
3216         {Opt_barrier, "barrier=%u"},
3217         {Opt_resize, "resize"},
3218 +       {Opt_tag, "tag"},
3219 +       {Opt_notag, "notag"},
3220 +       {Opt_tagid, "tagid=%u"},
3221         {Opt_err, NULL},
3222  };
3223  
3224 @@ -900,6 +903,20 @@ static int parse_options (char *options,
3225                 case Opt_nouid32:
3226                         set_opt (sbi->s_mount_opt, NO_UID32);
3227                         break;
3228 +#ifndef CONFIG_TAGGING_NONE
3229 +               case Opt_tag:
3230 +                       set_opt (sbi->s_mount_opt, TAGGED);
3231 +                       break;
3232 +               case Opt_notag:
3233 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3234 +                       break;
3235 +#endif
3236 +#ifdef CONFIG_PROPAGATE
3237 +               case Opt_tagid:
3238 +                       /* use args[0] */
3239 +                       set_opt (sbi->s_mount_opt, TAGGED);
3240 +                       break;
3241 +#endif
3242                 case Opt_nocheck:
3243                         clear_opt (sbi->s_mount_opt, CHECK);
3244                         break;
3245 @@ -1609,6 +1626,9 @@ static int ext3_fill_super (struct super
3246                             NULL, 0))
3247                 goto failed_mount;
3248  
3249 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3250 +               sb->s_flags |= MS_TAGGED;
3251 +
3252         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3253                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3254  
3255 @@ -2446,6 +2466,13 @@ static int ext3_remount (struct super_bl
3256         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3257                 ext3_abort(sb, __func__, "Abort forced by user");
3258  
3259 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3260 +               !(sb->s_flags & MS_TAGGED)) {
3261 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3262 +                       sb->s_id);
3263 +               return -EINVAL;
3264 +       }
3265 +
3266         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3267                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3268  
3269 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/symlink.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/symlink.c
3270 --- linux-2.6.27.25/fs/ext3/symlink.c   2008-07-13 23:51:29.000000000 +0200
3271 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/symlink.c      2008-10-13 14:54:20.000000000 +0200
3272 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3273         .listxattr      = ext3_listxattr,
3274         .removexattr    = generic_removexattr,
3275  #endif
3276 +       .sync_flags     = ext3_sync_flags,
3277  };
3278  
3279  const struct inode_operations ext3_fast_symlink_inode_operations = {
3280 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3281         .listxattr      = ext3_listxattr,
3282         .removexattr    = generic_removexattr,
3283  #endif
3284 +       .sync_flags     = ext3_sync_flags,
3285  };
3286 diff -NurpP --minimal linux-2.6.27.25/fs/ext3/xattr.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/xattr.c
3287 --- linux-2.6.27.25/fs/ext3/xattr.c     2008-07-13 23:51:29.000000000 +0200
3288 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext3/xattr.c        2008-10-13 14:54:20.000000000 +0200
3289 @@ -58,6 +58,7 @@
3290  #include <linux/mbcache.h>
3291  #include <linux/quotaops.h>
3292  #include <linux/rwsem.h>
3293 +#include <linux/vs_dlimit.h>
3294  #include "xattr.h"
3295  #include "acl.h"
3296  
3297 @@ -498,6 +499,7 @@ ext3_xattr_release_block(handle_t *handl
3298                 error = ext3_journal_dirty_metadata(handle, bh);
3299                 if (IS_SYNC(inode))
3300                         handle->h_sync = 1;
3301 +                       DLIMIT_FREE_BLOCK(inode, 1);
3302                 DQUOT_FREE_BLOCK(inode, 1);
3303                 ea_bdebug(bh, "refcount now=%d; releasing",
3304                           le32_to_cpu(BHDR(bh)->h_refcount));
3305 @@ -771,11 +773,14 @@ inserted:
3306                         if (new_bh == bs->bh)
3307                                 ea_bdebug(new_bh, "keeping");
3308                         else {
3309 +                               error = -ENOSPC;
3310 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3311 +                                       goto cleanup;
3312                                 /* The old block is released after updating
3313                                    the inode. */
3314                                 error = -EDQUOT;
3315                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3316 -                                       goto cleanup;
3317 +                                       goto cleanup_dlimit;
3318                                 error = ext3_journal_get_write_access(handle,
3319                                                                       new_bh);
3320                                 if (error)
3321 @@ -849,6 +854,8 @@ cleanup:
3322  
3323  cleanup_dquot:
3324         DQUOT_FREE_BLOCK(inode, 1);
3325 +cleanup_dlimit:
3326 +       DLIMIT_FREE_BLOCK(inode, 1);
3327         goto cleanup;
3328  
3329  bad_block:
3330 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/balloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/balloc.c
3331 --- linux-2.6.27.25/fs/ext4/balloc.c    2009-06-15 17:18:31.000000000 +0200
3332 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/balloc.c       2009-02-22 22:58:32.000000000 +0100
3333 @@ -17,6 +17,8 @@
3334  #include <linux/jbd2.h>
3335  #include <linux/quotaops.h>
3336  #include <linux/buffer_head.h>
3337 +#include <linux/vs_dlimit.h>
3338 +#include <linux/vs_tag.h>
3339  #include "ext4.h"
3340  #include "ext4_jbd2.h"
3341  #include "group.h"
3342 @@ -1019,8 +1021,10 @@ void ext4_free_blocks(handle_t *handle, 
3343         else
3344                 ext4_mb_free_blocks(handle, inode, block, count,
3345                                                 metadata, &dquot_freed_blocks);
3346 -       if (dquot_freed_blocks)
3347 +       if (dquot_freed_blocks) {
3348 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3349                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3350 +       }
3351         return;
3352  }
3353  
3354 @@ -1880,6 +1884,8 @@ ext4_fsblk_t ext4_old_new_blocks(handle_
3355                 *errp = -EDQUOT;
3356                 return 0;
3357         }
3358 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3359 +           goto out_dlimit;
3360  
3361         sbi = EXT4_SB(sb);
3362         es = EXT4_SB(sb)->s_es;
3363 @@ -2089,12 +2095,16 @@ allocated:
3364         *errp = 0;
3365         brelse(bitmap_bh);
3366         DQUOT_FREE_BLOCK(inode, *count-num);
3367 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3368         *count = num;
3369         return ret_block;
3370  
3371  io_error:
3372         *errp = -EIO;
3373  out:
3374 +       if (!performed_allocation)
3375 +               DLIMIT_FREE_BLOCK(inode, *count);
3376 +out_dlimit:
3377         if (fatal) {
3378                 *errp = fatal;
3379                 ext4_std_error(sb, fatal);
3380 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/ext4.h linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/ext4.h
3381 --- linux-2.6.27.25/fs/ext4/ext4.h      2009-06-15 17:18:31.000000000 +0200
3382 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/ext4.h 2009-06-15 17:22:10.000000000 +0200
3383 @@ -243,8 +243,12 @@ struct flex_groups {
3384  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3385  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3386  #define EXT4_EXT_MIGRATE               0x00100000 /* Inode is migrating */
3387 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3388  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3389  
3390 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3391 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3392 +
3393  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3394  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
3395  
3396 @@ -569,6 +573,7 @@ do {                                                                               \
3397  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3398  #define EXT4_MOUNT_MBALLOC             0x4000000 /* Buddy allocation support */
3399  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3400 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
3401  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
3402  #ifndef _LINUX_EXT2_FS_H
3403  #define clear_opt(o, opt)              o &= ~EXT4_MOUNT_##opt
3404 @@ -1089,6 +1094,7 @@ int ext4_get_blocks_handle(handle_t *han
3405                                 ext4_lblk_t iblock, unsigned long maxblocks,
3406                                 struct buffer_head *bh_result,
3407                                 int create, int extend_disksize);
3408 +extern int ext4_sync_flags(struct inode *inode);
3409  
3410  extern struct inode *ext4_iget(struct super_block *, unsigned long);
3411  extern int  ext4_write_inode (struct inode *, int);
3412 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/file.c
3413 --- linux-2.6.27.25/fs/ext4/file.c      2009-06-15 17:18:31.000000000 +0200
3414 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/file.c 2009-06-15 17:22:10.000000000 +0200
3415 @@ -175,5 +175,6 @@ const struct inode_operations ext4_file_
3416  #endif
3417         .permission     = ext4_permission,
3418         .fallocate      = ext4_fallocate,
3419 +       .sync_flags     = ext4_sync_flags,
3420  };
3421  
3422 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/ialloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/ialloc.c
3423 --- linux-2.6.27.25/fs/ext4/ialloc.c    2009-06-15 17:18:31.000000000 +0200
3424 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/ialloc.c       2009-06-15 17:22:10.000000000 +0200
3425 @@ -22,6 +22,8 @@
3426  #include <linux/random.h>
3427  #include <linux/bitops.h>
3428  #include <linux/blkdev.h>
3429 +#include <linux/vs_dlimit.h>
3430 +#include <linux/vs_tag.h>
3431  #include <asm/byteorder.h>
3432  #include "ext4.h"
3433  #include "ext4_jbd2.h"
3434 @@ -218,6 +220,7 @@ void ext4_free_inode (handle_t *handle, 
3435         ext4_xattr_delete_inode(handle, inode);
3436         DQUOT_FREE_INODE(inode);
3437         DQUOT_DROP(inode);
3438 +       DLIMIT_FREE_INODE(inode);
3439  
3440         is_directory = S_ISDIR(inode->i_mode);
3441  
3442 @@ -698,6 +701,12 @@ struct inode *ext4_new_inode(handle_t *h
3443         inode = new_inode(sb);
3444         if (!inode)
3445                 return ERR_PTR(-ENOMEM);
3446 +
3447 +       inode->i_tag = dx_current_fstag(sb);
3448 +       if (DLIMIT_ALLOC_INODE(inode)) {
3449 +               err = -ENOSPC;
3450 +               goto out_dlimit;
3451 +       }
3452         ei = EXT4_I(inode);
3453  
3454         sbi = EXT4_SB(sb);
3455 @@ -866,12 +875,17 @@ got:
3456         ei->i_disksize = 0;
3457  
3458         /*
3459 -        * Don't inherit extent flag from directory, amongst others. We set
3460 -        * extent flag on newly created directory and file only if -o extent
3461 -        * mount option is specified
3462 +        * Don't inherit extent flag from directory. We set extent flag on
3463 +        * newly created directory and file only if -o extent mount option is
3464 +        * specified
3465          */
3466 -       ei->i_flags =
3467 -               ext4_mask_flags(mode, EXT4_I(dir)->i_flags & EXT4_FL_INHERITED);
3468 +       ei->i_flags = EXT4_I(dir)->i_flags &
3469 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3470 +       if (S_ISLNK(mode))
3471 +               ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3472 +       /* dirsync only applies to directories */
3473 +       if (!S_ISDIR(mode))
3474 +               ei->i_flags &= ~EXT4_DIRSYNC_FL;
3475         ei->i_file_acl = 0;
3476         ei->i_dtime = 0;
3477         ei->i_block_alloc_info = NULL;
3478 @@ -922,6 +936,8 @@ got:
3479  fail:
3480         ext4_std_error(sb, err);
3481  out:
3482 +       DLIMIT_FREE_INODE(inode);
3483 +out_dlimit:
3484         iput(inode);
3485         ret = ERR_PTR(err);
3486  really_out:
3487 @@ -933,6 +949,7 @@ fail_free_drop:
3488  
3489  fail_drop:
3490         DQUOT_DROP(inode);
3491 +       DLIMIT_FREE_INODE(inode);
3492         inode->i_flags |= S_NOQUOTA;
3493         inode->i_nlink = 0;
3494         iput(inode);
3495 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/inode.c
3496 --- linux-2.6.27.25/fs/ext4/inode.c     2009-06-15 17:18:31.000000000 +0200
3497 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/inode.c        2009-06-15 17:22:10.000000000 +0200
3498 @@ -36,6 +36,7 @@
3499  #include <linux/mpage.h>
3500  #include <linux/uio.h>
3501  #include <linux/bio.h>
3502 +#include <linux/vs_tag.h>
3503  #include "ext4_jbd2.h"
3504  #include "xattr.h"
3505  #include "acl.h"
3506 @@ -3611,7 +3612,7 @@ static void ext4_free_branches(handle_t 
3507  
3508  int ext4_can_truncate(struct inode *inode)
3509  {
3510 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3511 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3512                 return 0;
3513         if (S_ISREG(inode->i_mode))
3514                 return 1;
3515 @@ -3973,37 +3974,86 @@ void ext4_set_inode_flags(struct inode *
3516  {
3517         unsigned int flags = EXT4_I(inode)->i_flags;
3518  
3519 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3520 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3521 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3522 +
3523 +       if (flags & EXT4_IMMUTABLE_FL)
3524 +               inode->i_flags |= S_IMMUTABLE;
3525 +       if (flags & EXT4_IXUNLINK_FL)
3526 +               inode->i_flags |= S_IXUNLINK;
3527 +
3528         if (flags & EXT4_SYNC_FL)
3529                 inode->i_flags |= S_SYNC;
3530         if (flags & EXT4_APPEND_FL)
3531                 inode->i_flags |= S_APPEND;
3532 -       if (flags & EXT4_IMMUTABLE_FL)
3533 -               inode->i_flags |= S_IMMUTABLE;
3534         if (flags & EXT4_NOATIME_FL)
3535                 inode->i_flags |= S_NOATIME;
3536         if (flags & EXT4_DIRSYNC_FL)
3537                 inode->i_flags |= S_DIRSYNC;
3538 +
3539 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3540 +
3541 +       if (flags & EXT4_BARRIER_FL)
3542 +               inode->i_vflags |= V_BARRIER;
3543 +       if (flags & EXT4_COW_FL)
3544 +               inode->i_vflags |= V_COW;
3545  }
3546  
3547  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3548  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3549  {
3550         unsigned int flags = ei->vfs_inode.i_flags;
3551 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3552 +
3553 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3554 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3555 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3556 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3557 +
3558 +       if (flags & S_IMMUTABLE)
3559 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3560 +       if (flags & S_IXUNLINK)
3561 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3562  
3563 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3564 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3565         if (flags & S_SYNC)
3566                 ei->i_flags |= EXT4_SYNC_FL;
3567         if (flags & S_APPEND)
3568                 ei->i_flags |= EXT4_APPEND_FL;
3569 -       if (flags & S_IMMUTABLE)
3570 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3571         if (flags & S_NOATIME)
3572                 ei->i_flags |= EXT4_NOATIME_FL;
3573         if (flags & S_DIRSYNC)
3574                 ei->i_flags |= EXT4_DIRSYNC_FL;
3575 +
3576 +       if (vflags & V_BARRIER)
3577 +               ei->i_flags |= EXT4_BARRIER_FL;
3578 +       if (vflags & V_COW)
3579 +               ei->i_flags |= EXT4_COW_FL;
3580  }
3581 +
3582 +int ext4_sync_flags(struct inode *inode)
3583 +{
3584 +       struct ext4_iloc iloc;
3585 +       handle_t *handle;
3586 +       int err;
3587 +
3588 +       handle = ext4_journal_start(inode, 1);
3589 +       if (IS_ERR(handle))
3590 +               return PTR_ERR(handle);
3591 +       if (IS_SYNC(inode))
3592 +               handle->h_sync = 1;
3593 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3594 +       if (err)
3595 +               goto flags_err;
3596 +
3597 +       ext4_get_inode_flags(EXT4_I(inode));
3598 +       inode->i_ctime = CURRENT_TIME;
3599 +
3600 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3601 +flags_err:
3602 +       ext4_journal_stop(handle);
3603 +       return err;
3604 +}
3605 +
3606  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3607                                         struct ext4_inode_info *ei)
3608  {
3609 @@ -4036,6 +4086,8 @@ struct inode *ext4_iget(struct super_blo
3610         struct inode *inode;
3611         long ret;
3612         int block;
3613 +       uid_t uid;
3614 +       gid_t gid;
3615  
3616         inode = iget_locked(sb, ino);
3617         if (!inode)
3618 @@ -4056,12 +4108,17 @@ struct inode *ext4_iget(struct super_blo
3619         bh = iloc.bh;
3620         raw_inode = ext4_raw_inode(&iloc);
3621         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3622 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3623 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3624 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3625 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3626         if(!(test_opt (inode->i_sb, NO_UID32))) {
3627 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3628 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3629 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3630 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3631         }
3632 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3633 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3634 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3635 +               le16_to_cpu(raw_inode->i_raw_tag));
3636 +
3637         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3638  
3639         ei->i_state = 0;
3640 @@ -4253,6 +4310,8 @@ static int ext4_do_update_inode(handle_t
3641         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3642         struct ext4_inode_info *ei = EXT4_I(inode);
3643         struct buffer_head *bh = iloc->bh;
3644 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3645 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3646         int err = 0, rc, block;
3647  
3648         /* For fields not not tracking in the in-memory inode,
3649 @@ -4263,29 +4322,32 @@ static int ext4_do_update_inode(handle_t
3650         ext4_get_inode_flags(ei);
3651         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3652         if(!(test_opt(inode->i_sb, NO_UID32))) {
3653 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3654 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3655 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3656 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3657  /*
3658   * Fix up interoperability with old kernels. Otherwise, old inodes get
3659   * re-used with the upper 16 bits of the uid/gid intact
3660   */
3661                 if(!ei->i_dtime) {
3662                         raw_inode->i_uid_high =
3663 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3664 +                               cpu_to_le16(high_16_bits(uid));
3665                         raw_inode->i_gid_high =
3666 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3667 +                               cpu_to_le16(high_16_bits(gid));
3668                 } else {
3669                         raw_inode->i_uid_high = 0;
3670                         raw_inode->i_gid_high = 0;
3671                 }
3672         } else {
3673                 raw_inode->i_uid_low =
3674 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3675 +                       cpu_to_le16(fs_high2lowuid(uid));
3676                 raw_inode->i_gid_low =
3677 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3678 +                       cpu_to_le16(fs_high2lowgid(gid));
3679                 raw_inode->i_uid_high = 0;
3680                 raw_inode->i_gid_high = 0;
3681         }
3682 +#ifdef CONFIG_TAGGING_INTERN
3683 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3684 +#endif
3685         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3686  
3687         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3688 @@ -4449,7 +4511,8 @@ int ext4_setattr(struct dentry *dentry, 
3689                 return error;
3690  
3691         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3692 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3693 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3694 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3695                 handle_t *handle;
3696  
3697                 /* (user+group)*(old+new) structure, inode write (sb,
3698 @@ -4471,6 +4534,8 @@ int ext4_setattr(struct dentry *dentry, 
3699                         inode->i_uid = attr->ia_uid;
3700                 if (attr->ia_valid & ATTR_GID)
3701                         inode->i_gid = attr->ia_gid;
3702 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3703 +                       inode->i_tag = attr->ia_tag;
3704                 error = ext4_mark_inode_dirty(handle, inode);
3705                 ext4_journal_stop(handle);
3706         }
3707 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/ioctl.c
3708 --- linux-2.6.27.25/fs/ext4/ioctl.c     2009-06-15 17:18:31.000000000 +0200
3709 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/ioctl.c        2009-06-15 17:24:03.000000000 +0200
3710 @@ -8,12 +8,14 @@
3711   */
3712  
3713  #include <linux/fs.h>
3714 +#include <linux/mount.h>
3715  #include <linux/jbd2.h>
3716  #include <linux/capability.h>
3717  #include <linux/time.h>
3718  #include <linux/compat.h>
3719  #include <linux/smp_lock.h>
3720  #include <linux/mount.h>
3721 +#include <linux/vs_tag.h>
3722  #include <asm/uaccess.h>
3723  #include "ext4_jbd2.h"
3724  #include "ext4.h"
3725 @@ -49,6 +51,11 @@ long ext4_ioctl(struct file *filp, unsig
3726                 if (err)
3727                         return err;
3728  
3729 +               if (IS_BARRIER(inode)) {
3730 +                       vxwprintk_task(1, "messing with the barrier.");
3731 +                       return -EACCES;
3732 +               }
3733 +
3734                 flags = ext4_mask_flags(inode->i_mode, flags);
3735  
3736                 err = -EPERM;
3737 @@ -68,7 +75,9 @@ long ext4_ioctl(struct file *filp, unsig
3738                  *
3739                  * This test looks nicer. Thanks to Pauline Middelink
3740                  */
3741 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3742 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3743 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3744 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3745                         if (!capable(CAP_LINUX_IMMUTABLE))
3746                                 goto flags_out;
3747                 }
3748 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/namei.c
3749 --- linux-2.6.27.25/fs/ext4/namei.c     2009-06-15 17:18:31.000000000 +0200
3750 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/namei.c        2009-06-15 17:22:10.000000000 +0200
3751 @@ -34,6 +34,7 @@
3752  #include <linux/quotaops.h>
3753  #include <linux/buffer_head.h>
3754  #include <linux/bio.h>
3755 +#include <linux/vs_tag.h>
3756  #include "ext4.h"
3757  #include "ext4_jbd2.h"
3758  
3759 @@ -919,6 +920,7 @@ restart:
3760                                 if (bh)
3761                                         ll_rw_block(READ_META, 1, &bh);
3762                         }
3763 +               dx_propagate_tag(nd, inode);
3764                 }
3765                 if ((bh = bh_use[ra_ptr++]) == NULL)
3766                         goto next;
3767 @@ -2487,6 +2489,7 @@ const struct inode_operations ext4_dir_i
3768         .removexattr    = generic_removexattr,
3769  #endif
3770         .permission     = ext4_permission,
3771 +       .sync_flags     = ext4_sync_flags,
3772  };
3773  
3774  const struct inode_operations ext4_special_inode_operations = {
3775 @@ -2498,4 +2501,5 @@ const struct inode_operations ext4_speci
3776         .removexattr    = generic_removexattr,
3777  #endif
3778         .permission     = ext4_permission,
3779 +       .sync_flags     = ext4_sync_flags,
3780  };
3781 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/super.c
3782 --- linux-2.6.27.25/fs/ext4/super.c     2009-06-15 17:18:31.000000000 +0200
3783 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/super.c        2009-03-25 14:32:29.000000000 +0100
3784 @@ -907,6 +907,7 @@ enum {
3785         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3786         Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
3787         Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3788 +       Opt_tag, Opt_notag, Opt_tagid
3789  };
3790  
3791  static match_table_t tokens = {
3792 @@ -967,6 +968,9 @@ static match_table_t tokens = {
3793         {Opt_resize, "resize"},
3794         {Opt_delalloc, "delalloc"},
3795         {Opt_nodelalloc, "nodelalloc"},
3796 +       {Opt_tag, "tag"},
3797 +       {Opt_notag, "notag"},
3798 +       {Opt_tagid, "tagid=%u"},
3799         {Opt_err, NULL},
3800  };
3801  
3802 @@ -1060,6 +1064,20 @@ static int parse_options(char *options, 
3803                 case Opt_nouid32:
3804                         set_opt(sbi->s_mount_opt, NO_UID32);
3805                         break;
3806 +#ifndef CONFIG_TAGGING_NONE
3807 +               case Opt_tag:
3808 +                       set_opt (sbi->s_mount_opt, TAGGED);
3809 +                       break;
3810 +               case Opt_notag:
3811 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3812 +                       break;
3813 +#endif
3814 +#ifdef CONFIG_PROPAGATE
3815 +               case Opt_tagid:
3816 +                       /* use args[0] */
3817 +                       set_opt (sbi->s_mount_opt, TAGGED);
3818 +                       break;
3819 +#endif
3820                 case Opt_nocheck:
3821                         clear_opt(sbi->s_mount_opt, CHECK);
3822                         break;
3823 @@ -2029,6 +2047,9 @@ static int ext4_fill_super(struct super_
3824                            NULL, 0))
3825                 goto failed_mount;
3826  
3827 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3828 +               sb->s_flags |= MS_TAGGED;
3829 +
3830         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3831                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3832  
3833 @@ -3033,6 +3054,13 @@ static int ext4_remount(struct super_blo
3834         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3835                 ext4_abort(sb, __func__, "Abort forced by user");
3836  
3837 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3838 +               !(sb->s_flags & MS_TAGGED)) {
3839 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3840 +                       sb->s_id);
3841 +               return -EINVAL;
3842 +       }
3843 +
3844         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3845                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3846  
3847 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/symlink.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/symlink.c
3848 --- linux-2.6.27.25/fs/ext4/symlink.c   2008-07-13 23:51:29.000000000 +0200
3849 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/symlink.c      2008-10-13 14:54:20.000000000 +0200
3850 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
3851         .listxattr      = ext4_listxattr,
3852         .removexattr    = generic_removexattr,
3853  #endif
3854 +       .sync_flags     = ext4_sync_flags,
3855  };
3856  
3857  const struct inode_operations ext4_fast_symlink_inode_operations = {
3858 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
3859         .listxattr      = ext4_listxattr,
3860         .removexattr    = generic_removexattr,
3861  #endif
3862 +       .sync_flags     = ext4_sync_flags,
3863  };
3864 diff -NurpP --minimal linux-2.6.27.25/fs/ext4/xattr.c linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/xattr.c
3865 --- linux-2.6.27.25/fs/ext4/xattr.c     2009-06-15 17:18:31.000000000 +0200
3866 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ext4/xattr.c        2009-02-03 17:59:04.000000000 +0100
3867 @@ -56,6 +56,7 @@
3868  #include <linux/mbcache.h>
3869  #include <linux/quotaops.h>
3870  #include <linux/rwsem.h>
3871 +#include <linux/vs_dlimit.h>
3872  #include "ext4_jbd2.h"
3873  #include "ext4.h"
3874  #include "xattr.h"
3875 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3876                 error = ext4_journal_dirty_metadata(handle, bh);
3877                 if (IS_SYNC(inode))
3878                         handle->h_sync = 1;
3879 +                       DLIMIT_FREE_BLOCK(inode, 1);
3880                 DQUOT_FREE_BLOCK(inode, 1);
3881                 ea_bdebug(bh, "refcount now=%d; releasing",
3882                           le32_to_cpu(BHDR(bh)->h_refcount));
3883 @@ -780,11 +782,14 @@ inserted:
3884                         if (new_bh == bs->bh)
3885                                 ea_bdebug(new_bh, "keeping");
3886                         else {
3887 +                               error = -ENOSPC;
3888 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3889 +                                       goto cleanup;
3890                                 /* The old block is released after updating
3891                                    the inode. */
3892                                 error = -EDQUOT;
3893                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3894 -                                       goto cleanup;
3895 +                                       goto cleanup_dlimit;
3896                                 error = ext4_journal_get_write_access(handle,
3897                                                                       new_bh);
3898                                 if (error)
3899 @@ -858,6 +863,8 @@ cleanup:
3900  
3901  cleanup_dquot:
3902         DQUOT_FREE_BLOCK(inode, 1);
3903 +cleanup_dlimit:
3904 +       DLIMIT_FREE_BLOCK(inode, 1);
3905         goto cleanup;
3906  
3907  bad_block:
3908 diff -NurpP --minimal linux-2.6.27.25/fs/fcntl.c linux-2.6.27.25-vs2.3.0.36.6/fs/fcntl.c
3909 --- linux-2.6.27.25/fs/fcntl.c  2009-06-15 17:18:31.000000000 +0200
3910 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/fcntl.c     2009-05-22 00:47:30.000000000 +0200
3911 @@ -20,6 +20,7 @@
3912  #include <linux/rcupdate.h>
3913  #include <linux/pid_namespace.h>
3914  #include <linux/smp_lock.h>
3915 +#include <linux/vs_limit.h>
3916  
3917  #include <asm/poll.h>
3918  #include <asm/siginfo.h>
3919 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3920  
3921         if (tofree)
3922                 filp_close(tofree, files);
3923 +       else
3924 +               vx_openfd_inc(newfd);   /* fd was unused */
3925  
3926         return newfd;
3927  
3928 @@ -344,6 +347,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3929         filp = fget(fd);
3930         if (!filp)
3931                 goto out;
3932 +       if (!vx_files_avail(1))
3933 +               goto out;
3934  
3935         err = security_file_fcntl(filp, cmd, arg);
3936         if (err) {
3937 diff -NurpP --minimal linux-2.6.27.25/fs/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/file.c
3938 --- linux-2.6.27.25/fs/file.c   2008-10-13 14:52:05.000000000 +0200
3939 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/file.c      2008-10-24 04:44:48.000000000 +0200
3940 @@ -19,6 +19,7 @@
3941  #include <linux/spinlock.h>
3942  #include <linux/rcupdate.h>
3943  #include <linux/workqueue.h>
3944 +#include <linux/vs_limit.h>
3945  
3946  struct fdtable_defer {
3947         spinlock_t lock;
3948 @@ -367,6 +368,8 @@ struct files_struct *dup_fd(struct files
3949                 struct file *f = *old_fds++;
3950                 if (f) {
3951                         get_file(f);
3952 +                       /* TODO: sum it first for check and performance */
3953 +                       vx_openfd_inc(open_files - i);
3954                 } else {
3955                         /*
3956                          * The fd may be claimed in the fd bitmap but not yet
3957 @@ -475,6 +478,7 @@ repeat:
3958         else
3959                 FD_CLR(fd, fdt->close_on_exec);
3960         error = fd;
3961 +       vx_openfd_inc(fd);
3962  #if 1
3963         /* Sanity check */
3964         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3965 diff -NurpP --minimal linux-2.6.27.25/fs/file_table.c linux-2.6.27.25-vs2.3.0.36.6/fs/file_table.c
3966 --- linux-2.6.27.25/fs/file_table.c     2008-10-13 14:52:05.000000000 +0200
3967 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/file_table.c        2008-10-13 14:54:20.000000000 +0200
3968 @@ -21,6 +21,8 @@
3969  #include <linux/fsnotify.h>
3970  #include <linux/sysctl.h>
3971  #include <linux/percpu_counter.h>
3972 +#include <linux/vs_limit.h>
3973 +#include <linux/vs_context.h>
3974  
3975  #include <asm/atomic.h>
3976  
3977 @@ -126,6 +128,8 @@ struct file *get_empty_filp(void)
3978         f->f_gid = tsk->fsgid;
3979         eventpoll_init_file(f);
3980         /* f->f_version: 0 */
3981 +       f->f_xid = vx_current_xid();
3982 +       vx_files_inc(f);
3983         return f;
3984  
3985  over:
3986 @@ -276,6 +280,8 @@ void __fput(struct file *file)
3987                 cdev_put(inode->i_cdev);
3988         fops_put(file->f_op);
3989         put_pid(file->f_owner.pid);
3990 +       vx_files_dec(file);
3991 +       file->f_xid = 0;
3992         file_kill(file);
3993         if (file->f_mode & FMODE_WRITE)
3994                 drop_file_write_access(file);
3995 @@ -343,6 +349,8 @@ void put_filp(struct file *file)
3996  {
3997         if (atomic_long_dec_and_test(&file->f_count)) {
3998                 security_file_free(file);
3999 +               vx_files_dec(file);
4000 +               file->f_xid = 0;
4001                 file_kill(file);
4002                 file_free(file);
4003         }
4004 diff -NurpP --minimal linux-2.6.27.25/fs/hfsplus/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/hfsplus/ioctl.c
4005 --- linux-2.6.27.25/fs/hfsplus/ioctl.c  2008-07-13 23:51:29.000000000 +0200
4006 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/hfsplus/ioctl.c     2008-10-13 14:54:20.000000000 +0200
4007 @@ -17,6 +17,7 @@
4008  #include <linux/mount.h>
4009  #include <linux/sched.h>
4010  #include <linux/xattr.h>
4011 +#include <linux/mount.h>
4012  #include <asm/uaccess.h>
4013  #include "hfsplus_fs.h"
4014  
4015 diff -NurpP --minimal linux-2.6.27.25/fs/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/inode.c
4016 --- linux-2.6.27.25/fs/inode.c  2009-06-15 17:18:31.000000000 +0200
4017 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/inode.c     2009-03-25 14:32:29.000000000 +0100
4018 @@ -124,6 +124,9 @@ static struct inode *alloc_inode(struct 
4019                 struct address_space * const mapping = &inode->i_data;
4020  
4021                 inode->i_sb = sb;
4022 +
4023 +               /* essential because of inode slab reuse */
4024 +               inode->i_tag = 0;
4025                 inode->i_blkbits = sb->s_blocksize_bits;
4026                 inode->i_flags = 0;
4027                 atomic_set(&inode->i_count, 1);
4028 @@ -142,6 +145,7 @@ static struct inode *alloc_inode(struct 
4029                 inode->i_bdev = NULL;
4030                 inode->i_cdev = NULL;
4031                 inode->i_rdev = 0;
4032 +               inode->i_mdev = 0;
4033                 inode->dirtied_when = 0;
4034                 if (security_inode_alloc(inode)) {
4035                         if (inode->i_sb->s_op->destroy_inode)
4036 @@ -247,6 +251,8 @@ void __iget(struct inode * inode)
4037         inodes_stat.nr_unused--;
4038  }
4039  
4040 +EXPORT_SYMBOL_GPL(__iget);
4041 +
4042  /**
4043   * clear_inode - clear an inode
4044   * @inode: inode to clear
4045 @@ -1434,9 +1440,11 @@ void init_special_inode(struct inode *in
4046         if (S_ISCHR(mode)) {
4047                 inode->i_fop = &def_chr_fops;
4048                 inode->i_rdev = rdev;
4049 +               inode->i_mdev = rdev;
4050         } else if (S_ISBLK(mode)) {
4051                 inode->i_fop = &def_blk_fops;
4052                 inode->i_rdev = rdev;
4053 +               inode->i_mdev = rdev;
4054         } else if (S_ISFIFO(mode))
4055                 inode->i_fop = &def_fifo_fops;
4056         else if (S_ISSOCK(mode))
4057 diff -NurpP --minimal linux-2.6.27.25/fs/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/ioctl.c
4058 --- linux-2.6.27.25/fs/ioctl.c  2009-06-15 17:18:31.000000000 +0200
4059 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ioctl.c     2009-02-03 17:59:04.000000000 +0100
4060 @@ -13,6 +13,9 @@
4061  #include <linux/security.h>
4062  #include <linux/module.h>
4063  #include <linux/uaccess.h>
4064 +#include <linux/proc_fs.h>
4065 +#include <linux/vserver/inode.h>
4066 +#include <linux/vs_tag.h>
4067  
4068  #include <asm/ioctls.h>
4069  
4070 diff -NurpP --minimal linux-2.6.27.25/fs/ioprio.c linux-2.6.27.25-vs2.3.0.36.6/fs/ioprio.c
4071 --- linux-2.6.27.25/fs/ioprio.c 2009-06-15 17:18:31.000000000 +0200
4072 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ioprio.c    2009-02-03 17:59:04.000000000 +0100
4073 @@ -26,6 +26,7 @@
4074  #include <linux/syscalls.h>
4075  #include <linux/security.h>
4076  #include <linux/pid_namespace.h>
4077 +#include <linux/vs_base.h>
4078  
4079  static int set_task_ioprio(struct task_struct *task, int ioprio)
4080  {
4081 @@ -116,6 +117,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4082                         else
4083                                 pgrp = find_vpid(who);
4084                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4085 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4086 +                                       continue;
4087                                 ret = set_task_ioprio(p, ioprio);
4088                                 if (ret)
4089                                         break;
4090 @@ -205,6 +208,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4091                         else
4092                                 pgrp = find_vpid(who);
4093                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4094 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4095 +                                       continue;
4096                                 tmpio = get_task_ioprio(p);
4097                                 if (tmpio < 0)
4098                                         continue;
4099 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/acl.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/acl.c
4100 --- linux-2.6.27.25/fs/jfs/acl.c        2008-10-13 14:52:05.000000000 +0200
4101 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/acl.c   2008-10-13 14:54:20.000000000 +0200
4102 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
4103                 return rc;
4104  
4105         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4106 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4107 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4108 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4109                 if (DQUOT_TRANSFER(inode, iattr))
4110                         return -EDQUOT;
4111         }
4112 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/file.c
4113 --- linux-2.6.27.25/fs/jfs/file.c       2008-07-13 23:51:29.000000000 +0200
4114 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/file.c  2008-10-13 14:54:20.000000000 +0200
4115 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4116         .setattr        = jfs_setattr,
4117         .permission     = jfs_permission,
4118  #endif
4119 +       .sync_flags     = jfs_sync_flags,
4120  };
4121  
4122  const struct file_operations jfs_file_operations = {
4123 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/inode.c
4124 --- linux-2.6.27.25/fs/jfs/inode.c      2008-07-13 23:51:29.000000000 +0200
4125 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/inode.c 2008-10-13 14:54:20.000000000 +0200
4126 @@ -22,6 +22,7 @@
4127  #include <linux/buffer_head.h>
4128  #include <linux/pagemap.h>
4129  #include <linux/quotaops.h>
4130 +#include <linux/vs_dlimit.h>
4131  #include "jfs_incore.h"
4132  #include "jfs_inode.h"
4133  #include "jfs_filsys.h"
4134 @@ -155,6 +156,7 @@ void jfs_delete_inode(struct inode *inod
4135                 DQUOT_INIT(inode);
4136                 DQUOT_FREE_INODE(inode);
4137                 DQUOT_DROP(inode);
4138 +               DLIMIT_FREE_INODE(inode);
4139         }
4140  
4141         clear_inode(inode);
4142 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/ioctl.c
4143 --- linux-2.6.27.25/fs/jfs/ioctl.c      2008-07-13 23:51:29.000000000 +0200
4144 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/ioctl.c 2008-10-13 14:54:20.000000000 +0200
4145 @@ -11,6 +11,7 @@
4146  #include <linux/mount.h>
4147  #include <linux/time.h>
4148  #include <linux/sched.h>
4149 +#include <linux/mount.h>
4150  #include <asm/current.h>
4151  #include <asm/uaccess.h>
4152  
4153 @@ -85,6 +86,11 @@ long jfs_ioctl(struct file *filp, unsign
4154                 if (!S_ISDIR(inode->i_mode))
4155                         flags &= ~JFS_DIRSYNC_FL;
4156  
4157 +               if (IS_BARRIER(inode)) {
4158 +                       vxwprintk_task(1, "messing with the barrier.");
4159 +                       return -EACCES;
4160 +               }
4161 +
4162                 /* Is it quota file? Do not allow user to mess with it */
4163                 if (IS_NOQUOTA(inode)) {
4164                         err = -EPERM;
4165 @@ -102,8 +108,8 @@ long jfs_ioctl(struct file *filp, unsign
4166                  * the relevant capability.
4167                  */
4168                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4169 -                       ((flags ^ oldflags) &
4170 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4171 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4172 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4173                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4174                                 mutex_unlock(&inode->i_mutex);
4175                                 err = -EPERM;
4176 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_dinode.h linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_dinode.h
4177 --- linux-2.6.27.25/fs/jfs/jfs_dinode.h 2008-07-13 23:51:29.000000000 +0200
4178 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_dinode.h    2008-10-31 18:15:18.000000000 +0100
4179 @@ -161,9 +161,13 @@ struct dinode {
4180  
4181  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4182  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4183 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4184  
4185 -#define JFS_FL_USER_VISIBLE    0x03F80000
4186 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4187 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4188 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4189 +
4190 +#define JFS_FL_USER_VISIBLE    0x07F80000
4191 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4192  #define JFS_FL_INHERIT         0x03C80000
4193  
4194  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4195 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_dtree.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_dtree.c
4196 --- linux-2.6.27.25/fs/jfs/jfs_dtree.c  2008-07-13 23:51:29.000000000 +0200
4197 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_dtree.c     2008-10-13 14:54:20.000000000 +0200
4198 @@ -102,6 +102,7 @@
4199  
4200  #include <linux/fs.h>
4201  #include <linux/quotaops.h>
4202 +#include <linux/vs_dlimit.h>
4203  #include "jfs_incore.h"
4204  #include "jfs_superblock.h"
4205  #include "jfs_filsys.h"
4206 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
4207                  */
4208                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4209                         goto clean_up;
4210 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4211 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4212 -                       goto clean_up;
4213 -               }
4214 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4215 +                       goto clean_up_dquot;
4216 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4217 +                       goto clean_up_dlimit;
4218  
4219                 /*
4220                  * Save the table, we're going to overwrite it with the
4221 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
4222  
4223         return index;
4224  
4225 +      clean_up_dlimit:
4226 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4227 +
4228 +      clean_up_dquot:
4229 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4230 +
4231        clean_up:
4232  
4233         jfs_ip->next_index--;
4234 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
4235         struct tlock *tlck;
4236         struct lv *lv;
4237         int quota_allocation = 0;
4238 +       int dlimit_allocation = 0;
4239  
4240         /* get split page */
4241         smp = split->mp;
4242 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
4243                 }
4244                 quota_allocation += n;
4245  
4246 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4247 +                       rc = -ENOSPC;
4248 +                       goto extendOut;
4249 +               }
4250 +               dlimit_allocation += n;
4251 +
4252                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4253                                     (s64) n, &nxaddr)))
4254                         goto extendOut;
4255 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
4256        freeKeyName:
4257         kfree(key.name);
4258  
4259 +       /* Rollback dlimit allocation */
4260 +       if (rc && dlimit_allocation)
4261 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4262         /* Rollback quota allocation */
4263         if (rc && quota_allocation)
4264                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4265 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4266                 release_metapage(rmp);
4267                 return -EDQUOT;
4268         }
4269 +       /* Allocate blocks to dlimit. */
4270 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4271 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4272 +               release_metapage(rmp);
4273 +               return -ENOSPC;
4274 +       }
4275  
4276         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4277  
4278 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
4279                 release_metapage(rmp);
4280                 return -EDQUOT;
4281         }
4282 +       /* Allocate blocks to dlimit. */
4283 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4284 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4285 +               release_metapage(rmp);
4286 +               return -ENOSPC;
4287 +       }
4288  
4289         BT_MARK_DIRTY(rmp, ip);
4290         /*
4291 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4292  
4293         xlen = lengthPXD(&fp->header.self);
4294  
4295 +       /* Free dlimit allocation. */
4296 +       DLIMIT_FREE_BLOCK(ip, xlen);
4297         /* Free quota allocation. */
4298         DQUOT_FREE_BLOCK(ip, xlen);
4299  
4300 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4301  
4302                                 xlen = lengthPXD(&p->header.self);
4303  
4304 +                               /* Free dlimit allocation */
4305 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4306                                 /* Free quota allocation */
4307                                 DQUOT_FREE_BLOCK(ip, xlen);
4308  
4309 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_extent.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_extent.c
4310 --- linux-2.6.27.25/fs/jfs/jfs_extent.c 2008-07-13 23:51:29.000000000 +0200
4311 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_extent.c    2008-10-13 14:54:20.000000000 +0200
4312 @@ -18,6 +18,7 @@
4313  
4314  #include <linux/fs.h>
4315  #include <linux/quotaops.h>
4316 +#include <linux/vs_dlimit.h>
4317  #include "jfs_incore.h"
4318  #include "jfs_inode.h"
4319  #include "jfs_superblock.h"
4320 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4321                 return -EDQUOT;
4322         }
4323  
4324 +       /* Allocate blocks to dlimit. */
4325 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4326 +               DQUOT_FREE_BLOCK(ip, nxlen);
4327 +               dbFree(ip, nxaddr, (s64) nxlen);
4328 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4329 +               return -ENOSPC;
4330 +       }
4331 +
4332         /* determine the value of the extent flag */
4333         xflag = abnr ? XAD_NOTRECORDED : 0;
4334  
4335 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4336          */
4337         if (rc) {
4338                 dbFree(ip, nxaddr, nxlen);
4339 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4340                 DQUOT_FREE_BLOCK(ip, nxlen);
4341                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4342                 return (rc);
4343 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4344                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4345                 return -EDQUOT;
4346         }
4347 +       /* Allocate blocks to dlimit. */
4348 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4349 +               DQUOT_FREE_BLOCK(ip, nxlen);
4350 +               dbFree(ip, nxaddr, (s64) nxlen);
4351 +               up(&JFS_IP(ip)->commit_sem);
4352 +               return -ENOSPC;
4353 +       }
4354  
4355         delta = nxlen - xlen;
4356  
4357 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4358                 /* extend the extent */
4359                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4360                         dbFree(ip, xaddr + xlen, delta);
4361 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4362                         DQUOT_FREE_BLOCK(ip, nxlen);
4363                         goto exit;
4364                 }
4365 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4366                  */
4367                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4368                         dbFree(ip, nxaddr, nxlen);
4369 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4370                         DQUOT_FREE_BLOCK(ip, nxlen);
4371                         goto exit;
4372                 }
4373 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_filsys.h linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_filsys.h
4374 --- linux-2.6.27.25/fs/jfs/jfs_filsys.h 2008-07-13 23:51:29.000000000 +0200
4375 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_filsys.h    2008-10-13 14:54:20.000000000 +0200
4376 @@ -263,6 +263,7 @@
4377  #define JFS_NAME_MAX   255
4378  #define JFS_PATH_MAX   BPSIZE
4379  
4380 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4381  
4382  /*
4383   *     file system state (superblock state)
4384 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_imap.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_imap.c
4385 --- linux-2.6.27.25/fs/jfs/jfs_imap.c   2008-10-13 14:52:05.000000000 +0200
4386 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_imap.c      2008-10-13 14:54:20.000000000 +0200
4387 @@ -45,6 +45,7 @@
4388  #include <linux/buffer_head.h>
4389  #include <linux/pagemap.h>
4390  #include <linux/quotaops.h>
4391 +#include <linux/vs_tag.h>
4392  
4393  #include "jfs_incore.h"
4394  #include "jfs_inode.h"
4395 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
4396  {
4397         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4398         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4399 +       uid_t uid;
4400 +       gid_t gid;
4401  
4402         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4403         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4404 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
4405         }
4406         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4407  
4408 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4409 +       uid = le32_to_cpu(dip->di_uid);
4410 +       gid = le32_to_cpu(dip->di_gid);
4411 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4412 +
4413 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4414         if (sbi->uid == -1)
4415                 ip->i_uid = jfs_ip->saved_uid;
4416         else {
4417                 ip->i_uid = sbi->uid;
4418         }
4419  
4420 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4421 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4422         if (sbi->gid == -1)
4423                 ip->i_gid = jfs_ip->saved_gid;
4424         else {
4425 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
4426         dip->di_size = cpu_to_le64(ip->i_size);
4427         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4428         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4429 -       if (sbi->uid == -1)
4430 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4431 -       else
4432 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4433 -       if (sbi->gid == -1)
4434 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4435 -       else
4436 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4437 +
4438 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4439 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4440 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4441 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4442 +
4443         jfs_get_inode_flags(jfs_ip);
4444         /*
4445          * mode2 is only needed for storing the higher order bits.
4446 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_inode.c
4447 --- linux-2.6.27.25/fs/jfs/jfs_inode.c  2008-07-13 23:51:29.000000000 +0200
4448 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_inode.c     2008-10-13 14:54:20.000000000 +0200
4449 @@ -18,6 +18,8 @@
4450  
4451  #include <linux/fs.h>
4452  #include <linux/quotaops.h>
4453 +#include <linux/vs_dlimit.h>
4454 +#include <linux/vs_tag.h>
4455  #include "jfs_incore.h"
4456  #include "jfs_inode.h"
4457  #include "jfs_filsys.h"
4458 @@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
4459  {
4460         unsigned int flags = JFS_IP(inode)->mode2;
4461  
4462 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4463 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4464 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4465 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4466  
4467         if (flags & JFS_IMMUTABLE_FL)
4468                 inode->i_flags |= S_IMMUTABLE;
4469 +       if (flags & JFS_IXUNLINK_FL)
4470 +               inode->i_flags |= S_IXUNLINK;
4471 +
4472 +       if (flags & JFS_SYNC_FL)
4473 +               inode->i_flags |= S_SYNC;
4474         if (flags & JFS_APPEND_FL)
4475                 inode->i_flags |= S_APPEND;
4476         if (flags & JFS_NOATIME_FL)
4477                 inode->i_flags |= S_NOATIME;
4478         if (flags & JFS_DIRSYNC_FL)
4479                 inode->i_flags |= S_DIRSYNC;
4480 -       if (flags & JFS_SYNC_FL)
4481 -               inode->i_flags |= S_SYNC;
4482 +
4483 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4484 +
4485 +       if (flags & JFS_BARRIER_FL)
4486 +               inode->i_vflags |= V_BARRIER;
4487 +       if (flags & JFS_COW_FL)
4488 +               inode->i_vflags |= V_COW;
4489  }
4490  
4491  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4492  {
4493         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4494 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4495 +
4496 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4497 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4498 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4499 +                          JFS_BARRIER_FL | JFS_COW_FL);
4500  
4501 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4502 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4503         if (flags & S_IMMUTABLE)
4504                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4505 +       if (flags & S_IXUNLINK)
4506 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4507 +
4508         if (flags & S_APPEND)
4509                 jfs_ip->mode2 |= JFS_APPEND_FL;
4510         if (flags & S_NOATIME)
4511 @@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
4512                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4513         if (flags & S_SYNC)
4514                 jfs_ip->mode2 |= JFS_SYNC_FL;
4515 +
4516 +       if (vflags & V_BARRIER)
4517 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4518 +       if (vflags & V_COW)
4519 +               jfs_ip->mode2 |= JFS_COW_FL;
4520 +}
4521 +
4522 +int jfs_sync_flags(struct inode *inode)
4523 +{
4524 +       jfs_get_inode_flags(JFS_IP(inode));
4525 +       inode->i_ctime = CURRENT_TIME;
4526 +       mark_inode_dirty(inode);
4527 +       return 0;
4528  }
4529  
4530  /*
4531 @@ -108,10 +140,17 @@ struct inode *ialloc(struct inode *paren
4532         jfs_inode->saved_uid = inode->i_uid;
4533         jfs_inode->saved_gid = inode->i_gid;
4534  
4535 +       inode->i_tag = dx_current_fstag(sb);
4536 +       if (DLIMIT_ALLOC_INODE(inode)) {
4537 +               iput(inode);
4538 +               return ERR_PTR(-ENOSPC);
4539 +       }
4540 +
4541         /*
4542          * Allocate inode to quota.
4543          */
4544         if (DQUOT_ALLOC_INODE(inode)) {
4545 +               DLIMIT_FREE_INODE(inode);
4546                 DQUOT_DROP(inode);
4547                 inode->i_flags |= S_NOQUOTA;
4548                 inode->i_nlink = 0;
4549 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_inode.h linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_inode.h
4550 --- linux-2.6.27.25/fs/jfs/jfs_inode.h  2008-07-13 23:51:29.000000000 +0200
4551 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_inode.h     2008-10-13 14:54:20.000000000 +0200
4552 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4553  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4554         int fh_len, int fh_type);
4555  extern void jfs_set_inode_flags(struct inode *);
4556 +extern int jfs_sync_flags(struct inode *);
4557  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4558  
4559  extern const struct address_space_operations jfs_aops;
4560 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/jfs_xtree.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_xtree.c
4561 --- linux-2.6.27.25/fs/jfs/jfs_xtree.c  2008-10-13 14:52:05.000000000 +0200
4562 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/jfs_xtree.c     2008-10-13 14:54:20.000000000 +0200
4563 @@ -23,6 +23,7 @@
4564  #include <linux/module.h>
4565  #include <linux/quotaops.h>
4566  #include <linux/seq_file.h>
4567 +#include <linux/vs_dlimit.h>
4568  #include "jfs_incore.h"
4569  #include "jfs_filsys.h"
4570  #include "jfs_metapage.h"
4571 @@ -848,7 +849,12 @@ int xtInsert(tid_t tid,            /* transaction 
4572                         hint = 0;
4573                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4574                         goto out;
4575 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4576 +                       DQUOT_FREE_BLOCK(ip, xlen);
4577 +                       goto out;
4578 +               }
4579                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4580 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4581                         DQUOT_FREE_BLOCK(ip, xlen);
4582                         goto out;
4583                 }
4584 @@ -878,6 +884,7 @@ int xtInsert(tid_t tid,             /* transaction 
4585                         /* undo data extent allocation */
4586                         if (*xaddrp == 0) {
4587                                 dbFree(ip, xaddr, (s64) xlen);
4588 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4589                                 DQUOT_FREE_BLOCK(ip, xlen);
4590                         }
4591                         return rc;
4592 @@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4593         struct tlock *tlck;
4594         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4595         int quota_allocation = 0;
4596 +       int dlimit_allocation = 0;
4597  
4598         smp = split->mp;
4599         sp = XT_PAGE(ip, smp);
4600 @@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4601  
4602         quota_allocation += lengthPXD(pxd);
4603  
4604 +       /* Allocate blocks to dlimit. */
4605 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4606 +              rc = -ENOSPC;
4607 +              goto clean_up;
4608 +       }
4609 +       dlimit_allocation += lengthPXD(pxd);
4610 +
4611         /*
4612          * allocate the new right page for the split
4613          */
4614 @@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4615  
4616        clean_up:
4617  
4618 +       /* Rollback dlimit allocation. */
4619 +       if (dlimit_allocation)
4620 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4621         /* Rollback quota allocation. */
4622         if (quota_allocation)
4623                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4624 @@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
4625                 release_metapage(rmp);
4626                 return -EDQUOT;
4627         }
4628 +       /* Allocate blocks to dlimit. */
4629 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4630 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4631 +               release_metapage(rmp);
4632 +               return -ENOSPC;
4633 +       }
4634  
4635         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4636  
4637 @@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4638         else
4639                 ip->i_size = newsize;
4640  
4641 +       /* update dlimit allocation to reflect freed blocks */
4642 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4643         /* update quota allocation to reflect freed blocks */
4644         DQUOT_FREE_BLOCK(ip, nfreed);
4645  
4646 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/namei.c
4647 --- linux-2.6.27.25/fs/jfs/namei.c      2008-10-13 14:52:05.000000000 +0200
4648 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/namei.c 2008-10-13 14:54:20.000000000 +0200
4649 @@ -21,6 +21,7 @@
4650  #include <linux/ctype.h>
4651  #include <linux/quotaops.h>
4652  #include <linux/exportfs.h>
4653 +#include <linux/vs_tag.h>
4654  #include "jfs_incore.h"
4655  #include "jfs_superblock.h"
4656  #include "jfs_inode.h"
4657 @@ -1468,6 +1469,7 @@ static struct dentry *jfs_lookup(struct 
4658                 return ERR_CAST(ip);
4659         }
4660  
4661 +       dx_propagate_tag(nd, ip);
4662         dentry = d_splice_alias(ip, dentry);
4663  
4664         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4665 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
4666         .setattr        = jfs_setattr,
4667         .permission     = jfs_permission,
4668  #endif
4669 +       .sync_flags     = jfs_sync_flags,
4670  };
4671  
4672  const struct file_operations jfs_dir_operations = {
4673 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/super.c
4674 --- linux-2.6.27.25/fs/jfs/super.c      2008-10-13 14:52:05.000000000 +0200
4675 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/super.c 2008-10-13 14:54:20.000000000 +0200
4676 @@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
4677  enum {
4678         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4679         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4680 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4681 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4682 +       Opt_tag, Opt_notag, Opt_tagid
4683  };
4684  
4685  static match_table_t tokens = {
4686 @@ -206,6 +207,10 @@ static match_table_t tokens = {
4687         {Opt_resize, "resize=%u"},
4688         {Opt_resize_nosize, "resize"},
4689         {Opt_errors, "errors=%s"},
4690 +       {Opt_tag, "tag"},
4691 +       {Opt_notag, "notag"},
4692 +       {Opt_tagid, "tagid=%u"},
4693 +       {Opt_tag, "tagxid"},
4694         {Opt_ignore, "noquota"},
4695         {Opt_ignore, "quota"},
4696         {Opt_usrquota, "usrquota"},
4697 @@ -340,6 +345,20 @@ static int parse_options(char *options, 
4698                         }
4699                         break;
4700                 }
4701 +#ifndef CONFIG_TAGGING_NONE
4702 +               case Opt_tag:
4703 +                       *flag |= JFS_TAGGED;
4704 +                       break;
4705 +               case Opt_notag:
4706 +                       *flag &= JFS_TAGGED;
4707 +                       break;
4708 +#endif
4709 +#ifdef CONFIG_PROPAGATE
4710 +               case Opt_tagid:
4711 +                       /* use args[0] */
4712 +                       *flag |= JFS_TAGGED;
4713 +                       break;
4714 +#endif
4715                 default:
4716                         printk("jfs: Unrecognized mount option \"%s\" "
4717                                         " or missing value\n", p);
4718 @@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
4719         if (!parse_options(data, sb, &newLVSize, &flag)) {
4720                 return -EINVAL;
4721         }
4722 +
4723 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4724 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4725 +                       sb->s_id);
4726 +               return -EINVAL;
4727 +       }
4728 +
4729         if (newLVSize) {
4730                 if (sb->s_flags & MS_RDONLY) {
4731                         printk(KERN_ERR
4732 @@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
4733  #ifdef CONFIG_JFS_POSIX_ACL
4734         sb->s_flags |= MS_POSIXACL;
4735  #endif
4736 +       /* map mount option tagxid */
4737 +       if (sbi->flag & JFS_TAGGED)
4738 +               sb->s_flags |= MS_TAGGED;
4739  
4740         if (newLVSize) {
4741                 printk(KERN_ERR "resize option for remount only\n");
4742 diff -NurpP --minimal linux-2.6.27.25/fs/jfs/xattr.c linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/xattr.c
4743 --- linux-2.6.27.25/fs/jfs/xattr.c      2008-07-13 23:51:29.000000000 +0200
4744 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/jfs/xattr.c 2008-10-13 14:54:20.000000000 +0200
4745 @@ -23,6 +23,7 @@
4746  #include <linux/posix_acl_xattr.h>
4747  #include <linux/quotaops.h>
4748  #include <linux/security.h>
4749 +#include <linux/vs_dlimit.h>
4750  #include "jfs_incore.h"
4751  #include "jfs_superblock.h"
4752  #include "jfs_dmap.h"
4753 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
4754         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
4755                 return -EDQUOT;
4756         }
4757 +       /* Allocate new blocks to dlimit. */
4758 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
4759 +               DQUOT_FREE_BLOCK(ip, nblocks);
4760 +               return -ENOSPC;
4761 +       }
4762  
4763         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
4764         if (rc) {
4765 +               /*Rollback dlimit allocation. */
4766 +               DLIMIT_FREE_BLOCK(ip, nblocks);
4767                 /*Rollback quota allocation. */
4768                 DQUOT_FREE_BLOCK(ip, nblocks);
4769                 return rc;
4770 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
4771  
4772        failed:
4773         /* Rollback quota allocation. */
4774 +       DLIMIT_FREE_BLOCK(ip, nblocks);
4775 +       /* Rollback quota allocation. */
4776         DQUOT_FREE_BLOCK(ip, nblocks);
4777  
4778         dbFree(ip, blkno, nblocks);
4779 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
4780         s64 blkno;
4781         int rc;
4782         int quota_allocation = 0;
4783 +       int dlimit_allocation = 0;
4784  
4785         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
4786         if (ji->ea.flag == 0)
4787 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
4788  
4789                 quota_allocation = blocks_needed;
4790  
4791 +               /* Allocate new blocks to dlimit. */
4792 +               rc = -ENOSPC;
4793 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
4794 +                       goto clean_up;
4795 +               dlimit_allocation = blocks_needed;
4796 +
4797                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
4798                              &blkno);
4799                 if (rc)
4800 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
4801         return ea_size;
4802  
4803        clean_up:
4804 +       /* Rollback dlimit allocation */
4805 +       if (dlimit_allocation)
4806 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
4807         /* Rollback quota allocation */
4808         if (quota_allocation)
4809                 DQUOT_FREE_BLOCK(inode, quota_allocation);
4810 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
4811         }
4812  
4813         /* If old blocks exist, they must be removed from quota allocation. */
4814 -       if (old_blocks)
4815 +       if (old_blocks) {
4816 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
4817                 DQUOT_FREE_BLOCK(inode, old_blocks);
4818 +       }
4819  
4820         inode->i_ctime = CURRENT_TIME;
4821  
4822 diff -NurpP --minimal linux-2.6.27.25/fs/libfs.c linux-2.6.27.25-vs2.3.0.36.6/fs/libfs.c
4823 --- linux-2.6.27.25/fs/libfs.c  2009-06-15 17:18:31.000000000 +0200
4824 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/libfs.c     2009-02-03 17:59:04.000000000 +0100
4825 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
4826   * both impossible due to the lock on directory.
4827   */
4828  
4829 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4830 +static inline int do_dcache_readdir_filter(struct file *filp,
4831 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4832  {
4833         struct dentry *dentry = filp->f_path.dentry;
4834         struct dentry *cursor = filp->private_data;
4835 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
4836                                 next = list_entry(p, struct dentry, d_u.d_child);
4837                                 if (d_unhashed(next) || !next->d_inode)
4838                                         continue;
4839 +                               if (filter && !filter(next))
4840 +                                       continue;
4841  
4842                                 spin_unlock(&dcache_lock);
4843                                 if (filldir(dirent, next->d_name.name, 
4844 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
4845         return 0;
4846  }
4847  
4848 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4849 +{
4850 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4851 +}
4852 +
4853 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4854 +       int (*filter)(struct dentry *))
4855 +{
4856 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4857 +}
4858 +
4859 +
4860  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4861  {
4862         return -EISDIR;
4863 @@ -823,6 +838,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4864  EXPORT_SYMBOL(dcache_dir_lseek);
4865  EXPORT_SYMBOL(dcache_dir_open);
4866  EXPORT_SYMBOL(dcache_readdir);
4867 +EXPORT_SYMBOL(dcache_readdir_filter);
4868  EXPORT_SYMBOL(generic_read_dir);
4869  EXPORT_SYMBOL(get_sb_pseudo);
4870  EXPORT_SYMBOL(simple_write_begin);
4871 diff -NurpP --minimal linux-2.6.27.25/fs/locks.c linux-2.6.27.25-vs2.3.0.36.6/fs/locks.c
4872 --- linux-2.6.27.25/fs/locks.c  2009-06-15 17:18:31.000000000 +0200
4873 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/locks.c     2009-02-03 17:59:04.000000000 +0100
4874 @@ -127,6 +127,8 @@
4875  #include <linux/time.h>
4876  #include <linux/rcupdate.h>
4877  #include <linux/pid_namespace.h>
4878 +#include <linux/vs_base.h>
4879 +#include <linux/vs_limit.h>
4880  
4881  #include <asm/uaccess.h>
4882  
4883 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4884  /* Allocate an empty lock structure. */
4885  static struct file_lock *locks_alloc_lock(void)
4886  {
4887 +       if (!vx_locks_avail(1))
4888 +               return NULL;
4889         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4890  }
4891  
4892 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
4893         BUG_ON(!list_empty(&fl->fl_block));
4894         BUG_ON(!list_empty(&fl->fl_link));
4895  
4896 +       vx_locks_dec(fl);
4897         locks_release_private(fl);
4898         kmem_cache_free(filelock_cache, fl);
4899  }
4900 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
4901         fl->fl_start = fl->fl_end = 0;
4902         fl->fl_ops = NULL;
4903         fl->fl_lmops = NULL;
4904 +       fl->fl_xid = -1;
4905  }
4906  
4907  EXPORT_SYMBOL(locks_init_lock);
4908 @@ -247,6 +253,7 @@ void locks_copy_lock(struct file_lock *n
4909         new->fl_file = fl->fl_file;
4910         new->fl_ops = fl->fl_ops;
4911         new->fl_lmops = fl->fl_lmops;
4912 +       new->fl_xid = fl->fl_xid;
4913  
4914         locks_copy_private(new, fl);
4915  }
4916 @@ -285,6 +292,11 @@ static int flock_make_lock(struct file *
4917         fl->fl_flags = FL_FLOCK;
4918         fl->fl_type = type;
4919         fl->fl_end = OFFSET_MAX;
4920 +
4921 +       vxd_assert(filp->f_xid == vx_current_xid(),
4922 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4923 +       fl->fl_xid = filp->f_xid;
4924 +       vx_locks_inc(fl);
4925         
4926         *lock = fl;
4927         return 0;
4928 @@ -450,6 +462,7 @@ static int lease_init(struct file *filp,
4929  
4930         fl->fl_owner = current->files;
4931         fl->fl_pid = current->tgid;
4932 +       fl->fl_xid = vx_current_xid();
4933  
4934         fl->fl_file = filp;
4935         fl->fl_flags = FL_LEASE;
4936 @@ -469,6 +482,11 @@ static struct file_lock *lease_alloc(str
4937         if (fl == NULL)
4938                 return ERR_PTR(error);
4939  
4940 +       fl->fl_xid = vx_current_xid();
4941 +       if (filp)
4942 +               vxd_assert(filp->f_xid == fl->fl_xid,
4943 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4944 +       vx_locks_inc(fl);
4945         error = lease_init(filp, type, fl);
4946         if (error) {
4947                 locks_free_lock(fl);
4948 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4949         if (found)
4950                 cond_resched_bkl();
4951  
4952 +       new_fl->fl_xid = -1;
4953  find_conflict:
4954         for_each_lock(inode, before) {
4955                 struct file_lock *fl = *before;
4956 @@ -789,6 +808,7 @@ find_conflict:
4957                 goto out;
4958         locks_copy_lock(new_fl, request);
4959         locks_insert_lock(before, new_fl);
4960 +       vx_locks_inc(new_fl);
4961         new_fl = NULL;
4962         error = 0;
4963  
4964 @@ -799,7 +819,8 @@ out:
4965         return error;
4966  }
4967  
4968 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4969 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4970 +       struct file_lock *conflock, xid_t xid)
4971  {
4972         struct file_lock *fl;
4973         struct file_lock *new_fl = NULL;
4974 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4975         struct file_lock **before;
4976         int error, added = 0;
4977  
4978 +       vxd_assert(xid == vx_current_xid(),
4979 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4980         /*
4981          * We may need two file_lock structures for this operation,
4982          * so we get them in advance to avoid races.
4983 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4984             (request->fl_type != F_UNLCK ||
4985              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4986                 new_fl = locks_alloc_lock();
4987 +               new_fl->fl_xid = xid;
4988 +               vx_locks_inc(new_fl);
4989                 new_fl2 = locks_alloc_lock();
4990 +               new_fl2->fl_xid = xid;
4991 +               vx_locks_inc(new_fl2);
4992         }
4993  
4994         lock_kernel();
4995 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4996  int posix_lock_file(struct file *filp, struct file_lock *fl,
4997                         struct file_lock *conflock)
4998  {
4999 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
5000 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
5001 +               fl, conflock, filp->f_xid);
5002  }
5003  EXPORT_SYMBOL(posix_lock_file);
5004  
5005 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
5006         fl.fl_end = offset + count - 1;
5007  
5008         for (;;) {
5009 -               error = __posix_lock_file(inode, &fl, NULL);
5010 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
5011                 if (error != FILE_LOCK_DEFERRED)
5012                         break;
5013                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
5014 @@ -1423,6 +1451,7 @@ int generic_setlease(struct file *filp, 
5015  
5016         locks_copy_lock(new_fl, lease);
5017         locks_insert_lock(before, new_fl);
5018 +       vx_locks_inc(new_fl);
5019  
5020         *flp = new_fl;
5021         return 0;
5022 @@ -1777,6 +1806,11 @@ int fcntl_setlk(unsigned int fd, struct 
5023         if (file_lock == NULL)
5024                 return -ENOLCK;
5025  
5026 +       vxd_assert(filp->f_xid == vx_current_xid(),
5027 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5028 +       file_lock->fl_xid = filp->f_xid;
5029 +       vx_locks_inc(file_lock);
5030 +
5031         /*
5032          * This might block, so we do it before checking the inode.
5033          */
5034 @@ -1895,6 +1929,11 @@ int fcntl_setlk64(unsigned int fd, struc
5035         if (file_lock == NULL)
5036                 return -ENOLCK;
5037  
5038 +       vxd_assert(filp->f_xid == vx_current_xid(),
5039 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5040 +       file_lock->fl_xid = filp->f_xid;
5041 +       vx_locks_inc(file_lock);
5042 +
5043         /*
5044          * This might block, so we do it before checking the inode.
5045          */
5046 @@ -2159,8 +2198,11 @@ static int locks_show(struct seq_file *f
5047  
5048         lock_get_status(f, fl, (long)f->private, "");
5049  
5050 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
5051 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
5052 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
5053 +                       continue;
5054                 lock_get_status(f, bfl, (long)f->private, " ->");
5055 +       }
5056  
5057         f->private++;
5058         return 0;
5059 diff -NurpP --minimal linux-2.6.27.25/fs/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/namei.c
5060 --- linux-2.6.27.25/fs/namei.c  2009-06-15 17:18:31.000000000 +0200
5061 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/namei.c     2009-02-03 17:59:04.000000000 +0100
5062 @@ -31,6 +31,14 @@
5063  #include <linux/file.h>
5064  #include <linux/fcntl.h>
5065  #include <linux/device_cgroup.h>
5066 +#include <linux/proc_fs.h>
5067 +#include <linux/vserver/inode.h>
5068 +#include <linux/vs_base.h>
5069 +#include <linux/vs_tag.h>
5070 +#include <linux/vs_cowbl.h>
5071 +#include <linux/vs_device.h>
5072 +#include <linux/vs_context.h>
5073 +#include <linux/pid_namespace.h>
5074  #include <asm/uaccess.h>
5075  
5076  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
5077 @@ -167,6 +175,77 @@ void putname(const char *name)
5078  EXPORT_SYMBOL(putname);
5079  #endif
5080  
5081 +static inline int dx_barrier(struct inode *inode)
5082 +{
5083 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
5084 +               vxwprintk_task(1, "did hit the barrier.");
5085 +               return 1;
5086 +       }
5087 +       return 0;
5088 +}
5089 +
5090 +static int __dx_permission(struct inode *inode, int mask)
5091 +{
5092 +       if (dx_barrier(inode))
5093 +               return -EACCES;
5094 +
5095 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5096 +               /* devpts is xid tagged */
5097 +               if (S_ISDIR(inode->i_mode) ||
5098 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
5099 +                       return 0;
5100 +       }
5101 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5102 +               struct proc_dir_entry *de = PDE(inode);
5103 +
5104 +               if (de && !vx_hide_check(0, de->vx_flags))
5105 +                       goto out;
5106 +
5107 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
5108 +                       struct pid *pid;
5109 +                       struct task_struct *tsk;
5110 +
5111 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
5112 +                           vx_flags(VXF_STATE_SETUP, 0))
5113 +                               return 0;
5114 +
5115 +                       pid = PROC_I(inode)->pid;
5116 +                       if (!pid)
5117 +                               goto out;
5118 +
5119 +                       tsk = pid_task(pid, PIDTYPE_PID);
5120 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
5121 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
5122 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
5123 +                               return 0;
5124 +               }
5125 +               else {
5126 +                       /* FIXME: Should we block some entries here? */
5127 +                       return 0;
5128 +               }
5129 +       }
5130 +       else {
5131 +               if (dx_notagcheck(inode->i_sb) ||
5132 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
5133 +                            DX_IDENT))
5134 +                       return 0;
5135 +       }
5136 +
5137 +out:
5138 +       return -EACCES;
5139 +}
5140 +
5141 +int dx_permission(struct inode *inode, int mask)
5142 +{
5143 +       int ret = __dx_permission(inode, mask);
5144 +       if (unlikely(ret)) {
5145 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
5146 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
5147 +                       inode->i_ino);
5148 +       }
5149 +       return ret;
5150 +}
5151 +
5152  
5153  /**
5154   * generic_permission  -  check for access rights on a Posix-like filesystem
5155 @@ -244,10 +323,14 @@ int inode_permission(struct inode *inode
5156                 /*
5157                  * Nobody gets write access to an immutable file.
5158                  */
5159 -               if (IS_IMMUTABLE(inode))
5160 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5161                         return -EACCES;
5162         }
5163  
5164 +       retval = dx_permission(inode, mask);
5165 +       if (retval)
5166 +               return retval;
5167 +
5168         /* Ordinary permission routines do not understand MAY_APPEND. */
5169         if (inode->i_op && inode->i_op->permission) {
5170                 retval = inode->i_op->permission(inode, mask);
5171 @@ -451,6 +534,8 @@ static int exec_permission_lite(struct i
5172  {
5173         umode_t mode = inode->i_mode;
5174  
5175 +       if (dx_barrier(inode))
5176 +               return -EACCES;
5177         if (inode->i_op && inode->i_op->permission)
5178                 return -EAGAIN;
5179  
5180 @@ -773,7 +858,8 @@ static __always_inline void follow_dotdo
5181                 if (nd->path.dentry == fs->root.dentry &&
5182                     nd->path.mnt == fs->root.mnt) {
5183                          read_unlock(&fs->lock);
5184 -                       break;
5185 +                       /* for sane '/' avoid follow_mount() */
5186 +                       return;
5187                 }
5188                  read_unlock(&fs->lock);
5189                 spin_lock(&dcache_lock);
5190 @@ -810,16 +896,30 @@ static int do_lookup(struct nameidata *n
5191  {
5192         struct vfsmount *mnt = nd->path.mnt;
5193         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5194 +       struct inode *inode;
5195  
5196         if (!dentry)
5197                 goto need_lookup;
5198         if (dentry->d_op && dentry->d_op->d_revalidate)
5199                 goto need_revalidate;
5200 +       inode = dentry->d_inode;
5201 +       if (!inode)
5202 +               goto done;
5203 +
5204 +       if (__dx_permission(inode, MAY_ACCESS))
5205 +               goto hidden;
5206 +
5207  done:
5208         path->mnt = mnt;
5209         path->dentry = dentry;
5210         __follow_mount(path);
5211         return 0;
5212 +hidden:
5213 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s«.",
5214 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5215 +               vxd_path(&nd->path));
5216 +       dput(dentry);
5217 +       return -ENOENT;
5218  
5219  need_lookup:
5220         dentry = real_lookup(nd->path.dentry, name, nd);
5221 @@ -1407,7 +1507,7 @@ static int may_delete(struct inode *dir,
5222         if (IS_APPEND(dir))
5223                 return -EPERM;
5224         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5225 -           IS_IMMUTABLE(victim->d_inode))
5226 +               IS_IXORUNLINK(victim->d_inode))
5227                 return -EPERM;
5228         if (isdir) {
5229                 if (!S_ISDIR(victim->d_inode->i_mode))
5230 @@ -1551,6 +1651,14 @@ int may_open(struct nameidata *nd, int a
5231                 flag &= ~O_TRUNC;
5232         }
5233  
5234 +#ifdef CONFIG_VSERVER_COWBL
5235 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5236 +               if (IS_COW_LINK(inode))
5237 +                       return -EMLINK;
5238 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5239 +               mark_inode_dirty(inode);
5240 +       }
5241 +#endif
5242         error = vfs_permission(nd, acc_mode);
5243         if (error)
5244                 return error;
5245 @@ -1677,6 +1785,11 @@ struct file *do_filp_open(int dfd, const
5246         int will_write;
5247         int flag = open_to_namei_flags(open_flag);
5248  
5249 +#ifdef CONFIG_VSERVER_COWBL
5250 +       int rflag = flag;
5251 +       int rmode = mode;
5252 +restart:
5253 +#endif
5254         acc_mode = MAY_OPEN | ACC_MODE(flag);
5255  
5256         /* O_TRUNC implies we need access checks for write permissions */
5257 @@ -1800,6 +1913,25 @@ ok:
5258                         goto exit;
5259         }
5260         error = may_open(&nd, acc_mode, flag);
5261 +#ifdef CONFIG_VSERVER_COWBL
5262 +       if (error == -EMLINK) {
5263 +               struct dentry *dentry;
5264 +               dentry = cow_break_link(pathname);
5265 +               if (IS_ERR(dentry)) {
5266 +                       error = PTR_ERR(dentry);
5267 +                       goto exit_cow;
5268 +               }
5269 +               dput(dentry);
5270 +               if (will_write)
5271 +                       mnt_drop_write(nd.path.mnt);
5272 +               release_open_intent(&nd);
5273 +               path_put(&nd.path);
5274 +               flag = rflag;
5275 +               mode = rmode;
5276 +               goto restart;
5277 +       }
5278 +exit_cow:
5279 +#endif
5280         if (error) {
5281                 if (will_write)
5282                         mnt_drop_write(nd.path.mnt);
5283 @@ -1952,9 +2084,17 @@ int vfs_mknod(struct inode *dir, struct 
5284         if (error)
5285                 return error;
5286  
5287 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5288 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5289 +               goto okay;
5290 +
5291 +       if (!capable(CAP_MKNOD))
5292                 return -EPERM;
5293  
5294 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5295 +               return -EPERM;
5296 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5297 +               return -EPERM;
5298 +okay:
5299         if (!dir->i_op || !dir->i_op->mknod)
5300                 return -EPERM;
5301  
5302 @@ -2395,7 +2535,7 @@ int vfs_link(struct dentry *old_dentry, 
5303         /*
5304          * A link to an append-only or immutable file cannot be created.
5305          */
5306 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5307 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5308                 return -EPERM;
5309         if (!dir->i_op || !dir->i_op->link)
5310                 return -EPERM;
5311 @@ -2755,6 +2895,217 @@ int vfs_follow_link(struct nameidata *nd
5312         return __vfs_follow_link(nd, link);
5313  }
5314  
5315 +
5316 +#ifdef CONFIG_VSERVER_COWBL
5317 +
5318 +#include <linux/file.h>
5319 +
5320 +static inline
5321 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5322 +{
5323 +       loff_t ppos = 0;
5324 +
5325 +       return do_splice_direct(in, &ppos, out, len, 0);
5326 +}
5327 +
5328 +struct dentry *cow_break_link(const char *pathname)
5329 +{
5330 +       int ret, mode, pathlen, redo = 0;
5331 +       struct nameidata old_nd, dir_nd;
5332 +       struct path old_path, new_path;
5333 +       struct dentry *dir, *res = NULL;
5334 +       struct file *old_file;
5335 +       struct file *new_file;
5336 +       char *to, *path, pad='\251';
5337 +       loff_t size;
5338 +
5339 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5340 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5341 +       ret = -ENOMEM;
5342 +       if (!path)
5343 +               goto out;
5344 +
5345 +       /* old_nd will have refs to dentry and mnt */
5346 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5347 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5348 +       if (ret < 0)
5349 +               goto out_free_path;
5350 +
5351 +       old_path = old_nd.path;
5352 +       mode = old_path.dentry->d_inode->i_mode;
5353 +
5354 +       to = d_path(&old_path, path, PATH_MAX-2);
5355 +       pathlen = strlen(to);
5356 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5357 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5358 +               old_path.dentry->d_name.len);
5359 +
5360 +       to[pathlen + 1] = 0;
5361 +retry:
5362 +       to[pathlen] = pad--;
5363 +       ret = -EMLINK;
5364 +       if (pad <= '\240')
5365 +               goto out_rel_old;
5366 +
5367 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5368 +       /* dir_nd will have refs to dentry and mnt */
5369 +       ret = path_lookup(to,
5370 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5371 +       vxdprintk(VXD_CBIT(misc, 2),
5372 +               "path_lookup(new): %d", ret);
5373 +       if (ret < 0)
5374 +               goto retry;
5375 +
5376 +       /* this puppy downs the inode mutex */
5377 +       new_path.dentry = lookup_create(&dir_nd, 0);
5378 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5379 +               vxdprintk(VXD_CBIT(misc, 2),
5380 +                       "lookup_create(new): %p", new_path.dentry);
5381 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5382 +               path_put(&dir_nd.path);
5383 +               goto retry;
5384 +       }
5385 +       vxdprintk(VXD_CBIT(misc, 2),
5386 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5387 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5388 +               new_path.dentry->d_name.len);
5389 +       dir = dir_nd.path.dentry;
5390 +
5391 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5392 +       vxdprintk(VXD_CBIT(misc, 2),
5393 +               "vfs_create(new): %d", ret);
5394 +       if (ret == -EEXIST) {
5395 +               mutex_unlock(&dir->d_inode->i_mutex);
5396 +               dput(new_path.dentry);
5397 +               path_put(&dir_nd.path);
5398 +               goto retry;
5399 +       }
5400 +       else if (ret < 0)
5401 +               goto out_unlock_new;
5402 +
5403 +       /* drop out early, ret passes ENOENT */
5404 +       ret = -ENOENT;
5405 +       if ((redo = d_unhashed(old_path.dentry)))
5406 +               goto out_unlock_new;
5407 +
5408 +       new_path.mnt = dir_nd.path.mnt;
5409 +       dget(old_path.dentry);
5410 +       mntget(old_path.mnt);
5411 +       /* this one cleans up the dentry/mnt in case of failure */
5412 +       old_file = dentry_open(old_path.dentry, old_path.mnt, O_RDONLY);
5413 +       vxdprintk(VXD_CBIT(misc, 2),
5414 +               "dentry_open(old): %p", old_file);
5415 +       if (!old_file || IS_ERR(old_file)) {
5416 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5417 +               goto out_unlock_new;
5418 +       }
5419 +
5420 +       dget(new_path.dentry);
5421 +       mntget(new_path.mnt);
5422 +       /* this one cleans up the dentry/mnt in case of failure */
5423 +       new_file = dentry_open(new_path.dentry, new_path.mnt, O_WRONLY);
5424 +       vxdprintk(VXD_CBIT(misc, 2),
5425 +               "dentry_open(new): %p", new_file);
5426 +
5427 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5428 +       if (!new_file || IS_ERR(new_file))
5429 +               goto out_fput_old;
5430 +
5431 +       size = i_size_read(old_file->f_dentry->d_inode);
5432 +       ret = do_cow_splice(old_file, new_file, size);
5433 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5434 +       if (ret < 0) {
5435 +               goto out_fput_both;
5436 +       } else if (ret < size) {
5437 +               ret = -ENOSPC;
5438 +               goto out_fput_both;
5439 +       } else {
5440 +               struct inode *old_inode = old_path.dentry->d_inode;
5441 +               struct inode *new_inode = new_path.dentry->d_inode;
5442 +               struct iattr attr = {
5443 +                       .ia_uid = old_inode->i_uid,
5444 +                       .ia_gid = old_inode->i_gid,
5445 +                       .ia_valid = ATTR_UID | ATTR_GID
5446 +                       };
5447 +
5448 +               ret = inode_setattr(new_inode, &attr);
5449 +               if (ret)
5450 +                       goto out_fput_both;
5451 +       }
5452 +
5453 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5454 +
5455 +       /* drop out late */
5456 +       ret = -ENOENT;
5457 +       if ((redo = d_unhashed(old_path.dentry)))
5458 +               goto out_unlock;
5459 +
5460 +       vxdprintk(VXD_CBIT(misc, 2),
5461 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5462 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5463 +               new_path.dentry->d_name.len,
5464 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5465 +               old_path.dentry->d_name.len);
5466 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5467 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5468 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5469 +       res = new_path.dentry;
5470 +
5471 +out_unlock:
5472 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5473 +
5474 +out_fput_both:
5475 +       vxdprintk(VXD_CBIT(misc, 3),
5476 +               "fput(new_file=%p[#%ld])", new_file,
5477 +               atomic_read(&new_file->f_count));
5478 +       fput(new_file);
5479 +
5480 +out_fput_old:
5481 +       vxdprintk(VXD_CBIT(misc, 3),
5482 +               "fput(old_file=%p[#%ld])", old_file,
5483 +               atomic_read(&old_file->f_count));
5484 +       fput(old_file);
5485 +
5486 +out_unlock_new:
5487 +       mutex_unlock(&dir->d_inode->i_mutex);
5488 +       if (!ret)
5489 +               goto out_redo;
5490 +
5491 +       /* error path cleanup */
5492 +       vfs_unlink(dir->d_inode, new_path.dentry);
5493 +       dput(new_path.dentry);
5494 +
5495 +out_redo:
5496 +       if (!redo)
5497 +               goto out_rel_both;
5498 +       /* lookup dentry once again */
5499 +       path_put(&old_nd.path);
5500 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5501 +       if (ret)
5502 +               goto out_rel_both;
5503 +
5504 +       new_path.dentry = old_nd.path.dentry;
5505 +       vxdprintk(VXD_CBIT(misc, 2),
5506 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5507 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5508 +               new_path.dentry->d_name.len);
5509 +       dget(new_path.dentry);
5510 +       res = new_path.dentry;
5511 +
5512 +out_rel_both:
5513 +       path_put(&dir_nd.path);
5514 +out_rel_old:
5515 +       path_put(&old_nd.path);
5516 +out_free_path:
5517 +       kfree(path);
5518 +out:
5519 +       if (ret)
5520 +               res = ERR_PTR(ret);
5521 +       return res;
5522 +}
5523 +
5524 +#endif
5525 +
5526  /* get the link contents into pagecache */
5527  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5528  {
5529 diff -NurpP --minimal linux-2.6.27.25/fs/namespace.c linux-2.6.27.25-vs2.3.0.36.6/fs/namespace.c
5530 --- linux-2.6.27.25/fs/namespace.c      2009-06-15 17:18:31.000000000 +0200
5531 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/namespace.c 2009-05-15 22:59:20.000000000 +0200
5532 @@ -27,6 +27,11 @@
5533  #include <linux/ramfs.h>
5534  #include <linux/log2.h>
5535  #include <linux/idr.h>
5536 +#include <linux/vs_base.h>
5537 +#include <linux/vs_context.h>
5538 +#include <linux/vs_tag.h>
5539 +#include <linux/vserver/space.h>
5540 +#include <linux/vserver/global.h>
5541  #include <asm/uaccess.h>
5542  #include <asm/unistd.h>
5543  #include "pnode.h"
5544 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5545                 mnt->mnt_root = dget(root);
5546                 mnt->mnt_mountpoint = mnt->mnt_root;
5547                 mnt->mnt_parent = mnt;
5548 +               mnt->mnt_tag = old->mnt_tag;
5549  
5550                 if (flag & CL_SLAVE) {
5551                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5552 @@ -685,6 +691,31 @@ static inline void mangle(struct seq_fil
5553         seq_escape(m, s, " \t\n\\");
5554  }
5555  
5556 +static int mnt_is_reachable(struct vfsmount *mnt)
5557 +{
5558 +       struct path root;
5559 +       struct dentry *point;
5560 +       int ret;
5561 +
5562 +       if (mnt == mnt->mnt_ns->root)
5563 +               return 1;
5564 +
5565 +       spin_lock(&vfsmount_lock);
5566 +       root = current->fs->root;
5567 +       point = root.dentry;
5568 +
5569 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5570 +               point = mnt->mnt_mountpoint;
5571 +               mnt = mnt->mnt_parent;
5572 +       }
5573 +
5574 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5575 +
5576 +       spin_unlock(&vfsmount_lock);
5577 +
5578 +       return ret;
5579 +}
5580 +
5581  /*
5582   * Simple .show_options callback for filesystems which don't want to
5583   * implement more complex mount option showing.
5584 @@ -757,6 +788,8 @@ static int show_sb_opts(struct seq_file 
5585                 { MS_SYNCHRONOUS, ",sync" },
5586                 { MS_DIRSYNC, ",dirsync" },
5587                 { MS_MANDLOCK, ",mand" },
5588 +               { MS_TAGGED, ",tag" },
5589 +               { MS_NOTAGCHECK, ",notagcheck" },
5590                 { 0, NULL }
5591         };
5592         const struct proc_fs_info *fs_infop;
5593 @@ -803,10 +836,20 @@ static int show_vfsmnt(struct seq_file *
5594         int err = 0;
5595         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5596  
5597 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5598 -       seq_putc(m, ' ');
5599 -       seq_path(m, &mnt_path, " \t\n\\");
5600 -       seq_putc(m, ' ');
5601 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5602 +               return SEQ_SKIP;
5603 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5604 +               return SEQ_SKIP;
5605 +
5606 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5607 +               mnt == current->fs->root.mnt) {
5608 +               seq_puts(m, "/dev/root / ");
5609 +       } else {
5610 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5611 +               seq_putc(m, ' ');
5612 +               seq_path(m, &mnt_path, " \t\n\\");
5613 +               seq_putc(m, ' ');
5614 +       }
5615         show_type(m, mnt->mnt_sb);
5616         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5617         err = show_sb_opts(m, mnt->mnt_sb);
5618 @@ -836,6 +879,11 @@ static int show_mountinfo(struct seq_fil
5619         struct path root = p->root;
5620         int err = 0;
5621  
5622 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5623 +               return SEQ_SKIP;
5624 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5625 +               return SEQ_SKIP;
5626 +
5627         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5628                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5629         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5630 @@ -894,17 +942,27 @@ static int show_vfsstat(struct seq_file 
5631         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5632         int err = 0;
5633  
5634 -       /* device */
5635 -       if (mnt->mnt_devname) {
5636 -               seq_puts(m, "device ");
5637 -               mangle(m, mnt->mnt_devname);
5638 -       } else
5639 -               seq_puts(m, "no device");
5640 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5641 +               return SEQ_SKIP;
5642 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5643 +               return SEQ_SKIP;
5644  
5645 -       /* mount point */
5646 -       seq_puts(m, " mounted on ");
5647 -       seq_path(m, &mnt_path, " \t\n\\");
5648 -       seq_putc(m, ' ');
5649 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5650 +               mnt == current->fs->root.mnt) {
5651 +               seq_puts(m, "device /dev/root mounted on / ");
5652 +       } else {
5653 +               /* device */
5654 +               if (mnt->mnt_devname) {
5655 +                       seq_puts(m, "device ");
5656 +                       mangle(m, mnt->mnt_devname);
5657 +               } else
5658 +                       seq_puts(m, "no device");
5659 +
5660 +               /* mount point */
5661 +               seq_puts(m, " mounted on ");
5662 +               seq_path(m, &mnt_path, " \t\n\\");
5663 +               seq_putc(m, ' ');
5664 +       }
5665  
5666         /* file system type */
5667         seq_puts(m, "with fstype ");
5668 @@ -1143,7 +1201,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5669                 goto dput_and_out;
5670  
5671         retval = -EPERM;
5672 -       if (!capable(CAP_SYS_ADMIN))
5673 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5674                 goto dput_and_out;
5675  
5676         retval = do_umount(path.mnt, flags);
5677 @@ -1169,7 +1227,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5678  
5679  static int mount_is_safe(struct nameidata *nd)
5680  {
5681 -       if (capable(CAP_SYS_ADMIN))
5682 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5683                 return 0;
5684         return -EPERM;
5685  #ifdef notyet
5686 @@ -1462,11 +1520,13 @@ static noinline int do_change_type(struc
5687   * noinline this do_mount helper to save do_mount stack space.
5688   */
5689  static noinline int do_loopback(struct nameidata *nd, char *old_name,
5690 -                               int recurse)
5691 +       tag_t tag, unsigned long flags, int mnt_flags)
5692  {
5693         struct nameidata old_nd;
5694         struct vfsmount *mnt = NULL;
5695         int err = mount_is_safe(nd);
5696 +       int recurse = flags & MS_REC;
5697 +
5698         if (err)
5699                 return err;
5700         if (!old_name || !*old_name)
5701 @@ -1500,6 +1560,7 @@ static noinline int do_loopback(struct n
5702                 spin_unlock(&vfsmount_lock);
5703                 release_mounts(&umount_list);
5704         }
5705 +       mnt->mnt_flags = mnt_flags;
5706  
5707  out:
5708         up_write(&namespace_sem);
5709 @@ -1531,12 +1592,12 @@ static int change_mount_flags(struct vfs
5710   * noinline this do_mount helper to save do_mount stack space.
5711   */
5712  static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags,
5713 -                     void *data)
5714 +       void *data, xid_t xid)
5715  {
5716         int err;
5717         struct super_block *sb = nd->path.mnt->mnt_sb;
5718  
5719 -       if (!capable(CAP_SYS_ADMIN))
5720 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5721                 return -EPERM;
5722  
5723         if (!check_mnt(nd->path.mnt))
5724 @@ -1582,7 +1643,7 @@ static noinline int do_move_mount(struct
5725         struct path parent_path;
5726         struct vfsmount *p;
5727         int err = 0;
5728 -       if (!capable(CAP_SYS_ADMIN))
5729 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5730                 return -EPERM;
5731         if (!old_name || !*old_name)
5732                 return -EINVAL;
5733 @@ -1665,7 +1726,7 @@ static noinline int do_new_mount(struct 
5734                 return -EINVAL;
5735  
5736         /* we need capabilities... */
5737 -       if (!capable(CAP_SYS_ADMIN))
5738 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5739                 return -EPERM;
5740  
5741         mnt = do_kern_mount(type, flags, name, data);
5742 @@ -1910,6 +1971,7 @@ long do_mount(char *dev_name, char *dir_
5743         struct nameidata nd;
5744         int retval = 0;
5745         int mnt_flags = 0;
5746 +       tag_t tag = 0;
5747  
5748         /* Discard magic */
5749         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5750 @@ -1925,6 +1987,12 @@ long do_mount(char *dev_name, char *dir_
5751         if (data_page)
5752                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5753  
5754 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5755 +               /* FIXME: bind and re-mounts get the tag flag? */
5756 +               if (flags & (MS_BIND|MS_REMOUNT))
5757 +                       flags |= MS_TAGID;
5758 +       }
5759 +
5760         /* Separate the per-mountpoint flags */
5761         if (flags & MS_NOSUID)
5762                 mnt_flags |= MNT_NOSUID;
5763 @@ -1941,6 +2009,8 @@ long do_mount(char *dev_name, char *dir_
5764         if (flags & MS_RDONLY)
5765                 mnt_flags |= MNT_READONLY;
5766  
5767 +       if (!capable(CAP_SYS_ADMIN))
5768 +               mnt_flags |= MNT_NODEV;
5769         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5770                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5771  
5772 @@ -1956,9 +2026,9 @@ long do_mount(char *dev_name, char *dir_
5773  
5774         if (flags & MS_REMOUNT)
5775                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
5776 -                                   data_page);
5777 +                                   data_page, tag);
5778         else if (flags & MS_BIND)
5779 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
5780 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
5781         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5782                 retval = do_change_type(&nd, flags);
5783         else if (flags & MS_MOVE)
5784 @@ -2027,6 +2097,7 @@ static struct mnt_namespace *dup_mnt_ns(
5785                 q = next_mnt(q, new_ns->root);
5786         }
5787         up_write(&namespace_sem);
5788 +       atomic_inc(&vs_global_mnt_ns);
5789  
5790         if (rootmnt)
5791                 mntput(rootmnt);
5792 @@ -2213,9 +2284,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5793         down_write(&namespace_sem);
5794         mutex_lock(&old.dentry->d_inode->i_mutex);
5795         error = -EINVAL;
5796 -       if (IS_MNT_SHARED(old.mnt) ||
5797 +       if ((IS_MNT_SHARED(old.mnt) ||
5798                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5799 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5800 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5801 +               !vx_flags(VXF_STATE_SETUP, 0))
5802                 goto out2;
5803         if (!check_mnt(root.mnt))
5804                 goto out2;
5805 @@ -2354,5 +2426,6 @@ void __put_mnt_ns(struct mnt_namespace *
5806         spin_unlock(&vfsmount_lock);
5807         up_write(&namespace_sem);
5808         release_mounts(&umount_list);
5809 +       atomic_dec(&vs_global_mnt_ns);
5810         kfree(ns);
5811  }
5812 diff -NurpP --minimal linux-2.6.27.25/fs/nfs/client.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/client.c
5813 --- linux-2.6.27.25/fs/nfs/client.c     2008-10-13 14:52:05.000000000 +0200
5814 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/client.c        2008-10-13 14:54:20.000000000 +0200
5815 @@ -601,6 +601,9 @@ static int nfs_init_server_rpcclient(str
5816         if (server->flags & NFS_MOUNT_SOFT)
5817                 server->client->cl_softrtry = 1;
5818  
5819 +       server->client->cl_tag = 0;
5820 +       if (server->flags & NFS_MOUNT_TAGGED)
5821 +               server->client->cl_tag = 1;
5822         return 0;
5823  }
5824  
5825 @@ -766,6 +769,10 @@ static void nfs_server_set_fsinfo(struct
5826                 server->acdirmin = server->acdirmax = 0;
5827         }
5828  
5829 +       /* FIXME: needs fsinfo
5830 +       if (server->flags & NFS_MOUNT_TAGGED)
5831 +               sb->s_flags |= MS_TAGGED;       */
5832 +
5833         server->maxfilesize = fsinfo->maxfilesize;
5834  
5835         /* We're airborne Set socket buffersize */
5836 diff -NurpP --minimal linux-2.6.27.25/fs/nfs/dir.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/dir.c
5837 --- linux-2.6.27.25/fs/nfs/dir.c        2009-06-15 17:18:31.000000000 +0200
5838 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/dir.c   2009-06-15 17:22:10.000000000 +0200
5839 @@ -34,6 +34,7 @@
5840  #include <linux/namei.h>
5841  #include <linux/mount.h>
5842  #include <linux/sched.h>
5843 +#include <linux/vs_tag.h>
5844  
5845  #include "nfs4_fs.h"
5846  #include "delegation.h"
5847 @@ -938,6 +939,7 @@ static struct dentry *nfs_lookup(struct 
5848         if (IS_ERR(res))
5849                 goto out_unblock_sillyrename;
5850  
5851 +       dx_propagate_tag(nd, inode);
5852  no_entry:
5853         res = d_materialise_unique(dentry, inode);
5854         if (res != NULL) {
5855 diff -NurpP --minimal linux-2.6.27.25/fs/nfs/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/inode.c
5856 --- linux-2.6.27.25/fs/nfs/inode.c      2008-10-13 14:52:05.000000000 +0200
5857 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/inode.c 2008-10-13 14:54:20.000000000 +0200
5858 @@ -37,6 +37,7 @@
5859  #include <linux/vfs.h>
5860  #include <linux/inet.h>
5861  #include <linux/nfs_xdr.h>
5862 +#include <linux/vs_tag.h>
5863  
5864  #include <asm/system.h>
5865  #include <asm/uaccess.h>
5866 @@ -314,8 +315,10 @@ nfs_fhget(struct super_block *sb, struct
5867                         nfsi->change_attr = fattr->change_attr;
5868                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5869                 inode->i_nlink = fattr->nlink;
5870 -               inode->i_uid = fattr->uid;
5871 -               inode->i_gid = fattr->gid;
5872 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5873 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5874 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5875 +                                        /* maybe fattr->xid someday */
5876                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5877                         /*
5878                          * report the blocks in 512byte units
5879 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5880                         inode->i_uid = attr->ia_uid;
5881                 if ((attr->ia_valid & ATTR_GID) != 0)
5882                         inode->i_gid = attr->ia_gid;
5883 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5884 +                       inode->i_tag = attr->ia_tag;
5885                 spin_lock(&inode->i_lock);
5886                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5887                 spin_unlock(&inode->i_lock);
5888 @@ -900,6 +905,9 @@ static int nfs_check_inode_attributes(st
5889         struct nfs_inode *nfsi = NFS_I(inode);
5890         loff_t cur_size, new_isize;
5891         unsigned long invalid = 0;
5892 +       uid_t uid;
5893 +       gid_t gid;
5894 +       tag_t tag;
5895  
5896  
5897         /* Has the inode gone and changed behind our back? */
5898 @@ -924,10 +932,15 @@ static int nfs_check_inode_attributes(st
5899         if (cur_size != new_isize && nfsi->npages == 0)
5900                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5901  
5902 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5903 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5904 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5905 +
5906         /* Have any file permissions changed? */
5907         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5908 -                       || inode->i_uid != fattr->uid
5909 -                       || inode->i_gid != fattr->gid)
5910 +                       || inode->i_uid != uid
5911 +                       || inode->i_gid != gid
5912 +                       || inode->i_tag != tag)
5913                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5914  
5915         /* Has the link count changed? */
5916 @@ -1048,6 +1061,9 @@ static int nfs_update_inode(struct inode
5917         loff_t cur_isize, new_isize;
5918         unsigned long invalid = 0;
5919         unsigned long now = jiffies;
5920 +       uid_t uid;
5921 +       gid_t gid;
5922 +       tag_t tag;
5923  
5924         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5925                         __func__, inode->i_sb->s_id, inode->i_ino,
5926 @@ -1121,15 +1137,21 @@ static int nfs_update_inode(struct inode
5927         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5928         nfsi->change_attr = fattr->change_attr;
5929  
5930 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5931 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5932 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5933 +
5934         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5935 -           inode->i_uid != fattr->uid ||
5936 -           inode->i_gid != fattr->gid)
5937 +           inode->i_uid != uid ||
5938 +           inode->i_gid != gid ||
5939 +           inode->i_tag != tag)
5940                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5941  
5942         inode->i_mode = fattr->mode;
5943         inode->i_nlink = fattr->nlink;
5944 -       inode->i_uid = fattr->uid;
5945 -       inode->i_gid = fattr->gid;
5946 +       inode->i_uid = uid;
5947 +       inode->i_gid = gid;
5948 +       inode->i_tag = tag;
5949  
5950         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5951                 /*
5952 diff -NurpP --minimal linux-2.6.27.25/fs/nfs/nfs3xdr.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/nfs3xdr.c
5953 --- linux-2.6.27.25/fs/nfs/nfs3xdr.c    2008-07-13 23:51:29.000000000 +0200
5954 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/nfs3xdr.c       2008-10-13 14:54:20.000000000 +0200
5955 @@ -22,6 +22,7 @@
5956  #include <linux/nfs3.h>
5957  #include <linux/nfs_fs.h>
5958  #include <linux/nfsacl.h>
5959 +#include <linux/vs_tag.h>
5960  #include "internal.h"
5961  
5962  #define NFSDBG_FACILITY                NFSDBG_XDR
5963 @@ -180,7 +181,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5964  }
5965  
5966  static inline __be32 *
5967 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5968 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5969  {
5970         if (attr->ia_valid & ATTR_MODE) {
5971                 *p++ = xdr_one;
5972 @@ -188,15 +189,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5973         } else {
5974                 *p++ = xdr_zero;
5975         }
5976 -       if (attr->ia_valid & ATTR_UID) {
5977 +       if (attr->ia_valid & ATTR_UID ||
5978 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5979                 *p++ = xdr_one;
5980 -               *p++ = htonl(attr->ia_uid);
5981 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5982         } else {
5983                 *p++ = xdr_zero;
5984         }
5985 -       if (attr->ia_valid & ATTR_GID) {
5986 +       if (attr->ia_valid & ATTR_GID ||
5987 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5988                 *p++ = xdr_one;
5989 -               *p++ = htonl(attr->ia_gid);
5990 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5991         } else {
5992                 *p++ = xdr_zero;
5993         }
5994 @@ -281,7 +284,8 @@ static int
5995  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5996  {
5997         p = xdr_encode_fhandle(p, args->fh);
5998 -       p = xdr_encode_sattr(p, args->sattr);
5999 +       p = xdr_encode_sattr(p, args->sattr,
6000 +               req->rq_task->tk_client->cl_tag);
6001         *p++ = htonl(args->guard);
6002         if (args->guard)
6003                 p = xdr_encode_time3(p, &args->guardtime);
6004 @@ -386,7 +390,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
6005                 *p++ = args->verifier[0];
6006                 *p++ = args->verifier[1];
6007         } else
6008 -               p = xdr_encode_sattr(p, args->sattr);
6009 +               p = xdr_encode_sattr(p, args->sattr,
6010 +                       req->rq_task->tk_client->cl_tag);
6011  
6012         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6013         return 0;
6014 @@ -400,7 +405,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
6015  {
6016         p = xdr_encode_fhandle(p, args->fh);
6017         p = xdr_encode_array(p, args->name, args->len);
6018 -       p = xdr_encode_sattr(p, args->sattr);
6019 +       p = xdr_encode_sattr(p, args->sattr,
6020 +               req->rq_task->tk_client->cl_tag);
6021         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6022         return 0;
6023  }
6024 @@ -413,7 +419,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
6025  {
6026         p = xdr_encode_fhandle(p, args->fromfh);
6027         p = xdr_encode_array(p, args->fromname, args->fromlen);
6028 -       p = xdr_encode_sattr(p, args->sattr);
6029 +       p = xdr_encode_sattr(p, args->sattr,
6030 +               req->rq_task->tk_client->cl_tag);
6031         *p++ = htonl(args->pathlen);
6032         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6033  
6034 @@ -431,7 +438,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6035         p = xdr_encode_fhandle(p, args->fh);
6036         p = xdr_encode_array(p, args->name, args->len);
6037         *p++ = htonl(args->type);
6038 -       p = xdr_encode_sattr(p, args->sattr);
6039 +       p = xdr_encode_sattr(p, args->sattr,
6040 +               req->rq_task->tk_client->cl_tag);
6041         if (args->type == NF3CHR || args->type == NF3BLK) {
6042                 *p++ = htonl(MAJOR(args->rdev));
6043                 *p++ = htonl(MINOR(args->rdev));
6044 diff -NurpP --minimal linux-2.6.27.25/fs/nfs/nfsroot.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/nfsroot.c
6045 --- linux-2.6.27.25/fs/nfs/nfsroot.c    2008-10-13 14:52:05.000000000 +0200
6046 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/nfsroot.c       2008-10-13 14:54:20.000000000 +0200
6047 @@ -117,12 +117,12 @@ static int mount_port __initdata = 0;             /
6048  enum {
6049         /* Options that take integer arguments */
6050         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6051 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6052 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6053         /* Options that take no arguments */
6054         Opt_soft, Opt_hard, Opt_intr,
6055         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6056         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6057 -       Opt_acl, Opt_noacl,
6058 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6059         /* Error token */
6060         Opt_err
6061  };
6062 @@ -159,6 +159,9 @@ static match_table_t __initdata tokens =
6063         {Opt_tcp, "tcp"},
6064         {Opt_acl, "acl"},
6065         {Opt_noacl, "noacl"},
6066 +       {Opt_tag, "tag"},
6067 +       {Opt_notag, "notag"},
6068 +       {Opt_tagid, "tagid=%u"},
6069         {Opt_err, NULL}
6070         
6071  };
6072 @@ -270,6 +273,20 @@ static int __init root_nfs_parse(char *n
6073                         case Opt_noacl:
6074                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6075                                 break;
6076 +#ifndef CONFIG_TAGGING_NONE
6077 +                       case Opt_tag:
6078 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6079 +                               break;
6080 +                       case Opt_notag:
6081 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6082 +                               break;
6083 +#endif
6084 +#ifdef CONFIG_PROPAGATE
6085 +                       case Opt_tagid:
6086 +                               /* use args[0] */
6087 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6088 +                               break;
6089 +#endif
6090                         default:
6091                                 printk(KERN_WARNING "Root-NFS: unknown "
6092                                         "option: %s\n", p);
6093 diff -NurpP --minimal linux-2.6.27.25/fs/nfs/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/super.c
6094 --- linux-2.6.27.25/fs/nfs/super.c      2008-10-13 14:52:05.000000000 +0200
6095 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfs/super.c 2008-10-13 14:54:20.000000000 +0200
6096 @@ -51,6 +51,7 @@
6097  #include <linux/nfs_xdr.h>
6098  #include <linux/magic.h>
6099  #include <linux/parser.h>
6100 +#include <linux/vs_tag.h>
6101  
6102  #include <asm/system.h>
6103  #include <asm/uaccess.h>
6104 @@ -504,6 +505,7 @@ static void nfs_show_mount_options(struc
6105                 { NFS_MOUNT_NOACL, ",noacl", "" },
6106                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6107                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
6108 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6109                 { 0, NULL, NULL }
6110         };
6111         const struct proc_nfs_info *nfs_infop;
6112 diff -NurpP --minimal linux-2.6.27.25/fs/nfsd/auth.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/auth.c
6113 --- linux-2.6.27.25/fs/nfsd/auth.c      2008-07-13 23:51:29.000000000 +0200
6114 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/auth.c 2008-10-13 14:54:20.000000000 +0200
6115 @@ -10,6 +10,7 @@
6116  #include <linux/sunrpc/svcauth.h>
6117  #include <linux/nfsd/nfsd.h>
6118  #include <linux/nfsd/export.h>
6119 +#include <linux/vs_tag.h>
6120  #include "auth.h"
6121  
6122  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6123 @@ -55,19 +56,23 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6124                 get_group_info(cred.cr_group_info);
6125  
6126         if (cred.cr_uid != (uid_t) -1)
6127 -               current->fsuid = cred.cr_uid;
6128 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6129         else
6130                 current->fsuid = exp->ex_anon_uid;
6131         if (cred.cr_gid != (gid_t) -1)
6132 -               current->fsgid = cred.cr_gid;
6133 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6134         else
6135                 current->fsgid = exp->ex_anon_gid;
6136  
6137 +       /* this desperately needs a tag :) */
6138 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6139 +
6140         if (!cred.cr_group_info)
6141                 return -ENOMEM;
6142         ret = set_current_groups(cred.cr_group_info);
6143         put_group_info(cred.cr_group_info);
6144 -       if ((cred.cr_uid)) {
6145 +
6146 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
6147                 current->cap_effective =
6148                         cap_drop_nfsd_set(current->cap_effective);
6149         } else {
6150 diff -NurpP --minimal linux-2.6.27.25/fs/nfsd/nfs3xdr.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/nfs3xdr.c
6151 --- linux-2.6.27.25/fs/nfsd/nfs3xdr.c   2008-07-13 23:51:29.000000000 +0200
6152 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/nfs3xdr.c      2008-10-13 14:54:20.000000000 +0200
6153 @@ -21,6 +21,7 @@
6154  #include <linux/sunrpc/svc.h>
6155  #include <linux/nfsd/nfsd.h>
6156  #include <linux/nfsd/xdr3.h>
6157 +#include <linux/vs_tag.h>
6158  #include "auth.h"
6159  
6160  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6161 @@ -108,6 +109,8 @@ static __be32 *
6162  decode_sattr3(__be32 *p, struct iattr *iap)
6163  {
6164         u32     tmp;
6165 +       uid_t   uid = 0;
6166 +       gid_t   gid = 0;
6167  
6168         iap->ia_valid = 0;
6169  
6170 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6171         }
6172         if (*p++) {
6173                 iap->ia_valid |= ATTR_UID;
6174 -               iap->ia_uid = ntohl(*p++);
6175 +               uid = ntohl(*p++);
6176         }
6177         if (*p++) {
6178                 iap->ia_valid |= ATTR_GID;
6179 -               iap->ia_gid = ntohl(*p++);
6180 +               gid = ntohl(*p++);
6181         }
6182 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6183 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6184 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6185         if (*p++) {
6186                 u64     newsize;
6187  
6188 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6189         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6190         *p++ = htonl((u32) stat->mode);
6191         *p++ = htonl((u32) stat->nlink);
6192 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6193 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6194 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6195 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6196 +               stat->uid, stat->tag)));
6197 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6198 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6199 +               stat->gid, stat->tag)));
6200         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6201                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6202         } else {
6203 diff -NurpP --minimal linux-2.6.27.25/fs/nfsd/nfs4xdr.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/nfs4xdr.c
6204 --- linux-2.6.27.25/fs/nfsd/nfs4xdr.c   2009-06-15 17:18:32.000000000 +0200
6205 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/nfs4xdr.c      2009-05-22 00:47:30.000000000 +0200
6206 @@ -58,6 +58,7 @@
6207  #include <linux/nfs4_acl.h>
6208  #include <linux/sunrpc/gss_api.h>
6209  #include <linux/sunrpc/svcauth_gss.h>
6210 +#include <linux/vs_tag.h>
6211  
6212  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6213  
6214 @@ -1704,14 +1705,18 @@ out_acl:
6215                 WRITE32(stat.nlink);
6216         }
6217         if (bmval1 & FATTR4_WORD1_OWNER) {
6218 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6219 +               status = nfsd4_encode_user(rqstp,
6220 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6221 +                       stat.uid, stat.tag), &p, &buflen);
6222                 if (status == nfserr_resource)
6223                         goto out_resource;
6224                 if (status)
6225                         goto out;
6226         }
6227         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6228 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6229 +               status = nfsd4_encode_group(rqstp,
6230 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6231 +                       stat.gid, stat.tag), &p, &buflen);
6232                 if (status == nfserr_resource)
6233                         goto out_resource;
6234                 if (status)
6235 diff -NurpP --minimal linux-2.6.27.25/fs/nfsd/nfsxdr.c linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/nfsxdr.c
6236 --- linux-2.6.27.25/fs/nfsd/nfsxdr.c    2008-07-13 23:51:29.000000000 +0200
6237 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/nfsd/nfsxdr.c       2008-10-13 14:54:20.000000000 +0200
6238 @@ -15,6 +15,7 @@
6239  #include <linux/nfsd/nfsd.h>
6240  #include <linux/nfsd/xdr.h>
6241  #include <linux/mm.h>
6242 +#include <linux/vs_tag.h>
6243  #include "auth.h"
6244  
6245  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6246 @@ -98,6 +99,8 @@ static __be32 *
6247  decode_sattr(__be32 *p, struct iattr *iap)
6248  {
6249         u32     tmp, tmp1;
6250 +       uid_t   uid = 0;
6251 +       gid_t   gid = 0;
6252  
6253         iap->ia_valid = 0;
6254  
6255 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6256         }
6257         if ((tmp = ntohl(*p++)) != (u32)-1) {
6258                 iap->ia_valid |= ATTR_UID;
6259 -               iap->ia_uid = tmp;
6260 +               uid = tmp;
6261         }
6262         if ((tmp = ntohl(*p++)) != (u32)-1) {
6263                 iap->ia_valid |= ATTR_GID;
6264 -               iap->ia_gid = tmp;
6265 +               gid = tmp;
6266         }
6267 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6268 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6269 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6270         if ((tmp = ntohl(*p++)) != (u32)-1) {
6271                 iap->ia_valid |= ATTR_SIZE;
6272                 iap->ia_size = tmp;
6273 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6274         *p++ = htonl(nfs_ftypes[type >> 12]);
6275         *p++ = htonl((u32) stat->mode);
6276         *p++ = htonl((u32) stat->nlink);
6277 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6278 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6279 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6280 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6281 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6282 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6283  
6284         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6285                 *p++ = htonl(NFS_MAXPATHLEN);
6286 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/dlm/dlmfs.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/dlm/dlmfs.c
6287 --- linux-2.6.27.25/fs/ocfs2/dlm/dlmfs.c        2008-10-13 14:52:06.000000000 +0200
6288 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/dlm/dlmfs.c   2008-10-13 14:54:20.000000000 +0200
6289 @@ -43,6 +43,7 @@
6290  #include <linux/init.h>
6291  #include <linux/string.h>
6292  #include <linux/backing-dev.h>
6293 +#include <linux/vs_tag.h>
6294  
6295  #include <asm/uaccess.h>
6296  
6297 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6298                 inode->i_mode = mode;
6299                 inode->i_uid = current->fsuid;
6300                 inode->i_gid = current->fsgid;
6301 +               inode->i_tag = dx_current_fstag(sb);
6302                 inode->i_blocks = 0;
6303                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6304                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6305 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6306         inode->i_mode = mode;
6307         inode->i_uid = current->fsuid;
6308         inode->i_gid = current->fsgid;
6309 +       inode->i_tag = dx_current_fstag(sb);
6310         inode->i_blocks = 0;
6311         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6312         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6313 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/dlmglue.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/dlmglue.c
6314 --- linux-2.6.27.25/fs/ocfs2/dlmglue.c  2008-10-13 14:52:06.000000000 +0200
6315 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/dlmglue.c     2008-10-13 14:54:20.000000000 +0200
6316 @@ -1846,6 +1846,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6317         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6318         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6319         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6320 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6321         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6322         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6323         lvb->lvb_iatime_packed  =
6324 @@ -1900,6 +1901,7 @@ static void ocfs2_refresh_inode_from_lvb
6325  
6326         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6327         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6328 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6329         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6330         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6331         ocfs2_unpack_timespec(&inode->i_atime,
6332 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/dlmglue.h linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/dlmglue.h
6333 --- linux-2.6.27.25/fs/ocfs2/dlmglue.h  2008-07-13 23:51:29.000000000 +0200
6334 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/dlmglue.h     2008-10-13 14:54:20.000000000 +0200
6335 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6336         __be16       lvb_inlink;
6337         __be32       lvb_iattr;
6338         __be32       lvb_igeneration;
6339 -       __be32       lvb_reserved2;
6340 +       __be16       lvb_itag;
6341 +       __be16       lvb_reserved2;
6342  };
6343  
6344  /* ocfs2_inode_lock_full() 'arg_flags' flags */
6345 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/file.c
6346 --- linux-2.6.27.25/fs/ocfs2/file.c     2009-06-15 17:18:32.000000000 +0200
6347 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/file.c        2009-05-22 00:47:30.000000000 +0200
6348 @@ -1058,13 +1058,15 @@ int ocfs2_setattr(struct dentry *dentry,
6349                 mlog(0, "uid change: %d\n", attr->ia_uid);
6350         if (attr->ia_valid & ATTR_GID)
6351                 mlog(0, "gid change: %d\n", attr->ia_gid);
6352 +       if (attr->ia_valid & ATTR_TAG)
6353 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6354         if (attr->ia_valid & ATTR_SIZE)
6355                 mlog(0, "size change...\n");
6356         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6357                 mlog(0, "time change...\n");
6358  
6359  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6360 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6361 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6362         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6363                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6364                 return 0;
6365 @@ -2285,6 +2287,7 @@ const struct inode_operations ocfs2_file
6366         .setattr        = ocfs2_setattr,
6367         .getattr        = ocfs2_getattr,
6368         .permission     = ocfs2_permission,
6369 +       .sync_flags     = ocfs2_sync_flags,
6370         .fallocate      = ocfs2_fallocate,
6371  };
6372  
6373 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/inode.c
6374 --- linux-2.6.27.25/fs/ocfs2/inode.c    2008-07-13 23:51:29.000000000 +0200
6375 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/inode.c       2008-10-13 14:54:20.000000000 +0200
6376 @@ -28,6 +28,7 @@
6377  #include <linux/slab.h>
6378  #include <linux/highmem.h>
6379  #include <linux/pagemap.h>
6380 +#include <linux/vs_tag.h>
6381  
6382  #include <asm/byteorder.h>
6383  
6384 @@ -42,6 +43,7 @@
6385  #include "file.h"
6386  #include "heartbeat.h"
6387  #include "inode.h"
6388 +#include "ioctl.h"
6389  #include "journal.h"
6390  #include "namei.h"
6391  #include "suballoc.h"
6392 @@ -74,11 +76,13 @@ void ocfs2_set_inode_flags(struct inode 
6393  {
6394         unsigned int flags = OCFS2_I(inode)->ip_attr;
6395  
6396 -       inode->i_flags &= ~(S_IMMUTABLE |
6397 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6398                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6399  
6400         if (flags & OCFS2_IMMUTABLE_FL)
6401                 inode->i_flags |= S_IMMUTABLE;
6402 +       if (flags & OCFS2_IXUNLINK_FL)
6403 +               inode->i_flags |= S_IXUNLINK;
6404  
6405         if (flags & OCFS2_SYNC_FL)
6406                 inode->i_flags |= S_SYNC;
6407 @@ -88,25 +92,85 @@ void ocfs2_set_inode_flags(struct inode 
6408                 inode->i_flags |= S_NOATIME;
6409         if (flags & OCFS2_DIRSYNC_FL)
6410                 inode->i_flags |= S_DIRSYNC;
6411 +
6412 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6413 +
6414 +       if (flags & OCFS2_BARRIER_FL)
6415 +               inode->i_vflags |= V_BARRIER;
6416 +       if (flags & OCFS2_COW_FL)
6417 +               inode->i_vflags |= V_COW;
6418  }
6419  
6420  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6421  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6422  {
6423         unsigned int flags = oi->vfs_inode.i_flags;
6424 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6425 +
6426 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6427 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6428 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6429 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6430 +
6431 +       if (flags & S_IMMUTABLE)
6432 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6433 +       if (flags & S_IXUNLINK)
6434 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6435  
6436 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6437 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6438         if (flags & S_SYNC)
6439                 oi->ip_attr |= OCFS2_SYNC_FL;
6440         if (flags & S_APPEND)
6441                 oi->ip_attr |= OCFS2_APPEND_FL;
6442 -       if (flags & S_IMMUTABLE)
6443 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6444         if (flags & S_NOATIME)
6445                 oi->ip_attr |= OCFS2_NOATIME_FL;
6446         if (flags & S_DIRSYNC)
6447                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6448 +
6449 +       if (vflags & V_BARRIER)
6450 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6451 +       if (vflags & V_COW)
6452 +               oi->ip_attr |= OCFS2_COW_FL;
6453 +}
6454 +
6455 +int ocfs2_sync_flags(struct inode *inode)
6456 +{
6457 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6458 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6459 +       handle_t *handle = NULL;
6460 +       struct buffer_head *bh = NULL;
6461 +       int status;
6462 +
6463 +       status = ocfs2_inode_lock(inode, &bh, 1);
6464 +       if (status < 0) {
6465 +               mlog_errno(status);
6466 +               goto bail;
6467 +       }
6468 +
6469 +       status = -EROFS;
6470 +       if (IS_RDONLY(inode))
6471 +               goto bail_unlock;
6472 +
6473 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6474 +       if (IS_ERR(handle)) {
6475 +               status = PTR_ERR(handle);
6476 +               mlog_errno(status);
6477 +               goto bail_unlock;
6478 +       }
6479 +
6480 +       ocfs2_get_inode_flags(ocfs2_inode);
6481 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6482 +       if (status < 0)
6483 +               mlog_errno(status);
6484 +
6485 +       ocfs2_commit_trans(osb, handle);
6486 +bail_unlock:
6487 +       ocfs2_inode_unlock(inode, 1);
6488 +bail:
6489 +       if (bh)
6490 +               brelse(bh);
6491 +
6492 +       mlog_exit(status);
6493 +       return status;
6494  }
6495  
6496  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6497 @@ -219,6 +283,8 @@ int ocfs2_populate_inode(struct inode *i
6498         struct super_block *sb;
6499         struct ocfs2_super *osb;
6500         int status = -EINVAL;
6501 +       uid_t uid;
6502 +       gid_t gid;
6503  
6504         mlog_entry("(0x%p, size:%llu)\n", inode,
6505                    (unsigned long long)le64_to_cpu(fe->i_size));
6506 @@ -254,8 +320,12 @@ int ocfs2_populate_inode(struct inode *i
6507         inode->i_generation = le32_to_cpu(fe->i_generation);
6508         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6509         inode->i_mode = le16_to_cpu(fe->i_mode);
6510 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6511 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6512 +       uid = le32_to_cpu(fe->i_uid);
6513 +       gid = le32_to_cpu(fe->i_gid);
6514 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6515 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6516 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6517 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6518  
6519         /* Fast symlinks will have i_size but no allocated clusters. */
6520         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6521 @@ -1230,8 +1300,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6522  
6523         fe->i_size = cpu_to_le64(i_size_read(inode));
6524         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6525 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6526 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6527 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6528 +               inode->i_uid, inode->i_tag));
6529 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6530 +               inode->i_gid, inode->i_tag));
6531 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6532         fe->i_mode = cpu_to_le16(inode->i_mode);
6533         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6534         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6535 @@ -1259,16 +1332,25 @@ leave:
6536  void ocfs2_refresh_inode(struct inode *inode,
6537                          struct ocfs2_dinode *fe)
6538  {
6539 +       uid_t uid;
6540 +       gid_t gid;
6541 +
6542         spin_lock(&OCFS2_I(inode)->ip_lock);
6543  
6544         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6545         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6546 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6547 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6548         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6549         ocfs2_set_inode_flags(inode);
6550         i_size_write(inode, le64_to_cpu(fe->i_size));
6551         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6552 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6553 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6554 +       uid = le32_to_cpu(fe->i_uid);
6555 +       gid = le32_to_cpu(fe->i_gid);
6556 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6557 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6558 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6559 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6560         inode->i_mode = le16_to_cpu(fe->i_mode);
6561         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6562                 inode->i_blocks = 0;
6563 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/inode.h linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/inode.h
6564 --- linux-2.6.27.25/fs/ocfs2/inode.h    2008-07-13 23:51:29.000000000 +0200
6565 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/inode.h       2008-10-13 14:54:20.000000000 +0200
6566 @@ -143,6 +143,7 @@ int ocfs2_aio_write(struct file *file, s
6567  
6568  void ocfs2_set_inode_flags(struct inode *inode);
6569  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6570 +int ocfs2_sync_flags(struct inode *inode);
6571  
6572  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6573  {
6574 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ioctl.c
6575 --- linux-2.6.27.25/fs/ocfs2/ioctl.c    2008-07-13 23:51:29.000000000 +0200
6576 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ioctl.c       2008-10-13 14:54:20.000000000 +0200
6577 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6578         return status;
6579  }
6580  
6581 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6582 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6583                                 unsigned mask)
6584  {
6585         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6586 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6587         if (!S_ISDIR(inode->i_mode))
6588                 flags &= ~OCFS2_DIRSYNC_FL;
6589  
6590 +       if (IS_BARRIER(inode)) {
6591 +               vxwprintk_task(1, "messing with the barrier.");
6592 +               goto bail_unlock;
6593 +       }
6594 +
6595         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6596         if (IS_ERR(handle)) {
6597                 status = PTR_ERR(handle);
6598 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/ioctl.h linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ioctl.h
6599 --- linux-2.6.27.25/fs/ocfs2/ioctl.h    2008-07-13 23:51:29.000000000 +0200
6600 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ioctl.h       2008-10-13 14:54:20.000000000 +0200
6601 @@ -10,6 +10,9 @@
6602  #ifndef OCFS2_IOCTL_H
6603  #define OCFS2_IOCTL_H
6604  
6605 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6606 +                               unsigned mask);
6607 +
6608  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6609  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6610  
6611 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/namei.c
6612 --- linux-2.6.27.25/fs/ocfs2/namei.c    2008-07-13 23:51:29.000000000 +0200
6613 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/namei.c       2008-10-13 14:54:20.000000000 +0200
6614 @@ -40,6 +40,7 @@
6615  #include <linux/types.h>
6616  #include <linux/slab.h>
6617  #include <linux/highmem.h>
6618 +#include <linux/vs_tag.h>
6619  
6620  #define MLOG_MASK_PREFIX ML_NAMEI
6621  #include <cluster/masklog.h>
6622 @@ -366,6 +367,9 @@ static int ocfs2_mknod_locked(struct ocf
6623         u64 fe_blkno = 0;
6624         u16 suballoc_bit;
6625         struct inode *inode = NULL;
6626 +       uid_t uid;
6627 +       gid_t gid;
6628 +       tag_t tag;
6629  
6630         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
6631                    (unsigned long)dev, dentry->d_name.len,
6632 @@ -425,13 +429,19 @@ static int ocfs2_mknod_locked(struct ocf
6633         fe->i_blkno = cpu_to_le64(fe_blkno);
6634         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6635         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6636 -       fe->i_uid = cpu_to_le32(current->fsuid);
6637 +
6638 +       tag = dx_current_fstag(osb->sb);
6639 +       uid = current->fsuid;
6640         if (dir->i_mode & S_ISGID) {
6641 -               fe->i_gid = cpu_to_le32(dir->i_gid);
6642 +               gid = dir->i_gid;
6643                 if (S_ISDIR(mode))
6644                         mode |= S_ISGID;
6645         } else
6646 -               fe->i_gid = cpu_to_le32(current->fsgid);
6647 +               gid = current->fsgid;
6648 +
6649 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
6650 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
6651 +       inode->i_tag = tag;
6652         fe->i_mode = cpu_to_le16(mode);
6653         if (S_ISCHR(mode) || S_ISBLK(mode))
6654                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6655 @@ -1917,5 +1927,6 @@ const struct inode_operations ocfs2_dir_
6656         .rename         = ocfs2_rename,
6657         .setattr        = ocfs2_setattr,
6658         .getattr        = ocfs2_getattr,
6659 +       .sync_flags     = ocfs2_sync_flags,
6660         .permission     = ocfs2_permission,
6661  };
6662 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/ocfs2_fs.h linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ocfs2_fs.h
6663 --- linux-2.6.27.25/fs/ocfs2/ocfs2_fs.h 2008-10-13 14:52:06.000000000 +0200
6664 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ocfs2_fs.h    2008-10-13 14:54:20.000000000 +0200
6665 @@ -195,18 +195,23 @@
6666  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6667  
6668  /* Inode attributes, keep in sync with EXT2 */
6669 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6670 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6671 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6672 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6673 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6674 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6675 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6676 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6677 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6678 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6679 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6680 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6681 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6682 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6683 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6684 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6685 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6686  
6687 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6688 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6689 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6690 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6691 +
6692 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6693 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6694 +
6695 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6696 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6697  
6698  /*
6699   * Extent record flags (e_node.leaf.flags)
6700 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/ocfs2.h linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ocfs2.h
6701 --- linux-2.6.27.25/fs/ocfs2/ocfs2.h    2008-10-13 14:52:06.000000000 +0200
6702 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/ocfs2.h       2008-10-13 14:54:20.000000000 +0200
6703 @@ -184,6 +184,7 @@ enum ocfs2_mount_options
6704         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
6705         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
6706         OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
6707 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
6708  };
6709  
6710  #define OCFS2_OSB_SOFT_RO      0x0001
6711 diff -NurpP --minimal linux-2.6.27.25/fs/ocfs2/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/super.c
6712 --- linux-2.6.27.25/fs/ocfs2/super.c    2008-10-13 14:52:06.000000000 +0200
6713 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/ocfs2/super.c       2008-10-13 14:54:20.000000000 +0200
6714 @@ -154,6 +154,7 @@ enum {
6715         Opt_localalloc,
6716         Opt_localflocks,
6717         Opt_stack,
6718 +       Opt_tag, Opt_notag, Opt_tagid,
6719         Opt_err,
6720  };
6721  
6722 @@ -173,6 +174,9 @@ static match_table_t tokens = {
6723         {Opt_localalloc, "localalloc=%d"},
6724         {Opt_localflocks, "localflocks"},
6725         {Opt_stack, "cluster_stack=%s"},
6726 +       {Opt_tag, "tag"},
6727 +       {Opt_notag, "notag"},
6728 +       {Opt_tagid, "tagid=%u"},
6729         {Opt_err, NULL}
6730  };
6731  
6732 @@ -392,6 +396,13 @@ static int ocfs2_remount(struct super_bl
6733                 goto out;
6734         }
6735  
6736 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6737 +               !(sb->s_flags & MS_TAGGED)) {
6738 +               ret = -EINVAL;
6739 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6740 +               goto out;
6741 +       }
6742 +
6743         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6744             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6745                 ret = -EINVAL;
6746 @@ -725,6 +736,9 @@ static int ocfs2_fill_super(struct super
6747  
6748         ocfs2_complete_mount_recovery(osb);
6749  
6750 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6751 +               sb->s_flags |= MS_TAGGED;
6752 +
6753         if (ocfs2_mount_local(osb))
6754                 snprintf(nodestr, sizeof(nodestr), "local");
6755         else
6756 @@ -918,6 +932,20 @@ static int ocfs2_parse_options(struct su
6757                                OCFS2_STACK_LABEL_LEN);
6758                         mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
6759                         break;
6760 +#ifndef CONFIG_TAGGING_NONE
6761 +               case Opt_tag:
6762 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6763 +                       break;
6764 +               case Opt_notag:
6765 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6766 +                       break;
6767 +#endif
6768 +#ifdef CONFIG_PROPAGATE
6769 +               case Opt_tagid:
6770 +                       /* use args[0] */
6771 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6772 +                       break;
6773 +#endif
6774                 default:
6775                         mlog(ML_ERROR,
6776                              "Unrecognized mount option \"%s\" "
6777 diff -NurpP --minimal linux-2.6.27.25/fs/open.c linux-2.6.27.25-vs2.3.0.36.6/fs/open.c
6778 --- linux-2.6.27.25/fs/open.c   2009-06-15 17:18:32.000000000 +0200
6779 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/open.c      2009-02-03 17:59:04.000000000 +0100
6780 @@ -29,22 +29,31 @@
6781  #include <linux/rcupdate.h>
6782  #include <linux/audit.h>
6783  #include <linux/falloc.h>
6784 +#include <linux/vs_base.h>
6785 +#include <linux/vs_limit.h>
6786 +#include <linux/vs_dlimit.h>
6787 +#include <linux/vs_tag.h>
6788 +#include <linux/vs_cowbl.h>
6789  
6790  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6791  {
6792         int retval = -ENODEV;
6793  
6794         if (dentry) {
6795 +               struct super_block *sb = dentry->d_sb;
6796 +
6797                 retval = -ENOSYS;
6798 -               if (dentry->d_sb->s_op->statfs) {
6799 +               if (sb->s_op->statfs) {
6800                         memset(buf, 0, sizeof(*buf));
6801                         retval = security_sb_statfs(dentry);
6802                         if (retval)
6803                                 return retval;
6804 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6805 +                       retval = sb->s_op->statfs(dentry, buf);
6806                         if (retval == 0 && buf->f_frsize == 0)
6807                                 buf->f_frsize = buf->f_bsize;
6808                 }
6809 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6810 +                       vx_vsi_statfs(sb, buf);
6811         }
6812         return retval;
6813  }
6814 @@ -643,6 +652,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6815         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6816         if (error)
6817                 goto out;
6818 +
6819 +       error = cow_check_and_break(&path);
6820 +       if (error)
6821 +               goto dput_and_out;
6822         inode = path.dentry->d_inode;
6823  
6824         error = mnt_want_write(path.mnt);
6825 @@ -676,11 +689,11 @@ static int chown_common(struct dentry * 
6826         newattrs.ia_valid =  ATTR_CTIME;
6827         if (user != (uid_t) -1) {
6828                 newattrs.ia_valid |= ATTR_UID;
6829 -               newattrs.ia_uid = user;
6830 +               newattrs.ia_uid = dx_map_uid(user);
6831         }
6832         if (group != (gid_t) -1) {
6833                 newattrs.ia_valid |= ATTR_GID;
6834 -               newattrs.ia_gid = group;
6835 +               newattrs.ia_gid = dx_map_gid(group);
6836         }
6837         if (!S_ISDIR(inode->i_mode))
6838                 newattrs.ia_valid |=
6839 @@ -703,7 +716,11 @@ SYSCALL_DEFINE3(chown, const char __user
6840         error = mnt_want_write(path.mnt);
6841         if (error)
6842                 goto out_release;
6843 -       error = chown_common(path.dentry, user, group);
6844 +#ifdef CONFIG_VSERVER_COWBL
6845 +       error = cow_check_and_break(&path);
6846 +       if (!error)
6847 +#endif
6848 +               error = chown_common(path.dentry, user, group);
6849         mnt_drop_write(path.mnt);
6850  out_release:
6851         path_put(&path);
6852 @@ -728,7 +745,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6853         error = mnt_want_write(path.mnt);
6854         if (error)
6855                 goto out_release;
6856 -       error = chown_common(path.dentry, user, group);
6857 +#ifdef CONFIG_VSERVER_COWBL
6858 +       error = cow_check_and_break(&path);
6859 +       if (!error)
6860 +#endif
6861 +               error = chown_common(path.dentry, user, group);
6862         mnt_drop_write(path.mnt);
6863  out_release:
6864         path_put(&path);
6865 @@ -747,7 +768,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6866         error = mnt_want_write(path.mnt);
6867         if (error)
6868                 goto out_release;
6869 -       error = chown_common(path.dentry, user, group);
6870 +#ifdef CONFIG_VSERVER_COWBL
6871 +       error = cow_check_and_break(&path);
6872 +       if (!error)
6873 +#endif
6874 +               error = chown_common(path.dentry, user, group);
6875         mnt_drop_write(path.mnt);
6876  out_release:
6877         path_put(&path);
6878 @@ -986,6 +1011,7 @@ static void __put_unused_fd(struct files
6879         __FD_CLR(fd, fdt->open_fds);
6880         if (fd < files->next_fd)
6881                 files->next_fd = fd;
6882 +       vx_openfd_dec(fd);
6883  }
6884  
6885  void put_unused_fd(unsigned int fd)
6886 diff -NurpP --minimal linux-2.6.27.25/fs/proc/array.c linux-2.6.27.25-vs2.3.0.36.6/fs/proc/array.c
6887 --- linux-2.6.27.25/fs/proc/array.c     2009-06-15 17:18:32.000000000 +0200
6888 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/array.c        2009-05-20 02:14:39.000000000 +0200
6889 @@ -82,6 +82,8 @@
6890  #include <linux/pid_namespace.h>
6891  #include <linux/ptrace.h>
6892  #include <linux/tracehook.h>
6893 +#include <linux/vs_context.h>
6894 +#include <linux/vs_network.h>
6895  
6896  #include <asm/pgtable.h>
6897  #include <asm/processor.h>
6898 @@ -143,8 +145,9 @@ static const char *task_state_array[] = 
6899         "D (disk sleep)",       /*  2 */
6900         "T (stopped)",          /*  4 */
6901         "T (tracing stop)",     /*  8 */
6902 -       "Z (zombie)",           /* 16 */
6903 -       "X (dead)"              /* 32 */
6904 +       "H (on hold)",          /* 16 */
6905 +       "Z (zombie)",           /* 32 */
6906 +       "X (dead)",             /* 64 */
6907  };
6908  
6909  static inline const char *get_task_state(struct task_struct *tsk)
6910 @@ -170,6 +173,9 @@ static inline void task_state(struct seq
6911         rcu_read_lock();
6912         ppid = pid_alive(p) ?
6913                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6914 +       if (unlikely(vx_current_initpid(p->pid)))
6915 +               ppid = 0;
6916 +
6917         tpid = 0;
6918         if (pid_alive(p)) {
6919                 struct task_struct *tracer = tracehook_tracer_task(p);
6920 @@ -287,7 +293,7 @@ static inline void task_sig(struct seq_f
6921  }
6922  
6923  static void render_cap_t(struct seq_file *m, const char *header,
6924 -                       kernel_cap_t *a)
6925 +                       struct vx_info *vxi, kernel_cap_t *a)
6926  {
6927         unsigned __capi;
6928  
6929 @@ -301,10 +307,10 @@ static void render_cap_t(struct seq_file
6930  
6931  static inline void task_cap(struct seq_file *m, struct task_struct *p)
6932  {
6933 -       render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
6934 -       render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
6935 -       render_cap_t(m, "CapEff:\t", &p->cap_effective);
6936 -       render_cap_t(m, "CapBnd:\t", &p->cap_bset);
6937 +       render_cap_t(m, "CapInh:\t", p->vx_info, &p->cap_inheritable);
6938 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &p->cap_permitted);
6939 +       render_cap_t(m, "CapEff:\t", p->vx_info, &p->cap_effective);
6940 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &p->cap_bset);
6941  }
6942  
6943  static inline void task_context_switch_counts(struct seq_file *m,
6944 @@ -316,6 +322,45 @@ static inline void task_context_switch_c
6945                         p->nivcsw);
6946  }
6947  
6948 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6949 +                       struct pid *pid, struct task_struct *task)
6950 +{
6951 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6952 +                       "Count:\t%u\n"
6953 +                       "uts:\t%p(%c)\n"
6954 +                       "ipc:\t%p(%c)\n"
6955 +                       "mnt:\t%p(%c)\n"
6956 +                       "pid:\t%p(%c)\n"
6957 +                       "user:\t%p(%c)\n"
6958 +                       "net:\t%p(%c)\n",
6959 +                       task->nsproxy,
6960 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6961 +                       atomic_read(&task->nsproxy->count),
6962 +                       task->nsproxy->uts_ns,
6963 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6964 +                       task->nsproxy->ipc_ns,
6965 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6966 +                       task->nsproxy->mnt_ns,
6967 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6968 +                       task->nsproxy->pid_ns,
6969 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6970 +                       task->nsproxy->user_ns,
6971 +                       (task->nsproxy->user_ns == init_task.nsproxy->user_ns ? 'I' : '-'),
6972 +                       task->nsproxy->net_ns,
6973 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6974 +       return 0;
6975 +}
6976 +
6977 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6978 +{
6979 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6980 +               return;
6981 +
6982 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6983 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6984 +}
6985 +
6986 +
6987  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6988                         struct pid *pid, struct task_struct *task)
6989  {
6990 @@ -331,6 +376,7 @@ int proc_pid_status(struct seq_file *m, 
6991         task_sig(m, task);
6992         task_cap(m, task);
6993         cpuset_task_status_allowed(m, task);
6994 +       task_vs_id(m, task);
6995  #if defined(CONFIG_S390)
6996         task_show_regs(m, task);
6997  #endif
6998 @@ -447,6 +493,17 @@ static int do_task_stat(struct seq_file 
6999         /* convert nsec -> ticks */
7000         start_time = nsec_to_clock_t(start_time);
7001  
7002 +       /* fixup start time for virt uptime */
7003 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
7004 +               unsigned long long bias =
7005 +                       current->vx_info->cvirt.bias_clock;
7006 +
7007 +               if (start_time > bias)
7008 +                       start_time -= bias;
7009 +               else
7010 +                       start_time = 0;
7011 +       }
7012 +
7013         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
7014  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
7015  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
7016 diff -NurpP --minimal linux-2.6.27.25/fs/proc/base.c linux-2.6.27.25-vs2.3.0.36.6/fs/proc/base.c
7017 --- linux-2.6.27.25/fs/proc/base.c      2009-06-15 17:18:32.000000000 +0200
7018 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/base.c 2009-05-15 22:57:04.000000000 +0200
7019 @@ -79,6 +79,8 @@
7020  #include <linux/oom.h>
7021  #include <linux/elf.h>
7022  #include <linux/pid_namespace.h>
7023 +#include <linux/vs_context.h>
7024 +#include <linux/vs_network.h>
7025  #include "internal.h"
7026  
7027  /* NOTE:
7028 @@ -1424,6 +1426,8 @@ static struct inode *proc_pid_make_inode
7029                 inode->i_uid = task->euid;
7030                 inode->i_gid = task->egid;
7031         }
7032 +       /* procfs is xid tagged */
7033 +       inode->i_tag = (tag_t)vx_task_xid(task);
7034         security_task_to_inode(task, inode);
7035  
7036  out:
7037 @@ -1964,6 +1968,13 @@ static struct dentry *proc_pident_lookup
7038         if (!task)
7039                 goto out_no_task;
7040  
7041 +       /* TODO: maybe we can come up with a generic approach? */
7042 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7043 +               (dentry->d_name.len == 5) &&
7044 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7045 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7046 +               goto out;
7047 +
7048         /*
7049          * Yes, it does not scale. And it should not. Don't add
7050          * new entries into /proc/<tgid>/ without very good reasons.
7051 @@ -2351,7 +2362,7 @@ out_iput:
7052  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7053  {
7054         struct dentry *error;
7055 -       struct task_struct *task = get_proc_task(dir);
7056 +       struct task_struct *task = get_proc_task_real(dir);
7057         const struct pid_entry *p, *last;
7058  
7059         error = ERR_PTR(-ENOENT);
7060 @@ -2434,6 +2445,9 @@ static int proc_tgid_io_accounting(struc
7061  static const struct file_operations proc_task_operations;
7062  static const struct inode_operations proc_task_inode_operations;
7063  
7064 +extern int proc_pid_vx_info(struct task_struct *, char *);
7065 +extern int proc_pid_nx_info(struct task_struct *, char *);
7066 +
7067  static const struct pid_entry tgid_base_stuff[] = {
7068         DIR("task",       S_IRUGO|S_IXUGO, task),
7069         DIR("fd",         S_IRUSR|S_IXUSR, fd),
7070 @@ -2488,6 +2502,8 @@ static const struct pid_entry tgid_base_
7071  #ifdef CONFIG_CGROUPS
7072         REG("cgroup",  S_IRUGO, cgroup),
7073  #endif
7074 +       INF("vinfo",      S_IRUGO, pid_vx_info),
7075 +       INF("ninfo",      S_IRUGO, pid_nx_info),
7076         INF("oom_score",  S_IRUGO, oom_score),
7077         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
7078  #ifdef CONFIG_AUDITSYSCALL
7079 @@ -2503,6 +2519,7 @@ static const struct pid_entry tgid_base_
7080  #ifdef CONFIG_TASK_IO_ACCOUNTING
7081         INF("io",       S_IRUGO, tgid_io_accounting),
7082  #endif
7083 +       ONE("nsproxy",  S_IRUGO, pid_nsproxy),
7084  };
7085  
7086  static int proc_tgid_base_readdir(struct file * filp,
7087 @@ -2699,7 +2716,7 @@ retry:
7088         iter.task = NULL;
7089         pid = find_ge_pid(iter.tgid, ns);
7090         if (pid) {
7091 -               iter.tgid = pid_nr_ns(pid, ns);
7092 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7093                 iter.task = pid_task(pid, PIDTYPE_PID);
7094                 /* What we to know is if the pid we have find is the
7095                  * pid of a thread_group_leader.  Testing for task
7096 @@ -2729,7 +2746,7 @@ static int proc_pid_fill_cache(struct fi
7097         struct tgid_iter iter)
7098  {
7099         char name[PROC_NUMBUF];
7100 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7101 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7102         return proc_fill_cache(filp, dirent, filldir, name, len,
7103                                 proc_pid_instantiate, iter.task, NULL);
7104  }
7105 @@ -2738,7 +2755,7 @@ static int proc_pid_fill_cache(struct fi
7106  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7107  {
7108         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7109 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7110 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7111         struct tgid_iter iter;
7112         struct pid_namespace *ns;
7113  
7114 @@ -2758,6 +2775,8 @@ int proc_pid_readdir(struct file * filp,
7115              iter.task;
7116              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7117                 filp->f_pos = iter.tgid + TGID_OFFSET;
7118 +               if (!vx_proc_task_visible(iter.task))
7119 +                       continue;
7120                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7121                         put_task_struct(iter.task);
7122                         goto out;
7123 @@ -2900,6 +2919,8 @@ static struct dentry *proc_task_lookup(s
7124         tid = name_to_int(dentry);
7125         if (tid == ~0U)
7126                 goto out;
7127 +       if (vx_current_initpid(tid))
7128 +               goto out;
7129  
7130         ns = dentry->d_sb->s_fs_info;
7131         rcu_read_lock();
7132 diff -NurpP --minimal linux-2.6.27.25/fs/proc/generic.c linux-2.6.27.25-vs2.3.0.36.6/fs/proc/generic.c
7133 --- linux-2.6.27.25/fs/proc/generic.c   2008-10-13 14:52:06.000000000 +0200
7134 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/generic.c      2008-10-13 14:54:20.000000000 +0200
7135 @@ -21,6 +21,7 @@
7136  #include <linux/bitops.h>
7137  #include <linux/spinlock.h>
7138  #include <linux/completion.h>
7139 +#include <linux/vserver/inode.h>
7140  #include <asm/uaccess.h>
7141  
7142  #include "internal.h"
7143 @@ -384,6 +385,8 @@ struct dentry *proc_lookup_de(struct pro
7144         for (de = de->subdir; de ; de = de->next) {
7145                 if (de->namelen != dentry->d_name.len)
7146                         continue;
7147 +                       if (!vx_hide_check(0, de->vx_flags))
7148 +                               continue;
7149                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7150                         unsigned int ino;
7151  
7152 @@ -392,6 +395,8 @@ struct dentry *proc_lookup_de(struct pro
7153                         spin_unlock(&proc_subdir_lock);
7154                         error = -EINVAL;
7155                         inode = proc_get_inode(dir->i_sb, ino, de);
7156 +                               /* generic proc entries belong to the host */
7157 +                               inode->i_tag = 0;
7158                         goto out_unlock;
7159                 }
7160         }
7161 @@ -472,6 +477,8 @@ int proc_readdir_de(struct proc_dir_entr
7162  
7163                                 /* filldir passes info to user space */
7164                                 de_get(de);
7165 +                               if (!vx_hide_check(0, de->vx_flags))
7166 +                                       goto skip;
7167                                 spin_unlock(&proc_subdir_lock);
7168                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7169                                             de->low_ino, de->mode >> 12) < 0) {
7170 @@ -479,6 +486,7 @@ int proc_readdir_de(struct proc_dir_entr
7171                                         goto out;
7172                                 }
7173                                 spin_lock(&proc_subdir_lock);
7174 +                       skip:
7175                                 filp->f_pos++;
7176                                 next = de->next;
7177                                 de_put(de);
7178 @@ -593,6 +601,7 @@ static struct proc_dir_entry *__proc_cre
7179         ent->nlink = nlink;
7180         atomic_set(&ent->count, 1);
7181         ent->pde_users = 0;
7182 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7183         spin_lock_init(&ent->pde_unload_lock);
7184         ent->pde_unload_completion = NULL;
7185         INIT_LIST_HEAD(&ent->pde_openers);
7186 @@ -616,7 +625,8 @@ struct proc_dir_entry *proc_symlink(cons
7187                                 kfree(ent->data);
7188                                 kfree(ent);
7189                                 ent = NULL;
7190 -                       }
7191 +                       } else
7192 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7193                 } else {
7194                         kfree(ent);
7195                         ent = NULL;
7196 diff -NurpP --minimal linux-2.6.27.25/fs/proc/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/proc/inode.c
7197 --- linux-2.6.27.25/fs/proc/inode.c     2008-10-13 14:52:06.000000000 +0200
7198 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/inode.c        2008-10-13 14:54:20.000000000 +0200
7199 @@ -469,6 +469,8 @@ struct inode *proc_get_inode(struct supe
7200                         inode->i_uid = de->uid;
7201                         inode->i_gid = de->gid;
7202                 }
7203 +               if (de->vx_flags)
7204 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7205                 if (de->size)
7206                         inode->i_size = de->size;
7207                 if (de->nlink)
7208 diff -NurpP --minimal linux-2.6.27.25/fs/proc/internal.h linux-2.6.27.25-vs2.3.0.36.6/fs/proc/internal.h
7209 --- linux-2.6.27.25/fs/proc/internal.h  2008-10-13 14:52:06.000000000 +0200
7210 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/internal.h     2008-10-13 14:54:20.000000000 +0200
7211 @@ -10,6 +10,7 @@
7212   */
7213  
7214  #include <linux/proc_fs.h>
7215 +#include <linux/vs_pid.h>
7216  
7217  extern struct proc_dir_entry proc_root;
7218  #ifdef CONFIG_PROC_SYSCTL
7219 @@ -55,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
7220                                 struct pid *pid, struct task_struct *task);
7221  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7222                                 struct pid *pid, struct task_struct *task);
7223 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7224 +                               struct pid *pid, struct task_struct *task);
7225 +
7226  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7227  
7228  extern const struct file_operations proc_maps_operations;
7229 @@ -75,11 +79,16 @@ static inline struct pid *proc_pid(struc
7230         return PROC_I(inode)->pid;
7231  }
7232  
7233 -static inline struct task_struct *get_proc_task(struct inode *inode)
7234 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7235  {
7236         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7237  }
7238  
7239 +static inline struct task_struct *get_proc_task(struct inode *inode)
7240 +{
7241 +       return vx_get_proc_task(inode, proc_pid(inode));
7242 +}
7243 +
7244  static inline int proc_fd(struct inode *inode)
7245  {
7246         return PROC_I(inode)->fd;
7247 diff -NurpP --minimal linux-2.6.27.25/fs/proc/proc_misc.c linux-2.6.27.25-vs2.3.0.36.6/fs/proc/proc_misc.c
7248 --- linux-2.6.27.25/fs/proc/proc_misc.c 2009-06-15 17:18:32.000000000 +0200
7249 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/proc_misc.c    2009-03-25 14:32:29.000000000 +0100
7250 @@ -57,6 +57,8 @@
7251  #include <asm/div64.h>
7252  #include "internal.h"
7253  
7254 +#include <linux/vs_cvirt.h>
7255 +
7256  #define LOAD_INT(x) ((x) >> FSHIFT)
7257  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
7258  /*
7259 @@ -84,22 +86,38 @@ static int proc_calc_metrics(char *page,
7260  static int loadavg_read_proc(char *page, char **start, off_t off,
7261                                  int count, int *eof, void *data)
7262  {
7263 +       unsigned long running;
7264 +       unsigned int threads;
7265         int a, b, c;
7266         int len;
7267         unsigned long seq;
7268  
7269         do {
7270                 seq = read_seqbegin(&xtime_lock);
7271 -               a = avenrun[0] + (FIXED_1/200);
7272 -               b = avenrun[1] + (FIXED_1/200);
7273 -               c = avenrun[2] + (FIXED_1/200);
7274 +               if (vx_flags(VXF_VIRT_LOAD, 0)) {
7275 +                       struct vx_info *vxi = current->vx_info;
7276 +
7277 +                       a = vxi->cvirt.load[0] + (FIXED_1/200);
7278 +                       b = vxi->cvirt.load[1] + (FIXED_1/200);
7279 +                       c = vxi->cvirt.load[2] + (FIXED_1/200);
7280 +
7281 +                       running = atomic_read(&vxi->cvirt.nr_running);
7282 +                       threads = atomic_read(&vxi->cvirt.nr_threads);
7283 +               } else {
7284 +                       a = avenrun[0] + (FIXED_1/200);
7285 +                       b = avenrun[1] + (FIXED_1/200);
7286 +                       c = avenrun[2] + (FIXED_1/200);
7287 +
7288 +                       running = nr_running();
7289 +                       threads = nr_threads;
7290 +               }
7291         } while (read_seqretry(&xtime_lock, seq));
7292  
7293         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
7294                 LOAD_INT(a), LOAD_FRAC(a),
7295                 LOAD_INT(b), LOAD_FRAC(b),
7296                 LOAD_INT(c), LOAD_FRAC(c),
7297 -               nr_running(), nr_threads,
7298 +               running, threads,
7299                 task_active_pid_ns(current)->last_pid);
7300         return proc_calc_metrics(page, start, off, count, eof, len);
7301  }
7302 @@ -115,6 +133,9 @@ static int uptime_read_proc(char *page, 
7303         do_posix_clock_monotonic_gettime(&uptime);
7304         monotonic_to_bootbased(&uptime);
7305         cputime_to_timespec(idletime, &idle);
7306 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7307 +               vx_vsi_uptime(&uptime, &idle);
7308 +
7309         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
7310                         (unsigned long) uptime.tv_sec,
7311                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7312 @@ -151,7 +172,7 @@ static int meminfo_read_proc(char *page,
7313  
7314         cached = global_page_state(NR_FILE_PAGES) -
7315                         total_swapcache_pages - i.bufferram;
7316 -       if (cached < 0)
7317 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7318                 cached = 0;
7319  
7320         get_vmalloc_info(&vmi);
7321 diff -NurpP --minimal linux-2.6.27.25/fs/proc/root.c linux-2.6.27.25-vs2.3.0.36.6/fs/proc/root.c
7322 --- linux-2.6.27.25/fs/proc/root.c      2008-07-13 23:51:29.000000000 +0200
7323 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/proc/root.c 2008-11-20 00:58:27.000000000 +0100
7324 @@ -19,9 +19,14 @@
7325  #include <linux/smp_lock.h>
7326  #include <linux/mount.h>
7327  #include <linux/pid_namespace.h>
7328 +#include <linux/vserver/inode.h>
7329  
7330  #include "internal.h"
7331  
7332 +struct proc_dir_entry *proc_virtual;
7333 +
7334 +extern void proc_vx_init(void);
7335 +
7336  static int proc_test_super(struct super_block *sb, void *data)
7337  {
7338         return sb->s_fs_info == data;
7339 @@ -137,6 +142,7 @@ void __init proc_root_init(void)
7340  #endif
7341         proc_mkdir("bus", NULL);
7342         proc_sys_init();
7343 +       proc_vx_init();
7344  }
7345  
7346  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7347 @@ -209,6 +215,7 @@ struct proc_dir_entry proc_root = {
7348         .proc_iops      = &proc_root_inode_operations, 
7349         .proc_fops      = &proc_root_operations,
7350         .parent         = &proc_root,
7351 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7352  };
7353  
7354  int pid_ns_prepare_proc(struct pid_namespace *ns)
7355 diff -NurpP --minimal linux-2.6.27.25/fs/quota.c linux-2.6.27.25-vs2.3.0.36.6/fs/quota.c
7356 --- linux-2.6.27.25/fs/quota.c  2009-06-15 17:18:32.000000000 +0200
7357 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/quota.c     2009-02-03 17:59:04.000000000 +0100
7358 @@ -18,6 +18,7 @@
7359  #include <linux/capability.h>
7360  #include <linux/quotaops.h>
7361  #include <linux/types.h>
7362 +#include <linux/vs_context.h>
7363  
7364  /* Check validity of generic quotactl commands */
7365  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7366 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7367         if (cmd == Q_GETQUOTA) {
7368                 if (((type == USRQUOTA && current->euid != id) ||
7369                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7370 -                   !capable(CAP_SYS_ADMIN))
7371 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7372                         return -EPERM;
7373         }
7374         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7375 -               if (!capable(CAP_SYS_ADMIN))
7376 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7377                         return -EPERM;
7378  
7379         return 0;
7380 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7381         if (cmd == Q_XGETQUOTA) {
7382                 if (((type == XQM_USRQUOTA && current->euid != id) ||
7383                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7384 -                    !capable(CAP_SYS_ADMIN))
7385 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7386                         return -EPERM;
7387         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7388 -               if (!capable(CAP_SYS_ADMIN))
7389 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7390                         return -EPERM;
7391         }
7392  
7393 @@ -334,6 +335,46 @@ static int do_quotactl(struct super_bloc
7394         return 0;
7395  }
7396  
7397 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7398 +
7399 +#include <linux/vroot.h>
7400 +#include <linux/major.h>
7401 +#include <linux/module.h>
7402 +#include <linux/kallsyms.h>
7403 +#include <linux/vserver/debug.h>
7404 +
7405 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7406 +
7407 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7408 +
7409 +int register_vroot_grb(vroot_grb_func *func) {
7410 +       int ret = -EBUSY;
7411 +
7412 +       spin_lock(&vroot_grb_lock);
7413 +       if (!vroot_get_real_bdev) {
7414 +               vroot_get_real_bdev = func;
7415 +               ret = 0;
7416 +       }
7417 +       spin_unlock(&vroot_grb_lock);
7418 +       return ret;
7419 +}
7420 +EXPORT_SYMBOL(register_vroot_grb);
7421 +
7422 +int unregister_vroot_grb(vroot_grb_func *func) {
7423 +       int ret = -EINVAL;
7424 +
7425 +       spin_lock(&vroot_grb_lock);
7426 +       if (vroot_get_real_bdev) {
7427 +               vroot_get_real_bdev = NULL;
7428 +               ret = 0;
7429 +       }
7430 +       spin_unlock(&vroot_grb_lock);
7431 +       return ret;
7432 +}
7433 +EXPORT_SYMBOL(unregister_vroot_grb);
7434 +
7435 +#endif
7436 +
7437  /*
7438   * look up a superblock on which quota ops will be performed
7439   * - use the name of a block device to find the superblock thereon
7440 @@ -351,6 +392,22 @@ static inline struct super_block *quotac
7441         putname(tmp);
7442         if (IS_ERR(bdev))
7443                 return ERR_CAST(bdev);
7444 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7445 +       if (bdev && bdev->bd_inode &&
7446 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7447 +               struct block_device *bdnew = (void *)-EINVAL;
7448 +
7449 +               if (vroot_get_real_bdev)
7450 +                       bdnew = vroot_get_real_bdev(bdev);
7451 +               else
7452 +                       vxdprintk(VXD_CBIT(misc, 0),
7453 +                                       "vroot_get_real_bdev not set");
7454 +               bdput(bdev);
7455 +               if (IS_ERR(bdnew))
7456 +                       return ERR_PTR(PTR_ERR(bdnew));
7457 +               bdev = bdnew;
7458 +       }
7459 +#endif
7460         sb = get_super(bdev);
7461         bdput(bdev);
7462         if (!sb)
7463 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/bitmap.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/bitmap.c
7464 --- linux-2.6.27.25/fs/reiserfs/bitmap.c        2008-07-13 23:51:29.000000000 +0200
7465 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/bitmap.c   2008-10-13 14:54:20.000000000 +0200
7466 @@ -13,6 +13,7 @@
7467  #include <linux/reiserfs_fs_sb.h>
7468  #include <linux/reiserfs_fs_i.h>
7469  #include <linux/quotaops.h>
7470 +#include <linux/vs_dlimit.h>
7471  
7472  #define PREALLOCATION_SIZE 9
7473  
7474 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7475         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7476  
7477         journal_mark_dirty(th, s, sbh);
7478 -       if (for_unformatted)
7479 +       if (for_unformatted) {
7480 +               DLIMIT_FREE_BLOCK(inode, 1);
7481                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7482 +       }
7483  }
7484  
7485  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7486 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7487         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7488         int passno = 0;
7489         int nr_allocated = 0;
7490 +       int blocks;
7491  
7492         determine_prealloc_size(hint);
7493         if (!hint->formatted_node) {
7494 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7495                                "reiserquota: allocating %d blocks id=%u",
7496                                amount_needed, hint->inode->i_uid);
7497  #endif
7498 -               quota_ret =
7499 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7500 -               if (quota_ret)  /* Quota exceeded? */
7501 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7502 +                       amount_needed);
7503 +               if (quota_ret)
7504                         return QUOTA_EXCEEDED;
7505 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7506 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7507 +                               amount_needed);
7508 +                       return NO_DISK_SPACE;
7509 +               }
7510 +
7511                 if (hint->preallocate && hint->prealloc_size) {
7512  #ifdef REISERQUOTA_DEBUG
7513                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7514                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7515                                        hint->prealloc_size, hint->inode->i_uid);
7516  #endif
7517 -                       quota_ret =
7518 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7519 -                                                        hint->prealloc_size);
7520 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7521 +                               hint->prealloc_size);
7522 +                       if (!quota_ret &&
7523 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7524 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7525 +                                       hint->prealloc_size);
7526 +                               quota_ret = 1;
7527 +                       }
7528                         if (quota_ret)
7529                                 hint->preallocate = hint->prealloc_size = 0;
7530                 }
7531 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7532                                                nr_allocated,
7533                                                hint->inode->i_uid);
7534  #endif
7535 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7536 +                               /* Free not allocated blocks */
7537 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7538 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7539 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7540                         }
7541                         while (nr_allocated--)
7542                                 reiserfs_free_block(hint->th, hint->inode,
7543 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7544                                REISERFS_I(hint->inode)->i_prealloc_count,
7545                                hint->inode->i_uid);
7546  #endif
7547 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7548 -                                        hint->prealloc_size - nr_allocated -
7549 -                                        REISERFS_I(hint->inode)->
7550 -                                        i_prealloc_count);
7551 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7552 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7553 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7554 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7555         }
7556  
7557         return CARRY_ON;
7558 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/file.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/file.c
7559 --- linux-2.6.27.25/fs/reiserfs/file.c  2008-07-13 23:51:29.000000000 +0200
7560 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/file.c     2008-10-13 14:54:20.000000000 +0200
7561 @@ -306,4 +306,5 @@ const struct inode_operations reiserfs_f
7562         .listxattr = reiserfs_listxattr,
7563         .removexattr = reiserfs_removexattr,
7564         .permission = reiserfs_permission,
7565 +       .sync_flags = reiserfs_sync_flags,
7566  };
7567 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/inode.c
7568 --- linux-2.6.27.25/fs/reiserfs/inode.c 2009-06-15 17:18:32.000000000 +0200
7569 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/inode.c    2009-02-03 17:59:04.000000000 +0100
7570 @@ -18,6 +18,8 @@
7571  #include <linux/writeback.h>
7572  #include <linux/quotaops.h>
7573  #include <linux/swap.h>
7574 +#include <linux/vs_dlimit.h>
7575 +#include <linux/vs_tag.h>
7576  
7577  int reiserfs_commit_write(struct file *f, struct page *page,
7578                           unsigned from, unsigned to);
7579 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7580                  * stat data deletion */
7581                 if (!err) 
7582                         DQUOT_FREE_INODE(inode);
7583 +               DLIMIT_FREE_INODE(inode);
7584  
7585                 if (journal_end(&th, inode->i_sb, jbegin_count))
7586                         goto out;
7587 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7588         struct buffer_head *bh;
7589         struct item_head *ih;
7590         __u32 rdev;
7591 +       uid_t uid;
7592 +       gid_t gid;
7593         //int version = ITEM_VERSION_1;
7594  
7595         bh = PATH_PLAST_BUFFER(path);
7596 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7597                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7598                 unsigned long blocks;
7599  
7600 +               uid = sd_v1_uid(sd);
7601 +               gid = sd_v1_gid(sd);
7602 +
7603                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7604                 set_inode_sd_version(inode, STAT_DATA_V1);
7605                 inode->i_mode = sd_v1_mode(sd);
7606                 inode->i_nlink = sd_v1_nlink(sd);
7607 -               inode->i_uid = sd_v1_uid(sd);
7608 -               inode->i_gid = sd_v1_gid(sd);
7609                 inode->i_size = sd_v1_size(sd);
7610                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7611                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7612 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7613                 // (directories and symlinks)
7614                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7615  
7616 +               uid    = sd_v2_uid(sd);
7617 +               gid    = sd_v2_gid(sd);
7618 +
7619                 inode->i_mode = sd_v2_mode(sd);
7620                 inode->i_nlink = sd_v2_nlink(sd);
7621 -               inode->i_uid = sd_v2_uid(sd);
7622                 inode->i_size = sd_v2_size(sd);
7623 -               inode->i_gid = sd_v2_gid(sd);
7624                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7625                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7626                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7627 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7628                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7629         }
7630  
7631 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7632 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7633 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7634 +
7635         pathrelse(path);
7636         if (S_ISREG(inode->i_mode)) {
7637                 inode->i_op = &reiserfs_file_inode_operations;
7638 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7639  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7640  {
7641         struct stat_data *sd_v2 = (struct stat_data *)sd;
7642 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7643 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7644         __u16 flags;
7645  
7646 +       set_sd_v2_uid(sd_v2, uid);
7647 +       set_sd_v2_gid(sd_v2, gid);
7648         set_sd_v2_mode(sd_v2, inode->i_mode);
7649         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7650 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7651         set_sd_v2_size(sd_v2, size);
7652 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7653         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7654         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7655         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7656 @@ -1771,6 +1784,10 @@ int reiserfs_new_inode(struct reiserfs_t
7657  
7658         BUG_ON(!th->t_trans_id);
7659  
7660 +       if (DLIMIT_ALLOC_INODE(inode)) {
7661 +               err = -ENOSPC;
7662 +               goto out_bad_dlimit;
7663 +       }
7664         if (DQUOT_ALLOC_INODE(inode)) {
7665                 err = -EDQUOT;
7666                 goto out_end_trans;
7667 @@ -1956,6 +1973,9 @@ int reiserfs_new_inode(struct reiserfs_t
7668         DQUOT_FREE_INODE(inode);
7669  
7670        out_end_trans:
7671 +       DLIMIT_FREE_INODE(inode);
7672 +
7673 +      out_bad_dlimit:
7674         journal_end(th, th->t_super, th->t_blocks_allocated);
7675         /* Drop can be outside and it needs more credits so it's better to have it outside */
7676         DQUOT_DROP(inode);
7677 @@ -2842,14 +2862,19 @@ int reiserfs_commit_write(struct file *f
7678  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7679  {
7680         if (reiserfs_attrs(inode->i_sb)) {
7681 -               if (sd_attrs & REISERFS_SYNC_FL)
7682 -                       inode->i_flags |= S_SYNC;
7683 -               else
7684 -                       inode->i_flags &= ~S_SYNC;
7685                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7686                         inode->i_flags |= S_IMMUTABLE;
7687                 else
7688                         inode->i_flags &= ~S_IMMUTABLE;
7689 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7690 +                       inode->i_flags |= S_IXUNLINK;
7691 +               else
7692 +                       inode->i_flags &= ~S_IXUNLINK;
7693 +
7694 +               if (sd_attrs & REISERFS_SYNC_FL)
7695 +                       inode->i_flags |= S_SYNC;
7696 +               else
7697 +                       inode->i_flags &= ~S_SYNC;
7698                 if (sd_attrs & REISERFS_APPEND_FL)
7699                         inode->i_flags |= S_APPEND;
7700                 else
7701 @@ -2862,6 +2887,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7702                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7703                 else
7704                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7705 +
7706 +               if (sd_attrs & REISERFS_BARRIER_FL)
7707 +                       inode->i_vflags |= V_BARRIER;
7708 +               else
7709 +                       inode->i_vflags &= ~V_BARRIER;
7710 +               if (sd_attrs & REISERFS_COW_FL)
7711 +                       inode->i_vflags |= V_COW;
7712 +               else
7713 +                       inode->i_vflags &= ~V_COW;
7714         }
7715  }
7716  
7717 @@ -2872,6 +2906,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7718                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7719                 else
7720                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7721 +               if (inode->i_flags & S_IXUNLINK)
7722 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7723 +               else
7724 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7725 +
7726                 if (inode->i_flags & S_SYNC)
7727                         *sd_attrs |= REISERFS_SYNC_FL;
7728                 else
7729 @@ -2884,6 +2923,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7730                         *sd_attrs |= REISERFS_NOTAIL_FL;
7731                 else
7732                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7733 +
7734 +               if (inode->i_vflags & V_BARRIER)
7735 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7736 +               else
7737 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7738 +               if (inode->i_vflags & V_COW)
7739 +                       *sd_attrs |= REISERFS_COW_FL;
7740 +               else
7741 +                       *sd_attrs &= ~REISERFS_COW_FL;
7742         }
7743  }
7744  
7745 @@ -3051,6 +3099,22 @@ static ssize_t reiserfs_direct_IO(int rw
7746                                   reiserfs_get_blocks_direct_io, NULL);
7747  }
7748  
7749 +int reiserfs_sync_flags(struct inode *inode)
7750 +{
7751 +       u16 oldflags, newflags;
7752 +
7753 +       oldflags = REISERFS_I(inode)->i_attrs;
7754 +       newflags = oldflags;
7755 +       i_attrs_to_sd_attrs(inode, &newflags);
7756 +
7757 +       if (oldflags ^ newflags) {
7758 +               REISERFS_I(inode)->i_attrs = newflags;
7759 +               inode->i_ctime = CURRENT_TIME_SEC;
7760 +               mark_inode_dirty(inode);
7761 +       }
7762 +       return 0;
7763 +}
7764 +
7765  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7766  {
7767         struct inode *inode = dentry->d_inode;
7768 @@ -3104,9 +3168,11 @@ int reiserfs_setattr(struct dentry *dent
7769         }
7770  
7771         error = inode_change_ok(inode, attr);
7772 +
7773         if (!error) {
7774                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7775 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7776 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7777 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7778                         error = reiserfs_chown_xattrs(inode, attr);
7779  
7780                         if (!error) {
7781 @@ -3136,6 +3202,9 @@ int reiserfs_setattr(struct dentry *dent
7782                                         inode->i_uid = attr->ia_uid;
7783                                 if (attr->ia_valid & ATTR_GID)
7784                                         inode->i_gid = attr->ia_gid;
7785 +                               if ((attr->ia_valid & ATTR_TAG) &&
7786 +                                       IS_TAGGED(inode))
7787 +                                       inode->i_tag = attr->ia_tag;
7788                                 mark_inode_dirty(inode);
7789                                 error =
7790                                     journal_end(&th, inode->i_sb, jbegin_count);
7791 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/ioctl.c
7792 --- linux-2.6.27.25/fs/reiserfs/ioctl.c 2008-07-13 23:51:29.000000000 +0200
7793 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/ioctl.c    2008-10-13 14:54:20.000000000 +0200
7794 @@ -7,6 +7,7 @@
7795  #include <linux/mount.h>
7796  #include <linux/reiserfs_fs.h>
7797  #include <linux/time.h>
7798 +#include <linux/mount.h>
7799  #include <asm/uaccess.h>
7800  #include <linux/pagemap.h>
7801  #include <linux/smp_lock.h>
7802 @@ -23,7 +24,7 @@
7803  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7804                    unsigned long arg)
7805  {
7806 -       unsigned int flags;
7807 +       unsigned int flags, oldflags;
7808         int err = 0;
7809  
7810         switch (cmd) {
7811 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7812  
7813                 flags = REISERFS_I(inode)->i_attrs;
7814                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7815 +               flags &= REISERFS_FL_USER_VISIBLE;
7816                 return put_user(flags, (int __user *)arg);
7817         case REISERFS_IOC_SETFLAGS:{
7818                         if (!reiserfs_attrs(inode->i_sb))
7819 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7820                                 err = -EFAULT;
7821                                 goto setflags_out;
7822                         }
7823 +                       if (IS_BARRIER(inode)) {
7824 +                               vxwprintk_task(1, "messing with the barrier.");
7825 +                               return -EACCES;
7826 +                       }
7827                         /*
7828                          * Is it quota file? Do not allow user to mess with it
7829                          */
7830 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7831                                         goto setflags_out;
7832                                 }
7833                         }
7834 +
7835 +                       oldflags = REISERFS_I(inode)->i_attrs;
7836 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7837 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7838                         sd_attrs_to_i_attrs(flags, inode);
7839                         REISERFS_I(inode)->i_attrs = flags;
7840                         inode->i_ctime = CURRENT_TIME_SEC;
7841 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/namei.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/namei.c
7842 --- linux-2.6.27.25/fs/reiserfs/namei.c 2008-07-13 23:51:29.000000000 +0200
7843 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/namei.c    2008-10-13 14:54:20.000000000 +0200
7844 @@ -17,6 +17,7 @@
7845  #include <linux/reiserfs_acl.h>
7846  #include <linux/reiserfs_xattr.h>
7847  #include <linux/quotaops.h>
7848 +#include <linux/vs_tag.h>
7849  
7850  #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; }
7851  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7852 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7853                         reiserfs_write_unlock(dir->i_sb);
7854                         return ERR_PTR(-EACCES);
7855                 }
7856 +               dx_propagate_tag(nd, inode);
7857  
7858                 /* Propogate the priv_object flag so we know we're in the priv tree */
7859                 if (is_reiserfs_priv_object(dir))
7860 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
7861         } else {
7862                 inode->i_gid = current->fsgid;
7863         }
7864 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7865         DQUOT_INIT(inode);
7866         return 0;
7867  }
7868 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
7869         .listxattr = reiserfs_listxattr,
7870         .removexattr = reiserfs_removexattr,
7871         .permission = reiserfs_permission,
7872 +       .sync_flags = reiserfs_sync_flags,
7873  };
7874  
7875  /*
7876 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
7877         .listxattr = reiserfs_listxattr,
7878         .removexattr = reiserfs_removexattr,
7879         .permission = reiserfs_permission,
7880 +       .sync_flags = reiserfs_sync_flags,
7881  
7882  };
7883  
7884 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
7885         .listxattr = reiserfs_listxattr,
7886         .removexattr = reiserfs_removexattr,
7887         .permission = reiserfs_permission,
7888 +       .sync_flags = reiserfs_sync_flags,
7889  
7890  };
7891 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/stree.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/stree.c
7892 --- linux-2.6.27.25/fs/reiserfs/stree.c 2008-07-13 23:51:29.000000000 +0200
7893 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/stree.c    2008-10-13 14:54:20.000000000 +0200
7894 @@ -55,6 +55,7 @@
7895  #include <linux/reiserfs_fs.h>
7896  #include <linux/buffer_head.h>
7897  #include <linux/quotaops.h>
7898 +#include <linux/vs_dlimit.h>
7899  
7900  /* Does the buffer contain a disk block which is in the tree. */
7901  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7902 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7903                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7904                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7905  #endif
7906 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7907         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7908  
7909         /* Return deleted body length */
7910 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7911  #endif
7912                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7913                                                          quota_cut_bytes);
7914 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7915                         }
7916                         break;
7917                 }
7918 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7919                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7920                        quota_cut_bytes, p_s_inode->i_uid, '?');
7921  #endif
7922 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7923         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7924         return n_ret_value;
7925  }
7926 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7927                 pathrelse(p_s_search_path);
7928                 return -EDQUOT;
7929         }
7930 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7931 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7932 +               pathrelse(p_s_search_path);
7933 +               return -ENOSPC;
7934 +       }
7935         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7936                        n_pasted_size);
7937  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7938 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7939                        n_pasted_size, inode->i_uid,
7940                        key2type(&(p_s_key->on_disk_key)));
7941  #endif
7942 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7943         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7944         return retval;
7945  }
7946 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7947                         pathrelse(p_s_path);
7948                         return -EDQUOT;
7949                 }
7950 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7951 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7952 +                       pathrelse(p_s_path);
7953 +                       return -ENOSPC;
7954 +               }
7955         }
7956         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7957                        IH_SIZE + ih_item_len(p_s_ih));
7958 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7959                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7960                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7961  #endif
7962 -       if (inode)
7963 +       if (inode) {
7964 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7965                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7966 +       }
7967         return retval;
7968  }
7969 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/super.c
7970 --- linux-2.6.27.25/fs/reiserfs/super.c 2008-10-13 14:52:06.000000000 +0200
7971 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/super.c    2008-10-13 14:54:20.000000000 +0200
7972 @@ -898,6 +898,14 @@ static int reiserfs_parse_options(struct
7973                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7974                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7975  #endif
7976 +#ifndef CONFIG_TAGGING_NONE
7977 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7978 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7979 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7980 +#endif
7981 +#ifdef CONFIG_PROPAGATE
7982 +               {"tag",.arg_required = 'T',.values = NULL},
7983 +#endif
7984  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7985                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7986                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7987 @@ -1193,6 +1201,12 @@ static int reiserfs_remount(struct super
7988         handle_quota_files(s, qf_names, &qfmt);
7989  #endif
7990  
7991 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7992 +               !(s->s_flags & MS_TAGGED)) {
7993 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7994 +               return -EINVAL;
7995 +       }
7996 +
7997         handle_attrs(s);
7998  
7999         /* Add options that are safe here */
8000 @@ -1657,6 +1671,10 @@ static int reiserfs_fill_super(struct su
8001                 goto error;
8002         }
8003  
8004 +       /* map mount option tagxid */
8005 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
8006 +               s->s_flags |= MS_TAGGED;
8007 +
8008         rs = SB_DISK_SUPER_BLOCK(s);
8009         /* Let's do basic sanity check to verify that underlying device is not
8010            smaller than the filesystem. If the check fails then abort and scream,
8011 diff -NurpP --minimal linux-2.6.27.25/fs/reiserfs/xattr.c linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/xattr.c
8012 --- linux-2.6.27.25/fs/reiserfs/xattr.c 2008-10-13 14:52:06.000000000 +0200
8013 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/reiserfs/xattr.c    2008-10-13 14:54:20.000000000 +0200
8014 @@ -35,6 +35,7 @@
8015  #include <linux/namei.h>
8016  #include <linux/errno.h>
8017  #include <linux/fs.h>
8018 +#include <linux/mount.h>
8019  #include <linux/file.h>
8020  #include <linux/pagemap.h>
8021  #include <linux/xattr.h>
8022 diff -NurpP --minimal linux-2.6.27.25/fs/stat.c linux-2.6.27.25-vs2.3.0.36.6/fs/stat.c
8023 --- linux-2.6.27.25/fs/stat.c   2009-06-15 17:18:32.000000000 +0200
8024 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/stat.c      2009-02-03 17:59:04.000000000 +0100
8025 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
8026         stat->nlink = inode->i_nlink;
8027         stat->uid = inode->i_uid;
8028         stat->gid = inode->i_gid;
8029 +       stat->tag = inode->i_tag;
8030         stat->rdev = inode->i_rdev;
8031         stat->atime = inode->i_atime;
8032         stat->mtime = inode->i_mtime;
8033 diff -NurpP --minimal linux-2.6.27.25/fs/super.c linux-2.6.27.25-vs2.3.0.36.6/fs/super.c
8034 --- linux-2.6.27.25/fs/super.c  2009-06-15 17:18:32.000000000 +0200
8035 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/super.c     2009-02-03 17:59:04.000000000 +0100
8036 @@ -38,6 +38,9 @@
8037  #include <linux/kobject.h>
8038  #include <linux/mutex.h>
8039  #include <linux/file.h>
8040 +#include <linux/devpts_fs.h>
8041 +#include <linux/proc_fs.h>
8042 +#include <linux/vs_context.h>
8043  #include <asm/uaccess.h>
8044  #include "internal.h"
8045  
8046 @@ -887,12 +890,18 @@ struct vfsmount *
8047  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
8048  {
8049         struct vfsmount *mnt;
8050 +       struct super_block *sb;
8051         char *secdata = NULL;
8052         int error;
8053  
8054         if (!type)
8055                 return ERR_PTR(-ENODEV);
8056  
8057 +       error = -EPERM;
8058 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
8059 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
8060 +               goto out;
8061 +
8062         error = -ENOMEM;
8063         mnt = alloc_vfsmnt(name);
8064         if (!mnt)
8065 @@ -913,7 +922,14 @@ vfs_kern_mount(struct file_system_type *
8066                 goto out_free_secdata;
8067         BUG_ON(!mnt->mnt_sb);
8068  
8069 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
8070 +       sb = mnt->mnt_sb;
8071 +       error = -EPERM;
8072 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
8073 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8074 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8075 +               goto out_sb;
8076 +
8077 +       error = security_sb_kern_mount(sb, secdata);
8078         if (error)
8079                 goto out_sb;
8080  
8081 diff -NurpP --minimal linux-2.6.27.25/fs/sysfs/mount.c linux-2.6.27.25-vs2.3.0.36.6/fs/sysfs/mount.c
8082 --- linux-2.6.27.25/fs/sysfs/mount.c    2008-07-13 23:51:29.000000000 +0200
8083 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/sysfs/mount.c       2008-10-13 14:54:20.000000000 +0200
8084 @@ -19,8 +19,6 @@
8085  
8086  #include "sysfs.h"
8087  
8088 -/* Random magic number */
8089 -#define SYSFS_MAGIC 0x62656572
8090  
8091  static struct vfsmount *sysfs_mount;
8092  struct super_block * sysfs_sb = NULL;
8093 @@ -46,7 +44,7 @@ static int sysfs_fill_super(struct super
8094  
8095         sb->s_blocksize = PAGE_CACHE_SIZE;
8096         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8097 -       sb->s_magic = SYSFS_MAGIC;
8098 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8099         sb->s_op = &sysfs_ops;
8100         sb->s_time_gran = 1;
8101         sysfs_sb = sb;
8102 diff -NurpP --minimal linux-2.6.27.25/fs/utimes.c linux-2.6.27.25-vs2.3.0.36.6/fs/utimes.c
8103 --- linux-2.6.27.25/fs/utimes.c 2009-06-15 17:18:32.000000000 +0200
8104 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/utimes.c    2009-02-03 17:59:04.000000000 +0100
8105 @@ -8,6 +8,8 @@
8106  #include <linux/stat.h>
8107  #include <linux/utime.h>
8108  #include <linux/syscalls.h>
8109 +#include <linux/mount.h>
8110 +#include <linux/vs_cowbl.h>
8111  #include <asm/uaccess.h>
8112  #include <asm/unistd.h>
8113  
8114 diff -NurpP --minimal linux-2.6.27.25/fs/xattr.c linux-2.6.27.25-vs2.3.0.36.6/fs/xattr.c
8115 --- linux-2.6.27.25/fs/xattr.c  2009-06-15 17:18:32.000000000 +0200
8116 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xattr.c     2009-02-03 17:59:04.000000000 +0100
8117 @@ -18,6 +18,7 @@
8118  #include <linux/module.h>
8119  #include <linux/fsnotify.h>
8120  #include <linux/audit.h>
8121 +#include <linux/mount.h>
8122  #include <asm/uaccess.h>
8123  
8124  
8125 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_ioctl.c
8126 --- linux-2.6.27.25/fs/xfs/linux-2.6/xfs_ioctl.c        2008-10-13 14:52:06.000000000 +0200
8127 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_ioctl.c   2008-11-12 18:41:58.000000000 +0100
8128 @@ -806,6 +806,10 @@ xfs_merge_ioc_xflags(
8129                 xflags |= XFS_XFLAG_IMMUTABLE;
8130         else
8131                 xflags &= ~XFS_XFLAG_IMMUTABLE;
8132 +       if (flags & FS_IXUNLINK_FL)
8133 +               xflags |= XFS_XFLAG_IXUNLINK;
8134 +       else
8135 +               xflags &= ~XFS_XFLAG_IXUNLINK;
8136         if (flags & FS_APPEND_FL)
8137                 xflags |= XFS_XFLAG_APPEND;
8138         else
8139 @@ -834,6 +838,8 @@ xfs_di2lxflags(
8140  
8141         if (di_flags & XFS_DIFLAG_IMMUTABLE)
8142                 flags |= FS_IMMUTABLE_FL;
8143 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
8144 +               flags |= FS_IXUNLINK_FL;
8145         if (di_flags & XFS_DIFLAG_APPEND)
8146                 flags |= FS_APPEND_FL;
8147         if (di_flags & XFS_DIFLAG_SYNC)
8148 @@ -892,6 +898,8 @@ xfs_set_diflags(
8149         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
8150         if (xflags & XFS_XFLAG_IMMUTABLE)
8151                 di_flags |= XFS_DIFLAG_IMMUTABLE;
8152 +       if (xflags & XFS_XFLAG_IXUNLINK)
8153 +               di_flags |= XFS_DIFLAG_IXUNLINK;
8154         if (xflags & XFS_XFLAG_APPEND)
8155                 di_flags |= XFS_DIFLAG_APPEND;
8156         if (xflags & XFS_XFLAG_SYNC)
8157 @@ -934,6 +942,10 @@ xfs_diflags_to_linux(
8158                 inode->i_flags |= S_IMMUTABLE;
8159         else
8160                 inode->i_flags &= ~S_IMMUTABLE;
8161 +       if (xflags & XFS_XFLAG_IXUNLINK)
8162 +               inode->i_flags |= S_IXUNLINK;
8163 +       else
8164 +               inode->i_flags &= ~S_IXUNLINK;
8165         if (xflags & XFS_XFLAG_APPEND)
8166                 inode->i_flags |= S_APPEND;
8167         else
8168 @@ -1392,10 +1404,18 @@ xfs_ioctl(
8169         case XFS_IOC_FSGETXATTRA:
8170                 return xfs_ioc_fsgetxattr(ip, 1, arg);
8171         case XFS_IOC_FSSETXATTR:
8172 +               if (IS_BARRIER(inode)) {
8173 +                       vxwprintk_task(1, "messing with the barrier.");
8174 +                       return -XFS_ERROR(EACCES);
8175 +               }
8176                 return xfs_ioc_fssetxattr(ip, filp, arg);
8177         case XFS_IOC_GETXFLAGS:
8178                 return xfs_ioc_getxflags(ip, arg);
8179         case XFS_IOC_SETXFLAGS:
8180 +               if (IS_BARRIER(inode)) {
8181 +                       vxwprintk_task(1, "messing with the barrier.");
8182 +                       return -XFS_ERROR(EACCES);
8183 +               }
8184                 return xfs_ioc_setxflags(ip, filp, arg);
8185  
8186         case XFS_IOC_FSSETDM: {
8187 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_iops.c
8188 --- linux-2.6.27.25/fs/xfs/linux-2.6/xfs_iops.c 2008-10-13 14:52:06.000000000 +0200
8189 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_iops.c    2008-11-12 18:41:58.000000000 +0100
8190 @@ -53,6 +53,7 @@
8191  #include <linux/namei.h>
8192  #include <linux/security.h>
8193  #include <linux/falloc.h>
8194 +#include <linux/vs_tag.h>
8195  
8196  /*
8197   * Bring the atime in the XFS inode uptodate.
8198 @@ -558,6 +559,7 @@ xfs_vn_getattr(
8199         stat->nlink = ip->i_d.di_nlink;
8200         stat->uid = ip->i_d.di_uid;
8201         stat->gid = ip->i_d.di_gid;
8202 +       stat->tag = ip->i_d.di_tag;
8203         stat->ino = ip->i_ino;
8204  #if XFS_BIG_INUMS
8205         stat->ino += mp->m_inoadd;
8206 @@ -597,6 +599,12 @@ xfs_vn_getattr(
8207  }
8208  
8209  STATIC int
8210 +xfs_vn_sync_xflags(struct inode *inode)
8211 +{
8212 +       return -xfs_sync_xflags(XFS_I(inode));
8213 +}
8214 +
8215 +STATIC int
8216  xfs_vn_setattr(
8217         struct dentry   *dentry,
8218         struct iattr    *iattr)
8219 @@ -671,6 +679,7 @@ static const struct inode_operations xfs
8220         .removexattr            = generic_removexattr,
8221         .listxattr              = xfs_vn_listxattr,
8222         .fallocate              = xfs_vn_fallocate,
8223 +       .sync_flags             = xfs_vn_sync_xflags,
8224  };
8225  
8226  static const struct inode_operations xfs_dir_inode_operations = {
8227 @@ -696,6 +705,7 @@ static const struct inode_operations xfs
8228         .getxattr               = generic_getxattr,
8229         .removexattr            = generic_removexattr,
8230         .listxattr              = xfs_vn_listxattr,
8231 +       .sync_flags             = xfs_vn_sync_xflags,
8232  };
8233  
8234  static const struct inode_operations xfs_dir_ci_inode_operations = {
8235 @@ -745,6 +755,10 @@ xfs_diflags_to_iflags(
8236                 inode->i_flags |= S_IMMUTABLE;
8237         else
8238                 inode->i_flags &= ~S_IMMUTABLE;
8239 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
8240 +               inode->i_flags |= S_IXUNLINK;
8241 +       else
8242 +               inode->i_flags &= ~S_IXUNLINK;
8243         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8244                 inode->i_flags |= S_APPEND;
8245         else
8246 @@ -757,6 +771,15 @@ xfs_diflags_to_iflags(
8247                 inode->i_flags |= S_NOATIME;
8248         else
8249                 inode->i_flags &= ~S_NOATIME;
8250 +
8251 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8252 +               inode->i_vflags |= V_BARRIER;
8253 +       else
8254 +               inode->i_vflags &= ~V_BARRIER;
8255 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8256 +               inode->i_vflags |= V_COW;
8257 +       else
8258 +               inode->i_vflags &= ~V_COW;
8259  }
8260  
8261  /*
8262 @@ -777,6 +800,7 @@ xfs_setup_inode(
8263         inode->i_nlink  = ip->i_d.di_nlink;
8264         inode->i_uid    = ip->i_d.di_uid;
8265         inode->i_gid    = ip->i_d.di_gid;
8266 +       inode->i_tag    = ip->i_d.di_tag;
8267  
8268         switch (inode->i_mode & S_IFMT) {
8269         case S_IFBLK:
8270 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_linux.h
8271 --- linux-2.6.27.25/fs/xfs/linux-2.6/xfs_linux.h        2008-10-13 14:52:06.000000000 +0200
8272 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_linux.h   2008-10-13 15:35:26.000000000 +0200
8273 @@ -126,6 +126,7 @@
8274  
8275  #define current_cpu()          (raw_smp_processor_id())
8276  #define current_pid()          (current->pid)
8277 +#define current_fstag(cred,vp) (dx_current_fstag(vp->i_sb))
8278  #define current_test_flags(f)  (current->flags & (f))
8279  #define current_set_flags_nested(sp, f)                \
8280                 (*(sp) = current->flags, current->flags |= (f))
8281 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/linux-2.6/xfs_super.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_super.c
8282 --- linux-2.6.27.25/fs/xfs/linux-2.6/xfs_super.c        2009-06-15 17:18:32.000000000 +0200
8283 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/linux-2.6/xfs_super.c   2009-02-03 17:59:04.000000000 +0100
8284 @@ -147,6 +147,9 @@ xfs_args_allocate(
8285  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8286  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8287  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8288 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8289 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8290 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8291  
8292  /*
8293   * Table driven mount option parser.
8294 @@ -155,10 +158,14 @@ xfs_args_allocate(
8295   * in the future, too.
8296   */
8297  enum {
8298 +       Opt_tag, Opt_notag,
8299         Opt_barrier, Opt_nobarrier, Opt_err
8300  };
8301  
8302  static match_table_t tokens = {
8303 +       {Opt_tag, "tagxid"},
8304 +       {Opt_tag, "tag"},
8305 +       {Opt_notag, "notag"},
8306         {Opt_barrier, "barrier"},
8307         {Opt_nobarrier, "nobarrier"},
8308         {Opt_err, NULL}
8309 @@ -383,6 +390,19 @@ xfs_parseargs(
8310                 } else if (!strcmp(this_char, "irixsgid")) {
8311                         cmn_err(CE_WARN,
8312         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8313 +#ifndef CONFIG_TAGGING_NONE
8314 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8315 +                       args->flags2 |= XFSMNT2_TAGGED;
8316 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8317 +                       args->flags2 &= ~XFSMNT2_TAGGED;
8318 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8319 +                       args->flags2 |= XFSMNT2_TAGGED;
8320 +#endif
8321 +#ifdef CONFIG_PROPAGATE
8322 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8323 +                       /* use value */
8324 +                       args->flags2 |= XFSMNT2_TAGGED;
8325 +#endif
8326                 } else {
8327                         cmn_err(CE_WARN,
8328                                 "XFS: unknown mount option [%s].", this_char);
8329 @@ -1301,6 +1321,16 @@ xfs_fs_remount(
8330                 case Opt_nobarrier:
8331                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8332                         break;
8333 +               case Opt_tag:
8334 +                       if (!(sb->s_flags & MS_TAGGED)) {
8335 +                               printk(KERN_INFO
8336 +                                       "XFS: %s: tagging not permitted on remount.\n",
8337 +                                       sb->s_id);
8338 +                               return -EINVAL;
8339 +                       }
8340 +                       break;
8341 +               case Opt_notag:
8342 +                       break;
8343                 default:
8344                         /*
8345                          * Logically we would return an error here to prevent
8346 @@ -1555,6 +1585,9 @@ xfs_start_flags(
8347  
8348         if (ap->flags & XFSMNT_DMAPI)
8349                 mp->m_flags |= XFS_MOUNT_DMAPI;
8350 +
8351 +       if (ap->flags2 & XFSMNT2_TAGGED)
8352 +               mp->m_flags |= XFS_MOUNT_TAGGED;
8353         return 0;
8354  
8355  
8356 @@ -1749,6 +1782,9 @@ xfs_fs_fill_super(
8357  
8358         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
8359  
8360 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8361 +               sb->s_flags |= MS_TAGGED;
8362 +
8363         sb->s_dirt = 1;
8364         sb->s_magic = XFS_SB_MAGIC;
8365         sb->s_blocksize = mp->m_sb.sb_blocksize;
8366 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/quota/xfs_qm_syscalls.c
8367 --- linux-2.6.27.25/fs/xfs/quota/xfs_qm_syscalls.c      2008-10-13 14:52:06.000000000 +0200
8368 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/quota/xfs_qm_syscalls.c 2008-10-24 03:47:08.000000000 +0200
8369 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8370         uint            accflags;
8371         __int64_t       sbflags;
8372  
8373 -       if (!capable(CAP_SYS_ADMIN))
8374 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8375                 return XFS_ERROR(EPERM);
8376  
8377         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8378 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_clnt.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_clnt.h
8379 --- linux-2.6.27.25/fs/xfs/xfs_clnt.h   2008-10-13 14:52:06.000000000 +0200
8380 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_clnt.h      2008-10-13 14:54:20.000000000 +0200
8381 @@ -101,5 +101,6 @@ struct xfs_mount_args {
8382                                                  * I/O size in stat(2) */
8383  #define XFSMNT2_FILESTREAMS    0x00000002      /* enable the filestreams
8384                                                  * allocator */
8385 +#define XFSMNT2_TAGGED         0x10000000      /* context tagging */
8386  
8387  #endif /* __XFS_CLNT_H__ */
8388 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_dinode.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_dinode.h
8389 --- linux-2.6.27.25/fs/xfs/xfs_dinode.h 2008-07-13 23:51:29.000000000 +0200
8390 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_dinode.h    2008-11-12 18:41:59.000000000 +0100
8391 @@ -53,7 +53,9 @@ typedef struct xfs_dinode_core {
8392         __be32          di_gid;         /* owner's group id */
8393         __be32          di_nlink;       /* number of links to file */
8394         __be16          di_projid;      /* owner's project id */
8395 -       __u8            di_pad[8];      /* unused, zeroed space */
8396 +       __be16          di_tag;         /* context tagging */
8397 +       __be16          di_vflags;      /* vserver specific flags */
8398 +       __u8            di_pad[4];      /* unused, zeroed space */
8399         __be16          di_flushiter;   /* incremented on flush */
8400         xfs_timestamp_t di_atime;       /* time last accessed */
8401         xfs_timestamp_t di_mtime;       /* time last modified */
8402 @@ -136,7 +138,9 @@ typedef struct xfs_dinode
8403  #define        XFS_DI_NEXT_UNLINKED    0x1000000
8404  #define        XFS_DI_U                0x2000000
8405  #define        XFS_DI_A                0x4000000
8406 -#define        XFS_DI_NUM_BITS         27
8407 +#define        XFS_DI_TAG              0x8000000
8408 +#define        XFS_DI_VFLAGS           0x10000000
8409 +#define        XFS_DI_NUM_BITS         29
8410  #define        XFS_DI_ALL_BITS         ((1 << XFS_DI_NUM_BITS) - 1)
8411  #define        XFS_DI_CORE_BITS        (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
8412  
8413 @@ -223,6 +227,8 @@ typedef enum xfs_dinode_fmt
8414  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8415  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8416  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8417 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8418 +
8419  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8420  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8421  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8422 @@ -238,6 +244,7 @@ typedef enum xfs_dinode_fmt
8423  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8424  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8425  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8426 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8427  
8428  #ifdef CONFIG_XFS_RT
8429  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8430 @@ -250,6 +257,10 @@ typedef enum xfs_dinode_fmt
8431          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8432          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8433          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8434 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8435 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8436 +        XFS_DIFLAG_IXUNLINK)
8437 +
8438 +#define XFS_DIVFLAG_BARRIER    0x01
8439 +#define XFS_DIVFLAG_COW                0x02
8440  
8441  #endif /* __XFS_DINODE_H__ */
8442 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_fs.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_fs.h
8443 --- linux-2.6.27.25/fs/xfs/xfs_fs.h     2008-10-13 14:52:06.000000000 +0200
8444 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_fs.h        2008-10-13 14:54:20.000000000 +0200
8445 @@ -67,6 +67,9 @@ struct fsxattr {
8446  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8447  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8448  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8449 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8450 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8451 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8452  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8453  
8454  /*
8455 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8456         __s32           bs_extents;     /* number of extents            */
8457         __u32           bs_gen;         /* generation count             */
8458         __u16           bs_projid;      /* project id                   */
8459 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8460 +       __u16           bs_tag;         /* context tagging              */
8461 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8462         __u32           bs_dmevmask;    /* DMIG event mask              */
8463         __u16           bs_dmstate;     /* DMIG state info              */
8464         __u16           bs_aextents;    /* attribute number of extents  */
8465 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_ialloc.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_ialloc.c
8466 --- linux-2.6.27.25/fs/xfs/xfs_ialloc.c 2008-07-13 23:51:29.000000000 +0200
8467 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_ialloc.c    2008-11-12 18:41:59.000000000 +0100
8468 @@ -84,6 +84,8 @@ xfs_ialloc_log_di(
8469                 offsetof(xfs_dinode_t, di_next_unlinked),
8470                 offsetof(xfs_dinode_t, di_u),
8471                 offsetof(xfs_dinode_t, di_a),
8472 +               offsetof(xfs_dinode_core_t, di_tag),
8473 +               offsetof(xfs_dinode_core_t, di_vflags),
8474                 sizeof(xfs_dinode_t)
8475         };
8476  
8477 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_inode.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_inode.c
8478 --- linux-2.6.27.25/fs/xfs/xfs_inode.c  2008-10-13 14:52:06.000000000 +0200
8479 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_inode.c     2008-11-12 18:42:00.000000000 +0100
8480 @@ -249,6 +249,7 @@ xfs_inotobp(
8481         return 0;
8482  }
8483  
8484 +#include <linux/vs_tag.h>
8485  
8486  /*
8487   * This routine is called to map an inode to the buffer containing
8488 @@ -660,15 +661,25 @@ xfs_iformat_btree(
8489  void
8490  xfs_dinode_from_disk(
8491         xfs_icdinode_t          *to,
8492 -       xfs_dinode_core_t       *from)
8493 +       xfs_dinode_core_t       *from,
8494 +       int tagged)
8495  {
8496 +       uint32_t uid, gid, tag;
8497 +
8498         to->di_magic = be16_to_cpu(from->di_magic);
8499         to->di_mode = be16_to_cpu(from->di_mode);
8500         to->di_version = from ->di_version;
8501         to->di_format = from->di_format;
8502         to->di_onlink = be16_to_cpu(from->di_onlink);
8503 -       to->di_uid = be32_to_cpu(from->di_uid);
8504 -       to->di_gid = be32_to_cpu(from->di_gid);
8505 +
8506 +       uid = be32_to_cpu(from->di_uid);
8507 +       gid = be32_to_cpu(from->di_gid);
8508 +       tag = be16_to_cpu(from->di_tag);
8509 +
8510 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8511 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8512 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8513 +
8514         to->di_nlink = be32_to_cpu(from->di_nlink);
8515         to->di_projid = be16_to_cpu(from->di_projid);
8516         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8517 @@ -689,21 +700,26 @@ xfs_dinode_from_disk(
8518         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8519         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8520         to->di_flags    = be16_to_cpu(from->di_flags);
8521 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8522         to->di_gen      = be32_to_cpu(from->di_gen);
8523  }
8524  
8525  void
8526  xfs_dinode_to_disk(
8527         xfs_dinode_core_t       *to,
8528 -       xfs_icdinode_t          *from)
8529 +       xfs_icdinode_t          *from,
8530 +       int tagged)
8531  {
8532         to->di_magic = cpu_to_be16(from->di_magic);
8533         to->di_mode = cpu_to_be16(from->di_mode);
8534         to->di_version = from ->di_version;
8535         to->di_format = from->di_format;
8536         to->di_onlink = cpu_to_be16(from->di_onlink);
8537 -       to->di_uid = cpu_to_be32(from->di_uid);
8538 -       to->di_gid = cpu_to_be32(from->di_gid);
8539 +
8540 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8541 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8542 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8543 +
8544         to->di_nlink = cpu_to_be32(from->di_nlink);
8545         to->di_projid = cpu_to_be16(from->di_projid);
8546         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8547 @@ -724,12 +740,14 @@ xfs_dinode_to_disk(
8548         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8549         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8550         to->di_flags = cpu_to_be16(from->di_flags);
8551 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8552         to->di_gen = cpu_to_be32(from->di_gen);
8553  }
8554  
8555  STATIC uint
8556  _xfs_dic2xflags(
8557 -       __uint16_t              di_flags)
8558 +       __uint16_t              di_flags,
8559 +       __uint16_t              di_vflags)
8560  {
8561         uint                    flags = 0;
8562  
8563 @@ -740,6 +758,8 @@ _xfs_dic2xflags(
8564                         flags |= XFS_XFLAG_PREALLOC;
8565                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8566                         flags |= XFS_XFLAG_IMMUTABLE;
8567 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8568 +                       flags |= XFS_XFLAG_IXUNLINK;
8569                 if (di_flags & XFS_DIFLAG_APPEND)
8570                         flags |= XFS_XFLAG_APPEND;
8571                 if (di_flags & XFS_DIFLAG_SYNC)
8572 @@ -764,6 +784,10 @@ _xfs_dic2xflags(
8573                         flags |= XFS_XFLAG_FILESTREAM;
8574         }
8575  
8576 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8577 +               flags |= FS_BARRIER_FL;
8578 +       if (di_vflags & XFS_DIVFLAG_COW)
8579 +               flags |= FS_COW_FL;
8580         return flags;
8581  }
8582  
8583 @@ -773,7 +797,7 @@ xfs_ip2xflags(
8584  {
8585         xfs_icdinode_t          *dic = &ip->i_d;
8586  
8587 -       return _xfs_dic2xflags(dic->di_flags) |
8588 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8589                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8590  }
8591  
8592 @@ -783,7 +807,8 @@ xfs_dic2xflags(
8593  {
8594         xfs_dinode_core_t       *dic = &dip->di_core;
8595  
8596 -       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
8597 +       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags),
8598 +                               be16_to_cpu(dic->di_vflags)) |
8599                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8600  }
8601  
8602 @@ -878,7 +903,8 @@ xfs_iread(
8603          * Otherwise, just get the truly permanent information.
8604          */
8605         if (dip->di_core.di_mode) {
8606 -               xfs_dinode_from_disk(&ip->i_d, &dip->di_core);
8607 +               xfs_dinode_from_disk(&ip->i_d, &dip->di_core,
8608 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8609                 error = xfs_iformat(ip, dip);
8610                 if (error)  {
8611                         kmem_zone_free(xfs_inode_zone, ip);
8612 @@ -1083,6 +1109,7 @@ xfs_ialloc(
8613         ASSERT(ip->i_d.di_nlink == nlink);
8614         ip->i_d.di_uid = current_fsuid();
8615         ip->i_d.di_gid = current_fsgid();
8616 +       ip->i_d.di_tag = current_fstag(cr, ip->i_vnode);
8617         ip->i_d.di_projid = prid;
8618         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8619  
8620 @@ -1143,6 +1170,7 @@ xfs_ialloc(
8621         ip->i_d.di_dmevmask = 0;
8622         ip->i_d.di_dmstate = 0;
8623         ip->i_d.di_flags = 0;
8624 +       ip->i_d.di_vflags = 0;
8625         flags = XFS_ILOG_CORE;
8626         switch (mode & S_IFMT) {
8627         case S_IFIFO:
8628 @@ -2249,6 +2277,7 @@ xfs_ifree(
8629         }
8630         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8631         ip->i_d.di_flags = 0;
8632 +       ip->i_d.di_vflags = 0;
8633         ip->i_d.di_dmevmask = 0;
8634         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8635         ip->i_df.if_ext_max =
8636 @@ -3342,7 +3371,8 @@ xfs_iflush_int(
8637          * because if the inode is dirty at all the core must
8638          * be.
8639          */
8640 -       xfs_dinode_to_disk(&dip->di_core, &ip->i_d);
8641 +       xfs_dinode_to_disk(&dip->di_core, &ip->i_d,
8642 +               mp->m_flags & XFS_MOUNT_TAGGED);
8643  
8644         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8645         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8646 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_inode.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_inode.h
8647 --- linux-2.6.27.25/fs/xfs/xfs_inode.h  2008-10-13 14:52:06.000000000 +0200
8648 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_inode.h     2008-11-12 18:42:03.000000000 +0100
8649 @@ -173,7 +173,9 @@ typedef struct xfs_icdinode {
8650         __uint32_t      di_gid;         /* owner's group id */
8651         __uint32_t      di_nlink;       /* number of links to file */
8652         __uint16_t      di_projid;      /* owner's project id */
8653 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8654 +       __uint16_t      di_tag;         /* context tagging */
8655 +       __uint16_t      di_vflags;      /* vserver specific flags */
8656 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8657         __uint16_t      di_flushiter;   /* incremented on flush */
8658         xfs_ictimestamp_t di_atime;     /* time last accessed */
8659         xfs_ictimestamp_t di_mtime;     /* time last modified */
8660 @@ -500,9 +502,9 @@ int         xfs_ialloc(struct xfs_trans *, xfs_
8661                            xfs_nlink_t, xfs_dev_t, struct cred *, xfs_prid_t,
8662                            int, struct xfs_buf **, boolean_t *, xfs_inode_t **);
8663  void           xfs_dinode_from_disk(struct xfs_icdinode *,
8664 -                                    struct xfs_dinode_core *);
8665 +                                    struct xfs_dinode_core *, int tagged);
8666  void           xfs_dinode_to_disk(struct xfs_dinode_core *,
8667 -                                  struct xfs_icdinode *);
8668 +                                  struct xfs_icdinode *, int tagged);
8669  
8670  uint           xfs_ip2xflags(struct xfs_inode *);
8671  uint           xfs_dic2xflags(struct xfs_dinode *);
8672 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_itable.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_itable.c
8673 --- linux-2.6.27.25/fs/xfs/xfs_itable.c 2008-10-13 14:52:06.000000000 +0200
8674 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_itable.c    2008-11-12 18:42:03.000000000 +0100
8675 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
8676         buf->bs_mode = dic->di_mode;
8677         buf->bs_uid = dic->di_uid;
8678         buf->bs_gid = dic->di_gid;
8679 +       buf->bs_tag = dic->di_tag;
8680         buf->bs_size = dic->di_size;
8681         vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
8682         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
8683 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_log_recover.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_log_recover.c
8684 --- linux-2.6.27.25/fs/xfs/xfs_log_recover.c    2008-10-13 14:52:06.000000000 +0200
8685 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_log_recover.c       2008-11-12 18:42:03.000000000 +0100
8686 @@ -2417,7 +2417,8 @@ xlog_recover_do_inode_trans(
8687  
8688         /* The core is in in-core format */
8689         xfs_dinode_to_disk(&dip->di_core,
8690 -               (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8691 +               (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8692 +               mp->m_flags & XFS_MOUNT_TAGGED);
8693  
8694         /* the rest is in on-disk format */
8695         if (item->ri_buf[1].i_len > sizeof(xfs_dinode_core_t)) {
8696 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_mount.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_mount.h
8697 --- linux-2.6.27.25/fs/xfs/xfs_mount.h  2008-10-13 14:52:06.000000000 +0200
8698 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_mount.h     2008-10-13 14:54:20.000000000 +0200
8699 @@ -384,6 +384,7 @@ typedef struct xfs_mount {
8700                                                    allocator */
8701  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8702  
8703 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8704  
8705  /*
8706   * Default minimum read and write sizes.
8707 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_vnodeops.c linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_vnodeops.c
8708 --- linux-2.6.27.25/fs/xfs/xfs_vnodeops.c       2008-10-13 14:52:06.000000000 +0200
8709 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_vnodeops.c  2008-11-12 18:42:03.000000000 +0100
8710 @@ -75,6 +75,89 @@ xfs_open(
8711         return 0;
8712  }
8713  
8714 +STATIC void
8715 +xfs_get_inode_flags(
8716 +       xfs_inode_t     *ip)
8717 +{
8718 +       struct inode    *inode = VFS_I(ip);
8719 +       unsigned int    flags = inode->i_flags;
8720 +       unsigned int    vflags = inode->i_vflags;
8721 +
8722 +       if (flags & S_IMMUTABLE)
8723 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8724 +       else
8725 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8726 +       if (flags & S_IXUNLINK)
8727 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8728 +       else
8729 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8730 +
8731 +       if (vflags & V_BARRIER)
8732 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8733 +       else
8734 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8735 +       if (vflags & V_COW)
8736 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8737 +       else
8738 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8739 +}
8740 +
8741 +int
8742 +xfs_sync_xflags(
8743 +       xfs_inode_t             *ip)
8744 +{
8745 +       struct xfs_mount        *mp = ip->i_mount;
8746 +       struct xfs_trans        *tp;
8747 +       unsigned int            lock_flags = 0;
8748 +       int                     code;
8749 +
8750 +       xfs_itrace_entry(ip);
8751 +
8752 +       if (mp->m_flags & XFS_MOUNT_RDONLY)
8753 +               return XFS_ERROR(EROFS);
8754 +
8755 +       /*
8756 +        * we acquire the inode lock and do an error checking pass.
8757 +        */
8758 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8759 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8760 +       if (code)
8761 +               goto error_return;
8762 +
8763 +       lock_flags = XFS_ILOCK_EXCL;
8764 +       xfs_ilock(ip, lock_flags);
8765 +
8766 +       xfs_trans_ijoin(tp, ip, lock_flags);
8767 +       xfs_trans_ihold(tp, ip);
8768 +
8769 +       xfs_get_inode_flags(ip);
8770 +       // xfs_diflags_to_linux(ip);
8771 +
8772 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8773 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8774 +
8775 +       XFS_STATS_INC(xs_ig_attrchg);
8776 +
8777 +       /*
8778 +        * If this is a synchronous mount, make sure that the
8779 +        * transaction goes to disk before returning to the user.
8780 +        */
8781 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8782 +               xfs_trans_set_sync(tp);
8783 +       code = xfs_trans_commit(tp, 0);
8784 +       xfs_iunlock(ip, lock_flags);
8785 +
8786 +       if (code)
8787 +               return code;
8788 +       return 0;
8789 +
8790 + error_return:
8791 +       xfs_trans_cancel(tp, 0);
8792 +       if (lock_flags)
8793 +               xfs_iunlock(ip, lock_flags);
8794 +       return code;
8795 +}
8796 +
8797  int
8798  xfs_setattr(
8799         struct xfs_inode        *ip,
8800 @@ -91,6 +174,7 @@ xfs_setattr(
8801         uint                    commit_flags=0;
8802         uid_t                   uid=0, iuid=0;
8803         gid_t                   gid=0, igid=0;
8804 +       tag_t                   tag=0, itag=0;
8805         int                     timeflags = 0;
8806         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8807         int                     file_owner;
8808 @@ -238,7 +322,7 @@ xfs_setattr(
8809          * and can change the group id only to a group of which he
8810          * or she is a member.
8811          */
8812 -       if (mask & (ATTR_UID|ATTR_GID)) {
8813 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8814                 /*
8815                  * These IDs could have changed since we last looked at them.
8816                  * But, we're assured that if the ownership did change
8817 @@ -247,8 +331,10 @@ xfs_setattr(
8818                  */
8819                 iuid = ip->i_d.di_uid;
8820                 igid = ip->i_d.di_gid;
8821 +               itag = ip->i_d.di_tag;
8822                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8823                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8824 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8825  
8826                 /*
8827                  * CAP_CHOWN overrides the following restrictions:
8828 @@ -272,7 +358,9 @@ xfs_setattr(
8829                  * going to change.
8830                  */
8831                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8832 -                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
8833 +                   (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8834 +                   (XFS_IS_GQUOTA_ON(mp) && itag != tag)) {
8835 +                       /* TODO: handle tagging? */
8836                         ASSERT(tp);
8837                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
8838                                                 capable(CAP_FOWNER) ?
8839 @@ -461,7 +549,7 @@ xfs_setattr(
8840          * and can change the group id only to a group of which he
8841          * or she is a member.
8842          */
8843 -       if (mask & (ATTR_UID|ATTR_GID)) {
8844 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8845                 /*
8846                  * CAP_FSETID overrides the following restrictions:
8847                  *
8848 @@ -477,6 +565,10 @@ xfs_setattr(
8849                  * Change the ownerships and register quota modifications
8850                  * in the transaction.
8851                  */
8852 +               if (itag != tag) {
8853 +                       ip->i_d.di_tag = tag;
8854 +                       inode->i_tag = tag;
8855 +               }
8856                 if (iuid != uid) {
8857                         if (XFS_IS_UQUOTA_ON(mp)) {
8858                                 ASSERT(mask & ATTR_UID);
8859 diff -NurpP --minimal linux-2.6.27.25/fs/xfs/xfs_vnodeops.h linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_vnodeops.h
8860 --- linux-2.6.27.25/fs/xfs/xfs_vnodeops.h       2008-10-13 14:52:06.000000000 +0200
8861 +++ linux-2.6.27.25-vs2.3.0.36.6/fs/xfs/xfs_vnodeops.h  2008-11-12 18:42:03.000000000 +0100
8862 @@ -15,6 +15,7 @@ struct xfs_iomap;
8863  
8864  
8865  int xfs_open(struct xfs_inode *ip);
8866 +int xfs_sync_xflags(struct xfs_inode *ip);
8867  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags,
8868                 struct cred *credp);
8869  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8870 diff -NurpP --minimal linux-2.6.27.25/include/asm-generic/tlb.h linux-2.6.27.25-vs2.3.0.36.6/include/asm-generic/tlb.h
8871 --- linux-2.6.27.25/include/asm-generic/tlb.h   2008-07-13 23:51:29.000000000 +0200
8872 +++ linux-2.6.27.25-vs2.3.0.36.6/include/asm-generic/tlb.h      2008-10-13 14:54:20.000000000 +0200
8873 @@ -14,6 +14,7 @@
8874  #define _ASM_GENERIC__TLB_H
8875  
8876  #include <linux/swap.h>
8877 +#include <linux/vs_memory.h>
8878  #include <asm/pgalloc.h>
8879  #include <asm/tlbflush.h>
8880  
8881 diff -NurpP --minimal linux-2.6.27.25/include/asm-x86/unistd_64.h linux-2.6.27.25-vs2.3.0.36.6/include/asm-x86/unistd_64.h
8882 --- linux-2.6.27.25/include/asm-x86/unistd_64.h 2008-10-13 14:52:08.000000000 +0200
8883 +++ linux-2.6.27.25-vs2.3.0.36.6/include/asm-x86/unistd_64.h    2008-10-13 14:54:20.000000000 +0200
8884 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
8885  #define __NR_utimes                            235
8886  __SYSCALL(__NR_utimes, sys_utimes)
8887  #define __NR_vserver                           236
8888 -__SYSCALL(__NR_vserver, sys_ni_syscall)
8889 +__SYSCALL(__NR_vserver, sys_vserver)
8890  #define __NR_mbind                             237
8891  __SYSCALL(__NR_mbind, sys_mbind)
8892  #define __NR_set_mempolicy                     238
8893 diff -NurpP --minimal linux-2.6.27.25/include/linux/capability.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/capability.h
8894 --- linux-2.6.27.25/include/linux/capability.h  2009-06-15 17:18:32.000000000 +0200
8895 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/capability.h     2009-05-15 22:57:04.000000000 +0200
8896 @@ -274,6 +274,7 @@ typedef struct kernel_cap_struct {
8897     arbitrary SCSI commands */
8898  /* Allow setting encryption key on loopback filesystem */
8899  /* Allow setting zone reclaim policy */
8900 +/* Allow the selection of a security context */
8901  
8902  #define CAP_SYS_ADMIN        21
8903  
8904 @@ -346,7 +347,13 @@ typedef struct kernel_cap_struct {
8905  
8906  #define CAP_MAC_ADMIN        33
8907  
8908 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8909 +/* Allow context manipulations */
8910 +/* Allow changing context info on files */
8911 +
8912 +#define CAP_CONTEXT         34
8913 +
8914 +
8915 +#define CAP_LAST_CAP         CAP_CONTEXT
8916  
8917  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8918  
8919 diff -NurpP --minimal linux-2.6.27.25/include/linux/devpts_fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/devpts_fs.h
8920 --- linux-2.6.27.25/include/linux/devpts_fs.h   2008-07-13 23:51:29.000000000 +0200
8921 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/devpts_fs.h      2008-10-13 14:54:20.000000000 +0200
8922 @@ -34,5 +34,4 @@ static inline void devpts_pty_kill(int n
8923  
8924  #endif
8925  
8926 -
8927  #endif /* _LINUX_DEVPTS_FS_H */
8928 diff -NurpP --minimal linux-2.6.27.25/include/linux/ext2_fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/ext2_fs.h
8929 --- linux-2.6.27.25/include/linux/ext2_fs.h     2008-10-13 14:52:09.000000000 +0200
8930 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/ext2_fs.h        2008-10-13 14:54:20.000000000 +0200
8931 @@ -189,8 +189,12 @@ struct ext2_group_desc
8932  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8933  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8934  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8935 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8936  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8937  
8938 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8939 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8940 +
8941  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8942  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8943  
8944 @@ -247,7 +251,7 @@ struct ext2_inode {
8945                 struct {
8946                         __u8    l_i_frag;       /* Fragment number */
8947                         __u8    l_i_fsize;      /* Fragment size */
8948 -                       __u16   i_pad1;
8949 +                       __u16   l_i_tag;        /* Context Tag */
8950                         __le16  l_i_uid_high;   /* these 2 fields    */
8951                         __le16  l_i_gid_high;   /* were reserved2[0] */
8952                         __u32   l_i_reserved2;
8953 @@ -279,6 +283,7 @@ struct ext2_inode {
8954  #define i_gid_low      i_gid
8955  #define i_uid_high     osd2.linux2.l_i_uid_high
8956  #define i_gid_high     osd2.linux2.l_i_gid_high
8957 +#define i_raw_tag      osd2.linux2.l_i_tag
8958  #define i_reserved2    osd2.linux2.l_i_reserved2
8959  #endif
8960  
8961 @@ -323,6 +328,7 @@ struct ext2_inode {
8962  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8963  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8964  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8965 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8966  
8967  
8968  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8969 diff -NurpP --minimal linux-2.6.27.25/include/linux/ext3_fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/ext3_fs.h
8970 --- linux-2.6.27.25/include/linux/ext3_fs.h     2008-10-13 14:52:09.000000000 +0200
8971 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/ext3_fs.h        2008-10-31 18:15:18.000000000 +0100
8972 @@ -173,10 +173,14 @@ struct ext3_group_desc
8973  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8974  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8975  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8976 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8977  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8978  
8979 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8980 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8981 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8982 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8983 +
8984 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8985 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8986  
8987  /*
8988   * Inode dynamic state flags
8989 @@ -292,7 +296,7 @@ struct ext3_inode {
8990                 struct {
8991                         __u8    l_i_frag;       /* Fragment number */
8992                         __u8    l_i_fsize;      /* Fragment size */
8993 -                       __u16   i_pad1;
8994 +                       __u16   l_i_tag;        /* Context Tag */
8995                         __le16  l_i_uid_high;   /* these 2 fields    */
8996                         __le16  l_i_gid_high;   /* were reserved2[0] */
8997                         __u32   l_i_reserved2;
8998 @@ -326,6 +330,7 @@ struct ext3_inode {
8999  #define i_gid_low      i_gid
9000  #define i_uid_high     osd2.linux2.l_i_uid_high
9001  #define i_gid_high     osd2.linux2.l_i_gid_high
9002 +#define i_raw_tag      osd2.linux2.l_i_tag
9003  #define i_reserved2    osd2.linux2.l_i_reserved2
9004  
9005  #elif defined(__GNU__)
9006 @@ -380,6 +385,7 @@ struct ext3_inode {
9007  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
9008  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
9009  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
9010 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
9011  
9012  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
9013  #ifndef _LINUX_EXT2_FS_H
9014 @@ -822,6 +828,7 @@ struct buffer_head * ext3_bread (handle_
9015  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
9016         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
9017         int create, int extend_disksize);
9018 +extern int ext3_sync_flags(struct inode *inode);
9019  
9020  extern struct inode *ext3_iget(struct super_block *, unsigned long);
9021  extern int  ext3_write_inode (struct inode *, int);
9022 diff -NurpP --minimal linux-2.6.27.25/include/linux/fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/fs.h
9023 --- linux-2.6.27.25/include/linux/fs.h  2009-06-15 17:18:32.000000000 +0200
9024 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/fs.h     2009-03-25 14:32:29.000000000 +0100
9025 @@ -133,6 +133,9 @@ extern int dir_notify_enable;
9026  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
9027  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
9028  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
9029 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
9030 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
9031 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
9032  #define MS_ACTIVE      (1<<30)
9033  #define MS_NOUSER      (1<<31)
9034  
9035 @@ -159,6 +162,14 @@ extern int dir_notify_enable;
9036  #define S_NOCMTIME     128     /* Do not update file c/mtime */
9037  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
9038  #define S_PRIVATE      512     /* Inode is fs-internal */
9039 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
9040 +
9041 +/* Linux-VServer related Inode flags */
9042 +
9043 +#define V_VALID                1
9044 +#define V_XATTR                2
9045 +#define V_BARRIER      4       /* Barrier for chroot() */
9046 +#define V_COW          8       /* Copy on Write */
9047  
9048  /*
9049   * Note that nosuid etc flags are inode-specific: setting some file-system
9050 @@ -181,12 +192,15 @@ extern int dir_notify_enable;
9051  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
9052                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
9053  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
9054 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9055 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
9056 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9057 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
9058 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
9059  
9060  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
9061  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
9062  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
9063 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
9064 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
9065  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
9066  
9067  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
9068 @@ -194,6 +208,16 @@ extern int dir_notify_enable;
9069  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
9070  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
9071  
9072 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
9073 +
9074 +#ifdef CONFIG_VSERVER_COWBL
9075 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
9076 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
9077 +#else
9078 +#  define IS_COW(inode)                (0)
9079 +#  define IS_COW_LINK(inode)   (0)
9080 +#endif
9081 +
9082  /* the read-only stuff doesn't really belong here, but any other place is
9083     probably as bad and I don't want to create yet another include file. */
9084  
9085 @@ -267,11 +291,14 @@ extern int dir_notify_enable;
9086  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
9087  #define FS_EXTENT_FL                   0x00080000 /* Extents */
9088  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
9089 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
9090  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
9091  
9092 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
9093 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
9094 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
9095 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
9096  
9097 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
9098 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
9099  
9100  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
9101  #define SYNC_FILE_RANGE_WRITE          2
9102 @@ -342,6 +369,7 @@ typedef void (dio_iodone_t)(struct kiocb
9103  #define ATTR_KILL_PRIV (1 << 14)
9104  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
9105  #define ATTR_TIMES_SET (1 << 16)
9106 +#define ATTR_TAG       (1 << 17)
9107  
9108  /*
9109   * This is the Inode Attributes structure, used for notify_change().  It
9110 @@ -357,6 +385,7 @@ struct iattr {
9111         umode_t         ia_mode;
9112         uid_t           ia_uid;
9113         gid_t           ia_gid;
9114 +       tag_t           ia_tag;
9115         loff_t          ia_size;
9116         struct timespec ia_atime;
9117         struct timespec ia_mtime;
9118 @@ -370,6 +399,9 @@ struct iattr {
9119         struct file     *ia_file;
9120  };
9121  
9122 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
9123 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
9124 +
9125  /*
9126   * Includes for diskquotas.
9127   */
9128 @@ -634,7 +666,9 @@ struct inode {
9129         unsigned int            i_nlink;
9130         uid_t                   i_uid;
9131         gid_t                   i_gid;
9132 +       tag_t                   i_tag;
9133         dev_t                   i_rdev;
9134 +       dev_t                   i_mdev;
9135         u64                     i_version;
9136         loff_t                  i_size;
9137  #ifdef __NEED_I_SIZE_ORDERED
9138 @@ -682,7 +716,8 @@ struct inode {
9139         unsigned long           i_state;
9140         unsigned long           dirtied_when;   /* jiffies of first dirtying */
9141  
9142 -       unsigned int            i_flags;
9143 +       unsigned short          i_flags;
9144 +       unsigned short          i_vflags;
9145  
9146         atomic_t                i_writecount;
9147  #ifdef CONFIG_SECURITY
9148 @@ -769,12 +804,12 @@ static inline void i_size_write(struct i
9149  
9150  static inline unsigned iminor(const struct inode *inode)
9151  {
9152 -       return MINOR(inode->i_rdev);
9153 +       return MINOR(inode->i_mdev);
9154  }
9155  
9156  static inline unsigned imajor(const struct inode *inode)
9157  {
9158 -       return MAJOR(inode->i_rdev);
9159 +       return MAJOR(inode->i_mdev);
9160  }
9161  
9162  extern struct block_device *I_BDEV(struct inode *inode);
9163 @@ -832,6 +867,7 @@ struct file {
9164         loff_t                  f_pos;
9165         struct fown_struct      f_owner;
9166         unsigned int            f_uid, f_gid;
9167 +       xid_t                   f_xid;
9168         struct file_ra_state    f_ra;
9169  
9170         u64                     f_version;
9171 @@ -966,6 +1002,7 @@ struct file_lock {
9172         struct file *fl_file;
9173         loff_t fl_start;
9174         loff_t fl_end;
9175 +       xid_t fl_xid;
9176  
9177         struct fasync_struct *  fl_fasync; /* for lease break notifications */
9178         unsigned long fl_break_time;    /* for nonblocking lease breaks */
9179 @@ -1294,6 +1331,7 @@ struct inode_operations {
9180         void (*truncate_range)(struct inode *, loff_t, loff_t);
9181         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
9182                           loff_t len);
9183 +       int (*sync_flags) (struct inode *);
9184  };
9185  
9186  struct seq_file;
9187 @@ -1309,6 +1347,7 @@ extern ssize_t vfs_readv(struct file *, 
9188                 unsigned long, loff_t *);
9189  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
9190                 unsigned long, loff_t *);
9191 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
9192  
9193  struct super_operations {
9194         struct inode *(*alloc_inode)(struct super_block *sb);
9195 @@ -1999,6 +2038,7 @@ extern int dcache_dir_open(struct inode 
9196  extern int dcache_dir_close(struct inode *, struct file *);
9197  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
9198  extern int dcache_readdir(struct file *, void *, filldir_t);
9199 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
9200  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
9201  extern int simple_statfs(struct dentry *, struct kstatfs *);
9202  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
9203 diff -NurpP --minimal linux-2.6.27.25/include/linux/if_tun.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/if_tun.h
9204 --- linux-2.6.27.25/include/linux/if_tun.h      2008-10-13 14:52:09.000000000 +0200
9205 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/if_tun.h 2008-10-13 14:54:20.000000000 +0200
9206 @@ -46,6 +46,7 @@
9207  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
9208  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
9209  #define TUNGETIFF      _IOR('T', 210, unsigned int)
9210 +#define TUNSETNID     _IOW('T', 215, int)
9211  
9212  /* TUNSETIFF ifr flags */
9213  #define IFF_TUN                0x0001
9214 diff -NurpP --minimal linux-2.6.27.25/include/linux/init_task.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/init_task.h
9215 --- linux-2.6.27.25/include/linux/init_task.h   2008-10-13 14:52:09.000000000 +0200
9216 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/init_task.h      2008-10-13 14:54:20.000000000 +0200
9217 @@ -179,6 +179,10 @@ extern struct group_info init_groups;
9218         INIT_IDS                                                        \
9219         INIT_TRACE_IRQFLAGS                                             \
9220         INIT_LOCKDEP                                                    \
9221 +       .xid            = 0,                                            \
9222 +       .vx_info        = NULL,                                         \
9223 +       .nid            = 0,                                            \
9224 +       .nx_info        = NULL,                                         \
9225  }
9226  
9227  
9228 diff -NurpP --minimal linux-2.6.27.25/include/linux/interrupt.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/interrupt.h
9229 --- linux-2.6.27.25/include/linux/interrupt.h   2008-10-13 14:52:09.000000000 +0200
9230 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/interrupt.h      2008-10-13 14:54:20.000000000 +0200
9231 @@ -8,8 +8,8 @@
9232  #include <linux/preempt.h>
9233  #include <linux/cpumask.h>
9234  #include <linux/irqreturn.h>
9235 -#include <linux/hardirq.h>
9236  #include <linux/sched.h>
9237 +#include <linux/hardirq.h>
9238  #include <linux/irqflags.h>
9239  #include <asm/atomic.h>
9240  #include <asm/ptrace.h>
9241 diff -NurpP --minimal linux-2.6.27.25/include/linux/ipc.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/ipc.h
9242 --- linux-2.6.27.25/include/linux/ipc.h 2008-07-13 23:51:29.000000000 +0200
9243 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/ipc.h    2008-10-13 14:54:20.000000000 +0200
9244 @@ -93,6 +93,7 @@ struct kern_ipc_perm
9245         key_t           key;
9246         uid_t           uid;
9247         gid_t           gid;
9248 +       xid_t           xid;
9249         uid_t           cuid;
9250         gid_t           cgid;
9251         mode_t          mode; 
9252 diff -NurpP --minimal linux-2.6.27.25/include/linux/Kbuild linux-2.6.27.25-vs2.3.0.36.6/include/linux/Kbuild
9253 --- linux-2.6.27.25/include/linux/Kbuild        2009-06-15 17:18:32.000000000 +0200
9254 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/Kbuild   2009-02-03 18:03:38.000000000 +0100
9255 @@ -370,3 +370,6 @@ unifdef-y += xattr.h
9256  unifdef-y += xfrm.h
9257  
9258  objhdr-y += version.h
9259 +
9260 +header-y += vserver/
9261 +
9262 diff -NurpP --minimal linux-2.6.27.25/include/linux/loop.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/loop.h
9263 --- linux-2.6.27.25/include/linux/loop.h        2008-07-13 23:51:29.000000000 +0200
9264 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/loop.h   2008-10-13 14:54:20.000000000 +0200
9265 @@ -45,6 +45,7 @@ struct loop_device {
9266         struct loop_func_table *lo_encryption;
9267         __u32           lo_init[2];
9268         uid_t           lo_key_owner;   /* Who set the key */
9269 +       xid_t           lo_xid;
9270         int             (*ioctl)(struct loop_device *, int cmd, 
9271                                  unsigned long arg); 
9272  
9273 diff -NurpP --minimal linux-2.6.27.25/include/linux/magic.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/magic.h
9274 --- linux-2.6.27.25/include/linux/magic.h       2008-07-13 23:51:29.000000000 +0200
9275 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/magic.h  2008-10-13 14:54:20.000000000 +0200
9276 @@ -3,7 +3,7 @@
9277  
9278  #define ADFS_SUPER_MAGIC       0xadf5
9279  #define AFFS_SUPER_MAGIC       0xadff
9280 -#define AFS_SUPER_MAGIC                0x5346414F
9281 +#define AFS_SUPER_MAGIC                0x5346414F
9282  #define AUTOFS_SUPER_MAGIC     0x0187
9283  #define CODA_SUPER_MAGIC       0x73757245
9284  #define EFS_SUPER_MAGIC                0x414A53
9285 @@ -26,6 +26,7 @@
9286  #define NFS_SUPER_MAGIC                0x6969
9287  #define OPENPROM_SUPER_MAGIC   0x9fa1
9288  #define PROC_SUPER_MAGIC       0x9fa0
9289 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9290  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9291  
9292  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9293 diff -NurpP --minimal linux-2.6.27.25/include/linux/major.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/major.h
9294 --- linux-2.6.27.25/include/linux/major.h       2008-10-13 14:52:09.000000000 +0200
9295 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/major.h  2008-10-13 14:54:20.000000000 +0200
9296 @@ -15,6 +15,7 @@
9297  #define HD_MAJOR               IDE0_MAJOR
9298  #define PTY_SLAVE_MAJOR                3
9299  #define TTY_MAJOR              4
9300 +#define VROOT_MAJOR            4
9301  #define TTYAUX_MAJOR           5
9302  #define LP_MAJOR               6
9303  #define VCS_MAJOR              7
9304 diff -NurpP --minimal linux-2.6.27.25/include/linux/mm_types.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/mm_types.h
9305 --- linux-2.6.27.25/include/linux/mm_types.h    2008-10-13 14:52:09.000000000 +0200
9306 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/mm_types.h       2008-10-13 14:54:20.000000000 +0200
9307 @@ -216,6 +216,7 @@ struct mm_struct {
9308  
9309         /* Architecture-specific MM context */
9310         mm_context_t context;
9311 +       struct vx_info *mm_vx_info;
9312  
9313         /* Swap token stuff */
9314         /*
9315 diff -NurpP --minimal linux-2.6.27.25/include/linux/mount.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/mount.h
9316 --- linux-2.6.27.25/include/linux/mount.h       2008-10-13 14:52:09.000000000 +0200
9317 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/mount.h  2008-10-24 03:34:52.000000000 +0200
9318 @@ -37,6 +37,9 @@ struct mnt_namespace;
9319  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
9320  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
9321  
9322 +#define MNT_TAGID      0x10000
9323 +#define MNT_NOTAG      0x20000
9324 +
9325  struct vfsmount {
9326         struct list_head mnt_hash;
9327         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9328 @@ -71,6 +74,7 @@ struct vfsmount {
9329          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
9330          */
9331         atomic_t __mnt_writers;
9332 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9333  };
9334  
9335  static inline struct vfsmount *mntget(struct vfsmount *mnt)
9336 diff -NurpP --minimal linux-2.6.27.25/include/linux/net.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/net.h
9337 --- linux-2.6.27.25/include/linux/net.h 2008-10-13 14:52:09.000000000 +0200
9338 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/net.h    2008-10-13 14:54:20.000000000 +0200
9339 @@ -68,6 +68,7 @@ struct net;
9340  #define SOCK_NOSPACE           2
9341  #define SOCK_PASSCRED          3
9342  #define SOCK_PASSSEC           4
9343 +#define SOCK_USER_SOCKET       5
9344  
9345  #ifndef ARCH_HAS_SOCKET_TYPES
9346  /**
9347 diff -NurpP --minimal linux-2.6.27.25/include/linux/nfs_mount.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/nfs_mount.h
9348 --- linux-2.6.27.25/include/linux/nfs_mount.h   2008-07-13 23:51:29.000000000 +0200
9349 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/nfs_mount.h      2008-10-13 14:54:20.000000000 +0200
9350 @@ -63,6 +63,7 @@ struct nfs_mount_data {
9351  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9352  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9353  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9354 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9355 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9356 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9357  
9358  #endif
9359 diff -NurpP --minimal linux-2.6.27.25/include/linux/nsproxy.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/nsproxy.h
9360 --- linux-2.6.27.25/include/linux/nsproxy.h     2008-10-13 14:52:09.000000000 +0200
9361 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/nsproxy.h        2008-10-13 14:54:20.000000000 +0200
9362 @@ -3,6 +3,7 @@
9363  
9364  #include <linux/spinlock.h>
9365  #include <linux/sched.h>
9366 +#include <linux/vserver/debug.h>
9367  
9368  struct mnt_namespace;
9369  struct uts_namespace;
9370 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9371  }
9372  
9373  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9374 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9375  void exit_task_namespaces(struct task_struct *tsk);
9376  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9377  void free_nsproxy(struct nsproxy *ns);
9378  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9379         struct fs_struct *);
9380  
9381 -static inline void put_nsproxy(struct nsproxy *ns)
9382 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9383 +
9384 +static inline void __get_nsproxy(struct nsproxy *ns,
9385 +       const char *_file, int _line)
9386  {
9387 -       if (atomic_dec_and_test(&ns->count)) {
9388 -               free_nsproxy(ns);
9389 -       }
9390 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9391 +               ns, atomic_read(&ns->count), _file, _line);
9392 +       atomic_inc(&ns->count);
9393  }
9394  
9395 -static inline void get_nsproxy(struct nsproxy *ns)
9396 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9397 +
9398 +static inline void __put_nsproxy(struct nsproxy *ns,
9399 +       const char *_file, int _line)
9400  {
9401 -       atomic_inc(&ns->count);
9402 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9403 +               ns, atomic_read(&ns->count), _file, _line);
9404 +       if (atomic_dec_and_test(&ns->count)) {
9405 +               free_nsproxy(ns);
9406 +       }
9407  }
9408  
9409  #ifdef CONFIG_CGROUP_NS
9410 diff -NurpP --minimal linux-2.6.27.25/include/linux/pid.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/pid.h
9411 --- linux-2.6.27.25/include/linux/pid.h 2009-06-15 17:18:32.000000000 +0200
9412 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/pid.h    2009-02-22 22:58:33.000000000 +0100
9413 @@ -8,7 +8,8 @@ enum pid_type
9414         PIDTYPE_PID,
9415         PIDTYPE_PGID,
9416         PIDTYPE_SID,
9417 -       PIDTYPE_MAX
9418 +       PIDTYPE_MAX,
9419 +       PIDTYPE_REALPID
9420  };
9421  
9422  /*
9423 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9424  }
9425  
9426  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9427 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9428  pid_t pid_vnr(struct pid *pid);
9429  
9430  #define do_each_pid_task(pid, type, task)                              \
9431 diff -NurpP --minimal linux-2.6.27.25/include/linux/proc_fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/proc_fs.h
9432 --- linux-2.6.27.25/include/linux/proc_fs.h     2008-10-13 14:52:09.000000000 +0200
9433 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/proc_fs.h        2008-10-13 14:54:20.000000000 +0200
9434 @@ -59,6 +59,7 @@ struct proc_dir_entry {
9435         nlink_t nlink;
9436         uid_t uid;
9437         gid_t gid;
9438 +       int vx_flags;
9439         loff_t size;
9440         const struct inode_operations *proc_iops;
9441         /*
9442 @@ -274,12 +275,18 @@ static inline void kclist_add(struct kco
9443  extern void kclist_add(struct kcore_list *, void *, size_t);
9444  #endif
9445  
9446 +struct vx_info;
9447 +struct nx_info;
9448 +
9449  union proc_op {
9450         int (*proc_get_link)(struct inode *, struct path *);
9451         int (*proc_read)(struct task_struct *task, char *page);
9452         int (*proc_show)(struct seq_file *m,
9453                 struct pid_namespace *ns, struct pid *pid,
9454                 struct task_struct *task);
9455 +       int (*proc_vs_read)(char *page);
9456 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9457 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9458  };
9459  
9460  struct ctl_table_header;
9461 @@ -287,6 +294,7 @@ struct ctl_table;
9462  
9463  struct proc_inode {
9464         struct pid *pid;
9465 +       int vx_flags;
9466         int fd;
9467         union proc_op op;
9468         struct proc_dir_entry *pde;
9469 diff -NurpP --minimal linux-2.6.27.25/include/linux/reiserfs_fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/reiserfs_fs.h
9470 --- linux-2.6.27.25/include/linux/reiserfs_fs.h 2008-10-13 14:52:09.000000000 +0200
9471 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/reiserfs_fs.h    2008-10-13 14:54:20.000000000 +0200
9472 @@ -837,6 +837,11 @@ struct stat_data_v1 {
9473  #define REISERFS_COMPR_FL     FS_COMPR_FL
9474  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9475  
9476 +/* unfortunately reiserfs sdattr is only 16 bit */
9477 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9478 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9479 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9480 +
9481  /* persistent flags that file inherits from the parent directory */
9482  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9483                                 REISERFS_SYNC_FL |      \
9484 @@ -846,6 +851,9 @@ struct stat_data_v1 {
9485                                 REISERFS_COMPR_FL |     \
9486                                 REISERFS_NOTAIL_FL )
9487  
9488 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9489 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9490 +
9491  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9492     address blocks) */
9493  struct stat_data {
9494 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
9495  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9496  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9497  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9498 +int reiserfs_sync_flags(struct inode *inode);
9499  
9500  /* namei.c */
9501  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9502 diff -NurpP --minimal linux-2.6.27.25/include/linux/reiserfs_fs_sb.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/reiserfs_fs_sb.h
9503 --- linux-2.6.27.25/include/linux/reiserfs_fs_sb.h      2008-10-13 14:52:09.000000000 +0200
9504 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/reiserfs_fs_sb.h 2008-10-13 14:54:20.000000000 +0200
9505 @@ -455,6 +455,7 @@ enum reiserfs_mount_options {
9506         REISERFS_POSIXACL,
9507         REISERFS_BARRIER_NONE,
9508         REISERFS_BARRIER_FLUSH,
9509 +       REISERFS_TAGGED,
9510  
9511         /* Actions on error */
9512         REISERFS_ERROR_PANIC,
9513 diff -NurpP --minimal linux-2.6.27.25/include/linux/sched.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/sched.h
9514 --- linux-2.6.27.25/include/linux/sched.h       2009-06-15 17:18:32.000000000 +0200
9515 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/sched.h  2009-05-15 22:57:04.000000000 +0200
9516 @@ -71,7 +71,6 @@ struct sched_param {
9517  #include <linux/fs_struct.h>
9518  #include <linux/compiler.h>
9519  #include <linux/completion.h>
9520 -#include <linux/pid.h>
9521  #include <linux/percpu.h>
9522  #include <linux/topology.h>
9523  #include <linux/proportions.h>
9524 @@ -88,6 +87,7 @@ struct sched_param {
9525  #include <linux/kobject.h>
9526  #include <linux/latencytop.h>
9527  #include <linux/cred.h>
9528 +#include <linux/pid.h>
9529  
9530  #include <asm/processor.h>
9531  
9532 @@ -175,12 +175,13 @@ extern unsigned long long time_sync_thre
9533  #define TASK_UNINTERRUPTIBLE   2
9534  #define __TASK_STOPPED         4
9535  #define __TASK_TRACED          8
9536 +#define TASK_ONHOLD            16
9537  /* in tsk->exit_state */
9538 -#define EXIT_ZOMBIE            16
9539 -#define EXIT_DEAD              32
9540 +#define EXIT_ZOMBIE            32
9541 +#define EXIT_DEAD              64
9542  /* in tsk->state again */
9543 -#define TASK_DEAD              64
9544 -#define TASK_WAKEKILL          128
9545 +#define TASK_DEAD              128
9546 +#define TASK_WAKEKILL          256
9547  
9548  /* Convenience macros for the sake of set_task_state */
9549  #define TASK_KILLABLE          (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
9550 @@ -358,25 +359,27 @@ extern void arch_unmap_area_topdown(stru
9551   * The mm counters are not protected by its page_table_lock,
9552   * so must be incremented atomically.
9553   */
9554 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9555 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9556 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9557 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9558 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9559 -
9560 +#define __set_mm_counter(mm, member, value) \
9561 +       atomic_long_set(&(mm)->_##member, value)
9562 +#define get_mm_counter(mm, member) \
9563 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9564  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
9565  /*
9566   * The mm counters are protected by its page_table_lock,
9567   * so can be incremented directly.
9568   */
9569 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9570 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9571  #define get_mm_counter(mm, member) ((mm)->_##member)
9572 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9573 -#define inc_mm_counter(mm, member) (mm)->_##member++
9574 -#define dec_mm_counter(mm, member) (mm)->_##member--
9575  
9576  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
9577  
9578 +#define set_mm_counter(mm, member, value) \
9579 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9580 +#define add_mm_counter(mm, member, value) \
9581 +       vx_ ## member ## pages_add((mm), (value))
9582 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9583 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9584 +
9585  #define get_mm_rss(mm)                                 \
9586         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9587  #define update_hiwater_rss(mm) do {                    \
9588 @@ -1048,7 +1051,9 @@ struct task_struct {
9589         const struct sched_class *sched_class;
9590         struct sched_entity se;
9591         struct sched_rt_entity rt;
9592 -
9593 +#ifdef CONFIG_VSERVER_HARDCPU
9594 +       struct list_head hq;
9595 +#endif
9596  #ifdef CONFIG_PREEMPT_NOTIFIERS
9597         /* list of struct preempt_notifier: */
9598         struct hlist_head preempt_notifiers;
9599 @@ -1200,6 +1205,14 @@ struct task_struct {
9600  #endif
9601         seccomp_t seccomp;
9602  
9603 +/* vserver context data */
9604 +       struct vx_info *vx_info;
9605 +       struct nx_info *nx_info;
9606 +
9607 +       xid_t xid;
9608 +       nid_t nid;
9609 +       tag_t tag;
9610 +
9611  /* Thread group tracking */
9612         u32 parent_exec_id;
9613         u32 self_exec_id;
9614 @@ -1386,6 +1399,11 @@ struct pid_namespace;
9615   * see also pid_nr() etc in include/linux/pid.h
9616   */
9617  
9618 +#include <linux/vserver/base.h>
9619 +#include <linux/vserver/context.h>
9620 +#include <linux/vserver/debug.h>
9621 +#include <linux/vserver/pid.h>
9622 +
9623  static inline pid_t task_pid_nr(struct task_struct *tsk)
9624  {
9625         return tsk->pid;
9626 @@ -1395,7 +1413,7 @@ pid_t task_pid_nr_ns(struct task_struct 
9627  
9628  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9629  {
9630 -       return pid_vnr(task_pid(tsk));
9631 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
9632  }
9633  
9634  
9635 @@ -1408,7 +1426,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9636  
9637  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9638  {
9639 -       return pid_vnr(task_tgid(tsk));
9640 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9641  }
9642  
9643  
9644 diff -NurpP --minimal linux-2.6.27.25/include/linux/shmem_fs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/shmem_fs.h
9645 --- linux-2.6.27.25/include/linux/shmem_fs.h    2008-10-13 14:52:09.000000000 +0200
9646 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/shmem_fs.h       2008-10-13 14:54:20.000000000 +0200
9647 @@ -8,6 +8,9 @@
9648  
9649  #define SHMEM_NR_DIRECT 16
9650  
9651 +#define TMPFS_SUPER_MAGIC      0x01021994
9652 +
9653 +
9654  struct shmem_inode_info {
9655         spinlock_t              lock;
9656         unsigned long           flags;
9657 diff -NurpP --minimal linux-2.6.27.25/include/linux/stat.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/stat.h
9658 --- linux-2.6.27.25/include/linux/stat.h        2008-07-13 23:51:29.000000000 +0200
9659 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/stat.h   2008-10-13 14:54:20.000000000 +0200
9660 @@ -66,6 +66,7 @@ struct kstat {
9661         unsigned int    nlink;
9662         uid_t           uid;
9663         gid_t           gid;
9664 +       tag_t           tag;
9665         dev_t           rdev;
9666         loff_t          size;
9667         struct timespec  atime;
9668 diff -NurpP --minimal linux-2.6.27.25/include/linux/sunrpc/auth.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/sunrpc/auth.h
9669 --- linux-2.6.27.25/include/linux/sunrpc/auth.h 2008-07-13 23:51:29.000000000 +0200
9670 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/sunrpc/auth.h    2008-10-13 14:54:20.000000000 +0200
9671 @@ -25,6 +25,7 @@
9672  struct auth_cred {
9673         uid_t   uid;
9674         gid_t   gid;
9675 +       tag_t   tag;
9676         struct group_info *group_info;
9677         unsigned char machine_cred : 1;
9678  };
9679 diff -NurpP --minimal linux-2.6.27.25/include/linux/sunrpc/clnt.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/sunrpc/clnt.h
9680 --- linux-2.6.27.25/include/linux/sunrpc/clnt.h 2008-10-13 14:52:09.000000000 +0200
9681 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/sunrpc/clnt.h    2008-10-13 14:54:20.000000000 +0200
9682 @@ -43,7 +43,8 @@ struct rpc_clnt {
9683         unsigned int            cl_softrtry : 1,/* soft timeouts */
9684                                 cl_discrtry : 1,/* disconnect before retry */
9685                                 cl_autobind : 1,/* use getport() */
9686 -                               cl_chatty   : 1;/* be verbose */
9687 +                               cl_chatty   : 1,/* be verbose */
9688 +                               cl_tag      : 1;/* context tagging */
9689  
9690         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9691         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9692 diff -NurpP --minimal linux-2.6.27.25/include/linux/syscalls.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/syscalls.h
9693 --- linux-2.6.27.25/include/linux/syscalls.h    2009-06-15 17:18:32.000000000 +0200
9694 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/syscalls.h       2009-02-22 22:58:33.000000000 +0100
9695 @@ -364,6 +364,8 @@ asmlinkage long sys_symlink(const char _
9696  asmlinkage long sys_unlink(const char __user *pathname);
9697  asmlinkage long sys_rename(const char __user *oldname,
9698                                 const char __user *newname);
9699 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9700 +                               umode_t mode);
9701  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9702  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9703  
9704 diff -NurpP --minimal linux-2.6.27.25/include/linux/sysctl.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/sysctl.h
9705 --- linux-2.6.27.25/include/linux/sysctl.h      2008-10-13 14:52:09.000000000 +0200
9706 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/sysctl.h 2008-10-13 14:54:20.000000000 +0200
9707 @@ -70,6 +70,7 @@ enum
9708         CTL_ABI=9,              /* Binary emulation */
9709         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9710         CTL_ARLAN=254,          /* arlan wireless driver */
9711 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9712         CTL_S390DBF=5677,       /* s390 debug */
9713         CTL_SUNRPC=7249,        /* sunrpc debug */
9714         CTL_PM=9899,            /* frv power management */
9715 @@ -104,6 +105,7 @@ enum
9716  
9717         KERN_PANIC=15,          /* int: panic timeout */
9718         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9719 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9720  
9721         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9722         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9723 diff -NurpP --minimal linux-2.6.27.25/include/linux/sysfs.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/sysfs.h
9724 --- linux-2.6.27.25/include/linux/sysfs.h       2008-10-13 14:52:09.000000000 +0200
9725 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/sysfs.h  2008-10-13 14:54:20.000000000 +0200
9726 @@ -17,6 +17,8 @@
9727  #include <linux/list.h>
9728  #include <asm/atomic.h>
9729  
9730 +#define SYSFS_SUPER_MAGIC      0x62656572
9731 +
9732  struct kobject;
9733  struct module;
9734  
9735 diff -NurpP --minimal linux-2.6.27.25/include/linux/time.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/time.h
9736 --- linux-2.6.27.25/include/linux/time.h        2009-06-15 17:18:32.000000000 +0200
9737 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/time.h   2009-02-03 17:59:04.000000000 +0100
9738 @@ -180,6 +180,9 @@ static __always_inline void timespec_add
9739         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9740         a->tv_nsec = ns;
9741  }
9742 +
9743 +#include <linux/vs_time.h>
9744 +
9745  #endif /* __KERNEL__ */
9746  
9747  #define NFDBITS                        __NFDBITS
9748 diff -NurpP --minimal linux-2.6.27.25/include/linux/types.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/types.h
9749 --- linux-2.6.27.25/include/linux/types.h       2008-07-13 23:51:29.000000000 +0200
9750 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/types.h  2008-10-13 14:54:20.000000000 +0200
9751 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9752  typedef __kernel_gid32_t       gid_t;
9753  typedef __kernel_uid16_t        uid16_t;
9754  typedef __kernel_gid16_t        gid16_t;
9755 +typedef unsigned int           xid_t;
9756 +typedef unsigned int           nid_t;
9757 +typedef unsigned int           tag_t;
9758  
9759  typedef unsigned long          uintptr_t;
9760  
9761 diff -NurpP --minimal linux-2.6.27.25/include/linux/vroot.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vroot.h
9762 --- linux-2.6.27.25/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
9763 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vroot.h  2008-10-13 14:54:20.000000000 +0200
9764 @@ -0,0 +1,51 @@
9765 +
9766 +/*
9767 + * include/linux/vroot.h
9768 + *
9769 + * written by Herbert Pötzl, 9/11/2002
9770 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9771 + *
9772 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9773 + * Redistribution of this file is permitted under the
9774 + * GNU General Public License.
9775 + */
9776 +
9777 +#ifndef _LINUX_VROOT_H
9778 +#define _LINUX_VROOT_H
9779 +
9780 +
9781 +#ifdef __KERNEL__
9782 +
9783 +/* Possible states of device */
9784 +enum {
9785 +       Vr_unbound,
9786 +       Vr_bound,
9787 +};
9788 +
9789 +struct vroot_device {
9790 +       int             vr_number;
9791 +       int             vr_refcnt;
9792 +
9793 +       struct semaphore        vr_ctl_mutex;
9794 +       struct block_device    *vr_device;
9795 +       int                     vr_state;
9796 +};
9797 +
9798 +
9799 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9800 +
9801 +extern int register_vroot_grb(vroot_grb_func *);
9802 +extern int unregister_vroot_grb(vroot_grb_func *);
9803 +
9804 +#endif /* __KERNEL__ */
9805 +
9806 +#define MAX_VROOT_DEFAULT      8
9807 +
9808 +/*
9809 + * IOCTL commands --- we will commandeer 0x56 ('V')
9810 + */
9811 +
9812 +#define VROOT_SET_DEV          0x5600
9813 +#define VROOT_CLR_DEV          0x5601
9814 +
9815 +#endif /* _LINUX_VROOT_H */
9816 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_base.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_base.h
9817 --- linux-2.6.27.25/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
9818 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_base.h        2008-10-13 14:54:20.000000000 +0200
9819 @@ -0,0 +1,10 @@
9820 +#ifndef _VS_BASE_H
9821 +#define _VS_BASE_H
9822 +
9823 +#include "vserver/base.h"
9824 +#include "vserver/check.h"
9825 +#include "vserver/debug.h"
9826 +
9827 +#else
9828 +#warning duplicate inclusion
9829 +#endif
9830 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_context.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_context.h
9831 --- linux-2.6.27.25/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
9832 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_context.h     2008-10-13 14:54:20.000000000 +0200
9833 @@ -0,0 +1,227 @@
9834 +#ifndef _VS_CONTEXT_H
9835 +#define _VS_CONTEXT_H
9836 +
9837 +#include "vserver/base.h"
9838 +#include "vserver/check.h"
9839 +#include "vserver/context.h"
9840 +#include "vserver/history.h"
9841 +#include "vserver/debug.h"
9842 +
9843 +#include <linux/sched.h>
9844 +
9845 +
9846 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9847 +
9848 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9849 +       const char *_file, int _line, void *_here)
9850 +{
9851 +       if (!vxi)
9852 +               return NULL;
9853 +
9854 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9855 +               vxi, vxi ? vxi->vx_id : 0,
9856 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9857 +               _file, _line);
9858 +       __vxh_get_vx_info(vxi, _here);
9859 +
9860 +       atomic_inc(&vxi->vx_usecnt);
9861 +       return vxi;
9862 +}
9863 +
9864 +
9865 +extern void free_vx_info(struct vx_info *);
9866 +
9867 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9868 +
9869 +static inline void __put_vx_info(struct vx_info *vxi,
9870 +       const char *_file, int _line, void *_here)
9871 +{
9872 +       if (!vxi)
9873 +               return;
9874 +
9875 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9876 +               vxi, vxi ? vxi->vx_id : 0,
9877 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9878 +               _file, _line);
9879 +       __vxh_put_vx_info(vxi, _here);
9880 +
9881 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9882 +               free_vx_info(vxi);
9883 +}
9884 +
9885 +
9886 +#define init_vx_info(p, i) \
9887 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9888 +
9889 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9890 +       const char *_file, int _line, void *_here)
9891 +{
9892 +       if (vxi) {
9893 +               vxlprintk(VXD_CBIT(xid, 3),
9894 +                       "init_vx_info(%p[#%d.%d])",
9895 +                       vxi, vxi ? vxi->vx_id : 0,
9896 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9897 +                       _file, _line);
9898 +               __vxh_init_vx_info(vxi, vxp, _here);
9899 +
9900 +               atomic_inc(&vxi->vx_usecnt);
9901 +       }
9902 +       *vxp = vxi;
9903 +}
9904 +
9905 +
9906 +#define set_vx_info(p, i) \
9907 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9908 +
9909 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9910 +       const char *_file, int _line, void *_here)
9911 +{
9912 +       struct vx_info *vxo;
9913 +
9914 +       if (!vxi)
9915 +               return;
9916 +
9917 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9918 +               vxi, vxi ? vxi->vx_id : 0,
9919 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9920 +               _file, _line);
9921 +       __vxh_set_vx_info(vxi, vxp, _here);
9922 +
9923 +       atomic_inc(&vxi->vx_usecnt);
9924 +       vxo = xchg(vxp, vxi);
9925 +       BUG_ON(vxo);
9926 +}
9927 +
9928 +
9929 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9930 +
9931 +static inline void __clr_vx_info(struct vx_info **vxp,
9932 +       const char *_file, int _line, void *_here)
9933 +{
9934 +       struct vx_info *vxo;
9935 +
9936 +       vxo = xchg(vxp, NULL);
9937 +       if (!vxo)
9938 +               return;
9939 +
9940 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9941 +               vxo, vxo ? vxo->vx_id : 0,
9942 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9943 +               _file, _line);
9944 +       __vxh_clr_vx_info(vxo, vxp, _here);
9945 +
9946 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9947 +               free_vx_info(vxo);
9948 +}
9949 +
9950 +
9951 +#define claim_vx_info(v, p) \
9952 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9953 +
9954 +static inline void __claim_vx_info(struct vx_info *vxi,
9955 +       struct task_struct *task,
9956 +       const char *_file, int _line, void *_here)
9957 +{
9958 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9959 +               vxi, vxi ? vxi->vx_id : 0,
9960 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9961 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9962 +               task, _file, _line);
9963 +       __vxh_claim_vx_info(vxi, task, _here);
9964 +
9965 +       atomic_inc(&vxi->vx_tasks);
9966 +}
9967 +
9968 +
9969 +extern void unhash_vx_info(struct vx_info *);
9970 +
9971 +#define release_vx_info(v, p) \
9972 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9973 +
9974 +static inline void __release_vx_info(struct vx_info *vxi,
9975 +       struct task_struct *task,
9976 +       const char *_file, int _line, void *_here)
9977 +{
9978 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9979 +               vxi, vxi ? vxi->vx_id : 0,
9980 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9981 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9982 +               task, _file, _line);
9983 +       __vxh_release_vx_info(vxi, task, _here);
9984 +
9985 +       might_sleep();
9986 +
9987 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9988 +               unhash_vx_info(vxi);
9989 +}
9990 +
9991 +
9992 +#define task_get_vx_info(p) \
9993 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9994 +
9995 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9996 +       const char *_file, int _line, void *_here)
9997 +{
9998 +       struct vx_info *vxi;
9999 +
10000 +       task_lock(p);
10001 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
10002 +               p, _file, _line);
10003 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
10004 +       task_unlock(p);
10005 +       return vxi;
10006 +}
10007 +
10008 +
10009 +static inline void __wakeup_vx_info(struct vx_info *vxi)
10010 +{
10011 +       if (waitqueue_active(&vxi->vx_wait))
10012 +               wake_up_interruptible(&vxi->vx_wait);
10013 +}
10014 +
10015 +
10016 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
10017 +
10018 +static inline void __enter_vx_info(struct vx_info *vxi,
10019 +       struct vx_info_save *vxis, const char *_file, int _line)
10020 +{
10021 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
10022 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
10023 +               current->xid, current->vx_info, _file, _line);
10024 +       vxis->vxi = xchg(&current->vx_info, vxi);
10025 +       vxis->xid = current->xid;
10026 +       current->xid = vxi ? vxi->vx_id : 0;
10027 +}
10028 +
10029 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
10030 +
10031 +static inline void __leave_vx_info(struct vx_info_save *vxis,
10032 +       const char *_file, int _line)
10033 +{
10034 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
10035 +               vxis, vxis->xid, vxis->vxi, current,
10036 +               current->xid, current->vx_info, _file, _line);
10037 +       (void)xchg(&current->vx_info, vxis->vxi);
10038 +       current->xid = vxis->xid;
10039 +}
10040 +
10041 +
10042 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
10043 +{
10044 +       vxis->vxi = xchg(&current->vx_info, NULL);
10045 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10046 +}
10047 +
10048 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10049 +{
10050 +       (void)xchg(&current->xid, vxis->xid);
10051 +       (void)xchg(&current->vx_info, vxis->vxi);
10052 +}
10053 +
10054 +extern void exit_vx_info(struct task_struct *, int);
10055 +extern void exit_vx_info_early(struct task_struct *, int);
10056 +
10057 +
10058 +#else
10059 +#warning duplicate inclusion
10060 +#endif
10061 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_cowbl.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_cowbl.h
10062 --- linux-2.6.27.25/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
10063 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_cowbl.h       2008-10-13 14:54:20.000000000 +0200
10064 @@ -0,0 +1,47 @@
10065 +#ifndef _VS_COWBL_H
10066 +#define _VS_COWBL_H
10067 +
10068 +#include <linux/fs.h>
10069 +#include <linux/dcache.h>
10070 +#include <linux/namei.h>
10071 +
10072 +extern struct dentry *cow_break_link(const char *pathname);
10073 +
10074 +static inline int cow_check_and_break(struct path *path)
10075 +{
10076 +       struct inode *inode = path->dentry->d_inode;
10077 +       int error = 0;
10078 +
10079 +       /* do we need this check? */
10080 +       if (IS_RDONLY(inode))
10081 +               return -EROFS;
10082 +
10083 +       if (IS_COW(inode)) {
10084 +               if (IS_COW_LINK(inode)) {
10085 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
10086 +                       char *pp, *buf;
10087 +
10088 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
10089 +                       if (!buf) {
10090 +                               return -ENOMEM;
10091 +                       }
10092 +                       pp = d_path(path, buf, PATH_MAX);
10093 +                       new_dentry = cow_break_link(pp);
10094 +                       kfree(buf);
10095 +                       if (!IS_ERR(new_dentry)) {
10096 +                               path->dentry = new_dentry;
10097 +                               dput(old_dentry);
10098 +                       } else
10099 +                               error = PTR_ERR(new_dentry);
10100 +               } else {
10101 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
10102 +                       inode->i_ctime = CURRENT_TIME;
10103 +                       mark_inode_dirty(inode);
10104 +               }
10105 +       }
10106 +       return error;
10107 +}
10108 +
10109 +#else
10110 +#warning duplicate inclusion
10111 +#endif
10112 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_cvirt.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_cvirt.h
10113 --- linux-2.6.27.25/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
10114 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_cvirt.h       2008-10-13 14:54:20.000000000 +0200
10115 @@ -0,0 +1,50 @@
10116 +#ifndef _VS_CVIRT_H
10117 +#define _VS_CVIRT_H
10118 +
10119 +#include "vserver/cvirt.h"
10120 +#include "vserver/context.h"
10121 +#include "vserver/base.h"
10122 +#include "vserver/check.h"
10123 +#include "vserver/debug.h"
10124 +
10125 +
10126 +static inline void vx_activate_task(struct task_struct *p)
10127 +{
10128 +       struct vx_info *vxi;
10129 +
10130 +       if ((vxi = p->vx_info)) {
10131 +               vx_update_load(vxi);
10132 +               atomic_inc(&vxi->cvirt.nr_running);
10133 +       }
10134 +}
10135 +
10136 +static inline void vx_deactivate_task(struct task_struct *p)
10137 +{
10138 +       struct vx_info *vxi;
10139 +
10140 +       if ((vxi = p->vx_info)) {
10141 +               vx_update_load(vxi);
10142 +               atomic_dec(&vxi->cvirt.nr_running);
10143 +       }
10144 +}
10145 +
10146 +static inline void vx_uninterruptible_inc(struct task_struct *p)
10147 +{
10148 +       struct vx_info *vxi;
10149 +
10150 +       if ((vxi = p->vx_info))
10151 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
10152 +}
10153 +
10154 +static inline void vx_uninterruptible_dec(struct task_struct *p)
10155 +{
10156 +       struct vx_info *vxi;
10157 +
10158 +       if ((vxi = p->vx_info))
10159 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
10160 +}
10161 +
10162 +
10163 +#else
10164 +#warning duplicate inclusion
10165 +#endif
10166 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_device.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_device.h
10167 --- linux-2.6.27.25/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
10168 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_device.h      2008-10-13 14:54:20.000000000 +0200
10169 @@ -0,0 +1,45 @@
10170 +#ifndef _VS_DEVICE_H
10171 +#define _VS_DEVICE_H
10172 +
10173 +#include "vserver/base.h"
10174 +#include "vserver/device.h"
10175 +#include "vserver/debug.h"
10176 +
10177 +
10178 +#ifdef CONFIG_VSERVER_DEVICE
10179 +
10180 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
10181 +
10182 +#define vs_device_perm(v, d, m, p) \
10183 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
10184 +
10185 +#else
10186 +
10187 +static inline
10188 +int vs_map_device(struct vx_info *vxi,
10189 +       dev_t device, dev_t *target, umode_t mode)
10190 +{
10191 +       if (target)
10192 +               *target = device;
10193 +       return ~0;
10194 +}
10195 +
10196 +#define vs_device_perm(v, d, m, p) ((p) == (p))
10197 +
10198 +#endif
10199 +
10200 +
10201 +#define vs_map_chrdev(d, t, p) \
10202 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
10203 +#define vs_map_blkdev(d, t, p) \
10204 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
10205 +
10206 +#define vs_chrdev_perm(d, p) \
10207 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
10208 +#define vs_blkdev_perm(d, p) \
10209 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
10210 +
10211 +
10212 +#else
10213 +#warning duplicate inclusion
10214 +#endif
10215 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_dlimit.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_dlimit.h
10216 --- linux-2.6.27.25/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
10217 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_dlimit.h      2008-10-13 14:54:20.000000000 +0200
10218 @@ -0,0 +1,211 @@
10219 +#ifndef _VS_DLIMIT_H
10220 +#define _VS_DLIMIT_H
10221 +
10222 +#include <linux/fs.h>
10223 +
10224 +#include "vserver/dlimit.h"
10225 +#include "vserver/base.h"
10226 +#include "vserver/debug.h"
10227 +
10228 +
10229 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10230 +
10231 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10232 +       const char *_file, int _line)
10233 +{
10234 +       if (!dli)
10235 +               return NULL;
10236 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10237 +               dli, dli ? dli->dl_tag : 0,
10238 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10239 +               _file, _line);
10240 +       atomic_inc(&dli->dl_usecnt);
10241 +       return dli;
10242 +}
10243 +
10244 +
10245 +#define free_dl_info(i) \
10246 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10247 +
10248 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10249 +
10250 +static inline void __put_dl_info(struct dl_info *dli,
10251 +       const char *_file, int _line)
10252 +{
10253 +       if (!dli)
10254 +               return;
10255 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10256 +               dli, dli ? dli->dl_tag : 0,
10257 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10258 +               _file, _line);
10259 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10260 +               free_dl_info(dli);
10261 +}
10262 +
10263 +
10264 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10265 +
10266 +static inline int __dl_alloc_space(struct super_block *sb,
10267 +       tag_t tag, dlsize_t nr, const char *file, int line)
10268 +{
10269 +       struct dl_info *dli = NULL;
10270 +       int ret = 0;
10271 +
10272 +       if (nr == 0)
10273 +               goto out;
10274 +       dli = locate_dl_info(sb, tag);
10275 +       if (!dli)
10276 +               goto out;
10277 +
10278 +       spin_lock(&dli->dl_lock);
10279 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10280 +       if (!ret)
10281 +               dli->dl_space_used += nr;
10282 +       spin_unlock(&dli->dl_lock);
10283 +       put_dl_info(dli);
10284 +out:
10285 +       vxlprintk(VXD_CBIT(dlim, 1),
10286 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10287 +               sb, tag, __dlimit_char(dli), (long long)nr,
10288 +               ret, file, line);
10289 +       return ret;
10290 +}
10291 +
10292 +static inline void __dl_free_space(struct super_block *sb,
10293 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10294 +{
10295 +       struct dl_info *dli = NULL;
10296 +
10297 +       if (nr == 0)
10298 +               goto out;
10299 +       dli = locate_dl_info(sb, tag);
10300 +       if (!dli)
10301 +               goto out;
10302 +
10303 +       spin_lock(&dli->dl_lock);
10304 +       if (dli->dl_space_used > nr)
10305 +               dli->dl_space_used -= nr;
10306 +       else
10307 +               dli->dl_space_used = 0;
10308 +       spin_unlock(&dli->dl_lock);
10309 +       put_dl_info(dli);
10310 +out:
10311 +       vxlprintk(VXD_CBIT(dlim, 1),
10312 +               "FREE  (%p,#%d)%c %lld bytes",
10313 +               sb, tag, __dlimit_char(dli), (long long)nr,
10314 +               _file, _line);
10315 +}
10316 +
10317 +static inline int __dl_alloc_inode(struct super_block *sb,
10318 +       tag_t tag, const char *_file, int _line)
10319 +{
10320 +       struct dl_info *dli;
10321 +       int ret = 0;
10322 +
10323 +       dli = locate_dl_info(sb, tag);
10324 +       if (!dli)
10325 +               goto out;
10326 +
10327 +       spin_lock(&dli->dl_lock);
10328 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10329 +       if (!ret)
10330 +               dli->dl_inodes_used++;
10331 +       spin_unlock(&dli->dl_lock);
10332 +       put_dl_info(dli);
10333 +out:
10334 +       vxlprintk(VXD_CBIT(dlim, 0),
10335 +               "ALLOC (%p,#%d)%c inode (%d)",
10336 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10337 +       return ret;
10338 +}
10339 +
10340 +static inline void __dl_free_inode(struct super_block *sb,
10341 +       tag_t tag, const char *_file, int _line)
10342 +{
10343 +       struct dl_info *dli;
10344 +
10345 +       dli = locate_dl_info(sb, tag);
10346 +       if (!dli)
10347 +               goto out;
10348 +
10349 +       spin_lock(&dli->dl_lock);
10350 +       if (dli->dl_inodes_used > 1)
10351 +               dli->dl_inodes_used--;
10352 +       else
10353 +               dli->dl_inodes_used = 0;
10354 +       spin_unlock(&dli->dl_lock);
10355 +       put_dl_info(dli);
10356 +out:
10357 +       vxlprintk(VXD_CBIT(dlim, 0),
10358 +               "FREE  (%p,#%d)%c inode",
10359 +               sb, tag, __dlimit_char(dli), _file, _line);
10360 +}
10361 +
10362 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10363 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10364 +       const char *_file, int _line)
10365 +{
10366 +       struct dl_info *dli;
10367 +       uint64_t broot, bfree;
10368 +
10369 +       dli = locate_dl_info(sb, tag);
10370 +       if (!dli)
10371 +               return;
10372 +
10373 +       spin_lock(&dli->dl_lock);
10374 +       broot = (dli->dl_space_total -
10375 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10376 +               >> sb->s_blocksize_bits;
10377 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10378 +                       >> sb->s_blocksize_bits;
10379 +       spin_unlock(&dli->dl_lock);
10380 +
10381 +       vxlprintk(VXD_CBIT(dlim, 2),
10382 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10383 +               (long long)bfree, (long long)broot,
10384 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10385 +               _file, _line);
10386 +       if (free_blocks) {
10387 +               if (*free_blocks > bfree)
10388 +                       *free_blocks = bfree;
10389 +       }
10390 +       if (root_blocks) {
10391 +               if (*root_blocks > broot)
10392 +                       *root_blocks = broot;
10393 +       }
10394 +       put_dl_info(dli);
10395 +}
10396 +
10397 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
10398 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10399 +               __FILE__, __LINE__ )
10400 +
10401 +#define DLIMIT_FREE_SPACE(in, bytes) \
10402 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10403 +               __FILE__, __LINE__ )
10404 +
10405 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
10406 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
10407 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10408 +               __FILE__, __LINE__ )
10409 +
10410 +#define DLIMIT_FREE_BLOCK(in, nr) \
10411 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
10412 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10413 +               __FILE__, __LINE__ )
10414 +
10415 +
10416 +#define DLIMIT_ALLOC_INODE(in) \
10417 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10418 +
10419 +#define DLIMIT_FREE_INODE(in) \
10420 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10421 +
10422 +
10423 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
10424 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10425 +
10426 +
10427 +#else
10428 +#warning duplicate inclusion
10429 +#endif
10430 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/base.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/base.h
10431 --- linux-2.6.27.25/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
10432 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/base.h   2008-10-13 14:54:20.000000000 +0200
10433 @@ -0,0 +1,157 @@
10434 +#ifndef _VX_BASE_H
10435 +#define _VX_BASE_H
10436 +
10437 +
10438 +/* context state changes */
10439 +
10440 +enum {
10441 +       VSC_STARTUP = 1,
10442 +       VSC_SHUTDOWN,
10443 +
10444 +       VSC_NETUP,
10445 +       VSC_NETDOWN,
10446 +};
10447 +
10448 +
10449 +
10450 +#define vx_task_xid(t) ((t)->xid)
10451 +
10452 +#define vx_current_xid() vx_task_xid(current)
10453 +
10454 +#define current_vx_info() (current->vx_info)
10455 +
10456 +
10457 +#define nx_task_nid(t) ((t)->nid)
10458 +
10459 +#define nx_current_nid() nx_task_nid(current)
10460 +
10461 +#define current_nx_info() (current->nx_info)
10462 +
10463 +
10464 +/* generic flag merging */
10465 +
10466 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10467 +
10468 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10469 +
10470 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10471 +
10472 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10473 +
10474 +
10475 +/* context flags */
10476 +
10477 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10478 +
10479 +#define vx_current_flags()     __vx_flags(current->vx_info)
10480 +
10481 +#define vx_info_flags(v, m, f) \
10482 +       vs_check_flags(__vx_flags(v), m, f)
10483 +
10484 +#define task_vx_flags(t, m, f) \
10485 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10486 +
10487 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
10488 +
10489 +
10490 +/* context caps */
10491 +
10492 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10493 +
10494 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
10495 +
10496 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10497 +
10498 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
10499 +
10500 +
10501 +
10502 +/* network flags */
10503 +
10504 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10505 +
10506 +#define nx_current_flags()     __nx_flags(current->nx_info)
10507 +
10508 +#define nx_info_flags(n, m, f) \
10509 +       vs_check_flags(__nx_flags(n), m, f)
10510 +
10511 +#define task_nx_flags(t, m, f) \
10512 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10513 +
10514 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
10515 +
10516 +
10517 +/* network caps */
10518 +
10519 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10520 +
10521 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
10522 +
10523 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10524 +
10525 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
10526 +
10527 +
10528 +/* context mask capabilities */
10529 +
10530 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10531 +
10532 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10533 +
10534 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
10535 +
10536 +
10537 +/* context bcap mask */
10538 +
10539 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10540 +
10541 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
10542 +
10543 +
10544 +/* mask given bcaps */
10545 +
10546 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10547 +
10548 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
10549 +
10550 +
10551 +/* masked cap_bset */
10552 +
10553 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10554 +
10555 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
10556 +
10557 +#if 0
10558 +#define vx_info_mbcap(v, b) \
10559 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10560 +       vx_info_bcaps(v, b) : (b))
10561 +
10562 +#define task_vx_mbcap(t, b) \
10563 +       vx_info_mbcap((t)->vx_info, (t)->b)
10564 +
10565 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10566 +#endif
10567 +
10568 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10569 +
10570 +#define vx_capable(b, c) (capable(b) || \
10571 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
10572 +
10573 +#define nx_capable(b, c) (capable(b) || \
10574 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
10575 +
10576 +#define vx_current_initpid(n) \
10577 +       (current->vx_info && \
10578 +       (current->vx_info->vx_initpid == (n)))
10579 +
10580 +
10581 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10582 +
10583 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10584 +
10585 +
10586 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10587 +
10588 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10589 +
10590 +#endif
10591 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cacct_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct_cmd.h
10592 --- linux-2.6.27.25/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
10593 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct_cmd.h      2008-10-13 14:54:20.000000000 +0200
10594 @@ -0,0 +1,23 @@
10595 +#ifndef _VX_CACCT_CMD_H
10596 +#define _VX_CACCT_CMD_H
10597 +
10598 +
10599 +/* virtual host info name commands */
10600 +
10601 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10602 +
10603 +struct vcmd_sock_stat_v0 {
10604 +       uint32_t field;
10605 +       uint32_t count[3];
10606 +       uint64_t total[3];
10607 +};
10608 +
10609 +
10610 +#ifdef __KERNEL__
10611 +
10612 +#include <linux/compiler.h>
10613 +
10614 +extern int vc_sock_stat(struct vx_info *, void __user *);
10615 +
10616 +#endif /* __KERNEL__ */
10617 +#endif /* _VX_CACCT_CMD_H */
10618 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cacct_def.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct_def.h
10619 --- linux-2.6.27.25/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
10620 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct_def.h      2008-10-13 14:54:20.000000000 +0200
10621 @@ -0,0 +1,43 @@
10622 +#ifndef _VX_CACCT_DEF_H
10623 +#define _VX_CACCT_DEF_H
10624 +
10625 +#include <asm/atomic.h>
10626 +#include <linux/vserver/cacct.h>
10627 +
10628 +
10629 +struct _vx_sock_acc {
10630 +       atomic_long_t count;
10631 +       atomic_long_t total;
10632 +};
10633 +
10634 +/* context sub struct */
10635 +
10636 +struct _vx_cacct {
10637 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10638 +       atomic_t slab[8];
10639 +       atomic_t page[6][8];
10640 +};
10641 +
10642 +#ifdef CONFIG_VSERVER_DEBUG
10643 +
10644 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10645 +{
10646 +       int i, j;
10647 +
10648 +       printk("\t_vx_cacct:");
10649 +       for (i = 0; i < 6; i++) {
10650 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10651 +
10652 +               printk("\t [%d] =", i);
10653 +               for (j = 0; j < 3; j++) {
10654 +                       printk(" [%d] = %8lu, %8lu", j,
10655 +                               atomic_long_read(&ptr[j].count),
10656 +                               atomic_long_read(&ptr[j].total));
10657 +               }
10658 +               printk("\n");
10659 +       }
10660 +}
10661 +
10662 +#endif
10663 +
10664 +#endif /* _VX_CACCT_DEF_H */
10665 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cacct.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct.h
10666 --- linux-2.6.27.25/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
10667 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct.h  2008-10-13 14:54:20.000000000 +0200
10668 @@ -0,0 +1,15 @@
10669 +#ifndef _VX_CACCT_H
10670 +#define _VX_CACCT_H
10671 +
10672 +
10673 +enum sock_acc_field {
10674 +       VXA_SOCK_UNSPEC = 0,
10675 +       VXA_SOCK_UNIX,
10676 +       VXA_SOCK_INET,
10677 +       VXA_SOCK_INET6,
10678 +       VXA_SOCK_PACKET,
10679 +       VXA_SOCK_OTHER,
10680 +       VXA_SOCK_SIZE   /* array size */
10681 +};
10682 +
10683 +#endif /* _VX_CACCT_H */
10684 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cacct_int.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct_int.h
10685 --- linux-2.6.27.25/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
10686 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cacct_int.h      2008-10-13 14:54:20.000000000 +0200
10687 @@ -0,0 +1,21 @@
10688 +#ifndef _VX_CACCT_INT_H
10689 +#define _VX_CACCT_INT_H
10690 +
10691 +
10692 +#ifdef __KERNEL__
10693 +
10694 +static inline
10695 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10696 +{
10697 +       return atomic_long_read(&cacct->sock[type][pos].count);
10698 +}
10699 +
10700 +
10701 +static inline
10702 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10703 +{
10704 +       return atomic_long_read(&cacct->sock[type][pos].total);
10705 +}
10706 +
10707 +#endif /* __KERNEL__ */
10708 +#endif /* _VX_CACCT_INT_H */
10709 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/check.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/check.h
10710 --- linux-2.6.27.25/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
10711 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/check.h  2008-10-13 14:54:20.000000000 +0200
10712 @@ -0,0 +1,89 @@
10713 +#ifndef _VS_CHECK_H
10714 +#define _VS_CHECK_H
10715 +
10716 +
10717 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10718 +
10719 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10720 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10721 +#else
10722 +#define MIN_D_CONTEXT  65536
10723 +#endif
10724 +
10725 +/* check conditions */
10726 +
10727 +#define VS_ADMIN       0x0001
10728 +#define VS_WATCH       0x0002
10729 +#define VS_HIDE                0x0004
10730 +#define VS_HOSTID      0x0008
10731 +
10732 +#define VS_IDENT       0x0010
10733 +#define VS_EQUIV       0x0020
10734 +#define VS_PARENT      0x0040
10735 +#define VS_CHILD       0x0080
10736 +
10737 +#define VS_ARG_MASK    0x00F0
10738 +
10739 +#define VS_DYNAMIC     0x0100
10740 +#define VS_STATIC      0x0200
10741 +
10742 +#define VS_ATR_MASK    0x0F00
10743 +
10744 +#ifdef CONFIG_VSERVER_PRIVACY
10745 +#define VS_ADMIN_P     (0)
10746 +#define VS_WATCH_P     (0)
10747 +#else
10748 +#define VS_ADMIN_P     VS_ADMIN
10749 +#define VS_WATCH_P     VS_WATCH
10750 +#endif
10751 +
10752 +#define VS_HARDIRQ     0x1000
10753 +#define VS_SOFTIRQ     0x2000
10754 +#define VS_IRQ         0x4000
10755 +
10756 +#define VS_IRQ_MASK    0xF000
10757 +
10758 +#include <linux/hardirq.h>
10759 +
10760 +/*
10761 + * check current context for ADMIN/WATCH and
10762 + * optionally against supplied argument
10763 + */
10764 +static inline int __vs_check(int cid, int id, unsigned int mode)
10765 +{
10766 +       if (mode & VS_ARG_MASK) {
10767 +               if ((mode & VS_IDENT) && (id == cid))
10768 +                       return 1;
10769 +       }
10770 +       if (mode & VS_ATR_MASK) {
10771 +               if ((mode & VS_DYNAMIC) &&
10772 +                       (id >= MIN_D_CONTEXT) &&
10773 +                       (id <= MAX_S_CONTEXT))
10774 +                       return 1;
10775 +               if ((mode & VS_STATIC) &&
10776 +                       (id > 1) && (id < MIN_D_CONTEXT))
10777 +                       return 1;
10778 +       }
10779 +       if (mode & VS_IRQ_MASK) {
10780 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10781 +                       return 1;
10782 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10783 +                       return 1;
10784 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10785 +                       return 1;
10786 +       }
10787 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10788 +               ((mode & VS_WATCH) && (cid == 1)) ||
10789 +               ((mode & VS_HOSTID) && (id == 0)));
10790 +}
10791 +
10792 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10793 +
10794 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10795 +
10796 +
10797 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10798 +
10799 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10800 +
10801 +#endif
10802 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/context_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/context_cmd.h
10803 --- linux-2.6.27.25/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
10804 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/context_cmd.h    2008-10-13 14:54:20.000000000 +0200
10805 @@ -0,0 +1,128 @@
10806 +#ifndef _VX_CONTEXT_CMD_H
10807 +#define _VX_CONTEXT_CMD_H
10808 +
10809 +
10810 +/* vinfo commands */
10811 +
10812 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10813 +
10814 +#ifdef __KERNEL__
10815 +extern int vc_task_xid(uint32_t);
10816 +
10817 +#endif /* __KERNEL__ */
10818 +
10819 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10820 +
10821 +struct vcmd_vx_info_v0 {
10822 +       uint32_t xid;
10823 +       uint32_t initpid;
10824 +       /* more to come */
10825 +};
10826 +
10827 +#ifdef __KERNEL__
10828 +extern int vc_vx_info(struct vx_info *, void __user *);
10829 +
10830 +#endif /* __KERNEL__ */
10831 +
10832 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10833 +
10834 +struct vcmd_ctx_stat_v0 {
10835 +       uint32_t usecnt;
10836 +       uint32_t tasks;
10837 +       /* more to come */
10838 +};
10839 +
10840 +#ifdef __KERNEL__
10841 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10842 +
10843 +#endif /* __KERNEL__ */
10844 +
10845 +/* context commands */
10846 +
10847 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10848 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10849 +
10850 +struct vcmd_ctx_create {
10851 +       uint64_t flagword;
10852 +};
10853 +
10854 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10855 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10856 +
10857 +struct vcmd_ctx_migrate {
10858 +       uint64_t flagword;
10859 +};
10860 +
10861 +#ifdef __KERNEL__
10862 +extern int vc_ctx_create(uint32_t, void __user *);
10863 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10864 +
10865 +#endif /* __KERNEL__ */
10866 +
10867 +
10868 +/* flag commands */
10869 +
10870 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10871 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10872 +
10873 +struct vcmd_ctx_flags_v0 {
10874 +       uint64_t flagword;
10875 +       uint64_t mask;
10876 +};
10877 +
10878 +#ifdef __KERNEL__
10879 +extern int vc_get_cflags(struct vx_info *, void __user *);
10880 +extern int vc_set_cflags(struct vx_info *, void __user *);
10881 +
10882 +#endif /* __KERNEL__ */
10883 +
10884 +
10885 +/* context caps commands */
10886 +
10887 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10888 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10889 +
10890 +struct vcmd_ctx_caps_v1 {
10891 +       uint64_t ccaps;
10892 +       uint64_t cmask;
10893 +};
10894 +
10895 +#ifdef __KERNEL__
10896 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10897 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10898 +
10899 +#endif /* __KERNEL__ */
10900 +
10901 +
10902 +/* bcaps commands */
10903 +
10904 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10905 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10906 +
10907 +struct vcmd_bcaps {
10908 +       uint64_t bcaps;
10909 +       uint64_t bmask;
10910 +};
10911 +
10912 +#ifdef __KERNEL__
10913 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10914 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10915 +
10916 +#endif /* __KERNEL__ */
10917 +
10918 +
10919 +/* OOM badness */
10920 +
10921 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10922 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10923 +
10924 +struct vcmd_badness_v0 {
10925 +       int64_t bias;
10926 +};
10927 +
10928 +#ifdef __KERNEL__
10929 +extern int vc_get_badness(struct vx_info *, void __user *);
10930 +extern int vc_set_badness(struct vx_info *, void __user *);
10931 +
10932 +#endif /* __KERNEL__ */
10933 +#endif /* _VX_CONTEXT_CMD_H */
10934 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/context.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/context.h
10935 --- linux-2.6.27.25/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
10936 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/context.h        2009-03-09 15:36:36.000000000 +0100
10937 @@ -0,0 +1,179 @@
10938 +#ifndef _VX_CONTEXT_H
10939 +#define _VX_CONTEXT_H
10940 +
10941 +#include <linux/types.h>
10942 +#include <linux/capability.h>
10943 +
10944 +
10945 +/* context flags */
10946 +
10947 +#define VXF_INFO_SCHED         0x00000002
10948 +#define VXF_INFO_NPROC         0x00000004
10949 +#define VXF_INFO_PRIVATE       0x00000008
10950 +
10951 +#define VXF_INFO_INIT          0x00000010
10952 +#define VXF_INFO_HIDE          0x00000020
10953 +#define VXF_INFO_ULIMIT                0x00000040
10954 +#define VXF_INFO_NSPACE                0x00000080
10955 +
10956 +#define VXF_SCHED_HARD         0x00000100
10957 +#define VXF_SCHED_PRIO         0x00000200
10958 +#define VXF_SCHED_PAUSE                0x00000400
10959 +
10960 +#define VXF_VIRT_MEM           0x00010000
10961 +#define VXF_VIRT_UPTIME                0x00020000
10962 +#define VXF_VIRT_CPU           0x00040000
10963 +#define VXF_VIRT_LOAD          0x00080000
10964 +#define VXF_VIRT_TIME          0x00100000
10965 +
10966 +#define VXF_HIDE_MOUNT         0x01000000
10967 +/* was VXF_HIDE_NETIF          0x02000000 */
10968 +#define VXF_HIDE_VINFO         0x04000000
10969 +
10970 +#define VXF_STATE_SETUP                (1ULL << 32)
10971 +#define VXF_STATE_INIT         (1ULL << 33)
10972 +#define VXF_STATE_ADMIN                (1ULL << 34)
10973 +
10974 +#define VXF_SC_HELPER          (1ULL << 36)
10975 +#define VXF_REBOOT_KILL                (1ULL << 37)
10976 +#define VXF_PERSISTENT         (1ULL << 38)
10977 +
10978 +#define VXF_FORK_RSS           (1ULL << 48)
10979 +#define VXF_PROLIFIC           (1ULL << 49)
10980 +
10981 +#define VXF_IGNEG_NICE         (1ULL << 52)
10982 +
10983 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10984 +
10985 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10986 +
10987 +
10988 +/* context migration */
10989 +
10990 +#define VXM_SET_INIT           0x00000001
10991 +#define VXM_SET_REAPER         0x00000002
10992 +
10993 +/* context caps */
10994 +
10995 +#define VXC_CAP_MASK           0x00000000
10996 +
10997 +#define VXC_SET_UTSNAME                0x00000001
10998 +#define VXC_SET_RLIMIT         0x00000002
10999 +#define VXC_FS_SECURITY                0x00000004
11000 +
11001 +/* was VXC_RAW_ICMP            0x00000100 */
11002 +#define VXC_SYSLOG             0x00001000
11003 +
11004 +#define VXC_SECURE_MOUNT       0x00010000
11005 +#define VXC_SECURE_REMOUNT     0x00020000
11006 +#define VXC_BINARY_MOUNT       0x00040000
11007 +
11008 +#define VXC_QUOTA_CTL          0x00100000
11009 +#define VXC_ADMIN_MAPPER       0x00200000
11010 +#define VXC_ADMIN_CLOOP                0x00400000
11011 +
11012 +#define VXC_KTHREAD            0x01000000
11013 +
11014 +
11015 +#ifdef __KERNEL__
11016 +
11017 +#include <linux/list.h>
11018 +#include <linux/spinlock.h>
11019 +#include <linux/rcupdate.h>
11020 +
11021 +#include "limit_def.h"
11022 +#include "sched_def.h"
11023 +#include "cvirt_def.h"
11024 +#include "cacct_def.h"
11025 +#include "device_def.h"
11026 +
11027 +#define VX_SPACES      2
11028 +
11029 +struct _vx_info_pc {
11030 +       struct _vx_sched_pc sched_pc;
11031 +       struct _vx_cvirt_pc cvirt_pc;
11032 +};
11033 +
11034 +struct vx_info {
11035 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11036 +       xid_t vx_id;                            /* context id */
11037 +       atomic_t vx_usecnt;                     /* usage count */
11038 +       atomic_t vx_tasks;                      /* tasks count */
11039 +       struct vx_info *vx_parent;              /* parent context */
11040 +       int vx_state;                           /* context state */
11041 +
11042 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
11043 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
11044 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
11045 +
11046 +       uint64_t vx_flags;                      /* context flags */
11047 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11048 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11049 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
11050 +
11051 +       struct task_struct *vx_reaper;          /* guest reaper process */
11052 +       pid_t vx_initpid;                       /* PID of guest init */
11053 +       int64_t vx_badness_bias;                /* OOM points bias */
11054 +
11055 +       struct _vx_limit limit;                 /* vserver limits */
11056 +       struct _vx_sched sched;                 /* vserver scheduler */
11057 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11058 +       struct _vx_cacct cacct;                 /* context accounting */
11059 +
11060 +       struct _vx_device dmap;                 /* default device map targets */
11061 +
11062 +#ifndef CONFIG_SMP
11063 +       struct _vx_info_pc info_pc;             /* per cpu data */
11064 +#else
11065 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11066 +#endif
11067 +
11068 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11069 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11070 +       int exit_code;                          /* last process exit code */
11071 +
11072 +       char vx_name[65];                       /* vserver name */
11073 +};
11074 +
11075 +#ifndef CONFIG_SMP
11076 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11077 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11078 +#else
11079 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11080 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11081 +#endif
11082 +
11083 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11084 +
11085 +
11086 +struct vx_info_save {
11087 +       struct vx_info *vxi;
11088 +       xid_t xid;
11089 +};
11090 +
11091 +
11092 +/* status flags */
11093 +
11094 +#define VXS_HASHED     0x0001
11095 +#define VXS_PAUSED     0x0010
11096 +#define VXS_SHUTDOWN   0x0100
11097 +#define VXS_HELPER     0x1000
11098 +#define VXS_RELEASED   0x8000
11099 +
11100 +
11101 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11102 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11103 +
11104 +extern struct vx_info *lookup_vx_info(int);
11105 +extern struct vx_info *lookup_or_create_vx_info(int);
11106 +
11107 +extern int get_xid_list(int, unsigned int *, int);
11108 +extern int xid_is_hashed(xid_t);
11109 +
11110 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11111 +
11112 +extern long vs_state_change(struct vx_info *, unsigned int);
11113 +
11114 +
11115 +#endif /* __KERNEL__ */
11116 +#endif /* _VX_CONTEXT_H */
11117 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cvirt_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cvirt_cmd.h
11118 --- linux-2.6.27.25/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
11119 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cvirt_cmd.h      2008-10-13 14:54:20.000000000 +0200
11120 @@ -0,0 +1,53 @@
11121 +#ifndef _VX_CVIRT_CMD_H
11122 +#define _VX_CVIRT_CMD_H
11123 +
11124 +
11125 +/* virtual host info name commands */
11126 +
11127 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11128 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11129 +
11130 +struct vcmd_vhi_name_v0 {
11131 +       uint32_t field;
11132 +       char name[65];
11133 +};
11134 +
11135 +
11136 +enum vhi_name_field {
11137 +       VHIN_CONTEXT = 0,
11138 +       VHIN_SYSNAME,
11139 +       VHIN_NODENAME,
11140 +       VHIN_RELEASE,
11141 +       VHIN_VERSION,
11142 +       VHIN_MACHINE,
11143 +       VHIN_DOMAINNAME,
11144 +};
11145 +
11146 +
11147 +#ifdef __KERNEL__
11148 +
11149 +#include <linux/compiler.h>
11150 +
11151 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11152 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11153 +
11154 +#endif /* __KERNEL__ */
11155 +
11156 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11157 +
11158 +struct vcmd_virt_stat_v0 {
11159 +       uint64_t offset;
11160 +       uint64_t uptime;
11161 +       uint32_t nr_threads;
11162 +       uint32_t nr_running;
11163 +       uint32_t nr_uninterruptible;
11164 +       uint32_t nr_onhold;
11165 +       uint32_t nr_forks;
11166 +       uint32_t load[3];
11167 +};
11168 +
11169 +#ifdef __KERNEL__
11170 +extern int vc_virt_stat(struct vx_info *, void __user *);
11171 +
11172 +#endif /* __KERNEL__ */
11173 +#endif /* _VX_CVIRT_CMD_H */
11174 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cvirt_def.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cvirt_def.h
11175 --- linux-2.6.27.25/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
11176 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cvirt_def.h      2008-10-13 14:54:20.000000000 +0200
11177 @@ -0,0 +1,80 @@
11178 +#ifndef _VX_CVIRT_DEF_H
11179 +#define _VX_CVIRT_DEF_H
11180 +
11181 +#include <linux/jiffies.h>
11182 +#include <linux/spinlock.h>
11183 +#include <linux/wait.h>
11184 +#include <linux/time.h>
11185 +#include <asm/atomic.h>
11186 +
11187 +
11188 +struct _vx_usage_stat {
11189 +       uint64_t user;
11190 +       uint64_t nice;
11191 +       uint64_t system;
11192 +       uint64_t softirq;
11193 +       uint64_t irq;
11194 +       uint64_t idle;
11195 +       uint64_t iowait;
11196 +};
11197 +
11198 +struct _vx_syslog {
11199 +       wait_queue_head_t log_wait;
11200 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11201 +
11202 +       unsigned long log_start;        /* next char to be read by syslog() */
11203 +       unsigned long con_start;        /* next char to be sent to consoles */
11204 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11205 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11206 +
11207 +       char log_buf[1024];
11208 +};
11209 +
11210 +
11211 +/* context sub struct */
11212 +
11213 +struct _vx_cvirt {
11214 +       atomic_t nr_threads;            /* number of current threads */
11215 +       atomic_t nr_running;            /* number of running threads */
11216 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11217 +
11218 +       atomic_t nr_onhold;             /* processes on hold */
11219 +       uint32_t onhold_last;           /* jiffies when put on hold */
11220 +
11221 +       struct timeval bias_tv;         /* time offset to the host */
11222 +       struct timespec bias_idle;
11223 +       struct timespec bias_uptime;    /* context creation point */
11224 +       uint64_t bias_clock;            /* offset in clock_t */
11225 +
11226 +       spinlock_t load_lock;           /* lock for the load averages */
11227 +       atomic_t load_updates;          /* nr of load updates done so far */
11228 +       uint32_t load_last;             /* last time load was calculated */
11229 +       uint32_t load[3];               /* load averages 1,5,15 */
11230 +
11231 +       atomic_t total_forks;           /* number of forks so far */
11232 +
11233 +       struct _vx_syslog syslog;
11234 +};
11235 +
11236 +struct _vx_cvirt_pc {
11237 +       struct _vx_usage_stat cpustat;
11238 +};
11239 +
11240 +
11241 +#ifdef CONFIG_VSERVER_DEBUG
11242 +
11243 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11244 +{
11245 +       printk("\t_vx_cvirt:\n");
11246 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11247 +               atomic_read(&cvirt->nr_threads),
11248 +               atomic_read(&cvirt->nr_running),
11249 +               atomic_read(&cvirt->nr_uninterruptible),
11250 +               atomic_read(&cvirt->nr_onhold));
11251 +       /* add rest here */
11252 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11253 +}
11254 +
11255 +#endif
11256 +
11257 +#endif /* _VX_CVIRT_DEF_H */
11258 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/cvirt.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cvirt.h
11259 --- linux-2.6.27.25/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
11260 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/cvirt.h  2008-10-13 14:54:20.000000000 +0200
11261 @@ -0,0 +1,20 @@
11262 +#ifndef _VX_CVIRT_H
11263 +#define _VX_CVIRT_H
11264 +
11265 +
11266 +#ifdef __KERNEL__
11267 +
11268 +struct timespec;
11269 +
11270 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11271 +
11272 +
11273 +struct vx_info;
11274 +
11275 +void vx_update_load(struct vx_info *);
11276 +
11277 +
11278 +int vx_do_syslog(int, char __user *, int);
11279 +
11280 +#endif /* __KERNEL__ */
11281 +#endif /* _VX_CVIRT_H */
11282 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/debug_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/debug_cmd.h
11283 --- linux-2.6.27.25/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
11284 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/debug_cmd.h      2008-10-13 14:54:20.000000000 +0200
11285 @@ -0,0 +1,58 @@
11286 +#ifndef _VX_DEBUG_CMD_H
11287 +#define _VX_DEBUG_CMD_H
11288 +
11289 +
11290 +/* debug commands */
11291 +
11292 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11293 +
11294 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11295 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11296 +
11297 +struct  vcmd_read_history_v0 {
11298 +       uint32_t index;
11299 +       uint32_t count;
11300 +       char __user *data;
11301 +};
11302 +
11303 +struct  vcmd_read_monitor_v0 {
11304 +       uint32_t index;
11305 +       uint32_t count;
11306 +       char __user *data;
11307 +};
11308 +
11309 +
11310 +#ifdef __KERNEL__
11311 +
11312 +#ifdef CONFIG_COMPAT
11313 +
11314 +#include <asm/compat.h>
11315 +
11316 +struct vcmd_read_history_v0_x32 {
11317 +       uint32_t index;
11318 +       uint32_t count;
11319 +       compat_uptr_t data_ptr;
11320 +};
11321 +
11322 +struct vcmd_read_monitor_v0_x32 {
11323 +       uint32_t index;
11324 +       uint32_t count;
11325 +       compat_uptr_t data_ptr;
11326 +};
11327 +
11328 +#endif  /* CONFIG_COMPAT */
11329 +
11330 +extern int vc_dump_history(uint32_t);
11331 +
11332 +extern int vc_read_history(uint32_t, void __user *);
11333 +extern int vc_read_monitor(uint32_t, void __user *);
11334 +
11335 +#ifdef CONFIG_COMPAT
11336 +
11337 +extern int vc_read_history_x32(uint32_t, void __user *);
11338 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11339 +
11340 +#endif  /* CONFIG_COMPAT */
11341 +
11342 +#endif /* __KERNEL__ */
11343 +#endif /* _VX_DEBUG_CMD_H */
11344 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/debug.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/debug.h
11345 --- linux-2.6.27.25/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
11346 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/debug.h  2008-10-13 14:54:20.000000000 +0200
11347 @@ -0,0 +1,127 @@
11348 +#ifndef _VX_DEBUG_H
11349 +#define _VX_DEBUG_H
11350 +
11351 +
11352 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11353 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11354 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11355 +
11356 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11357 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11358 +#define VXF_DEV                "%p[%lu,%d:%d]"
11359 +
11360 +
11361 +#define vxd_path(p)                                            \
11362 +       ({ static char _buffer[PATH_MAX];                       \
11363 +          d_path(p, _buffer, sizeof(_buffer)); })
11364 +
11365 +#define vxd_cond_path(n)                                       \
11366 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11367 +
11368 +
11369 +#ifdef CONFIG_VSERVER_DEBUG
11370 +
11371 +extern unsigned int vx_debug_switch;
11372 +extern unsigned int vx_debug_xid;
11373 +extern unsigned int vx_debug_nid;
11374 +extern unsigned int vx_debug_tag;
11375 +extern unsigned int vx_debug_net;
11376 +extern unsigned int vx_debug_limit;
11377 +extern unsigned int vx_debug_cres;
11378 +extern unsigned int vx_debug_dlim;
11379 +extern unsigned int vx_debug_quota;
11380 +extern unsigned int vx_debug_cvirt;
11381 +extern unsigned int vx_debug_space;
11382 +extern unsigned int vx_debug_misc;
11383 +
11384 +
11385 +#define VX_LOGLEVEL    "vxD: "
11386 +#define VX_PROC_FMT    "%p: "
11387 +#define VX_PROCESS     current
11388 +
11389 +#define vxdprintk(c, f, x...)                                  \
11390 +       do {                                                    \
11391 +               if (c)                                          \
11392 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11393 +                               VX_PROCESS , ##x);              \
11394 +       } while (0)
11395 +
11396 +#define vxlprintk(c, f, x...)                                  \
11397 +       do {                                                    \
11398 +               if (c)                                          \
11399 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11400 +       } while (0)
11401 +
11402 +#define vxfprintk(c, f, x...)                                  \
11403 +       do {                                                    \
11404 +               if (c)                                          \
11405 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11406 +       } while (0)
11407 +
11408 +
11409 +struct vx_info;
11410 +
11411 +void dump_vx_info(struct vx_info *, int);
11412 +void dump_vx_info_inactive(int);
11413 +
11414 +#else  /* CONFIG_VSERVER_DEBUG */
11415 +
11416 +#define vx_debug_switch 0
11417 +#define vx_debug_xid   0
11418 +#define vx_debug_nid   0
11419 +#define vx_debug_tag   0
11420 +#define vx_debug_net   0
11421 +#define vx_debug_limit 0
11422 +#define vx_debug_cres  0
11423 +#define vx_debug_dlim  0
11424 +#define vx_debug_cvirt 0
11425 +
11426 +#define vxdprintk(x...) do { } while (0)
11427 +#define vxlprintk(x...) do { } while (0)
11428 +#define vxfprintk(x...) do { } while (0)
11429 +
11430 +#endif /* CONFIG_VSERVER_DEBUG */
11431 +
11432 +
11433 +#ifdef CONFIG_VSERVER_WARN
11434 +
11435 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11436 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11437 +#define VX_WARN_XID    "[xid #%u] "
11438 +#define VX_WARN_NID    "[nid #%u] "
11439 +#define VX_WARN_TAG    "[tag #%u] "
11440 +
11441 +#define vxwprintk(c, f, x...)                                  \
11442 +       do {                                                    \
11443 +               if (c)                                          \
11444 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11445 +       } while (0)
11446 +
11447 +#else  /* CONFIG_VSERVER_WARN */
11448 +
11449 +#define vxwprintk(x...) do { } while (0)
11450 +
11451 +#endif /* CONFIG_VSERVER_WARN */
11452 +
11453 +#define vxwprintk_task(c, f, x...)                             \
11454 +       vxwprintk(c, VX_WARN_TASK f,                            \
11455 +               current->comm, current->pid,                    \
11456 +               current->xid, current->nid, current->tag, ##x)
11457 +#define vxwprintk_xid(c, f, x...)                              \
11458 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11459 +#define vxwprintk_nid(c, f, x...)                              \
11460 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11461 +#define vxwprintk_tag(c, f, x...)                              \
11462 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11463 +
11464 +#ifdef CONFIG_VSERVER_DEBUG
11465 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11466 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11467 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11468 +#else
11469 +#define vxd_assert_lock(l)     do { } while (0)
11470 +#define vxd_assert(c, f, x...) do { } while (0)
11471 +#endif
11472 +
11473 +
11474 +#endif /* _VX_DEBUG_H */
11475 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/device_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/device_cmd.h
11476 --- linux-2.6.27.25/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
11477 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/device_cmd.h     2008-10-13 14:54:20.000000000 +0200
11478 @@ -0,0 +1,44 @@
11479 +#ifndef _VX_DEVICE_CMD_H
11480 +#define _VX_DEVICE_CMD_H
11481 +
11482 +
11483 +/*  device vserver commands */
11484 +
11485 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11486 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11487 +
11488 +struct vcmd_set_mapping_v0 {
11489 +       const char __user *device;
11490 +       const char __user *target;
11491 +       uint32_t flags;
11492 +};
11493 +
11494 +
11495 +#ifdef __KERNEL__
11496 +
11497 +#ifdef CONFIG_COMPAT
11498 +
11499 +#include <asm/compat.h>
11500 +
11501 +struct vcmd_set_mapping_v0_x32 {
11502 +       compat_uptr_t device_ptr;
11503 +       compat_uptr_t target_ptr;
11504 +       uint32_t flags;
11505 +};
11506 +
11507 +#endif /* CONFIG_COMPAT */
11508 +
11509 +#include <linux/compiler.h>
11510 +
11511 +extern int vc_set_mapping(struct vx_info *, void __user *);
11512 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11513 +
11514 +#ifdef CONFIG_COMPAT
11515 +
11516 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11517 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11518 +
11519 +#endif /* CONFIG_COMPAT */
11520 +
11521 +#endif /* __KERNEL__ */
11522 +#endif /* _VX_DEVICE_CMD_H */
11523 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/device_def.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/device_def.h
11524 --- linux-2.6.27.25/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
11525 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/device_def.h     2008-10-13 14:54:20.000000000 +0200
11526 @@ -0,0 +1,17 @@
11527 +#ifndef _VX_DEVICE_DEF_H
11528 +#define _VX_DEVICE_DEF_H
11529 +
11530 +#include <linux/types.h>
11531 +
11532 +struct vx_dmap_target {
11533 +       dev_t target;
11534 +       uint32_t flags;
11535 +};
11536 +
11537 +struct _vx_device {
11538 +#ifdef CONFIG_VSERVER_DEVICE
11539 +       struct vx_dmap_target targets[2];
11540 +#endif
11541 +};
11542 +
11543 +#endif /* _VX_DEVICE_DEF_H */
11544 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/device.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/device.h
11545 --- linux-2.6.27.25/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
11546 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/device.h 2008-10-13 14:54:20.000000000 +0200
11547 @@ -0,0 +1,15 @@
11548 +#ifndef _VX_DEVICE_H
11549 +#define _VX_DEVICE_H
11550 +
11551 +
11552 +#define DATTR_CREATE   0x00000001
11553 +#define DATTR_OPEN     0x00000002
11554 +
11555 +#define DATTR_REMAP    0x00000010
11556 +
11557 +#define DATTR_MASK     0x00000013
11558 +
11559 +
11560 +#else  /* _VX_DEVICE_H */
11561 +#warning duplicate inclusion
11562 +#endif /* _VX_DEVICE_H */
11563 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/dlimit_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/dlimit_cmd.h
11564 --- linux-2.6.27.25/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
11565 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/dlimit_cmd.h     2008-10-13 14:54:20.000000000 +0200
11566 @@ -0,0 +1,74 @@
11567 +#ifndef _VX_DLIMIT_CMD_H
11568 +#define _VX_DLIMIT_CMD_H
11569 +
11570 +
11571 +/*  dlimit vserver commands */
11572 +
11573 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11574 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11575 +
11576 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11577 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11578 +
11579 +struct vcmd_ctx_dlimit_base_v0 {
11580 +       const char __user *name;
11581 +       uint32_t flags;
11582 +};
11583 +
11584 +struct vcmd_ctx_dlimit_v0 {
11585 +       const char __user *name;
11586 +       uint32_t space_used;                    /* used space in kbytes */
11587 +       uint32_t space_total;                   /* maximum space in kbytes */
11588 +       uint32_t inodes_used;                   /* used inodes */
11589 +       uint32_t inodes_total;                  /* maximum inodes */
11590 +       uint32_t reserved;                      /* reserved for root in % */
11591 +       uint32_t flags;
11592 +};
11593 +
11594 +#define CDLIM_UNSET            ((uint32_t)0UL)
11595 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11596 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11597 +
11598 +#ifdef __KERNEL__
11599 +
11600 +#ifdef CONFIG_COMPAT
11601 +
11602 +#include <asm/compat.h>
11603 +
11604 +struct vcmd_ctx_dlimit_base_v0_x32 {
11605 +       compat_uptr_t name_ptr;
11606 +       uint32_t flags;
11607 +};
11608 +
11609 +struct vcmd_ctx_dlimit_v0_x32 {
11610 +       compat_uptr_t name_ptr;
11611 +       uint32_t space_used;                    /* used space in kbytes */
11612 +       uint32_t space_total;                   /* maximum space in kbytes */
11613 +       uint32_t inodes_used;                   /* used inodes */
11614 +       uint32_t inodes_total;                  /* maximum inodes */
11615 +       uint32_t reserved;                      /* reserved for root in % */
11616 +       uint32_t flags;
11617 +};
11618 +
11619 +#endif /* CONFIG_COMPAT */
11620 +
11621 +#include <linux/compiler.h>
11622 +
11623 +extern int vc_add_dlimit(uint32_t, void __user *);
11624 +extern int vc_rem_dlimit(uint32_t, void __user *);
11625 +
11626 +extern int vc_set_dlimit(uint32_t, void __user *);
11627 +extern int vc_get_dlimit(uint32_t, void __user *);
11628 +
11629 +#ifdef CONFIG_COMPAT
11630 +
11631 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11632 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11633 +
11634 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11635 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11636 +
11637 +#endif /* CONFIG_COMPAT */
11638 +
11639 +#endif /* __KERNEL__ */
11640 +#endif /* _VX_DLIMIT_CMD_H */
11641 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/dlimit.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/dlimit.h
11642 --- linux-2.6.27.25/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
11643 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/dlimit.h 2008-10-13 14:54:20.000000000 +0200
11644 @@ -0,0 +1,54 @@
11645 +#ifndef _VX_DLIMIT_H
11646 +#define _VX_DLIMIT_H
11647 +
11648 +#include "switch.h"
11649 +
11650 +
11651 +#ifdef __KERNEL__
11652 +
11653 +/*      keep in sync with CDLIM_INFINITY       */
11654 +
11655 +#define DLIM_INFINITY          (~0ULL)
11656 +
11657 +#include <linux/spinlock.h>
11658 +#include <linux/rcupdate.h>
11659 +
11660 +struct super_block;
11661 +
11662 +struct dl_info {
11663 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11664 +       struct rcu_head dl_rcu;                 /* the rcu head */
11665 +       tag_t dl_tag;                           /* context tag */
11666 +       atomic_t dl_usecnt;                     /* usage count */
11667 +       atomic_t dl_refcnt;                     /* reference count */
11668 +
11669 +       struct super_block *dl_sb;              /* associated superblock */
11670 +
11671 +       spinlock_t dl_lock;                     /* protect the values */
11672 +
11673 +       unsigned long long dl_space_used;       /* used space in bytes */
11674 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11675 +       unsigned long dl_inodes_used;           /* used inodes */
11676 +       unsigned long dl_inodes_total;          /* maximum inodes */
11677 +
11678 +       unsigned int dl_nrlmult;                /* non root limit mult */
11679 +};
11680 +
11681 +struct rcu_head;
11682 +
11683 +extern void rcu_free_dl_info(struct rcu_head *);
11684 +extern void unhash_dl_info(struct dl_info *);
11685 +
11686 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11687 +
11688 +
11689 +struct kstatfs;
11690 +
11691 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11692 +
11693 +typedef uint64_t dlsize_t;
11694 +
11695 +#endif /* __KERNEL__ */
11696 +#else  /* _VX_DLIMIT_H */
11697 +#warning duplicate inclusion
11698 +#endif /* _VX_DLIMIT_H */
11699 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/global.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/global.h
11700 --- linux-2.6.27.25/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
11701 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/global.h 2008-10-13 14:54:20.000000000 +0200
11702 @@ -0,0 +1,20 @@
11703 +#ifndef _VX_GLOBAL_H
11704 +#define _VX_GLOBAL_H
11705 +
11706 +
11707 +extern atomic_t vx_global_ctotal;
11708 +extern atomic_t vx_global_cactive;
11709 +
11710 +extern atomic_t nx_global_ctotal;
11711 +extern atomic_t nx_global_cactive;
11712 +
11713 +extern atomic_t vs_global_nsproxy;
11714 +extern atomic_t vs_global_fs;
11715 +extern atomic_t vs_global_mnt_ns;
11716 +extern atomic_t vs_global_uts_ns;
11717 +extern atomic_t vs_global_ipc_ns;
11718 +extern atomic_t vs_global_user_ns;
11719 +extern atomic_t vs_global_pid_ns;
11720 +
11721 +
11722 +#endif /* _VX_GLOBAL_H */
11723 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/history.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/history.h
11724 --- linux-2.6.27.25/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
11725 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/history.h        2008-10-13 14:54:20.000000000 +0200
11726 @@ -0,0 +1,197 @@
11727 +#ifndef _VX_HISTORY_H
11728 +#define _VX_HISTORY_H
11729 +
11730 +
11731 +enum {
11732 +       VXH_UNUSED = 0,
11733 +       VXH_THROW_OOPS = 1,
11734 +
11735 +       VXH_GET_VX_INFO,
11736 +       VXH_PUT_VX_INFO,
11737 +       VXH_INIT_VX_INFO,
11738 +       VXH_SET_VX_INFO,
11739 +       VXH_CLR_VX_INFO,
11740 +       VXH_CLAIM_VX_INFO,
11741 +       VXH_RELEASE_VX_INFO,
11742 +       VXH_ALLOC_VX_INFO,
11743 +       VXH_DEALLOC_VX_INFO,
11744 +       VXH_HASH_VX_INFO,
11745 +       VXH_UNHASH_VX_INFO,
11746 +       VXH_LOC_VX_INFO,
11747 +       VXH_LOOKUP_VX_INFO,
11748 +       VXH_CREATE_VX_INFO,
11749 +};
11750 +
11751 +struct _vxhe_vxi {
11752 +       struct vx_info *ptr;
11753 +       unsigned xid;
11754 +       unsigned usecnt;
11755 +       unsigned tasks;
11756 +};
11757 +
11758 +struct _vxhe_set_clr {
11759 +       void *data;
11760 +};
11761 +
11762 +struct _vxhe_loc_lookup {
11763 +       unsigned arg;
11764 +};
11765 +
11766 +struct _vx_hist_entry {
11767 +       void *loc;
11768 +       unsigned short seq;
11769 +       unsigned short type;
11770 +       struct _vxhe_vxi vxi;
11771 +       union {
11772 +               struct _vxhe_set_clr sc;
11773 +               struct _vxhe_loc_lookup ll;
11774 +       };
11775 +};
11776 +
11777 +#ifdef CONFIG_VSERVER_HISTORY
11778 +
11779 +extern unsigned volatile int vxh_active;
11780 +
11781 +struct _vx_hist_entry *vxh_advance(void *loc);
11782 +
11783 +
11784 +static inline
11785 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11786 +{
11787 +       entry->vxi.ptr = vxi;
11788 +       if (vxi) {
11789 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11790 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11791 +               entry->vxi.xid = vxi->vx_id;
11792 +       }
11793 +}
11794 +
11795 +
11796 +#define        __HERE__ current_text_addr()
11797 +
11798 +#define __VXH_BODY(__type, __data, __here)     \
11799 +       struct _vx_hist_entry *entry;           \
11800 +                                               \
11801 +       preempt_disable();                      \
11802 +       entry = vxh_advance(__here);            \
11803 +       __data;                                 \
11804 +       entry->type = __type;                   \
11805 +       preempt_enable();
11806 +
11807 +
11808 +       /* pass vxi only */
11809 +
11810 +#define __VXH_SMPL                             \
11811 +       __vxh_copy_vxi(entry, vxi)
11812 +
11813 +static inline
11814 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11815 +{
11816 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11817 +}
11818 +
11819 +       /* pass vxi and data (void *) */
11820 +
11821 +#define __VXH_DATA                             \
11822 +       __vxh_copy_vxi(entry, vxi);             \
11823 +       entry->sc.data = data
11824 +
11825 +static inline
11826 +void   __vxh_data(struct vx_info *vxi, void *data,
11827 +                       int __type, void *__here)
11828 +{
11829 +       __VXH_BODY(__type, __VXH_DATA, __here)
11830 +}
11831 +
11832 +       /* pass vxi and arg (long) */
11833 +
11834 +#define __VXH_LONG                             \
11835 +       __vxh_copy_vxi(entry, vxi);             \
11836 +       entry->ll.arg = arg
11837 +
11838 +static inline
11839 +void   __vxh_long(struct vx_info *vxi, long arg,
11840 +                       int __type, void *__here)
11841 +{
11842 +       __VXH_BODY(__type, __VXH_LONG, __here)
11843 +}
11844 +
11845 +
11846 +static inline
11847 +void   __vxh_throw_oops(void *__here)
11848 +{
11849 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11850 +       /* prevent further acquisition */
11851 +       vxh_active = 0;
11852 +}
11853 +
11854 +
11855 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11856 +
11857 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11858 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11859 +
11860 +#define __vxh_init_vx_info(v, d, h) \
11861 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11862 +#define __vxh_set_vx_info(v, d, h) \
11863 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11864 +#define __vxh_clr_vx_info(v, d, h) \
11865 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11866 +
11867 +#define __vxh_claim_vx_info(v, d, h) \
11868 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11869 +#define __vxh_release_vx_info(v, d, h) \
11870 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11871 +
11872 +#define vxh_alloc_vx_info(v) \
11873 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11874 +#define vxh_dealloc_vx_info(v) \
11875 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11876 +
11877 +#define vxh_hash_vx_info(v) \
11878 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11879 +#define vxh_unhash_vx_info(v) \
11880 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11881 +
11882 +#define vxh_loc_vx_info(v, l) \
11883 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11884 +#define vxh_lookup_vx_info(v, l) \
11885 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11886 +#define vxh_create_vx_info(v, l) \
11887 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11888 +
11889 +extern void vxh_dump_history(void);
11890 +
11891 +
11892 +#else  /* CONFIG_VSERVER_HISTORY */
11893 +
11894 +#define        __HERE__        0
11895 +
11896 +#define vxh_throw_oops()               do { } while (0)
11897 +
11898 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11899 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11900 +
11901 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11902 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11903 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11904 +
11905 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11906 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11907 +
11908 +#define vxh_alloc_vx_info(v)           do { } while (0)
11909 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11910 +
11911 +#define vxh_hash_vx_info(v)            do { } while (0)
11912 +#define vxh_unhash_vx_info(v)          do { } while (0)
11913 +
11914 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11915 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11916 +#define vxh_create_vx_info(v, l)       do { } while (0)
11917 +
11918 +#define vxh_dump_history()             do { } while (0)
11919 +
11920 +
11921 +#endif /* CONFIG_VSERVER_HISTORY */
11922 +
11923 +#endif /* _VX_HISTORY_H */
11924 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/inode_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/inode_cmd.h
11925 --- linux-2.6.27.25/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
11926 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/inode_cmd.h      2008-10-13 14:54:20.000000000 +0200
11927 @@ -0,0 +1,59 @@
11928 +#ifndef _VX_INODE_CMD_H
11929 +#define _VX_INODE_CMD_H
11930 +
11931 +
11932 +/*  inode vserver commands */
11933 +
11934 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11935 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11936 +
11937 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11938 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11939 +
11940 +struct vcmd_ctx_iattr_v1 {
11941 +       const char __user *name;
11942 +       uint32_t tag;
11943 +       uint32_t flags;
11944 +       uint32_t mask;
11945 +};
11946 +
11947 +struct vcmd_ctx_fiattr_v0 {
11948 +       uint32_t tag;
11949 +       uint32_t flags;
11950 +       uint32_t mask;
11951 +};
11952 +
11953 +
11954 +#ifdef __KERNEL__
11955 +
11956 +
11957 +#ifdef CONFIG_COMPAT
11958 +
11959 +#include <asm/compat.h>
11960 +
11961 +struct vcmd_ctx_iattr_v1_x32 {
11962 +       compat_uptr_t name_ptr;
11963 +       uint32_t tag;
11964 +       uint32_t flags;
11965 +       uint32_t mask;
11966 +};
11967 +
11968 +#endif /* CONFIG_COMPAT */
11969 +
11970 +#include <linux/compiler.h>
11971 +
11972 +extern int vc_get_iattr(void __user *);
11973 +extern int vc_set_iattr(void __user *);
11974 +
11975 +extern int vc_fget_iattr(uint32_t, void __user *);
11976 +extern int vc_fset_iattr(uint32_t, void __user *);
11977 +
11978 +#ifdef CONFIG_COMPAT
11979 +
11980 +extern int vc_get_iattr_x32(void __user *);
11981 +extern int vc_set_iattr_x32(void __user *);
11982 +
11983 +#endif /* CONFIG_COMPAT */
11984 +
11985 +#endif /* __KERNEL__ */
11986 +#endif /* _VX_INODE_CMD_H */
11987 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/inode.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/inode.h
11988 --- linux-2.6.27.25/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
11989 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/inode.h  2008-10-13 14:54:20.000000000 +0200
11990 @@ -0,0 +1,38 @@
11991 +#ifndef _VX_INODE_H
11992 +#define _VX_INODE_H
11993 +
11994 +
11995 +#define IATTR_TAG      0x01000000
11996 +
11997 +#define IATTR_ADMIN    0x00000001
11998 +#define IATTR_WATCH    0x00000002
11999 +#define IATTR_HIDE     0x00000004
12000 +#define IATTR_FLAGS    0x00000007
12001 +
12002 +#define IATTR_BARRIER  0x00010000
12003 +#define IATTR_IXUNLINK 0x00020000
12004 +#define IATTR_IMMUTABLE 0x00040000
12005 +
12006 +#ifdef __KERNEL__
12007 +
12008 +
12009 +#ifdef CONFIG_VSERVER_PROC_SECURE
12010 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12011 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12012 +#else
12013 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12014 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12015 +#endif
12016 +
12017 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12018 +
12019 +#endif /* __KERNEL__ */
12020 +
12021 +/* inode ioctls */
12022 +
12023 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12024 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12025 +
12026 +#else  /* _VX_INODE_H */
12027 +#warning duplicate inclusion
12028 +#endif /* _VX_INODE_H */
12029 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/Kbuild linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/Kbuild
12030 --- linux-2.6.27.25/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
12031 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/Kbuild   2008-10-13 14:54:20.000000000 +0200
12032 @@ -0,0 +1,8 @@
12033 +
12034 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
12035 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12036 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12037 +       debug_cmd.h device_cmd.h
12038 +
12039 +unifdef-y += switch.h network.h monitor.h inode.h device.h
12040 +
12041 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/limit_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit_cmd.h
12042 --- linux-2.6.27.25/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
12043 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit_cmd.h      2009-01-04 02:28:31.000000000 +0100
12044 @@ -0,0 +1,69 @@
12045 +#ifndef _VX_LIMIT_CMD_H
12046 +#define _VX_LIMIT_CMD_H
12047 +
12048 +
12049 +/*  rlimit vserver commands */
12050 +
12051 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12052 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12053 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12054 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12055 +
12056 +struct vcmd_ctx_rlimit_v0 {
12057 +       uint32_t id;
12058 +       uint64_t minimum;
12059 +       uint64_t softlimit;
12060 +       uint64_t maximum;
12061 +};
12062 +
12063 +struct vcmd_ctx_rlimit_mask_v0 {
12064 +       uint32_t minimum;
12065 +       uint32_t softlimit;
12066 +       uint32_t maximum;
12067 +};
12068 +
12069 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12070 +
12071 +struct vcmd_rlimit_stat_v0 {
12072 +       uint32_t id;
12073 +       uint32_t hits;
12074 +       uint64_t value;
12075 +       uint64_t minimum;
12076 +       uint64_t maximum;
12077 +};
12078 +
12079 +#define CRLIM_UNSET            (0ULL)
12080 +#define CRLIM_INFINITY         (~0ULL)
12081 +#define CRLIM_KEEP             (~1ULL)
12082 +
12083 +#ifdef __KERNEL__
12084 +
12085 +#ifdef CONFIG_IA32_EMULATION
12086 +
12087 +struct vcmd_ctx_rlimit_v0_x32 {
12088 +       uint32_t id;
12089 +       uint64_t minimum;
12090 +       uint64_t softlimit;
12091 +       uint64_t maximum;
12092 +} __attribute__ ((packed));
12093 +
12094 +#endif /* CONFIG_IA32_EMULATION */
12095 +
12096 +#include <linux/compiler.h>
12097 +
12098 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12099 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12100 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12101 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12102 +
12103 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12104 +
12105 +#ifdef CONFIG_IA32_EMULATION
12106 +
12107 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12108 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12109 +
12110 +#endif /* CONFIG_IA32_EMULATION */
12111 +
12112 +#endif /* __KERNEL__ */
12113 +#endif /* _VX_LIMIT_CMD_H */
12114 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/limit_def.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit_def.h
12115 --- linux-2.6.27.25/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
12116 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit_def.h      2008-10-13 14:54:20.000000000 +0200
12117 @@ -0,0 +1,47 @@
12118 +#ifndef _VX_LIMIT_DEF_H
12119 +#define _VX_LIMIT_DEF_H
12120 +
12121 +#include <asm/atomic.h>
12122 +#include <asm/resource.h>
12123 +
12124 +#include "limit.h"
12125 +
12126 +
12127 +struct _vx_res_limit {
12128 +       rlim_t soft;            /* Context soft limit */
12129 +       rlim_t hard;            /* Context hard limit */
12130 +
12131 +       rlim_atomic_t rcur;     /* Current value */
12132 +       rlim_t rmin;            /* Context minimum */
12133 +       rlim_t rmax;            /* Context maximum */
12134 +
12135 +       atomic_t lhit;          /* Limit hits */
12136 +};
12137 +
12138 +/* context sub struct */
12139 +
12140 +struct _vx_limit {
12141 +       struct _vx_res_limit res[NUM_LIMITS];
12142 +};
12143 +
12144 +#ifdef CONFIG_VSERVER_DEBUG
12145 +
12146 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12147 +{
12148 +       int i;
12149 +
12150 +       printk("\t_vx_limit:");
12151 +       for (i = 0; i < NUM_LIMITS; i++) {
12152 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12153 +                       i, (unsigned long)__rlim_get(limit, i),
12154 +                       (unsigned long)__rlim_rmin(limit, i),
12155 +                       (unsigned long)__rlim_rmax(limit, i),
12156 +                       (long)__rlim_soft(limit, i),
12157 +                       (long)__rlim_hard(limit, i),
12158 +                       atomic_read(&__rlim_lhit(limit, i)));
12159 +       }
12160 +}
12161 +
12162 +#endif
12163 +
12164 +#endif /* _VX_LIMIT_DEF_H */
12165 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/limit.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit.h
12166 --- linux-2.6.27.25/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
12167 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit.h  2008-10-13 14:54:20.000000000 +0200
12168 @@ -0,0 +1,70 @@
12169 +#ifndef _VX_LIMIT_H
12170 +#define _VX_LIMIT_H
12171 +
12172 +#define VLIMIT_NSOCK   16
12173 +#define VLIMIT_OPENFD  17
12174 +#define VLIMIT_ANON    18
12175 +#define VLIMIT_SHMEM   19
12176 +#define VLIMIT_SEMARY  20
12177 +#define VLIMIT_NSEMS   21
12178 +#define VLIMIT_DENTRY  22
12179 +#define VLIMIT_MAPPED  23
12180 +
12181 +
12182 +#ifdef __KERNEL__
12183 +
12184 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12185 +
12186 +/*     keep in sync with CRLIM_INFINITY */
12187 +
12188 +#define        VLIM_INFINITY   (~0ULL)
12189 +
12190 +#include <asm/atomic.h>
12191 +#include <asm/resource.h>
12192 +
12193 +#ifndef RLIM_INFINITY
12194 +#warning RLIM_INFINITY is undefined
12195 +#endif
12196 +
12197 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12198 +
12199 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12200 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12201 +
12202 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12203 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12204 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12205 +
12206 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12207 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12208 +
12209 +typedef atomic_long_t rlim_atomic_t;
12210 +typedef unsigned long rlim_t;
12211 +
12212 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12213 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12214 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12215 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12216 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12217 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12218 +
12219 +
12220 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12221 +#define        VX_VLIM(r) ((long long)(long)(r))
12222 +#define        VX_RLIM(v) ((rlim_t)(v))
12223 +#else
12224 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12225 +               ? VLIM_INFINITY : (long long)(r))
12226 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12227 +               ? RLIM_INFINITY : (rlim_t)(v))
12228 +#endif
12229 +
12230 +struct sysinfo;
12231 +
12232 +void vx_vsi_meminfo(struct sysinfo *);
12233 +void vx_vsi_swapinfo(struct sysinfo *);
12234 +
12235 +#define NUM_LIMITS     24
12236 +
12237 +#endif /* __KERNEL__ */
12238 +#endif /* _VX_LIMIT_H */
12239 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/limit_int.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit_int.h
12240 --- linux-2.6.27.25/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
12241 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/limit_int.h      2008-10-13 14:54:20.000000000 +0200
12242 @@ -0,0 +1,198 @@
12243 +#ifndef _VX_LIMIT_INT_H
12244 +#define _VX_LIMIT_INT_H
12245 +
12246 +#include "context.h"
12247 +
12248 +#ifdef __KERNEL__
12249 +
12250 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12251 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12252 +
12253 +extern const char *vlimit_name[NUM_LIMITS];
12254 +
12255 +static inline void __vx_acc_cres(struct vx_info *vxi,
12256 +       int res, int dir, void *_data, char *_file, int _line)
12257 +{
12258 +       if (VXD_RCRES_COND(res))
12259 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12260 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12261 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12262 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12263 +       if (!vxi)
12264 +               return;
12265 +
12266 +       if (dir > 0)
12267 +               __rlim_inc(&vxi->limit, res);
12268 +       else
12269 +               __rlim_dec(&vxi->limit, res);
12270 +}
12271 +
12272 +static inline void __vx_add_cres(struct vx_info *vxi,
12273 +       int res, int amount, void *_data, char *_file, int _line)
12274 +{
12275 +       if (VXD_RCRES_COND(res))
12276 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12277 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12278 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12279 +                       amount, _data, _file, _line);
12280 +       if (amount == 0)
12281 +               return;
12282 +       if (!vxi)
12283 +               return;
12284 +       __rlim_add(&vxi->limit, res, amount);
12285 +}
12286 +
12287 +static inline
12288 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12289 +{
12290 +       int cond = (value > __rlim_rmax(limit, res));
12291 +
12292 +       if (cond)
12293 +               __rlim_rmax(limit, res) = value;
12294 +       return cond;
12295 +}
12296 +
12297 +static inline
12298 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12299 +{
12300 +       int cond = (value < __rlim_rmin(limit, res));
12301 +
12302 +       if (cond)
12303 +               __rlim_rmin(limit, res) = value;
12304 +       return cond;
12305 +}
12306 +
12307 +static inline
12308 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12309 +{
12310 +       if (!__vx_cres_adjust_max(limit, res, value))
12311 +               __vx_cres_adjust_min(limit, res, value);
12312 +}
12313 +
12314 +
12315 +/*     return values:
12316 +        +1 ... no limit hit
12317 +        -1 ... over soft limit
12318 +         0 ... over hard limit         */
12319 +
12320 +static inline int __vx_cres_avail(struct vx_info *vxi,
12321 +       int res, int num, char *_file, int _line)
12322 +{
12323 +       struct _vx_limit *limit;
12324 +       rlim_t value;
12325 +
12326 +       if (VXD_RLIMIT_COND(res))
12327 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12328 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12329 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12330 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12331 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12332 +                       num, _file, _line);
12333 +       if (!vxi)
12334 +               return 1;
12335 +
12336 +       limit = &vxi->limit;
12337 +       value = __rlim_get(limit, res);
12338 +
12339 +       if (!__vx_cres_adjust_max(limit, res, value))
12340 +               __vx_cres_adjust_min(limit, res, value);
12341 +
12342 +       if (num == 0)
12343 +               return 1;
12344 +
12345 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12346 +               return -1;
12347 +       if (value + num <= __rlim_soft(limit, res))
12348 +               return -1;
12349 +
12350 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12351 +               return 1;
12352 +       if (value + num <= __rlim_hard(limit, res))
12353 +               return 1;
12354 +
12355 +       __rlim_hit(limit, res);
12356 +       return 0;
12357 +}
12358 +
12359 +
12360 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12361 +
12362 +static inline
12363 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12364 +{
12365 +       rlim_t value, sum = 0;
12366 +       int res;
12367 +
12368 +       while ((res = *array++)) {
12369 +               value = __rlim_get(limit, res);
12370 +               __vx_cres_fixup(limit, res, value);
12371 +               sum += value;
12372 +       }
12373 +       return sum;
12374 +}
12375 +
12376 +static inline
12377 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12378 +{
12379 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12380 +       int res = *array;
12381 +
12382 +       if (value == __rlim_get(limit, res))
12383 +               return value;
12384 +
12385 +       __rlim_set(limit, res, value);
12386 +       /* now adjust min/max */
12387 +       if (!__vx_cres_adjust_max(limit, res, value))
12388 +               __vx_cres_adjust_min(limit, res, value);
12389 +
12390 +       return value;
12391 +}
12392 +
12393 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12394 +       const int *array, int num, char *_file, int _line)
12395 +{
12396 +       struct _vx_limit *limit;
12397 +       rlim_t value = 0;
12398 +       int res;
12399 +
12400 +       if (num == 0)
12401 +               return 1;
12402 +       if (!vxi)
12403 +               return 1;
12404 +
12405 +       limit = &vxi->limit;
12406 +       res = *array;
12407 +       value = __vx_cres_array_sum(limit, array + 1);
12408 +
12409 +       __rlim_set(limit, res, value);
12410 +       __vx_cres_fixup(limit, res, value);
12411 +
12412 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12413 +}
12414 +
12415 +
12416 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12417 +{
12418 +       rlim_t value;
12419 +       int res;
12420 +
12421 +       /* complex resources first */
12422 +       if ((id < 0) || (id == RLIMIT_RSS))
12423 +               __vx_cres_array_fixup(limit, VLA_RSS);
12424 +
12425 +       for (res = 0; res < NUM_LIMITS; res++) {
12426 +               if ((id > 0) && (res != id))
12427 +                       continue;
12428 +
12429 +               value = __rlim_get(limit, res);
12430 +               __vx_cres_fixup(limit, res, value);
12431 +
12432 +               /* not supposed to happen, maybe warn? */
12433 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12434 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12435 +       }
12436 +}
12437 +
12438 +
12439 +#endif /* __KERNEL__ */
12440 +#endif /* _VX_LIMIT_INT_H */
12441 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/monitor.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/monitor.h
12442 --- linux-2.6.27.25/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
12443 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/monitor.h        2008-10-13 14:54:20.000000000 +0200
12444 @@ -0,0 +1,96 @@
12445 +#ifndef _VX_MONITOR_H
12446 +#define _VX_MONITOR_H
12447 +
12448 +#include <linux/types.h>
12449 +
12450 +enum {
12451 +       VXM_UNUSED = 0,
12452 +
12453 +       VXM_SYNC = 0x10,
12454 +
12455 +       VXM_UPDATE = 0x20,
12456 +       VXM_UPDATE_1,
12457 +       VXM_UPDATE_2,
12458 +
12459 +       VXM_RQINFO_1 = 0x24,
12460 +       VXM_RQINFO_2,
12461 +
12462 +       VXM_ACTIVATE = 0x40,
12463 +       VXM_DEACTIVATE,
12464 +       VXM_IDLE,
12465 +
12466 +       VXM_HOLD = 0x44,
12467 +       VXM_UNHOLD,
12468 +
12469 +       VXM_MIGRATE = 0x48,
12470 +       VXM_RESCHED,
12471 +
12472 +       /* all other bits are flags */
12473 +       VXM_SCHED = 0x80,
12474 +};
12475 +
12476 +struct _vxm_update_1 {
12477 +       uint32_t tokens_max;
12478 +       uint32_t fill_rate;
12479 +       uint32_t interval;
12480 +};
12481 +
12482 +struct _vxm_update_2 {
12483 +       uint32_t tokens_min;
12484 +       uint32_t fill_rate;
12485 +       uint32_t interval;
12486 +};
12487 +
12488 +struct _vxm_rqinfo_1 {
12489 +       uint16_t running;
12490 +       uint16_t onhold;
12491 +       uint16_t iowait;
12492 +       uint16_t uintr;
12493 +       uint32_t idle_tokens;
12494 +};
12495 +
12496 +struct _vxm_rqinfo_2 {
12497 +       uint32_t norm_time;
12498 +       uint32_t idle_time;
12499 +       uint32_t idle_skip;
12500 +};
12501 +
12502 +struct _vxm_sched {
12503 +       uint32_t tokens;
12504 +       uint32_t norm_time;
12505 +       uint32_t idle_time;
12506 +};
12507 +
12508 +struct _vxm_task {
12509 +       uint16_t pid;
12510 +       uint16_t state;
12511 +};
12512 +
12513 +struct _vxm_event {
12514 +       uint32_t jif;
12515 +       union {
12516 +               uint32_t seq;
12517 +               uint32_t sec;
12518 +       };
12519 +       union {
12520 +               uint32_t tokens;
12521 +               uint32_t nsec;
12522 +               struct _vxm_task tsk;
12523 +       };
12524 +};
12525 +
12526 +struct _vx_mon_entry {
12527 +       uint16_t type;
12528 +       uint16_t xid;
12529 +       union {
12530 +               struct _vxm_event ev;
12531 +               struct _vxm_sched sd;
12532 +               struct _vxm_update_1 u1;
12533 +               struct _vxm_update_2 u2;
12534 +               struct _vxm_rqinfo_1 q1;
12535 +               struct _vxm_rqinfo_2 q2;
12536 +       };
12537 +};
12538 +
12539 +
12540 +#endif /* _VX_MONITOR_H */
12541 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/network_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/network_cmd.h
12542 --- linux-2.6.27.25/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
12543 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/network_cmd.h    2008-10-13 14:54:20.000000000 +0200
12544 @@ -0,0 +1,150 @@
12545 +#ifndef _VX_NETWORK_CMD_H
12546 +#define _VX_NETWORK_CMD_H
12547 +
12548 +
12549 +/* vinfo commands */
12550 +
12551 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12552 +
12553 +#ifdef __KERNEL__
12554 +extern int vc_task_nid(uint32_t);
12555 +
12556 +#endif /* __KERNEL__ */
12557 +
12558 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12559 +
12560 +struct vcmd_nx_info_v0 {
12561 +       uint32_t nid;
12562 +       /* more to come */
12563 +};
12564 +
12565 +#ifdef __KERNEL__
12566 +extern int vc_nx_info(struct nx_info *, void __user *);
12567 +
12568 +#endif /* __KERNEL__ */
12569 +
12570 +#include <linux/in.h>
12571 +#include <linux/in6.h>
12572 +
12573 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12574 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12575 +
12576 +struct  vcmd_net_create {
12577 +       uint64_t flagword;
12578 +};
12579 +
12580 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12581 +
12582 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12583 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12584 +
12585 +struct vcmd_net_addr_v0 {
12586 +       uint16_t type;
12587 +       uint16_t count;
12588 +       struct in_addr ip[4];
12589 +       struct in_addr mask[4];
12590 +};
12591 +
12592 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12593 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12594 +
12595 +struct vcmd_net_addr_ipv4_v1 {
12596 +       uint16_t type;
12597 +       uint16_t flags;
12598 +       struct in_addr ip;
12599 +       struct in_addr mask;
12600 +};
12601 +
12602 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12603 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12604 +
12605 +struct vcmd_net_addr_ipv6_v1 {
12606 +       uint16_t type;
12607 +       uint16_t flags;
12608 +       uint32_t prefix;
12609 +       struct in6_addr ip;
12610 +       struct in6_addr mask;
12611 +};
12612 +
12613 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12614 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12615 +
12616 +struct vcmd_match_ipv4_v0 {
12617 +       uint16_t type;
12618 +       uint16_t flags;
12619 +       uint16_t parent;
12620 +       uint16_t prefix;
12621 +       struct in_addr ip;
12622 +       struct in_addr ip2;
12623 +       struct in_addr mask;
12624 +};
12625 +
12626 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12627 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12628 +
12629 +struct vcmd_match_ipv6_v0 {
12630 +       uint16_t type;
12631 +       uint16_t flags;
12632 +       uint16_t parent;
12633 +       uint16_t prefix;
12634 +       struct in6_addr ip;
12635 +       struct in6_addr ip2;
12636 +       struct in6_addr mask;
12637 +};
12638 +
12639 +
12640 +#ifdef __KERNEL__
12641 +extern int vc_net_create(uint32_t, void __user *);
12642 +extern int vc_net_migrate(struct nx_info *, void __user *);
12643 +
12644 +extern int vc_net_add(struct nx_info *, void __user *);
12645 +extern int vc_net_remove(struct nx_info *, void __user *);
12646 +
12647 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12648 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12649 +
12650 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12651 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12652 +
12653 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12654 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12655 +
12656 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12657 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12658 +
12659 +#endif /* __KERNEL__ */
12660 +
12661 +
12662 +/* flag commands */
12663 +
12664 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12665 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12666 +
12667 +struct vcmd_net_flags_v0 {
12668 +       uint64_t flagword;
12669 +       uint64_t mask;
12670 +};
12671 +
12672 +#ifdef __KERNEL__
12673 +extern int vc_get_nflags(struct nx_info *, void __user *);
12674 +extern int vc_set_nflags(struct nx_info *, void __user *);
12675 +
12676 +#endif /* __KERNEL__ */
12677 +
12678 +
12679 +/* network caps commands */
12680 +
12681 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12682 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12683 +
12684 +struct vcmd_net_caps_v0 {
12685 +       uint64_t ncaps;
12686 +       uint64_t cmask;
12687 +};
12688 +
12689 +#ifdef __KERNEL__
12690 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12691 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12692 +
12693 +#endif /* __KERNEL__ */
12694 +#endif /* _VX_CONTEXT_CMD_H */
12695 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/network.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/network.h
12696 --- linux-2.6.27.25/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
12697 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/network.h        2008-10-13 14:54:20.000000000 +0200
12698 @@ -0,0 +1,146 @@
12699 +#ifndef _VX_NETWORK_H
12700 +#define _VX_NETWORK_H
12701 +
12702 +#include <linux/types.h>
12703 +
12704 +
12705 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12706 +
12707 +
12708 +/* network flags */
12709 +
12710 +#define NXF_INFO_PRIVATE       0x00000008
12711 +
12712 +#define NXF_SINGLE_IP          0x00000100
12713 +#define NXF_LBACK_REMAP                0x00000200
12714 +#define NXF_LBACK_ALLOW                0x00000400
12715 +
12716 +#define NXF_HIDE_NETIF         0x02000000
12717 +#define NXF_HIDE_LBACK         0x04000000
12718 +
12719 +#define NXF_STATE_SETUP                (1ULL << 32)
12720 +#define NXF_STATE_ADMIN                (1ULL << 34)
12721 +
12722 +#define NXF_SC_HELPER          (1ULL << 36)
12723 +#define NXF_PERSISTENT         (1ULL << 38)
12724 +
12725 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12726 +
12727 +
12728 +#define        NXF_INIT_SET            (__nxf_init_set())
12729 +
12730 +static inline uint64_t __nxf_init_set(void) {
12731 +       return    NXF_STATE_ADMIN
12732 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12733 +               | NXF_LBACK_REMAP
12734 +               | NXF_HIDE_LBACK
12735 +#endif
12736 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12737 +               | NXF_SINGLE_IP
12738 +#endif
12739 +               | NXF_HIDE_NETIF;
12740 +}
12741 +
12742 +
12743 +/* network caps */
12744 +
12745 +#define NXC_TUN_CREATE         0x00000001
12746 +
12747 +#define NXC_RAW_ICMP           0x00000100
12748 +
12749 +
12750 +/* address types */
12751 +
12752 +#define NXA_TYPE_IPV4          0x0001
12753 +#define NXA_TYPE_IPV6          0x0002
12754 +
12755 +#define NXA_TYPE_NONE          0x0000
12756 +#define NXA_TYPE_ANY           0x00FF
12757 +
12758 +#define NXA_TYPE_ADDR          0x0010
12759 +#define NXA_TYPE_MASK          0x0020
12760 +#define NXA_TYPE_RANGE         0x0040
12761 +
12762 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12763 +
12764 +#define NXA_MOD_BCAST          0x0100
12765 +#define NXA_MOD_LBACK          0x0200
12766 +
12767 +#define NXA_LOOPBACK           0x1000
12768 +
12769 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12770 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12771 +
12772 +#ifdef __KERNEL__
12773 +
12774 +#include <linux/list.h>
12775 +#include <linux/spinlock.h>
12776 +#include <linux/rcupdate.h>
12777 +#include <linux/in.h>
12778 +#include <linux/in6.h>
12779 +#include <asm/atomic.h>
12780 +
12781 +struct nx_addr_v4 {
12782 +       struct nx_addr_v4 *next;
12783 +       struct in_addr ip[2];
12784 +       struct in_addr mask;
12785 +       uint16_t type;
12786 +       uint16_t flags;
12787 +};
12788 +
12789 +struct nx_addr_v6 {
12790 +       struct nx_addr_v6 *next;
12791 +       struct in6_addr ip;
12792 +       struct in6_addr mask;
12793 +       uint32_t prefix;
12794 +       uint16_t type;
12795 +       uint16_t flags;
12796 +};
12797 +
12798 +struct nx_info {
12799 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12800 +       nid_t nx_id;                    /* vnet id */
12801 +       atomic_t nx_usecnt;             /* usage count */
12802 +       atomic_t nx_tasks;              /* tasks count */
12803 +       int nx_state;                   /* context state */
12804 +
12805 +       uint64_t nx_flags;              /* network flag word */
12806 +       uint64_t nx_ncaps;              /* network capabilities */
12807 +
12808 +       struct in_addr v4_lback;        /* Loopback address */
12809 +       struct in_addr v4_bcast;        /* Broadcast address */
12810 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12811 +#ifdef CONFIG_IPV6
12812 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12813 +#endif
12814 +       char nx_name[65];               /* network context name */
12815 +};
12816 +
12817 +
12818 +/* status flags */
12819 +
12820 +#define NXS_HASHED      0x0001
12821 +#define NXS_SHUTDOWN    0x0100
12822 +#define NXS_RELEASED    0x8000
12823 +
12824 +extern struct nx_info *lookup_nx_info(int);
12825 +
12826 +extern int get_nid_list(int, unsigned int *, int);
12827 +extern int nid_is_hashed(nid_t);
12828 +
12829 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12830 +
12831 +extern long vs_net_change(struct nx_info *, unsigned int);
12832 +
12833 +struct sock;
12834 +
12835 +
12836 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12837 +#ifdef  CONFIG_IPV6
12838 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12839 +#else
12840 +#define NX_IPV6(n)     (0)
12841 +#endif
12842 +
12843 +#endif /* __KERNEL__ */
12844 +#endif /* _VX_NETWORK_H */
12845 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/percpu.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/percpu.h
12846 --- linux-2.6.27.25/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
12847 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/percpu.h 2008-10-13 14:54:20.000000000 +0200
12848 @@ -0,0 +1,14 @@
12849 +#ifndef _VX_PERCPU_H
12850 +#define _VX_PERCPU_H
12851 +
12852 +#include "cvirt_def.h"
12853 +#include "sched_def.h"
12854 +
12855 +struct _vx_percpu {
12856 +       struct _vx_cvirt_pc cvirt;
12857 +       struct _vx_sched_pc sched;
12858 +};
12859 +
12860 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12861 +
12862 +#endif /* _VX_PERCPU_H */
12863 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/pid.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/pid.h
12864 --- linux-2.6.27.25/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
12865 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/pid.h    2008-10-13 14:54:20.000000000 +0200
12866 @@ -0,0 +1,51 @@
12867 +#ifndef _VSERVER_PID_H
12868 +#define _VSERVER_PID_H
12869 +
12870 +/* pid faking stuff */
12871 +
12872 +#define vx_info_map_pid(v, p) \
12873 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12874 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12875 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12876 +#define vx_map_tgid(p) vx_map_pid(p)
12877 +
12878 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12879 +       const char *func, const char *file, int line)
12880 +{
12881 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12882 +               vxfprintk(VXD_CBIT(cvirt, 2),
12883 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12884 +                       vxi, (long long)vxi->vx_flags, pid,
12885 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12886 +                       func, file, line);
12887 +               if (pid == 0)
12888 +                       return 0;
12889 +               if (pid == vxi->vx_initpid)
12890 +                       return 1;
12891 +       }
12892 +       return pid;
12893 +}
12894 +
12895 +#define vx_info_rmap_pid(v, p) \
12896 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12897 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12898 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12899 +
12900 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12901 +       const char *func, const char *file, int line)
12902 +{
12903 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12904 +               vxfprintk(VXD_CBIT(cvirt, 2),
12905 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12906 +                       vxi, (long long)vxi->vx_flags, pid,
12907 +                       (pid == 1) ? vxi->vx_initpid : pid,
12908 +                       func, file, line);
12909 +               if ((pid == 1) && vxi->vx_initpid)
12910 +                       return vxi->vx_initpid;
12911 +               if (pid == vxi->vx_initpid)
12912 +                       return ~0U;
12913 +       }
12914 +       return pid;
12915 +}
12916 +
12917 +#endif
12918 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/sched_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/sched_cmd.h
12919 --- linux-2.6.27.25/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
12920 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/sched_cmd.h      2008-10-13 14:54:20.000000000 +0200
12921 @@ -0,0 +1,108 @@
12922 +#ifndef _VX_SCHED_CMD_H
12923 +#define _VX_SCHED_CMD_H
12924 +
12925 +
12926 +/*  sched vserver commands */
12927 +
12928 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12929 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12930 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12931 +
12932 +struct vcmd_set_sched_v2 {
12933 +       int32_t fill_rate;
12934 +       int32_t interval;
12935 +       int32_t tokens;
12936 +       int32_t tokens_min;
12937 +       int32_t tokens_max;
12938 +       uint64_t cpu_mask;
12939 +};
12940 +
12941 +struct vcmd_set_sched_v3 {
12942 +       uint32_t set_mask;
12943 +       int32_t fill_rate;
12944 +       int32_t interval;
12945 +       int32_t tokens;
12946 +       int32_t tokens_min;
12947 +       int32_t tokens_max;
12948 +       int32_t priority_bias;
12949 +};
12950 +
12951 +struct vcmd_set_sched_v4 {
12952 +       uint32_t set_mask;
12953 +       int32_t fill_rate;
12954 +       int32_t interval;
12955 +       int32_t tokens;
12956 +       int32_t tokens_min;
12957 +       int32_t tokens_max;
12958 +       int32_t prio_bias;
12959 +       int32_t cpu_id;
12960 +       int32_t bucket_id;
12961 +};
12962 +
12963 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12964 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12965 +
12966 +struct vcmd_sched_v5 {
12967 +       uint32_t mask;
12968 +       int32_t cpu_id;
12969 +       int32_t bucket_id;
12970 +       int32_t fill_rate[2];
12971 +       int32_t interval[2];
12972 +       int32_t tokens;
12973 +       int32_t tokens_min;
12974 +       int32_t tokens_max;
12975 +       int32_t prio_bias;
12976 +};
12977 +
12978 +#define VXSM_FILL_RATE         0x0001
12979 +#define VXSM_INTERVAL          0x0002
12980 +#define VXSM_FILL_RATE2                0x0004
12981 +#define VXSM_INTERVAL2         0x0008
12982 +#define VXSM_TOKENS            0x0010
12983 +#define VXSM_TOKENS_MIN                0x0020
12984 +#define VXSM_TOKENS_MAX                0x0040
12985 +#define VXSM_PRIO_BIAS         0x0100
12986 +
12987 +#define VXSM_IDLE_TIME         0x0200
12988 +#define VXSM_FORCE             0x0400
12989 +
12990 +#define        VXSM_V3_MASK            0x0173
12991 +#define        VXSM_SET_MASK           0x01FF
12992 +
12993 +#define VXSM_CPU_ID            0x1000
12994 +#define VXSM_BUCKET_ID         0x2000
12995 +
12996 +#define VXSM_MSEC              0x4000
12997 +
12998 +#define SCHED_KEEP             (-2)    /* only for v2 */
12999 +
13000 +#ifdef __KERNEL__
13001 +
13002 +#include <linux/compiler.h>
13003 +
13004 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
13005 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
13006 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
13007 +extern int vc_set_sched(struct vx_info *, void __user *);
13008 +extern int vc_get_sched(struct vx_info *, void __user *);
13009 +
13010 +#endif /* __KERNEL__ */
13011 +
13012 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
13013 +
13014 +struct vcmd_sched_info {
13015 +       int32_t cpu_id;
13016 +       int32_t bucket_id;
13017 +       uint64_t user_msec;
13018 +       uint64_t sys_msec;
13019 +       uint64_t hold_msec;
13020 +       uint32_t token_usec;
13021 +       int32_t vavavoom;
13022 +};
13023 +
13024 +#ifdef __KERNEL__
13025 +
13026 +extern int vc_sched_info(struct vx_info *, void __user *);
13027 +
13028 +#endif /* __KERNEL__ */
13029 +#endif /* _VX_SCHED_CMD_H */
13030 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/sched_def.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/sched_def.h
13031 --- linux-2.6.27.25/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
13032 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/sched_def.h      2008-10-13 14:54:20.000000000 +0200
13033 @@ -0,0 +1,68 @@
13034 +#ifndef _VX_SCHED_DEF_H
13035 +#define _VX_SCHED_DEF_H
13036 +
13037 +#include <linux/spinlock.h>
13038 +#include <linux/jiffies.h>
13039 +#include <linux/cpumask.h>
13040 +#include <asm/atomic.h>
13041 +#include <asm/param.h>
13042 +
13043 +
13044 +/* context sub struct */
13045 +
13046 +struct _vx_sched {
13047 +       spinlock_t tokens_lock;         /* lock for token bucket */
13048 +
13049 +       int tokens;                     /* number of CPU tokens */
13050 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13051 +       int interval[2];                /* Divisor:   per Y jiffies   */
13052 +       int tokens_min;                 /* Limit:     minimum for unhold */
13053 +       int tokens_max;                 /* Limit:     no more than N tokens */
13054 +
13055 +       int prio_bias;                  /* bias offset for priority */
13056 +
13057 +       unsigned update_mask;           /* which features should be updated */
13058 +       cpumask_t update;               /* CPUs which should update */
13059 +};
13060 +
13061 +struct _vx_sched_pc {
13062 +       int tokens;                     /* number of CPU tokens */
13063 +       int flags;                      /* bucket flags */
13064 +
13065 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13066 +       int interval[2];                /* Divisor:   per Y jiffies   */
13067 +       int tokens_min;                 /* Limit:     minimum for unhold */
13068 +       int tokens_max;                 /* Limit:     no more than N tokens */
13069 +
13070 +       int prio_bias;                  /* bias offset for priority */
13071 +       int vavavoom;                   /* last calculated vavavoom */
13072 +
13073 +       unsigned long norm_time;        /* last time accounted */
13074 +       unsigned long idle_time;        /* non linear time for fair sched */
13075 +       unsigned long token_time;       /* token time for accounting */
13076 +       unsigned long onhold;           /* jiffies when put on hold */
13077 +
13078 +       uint64_t user_ticks;            /* token tick events */
13079 +       uint64_t sys_ticks;             /* token tick events */
13080 +       uint64_t hold_ticks;            /* token ticks paused */
13081 +};
13082 +
13083 +
13084 +#define VXSF_ONHOLD    0x0001
13085 +#define VXSF_IDLE_TIME 0x0100
13086 +
13087 +#ifdef CONFIG_VSERVER_DEBUG
13088 +
13089 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13090 +{
13091 +       printk("\t_vx_sched:\n");
13092 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
13093 +               sched->fill_rate[0], sched->interval[0],
13094 +               sched->fill_rate[1], sched->interval[1],
13095 +               sched->tokens_min, sched->tokens_max);
13096 +       printk("\t priority = %4d\n", sched->prio_bias);
13097 +}
13098 +
13099 +#endif
13100 +
13101 +#endif /* _VX_SCHED_DEF_H */
13102 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/sched.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/sched.h
13103 --- linux-2.6.27.25/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
13104 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/sched.h  2008-10-13 14:54:20.000000000 +0200
13105 @@ -0,0 +1,26 @@
13106 +#ifndef _VX_SCHED_H
13107 +#define _VX_SCHED_H
13108 +
13109 +
13110 +#ifdef __KERNEL__
13111 +
13112 +struct timespec;
13113 +
13114 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13115 +
13116 +
13117 +struct vx_info;
13118 +
13119 +void vx_update_load(struct vx_info *);
13120 +
13121 +
13122 +int vx_tokens_recalc(struct _vx_sched_pc *,
13123 +       unsigned long *, unsigned long *, int [2]);
13124 +
13125 +void vx_update_sched_param(struct _vx_sched *sched,
13126 +       struct _vx_sched_pc *sched_pc);
13127 +
13128 +#endif /* __KERNEL__ */
13129 +#else  /* _VX_SCHED_H */
13130 +#warning duplicate inclusion
13131 +#endif /* _VX_SCHED_H */
13132 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/signal_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/signal_cmd.h
13133 --- linux-2.6.27.25/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
13134 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/signal_cmd.h     2008-10-13 14:54:20.000000000 +0200
13135 @@ -0,0 +1,43 @@
13136 +#ifndef _VX_SIGNAL_CMD_H
13137 +#define _VX_SIGNAL_CMD_H
13138 +
13139 +
13140 +/*  signalling vserver commands */
13141 +
13142 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13143 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13144 +
13145 +struct vcmd_ctx_kill_v0 {
13146 +       int32_t pid;
13147 +       int32_t sig;
13148 +};
13149 +
13150 +struct vcmd_wait_exit_v0 {
13151 +       int32_t reboot_cmd;
13152 +       int32_t exit_code;
13153 +};
13154 +
13155 +#ifdef __KERNEL__
13156 +
13157 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13158 +extern int vc_wait_exit(struct vx_info *, void __user *);
13159 +
13160 +#endif /* __KERNEL__ */
13161 +
13162 +/*  process alteration commands */
13163 +
13164 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13165 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13166 +
13167 +struct vcmd_pflags_v0 {
13168 +       uint32_t flagword;
13169 +       uint32_t mask;
13170 +};
13171 +
13172 +#ifdef __KERNEL__
13173 +
13174 +extern int vc_get_pflags(uint32_t pid, void __user *);
13175 +extern int vc_set_pflags(uint32_t pid, void __user *);
13176 +
13177 +#endif /* __KERNEL__ */
13178 +#endif /* _VX_SIGNAL_CMD_H */
13179 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/signal.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/signal.h
13180 --- linux-2.6.27.25/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
13181 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/signal.h 2008-10-13 14:54:20.000000000 +0200
13182 @@ -0,0 +1,14 @@
13183 +#ifndef _VX_SIGNAL_H
13184 +#define _VX_SIGNAL_H
13185 +
13186 +
13187 +#ifdef __KERNEL__
13188 +
13189 +struct vx_info;
13190 +
13191 +int vx_info_kill(struct vx_info *, int, int);
13192 +
13193 +#endif /* __KERNEL__ */
13194 +#else  /* _VX_SIGNAL_H */
13195 +#warning duplicate inclusion
13196 +#endif /* _VX_SIGNAL_H */
13197 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/space_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/space_cmd.h
13198 --- linux-2.6.27.25/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
13199 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/space_cmd.h      2008-10-31 03:49:36.000000000 +0100
13200 @@ -0,0 +1,38 @@
13201 +#ifndef _VX_SPACE_CMD_H
13202 +#define _VX_SPACE_CMD_H
13203 +
13204 +
13205 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13206 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13207 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13208 +
13209 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13210 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13211 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13212 +
13213 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13214 +
13215 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13216 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13217 +
13218 +
13219 +struct vcmd_space_mask_v1 {
13220 +       uint64_t mask;
13221 +};
13222 +
13223 +struct vcmd_space_mask_v2 {
13224 +       uint64_t mask;
13225 +       uint32_t index;
13226 +};
13227 +
13228 +
13229 +#ifdef __KERNEL__
13230 +
13231 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13232 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13233 +extern int vc_enter_space(struct vx_info *, void __user *);
13234 +extern int vc_set_space(struct vx_info *, void __user *);
13235 +extern int vc_get_space_mask(void __user *, int);
13236 +
13237 +#endif /* __KERNEL__ */
13238 +#endif /* _VX_SPACE_CMD_H */
13239 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/space.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/space.h
13240 --- linux-2.6.27.25/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
13241 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/space.h  2008-10-31 04:02:02.000000000 +0100
13242 @@ -0,0 +1,12 @@
13243 +#ifndef _VX_SPACE_H
13244 +#define _VX_SPACE_H
13245 +
13246 +#include <linux/types.h>
13247 +
13248 +struct vx_info;
13249 +
13250 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13251 +
13252 +#else  /* _VX_SPACE_H */
13253 +#warning duplicate inclusion
13254 +#endif /* _VX_SPACE_H */
13255 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/switch.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/switch.h
13256 --- linux-2.6.27.25/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
13257 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/switch.h 2008-11-22 20:32:00.000000000 +0100
13258 @@ -0,0 +1,98 @@
13259 +#ifndef _VX_SWITCH_H
13260 +#define _VX_SWITCH_H
13261 +
13262 +#include <linux/types.h>
13263 +
13264 +
13265 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13266 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13267 +#define VC_VERSION(c)          ((c) & 0xFFF)
13268 +
13269 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13270 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13271 +
13272 +/*
13273 +
13274 +  Syscall Matrix V2.8
13275 +
13276 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13277 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13278 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13279 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13280 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13281 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13282 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13283 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13284 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13285 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13286 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13287 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13288 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13289 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13290 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13291 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13292 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13293 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13294 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13295 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13296 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13297 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13298 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13299 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13300 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13301 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13302 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13303 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13304 +
13305 +*/
13306 +
13307 +#define VC_CAT_VERSION         0
13308 +
13309 +#define VC_CAT_VSETUP          1
13310 +#define VC_CAT_VHOST           2
13311 +
13312 +#define VC_CAT_DEVICE          6
13313 +
13314 +#define VC_CAT_VPROC           9
13315 +#define VC_CAT_PROCALT         10
13316 +#define VC_CAT_PROCMIG         11
13317 +#define VC_CAT_PROCTRL         12
13318 +
13319 +#define VC_CAT_SCHED           14
13320 +#define VC_CAT_MEMCTRL         20
13321 +
13322 +#define VC_CAT_VNET            25
13323 +#define VC_CAT_NETALT          26
13324 +#define VC_CAT_NETMIG          27
13325 +#define VC_CAT_NETCTRL         28
13326 +
13327 +#define VC_CAT_TAGMIG          35
13328 +#define VC_CAT_DLIMIT          36
13329 +#define VC_CAT_INODE           38
13330 +
13331 +#define VC_CAT_VSTAT           40
13332 +#define VC_CAT_VINFO           46
13333 +#define VC_CAT_EVENT           48
13334 +
13335 +#define VC_CAT_FLAGS           52
13336 +#define VC_CAT_VSPACE          54
13337 +#define VC_CAT_DEBUG           56
13338 +#define VC_CAT_RLIMIT          60
13339 +
13340 +#define VC_CAT_SYSTEST         61
13341 +#define VC_CAT_COMPAT          63
13342 +
13343 +/*  query version */
13344 +
13345 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13346 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13347 +
13348 +
13349 +#ifdef __KERNEL__
13350 +
13351 +#include <linux/errno.h>
13352 +
13353 +#endif /* __KERNEL__ */
13354 +
13355 +#endif /* _VX_SWITCH_H */
13356 +
13357 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/tag_cmd.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/tag_cmd.h
13358 --- linux-2.6.27.25/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
13359 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/tag_cmd.h        2008-10-13 14:54:20.000000000 +0200
13360 @@ -0,0 +1,22 @@
13361 +#ifndef _VX_TAG_CMD_H
13362 +#define _VX_TAG_CMD_H
13363 +
13364 +
13365 +/* vinfo commands */
13366 +
13367 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13368 +
13369 +#ifdef __KERNEL__
13370 +extern int vc_task_tag(uint32_t);
13371 +
13372 +#endif /* __KERNEL__ */
13373 +
13374 +/* context commands */
13375 +
13376 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13377 +
13378 +#ifdef __KERNEL__
13379 +extern int vc_tag_migrate(uint32_t);
13380 +
13381 +#endif /* __KERNEL__ */
13382 +#endif /* _VX_TAG_CMD_H */
13383 diff -NurpP --minimal linux-2.6.27.25/include/linux/vserver/tag.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/tag.h
13384 --- linux-2.6.27.25/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
13385 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vserver/tag.h    2008-10-24 03:34:52.000000000 +0200
13386 @@ -0,0 +1,143 @@
13387 +#ifndef _DX_TAG_H
13388 +#define _DX_TAG_H
13389 +
13390 +#include <linux/types.h>
13391 +
13392 +
13393 +#define DX_TAG(in)     (IS_TAGGED(in))
13394 +
13395 +
13396 +#ifdef CONFIG_TAG_NFSD
13397 +#define DX_TAG_NFSD    1
13398 +#else
13399 +#define DX_TAG_NFSD    0
13400 +#endif
13401 +
13402 +
13403 +#ifdef CONFIG_TAGGING_NONE
13404 +
13405 +#define MAX_UID                0xFFFFFFFF
13406 +#define MAX_GID                0xFFFFFFFF
13407 +
13408 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13409 +
13410 +#define TAGINO_UID(cond, uid, tag)     (uid)
13411 +#define TAGINO_GID(cond, gid, tag)     (gid)
13412 +
13413 +#endif
13414 +
13415 +
13416 +#ifdef CONFIG_TAGGING_GID16
13417 +
13418 +#define MAX_UID                0xFFFFFFFF
13419 +#define MAX_GID                0x0000FFFF
13420 +
13421 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13422 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13423 +
13424 +#define TAGINO_UID(cond, uid, tag)     (uid)
13425 +#define TAGINO_GID(cond, gid, tag)     \
13426 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13427 +
13428 +#endif
13429 +
13430 +
13431 +#ifdef CONFIG_TAGGING_ID24
13432 +
13433 +#define MAX_UID                0x00FFFFFF
13434 +#define MAX_GID                0x00FFFFFF
13435 +
13436 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13437 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13438 +
13439 +#define TAGINO_UID(cond, uid, tag)     \
13440 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13441 +#define TAGINO_GID(cond, gid, tag)     \
13442 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13443 +
13444 +#endif
13445 +
13446 +
13447 +#ifdef CONFIG_TAGGING_UID16
13448 +
13449 +#define MAX_UID                0x0000FFFF
13450 +#define MAX_GID                0xFFFFFFFF
13451 +
13452 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13453 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13454 +
13455 +#define TAGINO_UID(cond, uid, tag)     \
13456 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13457 +#define TAGINO_GID(cond, gid, tag)     (gid)
13458 +
13459 +#endif
13460 +
13461 +
13462 +#ifdef CONFIG_TAGGING_INTERN
13463 +
13464 +#define MAX_UID                0xFFFFFFFF
13465 +#define MAX_GID                0xFFFFFFFF
13466 +
13467 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13468 +       ((cond) ? (tag) : 0)
13469 +
13470 +#define TAGINO_UID(cond, uid, tag)     (uid)
13471 +#define TAGINO_GID(cond, gid, tag)     (gid)
13472 +
13473 +#endif
13474 +
13475 +
13476 +#ifndef CONFIG_TAGGING_NONE
13477 +#define dx_current_fstag(sb)   \
13478 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13479 +#else
13480 +#define dx_current_fstag(sb)   (0)
13481 +#endif
13482 +
13483 +#ifndef CONFIG_TAGGING_INTERN
13484 +#define TAGINO_TAG(cond, tag)  (0)
13485 +#else
13486 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13487 +#endif
13488 +
13489 +#define INOTAG_UID(cond, uid, gid)     \
13490 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13491 +#define INOTAG_GID(cond, uid, gid)     \
13492 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13493 +
13494 +
13495 +static inline uid_t dx_map_uid(uid_t uid)
13496 +{
13497 +       if ((uid > MAX_UID) && (uid != -1))
13498 +               uid = -2;
13499 +       return (uid & MAX_UID);
13500 +}
13501 +
13502 +static inline gid_t dx_map_gid(gid_t gid)
13503 +{
13504 +       if ((gid > MAX_GID) && (gid != -1))
13505 +               gid = -2;
13506 +       return (gid & MAX_GID);
13507 +}
13508 +
13509 +struct peer_tag {
13510 +       int32_t xid;
13511 +       int32_t nid;
13512 +};
13513 +
13514 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13515 +
13516 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13517 +                unsigned long *flags);
13518 +
13519 +#ifdef CONFIG_PROPAGATE
13520 +
13521 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13522 +
13523 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13524 +
13525 +#else
13526 +#define dx_propagate_tag(n, i) do { } while (0)
13527 +#endif
13528 +
13529 +#endif /* _DX_TAG_H */
13530 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_inet6.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_inet6.h
13531 --- linux-2.6.27.25/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
13532 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_inet6.h       2008-11-16 17:35:20.000000000 +0100
13533 @@ -0,0 +1,246 @@
13534 +#ifndef _VS_INET6_H
13535 +#define _VS_INET6_H
13536 +
13537 +#include "vserver/base.h"
13538 +#include "vserver/network.h"
13539 +#include "vserver/debug.h"
13540 +
13541 +#include <net/ipv6.h>
13542 +
13543 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
13544 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
13545 +
13546 +
13547 +#ifdef CONFIG_IPV6
13548 +
13549 +static inline
13550 +int v6_addr_match(struct nx_addr_v6 *nxa,
13551 +       const struct in6_addr *addr, uint16_t mask)
13552 +{
13553 +       int ret = 0;
13554 +
13555 +       switch (nxa->type & mask) {
13556 +       case NXA_TYPE_MASK:
13557 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13558 +               break;
13559 +       case NXA_TYPE_ADDR:
13560 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13561 +               break;
13562 +       case NXA_TYPE_ANY:
13563 +               ret = 1;
13564 +               break;
13565 +       }
13566 +       vxdprintk(VXD_CBIT(net, 0),
13567 +               "v6_addr_match(%p" NXAV6_FMT ", " NIP6_FMT ", %04x) = %d",
13568 +               nxa, NXAV6(nxa), NIP6(*addr), mask, ret);
13569 +       return ret;
13570 +}
13571 +
13572 +static inline
13573 +int v6_addr_in_nx_info(struct nx_info *nxi,
13574 +       const struct in6_addr *addr, uint16_t mask)
13575 +{
13576 +       struct nx_addr_v6 *nxa;
13577 +       int ret = 1;
13578 +
13579 +       if (!nxi)
13580 +               goto out;
13581 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13582 +               if (v6_addr_match(nxa, addr, mask))
13583 +                       goto out;
13584 +       ret = 0;
13585 +out:
13586 +       vxdprintk(VXD_CBIT(net, 0),
13587 +               "v6_addr_in_nx_info(%p[#%u]," NIP6_FMT ",%04x) = %d",
13588 +               nxi, nxi ? nxi->nx_id : 0, NIP6(*addr), mask, ret);
13589 +       return ret;
13590 +}
13591 +
13592 +static inline
13593 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13594 +{
13595 +       /* FIXME: needs full range checks */
13596 +       return v6_addr_match(nxa, &addr->ip, mask);
13597 +}
13598 +
13599 +static inline
13600 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13601 +{
13602 +       struct nx_addr_v6 *ptr;
13603 +
13604 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13605 +               if (v6_nx_addr_match(ptr, nxa, mask))
13606 +                       return 1;
13607 +       return 0;
13608 +}
13609 +
13610 +
13611 +/*
13612 + *     Check if a given address matches for a socket
13613 + *
13614 + *     nxi:            the socket's nx_info if any
13615 + *     addr:           to be verified address
13616 + */
13617 +static inline
13618 +int v6_sock_addr_match (
13619 +       struct nx_info *nxi,
13620 +       struct inet_sock *inet,
13621 +       struct in6_addr *addr)
13622 +{
13623 +       struct sock *sk = &inet->sk;
13624 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13625 +
13626 +       if (!ipv6_addr_any(addr) &&
13627 +               ipv6_addr_equal(saddr, addr))
13628 +               return 1;
13629 +       if (ipv6_addr_any(saddr))
13630 +               return v6_addr_in_nx_info(nxi, addr, -1);
13631 +       return 0;
13632 +}
13633 +
13634 +/*
13635 + *     check if address is covered by socket
13636 + *
13637 + *     sk:     the socket to check against
13638 + *     addr:   the address in question (must be != 0)
13639 + */
13640 +
13641 +static inline
13642 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13643 +{
13644 +       struct nx_info *nxi = sk->sk_nx_info;
13645 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13646 +
13647 +       vxdprintk(VXD_CBIT(net, 5),
13648 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
13649 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
13650 +               (sk->sk_socket?sk->sk_socket->flags:0));
13651 +
13652 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13653 +               return v6_addr_match(nxa, saddr, -1);
13654 +       } else if (nxi) {               /* match against nx_info */
13655 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13656 +       } else {                        /* unrestricted any socket */
13657 +               return 1;
13658 +       }
13659 +}
13660 +
13661 +
13662 +/* inet related checks and helpers */
13663 +
13664 +
13665 +struct in_ifaddr;
13666 +struct net_device;
13667 +struct sock;
13668 +
13669 +
13670 +#include <linux/netdevice.h>
13671 +#include <linux/inetdevice.h>
13672 +#include <net/inet_timewait_sock.h>
13673 +
13674 +
13675 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13676 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13677 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13678 +
13679 +
13680 +
13681 +static inline
13682 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13683 +{
13684 +       if (!nxi)
13685 +               return 1;
13686 +       if (!ifa)
13687 +               return 0;
13688 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13689 +}
13690 +
13691 +static inline
13692 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13693 +{
13694 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13695 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13696 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13697 +
13698 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13699 +               return 1;
13700 +       if (v6_ifa_in_nx_info(ifa, nxi))
13701 +               return 1;
13702 +       return 0;
13703 +}
13704 +
13705 +
13706 +struct nx_v6_sock_addr {
13707 +       struct in6_addr saddr;  /* Address used for validation */
13708 +       struct in6_addr baddr;  /* Address used for socket bind */
13709 +};
13710 +
13711 +static inline
13712 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13713 +       struct nx_v6_sock_addr *nsa)
13714 +{
13715 +       // struct sock *sk = &inet->sk;
13716 +       // struct nx_info *nxi = sk->sk_nx_info;
13717 +       struct in6_addr saddr = addr->sin6_addr;
13718 +       struct in6_addr baddr = saddr;
13719 +
13720 +       nsa->saddr = saddr;
13721 +       nsa->baddr = baddr;
13722 +       return 0;
13723 +}
13724 +
13725 +static inline
13726 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13727 +{
13728 +       // struct sock *sk = &inet->sk;
13729 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13730 +
13731 +       // *saddr = nsa->baddr;
13732 +       // inet->saddr = nsa->baddr;
13733 +}
13734 +
13735 +static inline
13736 +int nx_info_has_v6(struct nx_info *nxi)
13737 +{
13738 +       if (!nxi)
13739 +               return 1;
13740 +       if (NX_IPV6(nxi))
13741 +               return 1;
13742 +       return 0;
13743 +}
13744 +
13745 +#else /* CONFIG_IPV6 */
13746 +
13747 +static inline
13748 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13749 +{
13750 +       return 1;
13751 +}
13752 +
13753 +
13754 +static inline
13755 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13756 +{
13757 +       return 1;
13758 +}
13759 +
13760 +static inline
13761 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13762 +{
13763 +       return 1;
13764 +}
13765 +
13766 +static inline
13767 +int nx_info_has_v6(struct nx_info *nxi)
13768 +{
13769 +       return 0;
13770 +}
13771 +
13772 +#endif /* CONFIG_IPV6 */
13773 +
13774 +#define current_nx_info_has_v6() \
13775 +       nx_info_has_v6(current_nx_info())
13776 +
13777 +#else
13778 +#warning duplicate inclusion
13779 +#endif
13780 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_inet.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_inet.h
13781 --- linux-2.6.27.25/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
13782 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_inet.h        2008-10-13 14:54:20.000000000 +0200
13783 @@ -0,0 +1,342 @@
13784 +#ifndef _VS_INET_H
13785 +#define _VS_INET_H
13786 +
13787 +#include "vserver/base.h"
13788 +#include "vserver/network.h"
13789 +#include "vserver/debug.h"
13790 +
13791 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13792 +
13793 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13794 +                       NIPQUAD((a)->mask), (a)->type
13795 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13796 +
13797 +
13798 +static inline
13799 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13800 +{
13801 +       __be32 ip = nxa->ip[0].s_addr;
13802 +       __be32 mask = nxa->mask.s_addr;
13803 +       __be32 bcast = ip | ~mask;
13804 +       int ret = 0;
13805 +
13806 +       switch (nxa->type & tmask) {
13807 +       case NXA_TYPE_MASK:
13808 +               ret = (ip == (addr & mask));
13809 +               break;
13810 +       case NXA_TYPE_ADDR:
13811 +               ret = 3;
13812 +               if (addr == ip)
13813 +                       break;
13814 +               /* fall through to broadcast */
13815 +       case NXA_MOD_BCAST:
13816 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13817 +               break;
13818 +       case NXA_TYPE_RANGE:
13819 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13820 +                       (nxa->ip[1].s_addr > addr));
13821 +               break;
13822 +       case NXA_TYPE_ANY:
13823 +               ret = 2;
13824 +               break;
13825 +       }
13826 +
13827 +       vxdprintk(VXD_CBIT(net, 0),
13828 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13829 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13830 +       return ret;
13831 +}
13832 +
13833 +static inline
13834 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13835 +{
13836 +       struct nx_addr_v4 *nxa;
13837 +       int ret = 1;
13838 +
13839 +       if (!nxi)
13840 +               goto out;
13841 +
13842 +       ret = 2;
13843 +       /* allow 127.0.0.1 when remapping lback */
13844 +       if ((tmask & NXA_LOOPBACK) &&
13845 +               (addr == IPI_LOOPBACK) &&
13846 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13847 +               goto out;
13848 +       ret = 3;
13849 +       /* check for lback address */
13850 +       if ((tmask & NXA_MOD_LBACK) &&
13851 +               (nxi->v4_lback.s_addr == addr))
13852 +               goto out;
13853 +       ret = 4;
13854 +       /* check for broadcast address */
13855 +       if ((tmask & NXA_MOD_BCAST) &&
13856 +               (nxi->v4_bcast.s_addr == addr))
13857 +               goto out;
13858 +       ret = 5;
13859 +       /* check for v4 addresses */
13860 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13861 +               if (v4_addr_match(nxa, addr, tmask))
13862 +                       goto out;
13863 +       ret = 0;
13864 +out:
13865 +       vxdprintk(VXD_CBIT(net, 0),
13866 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13867 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13868 +       return ret;
13869 +}
13870 +
13871 +static inline
13872 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13873 +{
13874 +       /* FIXME: needs full range checks */
13875 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13876 +}
13877 +
13878 +static inline
13879 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13880 +{
13881 +       struct nx_addr_v4 *ptr;
13882 +
13883 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13884 +               if (v4_nx_addr_match(ptr, nxa, mask))
13885 +                       return 1;
13886 +       return 0;
13887 +}
13888 +
13889 +#include <net/inet_sock.h>
13890 +
13891 +/*
13892 + *     Check if a given address matches for a socket
13893 + *
13894 + *     nxi:            the socket's nx_info if any
13895 + *     addr:           to be verified address
13896 + */
13897 +static inline
13898 +int v4_sock_addr_match (
13899 +       struct nx_info *nxi,
13900 +       struct inet_sock *inet,
13901 +       __be32 addr)
13902 +{
13903 +       __be32 saddr = inet->rcv_saddr;
13904 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13905 +
13906 +       if (addr && (saddr == addr || bcast == addr))
13907 +               return 1;
13908 +       if (!saddr)
13909 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13910 +       return 0;
13911 +}
13912 +
13913 +
13914 +/* inet related checks and helpers */
13915 +
13916 +
13917 +struct in_ifaddr;
13918 +struct net_device;
13919 +struct sock;
13920 +
13921 +#ifdef CONFIG_INET
13922 +
13923 +#include <linux/netdevice.h>
13924 +#include <linux/inetdevice.h>
13925 +#include <net/inet_sock.h>
13926 +#include <net/inet_timewait_sock.h>
13927 +
13928 +
13929 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13930 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13931 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13932 +
13933 +
13934 +/*
13935 + *     check if address is covered by socket
13936 + *
13937 + *     sk:     the socket to check against
13938 + *     addr:   the address in question (must be != 0)
13939 + */
13940 +
13941 +static inline
13942 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13943 +{
13944 +       struct nx_info *nxi = sk->sk_nx_info;
13945 +       __be32 saddr = inet_rcv_saddr(sk);
13946 +
13947 +       vxdprintk(VXD_CBIT(net, 5),
13948 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13949 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13950 +               (sk->sk_socket?sk->sk_socket->flags:0));
13951 +
13952 +       if (saddr) {            /* direct address match */
13953 +               return v4_addr_match(nxa, saddr, -1);
13954 +       } else if (nxi) {       /* match against nx_info */
13955 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13956 +       } else {                /* unrestricted any socket */
13957 +               return 1;
13958 +       }
13959 +}
13960 +
13961 +
13962 +
13963 +static inline
13964 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13965 +{
13966 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13967 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13968 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13969 +
13970 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13971 +               return 1;
13972 +       if (dev_in_nx_info(dev, nxi))
13973 +               return 1;
13974 +       return 0;
13975 +}
13976 +
13977 +
13978 +static inline
13979 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13980 +{
13981 +       if (!nxi)
13982 +               return 1;
13983 +       if (!ifa)
13984 +               return 0;
13985 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13986 +}
13987 +
13988 +static inline
13989 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13990 +{
13991 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13992 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13993 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13994 +
13995 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13996 +               return 1;
13997 +       if (v4_ifa_in_nx_info(ifa, nxi))
13998 +               return 1;
13999 +       return 0;
14000 +}
14001 +
14002 +
14003 +struct nx_v4_sock_addr {
14004 +       __be32 saddr;   /* Address used for validation */
14005 +       __be32 baddr;   /* Address used for socket bind */
14006 +};
14007 +
14008 +static inline
14009 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
14010 +       struct nx_v4_sock_addr *nsa)
14011 +{
14012 +       struct sock *sk = &inet->sk;
14013 +       struct nx_info *nxi = sk->sk_nx_info;
14014 +       __be32 saddr = addr->sin_addr.s_addr;
14015 +       __be32 baddr = saddr;
14016 +
14017 +       vxdprintk(VXD_CBIT(net, 3),
14018 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
14019 +               sk, sk->sk_nx_info, sk->sk_socket,
14020 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
14021 +               NIPQUAD(saddr));
14022 +
14023 +       if (nxi) {
14024 +               if (saddr == INADDR_ANY) {
14025 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
14026 +                               baddr = nxi->v4.ip[0].s_addr;
14027 +               } else if (saddr == IPI_LOOPBACK) {
14028 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14029 +                               baddr = nxi->v4_lback.s_addr;
14030 +               } else {        /* normal address bind */
14031 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
14032 +                               return -EADDRNOTAVAIL;
14033 +               }
14034 +       }
14035 +
14036 +       vxdprintk(VXD_CBIT(net, 3),
14037 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
14038 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
14039 +
14040 +       nsa->saddr = saddr;
14041 +       nsa->baddr = baddr;
14042 +       return 0;
14043 +}
14044 +
14045 +static inline
14046 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
14047 +{
14048 +       inet->saddr = nsa->baddr;
14049 +       inet->rcv_saddr = nsa->baddr;
14050 +}
14051 +
14052 +
14053 +/*
14054 + *      helper to simplify inet_lookup_listener
14055 + *
14056 + *      nxi:   the socket's nx_info if any
14057 + *      addr:  to be verified address
14058 + *      saddr: socket address
14059 + */
14060 +static inline int v4_inet_addr_match (
14061 +       struct nx_info *nxi,
14062 +       __be32 addr,
14063 +       __be32 saddr)
14064 +{
14065 +       if (addr && (saddr == addr))
14066 +               return 1;
14067 +       if (!saddr)
14068 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
14069 +       return 0;
14070 +}
14071 +
14072 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
14073 +{
14074 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
14075 +               (addr == nxi->v4_lback.s_addr))
14076 +               return IPI_LOOPBACK;
14077 +       return addr;
14078 +}
14079 +
14080 +static inline
14081 +int nx_info_has_v4(struct nx_info *nxi)
14082 +{
14083 +       if (!nxi)
14084 +               return 1;
14085 +       if (NX_IPV4(nxi))
14086 +               return 1;
14087 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14088 +               return 1;
14089 +       return 0;
14090 +}
14091 +
14092 +#else /* CONFIG_INET */
14093 +
14094 +static inline
14095 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
14096 +{
14097 +       return 1;
14098 +}
14099 +
14100 +static inline
14101 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14102 +{
14103 +       return 1;
14104 +}
14105 +
14106 +static inline
14107 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14108 +{
14109 +       return 1;
14110 +}
14111 +
14112 +static inline
14113 +int nx_info_has_v4(struct nx_info *nxi)
14114 +{
14115 +       return 0;
14116 +}
14117 +
14118 +#endif /* CONFIG_INET */
14119 +
14120 +#define current_nx_info_has_v4() \
14121 +       nx_info_has_v4(current_nx_info())
14122 +
14123 +#else
14124 +// #warning duplicate inclusion
14125 +#endif
14126 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_limit.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_limit.h
14127 --- linux-2.6.27.25/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
14128 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_limit.h       2008-10-13 14:54:20.000000000 +0200
14129 @@ -0,0 +1,140 @@
14130 +#ifndef _VS_LIMIT_H
14131 +#define _VS_LIMIT_H
14132 +
14133 +#include "vserver/limit.h"
14134 +#include "vserver/base.h"
14135 +#include "vserver/context.h"
14136 +#include "vserver/debug.h"
14137 +#include "vserver/context.h"
14138 +#include "vserver/limit_int.h"
14139 +
14140 +
14141 +#define vx_acc_cres(v, d, p, r) \
14142 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14143 +
14144 +#define vx_acc_cres_cond(x, d, p, r) \
14145 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14146 +       r, d, p, __FILE__, __LINE__)
14147 +
14148 +
14149 +#define vx_add_cres(v, a, p, r) \
14150 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
14151 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
14152 +
14153 +#define vx_add_cres_cond(x, a, p, r) \
14154 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14155 +       r, a, p, __FILE__, __LINE__)
14156 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
14157 +
14158 +
14159 +/* process and file limits */
14160 +
14161 +#define vx_nproc_inc(p) \
14162 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
14163 +
14164 +#define vx_nproc_dec(p) \
14165 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
14166 +
14167 +#define vx_files_inc(f) \
14168 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
14169 +
14170 +#define vx_files_dec(f) \
14171 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
14172 +
14173 +#define vx_locks_inc(l) \
14174 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
14175 +
14176 +#define vx_locks_dec(l) \
14177 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
14178 +
14179 +#define vx_openfd_inc(f) \
14180 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
14181 +
14182 +#define vx_openfd_dec(f) \
14183 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
14184 +
14185 +
14186 +#define vx_cres_avail(v, n, r) \
14187 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14188 +
14189 +
14190 +#define vx_nproc_avail(n) \
14191 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
14192 +
14193 +#define vx_files_avail(n) \
14194 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
14195 +
14196 +#define vx_locks_avail(n) \
14197 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
14198 +
14199 +#define vx_openfd_avail(n) \
14200 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
14201 +
14202 +
14203 +/* dentry limits */
14204 +
14205 +#define vx_dentry_inc(d) do {                                          \
14206 +       if (atomic_read(&d->d_count) == 1)                              \
14207 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
14208 +       } while (0)
14209 +
14210 +#define vx_dentry_dec(d) do {                                          \
14211 +       if (atomic_read(&d->d_count) == 0)                              \
14212 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
14213 +       } while (0)
14214 +
14215 +#define vx_dentry_avail(n) \
14216 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
14217 +
14218 +
14219 +/* socket limits */
14220 +
14221 +#define vx_sock_inc(s) \
14222 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14223 +
14224 +#define vx_sock_dec(s) \
14225 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14226 +
14227 +#define vx_sock_avail(n) \
14228 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
14229 +
14230 +
14231 +/* ipc resource limits */
14232 +
14233 +#define vx_ipcmsg_add(v, u, a) \
14234 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14235 +
14236 +#define vx_ipcmsg_sub(v, u, a) \
14237 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14238 +
14239 +#define vx_ipcmsg_avail(v, a) \
14240 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14241 +
14242 +
14243 +#define vx_ipcshm_add(v, k, a) \
14244 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14245 +
14246 +#define vx_ipcshm_sub(v, k, a) \
14247 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14248 +
14249 +#define vx_ipcshm_avail(v, a) \
14250 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14251 +
14252 +
14253 +#define vx_semary_inc(a) \
14254 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
14255 +
14256 +#define vx_semary_dec(a) \
14257 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
14258 +
14259 +
14260 +#define vx_nsems_add(a,n) \
14261 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14262 +
14263 +#define vx_nsems_sub(a,n) \
14264 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14265 +
14266 +
14267 +#else
14268 +#warning duplicate inclusion
14269 +#endif
14270 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_memory.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_memory.h
14271 --- linux-2.6.27.25/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
14272 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_memory.h      2008-10-13 14:54:20.000000000 +0200
14273 @@ -0,0 +1,159 @@
14274 +#ifndef _VS_MEMORY_H
14275 +#define _VS_MEMORY_H
14276 +
14277 +#include "vserver/limit.h"
14278 +#include "vserver/base.h"
14279 +#include "vserver/context.h"
14280 +#include "vserver/debug.h"
14281 +#include "vserver/context.h"
14282 +#include "vserver/limit_int.h"
14283 +
14284 +
14285 +#define __acc_add_long(a, v)   (*(v) += (a))
14286 +#define __acc_inc_long(v)      (++*(v))
14287 +#define __acc_dec_long(v)      (--*(v))
14288 +
14289 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14290 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14291 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14292 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14293 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14294 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14295 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14296 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14297 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14298 +
14299 +
14300 +#define vx_acc_page(m, d, v, r) do {                                   \
14301 +       if ((d) > 0)                                                    \
14302 +               __acc_inc_long(&(m)->v);                                \
14303 +       else                                                            \
14304 +               __acc_dec_long(&(m)->v);                                \
14305 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14306 +} while (0)
14307 +
14308 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14309 +       if ((d) > 0)                                                    \
14310 +               __acc_inc_atomic(&(m)->v);                              \
14311 +       else                                                            \
14312 +               __acc_dec_atomic(&(m)->v);                              \
14313 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14314 +} while (0)
14315 +
14316 +
14317 +#define vx_acc_pages(m, p, v, r) do {                                  \
14318 +       unsigned long __p = (p);                                        \
14319 +       __acc_add_long(__p, &(m)->v);                                   \
14320 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14321 +} while (0)
14322 +
14323 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14324 +       unsigned long __p = (p);                                        \
14325 +       __acc_add_atomic(__p, &(m)->v);                                 \
14326 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14327 +} while (0)
14328 +
14329 +
14330 +
14331 +#define vx_acc_vmpage(m, d) \
14332 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14333 +#define vx_acc_vmlpage(m, d) \
14334 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14335 +#define vx_acc_file_rsspage(m, d) \
14336 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14337 +#define vx_acc_anon_rsspage(m, d) \
14338 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14339 +
14340 +#define vx_acc_vmpages(m, p) \
14341 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14342 +#define vx_acc_vmlpages(m, p) \
14343 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14344 +#define vx_acc_file_rsspages(m, p) \
14345 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14346 +#define vx_acc_anon_rsspages(m, p) \
14347 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14348 +
14349 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14350 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14351 +
14352 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14353 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14354 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14355 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14356 +
14357 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14358 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14359 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14360 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14361 +
14362 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14363 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14364 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14365 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14366 +
14367 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14368 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14369 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14370 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14371 +
14372 +
14373 +#define vx_pages_avail(m, p, r) \
14374 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14375 +
14376 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14377 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14378 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14379 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14380 +
14381 +#define vx_rss_avail(m, p) \
14382 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14383 +
14384 +
14385 +enum {
14386 +       VXPT_UNKNOWN = 0,
14387 +       VXPT_ANON,
14388 +       VXPT_NONE,
14389 +       VXPT_FILE,
14390 +       VXPT_SWAP,
14391 +       VXPT_WRITE
14392 +};
14393 +
14394 +#if 0
14395 +#define        vx_page_fault(mm, vma, type, ret)
14396 +#else
14397 +
14398 +static inline
14399 +void __vx_page_fault(struct mm_struct *mm,
14400 +       struct vm_area_struct *vma, int type, int ret)
14401 +{
14402 +       struct vx_info *vxi = mm->mm_vx_info;
14403 +       int what;
14404 +/*
14405 +       static char *page_type[6] =
14406 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14407 +       static char *page_what[4] =
14408 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14409 +*/
14410 +
14411 +       if (!vxi)
14412 +               return;
14413 +
14414 +       what = (ret & 0x3);
14415 +
14416 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14417 +               type, what, ret, page_type[type], page_what[what]);
14418 +*/
14419 +       if (ret & VM_FAULT_WRITE)
14420 +               what |= 0x4;
14421 +       atomic_inc(&vxi->cacct.page[type][what]);
14422 +}
14423 +
14424 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14425 +#endif
14426 +
14427 +
14428 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14429 +
14430 +#else
14431 +#warning duplicate inclusion
14432 +#endif
14433 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_network.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_network.h
14434 --- linux-2.6.27.25/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
14435 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_network.h     2008-10-13 14:54:20.000000000 +0200
14436 @@ -0,0 +1,169 @@
14437 +#ifndef _NX_VS_NETWORK_H
14438 +#define _NX_VS_NETWORK_H
14439 +
14440 +#include "vserver/context.h"
14441 +#include "vserver/network.h"
14442 +#include "vserver/base.h"
14443 +#include "vserver/check.h"
14444 +#include "vserver/debug.h"
14445 +
14446 +#include <linux/sched.h>
14447 +
14448 +
14449 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14450 +
14451 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14452 +       const char *_file, int _line)
14453 +{
14454 +       if (!nxi)
14455 +               return NULL;
14456 +
14457 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14458 +               nxi, nxi ? nxi->nx_id : 0,
14459 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14460 +               _file, _line);
14461 +
14462 +       atomic_inc(&nxi->nx_usecnt);
14463 +       return nxi;
14464 +}
14465 +
14466 +
14467 +extern void free_nx_info(struct nx_info *);
14468 +
14469 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14470 +
14471 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14472 +{
14473 +       if (!nxi)
14474 +               return;
14475 +
14476 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14477 +               nxi, nxi ? nxi->nx_id : 0,
14478 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14479 +               _file, _line);
14480 +
14481 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14482 +               free_nx_info(nxi);
14483 +}
14484 +
14485 +
14486 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14487 +
14488 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14489 +               const char *_file, int _line)
14490 +{
14491 +       if (nxi) {
14492 +               vxlprintk(VXD_CBIT(nid, 3),
14493 +                       "init_nx_info(%p[#%d.%d])",
14494 +                       nxi, nxi ? nxi->nx_id : 0,
14495 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14496 +                       _file, _line);
14497 +
14498 +               atomic_inc(&nxi->nx_usecnt);
14499 +       }
14500 +       *nxp = nxi;
14501 +}
14502 +
14503 +
14504 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14505 +
14506 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14507 +       const char *_file, int _line)
14508 +{
14509 +       struct nx_info *nxo;
14510 +
14511 +       if (!nxi)
14512 +               return;
14513 +
14514 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14515 +               nxi, nxi ? nxi->nx_id : 0,
14516 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14517 +               _file, _line);
14518 +
14519 +       atomic_inc(&nxi->nx_usecnt);
14520 +       nxo = xchg(nxp, nxi);
14521 +       BUG_ON(nxo);
14522 +}
14523 +
14524 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14525 +
14526 +static inline void __clr_nx_info(struct nx_info **nxp,
14527 +       const char *_file, int _line)
14528 +{
14529 +       struct nx_info *nxo;
14530 +
14531 +       nxo = xchg(nxp, NULL);
14532 +       if (!nxo)
14533 +               return;
14534 +
14535 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14536 +               nxo, nxo ? nxo->nx_id : 0,
14537 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14538 +               _file, _line);
14539 +
14540 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14541 +               free_nx_info(nxo);
14542 +}
14543 +
14544 +
14545 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14546 +
14547 +static inline void __claim_nx_info(struct nx_info *nxi,
14548 +       struct task_struct *task, const char *_file, int _line)
14549 +{
14550 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14551 +               nxi, nxi ? nxi->nx_id : 0,
14552 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14553 +               nxi?atomic_read(&nxi->nx_tasks):0,
14554 +               task, _file, _line);
14555 +
14556 +       atomic_inc(&nxi->nx_tasks);
14557 +}
14558 +
14559 +
14560 +extern void unhash_nx_info(struct nx_info *);
14561 +
14562 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14563 +
14564 +static inline void __release_nx_info(struct nx_info *nxi,
14565 +       struct task_struct *task, const char *_file, int _line)
14566 +{
14567 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14568 +               nxi, nxi ? nxi->nx_id : 0,
14569 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14570 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14571 +               task, _file, _line);
14572 +
14573 +       might_sleep();
14574 +
14575 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14576 +               unhash_nx_info(nxi);
14577 +}
14578 +
14579 +
14580 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14581 +
14582 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14583 +       const char *_file, int _line)
14584 +{
14585 +       struct nx_info *nxi;
14586 +
14587 +       task_lock(p);
14588 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14589 +               p, _file, _line);
14590 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14591 +       task_unlock(p);
14592 +       return nxi;
14593 +}
14594 +
14595 +
14596 +static inline void exit_nx_info(struct task_struct *p)
14597 +{
14598 +       if (p->nx_info)
14599 +               release_nx_info(p->nx_info, p);
14600 +}
14601 +
14602 +
14603 +#else
14604 +#warning duplicate inclusion
14605 +#endif
14606 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_pid.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_pid.h
14607 --- linux-2.6.27.25/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
14608 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_pid.h 2008-10-13 14:54:20.000000000 +0200
14609 @@ -0,0 +1,95 @@
14610 +#ifndef _VS_PID_H
14611 +#define _VS_PID_H
14612 +
14613 +#include "vserver/base.h"
14614 +#include "vserver/check.h"
14615 +#include "vserver/context.h"
14616 +#include "vserver/debug.h"
14617 +#include "vserver/pid.h"
14618 +#include <linux/pid_namespace.h>
14619 +
14620 +
14621 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14622 +
14623 +static inline
14624 +int vx_proc_task_visible(struct task_struct *task)
14625 +{
14626 +       if ((task->pid == 1) &&
14627 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14628 +               /* show a blend through init */
14629 +               goto visible;
14630 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14631 +               goto visible;
14632 +       return 0;
14633 +visible:
14634 +       return 1;
14635 +}
14636 +
14637 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14638 +
14639 +#if 0
14640 +
14641 +static inline
14642 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14643 +{
14644 +       struct task_struct *task = find_task_by_real_pid(pid);
14645 +
14646 +       if (task && !vx_proc_task_visible(task)) {
14647 +               vxdprintk(VXD_CBIT(misc, 6),
14648 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14649 +                       task, task->xid, task->pid,
14650 +                       current, current->xid, current->pid);
14651 +               task = NULL;
14652 +       }
14653 +       return task;
14654 +}
14655 +
14656 +#endif
14657 +
14658 +static inline
14659 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14660 +{
14661 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14662 +
14663 +       if (task && !vx_proc_task_visible(task)) {
14664 +               vxdprintk(VXD_CBIT(misc, 6),
14665 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14666 +                       task, task->xid, task->pid,
14667 +                       current, current->xid, current->pid);
14668 +               put_task_struct(task);
14669 +               task = NULL;
14670 +       }
14671 +       return task;
14672 +}
14673 +
14674 +#if 0
14675 +
14676 +static inline
14677 +struct task_struct *vx_child_reaper(struct task_struct *p)
14678 +{
14679 +       struct vx_info *vxi = p->vx_info;
14680 +       struct task_struct *reaper = child_reaper(p);
14681 +
14682 +       if (!vxi)
14683 +               goto out;
14684 +
14685 +       BUG_ON(!p->vx_info->vx_reaper);
14686 +
14687 +       /* child reaper for the guest reaper */
14688 +       if (vxi->vx_reaper == p)
14689 +               goto out;
14690 +
14691 +       reaper = vxi->vx_reaper;
14692 +out:
14693 +       vxdprintk(VXD_CBIT(xid, 7),
14694 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14695 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14696 +       return reaper;
14697 +}
14698 +
14699 +#endif
14700 +
14701 +
14702 +#else
14703 +#warning duplicate inclusion
14704 +#endif
14705 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_sched.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_sched.h
14706 --- linux-2.6.27.25/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
14707 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_sched.h       2008-10-13 14:54:20.000000000 +0200
14708 @@ -0,0 +1,110 @@
14709 +#ifndef _VS_SCHED_H
14710 +#define _VS_SCHED_H
14711 +
14712 +#include "vserver/base.h"
14713 +#include "vserver/context.h"
14714 +#include "vserver/sched.h"
14715 +
14716 +
14717 +#define VAVAVOOM_RATIO          50
14718 +
14719 +#define MAX_PRIO_BIAS           20
14720 +#define MIN_PRIO_BIAS          -20
14721 +
14722 +
14723 +#ifdef CONFIG_VSERVER_HARDCPU
14724 +
14725 +/*
14726 + * effective_prio - return the priority that is based on the static
14727 + * priority but is modified by bonuses/penalties.
14728 + *
14729 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14730 + * into a -4 ... 0 ... +4 bonus/penalty range.
14731 + *
14732 + * Additionally, we scale another amount based on the number of
14733 + * CPU tokens currently held by the context, if the process is
14734 + * part of a context (and the appropriate SCHED flag is set).
14735 + * This ranges from -5 ... 0 ... +15, quadratically.
14736 + *
14737 + * So, the total bonus is -9 .. 0 .. +19
14738 + * We use ~50% of the full 0...39 priority range so that:
14739 + *
14740 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14741 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14742 + *    unless that context is far exceeding its CPU allocation.
14743 + *
14744 + * Both properties are important to certain workloads.
14745 + */
14746 +static inline
14747 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14748 +{
14749 +       int vavavoom, max;
14750 +
14751 +       /* lots of tokens = lots of vavavoom
14752 +        *      no tokens = no vavavoom      */
14753 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14754 +               max = sched_pc->tokens_max;
14755 +               vavavoom = max - vavavoom;
14756 +               max = max * max;
14757 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14758 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14759 +               return vavavoom;
14760 +       }
14761 +       return 0;
14762 +}
14763 +
14764 +
14765 +static inline
14766 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14767 +{
14768 +       struct vx_info *vxi = p->vx_info;
14769 +       struct _vx_sched_pc *sched_pc;
14770 +
14771 +       if (!vxi)
14772 +               return prio;
14773 +
14774 +       sched_pc = &vx_cpu(vxi, sched_pc);
14775 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14776 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14777 +
14778 +               sched_pc->vavavoom = vavavoom;
14779 +               prio += vavavoom;
14780 +       }
14781 +       prio += sched_pc->prio_bias;
14782 +       return prio;
14783 +}
14784 +
14785 +#else /* !CONFIG_VSERVER_HARDCPU */
14786 +
14787 +static inline
14788 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14789 +{
14790 +       struct vx_info *vxi = p->vx_info;
14791 +
14792 +       if (vxi)
14793 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14794 +       return prio;
14795 +}
14796 +
14797 +#endif /* CONFIG_VSERVER_HARDCPU */
14798 +
14799 +
14800 +static inline void vx_account_user(struct vx_info *vxi,
14801 +       cputime_t cputime, int nice)
14802 +{
14803 +       if (!vxi)
14804 +               return;
14805 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14806 +}
14807 +
14808 +static inline void vx_account_system(struct vx_info *vxi,
14809 +       cputime_t cputime, int idle)
14810 +{
14811 +       if (!vxi)
14812 +               return;
14813 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14814 +}
14815 +
14816 +#else
14817 +#warning duplicate inclusion
14818 +#endif
14819 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_socket.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_socket.h
14820 --- linux-2.6.27.25/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
14821 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_socket.h      2008-10-13 14:54:20.000000000 +0200
14822 @@ -0,0 +1,67 @@
14823 +#ifndef _VS_SOCKET_H
14824 +#define _VS_SOCKET_H
14825 +
14826 +#include "vserver/debug.h"
14827 +#include "vserver/base.h"
14828 +#include "vserver/cacct.h"
14829 +#include "vserver/context.h"
14830 +#include "vserver/tag.h"
14831 +
14832 +
14833 +/* socket accounting */
14834 +
14835 +#include <linux/socket.h>
14836 +
14837 +static inline int vx_sock_type(int family)
14838 +{
14839 +       switch (family) {
14840 +       case PF_UNSPEC:
14841 +               return VXA_SOCK_UNSPEC;
14842 +       case PF_UNIX:
14843 +               return VXA_SOCK_UNIX;
14844 +       case PF_INET:
14845 +               return VXA_SOCK_INET;
14846 +       case PF_INET6:
14847 +               return VXA_SOCK_INET6;
14848 +       case PF_PACKET:
14849 +               return VXA_SOCK_PACKET;
14850 +       default:
14851 +               return VXA_SOCK_OTHER;
14852 +       }
14853 +}
14854 +
14855 +#define vx_acc_sock(v, f, p, s) \
14856 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14857 +
14858 +static inline void __vx_acc_sock(struct vx_info *vxi,
14859 +       int family, int pos, int size, char *file, int line)
14860 +{
14861 +       if (vxi) {
14862 +               int type = vx_sock_type(family);
14863 +
14864 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14865 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14866 +       }
14867 +}
14868 +
14869 +#define vx_sock_recv(sk, s) \
14870 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14871 +#define vx_sock_send(sk, s) \
14872 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14873 +#define vx_sock_fail(sk, s) \
14874 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14875 +
14876 +
14877 +#define sock_vx_init(s) do {           \
14878 +       (s)->sk_xid = 0;                \
14879 +       (s)->sk_vx_info = NULL;         \
14880 +       } while (0)
14881 +
14882 +#define sock_nx_init(s) do {           \
14883 +       (s)->sk_nid = 0;                \
14884 +       (s)->sk_nx_info = NULL;         \
14885 +       } while (0)
14886 +
14887 +#else
14888 +#warning duplicate inclusion
14889 +#endif
14890 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_tag.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_tag.h
14891 --- linux-2.6.27.25/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
14892 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_tag.h 2008-10-24 03:34:52.000000000 +0200
14893 @@ -0,0 +1,47 @@
14894 +#ifndef _VS_TAG_H
14895 +#define _VS_TAG_H
14896 +
14897 +#include <linux/vserver/tag.h>
14898 +
14899 +/* check conditions */
14900 +
14901 +#define DX_ADMIN       0x0001
14902 +#define DX_WATCH       0x0002
14903 +#define DX_HOSTID      0x0008
14904 +
14905 +#define DX_IDENT       0x0010
14906 +
14907 +#define DX_ARG_MASK    0x0010
14908 +
14909 +
14910 +#define dx_task_tag(t) ((t)->tag)
14911 +
14912 +#define dx_current_tag() dx_task_tag(current)
14913 +
14914 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14915 +
14916 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14917 +
14918 +
14919 +/*
14920 + * check current context for ADMIN/WATCH and
14921 + * optionally against supplied argument
14922 + */
14923 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14924 +{
14925 +       if (mode & DX_ARG_MASK) {
14926 +               if ((mode & DX_IDENT) && (id == cid))
14927 +                       return 1;
14928 +       }
14929 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14930 +               ((mode & DX_WATCH) && (cid == 1)) ||
14931 +               ((mode & DX_HOSTID) && (id == 0)));
14932 +}
14933 +
14934 +struct inode;
14935 +int dx_permission(struct inode *inode, int mask);
14936 +
14937 +
14938 +#else
14939 +#warning duplicate inclusion
14940 +#endif
14941 diff -NurpP --minimal linux-2.6.27.25/include/linux/vs_time.h linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_time.h
14942 --- linux-2.6.27.25/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
14943 +++ linux-2.6.27.25-vs2.3.0.36.6/include/linux/vs_time.h        2008-10-13 14:54:20.000000000 +0200
14944 @@ -0,0 +1,19 @@
14945 +#ifndef _VS_TIME_H
14946 +#define _VS_TIME_H
14947 +
14948 +
14949 +/* time faking stuff */
14950 +
14951 +#ifdef CONFIG_VSERVER_VTIME
14952 +
14953 +extern void vx_gettimeofday(struct timeval *tv);
14954 +extern int vx_settimeofday(struct timespec *ts);
14955 +
14956 +#else
14957 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14958 +#define        vx_settimeofday(t)      do_settimeofday(t)
14959 +#endif
14960 +
14961 +#else
14962 +#warning duplicate inclusion
14963 +#endif
14964 diff -NurpP --minimal linux-2.6.27.25/include/net/addrconf.h linux-2.6.27.25-vs2.3.0.36.6/include/net/addrconf.h
14965 --- linux-2.6.27.25/include/net/addrconf.h      2008-10-13 14:52:09.000000000 +0200
14966 +++ linux-2.6.27.25-vs2.3.0.36.6/include/net/addrconf.h 2008-10-13 14:54:20.000000000 +0200
14967 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14968                                                struct net_device *dev,
14969                                                const struct in6_addr *daddr,
14970                                                unsigned int srcprefs,
14971 -                                              struct in6_addr *saddr);
14972 +                                              struct in6_addr *saddr,
14973 +                                              struct nx_info *nxi);
14974  extern int                     ipv6_get_lladdr(struct net_device *dev,
14975                                                 struct in6_addr *addr,
14976                                                 unsigned char banned_flags);
14977 diff -NurpP --minimal linux-2.6.27.25/include/net/af_unix.h linux-2.6.27.25-vs2.3.0.36.6/include/net/af_unix.h
14978 --- linux-2.6.27.25/include/net/af_unix.h       2009-06-15 17:18:32.000000000 +0200
14979 +++ linux-2.6.27.25-vs2.3.0.36.6/include/net/af_unix.h  2009-02-03 17:59:04.000000000 +0100
14980 @@ -4,6 +4,7 @@
14981  #include <linux/socket.h>
14982  #include <linux/un.h>
14983  #include <linux/mutex.h>
14984 +#include <linux/vs_base.h>
14985  #include <net/sock.h>
14986  
14987  extern void unix_inflight(struct file *fp);
14988 diff -NurpP --minimal linux-2.6.27.25/include/net/inet_sock.h linux-2.6.27.25-vs2.3.0.36.6/include/net/inet_sock.h
14989 --- linux-2.6.27.25/include/net/inet_sock.h     2008-10-13 14:52:09.000000000 +0200
14990 +++ linux-2.6.27.25-vs2.3.0.36.6/include/net/inet_sock.h        2008-10-13 14:54:20.000000000 +0200
14991 @@ -24,7 +24,7 @@
14992  #include <net/flow.h>
14993  #include <net/sock.h>
14994  #include <net/request_sock.h>
14995 -#include <net/route.h>
14996 +// #include <net/route.h>
14997  #include <net/netns/hash.h>
14998  
14999  /** struct ip_options - IP Options
15000 @@ -195,11 +195,6 @@ static inline int inet_sk_ehashfn(const 
15001  }
15002  
15003  
15004 -static inline int inet_iif(const struct sk_buff *skb)
15005 -{
15006 -       return skb->rtable->rt_iif;
15007 -}
15008 -
15009  static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
15010  {
15011         struct request_sock *req = reqsk_alloc(ops);
15012 diff -NurpP --minimal linux-2.6.27.25/include/net/inet_timewait_sock.h linux-2.6.27.25-vs2.3.0.36.6/include/net/inet_timewait_sock.h
15013 --- linux-2.6.27.25/include/net/inet_timewait_sock.h    2008-10-13 14:52:09.000000000 +0200
15014 +++ linux-2.6.27.25-vs2.3.0.36.6/include/net/inet_timewait_sock.h       2008-10-13 14:54:20.000000000 +0200
15015 @@ -15,15 +15,14 @@
15016  #ifndef _INET_TIMEWAIT_SOCK_
15017  #define _INET_TIMEWAIT_SOCK_
15018  
15019 +// #include <net/inet_sock.h>
15020 +#include <net/sock.h>
15021  
15022  #include <linux/list.h>
15023  #include <linux/module.h>
15024  #include <linux/timer.h>
15025  #include <linux/types.h>
15026  #include <linux/workqueue.h>
15027 -
15028 -#include <net/inet_sock.h>
15029 -#include <net/sock.h>
15030  #include <net/tcp_states.h>
15031  #include <net/timewait_sock.h>
15032  
15033 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
15034  #define tw_hash                        __tw_common.skc_hash
15035  #define tw_prot                        __tw_common.skc_prot
15036  #define tw_net                 __tw_common.skc_net
15037 +#define tw_xid                 __tw_common.skc_xid
15038 +#define tw_vx_info             __tw_common.skc_vx_info
15039 +#define tw_nid                 __tw_common.skc_nid
15040 +#define tw_nx_info             __tw_common.skc_nx_info
15041         int                     tw_timeout;
15042         volatile unsigned char  tw_substate;
15043         /* 3 bits hole, try to pack */
15044 diff -NurpP --minimal linux-2.6.27.25/include/net/route.h linux-2.6.27.25-vs2.3.0.36.6/include/net/route.h
15045 --- linux-2.6.27.25/include/net/route.h 2008-10-13 14:52:09.000000000 +0200
15046 +++ linux-2.6.27.25-vs2.3.0.36.6/include/net/route.h    2008-10-13 14:54:20.000000000 +0200
15047 @@ -28,6 +28,7 @@
15048  #include <net/inetpeer.h>
15049  #include <net/flow.h>
15050  #include <net/sock.h>
15051 +// #include <linux/in.h>
15052  #include <linux/in_route.h>
15053  #include <linux/rtnetlink.h>
15054  #include <linux/route.h>
15055 @@ -85,6 +86,11 @@ struct ip_rt_acct
15056         __u32   i_packets;
15057  };
15058  
15059 +static inline int inet_iif(const struct sk_buff *skb)
15060 +{
15061 +       return skb->rtable->rt_iif;
15062 +}
15063 +
15064  struct rt_cache_stat 
15065  {
15066          unsigned int in_hit;
15067 @@ -135,6 +141,9 @@ static inline void ip_rt_put(struct rtab
15068                 dst_release(&rt->u.dst);
15069  }
15070  
15071 +#include <linux/vs_base.h>
15072 +#include <linux/vs_inet.h>
15073 +
15074  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15075  
15076  extern const __u8 ip_tos2prio[16];
15077 @@ -144,6 +153,9 @@ static inline char rt_tos2priority(u8 to
15078         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15079  }
15080  
15081 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
15082 +       struct rtable **, struct flowi *);
15083 +
15084  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15085                                    __be32 src, u32 tos, int oif, u8 protocol,
15086                                    __be16 sport, __be16 dport, struct sock *sk,
15087 @@ -161,7 +173,21 @@ static inline int ip_route_connect(struc
15088  
15089         int err;
15090         struct net *net = sock_net(sk);
15091 -       if (!dst || !src) {
15092 +       struct nx_info *nx_info = current->nx_info;
15093 +
15094 +       if (sk)
15095 +               nx_info = sk->sk_nx_info;
15096 +
15097 +       vxdprintk(VXD_CBIT(net, 4),
15098 +               "ip_route_connect(%p) %p,%p;%lx",
15099 +               sk, nx_info, sk->sk_socket,
15100 +               (sk->sk_socket?sk->sk_socket->flags:0));
15101 +
15102 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
15103 +       if (err)
15104 +               return err;
15105 +
15106 +       if (!fl.fl4_dst || !fl.fl4_src) {
15107                 err = __ip_route_output_key(net, rp, &fl);
15108                 if (err)
15109                         return err;
15110 diff -NurpP --minimal linux-2.6.27.25/include/net/sock.h linux-2.6.27.25-vs2.3.0.36.6/include/net/sock.h
15111 --- linux-2.6.27.25/include/net/sock.h  2009-06-15 17:18:32.000000000 +0200
15112 +++ linux-2.6.27.25-vs2.3.0.36.6/include/net/sock.h     2009-03-25 14:32:29.000000000 +0100
15113 @@ -128,6 +128,10 @@ struct sock_common {
15114  #ifdef CONFIG_NET_NS
15115         struct net              *skc_net;
15116  #endif
15117 +       xid_t                   skc_xid;
15118 +       struct vx_info          *skc_vx_info;
15119 +       nid_t                   skc_nid;
15120 +       struct nx_info          *skc_nx_info;
15121  };
15122  
15123  /**
15124 @@ -211,6 +215,10 @@ struct sock {
15125  #define sk_hash                        __sk_common.skc_hash
15126  #define sk_prot                        __sk_common.skc_prot
15127  #define sk_net                 __sk_common.skc_net
15128 +#define sk_xid                 __sk_common.skc_xid
15129 +#define sk_vx_info             __sk_common.skc_vx_info
15130 +#define sk_nid                 __sk_common.skc_nid
15131 +#define sk_nx_info             __sk_common.skc_nx_info
15132         unsigned char           sk_shutdown : 2,
15133                                 sk_no_check : 2,
15134                                 sk_userlocks : 4;
15135 diff -NurpP --minimal linux-2.6.27.25/init/main.c linux-2.6.27.25-vs2.3.0.36.6/init/main.c
15136 --- linux-2.6.27.25/init/main.c 2008-10-13 14:52:09.000000000 +0200
15137 +++ linux-2.6.27.25-vs2.3.0.36.6/init/main.c    2008-10-13 14:54:20.000000000 +0200
15138 @@ -60,6 +60,7 @@
15139  #include <linux/sched.h>
15140  #include <linux/signal.h>
15141  #include <linux/idr.h>
15142 +#include <linux/vserver/percpu.h>
15143  
15144  #include <asm/io.h>
15145  #include <asm/bugs.h>
15146 @@ -391,12 +392,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15147  
15148  static void __init setup_per_cpu_areas(void)
15149  {
15150 -       unsigned long size, i;
15151 +       unsigned long size, vspc, i;
15152         char *ptr;
15153         unsigned long nr_possible_cpus = num_possible_cpus();
15154  
15155 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15156 +
15157         /* Copy section for each CPU (we discard the original) */
15158 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15159 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15160         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15161  
15162         for_each_possible_cpu(i) {
15163 diff -NurpP --minimal linux-2.6.27.25/ipc/mqueue.c linux-2.6.27.25-vs2.3.0.36.6/ipc/mqueue.c
15164 --- linux-2.6.27.25/ipc/mqueue.c        2009-06-15 17:18:32.000000000 +0200
15165 +++ linux-2.6.27.25-vs2.3.0.36.6/ipc/mqueue.c   2009-02-22 22:58:33.000000000 +0100
15166 @@ -31,6 +31,8 @@
15167  #include <linux/mutex.h>
15168  #include <linux/nsproxy.h>
15169  #include <linux/pid.h>
15170 +#include <linux/vs_context.h>
15171 +#include <linux/vs_limit.h>
15172  
15173  #include <net/sock.h>
15174  #include "util.h"
15175 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
15176         struct sigevent notify;
15177         struct pid* notify_owner;
15178         struct user_struct *user;       /* user who created, for accounting */
15179 +       struct vx_info *vxi;
15180         struct sock *notify_sock;
15181         struct sk_buff *notify_cookie;
15182  
15183 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
15184                         struct mqueue_inode_info *info;
15185                         struct task_struct *p = current;
15186                         struct user_struct *u = p->user;
15187 +                       struct vx_info *vxi = p->vx_info;
15188                         unsigned long mq_bytes, mq_msg_tblsz;
15189  
15190                         inode->i_fop = &mqueue_file_operations;
15191 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
15192                         info->notify_owner = NULL;
15193                         info->qsize = 0;
15194                         info->user = NULL;      /* set when all is ok */
15195 +                       info->vxi = NULL;
15196                         memset(&info->attr, 0, sizeof(info->attr));
15197                         info->attr.mq_maxmsg = DFLT_MSGMAX;
15198                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
15199 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
15200                         spin_lock(&mq_lock);
15201                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15202                             u->mq_bytes + mq_bytes >
15203 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15204 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15205 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15206                                 spin_unlock(&mq_lock);
15207                                 goto out_inode;
15208                         }
15209                         u->mq_bytes += mq_bytes;
15210 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15211                         spin_unlock(&mq_lock);
15212  
15213                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15214                         if (!info->messages) {
15215                                 spin_lock(&mq_lock);
15216                                 u->mq_bytes -= mq_bytes;
15217 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15218                                 spin_unlock(&mq_lock);
15219                                 goto out_inode;
15220                         }
15221                         /* all is ok */
15222                         info->user = get_uid(u);
15223 +                       info->vxi = get_vx_info(vxi);
15224                 } else if (S_ISDIR(mode)) {
15225                         inc_nlink(inode);
15226                         /* Some things misbehave if size == 0 on a directory */
15227 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
15228                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15229         user = info->user;
15230         if (user) {
15231 +               struct vx_info *vxi = info->vxi;
15232 +
15233                 spin_lock(&mq_lock);
15234                 user->mq_bytes -= mq_bytes;
15235 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15236                 queues_count--;
15237                 spin_unlock(&mq_lock);
15238 +               put_vx_info(vxi);
15239                 free_uid(user);
15240         }
15241  }
15242 diff -NurpP --minimal linux-2.6.27.25/ipc/msg.c linux-2.6.27.25-vs2.3.0.36.6/ipc/msg.c
15243 --- linux-2.6.27.25/ipc/msg.c   2009-06-15 17:18:32.000000000 +0200
15244 +++ linux-2.6.27.25-vs2.3.0.36.6/ipc/msg.c      2009-02-03 17:59:04.000000000 +0100
15245 @@ -38,6 +38,7 @@
15246  #include <linux/rwsem.h>
15247  #include <linux/nsproxy.h>
15248  #include <linux/ipc_namespace.h>
15249 +#include <linux/vs_base.h>
15250  
15251  #include <asm/current.h>
15252  #include <asm/uaccess.h>
15253 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
15254  
15255         msq->q_perm.mode = msgflg & S_IRWXUGO;
15256         msq->q_perm.key = key;
15257 +       msq->q_perm.xid = vx_current_xid();
15258  
15259         msq->q_perm.security = NULL;
15260         retval = security_msg_queue_alloc(msq);
15261 diff -NurpP --minimal linux-2.6.27.25/ipc/namespace.c linux-2.6.27.25-vs2.3.0.36.6/ipc/namespace.c
15262 --- linux-2.6.27.25/ipc/namespace.c     2008-07-13 23:51:29.000000000 +0200
15263 +++ linux-2.6.27.25-vs2.3.0.36.6/ipc/namespace.c        2008-10-13 14:54:20.000000000 +0200
15264 @@ -9,6 +9,8 @@
15265  #include <linux/rcupdate.h>
15266  #include <linux/nsproxy.h>
15267  #include <linux/slab.h>
15268 +#include <linux/vs_base.h>
15269 +#include <linux/vserver/global.h>
15270  
15271  #include "util.h"
15272  
15273 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
15274         register_ipcns_notifier(ns);
15275  
15276         kref_init(&ns->kref);
15277 +       atomic_inc(&vs_global_ipc_ns);
15278         return ns;
15279  }
15280  
15281 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
15282         sem_exit_ns(ns);
15283         msg_exit_ns(ns);
15284         shm_exit_ns(ns);
15285 +       atomic_dec(&vs_global_ipc_ns);
15286         kfree(ns);
15287         atomic_dec(&nr_ipc_ns);
15288  
15289 diff -NurpP --minimal linux-2.6.27.25/ipc/sem.c linux-2.6.27.25-vs2.3.0.36.6/ipc/sem.c
15290 --- linux-2.6.27.25/ipc/sem.c   2009-06-15 17:18:32.000000000 +0200
15291 +++ linux-2.6.27.25-vs2.3.0.36.6/ipc/sem.c      2009-03-31 19:53:55.000000000 +0200
15292 @@ -83,6 +83,8 @@
15293  #include <linux/rwsem.h>
15294  #include <linux/nsproxy.h>
15295  #include <linux/ipc_namespace.h>
15296 +#include <linux/vs_base.h>
15297 +#include <linux/vs_limit.h>
15298  
15299  #include <asm/uaccess.h>
15300  #include "util.h"
15301 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
15302  
15303         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15304         sma->sem_perm.key = key;
15305 +       sma->sem_perm.xid = vx_current_xid();
15306  
15307         sma->sem_perm.security = NULL;
15308         retval = security_sem_alloc(sma);
15309 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
15310                 return id;
15311         }
15312         ns->used_sems += nsems;
15313 +       /* FIXME: obsoleted? */
15314 +       vx_semary_inc(sma);
15315 +       vx_nsems_add(sma, nsems);
15316  
15317         sma->sem_base = (struct sem *) &sma[1];
15318         INIT_LIST_HEAD(&sma->sem_pending);
15319 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
15320         sem_unlock(sma);
15321  
15322         ns->used_sems -= sma->sem_nsems;
15323 +       /* FIXME: obsoleted? */
15324 +       vx_nsems_sub(sma, sma->sem_nsems);
15325 +       vx_semary_dec(sma);
15326         security_sem_free(sma);
15327         ipc_rcu_putref(sma);
15328  }
15329 diff -NurpP --minimal linux-2.6.27.25/ipc/shm.c linux-2.6.27.25-vs2.3.0.36.6/ipc/shm.c
15330 --- linux-2.6.27.25/ipc/shm.c   2009-06-15 17:18:32.000000000 +0200
15331 +++ linux-2.6.27.25-vs2.3.0.36.6/ipc/shm.c      2009-02-22 22:58:33.000000000 +0100
15332 @@ -39,6 +39,8 @@
15333  #include <linux/nsproxy.h>
15334  #include <linux/mount.h>
15335  #include <linux/ipc_namespace.h>
15336 +#include <linux/vs_context.h>
15337 +#include <linux/vs_limit.h>
15338  
15339  #include <asm/uaccess.h>
15340  
15341 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
15342   */
15343  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15344  {
15345 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15346 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15347 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15348 +
15349 +       vx_ipcshm_sub(vxi, shp, numpages);
15350 +       ns->shm_tot -= numpages;
15351 +
15352         shm_rmid(ns, shp);
15353         shm_unlock(shp);
15354         if (!is_file_hugepages(shp->shm_file))
15355 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
15356                                                 shp->mlock_user);
15357         fput (shp->shm_file);
15358         security_shm_free(shp);
15359 +       put_vx_info(vxi);
15360         ipc_rcu_putref(shp);
15361  }
15362  
15363 @@ -347,11 +355,15 @@ static int newseg(struct ipc_namespace *
15364         if (ns->shm_tot + numpages > ns->shm_ctlall)
15365                 return -ENOSPC;
15366  
15367 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15368 +               return -ENOSPC;
15369 +
15370         shp = ipc_rcu_alloc(sizeof(*shp));
15371         if (!shp)
15372                 return -ENOMEM;
15373  
15374         shp->shm_perm.key = key;
15375 +       shp->shm_perm.xid = vx_current_xid();
15376         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15377         shp->mlock_user = NULL;
15378  
15379 @@ -404,6 +416,7 @@ static int newseg(struct ipc_namespace *
15380         ns->shm_tot += numpages;
15381         error = shp->shm_perm.id;
15382         shm_unlock(shp);
15383 +       vx_ipcshm_add(current->vx_info, key, numpages);
15384         return error;
15385  
15386  no_id:
15387 diff -NurpP --minimal linux-2.6.27.25/kernel/capability.c linux-2.6.27.25-vs2.3.0.36.6/kernel/capability.c
15388 --- linux-2.6.27.25/kernel/capability.c 2009-06-15 17:18:32.000000000 +0200
15389 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/capability.c    2009-02-03 17:59:04.000000000 +0100
15390 @@ -13,6 +13,7 @@
15391  #include <linux/security.h>
15392  #include <linux/syscalls.h>
15393  #include <linux/pid_namespace.h>
15394 +#include <linux/vs_context.h>
15395  #include <asm/uaccess.h>
15396  
15397  /*
15398 @@ -166,6 +167,8 @@ static inline int cap_set_pg(int pgrp_nr
15399  
15400         pgrp = find_vpid(pgrp_nr);
15401         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
15402 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
15403 +                       continue;
15404                 target = g;
15405                 while_each_thread(g, target) {
15406                         if (!security_capset_check(target, effective,
15407 @@ -486,6 +489,8 @@ SYSCALL_DEFINE2(capset, cap_user_header_
15408         return ret;
15409  }
15410  
15411 +#include <linux/vserver/base.h>
15412 +
15413  /**
15414   * capable - Determine if the current task has a superior capability in effect
15415   * @cap: The capability to be tested for
15416 @@ -498,6 +503,9 @@ SYSCALL_DEFINE2(capset, cap_user_header_
15417   */
15418  int capable(int cap)
15419  {
15420 +       /* here for now so we don't require task locking */
15421 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15422 +               return 0;
15423         if (has_capability(current, cap)) {
15424                 current->flags |= PF_SUPERPRIV;
15425                 return 1;
15426 diff -NurpP --minimal linux-2.6.27.25/kernel/compat.c linux-2.6.27.25-vs2.3.0.36.6/kernel/compat.c
15427 --- linux-2.6.27.25/kernel/compat.c     2008-07-13 23:51:29.000000000 +0200
15428 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/compat.c        2008-10-13 14:54:20.000000000 +0200
15429 @@ -845,7 +845,7 @@ asmlinkage long compat_sys_time(compat_t
15430         compat_time_t i;
15431         struct timeval tv;
15432  
15433 -       do_gettimeofday(&tv);
15434 +       vx_gettimeofday(&tv);
15435         i = tv.tv_sec;
15436  
15437         if (tloc) {
15438 @@ -869,7 +869,7 @@ asmlinkage long compat_sys_stime(compat_
15439         if (err)
15440                 return err;
15441  
15442 -       do_settimeofday(&tv);
15443 +       vx_settimeofday(&tv);
15444         return 0;
15445  }
15446  
15447 diff -NurpP --minimal linux-2.6.27.25/kernel/exit.c linux-2.6.27.25-vs2.3.0.36.6/kernel/exit.c
15448 --- linux-2.6.27.25/kernel/exit.c       2009-06-15 17:18:32.000000000 +0200
15449 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/exit.c  2009-05-15 22:57:04.000000000 +0200
15450 @@ -47,6 +47,11 @@
15451  #include <linux/blkdev.h>
15452  #include <linux/task_io_accounting_ops.h>
15453  #include <linux/tracehook.h>
15454 +#include <linux/vs_limit.h>
15455 +#include <linux/vs_context.h>
15456 +#include <linux/vs_network.h>
15457 +#include <linux/vs_pid.h>
15458 +#include <linux/vserver/global.h>
15459  
15460  #include <asm/uaccess.h>
15461  #include <asm/unistd.h>
15462 @@ -485,9 +490,11 @@ static void close_files(struct files_str
15463                                         filp_close(file, files);
15464                                         cond_resched();
15465                                 }
15466 +                               vx_openfd_dec(i);
15467                         }
15468                         i++;
15469                         set >>= 1;
15470 +                       cond_resched();
15471                 }
15472         }
15473  }
15474 @@ -554,6 +561,7 @@ void put_fs_struct(struct fs_struct *fs)
15475         if (atomic_dec_and_test(&fs->count)) {
15476                 path_put(&fs->root);
15477                 path_put(&fs->pwd);
15478 +               atomic_dec(&vs_global_fs);
15479                 kmem_cache_free(fs_cachep, fs);
15480         }
15481  }
15482 @@ -1121,11 +1129,16 @@ NORET_TYPE void do_exit(long code)
15483         if (tsk->splice_pipe)
15484                 __free_pipe_info(tsk->splice_pipe);
15485  
15486 +       /* needs to stay after exit_notify() */
15487 +       exit_vx_info(tsk, code);
15488 +       exit_nx_info(tsk);
15489 +
15490         preempt_disable();
15491         /* causes final put_task_struct in finish_task_switch(). */
15492         tsk->state = TASK_DEAD;
15493  
15494         schedule();
15495 +       printk("bad task: %p [%lx]\n", current, current->state);
15496         BUG();
15497         /* Avoid "noreturn function does return".  */
15498         for (;;)
15499 diff -NurpP --minimal linux-2.6.27.25/kernel/fork.c linux-2.6.27.25-vs2.3.0.36.6/kernel/fork.c
15500 --- linux-2.6.27.25/kernel/fork.c       2009-06-15 17:18:32.000000000 +0200
15501 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/fork.c  2009-03-25 14:32:29.000000000 +0100
15502 @@ -58,6 +58,11 @@
15503  #include <linux/tty.h>
15504  #include <linux/proc_fs.h>
15505  #include <linux/blkdev.h>
15506 +#include <linux/vs_context.h>
15507 +#include <linux/vs_network.h>
15508 +#include <linux/vs_limit.h>
15509 +#include <linux/vs_memory.h>
15510 +#include <linux/vserver/global.h>
15511  
15512  #include <asm/pgtable.h>
15513  #include <asm/pgalloc.h>
15514 @@ -135,6 +140,8 @@ void free_task(struct task_struct *tsk)
15515         prop_local_destroy_single(&tsk->dirties);
15516         free_thread_info(tsk->stack);
15517         rt_mutex_debug_task_free(tsk);
15518 +       clr_vx_info(&tsk->vx_info);
15519 +       clr_nx_info(&tsk->nx_info);
15520         free_task_struct(tsk);
15521  }
15522  EXPORT_SYMBOL(free_task);
15523 @@ -274,6 +281,8 @@ static int dup_mmap(struct mm_struct *mm
15524         mm->free_area_cache = oldmm->mmap_base;
15525         mm->cached_hole_size = ~0UL;
15526         mm->map_count = 0;
15527 +       __set_mm_counter(mm, file_rss, 0);
15528 +       __set_mm_counter(mm, anon_rss, 0);
15529         cpus_clear(mm->cpu_vm_mask);
15530         mm->mm_rb = RB_ROOT;
15531         rb_link = &mm->mm_rb.rb_node;
15532 @@ -285,7 +294,7 @@ static int dup_mmap(struct mm_struct *mm
15533  
15534                 if (mpnt->vm_flags & VM_DONTCOPY) {
15535                         long pages = vma_pages(mpnt);
15536 -                       mm->total_vm -= pages;
15537 +                       vx_vmpages_sub(mm, pages);
15538                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15539                                                                 -pages);
15540                         continue;
15541 @@ -407,8 +416,8 @@ static struct mm_struct * mm_init(struct
15542                                   : MMF_DUMP_FILTER_DEFAULT;
15543         mm->core_state = NULL;
15544         mm->nr_ptes = 0;
15545 -       set_mm_counter(mm, file_rss, 0);
15546 -       set_mm_counter(mm, anon_rss, 0);
15547 +       __set_mm_counter(mm, file_rss, 0);
15548 +       __set_mm_counter(mm, anon_rss, 0);
15549         spin_lock_init(&mm->page_table_lock);
15550         rwlock_init(&mm->ioctx_list_lock);
15551         mm->ioctx_list = NULL;
15552 @@ -419,6 +428,7 @@ static struct mm_struct * mm_init(struct
15553         if (likely(!mm_alloc_pgd(mm))) {
15554                 mm->def_flags = 0;
15555                 mmu_notifier_mm_init(mm);
15556 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15557                 return mm;
15558         }
15559  
15560 @@ -452,6 +462,7 @@ void __mmdrop(struct mm_struct *mm)
15561         mm_free_pgd(mm);
15562         destroy_context(mm);
15563         mmu_notifier_mm_destroy(mm);
15564 +       clr_vx_info(&mm->mm_vx_info);
15565         free_mm(mm);
15566  }
15567  EXPORT_SYMBOL_GPL(__mmdrop);
15568 @@ -568,6 +579,7 @@ struct mm_struct *dup_mm(struct task_str
15569                 goto fail_nomem;
15570  
15571         memcpy(mm, oldmm, sizeof(*mm));
15572 +       mm->mm_vx_info = NULL;
15573  
15574         /* Initializing for Swap token stuff */
15575         mm->token_priority = 0;
15576 @@ -601,6 +613,7 @@ fail_nocontext:
15577          * If init_new_context() failed, we cannot use mmput() to free the mm
15578          * because it calls destroy_context()
15579          */
15580 +       clr_vx_info(&mm->mm_vx_info);
15581         mm_free_pgd(mm);
15582         free_mm(mm);
15583         return NULL;
15584 @@ -664,6 +677,7 @@ static struct fs_struct *__copy_fs_struc
15585                 fs->pwd = old->pwd;
15586                 path_get(&old->pwd);
15587                 read_unlock(&old->lock);
15588 +               atomic_inc(&vs_global_fs);
15589         }
15590         return fs;
15591  }
15592 @@ -907,6 +921,8 @@ static struct task_struct *copy_process(
15593         int retval;
15594         struct task_struct *p;
15595         int cgroup_callbacks_done = 0;
15596 +       struct vx_info *vxi;
15597 +       struct nx_info *nxi;
15598  
15599         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15600                 return ERR_PTR(-EINVAL);
15601 @@ -941,12 +957,28 @@ static struct task_struct *copy_process(
15602         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15603         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15604  #endif
15605 +       init_vx_info(&p->vx_info, current->vx_info);
15606 +       init_nx_info(&p->nx_info, current->nx_info);
15607 +
15608 +       /* check vserver memory */
15609 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15610 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15611 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15612 +               else
15613 +                       goto bad_fork_free;
15614 +       }
15615 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15616 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15617 +                       goto bad_fork_cleanup_vm;
15618 +       }
15619         retval = -EAGAIN;
15620 +       if (!vx_nproc_avail(1))
15621 +               goto bad_fork_cleanup_vm;
15622         if (atomic_read(&p->user->processes) >=
15623                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15624                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15625                     p->user != current->nsproxy->user_ns->root_user)
15626 -                       goto bad_fork_free;
15627 +                       goto bad_fork_cleanup_vm;
15628         }
15629  
15630         atomic_inc(&p->user->__count);
15631 @@ -1243,6 +1275,18 @@ static struct task_struct *copy_process(
15632  
15633         total_forks++;
15634         spin_unlock(&current->sighand->siglock);
15635 +
15636 +       /* p is copy of current */
15637 +       vxi = p->vx_info;
15638 +       if (vxi) {
15639 +               claim_vx_info(vxi, p);
15640 +               atomic_inc(&vxi->cvirt.nr_threads);
15641 +               atomic_inc(&vxi->cvirt.total_forks);
15642 +               vx_nproc_inc(p);
15643 +       }
15644 +       nxi = p->nx_info;
15645 +       if (nxi)
15646 +               claim_nx_info(nxi, p);
15647         write_unlock_irq(&tasklist_lock);
15648         proc_fork_connector(p);
15649         cgroup_post_fork(p);
15650 @@ -1289,6 +1333,9 @@ bad_fork_cleanup_count:
15651         put_group_info(p->group_info);
15652         atomic_dec(&p->user->processes);
15653         free_uid(p->user);
15654 +bad_fork_cleanup_vm:
15655 +       if (p->mm && !(clone_flags & CLONE_VM))
15656 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15657  bad_fork_free:
15658         free_task(p);
15659  fork_out:
15660 diff -NurpP --minimal linux-2.6.27.25/kernel/kthread.c linux-2.6.27.25-vs2.3.0.36.6/kernel/kthread.c
15661 --- linux-2.6.27.25/kernel/kthread.c    2008-10-13 14:52:09.000000000 +0200
15662 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/kthread.c       2008-10-13 14:54:20.000000000 +0200
15663 @@ -13,6 +13,7 @@
15664  #include <linux/file.h>
15665  #include <linux/module.h>
15666  #include <linux/mutex.h>
15667 +#include <linux/vs_pid.h>
15668  
15669  #define KTHREAD_NICE_LEVEL (-5)
15670  
15671 @@ -98,7 +99,7 @@ static void create_kthread(struct kthrea
15672                 struct sched_param param = { .sched_priority = 0 };
15673                 wait_for_completion(&create->started);
15674                 read_lock(&tasklist_lock);
15675 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15676 +               create->result = find_task_by_real_pid(pid);
15677                 read_unlock(&tasklist_lock);
15678                 /*
15679                  * root may have changed our (kthreadd's) priority or CPU mask.
15680 diff -NurpP --minimal linux-2.6.27.25/kernel/Makefile linux-2.6.27.25-vs2.3.0.36.6/kernel/Makefile
15681 --- linux-2.6.27.25/kernel/Makefile     2009-06-15 17:18:32.000000000 +0200
15682 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/Makefile        2009-02-03 17:59:04.000000000 +0100
15683 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15684  CFLAGS_REMOVE_sched.o = -pg
15685  endif
15686  
15687 +obj-y += vserver/
15688  obj-$(CONFIG_PROFILING) += profile.o
15689  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15690  obj-$(CONFIG_STACKTRACE) += stacktrace.o
15691 diff -NurpP --minimal linux-2.6.27.25/kernel/nsproxy.c linux-2.6.27.25-vs2.3.0.36.6/kernel/nsproxy.c
15692 --- linux-2.6.27.25/kernel/nsproxy.c    2008-10-13 14:52:09.000000000 +0200
15693 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/nsproxy.c       2008-10-13 14:54:20.000000000 +0200
15694 @@ -19,6 +19,8 @@
15695  #include <linux/mnt_namespace.h>
15696  #include <linux/utsname.h>
15697  #include <linux/pid_namespace.h>
15698 +#include <linux/vserver/global.h>
15699 +#include <linux/vserver/debug.h>
15700  #include <net/net_namespace.h>
15701  #include <linux/ipc_namespace.h>
15702  
15703 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15704         if (ns) {
15705                 memcpy(ns, orig, sizeof(struct nsproxy));
15706                 atomic_set(&ns->count, 1);
15707 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15708 +                       orig, atomic_read(&orig->count), ns);
15709 +               atomic_inc(&vs_global_nsproxy);
15710         }
15711         return ns;
15712  }
15713 @@ -46,47 +51,51 @@ static inline struct nsproxy *clone_nspr
15714   * Return the newly created nsproxy.  Do not attach this to the task,
15715   * leave it to the caller to do proper locking and attach it to task.
15716   */
15717 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15718 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15719 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15720 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15721  {
15722         struct nsproxy *new_nsp;
15723         int err;
15724  
15725 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15726 +       vxdprintk(VXD_CBIT(space, 4),
15727 +               "unshare_namespaces(0x%08lx,%p,%p)",
15728 +               flags, orig, new_fs);
15729 +
15730 +       new_nsp = clone_nsproxy(orig);
15731         if (!new_nsp)
15732                 return ERR_PTR(-ENOMEM);
15733  
15734 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15735 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15736         if (IS_ERR(new_nsp->mnt_ns)) {
15737                 err = PTR_ERR(new_nsp->mnt_ns);
15738                 goto out_ns;
15739         }
15740  
15741 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15742 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15743         if (IS_ERR(new_nsp->uts_ns)) {
15744                 err = PTR_ERR(new_nsp->uts_ns);
15745                 goto out_uts;
15746         }
15747  
15748 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15749 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15750         if (IS_ERR(new_nsp->ipc_ns)) {
15751                 err = PTR_ERR(new_nsp->ipc_ns);
15752                 goto out_ipc;
15753         }
15754  
15755 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15756 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15757         if (IS_ERR(new_nsp->pid_ns)) {
15758                 err = PTR_ERR(new_nsp->pid_ns);
15759                 goto out_pid;
15760         }
15761  
15762 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
15763 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15764         if (IS_ERR(new_nsp->user_ns)) {
15765                 err = PTR_ERR(new_nsp->user_ns);
15766                 goto out_user;
15767         }
15768  
15769 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15770 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15771         if (IS_ERR(new_nsp->net_ns)) {
15772                 err = PTR_ERR(new_nsp->net_ns);
15773                 goto out_net;
15774 @@ -114,6 +123,37 @@ out_ns:
15775         return ERR_PTR(err);
15776  }
15777  
15778 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15779 +                       struct fs_struct *new_fs)
15780 +{
15781 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15782 +}
15783 +
15784 +/*
15785 + * copies the nsproxy, setting refcount to 1, and grabbing a
15786 + * reference to all contained namespaces.
15787 + */
15788 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15789 +{
15790 +       struct nsproxy *ns = clone_nsproxy(orig);
15791 +
15792 +       if (ns) {
15793 +               if (ns->mnt_ns)
15794 +                       get_mnt_ns(ns->mnt_ns);
15795 +               if (ns->uts_ns)
15796 +                       get_uts_ns(ns->uts_ns);
15797 +               if (ns->ipc_ns)
15798 +                       get_ipc_ns(ns->ipc_ns);
15799 +               if (ns->pid_ns)
15800 +                       get_pid_ns(ns->pid_ns);
15801 +               if (ns->user_ns)
15802 +                       get_user_ns(ns->user_ns);
15803 +               if (ns->net_ns)
15804 +                       get_net(ns->net_ns);
15805 +       }
15806 +       return ns;
15807 +}
15808 +
15809  /*
15810   * called from clone.  This now handles copy for nsproxy and all
15811   * namespaces therein.
15812 @@ -121,9 +161,12 @@ out_ns:
15813  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15814  {
15815         struct nsproxy *old_ns = tsk->nsproxy;
15816 -       struct nsproxy *new_ns;
15817 +       struct nsproxy *new_ns = NULL;
15818         int err = 0;
15819  
15820 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15821 +               flags, tsk, old_ns);
15822 +
15823         if (!old_ns)
15824                 return 0;
15825  
15826 @@ -160,6 +203,9 @@ int copy_namespaces(unsigned long flags,
15827  
15828  out:
15829         put_nsproxy(old_ns);
15830 +       vxdprintk(VXD_CBIT(space, 3),
15831 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15832 +               flags, tsk, old_ns, err, new_ns);
15833         return err;
15834  }
15835  
15836 @@ -175,7 +221,9 @@ void free_nsproxy(struct nsproxy *ns)
15837                 put_pid_ns(ns->pid_ns);
15838         if (ns->user_ns)
15839                 put_user_ns(ns->user_ns);
15840 -       put_net(ns->net_ns);
15841 +       if (ns->net_ns)
15842 +               put_net(ns->net_ns);
15843 +       atomic_dec(&vs_global_nsproxy);
15844         kmem_cache_free(nsproxy_cachep, ns);
15845  }
15846  
15847 @@ -188,6 +236,10 @@ int unshare_nsproxy_namespaces(unsigned 
15848  {
15849         int err = 0;
15850  
15851 +       vxdprintk(VXD_CBIT(space, 4),
15852 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15853 +               unshare_flags, current->nsproxy);
15854 +
15855         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15856                                CLONE_NEWUSER | CLONE_NEWNET)))
15857                 return 0;
15858 diff -NurpP --minimal linux-2.6.27.25/kernel/pid.c linux-2.6.27.25-vs2.3.0.36.6/kernel/pid.c
15859 --- linux-2.6.27.25/kernel/pid.c        2008-10-13 14:52:09.000000000 +0200
15860 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/pid.c   2008-10-13 14:54:20.000000000 +0200
15861 @@ -36,6 +36,8 @@
15862  #include <linux/pid_namespace.h>
15863  #include <linux/init_task.h>
15864  #include <linux/syscalls.h>
15865 +#include <linux/vs_pid.h>
15866 +#include <linux/vserver/global.h>
15867  
15868  #define pid_hashfn(nr, ns)     \
15869         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15870 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15871  
15872  struct pid *find_vpid(int nr)
15873  {
15874 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15875 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15876  }
15877  EXPORT_SYMBOL_GPL(find_vpid);
15878  
15879 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15880  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15881  {
15882         struct task_struct *result = NULL;
15883 +
15884 +       if (type == PIDTYPE_REALPID)
15885 +               type = PIDTYPE_PID;
15886         if (pid) {
15887                 struct hlist_node *first;
15888                 first = rcu_dereference(pid->tasks[type].first);
15889 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15890  
15891  struct task_struct *find_task_by_vpid(pid_t vnr)
15892  {
15893 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15894 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15895                         current->nsproxy->pid_ns);
15896  }
15897  EXPORT_SYMBOL(find_task_by_vpid);
15898  
15899  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15900  {
15901 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15902 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15903  }
15904  EXPORT_SYMBOL(find_task_by_pid_ns);
15905  
15906 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15907  }
15908  EXPORT_SYMBOL_GPL(find_get_pid);
15909  
15910 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15911 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15912  {
15913         struct upid *upid;
15914         pid_t nr = 0;
15915 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15916         return nr;
15917  }
15918  
15919 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15920 +{
15921 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15922 +}
15923 +
15924  pid_t pid_vnr(struct pid *pid)
15925  {
15926         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15927 diff -NurpP --minimal linux-2.6.27.25/kernel/pid_namespace.c linux-2.6.27.25-vs2.3.0.36.6/kernel/pid_namespace.c
15928 --- linux-2.6.27.25/kernel/pid_namespace.c      2008-10-13 14:52:09.000000000 +0200
15929 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/pid_namespace.c 2008-10-13 14:54:20.000000000 +0200
15930 @@ -13,6 +13,7 @@
15931  #include <linux/syscalls.h>
15932  #include <linux/err.h>
15933  #include <linux/acct.h>
15934 +#include <linux/vserver/global.h>
15935  
15936  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15937  
15938 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15939                 goto out_free_map;
15940  
15941         kref_init(&ns->kref);
15942 +       atomic_inc(&vs_global_pid_ns);
15943         ns->level = level;
15944  
15945         set_bit(0, ns->pidmap[0].page);
15946 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15947  
15948         for (i = 0; i < PIDMAP_ENTRIES; i++)
15949                 kfree(ns->pidmap[i].page);
15950 +       atomic_dec(&vs_global_pid_ns);
15951         kmem_cache_free(pid_ns_cachep, ns);
15952  }
15953  
15954 diff -NurpP --minimal linux-2.6.27.25/kernel/posix-timers.c linux-2.6.27.25-vs2.3.0.36.6/kernel/posix-timers.c
15955 --- linux-2.6.27.25/kernel/posix-timers.c       2009-06-15 17:18:32.000000000 +0200
15956 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/posix-timers.c  2009-02-03 17:59:04.000000000 +0100
15957 @@ -46,6 +46,7 @@
15958  #include <linux/wait.h>
15959  #include <linux/workqueue.h>
15960  #include <linux/module.h>
15961 +#include <linux/vs_context.h>
15962  
15963  /*
15964   * Management arrays for POSIX timers.  Timers are kept in slab memory
15965 @@ -298,6 +299,12 @@ void do_schedule_next_timer(struct sigin
15966  
15967  int posix_timer_event(struct k_itimer *timr, int si_private)
15968  {
15969 +       struct vx_info_save vxis;
15970 +       struct vx_info *vxi;
15971 +       int ret;
15972 +
15973 +       vxi = task_get_vx_info(timr->it_process);
15974 +       enter_vx_info(vxi, &vxis);
15975         /*
15976          * FIXME: if ->sigq is queued we can race with
15977          * dequeue_signal()->do_schedule_next_timer().
15978 @@ -318,10 +325,11 @@ int posix_timer_event(struct k_itimer *t
15979  
15980         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
15981                 struct task_struct *leader;
15982 -               int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15983 +
15984 +               ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15985  
15986                 if (likely(ret >= 0))
15987 -                       return ret;
15988 +                       goto out;
15989  
15990                 timr->it_sigev_notify = SIGEV_SIGNAL;
15991                 leader = timr->it_process->group_leader;
15992 @@ -329,7 +337,11 @@ int posix_timer_event(struct k_itimer *t
15993                 timr->it_process = leader;
15994         }
15995  
15996 -       return send_sigqueue(timr->sigq, timr->it_process, 1);
15997 +       ret = send_sigqueue(timr->sigq, timr->it_process, 1);
15998 +out:
15999 +       leave_vx_info(&vxis);
16000 +       put_vx_info(vxi);
16001 +       return ret;
16002  }
16003  EXPORT_SYMBOL_GPL(posix_timer_event);
16004  
16005 diff -NurpP --minimal linux-2.6.27.25/kernel/printk.c linux-2.6.27.25-vs2.3.0.36.6/kernel/printk.c
16006 --- linux-2.6.27.25/kernel/printk.c     2009-06-15 17:18:32.000000000 +0200
16007 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/printk.c        2009-02-03 17:59:04.000000000 +0100
16008 @@ -32,6 +32,7 @@
16009  #include <linux/security.h>
16010  #include <linux/bootmem.h>
16011  #include <linux/syscalls.h>
16012 +#include <linux/vs_cvirt.h>
16013  
16014  #include <asm/uaccess.h>
16015  
16016 @@ -291,18 +292,13 @@ int do_syslog(int type, char __user *buf
16017         unsigned i, j, limit, count;
16018         int do_clear = 0;
16019         char c;
16020 -       int error = 0;
16021 +       int error;
16022  
16023         error = security_syslog(type);
16024         if (error)
16025                 return error;
16026  
16027 -       switch (type) {
16028 -       case 0:         /* Close log */
16029 -               break;
16030 -       case 1:         /* Open log */
16031 -               break;
16032 -       case 2:         /* Read from log */
16033 +       if ((type >= 2) && (type <= 4)) {
16034                 error = -EINVAL;
16035                 if (!buf || len < 0)
16036                         goto out;
16037 @@ -313,6 +309,16 @@ int do_syslog(int type, char __user *buf
16038                         error = -EFAULT;
16039                         goto out;
16040                 }
16041 +       }
16042 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16043 +               return vx_do_syslog(type, buf, len);
16044 +
16045 +       switch (type) {
16046 +       case 0:         /* Close log */
16047 +               break;
16048 +       case 1:         /* Open log */
16049 +               break;
16050 +       case 2:         /* Read from log */
16051                 error = wait_event_interruptible(log_wait,
16052                                                         (log_start - log_end));
16053                 if (error)
16054 @@ -337,16 +343,6 @@ int do_syslog(int type, char __user *buf
16055                 do_clear = 1;
16056                 /* FALL THRU */
16057         case 3:         /* Read last kernel messages */
16058 -               error = -EINVAL;
16059 -               if (!buf || len < 0)
16060 -                       goto out;
16061 -               error = 0;
16062 -               if (!len)
16063 -                       goto out;
16064 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16065 -                       error = -EFAULT;
16066 -                       goto out;
16067 -               }
16068                 count = len;
16069                 if (count > log_buf_len)
16070                         count = log_buf_len;
16071 diff -NurpP --minimal linux-2.6.27.25/kernel/ptrace.c linux-2.6.27.25-vs2.3.0.36.6/kernel/ptrace.c
16072 --- linux-2.6.27.25/kernel/ptrace.c     2009-06-15 17:18:33.000000000 +0200
16073 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/ptrace.c        2009-02-03 17:59:04.000000000 +0100
16074 @@ -21,6 +21,7 @@
16075  #include <linux/audit.h>
16076  #include <linux/pid_namespace.h>
16077  #include <linux/syscalls.h>
16078 +#include <linux/vs_context.h>
16079  
16080  #include <asm/pgtable.h>
16081  #include <asm/uaccess.h>
16082 @@ -139,6 +140,11 @@ int __ptrace_may_access(struct task_stru
16083                 dumpable = get_dumpable(task->mm);
16084         if (!dumpable && !capable(CAP_SYS_PTRACE))
16085                 return -EPERM;
16086 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16087 +               return -EPERM;
16088 +       if (!vx_check(task->xid, VS_IDENT) &&
16089 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16090 +               return -EACCES;
16091  
16092         return security_ptrace_may_access(task, mode);
16093  }
16094 @@ -567,6 +573,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
16095                 goto out;
16096         }
16097  
16098 +       ret = -EPERM;
16099 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16100 +               goto out_put_task_struct;
16101 +
16102         if (request == PTRACE_ATTACH) {
16103                 ret = ptrace_attach(child);
16104                 /*
16105 diff -NurpP --minimal linux-2.6.27.25/kernel/sched.c linux-2.6.27.25-vs2.3.0.36.6/kernel/sched.c
16106 --- linux-2.6.27.25/kernel/sched.c      2009-06-15 17:18:33.000000000 +0200
16107 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sched.c 2009-03-09 15:36:36.000000000 +0100
16108 @@ -71,6 +71,8 @@
16109  #include <linux/debugfs.h>
16110  #include <linux/ctype.h>
16111  #include <linux/ftrace.h>
16112 +#include <linux/vs_sched.h>
16113 +#include <linux/vs_cvirt.h>
16114  
16115  #include <asm/tlb.h>
16116  #include <asm/irq_regs.h>
16117 @@ -577,6 +579,16 @@ struct rq {
16118  #endif
16119         struct hrtimer hrtick_timer;
16120  #endif
16121 +       unsigned long norm_time;
16122 +       unsigned long idle_time;
16123 +#ifdef CONFIG_VSERVER_IDLETIME
16124 +       int idle_skip;
16125 +#endif
16126 +#ifdef CONFIG_VSERVER_HARDCPU
16127 +       struct list_head hold_queue;
16128 +       unsigned long nr_onhold;
16129 +       int idle_tokens;
16130 +#endif
16131  
16132  #ifdef CONFIG_SCHEDSTATS
16133         /* latency stats */
16134 @@ -1640,6 +1652,7 @@ static void update_avg(u64 *avg, u64 sam
16135  
16136  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
16137  {
16138 +       // BUG_ON(p->state & TASK_ONHOLD);
16139         sched_info_queued(p);
16140         p->sched_class->enqueue_task(rq, p, wakeup);
16141         p->se.on_rq = 1;
16142 @@ -1763,6 +1776,8 @@ static inline void check_class_changed(s
16143                 p->sched_class->prio_changed(rq, p, oldprio, running);
16144  }
16145  
16146 +#include "sched_mon.h"
16147 +
16148  #ifdef CONFIG_SMP
16149  
16150  /* Used instead of source_load when we know the type == 0 */
16151 @@ -1846,6 +1861,7 @@ migrate_task(struct task_struct *p, int 
16152  {
16153         struct rq *rq = task_rq(p);
16154  
16155 +       vxm_migrate_task(p, rq, dest_cpu);
16156         /*
16157          * If the task is not on a runqueue (and not running), then
16158          * it is sufficient to simply update the task's cpu field.
16159 @@ -2178,6 +2194,8 @@ static int sched_balance_self(int cpu, i
16160  
16161  #endif /* CONFIG_SMP */
16162  
16163 +#include "sched_hard.h"
16164 +
16165  /***
16166   * try_to_wake_up - wake up a thread
16167   * @p: the to-be-woken-up thread
16168 @@ -2221,6 +2239,13 @@ static int try_to_wake_up(struct task_st
16169         smp_wmb();
16170         rq = task_rq_lock(p, &flags);
16171         old_state = p->state;
16172 +
16173 +       /* we need to unhold suspended tasks */
16174 +       if (old_state & TASK_ONHOLD) {
16175 +               vx_unhold_task(p, rq);
16176 +               old_state = p->state;
16177 +       }
16178 +
16179         if (!(old_state & state))
16180                 goto out;
16181  
16182 @@ -2242,6 +2267,12 @@ static int try_to_wake_up(struct task_st
16183                 /* might preempt at this point */
16184                 rq = task_rq_lock(p, &flags);
16185                 old_state = p->state;
16186 +
16187 +       /* we need to unhold suspended tasks
16188 +       if (old_state & TASK_ONHOLD) {
16189 +               vx_unhold_task(p, rq);
16190 +               old_state = p->state;
16191 +       } */
16192                 if (!(old_state & state))
16193                         goto out;
16194                 if (p->se.on_rq)
16195 @@ -4067,13 +4098,16 @@ unsigned long long task_sched_runtime(st
16196  void account_user_time(struct task_struct *p, cputime_t cputime)
16197  {
16198         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16199 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16200         cputime64_t tmp;
16201 +       int nice = (TASK_NICE(p) > 0);
16202  
16203         p->utime = cputime_add(p->utime, cputime);
16204 +       vx_account_user(vxi, cputime, nice);
16205  
16206         /* Add user time to cpustat. */
16207         tmp = cputime_to_cputime64(cputime);
16208 -       if (TASK_NICE(p) > 0)
16209 +       if (nice)
16210                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16211         else
16212                 cpustat->user = cputime64_add(cpustat->user, tmp);
16213 @@ -4120,6 +4154,7 @@ void account_system_time(struct task_str
16214                          cputime_t cputime)
16215  {
16216         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16217 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16218         struct rq *rq = this_rq();
16219         cputime64_t tmp;
16220  
16221 @@ -4129,6 +4164,7 @@ void account_system_time(struct task_str
16222         }
16223  
16224         p->stime = cputime_add(p->stime, cputime);
16225 +       vx_account_system(vxi, cputime, (p == rq->idle));
16226  
16227         /* Add system time to cpustat. */
16228         tmp = cputime_to_cputime64(cputime);
16229 @@ -4451,6 +4487,11 @@ need_resched_nonpreemptible:
16230                 idle_balance(cpu, rq);
16231  
16232         prev->sched_class->put_prev_task(rq, prev);
16233 +
16234 +       vx_set_rq_time(rq, jiffies);    /* update time */
16235 +       vx_schedule(prev, rq, cpu);     /* hold if over limit */
16236 +       vx_try_unhold(rq, cpu);         /* unhold if refilled */
16237 +
16238         next = pick_next_task(rq, prev);
16239  
16240         if (likely(prev != next)) {
16241 @@ -4963,7 +5004,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16242                 nice = 19;
16243  
16244         if (increment < 0 && !can_nice(current, nice))
16245 -               return -EPERM;
16246 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16247  
16248         retval = security_task_setnice(current, nice);
16249         if (retval)
16250 @@ -8173,7 +8214,10 @@ void __init sched_init(void)
16251  
16252  #endif
16253  #endif /* CONFIG_FAIR_GROUP_SCHED */
16254 -
16255 +#ifdef CONFIG_VSERVER_HARDCPU
16256 +               INIT_LIST_HEAD(&rq->hold_queue);
16257 +               rq->nr_onhold = 0;
16258 +#endif
16259                 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
16260  #ifdef CONFIG_RT_GROUP_SCHED
16261                 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
16262 diff -NurpP --minimal linux-2.6.27.25/kernel/sched_fair.c linux-2.6.27.25-vs2.3.0.36.6/kernel/sched_fair.c
16263 --- linux-2.6.27.25/kernel/sched_fair.c 2008-10-13 14:52:09.000000000 +0200
16264 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sched_fair.c    2008-10-13 14:54:20.000000000 +0200
16265 @@ -724,6 +724,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16266         check_spread(cfs_rq, se);
16267         if (se != cfs_rq->curr)
16268                 __enqueue_entity(cfs_rq, se);
16269 +
16270 +       if (entity_is_task(se))
16271 +               vx_activate_task(task_of(se));
16272  }
16273  
16274  static void
16275 @@ -750,6 +753,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16276  
16277         if (se != cfs_rq->curr)
16278                 __dequeue_entity(cfs_rq, se);
16279 +       if (entity_is_task(se))
16280 +               vx_deactivate_task(task_of(se));
16281         account_entity_dequeue(cfs_rq, se);
16282  }
16283  
16284 diff -NurpP --minimal linux-2.6.27.25/kernel/sched_hard.h linux-2.6.27.25-vs2.3.0.36.6/kernel/sched_hard.h
16285 --- linux-2.6.27.25/kernel/sched_hard.h 1970-01-01 01:00:00.000000000 +0100
16286 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sched_hard.h    2009-03-09 15:36:36.000000000 +0100
16287 @@ -0,0 +1,353 @@
16288 +
16289 +#ifdef CONFIG_VSERVER_IDLELIMIT
16290 +
16291 +/*
16292 + * vx_idle_resched - reschedule after maxidle
16293 + */
16294 +static inline
16295 +void vx_idle_resched(struct rq *rq)
16296 +{
16297 +       /* maybe have a better criterion for paused */
16298 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16299 +               set_need_resched();
16300 +}
16301 +
16302 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16303 +
16304 +#define vx_idle_resched(rq)
16305 +
16306 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16307 +
16308 +
16309 +
16310 +#ifdef CONFIG_VSERVER_IDLETIME
16311 +
16312 +#define vx_set_rq_min_skip(rq, min)            \
16313 +       (rq)->idle_skip = (min)
16314 +
16315 +#define vx_save_min_skip(ret, min, val)                \
16316 +       __vx_save_min_skip(ret, min, val)
16317 +
16318 +static inline
16319 +void __vx_save_min_skip(int ret, int *min, int val)
16320 +{
16321 +       if (ret > -2)
16322 +               return;
16323 +       if ((*min > val) || !*min)
16324 +               *min = val;
16325 +}
16326 +
16327 +static inline
16328 +int vx_try_skip(struct rq *rq, int cpu)
16329 +{
16330 +       /* artificially advance time */
16331 +       if (rq->idle_skip > 0) {
16332 +               vxdprintk(list_empty(&rq->hold_queue),
16333 +                       "hold queue empty on cpu %d", cpu);
16334 +               rq->idle_time += rq->idle_skip;
16335 +               vxm_idle_skip(rq, cpu);
16336 +               return 1;
16337 +       }
16338 +       return 0;
16339 +}
16340 +
16341 +#else /* !CONFIG_VSERVER_IDLETIME */
16342 +
16343 +#define vx_set_rq_min_skip(rq, min)            \
16344 +       ({ int dummy = (min); dummy; })
16345 +
16346 +#define vx_save_min_skip(ret, min, val)
16347 +
16348 +static inline
16349 +int vx_try_skip(struct rq *rq, int cpu)
16350 +{
16351 +       return 0;
16352 +}
16353 +
16354 +#endif /* CONFIG_VSERVER_IDLETIME */
16355 +
16356 +
16357 +
16358 +#ifdef CONFIG_VSERVER_HARDCPU
16359 +
16360 +#define vx_set_rq_max_idle(rq, max)            \
16361 +       (rq)->idle_tokens = (max)
16362 +
16363 +#define vx_save_max_idle(ret, min, val)                \
16364 +       __vx_save_max_idle(ret, min, val)
16365 +
16366 +static inline
16367 +void __vx_save_max_idle(int ret, int *min, int val)
16368 +{
16369 +       if (*min > val)
16370 +               *min = val;
16371 +}
16372 +
16373 +
16374 +/*
16375 + * vx_hold_task - put a task on the hold queue
16376 + */
16377 +static inline
16378 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16379 +{
16380 +       // printk("@ hold_task(%p[%lx])\n", p, p->state);
16381 +
16382 +       /* ignore dead/killed tasks */
16383 +       if (unlikely(p->state & (TASK_DEAD | TASK_WAKEKILL)))
16384 +               return;
16385 +
16386 +       /* ignore sleeping tasks */
16387 +       if (unlikely(p->state & TASK_NORMAL))
16388 +               return;
16389 +
16390 +       /* remove task from runqueue */
16391 +       if (likely(p->se.on_rq))
16392 +               dequeue_task(rq, p, 0);
16393 +       else
16394 +               printk("@ woops, task %p not on runqueue?\n", p);
16395 +
16396 +       p->state |= TASK_ONHOLD;
16397 +       /* a new one on hold */
16398 +       rq->nr_onhold++;
16399 +       vxm_hold_task(p, rq);
16400 +       list_add_tail(&p->hq, &rq->hold_queue);
16401 +       // list_add_tail(&p->run_list, &rq->hold_queue);
16402 +}
16403 +
16404 +/*
16405 + * vx_unhold_task - put a task back to the runqueue
16406 + */
16407 +static inline
16408 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16409 +{
16410 +       // printk("@ unhold_task(%p[%lx])\n", p, p->state);
16411 +       list_del_init(&p->hq);
16412 +       // list_del(&p->run_list);
16413 +       /* one less waiting */
16414 +       rq->nr_onhold--;
16415 +       p->state &= ~TASK_ONHOLD;
16416 +       enqueue_task(rq, p, 0);
16417 +       // ? inc_nr_running(p, rq);
16418 +       vxm_unhold_task(p, rq);
16419 +}
16420 +
16421 +/*
16422 + * vx_remove_hold - remove a task from the hold queue
16423 + */
16424 +static inline
16425 +void vx_remove_hold(struct task_struct *p, struct rq *rq)
16426 +{
16427 +       printk("@ remove_hold(%p[%lx])\n", p, p->state);
16428 +       list_del_init(&p->hq);
16429 +       // list_del(&p->run_list);
16430 +       /* one less waiting */
16431 +       rq->nr_onhold--;
16432 +       p->state &= ~TASK_ONHOLD;
16433 +}
16434 +
16435 +unsigned long nr_onhold(void)
16436 +{
16437 +       unsigned long i, sum = 0;
16438 +
16439 +       for_each_online_cpu(i)
16440 +               sum += cpu_rq(i)->nr_onhold;
16441 +
16442 +       return sum;
16443 +}
16444 +
16445 +
16446 +
16447 +static inline
16448 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16449 +{
16450 +       return sched_pc->tokens;
16451 +}
16452 +
16453 +static inline
16454 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16455 +{
16456 +       sched_pc->tokens--;
16457 +}
16458 +
16459 +static inline
16460 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16461 +{
16462 +       struct vx_info *vxi = p->vx_info;
16463 +
16464 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16465 +               struct _vx_sched_pc *sched_pc =
16466 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16467 +               int tokens;
16468 +
16469 +               /* maybe we can simplify that to decrement
16470 +                  the token counter unconditional? */
16471 +
16472 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16473 +                       __vx_consume_token(sched_pc);
16474 +
16475 +               /* for tokens > 0, one token was consumed */
16476 +               if (tokens < 2)
16477 +                       slice = 0;
16478 +       }
16479 +       vxm_need_resched(p, slice, cpu);
16480 +       return (slice == 0);
16481 +}
16482 +
16483 +
16484 +#define vx_set_rq_time(rq, time) do {  \
16485 +       rq->norm_time = time;           \
16486 +} while (0)
16487 +
16488 +
16489 +static inline
16490 +void vx_try_unhold(struct rq *rq, int cpu)
16491 +{
16492 +       struct vx_info *vxi = NULL;
16493 +       struct list_head *l, *n;
16494 +       int maxidle = HZ;
16495 +       int minskip = 0;
16496 +
16497 +       /* nothing to do? what about pause? */
16498 +       if (list_empty(&rq->hold_queue))
16499 +               return;
16500 +
16501 +       list_for_each_safe(l, n, &rq->hold_queue) {
16502 +               int ret, delta_min[2];
16503 +               struct _vx_sched_pc *sched_pc;
16504 +               struct task_struct *p;
16505 +
16506 +               p = list_entry(l, struct task_struct, hq);
16507 +               /* don't bother with same context */
16508 +               if (vxi == p->vx_info)
16509 +                       continue;
16510 +
16511 +               vxi = p->vx_info;
16512 +               /* ignore paused contexts */
16513 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16514 +                       continue;
16515 +
16516 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16517 +
16518 +               /* recalc tokens */
16519 +               vxm_sched_info(sched_pc, vxi, cpu);
16520 +               ret = vx_tokens_recalc(sched_pc,
16521 +                       &rq->norm_time, &rq->idle_time, delta_min);
16522 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16523 +
16524 +               if (ret > 0) {
16525 +                       /* we found a runable context */
16526 +                       vx_unhold_task(p, rq);
16527 +                       break;
16528 +               }
16529 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16530 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16531 +       }
16532 +       vx_set_rq_max_idle(rq, maxidle);
16533 +       vx_set_rq_min_skip(rq, minskip);
16534 +       vxm_rq_max_min(rq, cpu);
16535 +}
16536 +
16537 +
16538 +static inline
16539 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16540 +{
16541 +       struct vx_info *vxi = next->vx_info;
16542 +       struct _vx_sched_pc *sched_pc;
16543 +       int delta_min[2];
16544 +       int flags, ret;
16545 +
16546 +       if (!vxi)
16547 +               return 1;
16548 +
16549 +       flags = vxi->vx_flags;
16550 +
16551 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16552 +               goto put_on_hold;
16553 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16554 +               return 1;
16555 +
16556 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16557 +#ifdef CONFIG_SMP
16558 +       /* update scheduler params */
16559 +       if (cpu_isset(cpu, vxi->sched.update)) {
16560 +               vx_update_sched_param(&vxi->sched, sched_pc);
16561 +               vxm_update_sched(sched_pc, vxi, cpu);
16562 +               cpu_clear(cpu, vxi->sched.update);
16563 +       }
16564 +#endif
16565 +       vxm_sched_info(sched_pc, vxi, cpu);
16566 +       ret  = vx_tokens_recalc(sched_pc,
16567 +               &rq->norm_time, &rq->idle_time, delta_min);
16568 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16569 +
16570 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16571 +               return 1;
16572 +
16573 +       if (unlikely(ret < 0)) {
16574 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16575 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16576 +               vxm_rq_max_min(rq, cpu);
16577 +       put_on_hold:
16578 +               vx_hold_task(next, rq);
16579 +               return 0;
16580 +       }
16581 +       return 1;
16582 +}
16583 +
16584 +
16585 +#else /* CONFIG_VSERVER_HARDCPU */
16586 +
16587 +static inline
16588 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16589 +{
16590 +       return;
16591 +}
16592 +
16593 +static inline
16594 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16595 +{
16596 +       return;
16597 +}
16598 +
16599 +unsigned long nr_onhold(void)
16600 +{
16601 +       return 0;
16602 +}
16603 +
16604 +
16605 +static inline
16606 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16607 +{
16608 +       return (slice == 0);
16609 +}
16610 +
16611 +
16612 +#define vx_set_rq_time(rq, time)
16613 +
16614 +static inline
16615 +void vx_try_unhold(struct rq *rq, int cpu)
16616 +{
16617 +       return;
16618 +}
16619 +
16620 +static inline
16621 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16622 +{
16623 +       struct vx_info *vxi = next->vx_info;
16624 +       struct _vx_sched_pc *sched_pc;
16625 +       int delta_min[2];
16626 +       int ret;
16627 +
16628 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16629 +               return 1;
16630 +
16631 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16632 +       vxm_sched_info(sched_pc, vxi, cpu);
16633 +       ret  = vx_tokens_recalc(sched_pc,
16634 +               &rq->norm_time, &rq->idle_time, delta_min);
16635 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16636 +       return 1;
16637 +}
16638 +
16639 +#endif /* CONFIG_VSERVER_HARDCPU */
16640 +
16641 diff -NurpP --minimal linux-2.6.27.25/kernel/sched_mon.h linux-2.6.27.25-vs2.3.0.36.6/kernel/sched_mon.h
16642 --- linux-2.6.27.25/kernel/sched_mon.h  1970-01-01 01:00:00.000000000 +0100
16643 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sched_mon.h     2008-10-13 14:54:20.000000000 +0200
16644 @@ -0,0 +1,200 @@
16645 +
16646 +#include <linux/vserver/monitor.h>
16647 +
16648 +#ifdef  CONFIG_VSERVER_MONITOR
16649 +
16650 +#ifdef CONFIG_VSERVER_HARDCPU
16651 +#define HARDCPU(x) (x)
16652 +#else
16653 +#define HARDCPU(x) (0)
16654 +#endif
16655 +
16656 +#ifdef CONFIG_VSERVER_IDLETIME
16657 +#define IDLETIME(x) (x)
16658 +#else
16659 +#define IDLETIME(x) (0)
16660 +#endif
16661 +
16662 +struct _vx_mon_entry *vxm_advance(int cpu);
16663 +
16664 +
16665 +static inline
16666 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16667 +{
16668 +       entry->type = type;
16669 +       entry->xid = xid;
16670 +}
16671 +
16672 +static inline
16673 +void   __vxm_sync(int cpu)
16674 +{
16675 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16676 +
16677 +       __vxm_basic(entry, 0, VXM_SYNC);
16678 +       entry->ev.sec = xtime.tv_sec;
16679 +       entry->ev.nsec = xtime.tv_nsec;
16680 +}
16681 +
16682 +static inline
16683 +void   __vxm_task(struct task_struct *p, int type)
16684 +{
16685 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16686 +
16687 +       __vxm_basic(entry, p->xid, type);
16688 +       entry->ev.tsk.pid = p->pid;
16689 +       entry->ev.tsk.state = p->state;
16690 +}
16691 +
16692 +static inline
16693 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16694 +{
16695 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16696 +
16697 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16698 +       entry->sd.tokens = s->tokens;
16699 +       entry->sd.norm_time = s->norm_time;
16700 +       entry->sd.idle_time = s->idle_time;
16701 +}
16702 +
16703 +static inline
16704 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16705 +{
16706 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16707 +
16708 +       entry->type = VXM_RQINFO_1;
16709 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16710 +       entry->q1.running = q->nr_running;
16711 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16712 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16713 +       entry->q1.uintr = q->nr_uninterruptible;
16714 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16715 +}
16716 +
16717 +static inline
16718 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16719 +{
16720 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16721 +
16722 +       entry->type = VXM_RQINFO_2;
16723 +       entry->xid = (unsigned long)q & 0xffff;
16724 +       entry->q2.norm_time = q->norm_time;
16725 +       entry->q2.idle_time = q->idle_time;
16726 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16727 +}
16728 +
16729 +static inline
16730 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16731 +{
16732 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16733 +
16734 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16735 +       entry->ev.tokens = s->tokens;
16736 +}
16737 +
16738 +static inline
16739 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16740 +{
16741 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16742 +
16743 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16744 +       entry->u1.tokens_max = s->tokens_max;
16745 +       entry->u1.fill_rate = s->fill_rate[0];
16746 +       entry->u1.interval = s->interval[0];
16747 +}
16748 +
16749 +static inline
16750 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16751 +{
16752 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16753 +
16754 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16755 +       entry->u2.tokens_min = s->tokens_min;
16756 +       entry->u2.fill_rate = s->fill_rate[1];
16757 +       entry->u2.interval = s->interval[1];
16758 +}
16759 +
16760 +
16761 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16762 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16763 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16764 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16765 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16766 +
16767 +static inline
16768 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16769 +{
16770 +       __vxm_task(p, VXM_MIGRATE);
16771 +       __vxm_rqinfo1(rq, task_cpu(p));
16772 +       __vxm_rqinfo2(rq, task_cpu(p));
16773 +}
16774 +
16775 +static inline
16776 +void   vxm_idle_skip(struct rq *rq, int cpu)
16777 +{
16778 +       __vxm_rqinfo1(rq, cpu);
16779 +       __vxm_rqinfo2(rq, cpu);
16780 +}
16781 +
16782 +static inline
16783 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16784 +{
16785 +       if (slice)
16786 +               return;
16787 +
16788 +       __vxm_task(p, VXM_RESCHED);
16789 +}
16790 +
16791 +static inline
16792 +void   vxm_sync(unsigned long now, int cpu)
16793 +{
16794 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16795 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16796 +               return;
16797 +
16798 +       __vxm_sync(cpu);
16799 +}
16800 +
16801 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16802 +
16803 +static inline
16804 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16805 +       struct vx_info *vxi, int cpu)
16806 +{
16807 +       __vxm_sched(s, vxi, cpu);
16808 +       __vxm_rqinfo2(rq, cpu);
16809 +}
16810 +
16811 +static inline
16812 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16813 +{
16814 +       __vxm_sched(s, vxi, cpu);
16815 +       __vxm_update(s, vxi, cpu);
16816 +       __vxm_update1(s, vxi, cpu);
16817 +       __vxm_update2(s, vxi, cpu);
16818 +}
16819 +
16820 +static inline
16821 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16822 +{
16823 +       __vxm_rqinfo1(rq, cpu);
16824 +       __vxm_rqinfo2(rq, cpu);
16825 +}
16826 +
16827 +#else  /* CONFIG_VSERVER_MONITOR */
16828 +
16829 +#define        vxm_activate_task(t,q)          do { } while (0)
16830 +#define        vxm_activate_idle(t,q)          do { } while (0)
16831 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16832 +#define        vxm_hold_task(t,q)              do { } while (0)
16833 +#define        vxm_unhold_task(t,q)            do { } while (0)
16834 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16835 +#define        vxm_idle_skip(q,c)              do { } while (0)
16836 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16837 +#define        vxm_sync(s,c)                   do { } while (0)
16838 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16839 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16840 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16841 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16842 +
16843 +#endif /* CONFIG_VSERVER_MONITOR */
16844 +
16845 diff -NurpP --minimal linux-2.6.27.25/kernel/signal.c linux-2.6.27.25-vs2.3.0.36.6/kernel/signal.c
16846 --- linux-2.6.27.25/kernel/signal.c     2009-06-15 17:18:33.000000000 +0200
16847 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/signal.c        2009-05-15 22:57:04.000000000 +0200
16848 @@ -27,6 +27,8 @@
16849  #include <linux/freezer.h>
16850  #include <linux/pid_namespace.h>
16851  #include <linux/nsproxy.h>
16852 +#include <linux/vs_context.h>
16853 +#include <linux/vs_pid.h>
16854  
16855  #include <asm/param.h>
16856  #include <asm/uaccess.h>
16857 @@ -571,6 +573,14 @@ static int check_kill_permission(int sig
16858         if (!valid_signal(sig))
16859                 return -EINVAL;
16860  
16861 +       if ((info != SEND_SIG_NOINFO) &&
16862 +               (is_si_special(info) || !SI_FROMUSER(info)))
16863 +               goto skip;
16864 +
16865 +       vxdprintk(VXD_CBIT(misc, 7),
16866 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16867 +               sig, info, t, vx_task_xid(t), t->pid);
16868 +
16869         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16870                 return 0;
16871  
16872 @@ -595,6 +605,18 @@ static int check_kill_permission(int sig
16873                 }
16874         }
16875  
16876 +       error = -EPERM;
16877 +       if (t->pid == 1 && current->xid)
16878 +               return error;
16879 +
16880 +       error = -ESRCH;
16881 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16882 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16883 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16884 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16885 +               return error;
16886 +       }
16887 +skip:
16888         return security_task_kill(t, info, sig, 0);
16889  }
16890  
16891 @@ -1051,7 +1073,7 @@ int kill_pid_info(int sig, struct siginf
16892         rcu_read_lock();
16893  retry:
16894         p = pid_task(pid, PIDTYPE_PID);
16895 -       if (p) {
16896 +       if (p && vx_check(vx_task_xid(p), VS_ADMIN | VS_IDENT)) {
16897                 error = group_send_sig_info(sig, info, p);
16898                 if (unlikely(error == -ESRCH))
16899                         /*
16900 @@ -1089,7 +1111,7 @@ int kill_pid_info_as_uid(int sig, struct
16901  
16902         read_lock(&tasklist_lock);
16903         p = pid_task(pid, PIDTYPE_PID);
16904 -       if (!p) {
16905 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16906                 ret = -ESRCH;
16907                 goto out_unlock;
16908         }
16909 @@ -1141,8 +1163,10 @@ static int kill_something_info(int sig, 
16910                 struct task_struct * p;
16911  
16912                 for_each_process(p) {
16913 -                       if (task_pid_vnr(p) > 1 &&
16914 -                                       !same_thread_group(p, current)) {
16915 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16916 +                               task_pid_vnr(p) > 1 &&
16917 +                               !same_thread_group(p, current) &&
16918 +                               !vx_current_initpid(p->pid)) {
16919                                 int err = group_send_sig_info(sig, info, p);
16920                                 ++count;
16921                                 if (err != -EPERM)
16922 @@ -1823,6 +1847,11 @@ relock:
16923                     !signal_group_exit(signal))
16924                         continue;
16925  
16926 +               /* virtual init is protected against user signals */
16927 +               if ((info->si_code == SI_USER) &&
16928 +                       vx_current_initpid(current->pid))
16929 +                       continue;
16930 +
16931                 if (sig_kernel_stop(signr)) {
16932                         /*
16933                          * The default action is to stop all threads in
16934 diff -NurpP --minimal linux-2.6.27.25/kernel/softirq.c linux-2.6.27.25-vs2.3.0.36.6/kernel/softirq.c
16935 --- linux-2.6.27.25/kernel/softirq.c    2008-10-13 14:52:09.000000000 +0200
16936 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/softirq.c       2008-10-13 14:54:20.000000000 +0200
16937 @@ -21,6 +21,7 @@
16938  #include <linux/rcupdate.h>
16939  #include <linux/smp.h>
16940  #include <linux/tick.h>
16941 +#include <linux/vs_context.h>
16942  
16943  #include <asm/irq.h>
16944  /*
16945 diff -NurpP --minimal linux-2.6.27.25/kernel/sys.c linux-2.6.27.25-vs2.3.0.36.6/kernel/sys.c
16946 --- linux-2.6.27.25/kernel/sys.c        2009-06-15 17:18:33.000000000 +0200
16947 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sys.c   2009-02-03 17:59:04.000000000 +0100
16948 @@ -38,6 +38,7 @@
16949  #include <linux/syscalls.h>
16950  #include <linux/kprobes.h>
16951  #include <linux/user_namespace.h>
16952 +#include <linux/vs_pid.h>
16953  
16954  #include <asm/uaccess.h>
16955  #include <asm/io.h>
16956 @@ -122,7 +123,10 @@ static int set_one_prio(struct task_stru
16957                 goto out;
16958         }
16959         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16960 -               error = -EACCES;
16961 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16962 +                       error = 0;
16963 +               else
16964 +                       error = -EACCES;
16965                 goto out;
16966         }
16967         no_nice = security_task_setnice(p, niceval);
16968 @@ -170,6 +174,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16969                         else
16970                                 pgrp = task_pgrp(current);
16971                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16972 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16973 +                                       continue;
16974                                 error = set_one_prio(p, niceval, error);
16975                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16976                         break;
16977 @@ -230,6 +236,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16978                         else
16979                                 pgrp = task_pgrp(current);
16980                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16981 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16982 +                                       continue;
16983                                 niceval = 20 - task_nice(p);
16984                                 if (niceval > retval)
16985                                         retval = niceval;
16986 @@ -339,6 +347,9 @@ void kernel_power_off(void)
16987         machine_power_off();
16988  }
16989  EXPORT_SYMBOL_GPL(kernel_power_off);
16990 +
16991 +long vs_reboot(unsigned int, void __user *);
16992 +
16993  /*
16994   * Reboot system call: for obvious reasons only root may call it,
16995   * and even root needs to set up some magic numbers in the registers
16996 @@ -370,6 +381,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16997         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16998                 cmd = LINUX_REBOOT_CMD_HALT;
16999  
17000 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17001 +               return vs_reboot(cmd, arg);
17002 +
17003         lock_kernel();
17004         switch (cmd) {
17005         case LINUX_REBOOT_CMD_RESTART:
17006 @@ -1345,7 +1359,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17007         int errno;
17008         char tmp[__NEW_UTS_LEN];
17009  
17010 -       if (!capable(CAP_SYS_ADMIN))
17011 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17012                 return -EPERM;
17013         if (len < 0 || len > __NEW_UTS_LEN)
17014                 return -EINVAL;
17015 @@ -1390,7 +1404,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17016         int errno;
17017         char tmp[__NEW_UTS_LEN];
17018  
17019 -       if (!capable(CAP_SYS_ADMIN))
17020 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17021                 return -EPERM;
17022         if (len < 0 || len > __NEW_UTS_LEN)
17023                 return -EINVAL;
17024 @@ -1458,7 +1472,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17025                 return -EINVAL;
17026         old_rlim = current->signal->rlim + resource;
17027         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17028 -           !capable(CAP_SYS_RESOURCE))
17029 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17030                 return -EPERM;
17031         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17032                 return -EPERM;
17033 diff -NurpP --minimal linux-2.6.27.25/kernel/sysctl.c linux-2.6.27.25-vs2.3.0.36.6/kernel/sysctl.c
17034 --- linux-2.6.27.25/kernel/sysctl.c     2009-06-15 17:18:33.000000000 +0200
17035 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sysctl.c        2009-02-03 17:59:04.000000000 +0100
17036 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
17037  #ifdef CONFIG_MODULES
17038  extern char modprobe_path[];
17039  #endif
17040 +extern char vshelper_path[];
17041  #ifdef CONFIG_CHR_DEV_SG
17042  extern int sg_big_buff;
17043  #endif
17044 @@ -503,6 +504,15 @@ static struct ctl_table kern_table[] = {
17045                 .strategy       = &sysctl_string,
17046         },
17047  #endif
17048 +       {
17049 +               .ctl_name       = KERN_VSHELPER,
17050 +               .procname       = "vshelper",
17051 +               .data           = &vshelper_path,
17052 +               .maxlen         = 256,
17053 +               .mode           = 0644,
17054 +               .proc_handler   = &proc_dostring,
17055 +               .strategy       = &sysctl_string,
17056 +       },
17057  #ifdef CONFIG_CHR_DEV_SG
17058         {
17059                 .ctl_name       = KERN_SG_BIG_BUFF,
17060 diff -NurpP --minimal linux-2.6.27.25/kernel/sysctl_check.c linux-2.6.27.25-vs2.3.0.36.6/kernel/sysctl_check.c
17061 --- linux-2.6.27.25/kernel/sysctl_check.c       2008-10-13 14:52:09.000000000 +0200
17062 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/sysctl_check.c  2008-10-13 14:54:20.000000000 +0200
17063 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17064  
17065         { KERN_PANIC,                   "panic" },
17066         { KERN_REALROOTDEV,             "real-root-dev" },
17067 +       { KERN_VSHELPER,                "vshelper", },
17068  
17069         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17070         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17071 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
17072         {}
17073  };
17074  
17075 +static struct trans_ctl_table trans_vserver_table[] = {
17076 +       { 1,    "debug_switch" },
17077 +       { 2,    "debug_xid" },
17078 +       { 3,    "debug_nid" },
17079 +       { 4,    "debug_tag" },
17080 +       { 5,    "debug_net" },
17081 +       { 6,    "debug_limit" },
17082 +       { 7,    "debug_cres" },
17083 +       { 8,    "debug_dlim" },
17084 +       { 9,    "debug_quota" },
17085 +       { 10,   "debug_cvirt" },
17086 +       { 11,   "debug_space" },
17087 +       { 12,   "debug_misc" },
17088 +       {}
17089 +};
17090 +
17091  static const struct trans_ctl_table trans_root_table[] = {
17092         { CTL_KERN,     "kernel",       trans_kern_table },
17093         { CTL_VM,       "vm",           trans_vm_table },
17094 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
17095         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17096         { CTL_PM,       "pm",           trans_pm_table },
17097         { CTL_FRV,      "frv",          trans_frv_table },
17098 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17099         {}
17100  };
17101  
17102 diff -NurpP --minimal linux-2.6.27.25/kernel/time.c linux-2.6.27.25-vs2.3.0.36.6/kernel/time.c
17103 --- linux-2.6.27.25/kernel/time.c       2009-06-15 17:18:33.000000000 +0200
17104 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/time.c  2009-02-03 17:59:04.000000000 +0100
17105 @@ -62,6 +62,7 @@ EXPORT_SYMBOL(sys_tz);
17106  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17107  {
17108         time_t i = get_seconds();
17109 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17110  
17111         if (tloc) {
17112                 if (put_user(i,tloc))
17113 @@ -91,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17114         if (err)
17115                 return err;
17116  
17117 -       do_settimeofday(&tv);
17118 +       vx_settimeofday(&tv);
17119         return 0;
17120  }
17121  
17122 @@ -102,7 +103,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17123  {
17124         if (likely(tv != NULL)) {
17125                 struct timeval ktv;
17126 -               do_gettimeofday(&ktv);
17127 +               vx_gettimeofday(&ktv);
17128                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17129                         return -EFAULT;
17130         }
17131 @@ -177,7 +178,7 @@ int do_sys_settimeofday(struct timespec 
17132                 /* SMP safe, again the code in arch/foo/time.c should
17133                  * globally block out interrupts when it runs.
17134                  */
17135 -               return do_settimeofday(tv);
17136 +               return vx_settimeofday(tv);
17137         }
17138         return 0;
17139  }
17140 @@ -309,7 +310,7 @@ void getnstimeofday(struct timespec *tv)
17141  {
17142         struct timeval x;
17143  
17144 -       do_gettimeofday(&x);
17145 +       vx_gettimeofday(&x);
17146         tv->tv_sec = x.tv_sec;
17147         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17148  }
17149 diff -NurpP --minimal linux-2.6.27.25/kernel/timer.c linux-2.6.27.25-vs2.3.0.36.6/kernel/timer.c
17150 --- linux-2.6.27.25/kernel/timer.c      2009-06-15 17:18:33.000000000 +0200
17151 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/timer.c 2009-03-09 15:36:36.000000000 +0100
17152 @@ -37,6 +37,10 @@
17153  #include <linux/delay.h>
17154  #include <linux/tick.h>
17155  #include <linux/kallsyms.h>
17156 +#include <linux/vs_base.h>
17157 +#include <linux/vs_cvirt.h>
17158 +#include <linux/vs_pid.h>
17159 +#include <linux/vserver/sched.h>
17160  
17161  #include <asm/uaccess.h>
17162  #include <asm/unistd.h>
17163 @@ -964,6 +968,25 @@ void account_process_tick(struct task_st
17164  }
17165  #endif
17166  
17167 +static inline
17168 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
17169 +{
17170 +       sched_pc->tokens--;
17171 +}
17172 +
17173 +static inline
17174 +void vx_hard_tick(struct task_struct *p, int cpu)
17175 +{
17176 +       struct vx_info *vxi = p->vx_info;
17177 +
17178 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
17179 +               struct _vx_sched_pc *sched_pc =
17180 +                       &vx_per_cpu(vxi, sched_pc, cpu);
17181 +
17182 +               __vx_consume_token(sched_pc);
17183 +       }
17184 +}
17185 +
17186  /*
17187   * Called from the timer interrupt handler to charge one tick to the current
17188   * process.  user_tick is 1 if the tick is user time, 0 for system.
17189 @@ -979,6 +1002,7 @@ void update_process_times(int user_tick)
17190         if (rcu_pending(cpu))
17191                 rcu_check_callbacks(cpu, user_tick);
17192         scheduler_tick();
17193 +       vx_hard_tick(p, cpu);
17194         run_posix_cpu_timers(p);
17195  }
17196  
17197 @@ -1081,12 +1105,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17198  
17199  #endif
17200  
17201 -#ifndef __alpha__
17202 -
17203 -/*
17204 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17205 - * should be moved into arch/i386 instead?
17206 - */
17207  
17208  /**
17209   * sys_getpid - return the thread group id of the current process
17210 @@ -1115,10 +1133,23 @@ SYSCALL_DEFINE0(getppid)
17211         rcu_read_lock();
17212         pid = task_tgid_vnr(current->real_parent);
17213         rcu_read_unlock();
17214 +       return vx_map_pid(pid);
17215 +}
17216  
17217 -       return pid;
17218 +#ifdef __alpha__
17219 +
17220 +/*
17221 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17222 + */
17223 +
17224 +asmlinkage long do_getxpid(long *ppid)
17225 +{
17226 +       *ppid = sys_getppid();
17227 +       return sys_getpid();
17228  }
17229  
17230 +#else /* _alpha_ */
17231 +
17232  SYSCALL_DEFINE0(getuid)
17233  {
17234         /* Only we change this so SMP safe */
17235 @@ -1289,6 +1320,8 @@ int do_sysinfo(struct sysinfo *info)
17236                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17237                         tp.tv_sec++;
17238                 }
17239 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17240 +                       vx_vsi_uptime(&tp, NULL);
17241                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17242  
17243                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17244 diff -NurpP --minimal linux-2.6.27.25/kernel/user.c linux-2.6.27.25-vs2.3.0.36.6/kernel/user.c
17245 --- linux-2.6.27.25/kernel/user.c       2008-07-13 23:51:29.000000000 +0200
17246 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/user.c  2008-10-13 14:54:20.000000000 +0200
17247 @@ -243,12 +243,15 @@ static struct kobj_type uids_ktype = {
17248  };
17249  
17250  /* create /sys/kernel/uids/<uid>/cpu_share file for this user */
17251 -static int uids_user_create(struct user_struct *up)
17252 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17253  {
17254         struct kobject *kobj = &up->kobj;
17255 -       int error;
17256 +       int error = 0;
17257  
17258         memset(kobj, 0, sizeof(struct kobject));
17259 +       if (ns != &init_user_ns)
17260 +               goto done;
17261 +
17262         kobj->kset = uids_kset;
17263         error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
17264         if (error) {
17265 @@ -272,7 +275,7 @@ int __init uids_sysfs_init(void)
17266         if (!uids_kset)
17267                 return -ENOMEM;
17268  
17269 -       return uids_user_create(&root_user);
17270 +       return uids_user_create(NULL, &root_user);
17271  }
17272  
17273  /* work function to remove sysfs directory for a user and free up
17274 @@ -302,9 +305,11 @@ static void remove_user_sysfs_dir(struct
17275         if (!remove_user)
17276                 goto done;
17277  
17278 -       kobject_uevent(&up->kobj, KOBJ_REMOVE);
17279 -       kobject_del(&up->kobj);
17280 -       kobject_put(&up->kobj);
17281 +       if (up->kobj.name) {
17282 +               kobject_uevent(&up->kobj, KOBJ_REMOVE);
17283 +               kobject_del(&up->kobj);
17284 +               kobject_put(&up->kobj);
17285 +       }
17286  
17287         sched_destroy_user(up);
17288         key_put(up->uid_keyring);
17289 @@ -332,7 +337,8 @@ static inline void free_user(struct user
17290  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
17291  
17292  int uids_sysfs_init(void) { return 0; }
17293 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17294 +static inline int uids_user_create(struct user_namespace *ns,
17295 +       struct user_struct *up) { return 0; }
17296  static inline void uids_mutex_lock(void) { }
17297  static inline void uids_mutex_unlock(void) { }
17298  
17299 @@ -409,7 +415,7 @@ struct user_struct *alloc_uid(struct use
17300                 if (sched_create_user(new) < 0)
17301                         goto out_free_user;
17302  
17303 -               if (uids_user_create(new))
17304 +               if (uids_user_create(ns, new))
17305                         goto out_destoy_sched;
17306  
17307                 /*
17308 diff -NurpP --minimal linux-2.6.27.25/kernel/user_namespace.c linux-2.6.27.25-vs2.3.0.36.6/kernel/user_namespace.c
17309 --- linux-2.6.27.25/kernel/user_namespace.c     2008-10-13 14:52:09.000000000 +0200
17310 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/user_namespace.c        2008-10-13 14:54:20.000000000 +0200
17311 @@ -9,6 +9,7 @@
17312  #include <linux/nsproxy.h>
17313  #include <linux/slab.h>
17314  #include <linux/user_namespace.h>
17315 +#include <linux/vserver/global.h>
17316  
17317  /*
17318   * Clone a new ns copying an original user ns, setting refcount to 1
17319 @@ -26,6 +27,7 @@ static struct user_namespace *clone_user
17320                 return ERR_PTR(-ENOMEM);
17321  
17322         kref_init(&ns->kref);
17323 +       atomic_inc(&vs_global_user_ns);
17324  
17325         for (n = 0; n < UIDHASH_SZ; ++n)
17326                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17327 @@ -71,6 +73,7 @@ void free_user_ns(struct kref *kref)
17328  
17329         ns = container_of(kref, struct user_namespace, kref);
17330         release_uids(ns);
17331 +       atomic_dec(&vs_global_user_ns);
17332         kfree(ns);
17333  }
17334  EXPORT_SYMBOL(free_user_ns);
17335 diff -NurpP --minimal linux-2.6.27.25/kernel/utsname.c linux-2.6.27.25-vs2.3.0.36.6/kernel/utsname.c
17336 --- linux-2.6.27.25/kernel/utsname.c    2008-10-13 14:52:09.000000000 +0200
17337 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/utsname.c       2008-10-13 14:54:20.000000000 +0200
17338 @@ -14,6 +14,7 @@
17339  #include <linux/utsname.h>
17340  #include <linux/err.h>
17341  #include <linux/slab.h>
17342 +#include <linux/vserver/global.h>
17343  
17344  /*
17345   * Clone a new ns copying an original utsname, setting refcount to 1
17346 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17347         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17348         up_read(&uts_sem);
17349         kref_init(&ns->kref);
17350 +       atomic_inc(&vs_global_uts_ns);
17351         return ns;
17352  }
17353  
17354 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17355         struct uts_namespace *ns;
17356  
17357         ns = container_of(kref, struct uts_namespace, kref);
17358 +       atomic_dec(&vs_global_uts_ns);
17359         kfree(ns);
17360  }
17361 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/cacct.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cacct.c
17362 --- linux-2.6.27.25/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
17363 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cacct.c 2008-10-13 14:54:20.000000000 +0200
17364 @@ -0,0 +1,42 @@
17365 +/*
17366 + *  linux/kernel/vserver/cacct.c
17367 + *
17368 + *  Virtual Server: Context Accounting
17369 + *
17370 + *  Copyright (C) 2006-2007 Herbert Pötzl
17371 + *
17372 + *  V0.01  added accounting stats
17373 + *
17374 + */
17375 +
17376 +#include <linux/types.h>
17377 +#include <linux/vs_context.h>
17378 +#include <linux/vserver/cacct_cmd.h>
17379 +#include <linux/vserver/cacct_int.h>
17380 +
17381 +#include <asm/errno.h>
17382 +#include <asm/uaccess.h>
17383 +
17384 +
17385 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17386 +{
17387 +       struct vcmd_sock_stat_v0 vc_data;
17388 +       int j, field;
17389 +
17390 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17391 +               return -EFAULT;
17392 +
17393 +       field = vc_data.field;
17394 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17395 +               return -EINVAL;
17396 +
17397 +       for (j = 0; j < 3; j++) {
17398 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17399 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17400 +       }
17401 +
17402 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17403 +               return -EFAULT;
17404 +       return 0;
17405 +}
17406 +
17407 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/cacct_init.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cacct_init.h
17408 --- linux-2.6.27.25/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
17409 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cacct_init.h    2008-10-13 14:54:20.000000000 +0200
17410 @@ -0,0 +1,25 @@
17411 +
17412 +
17413 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17414 +{
17415 +       int i, j;
17416 +
17417 +
17418 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17419 +               for (j = 0; j < 3; j++) {
17420 +                       atomic_set(&cacct->sock[i][j].count, 0);
17421 +                       atomic_set(&cacct->sock[i][j].total, 0);
17422 +               }
17423 +       }
17424 +       for (i = 0; i < 8; i++)
17425 +               atomic_set(&cacct->slab[i], 0);
17426 +       for (i = 0; i < 5; i++)
17427 +               for (j = 0; j < 4; j++)
17428 +                       atomic_set(&cacct->page[i][j], 0);
17429 +}
17430 +
17431 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17432 +{
17433 +       return;
17434 +}
17435 +
17436 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/cacct_proc.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cacct_proc.h
17437 --- linux-2.6.27.25/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
17438 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cacct_proc.h    2008-10-13 14:54:20.000000000 +0200
17439 @@ -0,0 +1,53 @@
17440 +#ifndef _VX_CACCT_PROC_H
17441 +#define _VX_CACCT_PROC_H
17442 +
17443 +#include <linux/vserver/cacct_int.h>
17444 +
17445 +
17446 +#define VX_SOCKA_TOP   \
17447 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17448 +
17449 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17450 +{
17451 +       int i, j, length = 0;
17452 +       static char *type[VXA_SOCK_SIZE] = {
17453 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17454 +       };
17455 +
17456 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17457 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17458 +               length += sprintf(buffer + length, "%s:", type[i]);
17459 +               for (j = 0; j < 3; j++) {
17460 +                       length += sprintf(buffer + length,
17461 +                               "\t%10lu/%-10lu",
17462 +                               vx_sock_count(cacct, i, j),
17463 +                               vx_sock_total(cacct, i, j));
17464 +               }
17465 +               buffer[length++] = '\n';
17466 +       }
17467 +
17468 +       length += sprintf(buffer + length, "\n");
17469 +       length += sprintf(buffer + length,
17470 +               "slab:\t %8u %8u %8u %8u\n",
17471 +               atomic_read(&cacct->slab[1]),
17472 +               atomic_read(&cacct->slab[4]),
17473 +               atomic_read(&cacct->slab[0]),
17474 +               atomic_read(&cacct->slab[2]));
17475 +
17476 +       length += sprintf(buffer + length, "\n");
17477 +       for (i = 0; i < 5; i++) {
17478 +               length += sprintf(buffer + length,
17479 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17480 +                       atomic_read(&cacct->page[i][0]),
17481 +                       atomic_read(&cacct->page[i][1]),
17482 +                       atomic_read(&cacct->page[i][2]),
17483 +                       atomic_read(&cacct->page[i][3]),
17484 +                       atomic_read(&cacct->page[i][4]),
17485 +                       atomic_read(&cacct->page[i][5]),
17486 +                       atomic_read(&cacct->page[i][6]),
17487 +                       atomic_read(&cacct->page[i][7]));
17488 +       }
17489 +       return length;
17490 +}
17491 +
17492 +#endif /* _VX_CACCT_PROC_H */
17493 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/context.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/context.c
17494 --- linux-2.6.27.25/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
17495 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/context.c       2008-10-31 03:56:55.000000000 +0100
17496 @@ -0,0 +1,1018 @@
17497 +/*
17498 + *  linux/kernel/vserver/context.c
17499 + *
17500 + *  Virtual Server: Context Support
17501 + *
17502 + *  Copyright (C) 2003-2007  Herbert Pötzl
17503 + *
17504 + *  V0.01  context helper
17505 + *  V0.02  vx_ctx_kill syscall command
17506 + *  V0.03  replaced context_info calls
17507 + *  V0.04  redesign of struct (de)alloc
17508 + *  V0.05  rlimit basic implementation
17509 + *  V0.06  task_xid and info commands
17510 + *  V0.07  context flags and caps
17511 + *  V0.08  switch to RCU based hash
17512 + *  V0.09  revert to non RCU for now
17513 + *  V0.10  and back to working RCU hash
17514 + *  V0.11  and back to locking again
17515 + *  V0.12  referenced context store
17516 + *  V0.13  separate per cpu data
17517 + *  V0.14  changed vcmds to vxi arg
17518 + *  V0.15  added context stat
17519 + *  V0.16  have __create claim() the vxi
17520 + *  V0.17  removed older and legacy stuff
17521 + *
17522 + */
17523 +
17524 +#include <linux/slab.h>
17525 +#include <linux/types.h>
17526 +#include <linux/security.h>
17527 +#include <linux/pid_namespace.h>
17528 +
17529 +#include <linux/vserver/context.h>
17530 +#include <linux/vserver/network.h>
17531 +#include <linux/vserver/debug.h>
17532 +#include <linux/vserver/limit.h>
17533 +#include <linux/vserver/limit_int.h>
17534 +#include <linux/vserver/space.h>
17535 +
17536 +#include <linux/vs_context.h>
17537 +#include <linux/vs_limit.h>
17538 +#include <linux/vs_pid.h>
17539 +#include <linux/vserver/context_cmd.h>
17540 +
17541 +#include "cvirt_init.h"
17542 +#include "cacct_init.h"
17543 +#include "limit_init.h"
17544 +#include "sched_init.h"
17545 +
17546 +
17547 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17548 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17549 +
17550 +
17551 +/*     now inactive context structures */
17552 +
17553 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17554 +
17555 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17556 +
17557 +
17558 +/*     __alloc_vx_info()
17559 +
17560 +       * allocate an initialized vx_info struct
17561 +       * doesn't make it visible (hash)                        */
17562 +
17563 +static struct vx_info *__alloc_vx_info(xid_t xid)
17564 +{
17565 +       struct vx_info *new = NULL;
17566 +       int cpu;
17567 +
17568 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17569 +
17570 +       /* would this benefit from a slab cache? */
17571 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17572 +       if (!new)
17573 +               return 0;
17574 +
17575 +       memset(new, 0, sizeof(struct vx_info));
17576 +#ifdef CONFIG_SMP
17577 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17578 +       if (!new->ptr_pc)
17579 +               goto error;
17580 +#endif
17581 +       new->vx_id = xid;
17582 +       INIT_HLIST_NODE(&new->vx_hlist);
17583 +       atomic_set(&new->vx_usecnt, 0);
17584 +       atomic_set(&new->vx_tasks, 0);
17585 +       new->vx_parent = NULL;
17586 +       new->vx_state = 0;
17587 +       init_waitqueue_head(&new->vx_wait);
17588 +
17589 +       /* prepare reaper */
17590 +       get_task_struct(init_pid_ns.child_reaper);
17591 +       new->vx_reaper = init_pid_ns.child_reaper;
17592 +       new->vx_badness_bias = 0;
17593 +
17594 +       /* rest of init goes here */
17595 +       vx_info_init_limit(&new->limit);
17596 +       vx_info_init_sched(&new->sched);
17597 +       vx_info_init_cvirt(&new->cvirt);
17598 +       vx_info_init_cacct(&new->cacct);
17599 +
17600 +       /* per cpu data structures */
17601 +       for_each_possible_cpu(cpu) {
17602 +               vx_info_init_sched_pc(
17603 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17604 +               vx_info_init_cvirt_pc(
17605 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17606 +       }
17607 +
17608 +       new->vx_flags = VXF_INIT_SET;
17609 +       cap_set_init_eff(new->vx_bcaps);
17610 +       new->vx_ccaps = 0;
17611 +       // new->vx_cap_bset = current->cap_bset;
17612 +
17613 +       new->reboot_cmd = 0;
17614 +       new->exit_code = 0;
17615 +
17616 +       vxdprintk(VXD_CBIT(xid, 0),
17617 +               "alloc_vx_info(%d) = %p", xid, new);
17618 +       vxh_alloc_vx_info(new);
17619 +       atomic_inc(&vx_global_ctotal);
17620 +       return new;
17621 +#ifdef CONFIG_SMP
17622 +error:
17623 +       kfree(new);
17624 +       return 0;
17625 +#endif
17626 +}
17627 +
17628 +/*     __dealloc_vx_info()
17629 +
17630 +       * final disposal of vx_info                             */
17631 +
17632 +static void __dealloc_vx_info(struct vx_info *vxi)
17633 +{
17634 +       struct vx_info_save vxis;
17635 +       int cpu;
17636 +
17637 +       vxdprintk(VXD_CBIT(xid, 0),
17638 +               "dealloc_vx_info(%p)", vxi);
17639 +       vxh_dealloc_vx_info(vxi);
17640 +
17641 +#ifdef CONFIG_VSERVER_WARN
17642 +       enter_vx_info(vxi, &vxis);
17643 +       vx_info_exit_limit(&vxi->limit);
17644 +       vx_info_exit_sched(&vxi->sched);
17645 +       vx_info_exit_cvirt(&vxi->cvirt);
17646 +       vx_info_exit_cacct(&vxi->cacct);
17647 +
17648 +       for_each_possible_cpu(cpu) {
17649 +               vx_info_exit_sched_pc(
17650 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17651 +               vx_info_exit_cvirt_pc(
17652 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17653 +       }
17654 +       leave_vx_info(&vxis);
17655 +#endif
17656 +
17657 +       vxi->vx_id = -1;
17658 +       vxi->vx_state |= VXS_RELEASED;
17659 +
17660 +#ifdef CONFIG_SMP
17661 +       free_percpu(vxi->ptr_pc);
17662 +#endif
17663 +       kfree(vxi);
17664 +       atomic_dec(&vx_global_ctotal);
17665 +}
17666 +
17667 +static void __shutdown_vx_info(struct vx_info *vxi)
17668 +{
17669 +       struct nsproxy *nsproxy;
17670 +       struct fs_struct *fs;
17671 +       int index;
17672 +
17673 +       might_sleep();
17674 +
17675 +       vxi->vx_state |= VXS_SHUTDOWN;
17676 +       vs_state_change(vxi, VSC_SHUTDOWN);
17677 +
17678 +       for (index = 0; index < VX_SPACES; index++) {
17679 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17680 +               if (nsproxy)
17681 +                       put_nsproxy(nsproxy);
17682 +
17683 +               fs = xchg(&vxi->vx_fs[index], NULL);
17684 +               if (fs)
17685 +                       put_fs_struct(fs);
17686 +       }
17687 +}
17688 +
17689 +/* exported stuff */
17690 +
17691 +void free_vx_info(struct vx_info *vxi)
17692 +{
17693 +       unsigned long flags;
17694 +       unsigned index;
17695 +
17696 +       /* check for reference counts first */
17697 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17698 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17699 +
17700 +       /* context must not be hashed */
17701 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17702 +
17703 +       /* context shutdown is mandatory */
17704 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17705 +
17706 +       /* nsproxy and fs check */
17707 +       for (index = 0; index < VX_SPACES; index++) {
17708 +               BUG_ON(vxi->vx_nsproxy[index]);
17709 +               BUG_ON(vxi->vx_fs[index]);
17710 +       }
17711 +
17712 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17713 +       hlist_del(&vxi->vx_hlist);
17714 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17715 +
17716 +       __dealloc_vx_info(vxi);
17717 +}
17718 +
17719 +
17720 +/*     hash table for vx_info hash */
17721 +
17722 +#define VX_HASH_SIZE   13
17723 +
17724 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17725 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17726 +
17727 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17728 +
17729 +
17730 +static inline unsigned int __hashval(xid_t xid)
17731 +{
17732 +       return (xid % VX_HASH_SIZE);
17733 +}
17734 +
17735 +
17736 +
17737 +/*     __hash_vx_info()
17738 +
17739 +       * add the vxi to the global hash table
17740 +       * requires the hash_lock to be held                     */
17741 +
17742 +static inline void __hash_vx_info(struct vx_info *vxi)
17743 +{
17744 +       struct hlist_head *head;
17745 +
17746 +       vxd_assert_lock(&vx_info_hash_lock);
17747 +       vxdprintk(VXD_CBIT(xid, 4),
17748 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17749 +       vxh_hash_vx_info(vxi);
17750 +
17751 +       /* context must not be hashed */
17752 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17753 +
17754 +       vxi->vx_state |= VXS_HASHED;
17755 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17756 +       hlist_add_head(&vxi->vx_hlist, head);
17757 +       atomic_inc(&vx_global_cactive);
17758 +}
17759 +
17760 +/*     __unhash_vx_info()
17761 +
17762 +       * remove the vxi from the global hash table
17763 +       * requires the hash_lock to be held                     */
17764 +
17765 +static inline void __unhash_vx_info(struct vx_info *vxi)
17766 +{
17767 +       unsigned long flags;
17768 +
17769 +       vxd_assert_lock(&vx_info_hash_lock);
17770 +       vxdprintk(VXD_CBIT(xid, 4),
17771 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17772 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17773 +       vxh_unhash_vx_info(vxi);
17774 +
17775 +       /* context must be hashed */
17776 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17777 +       /* but without tasks */
17778 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17779 +
17780 +       vxi->vx_state &= ~VXS_HASHED;
17781 +       hlist_del_init(&vxi->vx_hlist);
17782 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17783 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17784 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17785 +       atomic_dec(&vx_global_cactive);
17786 +}
17787 +
17788 +
17789 +/*     __lookup_vx_info()
17790 +
17791 +       * requires the hash_lock to be held
17792 +       * doesn't increment the vx_refcnt                       */
17793 +
17794 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17795 +{
17796 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17797 +       struct hlist_node *pos;
17798 +       struct vx_info *vxi;
17799 +
17800 +       vxd_assert_lock(&vx_info_hash_lock);
17801 +       hlist_for_each(pos, head) {
17802 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17803 +
17804 +               if (vxi->vx_id == xid)
17805 +                       goto found;
17806 +       }
17807 +       vxi = NULL;
17808 +found:
17809 +       vxdprintk(VXD_CBIT(xid, 0),
17810 +               "__lookup_vx_info(#%u): %p[#%u]",
17811 +               xid, vxi, vxi ? vxi->vx_id : 0);
17812 +       vxh_lookup_vx_info(vxi, xid);
17813 +       return vxi;
17814 +}
17815 +
17816 +
17817 +/*     __create_vx_info()
17818 +
17819 +       * create the requested context
17820 +       * get(), claim() and hash it                            */
17821 +
17822 +static struct vx_info *__create_vx_info(int id)
17823 +{
17824 +       struct vx_info *new, *vxi = NULL;
17825 +
17826 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17827 +
17828 +       if (!(new = __alloc_vx_info(id)))
17829 +               return ERR_PTR(-ENOMEM);
17830 +
17831 +       /* required to make dynamic xids unique */
17832 +       spin_lock(&vx_info_hash_lock);
17833 +
17834 +       /* static context requested */
17835 +       if ((vxi = __lookup_vx_info(id))) {
17836 +               vxdprintk(VXD_CBIT(xid, 0),
17837 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17838 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17839 +                       vxi = ERR_PTR(-EBUSY);
17840 +               else
17841 +                       vxi = ERR_PTR(-EEXIST);
17842 +               goto out_unlock;
17843 +       }
17844 +       /* new context */
17845 +       vxdprintk(VXD_CBIT(xid, 0),
17846 +               "create_vx_info(%d) = %p (new)", id, new);
17847 +       claim_vx_info(new, NULL);
17848 +       __hash_vx_info(get_vx_info(new));
17849 +       vxi = new, new = NULL;
17850 +
17851 +out_unlock:
17852 +       spin_unlock(&vx_info_hash_lock);
17853 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17854 +       if (new)
17855 +               __dealloc_vx_info(new);
17856 +       return vxi;
17857 +}
17858 +
17859 +
17860 +/*     exported stuff                                          */
17861 +
17862 +
17863 +void unhash_vx_info(struct vx_info *vxi)
17864 +{
17865 +       __shutdown_vx_info(vxi);
17866 +       spin_lock(&vx_info_hash_lock);
17867 +       __unhash_vx_info(vxi);
17868 +       spin_unlock(&vx_info_hash_lock);
17869 +       __wakeup_vx_info(vxi);
17870 +}
17871 +
17872 +
17873 +/*     lookup_vx_info()
17874 +
17875 +       * search for a vx_info and get() it
17876 +       * negative id means current                             */
17877 +
17878 +struct vx_info *lookup_vx_info(int id)
17879 +{
17880 +       struct vx_info *vxi = NULL;
17881 +
17882 +       if (id < 0) {
17883 +               vxi = get_vx_info(current->vx_info);
17884 +       } else if (id > 1) {
17885 +               spin_lock(&vx_info_hash_lock);
17886 +               vxi = get_vx_info(__lookup_vx_info(id));
17887 +               spin_unlock(&vx_info_hash_lock);
17888 +       }
17889 +       return vxi;
17890 +}
17891 +
17892 +/*     xid_is_hashed()
17893 +
17894 +       * verify that xid is still hashed                       */
17895 +
17896 +int xid_is_hashed(xid_t xid)
17897 +{
17898 +       int hashed;
17899 +
17900 +       spin_lock(&vx_info_hash_lock);
17901 +       hashed = (__lookup_vx_info(xid) != NULL);
17902 +       spin_unlock(&vx_info_hash_lock);
17903 +       return hashed;
17904 +}
17905 +
17906 +#ifdef CONFIG_PROC_FS
17907 +
17908 +/*     get_xid_list()
17909 +
17910 +       * get a subset of hashed xids for proc
17911 +       * assumes size is at least one                          */
17912 +
17913 +int get_xid_list(int index, unsigned int *xids, int size)
17914 +{
17915 +       int hindex, nr_xids = 0;
17916 +
17917 +       /* only show current and children */
17918 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17919 +               if (index > 0)
17920 +                       return 0;
17921 +               xids[nr_xids] = vx_current_xid();
17922 +               return 1;
17923 +       }
17924 +
17925 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17926 +               struct hlist_head *head = &vx_info_hash[hindex];
17927 +               struct hlist_node *pos;
17928 +
17929 +               spin_lock(&vx_info_hash_lock);
17930 +               hlist_for_each(pos, head) {
17931 +                       struct vx_info *vxi;
17932 +
17933 +                       if (--index > 0)
17934 +                               continue;
17935 +
17936 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17937 +                       xids[nr_xids] = vxi->vx_id;
17938 +                       if (++nr_xids >= size) {
17939 +                               spin_unlock(&vx_info_hash_lock);
17940 +                               goto out;
17941 +                       }
17942 +               }
17943 +               /* keep the lock time short */
17944 +               spin_unlock(&vx_info_hash_lock);
17945 +       }
17946 +out:
17947 +       return nr_xids;
17948 +}
17949 +#endif
17950 +
17951 +#ifdef CONFIG_VSERVER_DEBUG
17952 +
17953 +void   dump_vx_info_inactive(int level)
17954 +{
17955 +       struct hlist_node *entry, *next;
17956 +
17957 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17958 +               struct vx_info *vxi =
17959 +                       list_entry(entry, struct vx_info, vx_hlist);
17960 +
17961 +               dump_vx_info(vxi, level);
17962 +       }
17963 +}
17964 +
17965 +#endif
17966 +
17967 +#if 0
17968 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17969 +{
17970 +       struct user_struct *new_user, *old_user;
17971 +
17972 +       if (!p || !vxi)
17973 +               BUG();
17974 +
17975 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17976 +               return -EACCES;
17977 +
17978 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17979 +       if (!new_user)
17980 +               return -ENOMEM;
17981 +
17982 +       old_user = p->user;
17983 +       if (new_user != old_user) {
17984 +               atomic_inc(&new_user->processes);
17985 +               atomic_dec(&old_user->processes);
17986 +               p->user = new_user;
17987 +       }
17988 +       free_uid(old_user);
17989 +       return 0;
17990 +}
17991 +#endif
17992 +
17993 +#if 0
17994 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17995 +{
17996 +       // p->cap_effective &= vxi->vx_cap_bset;
17997 +       p->cap_effective =
17998 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17999 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18000 +       p->cap_inheritable =
18001 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18002 +       // p->cap_permitted &= vxi->vx_cap_bset;
18003 +       p->cap_permitted =
18004 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18005 +}
18006 +#endif
18007 +
18008 +
18009 +#include <linux/file.h>
18010 +#include <linux/fdtable.h>
18011 +
18012 +static int vx_openfd_task(struct task_struct *tsk)
18013 +{
18014 +       struct files_struct *files = tsk->files;
18015 +       struct fdtable *fdt;
18016 +       const unsigned long *bptr;
18017 +       int count, total;
18018 +
18019 +       /* no rcu_read_lock() because of spin_lock() */
18020 +       spin_lock(&files->file_lock);
18021 +       fdt = files_fdtable(files);
18022 +       bptr = fdt->open_fds->fds_bits;
18023 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18024 +       for (total = 0; count > 0; count--) {
18025 +               if (*bptr)
18026 +                       total += hweight_long(*bptr);
18027 +               bptr++;
18028 +       }
18029 +       spin_unlock(&files->file_lock);
18030 +       return total;
18031 +}
18032 +
18033 +
18034 +/*     for *space compatibility */
18035 +
18036 +asmlinkage long sys_unshare(unsigned long);
18037 +
18038 +/*
18039 + *     migrate task to new context
18040 + *     gets vxi, puts old_vxi on change
18041 + *     optionally unshares namespaces (hack)
18042 + */
18043 +
18044 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18045 +{
18046 +       struct vx_info *old_vxi;
18047 +       int ret = 0;
18048 +
18049 +       if (!p || !vxi)
18050 +               BUG();
18051 +
18052 +       vxdprintk(VXD_CBIT(xid, 5),
18053 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18054 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18055 +
18056 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18057 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18058 +               return -EACCES;
18059 +
18060 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18061 +               return -EFAULT;
18062 +
18063 +       old_vxi = task_get_vx_info(p);
18064 +       if (old_vxi == vxi)
18065 +               goto out;
18066 +
18067 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18068 +       {
18069 +               int openfd;
18070 +
18071 +               task_lock(p);
18072 +               openfd = vx_openfd_task(p);
18073 +
18074 +               if (old_vxi) {
18075 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18076 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18077 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18078 +                       /* FIXME: what about the struct files here? */
18079 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18080 +                       /* account for the executable */
18081 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18082 +               }
18083 +               atomic_inc(&vxi->cvirt.nr_threads);
18084 +               atomic_inc(&vxi->cvirt.nr_running);
18085 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18086 +               /* FIXME: what about the struct files here? */
18087 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18088 +               /* account for the executable */
18089 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18090 +
18091 +               if (old_vxi) {
18092 +                       release_vx_info(old_vxi, p);
18093 +                       clr_vx_info(&p->vx_info);
18094 +               }
18095 +               claim_vx_info(vxi, p);
18096 +               set_vx_info(&p->vx_info, vxi);
18097 +               p->xid = vxi->vx_id;
18098 +
18099 +               vxdprintk(VXD_CBIT(xid, 5),
18100 +                       "moved task %p into vxi:%p[#%d]",
18101 +                       p, vxi, vxi->vx_id);
18102 +
18103 +               // vx_mask_cap_bset(vxi, p);
18104 +               task_unlock(p);
18105 +
18106 +               /* hack for *spaces to provide compatibility */
18107 +               if (unshare) {
18108 +                       struct nsproxy *old_nsp, *new_nsp;
18109 +
18110 +                       ret = unshare_nsproxy_namespaces(
18111 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18112 +                               &new_nsp, NULL);
18113 +                       if (ret)
18114 +                               goto out;
18115 +
18116 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18117 +                       vx_set_space(vxi,
18118 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18119 +                       put_nsproxy(old_nsp);
18120 +               }
18121 +       }
18122 +out:
18123 +       put_vx_info(old_vxi);
18124 +       return ret;
18125 +}
18126 +
18127 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18128 +{
18129 +       struct task_struct *old_reaper;
18130 +
18131 +       if (!vxi)
18132 +               return -EINVAL;
18133 +
18134 +       vxdprintk(VXD_CBIT(xid, 6),
18135 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18136 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18137 +
18138 +       old_reaper = vxi->vx_reaper;
18139 +       if (old_reaper == p)
18140 +               return 0;
18141 +
18142 +       /* set new child reaper */
18143 +       get_task_struct(p);
18144 +       vxi->vx_reaper = p;
18145 +       put_task_struct(old_reaper);
18146 +       return 0;
18147 +}
18148 +
18149 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18150 +{
18151 +       if (!vxi)
18152 +               return -EINVAL;
18153 +
18154 +       vxdprintk(VXD_CBIT(xid, 6),
18155 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18156 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18157 +
18158 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18159 +       vxi->vx_initpid = p->tgid;
18160 +       return 0;
18161 +}
18162 +
18163 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18164 +{
18165 +       vxdprintk(VXD_CBIT(xid, 6),
18166 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18167 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18168 +
18169 +       vxi->exit_code = code;
18170 +       vxi->vx_initpid = 0;
18171 +}
18172 +
18173 +
18174 +void vx_set_persistent(struct vx_info *vxi)
18175 +{
18176 +       vxdprintk(VXD_CBIT(xid, 6),
18177 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18178 +
18179 +       get_vx_info(vxi);
18180 +       claim_vx_info(vxi, NULL);
18181 +}
18182 +
18183 +void vx_clear_persistent(struct vx_info *vxi)
18184 +{
18185 +       vxdprintk(VXD_CBIT(xid, 6),
18186 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18187 +
18188 +       release_vx_info(vxi, NULL);
18189 +       put_vx_info(vxi);
18190 +}
18191 +
18192 +void vx_update_persistent(struct vx_info *vxi)
18193 +{
18194 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18195 +               vx_set_persistent(vxi);
18196 +       else
18197 +               vx_clear_persistent(vxi);
18198 +}
18199 +
18200 +
18201 +/*     task must be current or locked          */
18202 +
18203 +void   exit_vx_info(struct task_struct *p, int code)
18204 +{
18205 +       struct vx_info *vxi = p->vx_info;
18206 +
18207 +       if (vxi) {
18208 +               atomic_dec(&vxi->cvirt.nr_threads);
18209 +               vx_nproc_dec(p);
18210 +
18211 +               vxi->exit_code = code;
18212 +               release_vx_info(vxi, p);
18213 +       }
18214 +}
18215 +
18216 +void   exit_vx_info_early(struct task_struct *p, int code)
18217 +{
18218 +       struct vx_info *vxi = p->vx_info;
18219 +
18220 +       if (vxi) {
18221 +               if (vxi->vx_initpid == p->tgid)
18222 +                       vx_exit_init(vxi, p, code);
18223 +               if (vxi->vx_reaper == p)
18224 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18225 +       }
18226 +}
18227 +
18228 +
18229 +/* vserver syscall commands below here */
18230 +
18231 +/* taks xid and vx_info functions */
18232 +
18233 +#include <asm/uaccess.h>
18234 +
18235 +
18236 +int vc_task_xid(uint32_t id)
18237 +{
18238 +       xid_t xid;
18239 +
18240 +       if (id) {
18241 +               struct task_struct *tsk;
18242 +
18243 +               read_lock(&tasklist_lock);
18244 +               tsk = find_task_by_real_pid(id);
18245 +               xid = (tsk) ? tsk->xid : -ESRCH;
18246 +               read_unlock(&tasklist_lock);
18247 +       } else
18248 +               xid = vx_current_xid();
18249 +       return xid;
18250 +}
18251 +
18252 +
18253 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18254 +{
18255 +       struct vcmd_vx_info_v0 vc_data;
18256 +
18257 +       vc_data.xid = vxi->vx_id;
18258 +       vc_data.initpid = vxi->vx_initpid;
18259 +
18260 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18261 +               return -EFAULT;
18262 +       return 0;
18263 +}
18264 +
18265 +
18266 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18267 +{
18268 +       struct vcmd_ctx_stat_v0 vc_data;
18269 +
18270 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18271 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18272 +
18273 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18274 +               return -EFAULT;
18275 +       return 0;
18276 +}
18277 +
18278 +
18279 +/* context functions */
18280 +
18281 +int vc_ctx_create(uint32_t xid, void __user *data)
18282 +{
18283 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18284 +       struct vx_info *new_vxi;
18285 +       int ret;
18286 +
18287 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18288 +               return -EFAULT;
18289 +
18290 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18291 +               return -EINVAL;
18292 +
18293 +       new_vxi = __create_vx_info(xid);
18294 +       if (IS_ERR(new_vxi))
18295 +               return PTR_ERR(new_vxi);
18296 +
18297 +       /* initial flags */
18298 +       new_vxi->vx_flags = vc_data.flagword;
18299 +
18300 +       ret = -ENOEXEC;
18301 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18302 +               goto out;
18303 +
18304 +       ret = vx_migrate_task(current, new_vxi, (!data));
18305 +       if (ret)
18306 +               goto out;
18307 +
18308 +       /* return context id on success */
18309 +       ret = new_vxi->vx_id;
18310 +
18311 +       /* get a reference for persistent contexts */
18312 +       if ((vc_data.flagword & VXF_PERSISTENT))
18313 +               vx_set_persistent(new_vxi);
18314 +out:
18315 +       release_vx_info(new_vxi, NULL);
18316 +       put_vx_info(new_vxi);
18317 +       return ret;
18318 +}
18319 +
18320 +
18321 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18322 +{
18323 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18324 +       int ret;
18325 +
18326 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18327 +               return -EFAULT;
18328 +
18329 +       ret = vx_migrate_task(current, vxi, 0);
18330 +       if (ret)
18331 +               return ret;
18332 +       if (vc_data.flagword & VXM_SET_INIT)
18333 +               ret = vx_set_init(vxi, current);
18334 +       if (ret)
18335 +               return ret;
18336 +       if (vc_data.flagword & VXM_SET_REAPER)
18337 +               ret = vx_set_reaper(vxi, current);
18338 +       return ret;
18339 +}
18340 +
18341 +
18342 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18343 +{
18344 +       struct vcmd_ctx_flags_v0 vc_data;
18345 +
18346 +       vc_data.flagword = vxi->vx_flags;
18347 +
18348 +       /* special STATE flag handling */
18349 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18350 +
18351 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18352 +               return -EFAULT;
18353 +       return 0;
18354 +}
18355 +
18356 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18357 +{
18358 +       struct vcmd_ctx_flags_v0 vc_data;
18359 +       uint64_t mask, trigger;
18360 +
18361 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18362 +               return -EFAULT;
18363 +
18364 +       /* special STATE flag handling */
18365 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18366 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18367 +
18368 +       if (vxi == current->vx_info) {
18369 +               /* if (trigger & VXF_STATE_SETUP)
18370 +                       vx_mask_cap_bset(vxi, current); */
18371 +               if (trigger & VXF_STATE_INIT) {
18372 +                       int ret;
18373 +
18374 +                       ret = vx_set_init(vxi, current);
18375 +                       if (ret)
18376 +                               return ret;
18377 +                       ret = vx_set_reaper(vxi, current);
18378 +                       if (ret)
18379 +                               return ret;
18380 +               }
18381 +       }
18382 +
18383 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18384 +               vc_data.flagword, mask);
18385 +       if (trigger & VXF_PERSISTENT)
18386 +               vx_update_persistent(vxi);
18387 +
18388 +       return 0;
18389 +}
18390 +
18391 +
18392 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18393 +{
18394 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18395 +
18396 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18397 +       return v;
18398 +}
18399 +
18400 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18401 +{
18402 +       kernel_cap_t c = __cap_empty_set;
18403 +
18404 +       c.cap[0] = v & 0xFFFFFFFF;
18405 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18406 +
18407 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18408 +       return c;
18409 +}
18410 +
18411 +
18412 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18413 +{
18414 +       if (bcaps)
18415 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18416 +       if (ccaps)
18417 +               *ccaps = vxi->vx_ccaps;
18418 +
18419 +       return 0;
18420 +}
18421 +
18422 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18423 +{
18424 +       struct vcmd_ctx_caps_v1 vc_data;
18425 +       int ret;
18426 +
18427 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18428 +       if (ret)
18429 +               return ret;
18430 +       vc_data.cmask = ~0ULL;
18431 +
18432 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18433 +               return -EFAULT;
18434 +       return 0;
18435 +}
18436 +
18437 +static int do_set_caps(struct vx_info *vxi,
18438 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18439 +{
18440 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18441 +
18442 +#if 0
18443 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18444 +               bcaps, bmask, ccaps, cmask);
18445 +#endif
18446 +       vxi->vx_bcaps = cap_t_from_caps(
18447 +               vs_mask_flags(bcold, bcaps, bmask));
18448 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18449 +
18450 +       return 0;
18451 +}
18452 +
18453 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18454 +{
18455 +       struct vcmd_ctx_caps_v1 vc_data;
18456 +
18457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18458 +               return -EFAULT;
18459 +
18460 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18461 +}
18462 +
18463 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18464 +{
18465 +       struct vcmd_bcaps vc_data;
18466 +       int ret;
18467 +
18468 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18469 +       if (ret)
18470 +               return ret;
18471 +       vc_data.bmask = ~0ULL;
18472 +
18473 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18474 +               return -EFAULT;
18475 +       return 0;
18476 +}
18477 +
18478 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18479 +{
18480 +       struct vcmd_bcaps vc_data;
18481 +
18482 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18483 +               return -EFAULT;
18484 +
18485 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18486 +}
18487 +
18488 +
18489 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18490 +{
18491 +       struct vcmd_badness_v0 vc_data;
18492 +
18493 +       vc_data.bias = vxi->vx_badness_bias;
18494 +
18495 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18496 +               return -EFAULT;
18497 +       return 0;
18498 +}
18499 +
18500 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18501 +{
18502 +       struct vcmd_badness_v0 vc_data;
18503 +
18504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18505 +               return -EFAULT;
18506 +
18507 +       vxi->vx_badness_bias = vc_data.bias;
18508 +       return 0;
18509 +}
18510 +
18511 +#include <linux/module.h>
18512 +
18513 +EXPORT_SYMBOL_GPL(free_vx_info);
18514 +
18515 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/cvirt.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cvirt.c
18516 --- linux-2.6.27.25/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
18517 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cvirt.c 2008-10-31 03:49:36.000000000 +0100
18518 @@ -0,0 +1,300 @@
18519 +/*
18520 + *  linux/kernel/vserver/cvirt.c
18521 + *
18522 + *  Virtual Server: Context Virtualization
18523 + *
18524 + *  Copyright (C) 2004-2007  Herbert Pötzl
18525 + *
18526 + *  V0.01  broken out from limit.c
18527 + *  V0.02  added utsname stuff
18528 + *  V0.03  changed vcmds to vxi arg
18529 + *
18530 + */
18531 +
18532 +#include <linux/types.h>
18533 +#include <linux/utsname.h>
18534 +#include <linux/vs_cvirt.h>
18535 +#include <linux/vserver/switch.h>
18536 +#include <linux/vserver/cvirt_cmd.h>
18537 +
18538 +#include <asm/uaccess.h>
18539 +
18540 +
18541 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18542 +{
18543 +       struct vx_info *vxi = current->vx_info;
18544 +
18545 +       set_normalized_timespec(uptime,
18546 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18547 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18548 +       if (!idle)
18549 +               return;
18550 +       set_normalized_timespec(idle,
18551 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18552 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18553 +       return;
18554 +}
18555 +
18556 +uint64_t vx_idle_jiffies(void)
18557 +{
18558 +       return init_task.utime + init_task.stime;
18559 +}
18560 +
18561 +
18562 +
18563 +static inline uint32_t __update_loadavg(uint32_t load,
18564 +       int wsize, int delta, int n)
18565 +{
18566 +       unsigned long long calc, prev;
18567 +
18568 +       /* just set it to n */
18569 +       if (unlikely(delta >= wsize))
18570 +               return (n << FSHIFT);
18571 +
18572 +       calc = delta * n;
18573 +       calc <<= FSHIFT;
18574 +       prev = (wsize - delta);
18575 +       prev *= load;
18576 +       calc += prev;
18577 +       do_div(calc, wsize);
18578 +       return calc;
18579 +}
18580 +
18581 +
18582 +void vx_update_load(struct vx_info *vxi)
18583 +{
18584 +       uint32_t now, last, delta;
18585 +       unsigned int nr_running, nr_uninterruptible;
18586 +       unsigned int total;
18587 +       unsigned long flags;
18588 +
18589 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18590 +
18591 +       now = jiffies;
18592 +       last = vxi->cvirt.load_last;
18593 +       delta = now - last;
18594 +
18595 +       if (delta < 5*HZ)
18596 +               goto out;
18597 +
18598 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18599 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18600 +       total = nr_running + nr_uninterruptible;
18601 +
18602 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18603 +               60*HZ, delta, total);
18604 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18605 +               5*60*HZ, delta, total);
18606 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18607 +               15*60*HZ, delta, total);
18608 +
18609 +       vxi->cvirt.load_last = now;
18610 +out:
18611 +       atomic_inc(&vxi->cvirt.load_updates);
18612 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18613 +}
18614 +
18615 +
18616 +/*
18617 + * Commands to do_syslog:
18618 + *
18619 + *      0 -- Close the log.  Currently a NOP.
18620 + *      1 -- Open the log. Currently a NOP.
18621 + *      2 -- Read from the log.
18622 + *      3 -- Read all messages remaining in the ring buffer.
18623 + *      4 -- Read and clear all messages remaining in the ring buffer
18624 + *      5 -- Clear ring buffer.
18625 + *      6 -- Disable printk's to console
18626 + *      7 -- Enable printk's to console
18627 + *      8 -- Set level of messages printed to console
18628 + *      9 -- Return number of unread characters in the log buffer
18629 + *     10 -- Return size of the log buffer
18630 + */
18631 +int vx_do_syslog(int type, char __user *buf, int len)
18632 +{
18633 +       int error = 0;
18634 +       int do_clear = 0;
18635 +       struct vx_info *vxi = current->vx_info;
18636 +       struct _vx_syslog *log;
18637 +
18638 +       if (!vxi)
18639 +               return -EINVAL;
18640 +       log = &vxi->cvirt.syslog;
18641 +
18642 +       switch (type) {
18643 +       case 0:         /* Close log */
18644 +       case 1:         /* Open log */
18645 +               break;
18646 +       case 2:         /* Read from log */
18647 +               error = wait_event_interruptible(log->log_wait,
18648 +                       (log->log_start - log->log_end));
18649 +               if (error)
18650 +                       break;
18651 +               spin_lock_irq(&log->logbuf_lock);
18652 +               spin_unlock_irq(&log->logbuf_lock);
18653 +               break;
18654 +       case 4:         /* Read/clear last kernel messages */
18655 +               do_clear = 1;
18656 +               /* fall through */
18657 +       case 3:         /* Read last kernel messages */
18658 +               return 0;
18659 +
18660 +       case 5:         /* Clear ring buffer */
18661 +               return 0;
18662 +
18663 +       case 6:         /* Disable logging to console */
18664 +       case 7:         /* Enable logging to console */
18665 +       case 8:         /* Set level of messages printed to console */
18666 +               break;
18667 +
18668 +       case 9:         /* Number of chars in the log buffer */
18669 +               return 0;
18670 +       case 10:        /* Size of the log buffer */
18671 +               return 0;
18672 +       default:
18673 +               error = -EINVAL;
18674 +               break;
18675 +       }
18676 +       return error;
18677 +}
18678 +
18679 +
18680 +/* virtual host info names */
18681 +
18682 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18683 +{
18684 +       struct nsproxy *nsproxy;
18685 +       struct uts_namespace *uts;
18686 +
18687 +       if (id == VHIN_CONTEXT)
18688 +               return vxi->vx_name;
18689 +
18690 +       nsproxy = vxi->vx_nsproxy[0];
18691 +       if (!nsproxy)
18692 +               return NULL;
18693 +
18694 +       uts = nsproxy->uts_ns;
18695 +       if (!uts)
18696 +               return NULL;
18697 +
18698 +       switch (id) {
18699 +       case VHIN_SYSNAME:
18700 +               return uts->name.sysname;
18701 +       case VHIN_NODENAME:
18702 +               return uts->name.nodename;
18703 +       case VHIN_RELEASE:
18704 +               return uts->name.release;
18705 +       case VHIN_VERSION:
18706 +               return uts->name.version;
18707 +       case VHIN_MACHINE:
18708 +               return uts->name.machine;
18709 +       case VHIN_DOMAINNAME:
18710 +               return uts->name.domainname;
18711 +       default:
18712 +               return NULL;
18713 +       }
18714 +       return NULL;
18715 +}
18716 +
18717 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18718 +{
18719 +       struct vcmd_vhi_name_v0 vc_data;
18720 +       char *name;
18721 +
18722 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18723 +               return -EFAULT;
18724 +
18725 +       name = vx_vhi_name(vxi, vc_data.field);
18726 +       if (!name)
18727 +               return -EINVAL;
18728 +
18729 +       memcpy(name, vc_data.name, 65);
18730 +       return 0;
18731 +}
18732 +
18733 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18734 +{
18735 +       struct vcmd_vhi_name_v0 vc_data;
18736 +       char *name;
18737 +
18738 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18739 +               return -EFAULT;
18740 +
18741 +       name = vx_vhi_name(vxi, vc_data.field);
18742 +       if (!name)
18743 +               return -EINVAL;
18744 +
18745 +       memcpy(vc_data.name, name, 65);
18746 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18747 +               return -EFAULT;
18748 +       return 0;
18749 +}
18750 +
18751 +
18752 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18753 +{
18754 +       struct vcmd_virt_stat_v0 vc_data;
18755 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18756 +       struct timespec uptime;
18757 +
18758 +       do_posix_clock_monotonic_gettime(&uptime);
18759 +       set_normalized_timespec(&uptime,
18760 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18761 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18762 +
18763 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18764 +       vc_data.uptime = timespec_to_ns(&uptime);
18765 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18766 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18767 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18768 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18769 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18770 +       vc_data.load[0] = cvirt->load[0];
18771 +       vc_data.load[1] = cvirt->load[1];
18772 +       vc_data.load[2] = cvirt->load[2];
18773 +
18774 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18775 +               return -EFAULT;
18776 +       return 0;
18777 +}
18778 +
18779 +
18780 +#ifdef CONFIG_VSERVER_VTIME
18781 +
18782 +/* virtualized time base */
18783 +
18784 +void vx_gettimeofday(struct timeval *tv)
18785 +{
18786 +       do_gettimeofday(tv);
18787 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18788 +               return;
18789 +
18790 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18791 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18792 +
18793 +       if (tv->tv_usec >= USEC_PER_SEC) {
18794 +               tv->tv_sec++;
18795 +               tv->tv_usec -= USEC_PER_SEC;
18796 +       } else if (tv->tv_usec < 0) {
18797 +               tv->tv_sec--;
18798 +               tv->tv_usec += USEC_PER_SEC;
18799 +       }
18800 +}
18801 +
18802 +int vx_settimeofday(struct timespec *ts)
18803 +{
18804 +       struct timeval tv;
18805 +
18806 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18807 +               return do_settimeofday(ts);
18808 +
18809 +       do_gettimeofday(&tv);
18810 +       current->vx_info->cvirt.bias_tv.tv_sec =
18811 +               ts->tv_sec - tv.tv_sec;
18812 +       current->vx_info->cvirt.bias_tv.tv_usec =
18813 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18814 +       return 0;
18815 +}
18816 +
18817 +#endif
18818 +
18819 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/cvirt_init.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cvirt_init.h
18820 --- linux-2.6.27.25/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
18821 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cvirt_init.h    2008-10-13 14:54:20.000000000 +0200
18822 @@ -0,0 +1,69 @@
18823 +
18824 +
18825 +extern uint64_t vx_idle_jiffies(void);
18826 +
18827 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18828 +{
18829 +       uint64_t idle_jiffies = vx_idle_jiffies();
18830 +       uint64_t nsuptime;
18831 +
18832 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18833 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18834 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18835 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18836 +       cvirt->bias_tv.tv_sec = 0;
18837 +       cvirt->bias_tv.tv_usec = 0;
18838 +
18839 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18840 +       atomic_set(&cvirt->nr_threads, 0);
18841 +       atomic_set(&cvirt->nr_running, 0);
18842 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18843 +       atomic_set(&cvirt->nr_onhold, 0);
18844 +
18845 +       spin_lock_init(&cvirt->load_lock);
18846 +       cvirt->load_last = jiffies;
18847 +       atomic_set(&cvirt->load_updates, 0);
18848 +       cvirt->load[0] = 0;
18849 +       cvirt->load[1] = 0;
18850 +       cvirt->load[2] = 0;
18851 +       atomic_set(&cvirt->total_forks, 0);
18852 +
18853 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18854 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18855 +       cvirt->syslog.log_start = 0;
18856 +       cvirt->syslog.log_end = 0;
18857 +       cvirt->syslog.con_start = 0;
18858 +       cvirt->syslog.logged_chars = 0;
18859 +}
18860 +
18861 +static inline
18862 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18863 +{
18864 +       // cvirt_pc->cpustat = { 0 };
18865 +}
18866 +
18867 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18868 +{
18869 +       int value;
18870 +
18871 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18872 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18873 +               cvirt, value);
18874 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18875 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18876 +               cvirt, value);
18877 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18878 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18879 +               cvirt, value);
18880 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18881 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18882 +               cvirt, value);
18883 +       return;
18884 +}
18885 +
18886 +static inline
18887 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18888 +{
18889 +       return;
18890 +}
18891 +
18892 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/cvirt_proc.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cvirt_proc.h
18893 --- linux-2.6.27.25/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
18894 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/cvirt_proc.h    2008-10-13 14:54:20.000000000 +0200
18895 @@ -0,0 +1,135 @@
18896 +#ifndef _VX_CVIRT_PROC_H
18897 +#define _VX_CVIRT_PROC_H
18898 +
18899 +#include <linux/nsproxy.h>
18900 +#include <linux/mnt_namespace.h>
18901 +#include <linux/ipc_namespace.h>
18902 +#include <linux/utsname.h>
18903 +#include <linux/ipc.h>
18904 +
18905 +
18906 +static inline
18907 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18908 +{
18909 +       struct mnt_namespace *ns;
18910 +       struct uts_namespace *uts;
18911 +       struct ipc_namespace *ipc;
18912 +       struct path path;
18913 +       char *pstr, *root;
18914 +       int length = 0;
18915 +
18916 +       if (!nsproxy)
18917 +               goto out;
18918 +
18919 +       length += sprintf(buffer + length,
18920 +               "NSProxy:\t%p [%p,%p,%p]\n",
18921 +               nsproxy, nsproxy->mnt_ns,
18922 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18923 +
18924 +       ns = nsproxy->mnt_ns;
18925 +       if (!ns)
18926 +               goto skip_ns;
18927 +
18928 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18929 +       if (!pstr)
18930 +               goto skip_ns;
18931 +
18932 +       path.mnt = ns->root;
18933 +       path.dentry = ns->root->mnt_root;
18934 +       root = d_path(&path, pstr, PATH_MAX - 2);
18935 +       length += sprintf(buffer + length,
18936 +               "Namespace:\t%p [#%u]\n"
18937 +               "RootPath:\t%s\n",
18938 +               ns, atomic_read(&ns->count),
18939 +               root);
18940 +       kfree(pstr);
18941 +skip_ns:
18942 +
18943 +       uts = nsproxy->uts_ns;
18944 +       if (!uts)
18945 +               goto skip_uts;
18946 +
18947 +       length += sprintf(buffer + length,
18948 +               "SysName:\t%.*s\n"
18949 +               "NodeName:\t%.*s\n"
18950 +               "Release:\t%.*s\n"
18951 +               "Version:\t%.*s\n"
18952 +               "Machine:\t%.*s\n"
18953 +               "DomainName:\t%.*s\n",
18954 +               __NEW_UTS_LEN, uts->name.sysname,
18955 +               __NEW_UTS_LEN, uts->name.nodename,
18956 +               __NEW_UTS_LEN, uts->name.release,
18957 +               __NEW_UTS_LEN, uts->name.version,
18958 +               __NEW_UTS_LEN, uts->name.machine,
18959 +               __NEW_UTS_LEN, uts->name.domainname);
18960 +skip_uts:
18961 +
18962 +       ipc = nsproxy->ipc_ns;
18963 +       if (!ipc)
18964 +               goto skip_ipc;
18965 +
18966 +       length += sprintf(buffer + length,
18967 +               "SEMS:\t\t%d %d %d %d  %d\n"
18968 +               "MSG:\t\t%d %d %d\n"
18969 +               "SHM:\t\t%lu %lu  %d %d\n",
18970 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18971 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18972 +               ipc->used_sems,
18973 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18974 +               (unsigned long)ipc->shm_ctlmax,
18975 +               (unsigned long)ipc->shm_ctlall,
18976 +               ipc->shm_ctlmni, ipc->shm_tot);
18977 +skip_ipc:
18978 +out:
18979 +       return length;
18980 +}
18981 +
18982 +
18983 +#include <linux/sched.h>
18984 +
18985 +#define LOAD_INT(x) ((x) >> FSHIFT)
18986 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18987 +
18988 +static inline
18989 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18990 +{
18991 +       int length = 0;
18992 +       int a, b, c;
18993 +
18994 +       length += sprintf(buffer + length,
18995 +               "BiasUptime:\t%lu.%02lu\n",
18996 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18997 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18998 +
18999 +       a = cvirt->load[0] + (FIXED_1 / 200);
19000 +       b = cvirt->load[1] + (FIXED_1 / 200);
19001 +       c = cvirt->load[2] + (FIXED_1 / 200);
19002 +       length += sprintf(buffer + length,
19003 +               "nr_threads:\t%d\n"
19004 +               "nr_running:\t%d\n"
19005 +               "nr_unintr:\t%d\n"
19006 +               "nr_onhold:\t%d\n"
19007 +               "load_updates:\t%d\n"
19008 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19009 +               "total_forks:\t%d\n",
19010 +               atomic_read(&cvirt->nr_threads),
19011 +               atomic_read(&cvirt->nr_running),
19012 +               atomic_read(&cvirt->nr_uninterruptible),
19013 +               atomic_read(&cvirt->nr_onhold),
19014 +               atomic_read(&cvirt->load_updates),
19015 +               LOAD_INT(a), LOAD_FRAC(a),
19016 +               LOAD_INT(b), LOAD_FRAC(b),
19017 +               LOAD_INT(c), LOAD_FRAC(c),
19018 +               atomic_read(&cvirt->total_forks));
19019 +       return length;
19020 +}
19021 +
19022 +static inline
19023 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19024 +       char *buffer, int cpu)
19025 +{
19026 +       int length = 0;
19027 +       return length;
19028 +}
19029 +
19030 +#endif /* _VX_CVIRT_PROC_H */
19031 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/debug.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/debug.c
19032 --- linux-2.6.27.25/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
19033 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/debug.c 2008-10-13 14:54:20.000000000 +0200
19034 @@ -0,0 +1,32 @@
19035 +/*
19036 + *  kernel/vserver/debug.c
19037 + *
19038 + *  Copyright (C) 2005-2007 Herbert Pötzl
19039 + *
19040 + *  V0.01  vx_info dump support
19041 + *
19042 + */
19043 +
19044 +#include <linux/module.h>
19045 +
19046 +#include <linux/vserver/context.h>
19047 +
19048 +
19049 +void   dump_vx_info(struct vx_info *vxi, int level)
19050 +{
19051 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19052 +               atomic_read(&vxi->vx_usecnt),
19053 +               atomic_read(&vxi->vx_tasks),
19054 +               vxi->vx_state);
19055 +       if (level > 0) {
19056 +               __dump_vx_limit(&vxi->limit);
19057 +               __dump_vx_sched(&vxi->sched);
19058 +               __dump_vx_cvirt(&vxi->cvirt);
19059 +               __dump_vx_cacct(&vxi->cacct);
19060 +       }
19061 +       printk("---\n");
19062 +}
19063 +
19064 +
19065 +EXPORT_SYMBOL_GPL(dump_vx_info);
19066 +
19067 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/device.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/device.c
19068 --- linux-2.6.27.25/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
19069 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/device.c        2008-10-13 14:54:20.000000000 +0200
19070 @@ -0,0 +1,443 @@
19071 +/*
19072 + *  linux/kernel/vserver/device.c
19073 + *
19074 + *  Linux-VServer: Device Support
19075 + *
19076 + *  Copyright (C) 2006  Herbert Pötzl
19077 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19078 + *
19079 + *  V0.01  device mapping basics
19080 + *  V0.02  added defaults
19081 + *
19082 + */
19083 +
19084 +#include <linux/slab.h>
19085 +#include <linux/rcupdate.h>
19086 +#include <linux/fs.h>
19087 +#include <linux/namei.h>
19088 +#include <linux/hash.h>
19089 +
19090 +#include <asm/errno.h>
19091 +#include <asm/uaccess.h>
19092 +#include <linux/vserver/base.h>
19093 +#include <linux/vserver/debug.h>
19094 +#include <linux/vserver/context.h>
19095 +#include <linux/vserver/device.h>
19096 +#include <linux/vserver/device_cmd.h>
19097 +
19098 +
19099 +#define DMAP_HASH_BITS 4
19100 +
19101 +
19102 +struct vs_mapping {
19103 +       union {
19104 +               struct hlist_node hlist;
19105 +               struct list_head list;
19106 +       } u;
19107 +#define dm_hlist       u.hlist
19108 +#define dm_list                u.list
19109 +       xid_t xid;
19110 +       dev_t device;
19111 +       struct vx_dmap_target target;
19112 +};
19113 +
19114 +
19115 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19116 +
19117 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19118 +
19119 +static struct vx_dmap_target dmap_defaults[2] = {
19120 +       { .flags = DATTR_OPEN },
19121 +       { .flags = DATTR_OPEN },
19122 +};
19123 +
19124 +
19125 +struct kmem_cache *dmap_cachep __read_mostly;
19126 +
19127 +int __init dmap_cache_init(void)
19128 +{
19129 +       dmap_cachep = kmem_cache_create("dmap_cache",
19130 +               sizeof(struct vs_mapping), 0,
19131 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19132 +       return 0;
19133 +}
19134 +
19135 +__initcall(dmap_cache_init);
19136 +
19137 +
19138 +static inline unsigned int __hashval(dev_t dev, int bits)
19139 +{
19140 +       return hash_long((unsigned long)dev, bits);
19141 +}
19142 +
19143 +
19144 +/*     __hash_mapping()
19145 + *     add the mapping to the hash table
19146 + */
19147 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19148 +{
19149 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19150 +       struct hlist_head *head, *hash = dmap_main_hash;
19151 +       int device = vdm->device;
19152 +
19153 +       spin_lock(hash_lock);
19154 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19155 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19156 +
19157 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19158 +       hlist_add_head(&vdm->dm_hlist, head);
19159 +       spin_unlock(hash_lock);
19160 +}
19161 +
19162 +
19163 +static inline int __mode_to_default(umode_t mode)
19164 +{
19165 +       switch (mode) {
19166 +       case S_IFBLK:
19167 +               return 0;
19168 +       case S_IFCHR:
19169 +               return 1;
19170 +       default:
19171 +               BUG();
19172 +       }
19173 +}
19174 +
19175 +
19176 +/*     __set_default()
19177 + *     set a default
19178 + */
19179 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19180 +       struct vx_dmap_target *vdmt)
19181 +{
19182 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19183 +       spin_lock(hash_lock);
19184 +
19185 +       if (vxi)
19186 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19187 +       else
19188 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19189 +
19190 +
19191 +       spin_unlock(hash_lock);
19192 +
19193 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19194 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19195 +}
19196 +
19197 +
19198 +/*     __remove_default()
19199 + *     remove a default
19200 + */
19201 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19202 +{
19203 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19204 +       spin_lock(hash_lock);
19205 +
19206 +       if (vxi)
19207 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19208 +       else    /* remove == reset */
19209 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19210 +
19211 +       spin_unlock(hash_lock);
19212 +       return 0;
19213 +}
19214 +
19215 +
19216 +/*     __find_mapping()
19217 + *     find a mapping in the hash table
19218 + *
19219 + *     caller must hold hash_lock
19220 + */
19221 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19222 +       struct vs_mapping **local, struct vs_mapping **global)
19223 +{
19224 +       struct hlist_head *hash = dmap_main_hash;
19225 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19226 +       struct hlist_node *pos;
19227 +       struct vs_mapping *vdm;
19228 +
19229 +       *local = NULL;
19230 +       if (global)
19231 +               *global = NULL;
19232 +
19233 +       hlist_for_each(pos, head) {
19234 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19235 +
19236 +               if ((vdm->device == device) &&
19237 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19238 +                       if (vdm->xid == xid) {
19239 +                               *local = vdm;
19240 +                               return 1;
19241 +                       } else if (global && vdm->xid == 0)
19242 +                               *global = vdm;
19243 +               }
19244 +       }
19245 +
19246 +       if (global && *global)
19247 +               return 0;
19248 +       else
19249 +               return -ENOENT;
19250 +}
19251 +
19252 +
19253 +/*     __lookup_mapping()
19254 + *     find a mapping and store the result in target and flags
19255 + */
19256 +static inline int __lookup_mapping(struct vx_info *vxi,
19257 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19258 +{
19259 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19260 +       struct vs_mapping *vdm, *global;
19261 +       struct vx_dmap_target *vdmt;
19262 +       int ret = 0;
19263 +       xid_t xid = vxi->vx_id;
19264 +       int index;
19265 +
19266 +       spin_lock(hash_lock);
19267 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19268 +               ret = 1;
19269 +               vdmt = &vdm->target;
19270 +               goto found;
19271 +       }
19272 +
19273 +       index = __mode_to_default(mode);
19274 +       if (vxi && vxi->dmap.targets[index].flags) {
19275 +               ret = 2;
19276 +               vdmt = &vxi->dmap.targets[index];
19277 +       } else if (global) {
19278 +               ret = 3;
19279 +               vdmt = &global->target;
19280 +               goto found;
19281 +       } else {
19282 +               ret = 4;
19283 +               vdmt = &dmap_defaults[index];
19284 +       }
19285 +
19286 +found:
19287 +       if (target && (vdmt->flags & DATTR_REMAP))
19288 +               *target = vdmt->target;
19289 +       else if (target)
19290 +               *target = device;
19291 +       if (flags)
19292 +               *flags = vdmt->flags;
19293 +
19294 +       spin_unlock(hash_lock);
19295 +
19296 +       return ret;
19297 +}
19298 +
19299 +
19300 +/*     __remove_mapping()
19301 + *     remove a mapping from the hash table
19302 + */
19303 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19304 +       umode_t mode)
19305 +{
19306 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19307 +       struct vs_mapping *vdm = NULL;
19308 +       int ret = 0;
19309 +
19310 +       spin_lock(hash_lock);
19311 +
19312 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19313 +               NULL);
19314 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19315 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19316 +       if (ret < 0)
19317 +               goto out;
19318 +       hlist_del(&vdm->dm_hlist);
19319 +
19320 +out:
19321 +       spin_unlock(hash_lock);
19322 +       if (vdm)
19323 +               kmem_cache_free(dmap_cachep, vdm);
19324 +       return ret;
19325 +}
19326 +
19327 +
19328 +
19329 +int vs_map_device(struct vx_info *vxi,
19330 +       dev_t device, dev_t *target, umode_t mode)
19331 +{
19332 +       int ret, flags = DATTR_MASK;
19333 +
19334 +       if (!vxi) {
19335 +               if (target)
19336 +                       *target = device;
19337 +               goto out;
19338 +       }
19339 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19340 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19341 +               device, target ? *target : 0, flags, mode, ret);
19342 +out:
19343 +       return (flags & DATTR_MASK);
19344 +}
19345 +
19346 +
19347 +
19348 +static int do_set_mapping(struct vx_info *vxi,
19349 +       dev_t device, dev_t target, int flags, umode_t mode)
19350 +{
19351 +       if (device) {
19352 +               struct vs_mapping *new;
19353 +
19354 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19355 +               if (!new)
19356 +                       return -ENOMEM;
19357 +
19358 +               INIT_HLIST_NODE(&new->dm_hlist);
19359 +               new->device = device;
19360 +               new->target.target = target;
19361 +               new->target.flags = flags | mode;
19362 +               new->xid = (vxi ? vxi->vx_id : 0);
19363 +
19364 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19365 +               __hash_mapping(vxi, new);
19366 +       } else {
19367 +               struct vx_dmap_target new = {
19368 +                       .target = target,
19369 +                       .flags = flags | mode,
19370 +               };
19371 +               __set_default(vxi, mode, &new);
19372 +       }
19373 +       return 0;
19374 +}
19375 +
19376 +
19377 +static int do_unset_mapping(struct vx_info *vxi,
19378 +       dev_t device, dev_t target, int flags, umode_t mode)
19379 +{
19380 +       int ret = -EINVAL;
19381 +
19382 +       if (device) {
19383 +               ret = __remove_mapping(vxi, device, mode);
19384 +               if (ret < 0)
19385 +                       goto out;
19386 +       } else {
19387 +               ret = __remove_default(vxi, mode);
19388 +               if (ret < 0)
19389 +                       goto out;
19390 +       }
19391 +
19392 +out:
19393 +       return ret;
19394 +}
19395 +
19396 +
19397 +static inline int __user_device(const char __user *name, dev_t *dev,
19398 +       umode_t *mode)
19399 +{
19400 +       struct nameidata nd;
19401 +       int ret;
19402 +
19403 +       if (!name) {
19404 +               *dev = 0;
19405 +               return 0;
19406 +       }
19407 +       ret = user_lpath(name, &nd.path);
19408 +       if (ret)
19409 +               return ret;
19410 +       if (nd.path.dentry->d_inode) {
19411 +               *dev = nd.path.dentry->d_inode->i_rdev;
19412 +               *mode = nd.path.dentry->d_inode->i_mode;
19413 +       }
19414 +       path_put(&nd.path);
19415 +       return 0;
19416 +}
19417 +
19418 +static inline int __mapping_mode(dev_t device, dev_t target,
19419 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19420 +{
19421 +       if (device)
19422 +               *mode = device_mode & S_IFMT;
19423 +       else if (target)
19424 +               *mode = target_mode & S_IFMT;
19425 +       else
19426 +               return -EINVAL;
19427 +
19428 +       /* if both given, device and target mode have to match */
19429 +       if (device && target &&
19430 +               ((device_mode ^ target_mode) & S_IFMT))
19431 +               return -EINVAL;
19432 +       return 0;
19433 +}
19434 +
19435 +
19436 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19437 +       const char __user *target_path, int flags, int set)
19438 +{
19439 +       dev_t device = ~0, target = ~0;
19440 +       umode_t device_mode = 0, target_mode = 0, mode;
19441 +       int ret;
19442 +
19443 +       ret = __user_device(device_path, &device, &device_mode);
19444 +       if (ret)
19445 +               return ret;
19446 +       ret = __user_device(target_path, &target, &target_mode);
19447 +       if (ret)
19448 +               return ret;
19449 +
19450 +       ret = __mapping_mode(device, target,
19451 +               device_mode, target_mode, &mode);
19452 +       if (ret)
19453 +               return ret;
19454 +
19455 +       if (set)
19456 +               return do_set_mapping(vxi, device, target,
19457 +                       flags, mode);
19458 +       else
19459 +               return do_unset_mapping(vxi, device, target,
19460 +                       flags, mode);
19461 +}
19462 +
19463 +
19464 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19465 +{
19466 +       struct vcmd_set_mapping_v0 vc_data;
19467 +
19468 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19469 +               return -EFAULT;
19470 +
19471 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19472 +               vc_data.flags, 1);
19473 +}
19474 +
19475 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19476 +{
19477 +       struct vcmd_set_mapping_v0 vc_data;
19478 +
19479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19480 +               return -EFAULT;
19481 +
19482 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19483 +               vc_data.flags, 0);
19484 +}
19485 +
19486 +
19487 +#ifdef CONFIG_COMPAT
19488 +
19489 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19490 +{
19491 +       struct vcmd_set_mapping_v0_x32 vc_data;
19492 +
19493 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19494 +               return -EFAULT;
19495 +
19496 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19497 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19498 +}
19499 +
19500 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19501 +{
19502 +       struct vcmd_set_mapping_v0_x32 vc_data;
19503 +
19504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19505 +               return -EFAULT;
19506 +
19507 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19508 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19509 +}
19510 +
19511 +#endif /* CONFIG_COMPAT */
19512 +
19513 +
19514 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/dlimit.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/dlimit.c
19515 --- linux-2.6.27.25/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
19516 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/dlimit.c        2008-10-13 14:54:20.000000000 +0200
19517 @@ -0,0 +1,522 @@
19518 +/*
19519 + *  linux/kernel/vserver/dlimit.c
19520 + *
19521 + *  Virtual Server: Context Disk Limits
19522 + *
19523 + *  Copyright (C) 2004-2007  Herbert Pötzl
19524 + *
19525 + *  V0.01  initial version
19526 + *  V0.02  compat32 splitup
19527 + *
19528 + */
19529 +
19530 +#include <linux/statfs.h>
19531 +#include <linux/sched.h>
19532 +#include <linux/namei.h>
19533 +#include <linux/vs_tag.h>
19534 +#include <linux/vs_dlimit.h>
19535 +#include <linux/vserver/dlimit_cmd.h>
19536 +
19537 +#include <asm/uaccess.h>
19538 +
19539 +/*     __alloc_dl_info()
19540 +
19541 +       * allocate an initialized dl_info struct
19542 +       * doesn't make it visible (hash)                        */
19543 +
19544 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19545 +{
19546 +       struct dl_info *new = NULL;
19547 +
19548 +       vxdprintk(VXD_CBIT(dlim, 5),
19549 +               "alloc_dl_info(%p,%d)*", sb, tag);
19550 +
19551 +       /* would this benefit from a slab cache? */
19552 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19553 +       if (!new)
19554 +               return 0;
19555 +
19556 +       memset(new, 0, sizeof(struct dl_info));
19557 +       new->dl_tag = tag;
19558 +       new->dl_sb = sb;
19559 +       INIT_RCU_HEAD(&new->dl_rcu);
19560 +       INIT_HLIST_NODE(&new->dl_hlist);
19561 +       spin_lock_init(&new->dl_lock);
19562 +       atomic_set(&new->dl_refcnt, 0);
19563 +       atomic_set(&new->dl_usecnt, 0);
19564 +
19565 +       /* rest of init goes here */
19566 +
19567 +       vxdprintk(VXD_CBIT(dlim, 4),
19568 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19569 +       return new;
19570 +}
19571 +
19572 +/*     __dealloc_dl_info()
19573 +
19574 +       * final disposal of dl_info                             */
19575 +
19576 +static void __dealloc_dl_info(struct dl_info *dli)
19577 +{
19578 +       vxdprintk(VXD_CBIT(dlim, 4),
19579 +               "dealloc_dl_info(%p)", dli);
19580 +
19581 +       dli->dl_hlist.next = LIST_POISON1;
19582 +       dli->dl_tag = -1;
19583 +       dli->dl_sb = 0;
19584 +
19585 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19586 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19587 +
19588 +       kfree(dli);
19589 +}
19590 +
19591 +
19592 +/*     hash table for dl_info hash */
19593 +
19594 +#define DL_HASH_SIZE   13
19595 +
19596 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19597 +
19598 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19599 +
19600 +
19601 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19602 +{
19603 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19604 +}
19605 +
19606 +
19607 +
19608 +/*     __hash_dl_info()
19609 +
19610 +       * add the dli to the global hash table
19611 +       * requires the hash_lock to be held                     */
19612 +
19613 +static inline void __hash_dl_info(struct dl_info *dli)
19614 +{
19615 +       struct hlist_head *head;
19616 +
19617 +       vxdprintk(VXD_CBIT(dlim, 6),
19618 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19619 +       get_dl_info(dli);
19620 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19621 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19622 +}
19623 +
19624 +/*     __unhash_dl_info()
19625 +
19626 +       * remove the dli from the global hash table
19627 +       * requires the hash_lock to be held                     */
19628 +
19629 +static inline void __unhash_dl_info(struct dl_info *dli)
19630 +{
19631 +       vxdprintk(VXD_CBIT(dlim, 6),
19632 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19633 +       hlist_del_rcu(&dli->dl_hlist);
19634 +       put_dl_info(dli);
19635 +}
19636 +
19637 +
19638 +/*     __lookup_dl_info()
19639 +
19640 +       * requires the rcu_read_lock()
19641 +       * doesn't increment the dl_refcnt                       */
19642 +
19643 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19644 +{
19645 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19646 +       struct hlist_node *pos;
19647 +       struct dl_info *dli;
19648 +
19649 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19650 +
19651 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19652 +                       return dli;
19653 +               }
19654 +       }
19655 +       return NULL;
19656 +}
19657 +
19658 +
19659 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19660 +{
19661 +       struct dl_info *dli;
19662 +
19663 +       rcu_read_lock();
19664 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19665 +       vxdprintk(VXD_CBIT(dlim, 7),
19666 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19667 +       rcu_read_unlock();
19668 +       return dli;
19669 +}
19670 +
19671 +void rcu_free_dl_info(struct rcu_head *head)
19672 +{
19673 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19674 +       int usecnt, refcnt;
19675 +
19676 +       BUG_ON(!dli || !head);
19677 +
19678 +       usecnt = atomic_read(&dli->dl_usecnt);
19679 +       BUG_ON(usecnt < 0);
19680 +
19681 +       refcnt = atomic_read(&dli->dl_refcnt);
19682 +       BUG_ON(refcnt < 0);
19683 +
19684 +       vxdprintk(VXD_CBIT(dlim, 3),
19685 +               "rcu_free_dl_info(%p)", dli);
19686 +       if (!usecnt)
19687 +               __dealloc_dl_info(dli);
19688 +       else
19689 +               printk("!!! rcu didn't free\n");
19690 +}
19691 +
19692 +
19693 +
19694 +
19695 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19696 +       uint32_t flags, int add)
19697 +{
19698 +       struct path path;
19699 +       int ret;
19700 +
19701 +       ret = user_lpath(name, &path);
19702 +       if (!ret) {
19703 +               struct super_block *sb;
19704 +               struct dl_info *dli;
19705 +
19706 +               ret = -EINVAL;
19707 +               if (!path.dentry->d_inode)
19708 +                       goto out_release;
19709 +               if (!(sb = path.dentry->d_inode->i_sb))
19710 +                       goto out_release;
19711 +
19712 +               if (add) {
19713 +                       dli = __alloc_dl_info(sb, id);
19714 +                       spin_lock(&dl_info_hash_lock);
19715 +
19716 +                       ret = -EEXIST;
19717 +                       if (__lookup_dl_info(sb, id))
19718 +                               goto out_unlock;
19719 +                       __hash_dl_info(dli);
19720 +                       dli = NULL;
19721 +               } else {
19722 +                       spin_lock(&dl_info_hash_lock);
19723 +                       dli = __lookup_dl_info(sb, id);
19724 +
19725 +                       ret = -ESRCH;
19726 +                       if (!dli)
19727 +                               goto out_unlock;
19728 +                       __unhash_dl_info(dli);
19729 +               }
19730 +               ret = 0;
19731 +       out_unlock:
19732 +               spin_unlock(&dl_info_hash_lock);
19733 +               if (add && dli)
19734 +                       __dealloc_dl_info(dli);
19735 +       out_release:
19736 +               path_put(&path);
19737 +       }
19738 +       return ret;
19739 +}
19740 +
19741 +int vc_add_dlimit(uint32_t id, void __user *data)
19742 +{
19743 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19744 +
19745 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19746 +               return -EFAULT;
19747 +
19748 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19749 +}
19750 +
19751 +int vc_rem_dlimit(uint32_t id, void __user *data)
19752 +{
19753 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19754 +
19755 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19756 +               return -EFAULT;
19757 +
19758 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19759 +}
19760 +
19761 +#ifdef CONFIG_COMPAT
19762 +
19763 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19764 +{
19765 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19766 +
19767 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19768 +               return -EFAULT;
19769 +
19770 +       return do_addrem_dlimit(id,
19771 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19772 +}
19773 +
19774 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19775 +{
19776 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19777 +
19778 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19779 +               return -EFAULT;
19780 +
19781 +       return do_addrem_dlimit(id,
19782 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19783 +}
19784 +
19785 +#endif /* CONFIG_COMPAT */
19786 +
19787 +
19788 +static inline
19789 +int do_set_dlimit(uint32_t id, const char __user *name,
19790 +       uint32_t space_used, uint32_t space_total,
19791 +       uint32_t inodes_used, uint32_t inodes_total,
19792 +       uint32_t reserved, uint32_t flags)
19793 +{
19794 +       struct path path;
19795 +       int ret;
19796 +
19797 +       ret = user_lpath(name, &path);
19798 +       if (!ret) {
19799 +               struct super_block *sb;
19800 +               struct dl_info *dli;
19801 +
19802 +               ret = -EINVAL;
19803 +               if (!path.dentry->d_inode)
19804 +                       goto out_release;
19805 +               if (!(sb = path.dentry->d_inode->i_sb))
19806 +                       goto out_release;
19807 +               if ((reserved != CDLIM_KEEP &&
19808 +                       reserved > 100) ||
19809 +                       (inodes_used != CDLIM_KEEP &&
19810 +                       inodes_used > inodes_total) ||
19811 +                       (space_used != CDLIM_KEEP &&
19812 +                       space_used > space_total))
19813 +                       goto out_release;
19814 +
19815 +               ret = -ESRCH;
19816 +               dli = locate_dl_info(sb, id);
19817 +               if (!dli)
19818 +                       goto out_release;
19819 +
19820 +               spin_lock(&dli->dl_lock);
19821 +
19822 +               if (inodes_used != CDLIM_KEEP)
19823 +                       dli->dl_inodes_used = inodes_used;
19824 +               if (inodes_total != CDLIM_KEEP)
19825 +                       dli->dl_inodes_total = inodes_total;
19826 +               if (space_used != CDLIM_KEEP) {
19827 +                       dli->dl_space_used = space_used;
19828 +                       dli->dl_space_used <<= 10;
19829 +               }
19830 +               if (space_total == CDLIM_INFINITY)
19831 +                       dli->dl_space_total = DLIM_INFINITY;
19832 +               else if (space_total != CDLIM_KEEP) {
19833 +                       dli->dl_space_total = space_total;
19834 +                       dli->dl_space_total <<= 10;
19835 +               }
19836 +               if (reserved != CDLIM_KEEP)
19837 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19838 +
19839 +               spin_unlock(&dli->dl_lock);
19840 +
19841 +               put_dl_info(dli);
19842 +               ret = 0;
19843 +
19844 +       out_release:
19845 +               path_put(&path);
19846 +       }
19847 +       return ret;
19848 +}
19849 +
19850 +int vc_set_dlimit(uint32_t id, void __user *data)
19851 +{
19852 +       struct vcmd_ctx_dlimit_v0 vc_data;
19853 +
19854 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19855 +               return -EFAULT;
19856 +
19857 +       return do_set_dlimit(id, vc_data.name,
19858 +               vc_data.space_used, vc_data.space_total,
19859 +               vc_data.inodes_used, vc_data.inodes_total,
19860 +               vc_data.reserved, vc_data.flags);
19861 +}
19862 +
19863 +#ifdef CONFIG_COMPAT
19864 +
19865 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19866 +{
19867 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19868 +
19869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19870 +               return -EFAULT;
19871 +
19872 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19873 +               vc_data.space_used, vc_data.space_total,
19874 +               vc_data.inodes_used, vc_data.inodes_total,
19875 +               vc_data.reserved, vc_data.flags);
19876 +}
19877 +
19878 +#endif /* CONFIG_COMPAT */
19879 +
19880 +
19881 +static inline
19882 +int do_get_dlimit(uint32_t id, const char __user *name,
19883 +       uint32_t *space_used, uint32_t *space_total,
19884 +       uint32_t *inodes_used, uint32_t *inodes_total,
19885 +       uint32_t *reserved, uint32_t *flags)
19886 +{
19887 +       struct path path;
19888 +       int ret;
19889 +
19890 +       ret = user_lpath(name, &path);
19891 +       if (!ret) {
19892 +               struct super_block *sb;
19893 +               struct dl_info *dli;
19894 +
19895 +               ret = -EINVAL;
19896 +               if (!path.dentry->d_inode)
19897 +                       goto out_release;
19898 +               if (!(sb = path.dentry->d_inode->i_sb))
19899 +                       goto out_release;
19900 +
19901 +               ret = -ESRCH;
19902 +               dli = locate_dl_info(sb, id);
19903 +               if (!dli)
19904 +                       goto out_release;
19905 +
19906 +               spin_lock(&dli->dl_lock);
19907 +               *inodes_used = dli->dl_inodes_used;
19908 +               *inodes_total = dli->dl_inodes_total;
19909 +               *space_used = dli->dl_space_used >> 10;
19910 +               if (dli->dl_space_total == DLIM_INFINITY)
19911 +                       *space_total = CDLIM_INFINITY;
19912 +               else
19913 +                       *space_total = dli->dl_space_total >> 10;
19914 +
19915 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19916 +               spin_unlock(&dli->dl_lock);
19917 +
19918 +               put_dl_info(dli);
19919 +               ret = -EFAULT;
19920 +
19921 +               ret = 0;
19922 +       out_release:
19923 +               path_put(&path);
19924 +       }
19925 +       return ret;
19926 +}
19927 +
19928 +
19929 +int vc_get_dlimit(uint32_t id, void __user *data)
19930 +{
19931 +       struct vcmd_ctx_dlimit_v0 vc_data;
19932 +       int ret;
19933 +
19934 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19935 +               return -EFAULT;
19936 +
19937 +       ret = do_get_dlimit(id, vc_data.name,
19938 +               &vc_data.space_used, &vc_data.space_total,
19939 +               &vc_data.inodes_used, &vc_data.inodes_total,
19940 +               &vc_data.reserved, &vc_data.flags);
19941 +       if (ret)
19942 +               return ret;
19943 +
19944 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19945 +               return -EFAULT;
19946 +       return 0;
19947 +}
19948 +
19949 +#ifdef CONFIG_COMPAT
19950 +
19951 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19952 +{
19953 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19954 +       int ret;
19955 +
19956 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19957 +               return -EFAULT;
19958 +
19959 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19960 +               &vc_data.space_used, &vc_data.space_total,
19961 +               &vc_data.inodes_used, &vc_data.inodes_total,
19962 +               &vc_data.reserved, &vc_data.flags);
19963 +       if (ret)
19964 +               return ret;
19965 +
19966 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19967 +               return -EFAULT;
19968 +       return 0;
19969 +}
19970 +
19971 +#endif /* CONFIG_COMPAT */
19972 +
19973 +
19974 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19975 +{
19976 +       struct dl_info *dli;
19977 +       __u64 blimit, bfree, bavail;
19978 +       __u32 ifree;
19979 +
19980 +       dli = locate_dl_info(sb, dx_current_tag());
19981 +       if (!dli)
19982 +               return;
19983 +
19984 +       spin_lock(&dli->dl_lock);
19985 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19986 +               goto no_ilim;
19987 +
19988 +       /* reduce max inodes available to limit */
19989 +       if (buf->f_files > dli->dl_inodes_total)
19990 +               buf->f_files = dli->dl_inodes_total;
19991 +
19992 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19993 +       /* reduce free inodes to min */
19994 +       if (ifree < buf->f_ffree)
19995 +               buf->f_ffree = ifree;
19996 +
19997 +no_ilim:
19998 +       if (dli->dl_space_total == DLIM_INFINITY)
19999 +               goto no_blim;
20000 +
20001 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20002 +
20003 +       if (dli->dl_space_total < dli->dl_space_used)
20004 +               bfree = 0;
20005 +       else
20006 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20007 +                       >> sb->s_blocksize_bits;
20008 +
20009 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20010 +       if (bavail < dli->dl_space_used)
20011 +               bavail = 0;
20012 +       else
20013 +               bavail = (bavail - dli->dl_space_used)
20014 +                       >> sb->s_blocksize_bits;
20015 +
20016 +       /* reduce max space available to limit */
20017 +       if (buf->f_blocks > blimit)
20018 +               buf->f_blocks = blimit;
20019 +
20020 +       /* reduce free space to min */
20021 +       if (bfree < buf->f_bfree)
20022 +               buf->f_bfree = bfree;
20023 +
20024 +       /* reduce avail space to min */
20025 +       if (bavail < buf->f_bavail)
20026 +               buf->f_bavail = bavail;
20027 +
20028 +no_blim:
20029 +       spin_unlock(&dli->dl_lock);
20030 +       put_dl_info(dli);
20031 +
20032 +       return;
20033 +}
20034 +
20035 +#include <linux/module.h>
20036 +
20037 +EXPORT_SYMBOL_GPL(locate_dl_info);
20038 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20039 +
20040 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/helper.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/helper.c
20041 --- linux-2.6.27.25/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
20042 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/helper.c        2008-10-13 14:54:20.000000000 +0200
20043 @@ -0,0 +1,199 @@
20044 +/*
20045 + *  linux/kernel/vserver/helper.c
20046 + *
20047 + *  Virtual Context Support
20048 + *
20049 + *  Copyright (C) 2004-2007  Herbert Pötzl
20050 + *
20051 + *  V0.01  basic helper
20052 + *
20053 + */
20054 +
20055 +#include <linux/kmod.h>
20056 +#include <linux/reboot.h>
20057 +#include <linux/vs_context.h>
20058 +#include <linux/vs_network.h>
20059 +#include <linux/vserver/signal.h>
20060 +
20061 +
20062 +char vshelper_path[255] = "/sbin/vshelper";
20063 +
20064 +
20065 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20066 +{
20067 +       int ret;
20068 +
20069 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20070 +               printk( KERN_WARNING
20071 +                       "%s: (%s %s) returned %s with %d\n",
20072 +                       name, argv[1], argv[2],
20073 +                       sync ? "sync" : "async", ret);
20074 +       }
20075 +       vxdprintk(VXD_CBIT(switch, 4),
20076 +               "%s: (%s %s) returned %s with %d",
20077 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20078 +       return ret;
20079 +}
20080 +
20081 +/*
20082 + *      vshelper path is set via /proc/sys
20083 + *      invoked by vserver sys_reboot(), with
20084 + *      the following arguments
20085 + *
20086 + *      argv [0] = vshelper_path;
20087 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20088 + *      argv [2] = context identifier
20089 + *
20090 + *      envp [*] = type-specific parameters
20091 + */
20092 +
20093 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20094 +{
20095 +       char id_buf[8], cmd_buf[16];
20096 +       char uid_buf[16], pid_buf[16];
20097 +       int ret;
20098 +
20099 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20100 +       char *envp[] = {"HOME=/", "TERM=linux",
20101 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20102 +                       uid_buf, pid_buf, cmd_buf, 0};
20103 +
20104 +       if (vx_info_state(vxi, VXS_HELPER))
20105 +               return -EAGAIN;
20106 +       vxi->vx_state |= VXS_HELPER;
20107 +
20108 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20109 +
20110 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20111 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
20112 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20113 +
20114 +       switch (cmd) {
20115 +       case LINUX_REBOOT_CMD_RESTART:
20116 +               argv[1] = "restart";
20117 +               break;
20118 +
20119 +       case LINUX_REBOOT_CMD_HALT:
20120 +               argv[1] = "halt";
20121 +               break;
20122 +
20123 +       case LINUX_REBOOT_CMD_POWER_OFF:
20124 +               argv[1] = "poweroff";
20125 +               break;
20126 +
20127 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20128 +               argv[1] = "swsusp";
20129 +               break;
20130 +
20131 +       default:
20132 +               vxi->vx_state &= ~VXS_HELPER;
20133 +               return 0;
20134 +       }
20135 +
20136 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20137 +       vxi->vx_state &= ~VXS_HELPER;
20138 +       __wakeup_vx_info(vxi);
20139 +       return (ret) ? -EPERM : 0;
20140 +}
20141 +
20142 +
20143 +long vs_reboot(unsigned int cmd, void __user *arg)
20144 +{
20145 +       struct vx_info *vxi = current->vx_info;
20146 +       long ret = 0;
20147 +
20148 +       vxdprintk(VXD_CBIT(misc, 5),
20149 +               "vs_reboot(%p[#%d],%d)",
20150 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20151 +
20152 +       ret = vs_reboot_helper(vxi, cmd, arg);
20153 +       if (ret)
20154 +               return ret;
20155 +
20156 +       vxi->reboot_cmd = cmd;
20157 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20158 +               switch (cmd) {
20159 +               case LINUX_REBOOT_CMD_RESTART:
20160 +               case LINUX_REBOOT_CMD_HALT:
20161 +               case LINUX_REBOOT_CMD_POWER_OFF:
20162 +                       vx_info_kill(vxi, 0, SIGKILL);
20163 +                       vx_info_kill(vxi, 1, SIGKILL);
20164 +               default:
20165 +                       break;
20166 +               }
20167 +       }
20168 +       return 0;
20169 +}
20170 +
20171 +
20172 +/*
20173 + *      argv [0] = vshelper_path;
20174 + *      argv [1] = action: "startup", "shutdown"
20175 + *      argv [2] = context identifier
20176 + *
20177 + *      envp [*] = type-specific parameters
20178 + */
20179 +
20180 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20181 +{
20182 +       char id_buf[8], cmd_buf[16];
20183 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20184 +       char *envp[] = {"HOME=/", "TERM=linux",
20185 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20186 +
20187 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20188 +               return 0;
20189 +
20190 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20191 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20192 +
20193 +       switch (cmd) {
20194 +       case VSC_STARTUP:
20195 +               argv[1] = "startup";
20196 +               break;
20197 +       case VSC_SHUTDOWN:
20198 +               argv[1] = "shutdown";
20199 +               break;
20200 +       default:
20201 +               return 0;
20202 +       }
20203 +
20204 +       return do_vshelper(vshelper_path, argv, envp, 1);
20205 +}
20206 +
20207 +
20208 +/*
20209 + *      argv [0] = vshelper_path;
20210 + *      argv [1] = action: "netup", "netdown"
20211 + *      argv [2] = context identifier
20212 + *
20213 + *      envp [*] = type-specific parameters
20214 + */
20215 +
20216 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20217 +{
20218 +       char id_buf[8], cmd_buf[16];
20219 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20220 +       char *envp[] = {"HOME=/", "TERM=linux",
20221 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20222 +
20223 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20224 +               return 0;
20225 +
20226 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20227 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20228 +
20229 +       switch (cmd) {
20230 +       case VSC_NETUP:
20231 +               argv[1] = "netup";
20232 +               break;
20233 +       case VSC_NETDOWN:
20234 +               argv[1] = "netdown";
20235 +               break;
20236 +       default:
20237 +               return 0;
20238 +       }
20239 +
20240 +       return do_vshelper(vshelper_path, argv, envp, 1);
20241 +}
20242 +
20243 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/history.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/history.c
20244 --- linux-2.6.27.25/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
20245 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/history.c       2008-10-13 14:54:20.000000000 +0200
20246 @@ -0,0 +1,258 @@
20247 +/*
20248 + *  kernel/vserver/history.c
20249 + *
20250 + *  Virtual Context History Backtrace
20251 + *
20252 + *  Copyright (C) 2004-2007  Herbert Pötzl
20253 + *
20254 + *  V0.01  basic structure
20255 + *  V0.02  hash/unhash and trace
20256 + *  V0.03  preemption fixes
20257 + *
20258 + */
20259 +
20260 +#include <linux/module.h>
20261 +#include <asm/uaccess.h>
20262 +
20263 +#include <linux/vserver/context.h>
20264 +#include <linux/vserver/debug.h>
20265 +#include <linux/vserver/debug_cmd.h>
20266 +#include <linux/vserver/history.h>
20267 +
20268 +
20269 +#ifdef CONFIG_VSERVER_HISTORY
20270 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20271 +#else
20272 +#define VXH_SIZE       64
20273 +#endif
20274 +
20275 +struct _vx_history {
20276 +       unsigned int counter;
20277 +
20278 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20279 +};
20280 +
20281 +
20282 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20283 +
20284 +unsigned volatile int vxh_active = 1;
20285 +
20286 +static atomic_t sequence = ATOMIC_INIT(0);
20287 +
20288 +
20289 +/*     vxh_advance()
20290 +
20291 +       * requires disabled preemption                          */
20292 +
20293 +struct _vx_hist_entry *vxh_advance(void *loc)
20294 +{
20295 +       unsigned int cpu = smp_processor_id();
20296 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20297 +       struct _vx_hist_entry *entry;
20298 +       unsigned int index;
20299 +
20300 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20301 +       entry = &hist->entry[index];
20302 +
20303 +       entry->seq = atomic_inc_return(&sequence);
20304 +       entry->loc = loc;
20305 +       return entry;
20306 +}
20307 +
20308 +EXPORT_SYMBOL_GPL(vxh_advance);
20309 +
20310 +
20311 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20312 +
20313 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20314 +
20315 +
20316 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20317 +
20318 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20319 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20320 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20321 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20322 +
20323 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20324 +{
20325 +       switch (e->type) {
20326 +       case VXH_THROW_OOPS:
20327 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20328 +               break;
20329 +
20330 +       case VXH_GET_VX_INFO:
20331 +       case VXH_PUT_VX_INFO:
20332 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20333 +                       VXH_LOC_ARGS(e),
20334 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20335 +                       VXH_VXI_ARGS(e));
20336 +               break;
20337 +
20338 +       case VXH_INIT_VX_INFO:
20339 +       case VXH_SET_VX_INFO:
20340 +       case VXH_CLR_VX_INFO:
20341 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20342 +                       VXH_LOC_ARGS(e),
20343 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20344 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20345 +                       VXH_VXI_ARGS(e), e->sc.data);
20346 +               break;
20347 +
20348 +       case VXH_CLAIM_VX_INFO:
20349 +       case VXH_RELEASE_VX_INFO:
20350 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20351 +                       VXH_LOC_ARGS(e),
20352 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20353 +                       VXH_VXI_ARGS(e), e->sc.data);
20354 +               break;
20355 +
20356 +       case VXH_ALLOC_VX_INFO:
20357 +       case VXH_DEALLOC_VX_INFO:
20358 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20359 +                       VXH_LOC_ARGS(e),
20360 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20361 +                       VXH_VXI_ARGS(e));
20362 +               break;
20363 +
20364 +       case VXH_HASH_VX_INFO:
20365 +       case VXH_UNHASH_VX_INFO:
20366 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20367 +                       VXH_LOC_ARGS(e),
20368 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20369 +                       VXH_VXI_ARGS(e));
20370 +               break;
20371 +
20372 +       case VXH_LOC_VX_INFO:
20373 +       case VXH_LOOKUP_VX_INFO:
20374 +       case VXH_CREATE_VX_INFO:
20375 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20376 +                       VXH_LOC_ARGS(e),
20377 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20378 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20379 +                       e->ll.arg, VXH_VXI_ARGS(e));
20380 +               break;
20381 +       }
20382 +}
20383 +
20384 +static void __vxh_dump_history(void)
20385 +{
20386 +       unsigned int i, cpu;
20387 +
20388 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20389 +               atomic_read(&sequence), NR_CPUS);
20390 +
20391 +       for (i = 0; i < VXH_SIZE; i++) {
20392 +               for_each_online_cpu(cpu) {
20393 +                       struct _vx_history *hist =
20394 +                               &per_cpu(vx_history_buffer, cpu);
20395 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20396 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20397 +
20398 +                       vxh_dump_entry(entry, cpu);
20399 +               }
20400 +       }
20401 +}
20402 +
20403 +void   vxh_dump_history(void)
20404 +{
20405 +       vxh_active = 0;
20406 +#ifdef CONFIG_SMP
20407 +       local_irq_enable();
20408 +       smp_send_stop();
20409 +       local_irq_disable();
20410 +#endif
20411 +       __vxh_dump_history();
20412 +}
20413 +
20414 +
20415 +/* vserver syscall commands below here */
20416 +
20417 +
20418 +int vc_dump_history(uint32_t id)
20419 +{
20420 +       vxh_active = 0;
20421 +       __vxh_dump_history();
20422 +       vxh_active = 1;
20423 +
20424 +       return 0;
20425 +}
20426 +
20427 +
20428 +int do_read_history(struct __user _vx_hist_entry *data,
20429 +       int cpu, uint32_t *index, uint32_t *count)
20430 +{
20431 +       int pos, ret = 0;
20432 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20433 +       int end = hist->counter;
20434 +       int start = end - VXH_SIZE + 2;
20435 +       int idx = *index;
20436 +
20437 +       /* special case: get current pos */
20438 +       if (!*count) {
20439 +               *index = end;
20440 +               return 0;
20441 +       }
20442 +
20443 +       /* have we lost some data? */
20444 +       if (idx < start)
20445 +               idx = start;
20446 +
20447 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20448 +               struct _vx_hist_entry *entry =
20449 +                       &hist->entry[idx % VXH_SIZE];
20450 +
20451 +               /* send entry to userspace */
20452 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20453 +               if (ret)
20454 +                       break;
20455 +       }
20456 +       /* save new index and count */
20457 +       *index = idx;
20458 +       *count = pos;
20459 +       return ret ? ret : (*index < end);
20460 +}
20461 +
20462 +int vc_read_history(uint32_t id, void __user *data)
20463 +{
20464 +       struct vcmd_read_history_v0 vc_data;
20465 +       int ret;
20466 +
20467 +       if (id >= NR_CPUS)
20468 +               return -EINVAL;
20469 +
20470 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20471 +               return -EFAULT;
20472 +
20473 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20474 +               id, &vc_data.index, &vc_data.count);
20475 +
20476 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20477 +               return -EFAULT;
20478 +       return ret;
20479 +}
20480 +
20481 +#ifdef CONFIG_COMPAT
20482 +
20483 +int vc_read_history_x32(uint32_t id, void __user *data)
20484 +{
20485 +       struct vcmd_read_history_v0_x32 vc_data;
20486 +       int ret;
20487 +
20488 +       if (id >= NR_CPUS)
20489 +               return -EINVAL;
20490 +
20491 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20492 +               return -EFAULT;
20493 +
20494 +       ret = do_read_history((struct __user _vx_hist_entry *)
20495 +               compat_ptr(vc_data.data_ptr),
20496 +               id, &vc_data.index, &vc_data.count);
20497 +
20498 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20499 +               return -EFAULT;
20500 +       return ret;
20501 +}
20502 +
20503 +#endif /* CONFIG_COMPAT */
20504 +
20505 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/inet.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/inet.c
20506 --- linux-2.6.27.25/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
20507 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/inet.c  2008-10-13 14:54:20.000000000 +0200
20508 @@ -0,0 +1,225 @@
20509 +
20510 +#include <linux/in.h>
20511 +#include <linux/inetdevice.h>
20512 +#include <linux/vs_inet.h>
20513 +#include <linux/vs_inet6.h>
20514 +#include <linux/vserver/debug.h>
20515 +#include <net/route.h>
20516 +#include <net/addrconf.h>
20517 +
20518 +
20519 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20520 +{
20521 +       int ret = 0;
20522 +
20523 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20524 +               ret = 1;
20525 +       else {
20526 +               struct nx_addr_v4 *ptr;
20527 +
20528 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20529 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20530 +                               ret = 1;
20531 +                               break;
20532 +                       }
20533 +               }
20534 +       }
20535 +
20536 +       vxdprintk(VXD_CBIT(net, 2),
20537 +               "nx_v4_addr_conflict(%p,%p): %d",
20538 +               nxi1, nxi2, ret);
20539 +
20540 +       return ret;
20541 +}
20542 +
20543 +
20544 +#ifdef CONFIG_IPV6
20545 +
20546 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20547 +{
20548 +       int ret = 0;
20549 +
20550 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20551 +               ret = 1;
20552 +       else {
20553 +               struct nx_addr_v6 *ptr;
20554 +
20555 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20556 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20557 +                               ret = 1;
20558 +                               break;
20559 +                       }
20560 +               }
20561 +       }
20562 +
20563 +       vxdprintk(VXD_CBIT(net, 2),
20564 +               "nx_v6_addr_conflict(%p,%p): %d",
20565 +               nxi1, nxi2, ret);
20566 +
20567 +       return ret;
20568 +}
20569 +
20570 +#endif
20571 +
20572 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20573 +{
20574 +       struct in_device *in_dev;
20575 +       struct in_ifaddr **ifap;
20576 +       struct in_ifaddr *ifa;
20577 +       int ret = 0;
20578 +
20579 +       if (!dev)
20580 +               goto out;
20581 +       in_dev = in_dev_get(dev);
20582 +       if (!in_dev)
20583 +               goto out;
20584 +
20585 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20586 +               ifap = &ifa->ifa_next) {
20587 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20588 +                       ret = 1;
20589 +                       break;
20590 +               }
20591 +       }
20592 +       in_dev_put(in_dev);
20593 +out:
20594 +       return ret;
20595 +}
20596 +
20597 +
20598 +#ifdef CONFIG_IPV6
20599 +
20600 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20601 +{
20602 +       struct inet6_dev *in_dev;
20603 +       struct inet6_ifaddr **ifap;
20604 +       struct inet6_ifaddr *ifa;
20605 +       int ret = 0;
20606 +
20607 +       if (!dev)
20608 +               goto out;
20609 +       in_dev = in6_dev_get(dev);
20610 +       if (!in_dev)
20611 +               goto out;
20612 +
20613 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20614 +               ifap = &ifa->if_next) {
20615 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20616 +                       ret = 1;
20617 +                       break;
20618 +               }
20619 +       }
20620 +       in6_dev_put(in_dev);
20621 +out:
20622 +       return ret;
20623 +}
20624 +
20625 +#endif
20626 +
20627 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20628 +{
20629 +       int ret = 1;
20630 +
20631 +       if (!nxi)
20632 +               goto out;
20633 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20634 +               goto out;
20635 +#ifdef CONFIG_IPV6
20636 +       ret = 2;
20637 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20638 +               goto out;
20639 +#endif
20640 +       ret = 0;
20641 +out:
20642 +       vxdprintk(VXD_CBIT(net, 3),
20643 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20644 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20645 +       return ret;
20646 +}
20647 +
20648 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20649 +       struct rtable **rp, struct flowi *fl)
20650 +{
20651 +       if (!nxi)
20652 +               return 0;
20653 +
20654 +       /* FIXME: handle lback only case */
20655 +       if (!NX_IPV4(nxi))
20656 +               return -EPERM;
20657 +
20658 +       vxdprintk(VXD_CBIT(net, 4),
20659 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20660 +               nxi, nxi ? nxi->nx_id : 0,
20661 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20662 +
20663 +       /* single IP is unconditional */
20664 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20665 +               (fl->fl4_src == INADDR_ANY))
20666 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20667 +
20668 +       if (fl->fl4_src == INADDR_ANY) {
20669 +               struct nx_addr_v4 *ptr;
20670 +               __be32 found = 0;
20671 +               int err;
20672 +
20673 +               err = __ip_route_output_key(net, rp, fl);
20674 +               if (!err) {
20675 +                       found = (*rp)->rt_src;
20676 +                       ip_rt_put(*rp);
20677 +                       vxdprintk(VXD_CBIT(net, 4),
20678 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20679 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20680 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20681 +                               goto found;
20682 +               }
20683 +
20684 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20685 +                       __be32 primary = ptr->ip[0].s_addr;
20686 +                       __be32 mask = ptr->mask.s_addr;
20687 +                       __be32 neta = primary & mask;
20688 +
20689 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20690 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20691 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20692 +                               NIPQUAD(mask), NIPQUAD(neta));
20693 +                       if ((found & mask) != neta)
20694 +                               continue;
20695 +
20696 +                       fl->fl4_src = primary;
20697 +                       err = __ip_route_output_key(net, rp, fl);
20698 +                       vxdprintk(VXD_CBIT(net, 4),
20699 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20700 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20701 +                       if (!err) {
20702 +                               found = (*rp)->rt_src;
20703 +                               ip_rt_put(*rp);
20704 +                               if (found == primary)
20705 +                                       goto found;
20706 +                       }
20707 +               }
20708 +               /* still no source ip? */
20709 +               found = ipv4_is_loopback(fl->fl4_dst)
20710 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20711 +       found:
20712 +               /* assign src ip to flow */
20713 +               fl->fl4_src = found;
20714 +
20715 +       } else {
20716 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20717 +                       return -EPERM;
20718 +       }
20719 +
20720 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20721 +               if (ipv4_is_loopback(fl->fl4_dst))
20722 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20723 +               if (ipv4_is_loopback(fl->fl4_src))
20724 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20725 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20726 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20727 +               return -EPERM;
20728 +
20729 +       return 0;
20730 +}
20731 +
20732 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20733 +
20734 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/init.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/init.c
20735 --- linux-2.6.27.25/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
20736 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/init.c  2008-10-13 14:54:20.000000000 +0200
20737 @@ -0,0 +1,45 @@
20738 +/*
20739 + *  linux/kernel/init.c
20740 + *
20741 + *  Virtual Server Init
20742 + *
20743 + *  Copyright (C) 2004-2007  Herbert Pötzl
20744 + *
20745 + *  V0.01  basic structure
20746 + *
20747 + */
20748 +
20749 +#include <linux/init.h>
20750 +
20751 +int    vserver_register_sysctl(void);
20752 +void   vserver_unregister_sysctl(void);
20753 +
20754 +
20755 +static int __init init_vserver(void)
20756 +{
20757 +       int ret = 0;
20758 +
20759 +#ifdef CONFIG_VSERVER_DEBUG
20760 +       vserver_register_sysctl();
20761 +#endif
20762 +       return ret;
20763 +}
20764 +
20765 +
20766 +static void __exit exit_vserver(void)
20767 +{
20768 +
20769 +#ifdef CONFIG_VSERVER_DEBUG
20770 +       vserver_unregister_sysctl();
20771 +#endif
20772 +       return;
20773 +}
20774 +
20775 +/* FIXME: GFP_ZONETYPES gone
20776 +long vx_slab[GFP_ZONETYPES]; */
20777 +long vx_area;
20778 +
20779 +
20780 +module_init(init_vserver);
20781 +module_exit(exit_vserver);
20782 +
20783 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/inode.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/inode.c
20784 --- linux-2.6.27.25/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
20785 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/inode.c 2008-10-24 03:34:52.000000000 +0200
20786 @@ -0,0 +1,422 @@
20787 +/*
20788 + *  linux/kernel/vserver/inode.c
20789 + *
20790 + *  Virtual Server: File System Support
20791 + *
20792 + *  Copyright (C) 2004-2007  Herbert Pötzl
20793 + *
20794 + *  V0.01  separated from vcontext V0.05
20795 + *  V0.02  moved to tag (instead of xid)
20796 + *
20797 + */
20798 +
20799 +#include <linux/tty.h>
20800 +#include <linux/proc_fs.h>
20801 +#include <linux/devpts_fs.h>
20802 +#include <linux/fs.h>
20803 +#include <linux/file.h>
20804 +#include <linux/mount.h>
20805 +#include <linux/parser.h>
20806 +#include <linux/namei.h>
20807 +#include <linux/vserver/inode.h>
20808 +#include <linux/vserver/inode_cmd.h>
20809 +#include <linux/vs_base.h>
20810 +#include <linux/vs_tag.h>
20811 +
20812 +#include <asm/uaccess.h>
20813 +
20814 +
20815 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20816 +{
20817 +       struct proc_dir_entry *entry;
20818 +
20819 +       if (!in || !in->i_sb)
20820 +               return -ESRCH;
20821 +
20822 +       *flags = IATTR_TAG
20823 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20824 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20825 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20826 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20827 +
20828 +       if (S_ISDIR(in->i_mode))
20829 +               *mask |= IATTR_BARRIER;
20830 +
20831 +       if (IS_TAGGED(in)) {
20832 +               *tag = in->i_tag;
20833 +               *mask |= IATTR_TAG;
20834 +       }
20835 +
20836 +       switch (in->i_sb->s_magic) {
20837 +       case PROC_SUPER_MAGIC:
20838 +               entry = PROC_I(in)->pde;
20839 +
20840 +               /* check for specific inodes? */
20841 +               if (entry)
20842 +                       *mask |= IATTR_FLAGS;
20843 +               if (entry)
20844 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20845 +               else
20846 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20847 +               break;
20848 +
20849 +       case DEVPTS_SUPER_MAGIC:
20850 +               *tag = in->i_tag;
20851 +               *mask |= IATTR_TAG;
20852 +               break;
20853 +
20854 +       default:
20855 +               break;
20856 +       }
20857 +       return 0;
20858 +}
20859 +
20860 +int vc_get_iattr(void __user *data)
20861 +{
20862 +       struct path path;
20863 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20864 +       int ret;
20865 +
20866 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20867 +               return -EFAULT;
20868 +
20869 +       ret = user_lpath(vc_data.name, &path);
20870 +       if (!ret) {
20871 +               ret = __vc_get_iattr(path.dentry->d_inode,
20872 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20873 +               path_put(&path);
20874 +       }
20875 +       if (ret)
20876 +               return ret;
20877 +
20878 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20879 +               ret = -EFAULT;
20880 +       return ret;
20881 +}
20882 +
20883 +#ifdef CONFIG_COMPAT
20884 +
20885 +int vc_get_iattr_x32(void __user *data)
20886 +{
20887 +       struct path path;
20888 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20889 +       int ret;
20890 +
20891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20892 +               return -EFAULT;
20893 +
20894 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20895 +       if (!ret) {
20896 +               ret = __vc_get_iattr(path.dentry->d_inode,
20897 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20898 +               path_put(&path);
20899 +       }
20900 +       if (ret)
20901 +               return ret;
20902 +
20903 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20904 +               ret = -EFAULT;
20905 +       return ret;
20906 +}
20907 +
20908 +#endif /* CONFIG_COMPAT */
20909 +
20910 +
20911 +int vc_fget_iattr(uint32_t fd, void __user *data)
20912 +{
20913 +       struct file *filp;
20914 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20915 +       int ret;
20916 +
20917 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20918 +               return -EFAULT;
20919 +
20920 +       filp = fget(fd);
20921 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20922 +               return -EBADF;
20923 +
20924 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20925 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20926 +
20927 +       fput(filp);
20928 +
20929 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20930 +               ret = -EFAULT;
20931 +       return ret;
20932 +}
20933 +
20934 +
20935 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20936 +{
20937 +       struct inode *in = de->d_inode;
20938 +       int error = 0, is_proc = 0, has_tag = 0;
20939 +       struct iattr attr = { 0 };
20940 +
20941 +       if (!in || !in->i_sb)
20942 +               return -ESRCH;
20943 +
20944 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20945 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20946 +               return -EINVAL;
20947 +
20948 +       has_tag = IS_TAGGED(in) ||
20949 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20950 +       if ((*mask & IATTR_TAG) && !has_tag)
20951 +               return -EINVAL;
20952 +
20953 +       mutex_lock(&in->i_mutex);
20954 +       if (*mask & IATTR_TAG) {
20955 +               attr.ia_tag = *tag;
20956 +               attr.ia_valid |= ATTR_TAG;
20957 +       }
20958 +
20959 +       if (*mask & IATTR_FLAGS) {
20960 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20961 +               unsigned int iflags = PROC_I(in)->vx_flags;
20962 +
20963 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20964 +                       | (*flags & IATTR_FLAGS);
20965 +               PROC_I(in)->vx_flags = iflags;
20966 +               if (entry)
20967 +                       entry->vx_flags = iflags;
20968 +       }
20969 +
20970 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20971 +               if (*mask & IATTR_IMMUTABLE) {
20972 +                       if (*flags & IATTR_IMMUTABLE)
20973 +                               in->i_flags |= S_IMMUTABLE;
20974 +                       else
20975 +                               in->i_flags &= ~S_IMMUTABLE;
20976 +               }
20977 +               if (*mask & IATTR_IXUNLINK) {
20978 +                       if (*flags & IATTR_IXUNLINK)
20979 +                               in->i_flags |= S_IXUNLINK;
20980 +                       else
20981 +                               in->i_flags &= ~S_IXUNLINK;
20982 +               }
20983 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20984 +                       if (*flags & IATTR_BARRIER)
20985 +                               in->i_vflags |= V_BARRIER;
20986 +                       else
20987 +                               in->i_vflags &= ~V_BARRIER;
20988 +               }
20989 +               if (in->i_op && in->i_op->sync_flags) {
20990 +                       error = in->i_op->sync_flags(in);
20991 +                       if (error)
20992 +                               goto out;
20993 +               }
20994 +       }
20995 +
20996 +       if (attr.ia_valid) {
20997 +               if (in->i_op && in->i_op->setattr)
20998 +                       error = in->i_op->setattr(de, &attr);
20999 +               else {
21000 +                       error = inode_change_ok(in, &attr);
21001 +                       if (!error)
21002 +                               error = inode_setattr(in, &attr);
21003 +               }
21004 +       }
21005 +
21006 +out:
21007 +       mutex_unlock(&in->i_mutex);
21008 +       return error;
21009 +}
21010 +
21011 +int vc_set_iattr(void __user *data)
21012 +{
21013 +       struct path path;
21014 +       struct vcmd_ctx_iattr_v1 vc_data;
21015 +       int ret;
21016 +
21017 +       if (!capable(CAP_LINUX_IMMUTABLE))
21018 +               return -EPERM;
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_set_iattr(path.dentry,
21025 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21026 +               path_put(&path);
21027 +       }
21028 +
21029 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21030 +               ret = -EFAULT;
21031 +       return ret;
21032 +}
21033 +
21034 +#ifdef CONFIG_COMPAT
21035 +
21036 +int vc_set_iattr_x32(void __user *data)
21037 +{
21038 +       struct path path;
21039 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21040 +       int ret;
21041 +
21042 +       if (!capable(CAP_LINUX_IMMUTABLE))
21043 +               return -EPERM;
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_set_iattr(path.dentry,
21050 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21051 +               path_put(&path);
21052 +       }
21053 +
21054 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21055 +               ret = -EFAULT;
21056 +       return ret;
21057 +}
21058 +
21059 +#endif /* CONFIG_COMPAT */
21060 +
21061 +int vc_fset_iattr(uint32_t fd, void __user *data)
21062 +{
21063 +       struct file *filp;
21064 +       struct vcmd_ctx_fiattr_v0 vc_data;
21065 +       int ret;
21066 +
21067 +       if (!capable(CAP_LINUX_IMMUTABLE))
21068 +               return -EPERM;
21069 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21070 +               return -EFAULT;
21071 +
21072 +       filp = fget(fd);
21073 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21074 +               return -EBADF;
21075 +
21076 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21077 +               &vc_data.flags, &vc_data.mask);
21078 +
21079 +       fput(filp);
21080 +
21081 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21082 +               return -EFAULT;
21083 +       return ret;
21084 +}
21085 +
21086 +
21087 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21088 +
21089 +static match_table_t tokens = {
21090 +       {Opt_notagcheck, "notagcheck"},
21091 +#ifdef CONFIG_PROPAGATE
21092 +       {Opt_notag, "notag"},
21093 +       {Opt_tag, "tag"},
21094 +       {Opt_tagid, "tagid=%u"},
21095 +#endif
21096 +       {Opt_err, NULL}
21097 +};
21098 +
21099 +
21100 +static void __dx_parse_remove(char *string, char *opt)
21101 +{
21102 +       char *p = strstr(string, opt);
21103 +       char *q = p;
21104 +
21105 +       if (p) {
21106 +               while (*q != '\0' && *q != ',')
21107 +                       q++;
21108 +               while (*q)
21109 +                       *p++ = *q++;
21110 +               while (*p)
21111 +                       *p++ = '\0';
21112 +       }
21113 +}
21114 +
21115 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21116 +                unsigned long *flags)
21117 +{
21118 +       int set = 0;
21119 +       substring_t args[MAX_OPT_ARGS];
21120 +       int token, option = 0;
21121 +       char *s, *p, *opts;
21122 +
21123 +       if (!string)
21124 +               return 0;
21125 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21126 +       if (!s)
21127 +               return 0;
21128 +
21129 +       opts = s;
21130 +       while ((p = strsep(&opts, ",")) != NULL) {
21131 +               token = match_token(p, tokens, args);
21132 +
21133 +               vxdprintk(VXD_CBIT(tag, 7),
21134 +                       "dx_parse_tag(»%s«): %d:#%d",
21135 +                       p, token, option);
21136 +
21137 +               switch (token) {
21138 +#ifdef CONFIG_PROPAGATE
21139 +               case Opt_tag:
21140 +                       if (tag)
21141 +                               *tag = 0;
21142 +                       if (remove)
21143 +                               __dx_parse_remove(s, "tag");
21144 +                       *mnt_flags |= MNT_TAGID;
21145 +                       set |= MNT_TAGID;
21146 +                       break;
21147 +               case Opt_notag:
21148 +                       if (remove)
21149 +                               __dx_parse_remove(s, "notag");
21150 +                       *mnt_flags |= MNT_NOTAG;
21151 +                       set |= MNT_NOTAG;
21152 +                       break;
21153 +               case Opt_tagid:
21154 +                       if (tag && !match_int(args, &option))
21155 +                               *tag = option;
21156 +                       if (remove)
21157 +                               __dx_parse_remove(s, "tagid");
21158 +                       *mnt_flags |= MNT_TAGID;
21159 +                       set |= MNT_TAGID;
21160 +                       break;
21161 +#endif
21162 +               case Opt_notagcheck:
21163 +                       if (remove)
21164 +                               __dx_parse_remove(s, "notagcheck");
21165 +                       *flags |= MS_NOTAGCHECK;
21166 +                       set |= MS_NOTAGCHECK;
21167 +                       break;
21168 +               }
21169 +       }
21170 +       if (set)
21171 +               strcpy(string, s);
21172 +       kfree(s);
21173 +       return set;
21174 +}
21175 +
21176 +#ifdef CONFIG_PROPAGATE
21177 +
21178 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21179 +{
21180 +       tag_t new_tag = 0;
21181 +       struct vfsmount *mnt;
21182 +       int propagate;
21183 +
21184 +       if (!nd)
21185 +               return;
21186 +       mnt = nd->path.mnt;
21187 +       if (!mnt)
21188 +               return;
21189 +
21190 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21191 +       if (propagate)
21192 +               new_tag = mnt->mnt_tag;
21193 +
21194 +       vxdprintk(VXD_CBIT(tag, 7),
21195 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21196 +               inode, inode->i_ino, inode->i_tag,
21197 +               new_tag, (propagate) ? 1 : 0);
21198 +
21199 +       if (propagate)
21200 +               inode->i_tag = new_tag;
21201 +}
21202 +
21203 +#include <linux/module.h>
21204 +
21205 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21206 +
21207 +#endif /* CONFIG_PROPAGATE */
21208 +
21209 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/Kconfig linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/Kconfig
21210 --- linux-2.6.27.25/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
21211 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/Kconfig 2008-10-13 14:54:20.000000000 +0200
21212 @@ -0,0 +1,251 @@
21213 +#
21214 +# Linux VServer configuration
21215 +#
21216 +
21217 +menu "Linux VServer"
21218 +
21219 +config VSERVER_AUTO_LBACK
21220 +       bool    "Automatically Assign Loopback IP"
21221 +       default y
21222 +       help
21223 +         Automatically assign a guest specific loopback
21224 +         IP and add it to the kernel network stack on
21225 +         startup.
21226 +
21227 +config VSERVER_AUTO_SINGLE
21228 +       bool    "Automatic Single IP Special Casing"
21229 +       depends on EXPERIMENTAL
21230 +       default y
21231 +       help
21232 +         This allows network contexts with a single IP to
21233 +         automatically remap 0.0.0.0 bindings to that IP,
21234 +         avoiding further network checks and improving
21235 +         performance.
21236 +
21237 +         (note: such guests do not allow to change the ip
21238 +          on the fly and do not show loopback addresses)
21239 +
21240 +config VSERVER_COWBL
21241 +       bool    "Enable COW Immutable Link Breaking"
21242 +       default y
21243 +       help
21244 +         This enables the COW (Copy-On-Write) link break code.
21245 +         It allows you to treat unified files like normal files
21246 +         when writing to them (which will implicitely break the
21247 +         link and create a copy of the unified file)
21248 +
21249 +config VSERVER_VTIME
21250 +       bool    "Enable Virtualized Guest Time"
21251 +       depends on EXPERIMENTAL
21252 +       default n
21253 +       help
21254 +         This enables per guest time offsets to allow for
21255 +         adjusting the system clock individually per guest.
21256 +         this adds some overhead to the time functions and
21257 +         therefore should not be enabled without good reason.
21258 +
21259 +config VSERVER_DEVICE
21260 +       bool    "Enable Guest Device Mapping"
21261 +       depends on EXPERIMENTAL
21262 +       default n
21263 +       help
21264 +         This enables generic device remapping.
21265 +
21266 +config VSERVER_PROC_SECURE
21267 +       bool    "Enable Proc Security"
21268 +       depends on PROC_FS
21269 +       default y
21270 +       help
21271 +         This configures ProcFS security to initially hide
21272 +         non-process entries for all contexts except the main and
21273 +         spectator context (i.e. for all guests), which is a secure
21274 +         default.
21275 +
21276 +         (note: on 1.2x the entries were visible by default)
21277 +
21278 +config VSERVER_HARDCPU
21279 +       bool    "Enable Hard CPU Limits"
21280 +       default y
21281 +       help
21282 +         Activate the Hard CPU Limits
21283 +
21284 +         This will compile in code that allows the Token Bucket
21285 +         Scheduler to put processes on hold when a context's
21286 +         tokens are depleted (provided that its per-context
21287 +         sched_hard flag is set).
21288 +
21289 +         Processes belonging to that context will not be able
21290 +         to consume CPU resources again until a per-context
21291 +         configured minimum of tokens has been reached.
21292 +
21293 +config VSERVER_IDLETIME
21294 +       bool    "Avoid idle CPUs by skipping Time"
21295 +       depends on VSERVER_HARDCPU
21296 +       default y
21297 +       help
21298 +         This option allows the scheduler to artificially
21299 +         advance time (per cpu) when otherwise the idle
21300 +         task would be scheduled, thus keeping the cpu
21301 +         busy and sharing the available resources among
21302 +         certain contexts.
21303 +
21304 +config VSERVER_IDLELIMIT
21305 +       bool    "Limit the IDLE task"
21306 +       depends on VSERVER_HARDCPU
21307 +       default n
21308 +       help
21309 +         Limit the idle slices, so the the next context
21310 +         will be scheduled as soon as possible.
21311 +
21312 +         This might improve interactivity and latency, but
21313 +         will also marginally increase scheduling overhead.
21314 +
21315 +choice
21316 +       prompt  "Persistent Inode Tagging"
21317 +       default TAGGING_ID24
21318 +       help
21319 +         This adds persistent context information to filesystems
21320 +         mounted with the tagxid option. Tagging is a requirement
21321 +         for per-context disk limits and per-context quota.
21322 +
21323 +
21324 +config TAGGING_NONE
21325 +       bool    "Disabled"
21326 +       help
21327 +         do not store per-context information in inodes.
21328 +
21329 +config TAGGING_UID16
21330 +       bool    "UID16/GID32"
21331 +       help
21332 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21333 +
21334 +config TAGGING_GID16
21335 +       bool    "UID32/GID16"
21336 +       help
21337 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21338 +
21339 +config TAGGING_ID24
21340 +       bool    "UID24/GID24"
21341 +       help
21342 +         uses the upper 8bit from UID and GID for XID tagging
21343 +         which leaves 24bit for UID/GID each, which should be
21344 +         more than sufficient for normal use.
21345 +
21346 +config TAGGING_INTERN
21347 +       bool    "UID32/GID32"
21348 +       help
21349 +         this uses otherwise reserved inode fields in the on
21350 +         disk representation, which limits the use to a few
21351 +         filesystems (currently ext2 and ext3)
21352 +
21353 +endchoice
21354 +
21355 +config TAG_NFSD
21356 +       bool    "Tag NFSD User Auth and Files"
21357 +       default n
21358 +       help
21359 +         Enable this if you do want the in-kernel NFS
21360 +         Server to use the tagging specified above.
21361 +         (will require patched clients too)
21362 +
21363 +config VSERVER_PRIVACY
21364 +       bool    "Honor Privacy Aspects of Guests"
21365 +       default n
21366 +       help
21367 +         When enabled, most context checks will disallow
21368 +         access to structures assigned to a specific context,
21369 +         like ptys or loop devices.
21370 +
21371 +config VSERVER_CONTEXTS
21372 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21373 +       range 1 65533
21374 +       default "768"   if 64BIT
21375 +       default "256"
21376 +       help
21377 +         This setting will optimize certain data structures
21378 +         and memory allocations according to the expected
21379 +         maximum.
21380 +
21381 +         note: this is not a strict upper limit.
21382 +
21383 +config VSERVER_WARN
21384 +       bool    "VServer Warnings"
21385 +       default y
21386 +       help
21387 +         This enables various runtime warnings, which will
21388 +         notify about potential manipulation attempts or
21389 +         resource shortage. It is generally considered to
21390 +         be a good idea to have that enabled.
21391 +
21392 +config VSERVER_DEBUG
21393 +       bool    "VServer Debugging Code"
21394 +       default n
21395 +       help
21396 +         Set this to yes if you want to be able to activate
21397 +         debugging output at runtime. It adds a very small
21398 +         overhead to all vserver related functions and
21399 +         increases the kernel size by about 20k.
21400 +
21401 +config VSERVER_HISTORY
21402 +       bool    "VServer History Tracing"
21403 +       depends on VSERVER_DEBUG
21404 +       default n
21405 +       help
21406 +         Set this to yes if you want to record the history of
21407 +         linux-vserver activities, so they can be replayed in
21408 +         the event of a kernel panic or oops.
21409 +
21410 +config VSERVER_HISTORY_SIZE
21411 +       int     "Per-CPU History Size (32-65536)"
21412 +       depends on VSERVER_HISTORY
21413 +       range 32 65536
21414 +       default 64
21415 +       help
21416 +         This allows you to specify the number of entries in
21417 +         the per-CPU history buffer.
21418 +
21419 +config VSERVER_MONITOR
21420 +       bool    "VServer Scheduling Monitor"
21421 +       depends on VSERVER_DISABLED
21422 +       default n
21423 +       help
21424 +         Set this to yes if you want to record the scheduling
21425 +         decisions, so that they can be relayed to userspace
21426 +         for detailed analysis.
21427 +
21428 +config VSERVER_MONITOR_SIZE
21429 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21430 +       depends on VSERVER_MONITOR
21431 +       range 32 65536
21432 +       default 1024
21433 +       help
21434 +         This allows you to specify the number of entries in
21435 +         the per-CPU scheduling monitor buffer.
21436 +
21437 +config VSERVER_MONITOR_SYNC
21438 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21439 +       depends on VSERVER_MONITOR
21440 +       range 0 65536
21441 +       default 256
21442 +       help
21443 +         This allows you to specify the interval in ticks
21444 +         when a time sync entry is inserted.
21445 +
21446 +endmenu
21447 +
21448 +
21449 +config VSERVER
21450 +       bool
21451 +       default y
21452 +       select NAMESPACES
21453 +       select UTS_NS
21454 +       select IPC_NS
21455 +       select USER_NS
21456 +       select SYSVIPC
21457 +
21458 +config VSERVER_SECURITY
21459 +       bool
21460 +       depends on SECURITY
21461 +       default y
21462 +       select SECURITY_CAPABILITIES
21463 +
21464 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/limit.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/limit.c
21465 --- linux-2.6.27.25/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
21466 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/limit.c 2008-10-13 14:54:20.000000000 +0200
21467 @@ -0,0 +1,319 @@
21468 +/*
21469 + *  linux/kernel/vserver/limit.c
21470 + *
21471 + *  Virtual Server: Context Limits
21472 + *
21473 + *  Copyright (C) 2004-2007  Herbert Pötzl
21474 + *
21475 + *  V0.01  broken out from vcontext V0.05
21476 + *  V0.02  changed vcmds to vxi arg
21477 + *
21478 + */
21479 +
21480 +#include <linux/sched.h>
21481 +#include <linux/module.h>
21482 +#include <linux/vs_limit.h>
21483 +#include <linux/vserver/limit.h>
21484 +#include <linux/vserver/limit_cmd.h>
21485 +
21486 +#include <asm/uaccess.h>
21487 +
21488 +
21489 +const char *vlimit_name[NUM_LIMITS] = {
21490 +       [RLIMIT_CPU]            = "CPU",
21491 +       [RLIMIT_RSS]            = "RSS",
21492 +       [RLIMIT_NPROC]          = "NPROC",
21493 +       [RLIMIT_NOFILE]         = "NOFILE",
21494 +       [RLIMIT_MEMLOCK]        = "VML",
21495 +       [RLIMIT_AS]             = "VM",
21496 +       [RLIMIT_LOCKS]          = "LOCKS",
21497 +       [RLIMIT_SIGPENDING]     = "SIGP",
21498 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21499 +
21500 +       [VLIMIT_NSOCK]          = "NSOCK",
21501 +       [VLIMIT_OPENFD]         = "OPENFD",
21502 +       [VLIMIT_ANON]           = "ANON",
21503 +       [VLIMIT_SHMEM]          = "SHMEM",
21504 +       [VLIMIT_DENTRY]         = "DENTRY",
21505 +};
21506 +
21507 +EXPORT_SYMBOL_GPL(vlimit_name);
21508 +
21509 +#define MASK_ENTRY(x)  (1 << (x))
21510 +
21511 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21512 +               /* minimum */
21513 +       0
21514 +       ,       /* softlimit */
21515 +       MASK_ENTRY( RLIMIT_RSS          ) |
21516 +       MASK_ENTRY( VLIMIT_ANON         ) |
21517 +       0
21518 +       ,       /* maximum */
21519 +       MASK_ENTRY( RLIMIT_RSS          ) |
21520 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21521 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21522 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21523 +       MASK_ENTRY( RLIMIT_AS           ) |
21524 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21525 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21526 +
21527 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21528 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21529 +       MASK_ENTRY( VLIMIT_ANON         ) |
21530 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21531 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21532 +       0
21533 +};
21534 +               /* accounting only */
21535 +uint32_t account_mask =
21536 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21537 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21538 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21539 +       0;
21540 +
21541 +
21542 +static int is_valid_vlimit(int id)
21543 +{
21544 +       uint32_t mask = vlimit_mask.minimum |
21545 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21546 +       return mask & (1 << id);
21547 +}
21548 +
21549 +static int is_accounted_vlimit(int id)
21550 +{
21551 +       if (is_valid_vlimit(id))
21552 +               return 1;
21553 +       return account_mask & (1 << id);
21554 +}
21555 +
21556 +
21557 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21558 +{
21559 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21560 +       return VX_VLIM(limit);
21561 +}
21562 +
21563 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21564 +{
21565 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21566 +       return VX_VLIM(limit);
21567 +}
21568 +
21569 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21570 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21571 +{
21572 +       if (!is_valid_vlimit(id))
21573 +               return -EINVAL;
21574 +
21575 +       if (minimum)
21576 +               *minimum = CRLIM_UNSET;
21577 +       if (softlimit)
21578 +               *softlimit = vc_get_soft(vxi, id);
21579 +       if (maximum)
21580 +               *maximum = vc_get_hard(vxi, id);
21581 +       return 0;
21582 +}
21583 +
21584 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21585 +{
21586 +       struct vcmd_ctx_rlimit_v0 vc_data;
21587 +       int ret;
21588 +
21589 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21590 +               return -EFAULT;
21591 +
21592 +       ret = do_get_rlimit(vxi, vc_data.id,
21593 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21594 +       if (ret)
21595 +               return ret;
21596 +
21597 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21598 +               return -EFAULT;
21599 +       return 0;
21600 +}
21601 +
21602 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21603 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21604 +{
21605 +       if (!is_valid_vlimit(id))
21606 +               return -EINVAL;
21607 +
21608 +       if (maximum != CRLIM_KEEP)
21609 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21610 +       if (softlimit != CRLIM_KEEP)
21611 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21612 +
21613 +       /* clamp soft limit */
21614 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21615 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21616 +
21617 +       return 0;
21618 +}
21619 +
21620 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21621 +{
21622 +       struct vcmd_ctx_rlimit_v0 vc_data;
21623 +
21624 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21625 +               return -EFAULT;
21626 +
21627 +       return do_set_rlimit(vxi, vc_data.id,
21628 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21629 +}
21630 +
21631 +#ifdef CONFIG_IA32_EMULATION
21632 +
21633 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21634 +{
21635 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21636 +
21637 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21638 +               return -EFAULT;
21639 +
21640 +       return do_set_rlimit(vxi, vc_data.id,
21641 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21642 +}
21643 +
21644 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21645 +{
21646 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21647 +       int ret;
21648 +
21649 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21650 +               return -EFAULT;
21651 +
21652 +       ret = do_get_rlimit(vxi, vc_data.id,
21653 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21654 +       if (ret)
21655 +               return ret;
21656 +
21657 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21658 +               return -EFAULT;
21659 +       return 0;
21660 +}
21661 +
21662 +#endif /* CONFIG_IA32_EMULATION */
21663 +
21664 +
21665 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21666 +{
21667 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21668 +               return -EFAULT;
21669 +       return 0;
21670 +}
21671 +
21672 +
21673 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21674 +{
21675 +       rlim_t value;
21676 +       int lim;
21677 +
21678 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21679 +               value = __rlim_get(limit, lim);
21680 +               __rlim_rmax(limit, lim) = value;
21681 +               __rlim_rmin(limit, lim) = value;
21682 +       }
21683 +}
21684 +
21685 +
21686 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21687 +{
21688 +       vx_reset_minmax(&vxi->limit);
21689 +       return 0;
21690 +}
21691 +
21692 +
21693 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21694 +{
21695 +       struct vcmd_rlimit_stat_v0 vc_data;
21696 +       struct _vx_limit *limit = &vxi->limit;
21697 +       int id;
21698 +
21699 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21700 +               return -EFAULT;
21701 +
21702 +       id = vc_data.id;
21703 +       if (!is_accounted_vlimit(id))
21704 +               return -EINVAL;
21705 +
21706 +       vx_limit_fixup(limit, id);
21707 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21708 +       vc_data.value = __rlim_get(limit, id);
21709 +       vc_data.minimum = __rlim_rmin(limit, id);
21710 +       vc_data.maximum = __rlim_rmax(limit, id);
21711 +
21712 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21713 +               return -EFAULT;
21714 +       return 0;
21715 +}
21716 +
21717 +
21718 +void vx_vsi_meminfo(struct sysinfo *val)
21719 +{
21720 +       struct vx_info *vxi = current->vx_info;
21721 +       unsigned long totalram, freeram;
21722 +       rlim_t v;
21723 +
21724 +       /* we blindly accept the max */
21725 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21726 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21727 +
21728 +       /* total minus used equals free */
21729 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21730 +       freeram = (v < totalram) ? totalram - v : 0;
21731 +
21732 +       val->totalram = totalram;
21733 +       val->freeram = freeram;
21734 +       val->bufferram = 0;
21735 +       val->totalhigh = 0;
21736 +       val->freehigh = 0;
21737 +       return;
21738 +}
21739 +
21740 +void vx_vsi_swapinfo(struct sysinfo *val)
21741 +{
21742 +       struct vx_info *vxi = current->vx_info;
21743 +       unsigned long totalswap, freeswap;
21744 +       rlim_t v, w;
21745 +
21746 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21747 +       if (v == RLIM_INFINITY) {
21748 +               val->freeswap = val->totalswap;
21749 +               return;
21750 +       }
21751 +
21752 +       /* we blindly accept the max */
21753 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21754 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21755 +
21756 +       /* currently 'used' swap */
21757 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21758 +       w -= (w > v) ? v : w;
21759 +
21760 +       /* total minus used equals free */
21761 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21762 +
21763 +       val->totalswap = totalswap;
21764 +       val->freeswap = freeswap;
21765 +       return;
21766 +}
21767 +
21768 +
21769 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21770 +{
21771 +       struct vx_info *vxi = mm->mm_vx_info;
21772 +       unsigned long points;
21773 +       rlim_t v, w;
21774 +
21775 +       if (!vxi)
21776 +               return 0;
21777 +
21778 +       points = vxi->vx_badness_bias;
21779 +
21780 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21781 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21782 +       points += (v > w) ? (v - w) : 0;
21783 +
21784 +       return points;
21785 +}
21786 +
21787 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/limit_init.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/limit_init.h
21788 --- linux-2.6.27.25/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
21789 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/limit_init.h    2008-10-13 14:54:20.000000000 +0200
21790 @@ -0,0 +1,31 @@
21791 +
21792 +
21793 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21794 +{
21795 +       int lim;
21796 +
21797 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21798 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21799 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21800 +               __rlim_set(limit, lim, 0);
21801 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21802 +               __rlim_rmin(limit, lim) = 0;
21803 +               __rlim_rmax(limit, lim) = 0;
21804 +       }
21805 +}
21806 +
21807 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21808 +{
21809 +       rlim_t value;
21810 +       int lim;
21811 +
21812 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21813 +               if ((1 << lim) & VLIM_NOCHECK)
21814 +                       continue;
21815 +               value = __rlim_get(limit, lim);
21816 +               vxwprintk_xid(value,
21817 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21818 +                       limit, vlimit_name[lim], lim, (long)value);
21819 +       }
21820 +}
21821 +
21822 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/limit_proc.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/limit_proc.h
21823 --- linux-2.6.27.25/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
21824 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/limit_proc.h    2008-10-13 14:54:20.000000000 +0200
21825 @@ -0,0 +1,57 @@
21826 +#ifndef _VX_LIMIT_PROC_H
21827 +#define _VX_LIMIT_PROC_H
21828 +
21829 +#include <linux/vserver/limit_int.h>
21830 +
21831 +
21832 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21833 +#define VX_LIMIT_TOP   \
21834 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21835 +
21836 +#define VX_LIMIT_ARG(r)                                \
21837 +       (unsigned long)__rlim_get(limit, r),    \
21838 +       (unsigned long)__rlim_rmin(limit, r),   \
21839 +       (unsigned long)__rlim_rmax(limit, r),   \
21840 +       VX_VLIM(__rlim_soft(limit, r)),         \
21841 +       VX_VLIM(__rlim_hard(limit, r)),         \
21842 +       atomic_read(&__rlim_lhit(limit, r))
21843 +
21844 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21845 +{
21846 +       vx_limit_fixup(limit, -1);
21847 +       return sprintf(buffer, VX_LIMIT_TOP
21848 +               "PROC"  VX_LIMIT_FMT
21849 +               "VM"    VX_LIMIT_FMT
21850 +               "VML"   VX_LIMIT_FMT
21851 +               "RSS"   VX_LIMIT_FMT
21852 +               "ANON"  VX_LIMIT_FMT
21853 +               "RMAP"  VX_LIMIT_FMT
21854 +               "FILES" VX_LIMIT_FMT
21855 +               "OFD"   VX_LIMIT_FMT
21856 +               "LOCKS" VX_LIMIT_FMT
21857 +               "SOCK"  VX_LIMIT_FMT
21858 +               "MSGQ"  VX_LIMIT_FMT
21859 +               "SHM"   VX_LIMIT_FMT
21860 +               "SEMA"  VX_LIMIT_FMT
21861 +               "SEMS"  VX_LIMIT_FMT
21862 +               "DENT"  VX_LIMIT_FMT,
21863 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21864 +               VX_LIMIT_ARG(RLIMIT_AS),
21865 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21866 +               VX_LIMIT_ARG(RLIMIT_RSS),
21867 +               VX_LIMIT_ARG(VLIMIT_ANON),
21868 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21869 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21870 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21871 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21872 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21873 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21874 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21875 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21876 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21877 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21878 +}
21879 +
21880 +#endif /* _VX_LIMIT_PROC_H */
21881 +
21882 +
21883 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/Makefile linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/Makefile
21884 --- linux-2.6.27.25/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
21885 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/Makefile        2008-10-13 14:54:20.000000000 +0200
21886 @@ -0,0 +1,18 @@
21887 +#
21888 +# Makefile for the Linux vserver routines.
21889 +#
21890 +
21891 +
21892 +obj-y          += vserver.o
21893 +
21894 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21895 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21896 +                  dlimit.o tag.o
21897 +
21898 +vserver-$(CONFIG_INET) += inet.o
21899 +vserver-$(CONFIG_PROC_FS) += proc.o
21900 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21901 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21902 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21903 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21904 +
21905 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/monitor.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/monitor.c
21906 --- linux-2.6.27.25/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
21907 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/monitor.c       2008-10-13 14:54:20.000000000 +0200
21908 @@ -0,0 +1,138 @@
21909 +/*
21910 + *  kernel/vserver/monitor.c
21911 + *
21912 + *  Virtual Context Scheduler Monitor
21913 + *
21914 + *  Copyright (C) 2006-2007 Herbert Pötzl
21915 + *
21916 + *  V0.01  basic design
21917 + *
21918 + */
21919 +
21920 +#include <linux/module.h>
21921 +#include <linux/jiffies.h>
21922 +#include <asm/uaccess.h>
21923 +#include <asm/atomic.h>
21924 +
21925 +#include <linux/vserver/monitor.h>
21926 +#include <linux/vserver/debug_cmd.h>
21927 +
21928 +
21929 +#ifdef CONFIG_VSERVER_MONITOR
21930 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21931 +#else
21932 +#define VXM_SIZE       64
21933 +#endif
21934 +
21935 +struct _vx_monitor {
21936 +       unsigned int counter;
21937 +
21938 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21939 +};
21940 +
21941 +
21942 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21943 +
21944 +unsigned volatile int vxm_active = 1;
21945 +
21946 +static atomic_t sequence = ATOMIC_INIT(0);
21947 +
21948 +
21949 +/*     vxm_advance()
21950 +
21951 +       * requires disabled preemption                          */
21952 +
21953 +struct _vx_mon_entry *vxm_advance(int cpu)
21954 +{
21955 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21956 +       struct _vx_mon_entry *entry;
21957 +       unsigned int index;
21958 +
21959 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21960 +       entry = &mon->entry[index];
21961 +
21962 +       entry->ev.seq = atomic_inc_return(&sequence);
21963 +       entry->ev.jif = jiffies;
21964 +       return entry;
21965 +}
21966 +
21967 +EXPORT_SYMBOL_GPL(vxm_advance);
21968 +
21969 +
21970 +int do_read_monitor(struct __user _vx_mon_entry *data,
21971 +       int cpu, uint32_t *index, uint32_t *count)
21972 +{
21973 +       int pos, ret = 0;
21974 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21975 +       int end = mon->counter;
21976 +       int start = end - VXM_SIZE + 2;
21977 +       int idx = *index;
21978 +
21979 +       /* special case: get current pos */
21980 +       if (!*count) {
21981 +               *index = end;
21982 +               return 0;
21983 +       }
21984 +
21985 +       /* have we lost some data? */
21986 +       if (idx < start)
21987 +               idx = start;
21988 +
21989 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21990 +               struct _vx_mon_entry *entry =
21991 +                       &mon->entry[idx % VXM_SIZE];
21992 +
21993 +               /* send entry to userspace */
21994 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21995 +               if (ret)
21996 +                       break;
21997 +       }
21998 +       /* save new index and count */
21999 +       *index = idx;
22000 +       *count = pos;
22001 +       return ret ? ret : (*index < end);
22002 +}
22003 +
22004 +int vc_read_monitor(uint32_t id, void __user *data)
22005 +{
22006 +       struct vcmd_read_monitor_v0 vc_data;
22007 +       int ret;
22008 +
22009 +       if (id >= NR_CPUS)
22010 +               return -EINVAL;
22011 +
22012 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22013 +               return -EFAULT;
22014 +
22015 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22016 +               id, &vc_data.index, &vc_data.count);
22017 +
22018 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22019 +               return -EFAULT;
22020 +       return ret;
22021 +}
22022 +
22023 +#ifdef CONFIG_COMPAT
22024 +
22025 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22026 +{
22027 +       struct vcmd_read_monitor_v0_x32 vc_data;
22028 +       int ret;
22029 +
22030 +       if (id >= NR_CPUS)
22031 +               return -EINVAL;
22032 +
22033 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22034 +               return -EFAULT;
22035 +
22036 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22037 +               compat_ptr(vc_data.data_ptr),
22038 +               id, &vc_data.index, &vc_data.count);
22039 +
22040 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22041 +               return -EFAULT;
22042 +       return ret;
22043 +}
22044 +
22045 +#endif /* CONFIG_COMPAT */
22046 +
22047 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/network.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/network.c
22048 --- linux-2.6.27.25/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
22049 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/network.c       2008-10-13 14:54:20.000000000 +0200
22050 @@ -0,0 +1,864 @@
22051 +/*
22052 + *  linux/kernel/vserver/network.c
22053 + *
22054 + *  Virtual Server: Network Support
22055 + *
22056 + *  Copyright (C) 2003-2007  Herbert Pötzl
22057 + *
22058 + *  V0.01  broken out from vcontext V0.05
22059 + *  V0.02  cleaned up implementation
22060 + *  V0.03  added equiv nx commands
22061 + *  V0.04  switch to RCU based hash
22062 + *  V0.05  and back to locking again
22063 + *  V0.06  changed vcmds to nxi arg
22064 + *  V0.07  have __create claim() the nxi
22065 + *
22066 + */
22067 +
22068 +#include <linux/err.h>
22069 +#include <linux/slab.h>
22070 +#include <linux/rcupdate.h>
22071 +
22072 +#include <linux/vs_network.h>
22073 +#include <linux/vs_pid.h>
22074 +#include <linux/vserver/network_cmd.h>
22075 +
22076 +
22077 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22078 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22079 +
22080 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22081 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22082 +
22083 +
22084 +static int __init init_network(void)
22085 +{
22086 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22087 +               sizeof(struct nx_addr_v4), 0,
22088 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22089 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22090 +               sizeof(struct nx_addr_v6), 0,
22091 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22092 +       return 0;
22093 +}
22094 +
22095 +
22096 +/*     __alloc_nx_addr_v4()                                    */
22097 +
22098 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22099 +{
22100 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22101 +               nx_addr_v4_cachep, GFP_KERNEL);
22102 +
22103 +       if (!IS_ERR(nxa))
22104 +               memset(nxa, 0, sizeof(*nxa));
22105 +       return nxa;
22106 +}
22107 +
22108 +/*     __dealloc_nx_addr_v4()                                  */
22109 +
22110 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22111 +{
22112 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22113 +}
22114 +
22115 +/*     __dealloc_nx_addr_v4_all()                              */
22116 +
22117 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22118 +{
22119 +       while (nxa) {
22120 +               struct nx_addr_v4 *next = nxa->next;
22121 +
22122 +               __dealloc_nx_addr_v4(nxa);
22123 +               nxa = next;
22124 +       }
22125 +}
22126 +
22127 +
22128 +#ifdef CONFIG_IPV6
22129 +
22130 +/*     __alloc_nx_addr_v6()                                    */
22131 +
22132 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22133 +{
22134 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22135 +               nx_addr_v6_cachep, GFP_KERNEL);
22136 +
22137 +       if (!IS_ERR(nxa))
22138 +               memset(nxa, 0, sizeof(*nxa));
22139 +       return nxa;
22140 +}
22141 +
22142 +/*     __dealloc_nx_addr_v6()                                  */
22143 +
22144 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22145 +{
22146 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22147 +}
22148 +
22149 +/*     __dealloc_nx_addr_v6_all()                              */
22150 +
22151 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22152 +{
22153 +       while (nxa) {
22154 +               struct nx_addr_v6 *next = nxa->next;
22155 +
22156 +               __dealloc_nx_addr_v6(nxa);
22157 +               nxa = next;
22158 +       }
22159 +}
22160 +
22161 +#endif /* CONFIG_IPV6 */
22162 +
22163 +/*     __alloc_nx_info()
22164 +
22165 +       * allocate an initialized nx_info struct
22166 +       * doesn't make it visible (hash)                        */
22167 +
22168 +static struct nx_info *__alloc_nx_info(nid_t nid)
22169 +{
22170 +       struct nx_info *new = NULL;
22171 +
22172 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22173 +
22174 +       /* would this benefit from a slab cache? */
22175 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22176 +       if (!new)
22177 +               return 0;
22178 +
22179 +       memset(new, 0, sizeof(struct nx_info));
22180 +       new->nx_id = nid;
22181 +       INIT_HLIST_NODE(&new->nx_hlist);
22182 +       atomic_set(&new->nx_usecnt, 0);
22183 +       atomic_set(&new->nx_tasks, 0);
22184 +       new->nx_state = 0;
22185 +
22186 +       new->nx_flags = NXF_INIT_SET;
22187 +
22188 +       /* rest of init goes here */
22189 +
22190 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22191 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22192 +
22193 +       vxdprintk(VXD_CBIT(nid, 0),
22194 +               "alloc_nx_info(%d) = %p", nid, new);
22195 +       atomic_inc(&nx_global_ctotal);
22196 +       return new;
22197 +}
22198 +
22199 +/*     __dealloc_nx_info()
22200 +
22201 +       * final disposal of nx_info                             */
22202 +
22203 +static void __dealloc_nx_info(struct nx_info *nxi)
22204 +{
22205 +       vxdprintk(VXD_CBIT(nid, 0),
22206 +               "dealloc_nx_info(%p)", nxi);
22207 +
22208 +       nxi->nx_hlist.next = LIST_POISON1;
22209 +       nxi->nx_id = -1;
22210 +
22211 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22212 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22213 +
22214 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22215 +
22216 +       nxi->nx_state |= NXS_RELEASED;
22217 +       kfree(nxi);
22218 +       atomic_dec(&nx_global_ctotal);
22219 +}
22220 +
22221 +static void __shutdown_nx_info(struct nx_info *nxi)
22222 +{
22223 +       nxi->nx_state |= NXS_SHUTDOWN;
22224 +       vs_net_change(nxi, VSC_NETDOWN);
22225 +}
22226 +
22227 +/*     exported stuff                                          */
22228 +
22229 +void free_nx_info(struct nx_info *nxi)
22230 +{
22231 +       /* context shutdown is mandatory */
22232 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22233 +
22234 +       /* context must not be hashed */
22235 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22236 +
22237 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22238 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22239 +
22240 +       __dealloc_nx_info(nxi);
22241 +}
22242 +
22243 +
22244 +void __nx_set_lback(struct nx_info *nxi)
22245 +{
22246 +       int nid = nxi->nx_id;
22247 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22248 +
22249 +       nxi->v4_lback.s_addr = lback;
22250 +}
22251 +
22252 +extern int __nx_inet_add_lback(__be32 addr);
22253 +extern int __nx_inet_del_lback(__be32 addr);
22254 +
22255 +
22256 +/*     hash table for nx_info hash */
22257 +
22258 +#define NX_HASH_SIZE   13
22259 +
22260 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22261 +
22262 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22263 +
22264 +
22265 +static inline unsigned int __hashval(nid_t nid)
22266 +{
22267 +       return (nid % NX_HASH_SIZE);
22268 +}
22269 +
22270 +
22271 +
22272 +/*     __hash_nx_info()
22273 +
22274 +       * add the nxi to the global hash table
22275 +       * requires the hash_lock to be held                     */
22276 +
22277 +static inline void __hash_nx_info(struct nx_info *nxi)
22278 +{
22279 +       struct hlist_head *head;
22280 +
22281 +       vxd_assert_lock(&nx_info_hash_lock);
22282 +       vxdprintk(VXD_CBIT(nid, 4),
22283 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22284 +
22285 +       /* context must not be hashed */
22286 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22287 +
22288 +       nxi->nx_state |= NXS_HASHED;
22289 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22290 +       hlist_add_head(&nxi->nx_hlist, head);
22291 +       atomic_inc(&nx_global_cactive);
22292 +}
22293 +
22294 +/*     __unhash_nx_info()
22295 +
22296 +       * remove the nxi from the global hash table
22297 +       * requires the hash_lock to be held                     */
22298 +
22299 +static inline void __unhash_nx_info(struct nx_info *nxi)
22300 +{
22301 +       vxd_assert_lock(&nx_info_hash_lock);
22302 +       vxdprintk(VXD_CBIT(nid, 4),
22303 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22304 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22305 +
22306 +       /* context must be hashed */
22307 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22308 +       /* but without tasks */
22309 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22310 +
22311 +       nxi->nx_state &= ~NXS_HASHED;
22312 +       hlist_del(&nxi->nx_hlist);
22313 +       atomic_dec(&nx_global_cactive);
22314 +}
22315 +
22316 +
22317 +/*     __lookup_nx_info()
22318 +
22319 +       * requires the hash_lock to be held
22320 +       * doesn't increment the nx_refcnt                       */
22321 +
22322 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22323 +{
22324 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22325 +       struct hlist_node *pos;
22326 +       struct nx_info *nxi;
22327 +
22328 +       vxd_assert_lock(&nx_info_hash_lock);
22329 +       hlist_for_each(pos, head) {
22330 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22331 +
22332 +               if (nxi->nx_id == nid)
22333 +                       goto found;
22334 +       }
22335 +       nxi = NULL;
22336 +found:
22337 +       vxdprintk(VXD_CBIT(nid, 0),
22338 +               "__lookup_nx_info(#%u): %p[#%u]",
22339 +               nid, nxi, nxi ? nxi->nx_id : 0);
22340 +       return nxi;
22341 +}
22342 +
22343 +
22344 +/*     __create_nx_info()
22345 +
22346 +       * create the requested context
22347 +       * get(), claim() and hash it                            */
22348 +
22349 +static struct nx_info *__create_nx_info(int id)
22350 +{
22351 +       struct nx_info *new, *nxi = NULL;
22352 +
22353 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22354 +
22355 +       if (!(new = __alloc_nx_info(id)))
22356 +               return ERR_PTR(-ENOMEM);
22357 +
22358 +       /* required to make dynamic xids unique */
22359 +       spin_lock(&nx_info_hash_lock);
22360 +
22361 +       /* static context requested */
22362 +       if ((nxi = __lookup_nx_info(id))) {
22363 +               vxdprintk(VXD_CBIT(nid, 0),
22364 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22365 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22366 +                       nxi = ERR_PTR(-EBUSY);
22367 +               else
22368 +                       nxi = ERR_PTR(-EEXIST);
22369 +               goto out_unlock;
22370 +       }
22371 +       /* new context */
22372 +       vxdprintk(VXD_CBIT(nid, 0),
22373 +               "create_nx_info(%d) = %p (new)", id, new);
22374 +       claim_nx_info(new, NULL);
22375 +       __nx_set_lback(new);
22376 +       __hash_nx_info(get_nx_info(new));
22377 +       nxi = new, new = NULL;
22378 +
22379 +out_unlock:
22380 +       spin_unlock(&nx_info_hash_lock);
22381 +       if (new)
22382 +               __dealloc_nx_info(new);
22383 +       return nxi;
22384 +}
22385 +
22386 +
22387 +
22388 +/*     exported stuff                                          */
22389 +
22390 +
22391 +void unhash_nx_info(struct nx_info *nxi)
22392 +{
22393 +       __shutdown_nx_info(nxi);
22394 +       spin_lock(&nx_info_hash_lock);
22395 +       __unhash_nx_info(nxi);
22396 +       spin_unlock(&nx_info_hash_lock);
22397 +}
22398 +
22399 +/*     lookup_nx_info()
22400 +
22401 +       * search for a nx_info and get() it
22402 +       * negative id means current                             */
22403 +
22404 +struct nx_info *lookup_nx_info(int id)
22405 +{
22406 +       struct nx_info *nxi = NULL;
22407 +
22408 +       if (id < 0) {
22409 +               nxi = get_nx_info(current->nx_info);
22410 +       } else if (id > 1) {
22411 +               spin_lock(&nx_info_hash_lock);
22412 +               nxi = get_nx_info(__lookup_nx_info(id));
22413 +               spin_unlock(&nx_info_hash_lock);
22414 +       }
22415 +       return nxi;
22416 +}
22417 +
22418 +/*     nid_is_hashed()
22419 +
22420 +       * verify that nid is still hashed                       */
22421 +
22422 +int nid_is_hashed(nid_t nid)
22423 +{
22424 +       int hashed;
22425 +
22426 +       spin_lock(&nx_info_hash_lock);
22427 +       hashed = (__lookup_nx_info(nid) != NULL);
22428 +       spin_unlock(&nx_info_hash_lock);
22429 +       return hashed;
22430 +}
22431 +
22432 +
22433 +#ifdef CONFIG_PROC_FS
22434 +
22435 +/*     get_nid_list()
22436 +
22437 +       * get a subset of hashed nids for proc
22438 +       * assumes size is at least one                          */
22439 +
22440 +int get_nid_list(int index, unsigned int *nids, int size)
22441 +{
22442 +       int hindex, nr_nids = 0;
22443 +
22444 +       /* only show current and children */
22445 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22446 +               if (index > 0)
22447 +                       return 0;
22448 +               nids[nr_nids] = nx_current_nid();
22449 +               return 1;
22450 +       }
22451 +
22452 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22453 +               struct hlist_head *head = &nx_info_hash[hindex];
22454 +               struct hlist_node *pos;
22455 +
22456 +               spin_lock(&nx_info_hash_lock);
22457 +               hlist_for_each(pos, head) {
22458 +                       struct nx_info *nxi;
22459 +
22460 +                       if (--index > 0)
22461 +                               continue;
22462 +
22463 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22464 +                       nids[nr_nids] = nxi->nx_id;
22465 +                       if (++nr_nids >= size) {
22466 +                               spin_unlock(&nx_info_hash_lock);
22467 +                               goto out;
22468 +                       }
22469 +               }
22470 +               /* keep the lock time short */
22471 +               spin_unlock(&nx_info_hash_lock);
22472 +       }
22473 +out:
22474 +       return nr_nids;
22475 +}
22476 +#endif
22477 +
22478 +
22479 +/*
22480 + *     migrate task to new network
22481 + *     gets nxi, puts old_nxi on change
22482 + */
22483 +
22484 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22485 +{
22486 +       struct nx_info *old_nxi;
22487 +       int ret = 0;
22488 +
22489 +       if (!p || !nxi)
22490 +               BUG();
22491 +
22492 +       vxdprintk(VXD_CBIT(nid, 5),
22493 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22494 +               p, nxi, nxi->nx_id,
22495 +               atomic_read(&nxi->nx_usecnt),
22496 +               atomic_read(&nxi->nx_tasks));
22497 +
22498 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22499 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22500 +               return -EACCES;
22501 +
22502 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22503 +               return -EFAULT;
22504 +
22505 +       /* maybe disallow this completely? */
22506 +       old_nxi = task_get_nx_info(p);
22507 +       if (old_nxi == nxi)
22508 +               goto out;
22509 +
22510 +       task_lock(p);
22511 +       if (old_nxi)
22512 +               clr_nx_info(&p->nx_info);
22513 +       claim_nx_info(nxi, p);
22514 +       set_nx_info(&p->nx_info, nxi);
22515 +       p->nid = nxi->nx_id;
22516 +       task_unlock(p);
22517 +
22518 +       vxdprintk(VXD_CBIT(nid, 5),
22519 +               "moved task %p into nxi:%p[#%d]",
22520 +               p, nxi, nxi->nx_id);
22521 +
22522 +       if (old_nxi)
22523 +               release_nx_info(old_nxi, p);
22524 +       ret = 0;
22525 +out:
22526 +       put_nx_info(old_nxi);
22527 +       return ret;
22528 +}
22529 +
22530 +
22531 +void nx_set_persistent(struct nx_info *nxi)
22532 +{
22533 +       vxdprintk(VXD_CBIT(nid, 6),
22534 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22535 +
22536 +       get_nx_info(nxi);
22537 +       claim_nx_info(nxi, NULL);
22538 +}
22539 +
22540 +void nx_clear_persistent(struct nx_info *nxi)
22541 +{
22542 +       vxdprintk(VXD_CBIT(nid, 6),
22543 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22544 +
22545 +       release_nx_info(nxi, NULL);
22546 +       put_nx_info(nxi);
22547 +}
22548 +
22549 +void nx_update_persistent(struct nx_info *nxi)
22550 +{
22551 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22552 +               nx_set_persistent(nxi);
22553 +       else
22554 +               nx_clear_persistent(nxi);
22555 +}
22556 +
22557 +/* vserver syscall commands below here */
22558 +
22559 +/* taks nid and nx_info functions */
22560 +
22561 +#include <asm/uaccess.h>
22562 +
22563 +
22564 +int vc_task_nid(uint32_t id)
22565 +{
22566 +       nid_t nid;
22567 +
22568 +       if (id) {
22569 +               struct task_struct *tsk;
22570 +
22571 +               read_lock(&tasklist_lock);
22572 +               tsk = find_task_by_real_pid(id);
22573 +               nid = (tsk) ? tsk->nid : -ESRCH;
22574 +               read_unlock(&tasklist_lock);
22575 +       } else
22576 +               nid = nx_current_nid();
22577 +       return nid;
22578 +}
22579 +
22580 +
22581 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22582 +{
22583 +       struct vcmd_nx_info_v0 vc_data;
22584 +
22585 +       vc_data.nid = nxi->nx_id;
22586 +
22587 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22588 +               return -EFAULT;
22589 +       return 0;
22590 +}
22591 +
22592 +
22593 +/* network functions */
22594 +
22595 +int vc_net_create(uint32_t nid, void __user *data)
22596 +{
22597 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22598 +       struct nx_info *new_nxi;
22599 +       int ret;
22600 +
22601 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22602 +               return -EFAULT;
22603 +
22604 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22605 +               return -EINVAL;
22606 +
22607 +       new_nxi = __create_nx_info(nid);
22608 +       if (IS_ERR(new_nxi))
22609 +               return PTR_ERR(new_nxi);
22610 +
22611 +       /* initial flags */
22612 +       new_nxi->nx_flags = vc_data.flagword;
22613 +
22614 +       ret = -ENOEXEC;
22615 +       if (vs_net_change(new_nxi, VSC_NETUP))
22616 +               goto out;
22617 +
22618 +       ret = nx_migrate_task(current, new_nxi);
22619 +       if (ret)
22620 +               goto out;
22621 +
22622 +       /* return context id on success */
22623 +       ret = new_nxi->nx_id;
22624 +
22625 +       /* get a reference for persistent contexts */
22626 +       if ((vc_data.flagword & NXF_PERSISTENT))
22627 +               nx_set_persistent(new_nxi);
22628 +out:
22629 +       release_nx_info(new_nxi, NULL);
22630 +       put_nx_info(new_nxi);
22631 +       return ret;
22632 +}
22633 +
22634 +
22635 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22636 +{
22637 +       return nx_migrate_task(current, nxi);
22638 +}
22639 +
22640 +
22641 +
22642 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22643 +       uint16_t type, uint16_t flags)
22644 +{
22645 +       struct nx_addr_v4 *nxa = &nxi->v4;
22646 +
22647 +       if (NX_IPV4(nxi)) {
22648 +               /* locate last entry */
22649 +               for (; nxa->next; nxa = nxa->next);
22650 +               nxa->next = __alloc_nx_addr_v4();
22651 +               nxa = nxa->next;
22652 +
22653 +               if (IS_ERR(nxa))
22654 +                       return PTR_ERR(nxa);
22655 +       }
22656 +
22657 +       if (nxi->v4.next)
22658 +               /* remove single ip for ip list */
22659 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22660 +
22661 +       nxa->ip[0].s_addr = ip;
22662 +       nxa->ip[1].s_addr = ip2;
22663 +       nxa->mask.s_addr = mask;
22664 +       nxa->type = type;
22665 +       nxa->flags = flags;
22666 +       return 0;
22667 +}
22668 +
22669 +
22670 +int vc_net_add(struct nx_info *nxi, void __user *data)
22671 +{
22672 +       struct vcmd_net_addr_v0 vc_data;
22673 +       int index, ret = 0;
22674 +
22675 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22676 +               return -EFAULT;
22677 +
22678 +       switch (vc_data.type) {
22679 +       case NXA_TYPE_IPV4:
22680 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22681 +                       return -EINVAL;
22682 +
22683 +               index = 0;
22684 +               while (index < vc_data.count) {
22685 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22686 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22687 +                       if (ret)
22688 +                               return ret;
22689 +                       index++;
22690 +               }
22691 +               ret = index;
22692 +               break;
22693 +
22694 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22695 +               nxi->v4_bcast = vc_data.ip[0];
22696 +               ret = 1;
22697 +               break;
22698 +
22699 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22700 +               nxi->v4_lback = vc_data.ip[0];
22701 +               ret = 1;
22702 +               break;
22703 +
22704 +       default:
22705 +               ret = -EINVAL;
22706 +               break;
22707 +       }
22708 +       return ret;
22709 +}
22710 +
22711 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22712 +{
22713 +       struct vcmd_net_addr_v0 vc_data;
22714 +
22715 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22716 +               return -EFAULT;
22717 +
22718 +       switch (vc_data.type) {
22719 +       case NXA_TYPE_ANY:
22720 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22721 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22722 +               break;
22723 +
22724 +       default:
22725 +               return -EINVAL;
22726 +       }
22727 +       return 0;
22728 +}
22729 +
22730 +
22731 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22732 +{
22733 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22734 +
22735 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22736 +               return -EFAULT;
22737 +
22738 +       switch (vc_data.type) {
22739 +       case NXA_TYPE_ADDR:
22740 +       case NXA_TYPE_RANGE:
22741 +       case NXA_TYPE_MASK:
22742 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22743 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22744 +
22745 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22746 +               nxi->v4_bcast = vc_data.ip;
22747 +               break;
22748 +
22749 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22750 +               nxi->v4_lback = vc_data.ip;
22751 +               break;
22752 +
22753 +       default:
22754 +               return -EINVAL;
22755 +       }
22756 +       return 0;
22757 +}
22758 +
22759 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22760 +{
22761 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22762 +
22763 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22764 +               return -EFAULT;
22765 +
22766 +       switch (vc_data.type) {
22767 +/*     case NXA_TYPE_ADDR:
22768 +               break;          */
22769 +
22770 +       case NXA_TYPE_ANY:
22771 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22772 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22773 +               break;
22774 +
22775 +       default:
22776 +               return -EINVAL;
22777 +       }
22778 +       return 0;
22779 +}
22780 +
22781 +
22782 +#ifdef CONFIG_IPV6
22783 +
22784 +int do_add_v6_addr(struct nx_info *nxi,
22785 +       struct in6_addr *ip, struct in6_addr *mask,
22786 +       uint32_t prefix, uint16_t type, uint16_t flags)
22787 +{
22788 +       struct nx_addr_v6 *nxa = &nxi->v6;
22789 +
22790 +       if (NX_IPV6(nxi)) {
22791 +               /* locate last entry */
22792 +               for (; nxa->next; nxa = nxa->next);
22793 +               nxa->next = __alloc_nx_addr_v6();
22794 +               nxa = nxa->next;
22795 +
22796 +               if (IS_ERR(nxa))
22797 +                       return PTR_ERR(nxa);
22798 +       }
22799 +
22800 +       nxa->ip = *ip;
22801 +       nxa->mask = *mask;
22802 +       nxa->prefix = prefix;
22803 +       nxa->type = type;
22804 +       nxa->flags = flags;
22805 +       return 0;
22806 +}
22807 +
22808 +
22809 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22810 +{
22811 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22812 +
22813 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22814 +               return -EFAULT;
22815 +
22816 +       switch (vc_data.type) {
22817 +       case NXA_TYPE_ADDR:
22818 +       case NXA_TYPE_MASK:
22819 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22820 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22821 +       default:
22822 +               return -EINVAL;
22823 +       }
22824 +       return 0;
22825 +}
22826 +
22827 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22828 +{
22829 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22830 +
22831 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22832 +               return -EFAULT;
22833 +
22834 +       switch (vc_data.type) {
22835 +       case NXA_TYPE_ANY:
22836 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22837 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22838 +               break;
22839 +
22840 +       default:
22841 +               return -EINVAL;
22842 +       }
22843 +       return 0;
22844 +}
22845 +
22846 +#endif /* CONFIG_IPV6 */
22847 +
22848 +
22849 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22850 +{
22851 +       struct vcmd_net_flags_v0 vc_data;
22852 +
22853 +       vc_data.flagword = nxi->nx_flags;
22854 +
22855 +       /* special STATE flag handling */
22856 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22857 +
22858 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22859 +               return -EFAULT;
22860 +       return 0;
22861 +}
22862 +
22863 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22864 +{
22865 +       struct vcmd_net_flags_v0 vc_data;
22866 +       uint64_t mask, trigger;
22867 +
22868 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22869 +               return -EFAULT;
22870 +
22871 +       /* special STATE flag handling */
22872 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22873 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22874 +
22875 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22876 +               vc_data.flagword, mask);
22877 +       if (trigger & NXF_PERSISTENT)
22878 +               nx_update_persistent(nxi);
22879 +
22880 +       return 0;
22881 +}
22882 +
22883 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22884 +{
22885 +       struct vcmd_net_caps_v0 vc_data;
22886 +
22887 +       vc_data.ncaps = nxi->nx_ncaps;
22888 +       vc_data.cmask = ~0ULL;
22889 +
22890 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22891 +               return -EFAULT;
22892 +       return 0;
22893 +}
22894 +
22895 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22896 +{
22897 +       struct vcmd_net_caps_v0 vc_data;
22898 +
22899 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22900 +               return -EFAULT;
22901 +
22902 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22903 +               vc_data.ncaps, vc_data.cmask);
22904 +       return 0;
22905 +}
22906 +
22907 +
22908 +#include <linux/module.h>
22909 +
22910 +module_init(init_network);
22911 +
22912 +EXPORT_SYMBOL_GPL(free_nx_info);
22913 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22914 +
22915 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/proc.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/proc.c
22916 --- linux-2.6.27.25/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
22917 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/proc.c  2008-10-31 18:15:28.000000000 +0100
22918 @@ -0,0 +1,1092 @@
22919 +/*
22920 + *  linux/kernel/vserver/proc.c
22921 + *
22922 + *  Virtual Context Support
22923 + *
22924 + *  Copyright (C) 2003-2007  Herbert Pötzl
22925 + *
22926 + *  V0.01  basic structure
22927 + *  V0.02  adaptation vs1.3.0
22928 + *  V0.03  proc permissions
22929 + *  V0.04  locking/generic
22930 + *  V0.05  next generation procfs
22931 + *  V0.06  inode validation
22932 + *  V0.07  generic rewrite vid
22933 + *  V0.08  remove inode type
22934 + *
22935 + */
22936 +
22937 +#include <linux/proc_fs.h>
22938 +#include <asm/unistd.h>
22939 +
22940 +#include <linux/vs_context.h>
22941 +#include <linux/vs_network.h>
22942 +#include <linux/vs_cvirt.h>
22943 +
22944 +#include <linux/in.h>
22945 +#include <linux/inetdevice.h>
22946 +#include <linux/vs_inet.h>
22947 +#include <linux/vs_inet6.h>
22948 +
22949 +#include <linux/vserver/global.h>
22950 +
22951 +#include "cvirt_proc.h"
22952 +#include "cacct_proc.h"
22953 +#include "limit_proc.h"
22954 +#include "sched_proc.h"
22955 +#include "vci_config.h"
22956 +
22957 +
22958 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22959 +{
22960 +       unsigned __capi;
22961 +
22962 +       CAP_FOR_EACH_U32(__capi) {
22963 +               buffer += sprintf(buffer, "%08x",
22964 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22965 +       }
22966 +       return buffer;
22967 +}
22968 +
22969 +
22970 +static struct proc_dir_entry *proc_virtual;
22971 +
22972 +static struct proc_dir_entry *proc_virtnet;
22973 +
22974 +
22975 +/* first the actual feeds */
22976 +
22977 +
22978 +static int proc_vci(char *buffer)
22979 +{
22980 +       return sprintf(buffer,
22981 +               "VCIVersion:\t%04x:%04x\n"
22982 +               "VCISyscall:\t%d\n"
22983 +               "VCIKernel:\t%08x\n",
22984 +               VCI_VERSION >> 16,
22985 +               VCI_VERSION & 0xFFFF,
22986 +               __NR_vserver,
22987 +               vci_kernel_config());
22988 +}
22989 +
22990 +static int proc_virtual_info(char *buffer)
22991 +{
22992 +       return proc_vci(buffer);
22993 +}
22994 +
22995 +static int proc_virtual_status(char *buffer)
22996 +{
22997 +       return sprintf(buffer,
22998 +               "#CTotal:\t%d\n"
22999 +               "#CActive:\t%d\n"
23000 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
23001 +               atomic_read(&vx_global_ctotal),
23002 +               atomic_read(&vx_global_cactive),
23003 +               atomic_read(&vs_global_nsproxy),
23004 +               atomic_read(&vs_global_fs),
23005 +               atomic_read(&vs_global_mnt_ns),
23006 +               atomic_read(&vs_global_uts_ns),
23007 +               atomic_read(&vs_global_ipc_ns),
23008 +               atomic_read(&vs_global_user_ns),
23009 +               atomic_read(&vs_global_pid_ns));
23010 +}
23011 +
23012 +
23013 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23014 +{
23015 +       int length;
23016 +
23017 +       length = sprintf(buffer,
23018 +               "ID:\t%d\n"
23019 +               "Info:\t%p\n"
23020 +               "Init:\t%d\n"
23021 +               "OOM:\t%lld\n",
23022 +               vxi->vx_id,
23023 +               vxi,
23024 +               vxi->vx_initpid,
23025 +               vxi->vx_badness_bias);
23026 +       return length;
23027 +}
23028 +
23029 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23030 +{
23031 +       char *orig = buffer;
23032 +
23033 +       buffer += sprintf(buffer,
23034 +               "UseCnt:\t%d\n"
23035 +               "Tasks:\t%d\n"
23036 +               "Flags:\t%016llx\n",
23037 +               atomic_read(&vxi->vx_usecnt),
23038 +               atomic_read(&vxi->vx_tasks),
23039 +               (unsigned long long)vxi->vx_flags);
23040 +
23041 +       buffer += sprintf(buffer, "BCaps:\t");
23042 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23043 +       buffer += sprintf(buffer, "\n");
23044 +
23045 +       buffer += sprintf(buffer,
23046 +               "CCaps:\t%016llx\n"
23047 +               "Spaces:\t%08lx %08lx\n",
23048 +               (unsigned long long)vxi->vx_ccaps,
23049 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23050 +       return buffer - orig;
23051 +}
23052 +
23053 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23054 +{
23055 +       return vx_info_proc_limit(&vxi->limit, buffer);
23056 +}
23057 +
23058 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23059 +{
23060 +       int cpu, length;
23061 +
23062 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23063 +       for_each_online_cpu(cpu) {
23064 +               length += vx_info_proc_sched_pc(
23065 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23066 +                       buffer + length, cpu);
23067 +       }
23068 +       return length;
23069 +}
23070 +
23071 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23072 +{
23073 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23074 +}
23075 +
23076 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23077 +{
23078 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23079 +}
23080 +
23081 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23082 +{
23083 +       int cpu, length;
23084 +
23085 +       vx_update_load(vxi);
23086 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23087 +       for_each_online_cpu(cpu) {
23088 +               length += vx_info_proc_cvirt_pc(
23089 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23090 +                       buffer + length, cpu);
23091 +       }
23092 +       return length;
23093 +}
23094 +
23095 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23096 +{
23097 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23098 +}
23099 +
23100 +
23101 +static int proc_virtnet_info(char *buffer)
23102 +{
23103 +       return proc_vci(buffer);
23104 +}
23105 +
23106 +static int proc_virtnet_status(char *buffer)
23107 +{
23108 +       return sprintf(buffer,
23109 +               "#CTotal:\t%d\n"
23110 +               "#CActive:\t%d\n",
23111 +               atomic_read(&nx_global_ctotal),
23112 +               atomic_read(&nx_global_cactive));
23113 +}
23114 +
23115 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23116 +{
23117 +       struct nx_addr_v4 *v4a;
23118 +#ifdef CONFIG_IPV6
23119 +       struct nx_addr_v6 *v6a;
23120 +#endif
23121 +       int length, i;
23122 +
23123 +       length = sprintf(buffer,
23124 +               "ID:\t%d\n"
23125 +               "Info:\t%p\n"
23126 +               "Bcast:\t" NIPQUAD_FMT "\n"
23127 +               "Lback:\t" NIPQUAD_FMT "\n",
23128 +               nxi->nx_id,
23129 +               nxi,
23130 +               NIPQUAD(nxi->v4_bcast.s_addr),
23131 +               NIPQUAD(nxi->v4_lback.s_addr));
23132 +
23133 +       if (!NX_IPV4(nxi))
23134 +               goto skip_v4;
23135 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23136 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23137 +                       i, NXAV4(v4a));
23138 +skip_v4:
23139 +#ifdef CONFIG_IPV6
23140 +       if (!NX_IPV6(nxi))
23141 +               goto skip_v6;
23142 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23143 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23144 +                       i, NXAV6(v6a));
23145 +skip_v6:
23146 +#endif
23147 +       return length;
23148 +}
23149 +
23150 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23151 +{
23152 +       int length;
23153 +
23154 +       length = sprintf(buffer,
23155 +               "UseCnt:\t%d\n"
23156 +               "Tasks:\t%d\n"
23157 +               "Flags:\t%016llx\n"
23158 +               "NCaps:\t%016llx\n",
23159 +               atomic_read(&nxi->nx_usecnt),
23160 +               atomic_read(&nxi->nx_tasks),
23161 +               (unsigned long long)nxi->nx_flags,
23162 +               (unsigned long long)nxi->nx_ncaps);
23163 +       return length;
23164 +}
23165 +
23166 +
23167 +
23168 +/* here the inode helpers */
23169 +
23170 +struct vs_entry {
23171 +       int len;
23172 +       char *name;
23173 +       mode_t mode;
23174 +       struct inode_operations *iop;
23175 +       struct file_operations *fop;
23176 +       union proc_op op;
23177 +};
23178 +
23179 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23180 +{
23181 +       struct inode *inode = new_inode(sb);
23182 +
23183 +       if (!inode)
23184 +               goto out;
23185 +
23186 +       inode->i_mode = p->mode;
23187 +       if (p->iop)
23188 +               inode->i_op = p->iop;
23189 +       if (p->fop)
23190 +               inode->i_fop = p->fop;
23191 +
23192 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23193 +       inode->i_flags |= S_IMMUTABLE;
23194 +
23195 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23196 +
23197 +       inode->i_uid = 0;
23198 +       inode->i_gid = 0;
23199 +       inode->i_tag = 0;
23200 +out:
23201 +       return inode;
23202 +}
23203 +
23204 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23205 +       struct dentry *dentry, int id, void *ptr)
23206 +{
23207 +       struct vs_entry *p = ptr;
23208 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23209 +       struct dentry *error = ERR_PTR(-EINVAL);
23210 +
23211 +       if (!inode)
23212 +               goto out;
23213 +
23214 +       PROC_I(inode)->op = p->op;
23215 +       PROC_I(inode)->fd = id;
23216 +       d_add(dentry, inode);
23217 +       error = NULL;
23218 +out:
23219 +       return error;
23220 +}
23221 +
23222 +/* Lookups */
23223 +
23224 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23225 +
23226 +/*
23227 + * Fill a directory entry.
23228 + *
23229 + * If possible create the dcache entry and derive our inode number and
23230 + * file type from dcache entry.
23231 + *
23232 + * Since all of the proc inode numbers are dynamically generated, the inode
23233 + * numbers do not exist until the inode is cache.  This means creating the
23234 + * the dcache entry in readdir is necessary to keep the inode numbers
23235 + * reported by readdir in sync with the inode numbers reported
23236 + * by stat.
23237 + */
23238 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23239 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23240 +{
23241 +       struct dentry *child, *dir = filp->f_dentry;
23242 +       struct inode *inode;
23243 +       struct qstr qname;
23244 +       ino_t ino = 0;
23245 +       unsigned type = DT_UNKNOWN;
23246 +
23247 +       qname.name = name;
23248 +       qname.len  = len;
23249 +       qname.hash = full_name_hash(name, len);
23250 +
23251 +       child = d_lookup(dir, &qname);
23252 +       if (!child) {
23253 +               struct dentry *new;
23254 +               new = d_alloc(dir, &qname);
23255 +               if (new) {
23256 +                       child = instantiate(dir->d_inode, new, id, ptr);
23257 +                       if (child)
23258 +                               dput(new);
23259 +                       else
23260 +                               child = new;
23261 +               }
23262 +       }
23263 +       if (!child || IS_ERR(child) || !child->d_inode)
23264 +               goto end_instantiate;
23265 +       inode = child->d_inode;
23266 +       if (inode) {
23267 +               ino = inode->i_ino;
23268 +               type = inode->i_mode >> 12;
23269 +       }
23270 +       dput(child);
23271 +end_instantiate:
23272 +       if (!ino)
23273 +               ino = find_inode_number(dir, &qname);
23274 +       if (!ino)
23275 +               ino = 1;
23276 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23277 +}
23278 +
23279 +
23280 +
23281 +/* get and revalidate vx_info/xid */
23282 +
23283 +static inline
23284 +struct vx_info *get_proc_vx_info(struct inode *inode)
23285 +{
23286 +       return lookup_vx_info(PROC_I(inode)->fd);
23287 +}
23288 +
23289 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23290 +{
23291 +       struct inode *inode = dentry->d_inode;
23292 +       xid_t xid = PROC_I(inode)->fd;
23293 +
23294 +       if (!xid || xid_is_hashed(xid))
23295 +               return 1;
23296 +       d_drop(dentry);
23297 +       return 0;
23298 +}
23299 +
23300 +
23301 +/* get and revalidate nx_info/nid */
23302 +
23303 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23304 +{
23305 +       struct inode *inode = dentry->d_inode;
23306 +       nid_t nid = PROC_I(inode)->fd;
23307 +
23308 +       if (!nid || nid_is_hashed(nid))
23309 +               return 1;
23310 +       d_drop(dentry);
23311 +       return 0;
23312 +}
23313 +
23314 +
23315 +
23316 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23317 +
23318 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23319 +                         size_t count, loff_t *ppos)
23320 +{
23321 +       struct inode *inode = file->f_dentry->d_inode;
23322 +       unsigned long page;
23323 +       ssize_t length = 0;
23324 +
23325 +       if (count > PROC_BLOCK_SIZE)
23326 +               count = PROC_BLOCK_SIZE;
23327 +
23328 +       /* fade that out as soon as stable */
23329 +       WARN_ON(PROC_I(inode)->fd);
23330 +
23331 +       if (!(page = __get_free_page(GFP_KERNEL)))
23332 +               return -ENOMEM;
23333 +
23334 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23335 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23336 +
23337 +       if (length >= 0)
23338 +               length = simple_read_from_buffer(buf, count, ppos,
23339 +                       (char *)page, length);
23340 +
23341 +       free_page(page);
23342 +       return length;
23343 +}
23344 +
23345 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23346 +                         size_t count, loff_t *ppos)
23347 +{
23348 +       struct inode *inode = file->f_dentry->d_inode;
23349 +       struct vx_info *vxi = NULL;
23350 +       xid_t xid = PROC_I(inode)->fd;
23351 +       unsigned long page;
23352 +       ssize_t length = 0;
23353 +
23354 +       if (count > PROC_BLOCK_SIZE)
23355 +               count = PROC_BLOCK_SIZE;
23356 +
23357 +       /* fade that out as soon as stable */
23358 +       WARN_ON(!xid);
23359 +       vxi = lookup_vx_info(xid);
23360 +       if (!vxi)
23361 +               goto out;
23362 +
23363 +       length = -ENOMEM;
23364 +       if (!(page = __get_free_page(GFP_KERNEL)))
23365 +               goto out_put;
23366 +
23367 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23368 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23369 +
23370 +       if (length >= 0)
23371 +               length = simple_read_from_buffer(buf, count, ppos,
23372 +                       (char *)page, length);
23373 +
23374 +       free_page(page);
23375 +out_put:
23376 +       put_vx_info(vxi);
23377 +out:
23378 +       return length;
23379 +}
23380 +
23381 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23382 +                         size_t count, loff_t *ppos)
23383 +{
23384 +       struct inode *inode = file->f_dentry->d_inode;
23385 +       struct nx_info *nxi = NULL;
23386 +       nid_t nid = PROC_I(inode)->fd;
23387 +       unsigned long page;
23388 +       ssize_t length = 0;
23389 +
23390 +       if (count > PROC_BLOCK_SIZE)
23391 +               count = PROC_BLOCK_SIZE;
23392 +
23393 +       /* fade that out as soon as stable */
23394 +       WARN_ON(!nid);
23395 +       nxi = lookup_nx_info(nid);
23396 +       if (!nxi)
23397 +               goto out;
23398 +
23399 +       length = -ENOMEM;
23400 +       if (!(page = __get_free_page(GFP_KERNEL)))
23401 +               goto out_put;
23402 +
23403 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23404 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23405 +
23406 +       if (length >= 0)
23407 +               length = simple_read_from_buffer(buf, count, ppos,
23408 +                       (char *)page, length);
23409 +
23410 +       free_page(page);
23411 +out_put:
23412 +       put_nx_info(nxi);
23413 +out:
23414 +       return length;
23415 +}
23416 +
23417 +
23418 +
23419 +/* here comes the lower level */
23420 +
23421 +
23422 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23423 +       .len  = sizeof(NAME) - 1,       \
23424 +       .name = (NAME),                 \
23425 +       .mode = MODE,                   \
23426 +       .iop  = IOP,                    \
23427 +       .fop  = FOP,                    \
23428 +       .op   = OP,                     \
23429 +}
23430 +
23431 +
23432 +#define DIR(NAME, MODE, OTYPE)                         \
23433 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23434 +               &proc_ ## OTYPE ## _inode_operations,   \
23435 +               &proc_ ## OTYPE ## _file_operations, { } )
23436 +
23437 +#define INF(NAME, MODE, OTYPE)                         \
23438 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23439 +               &proc_vs_info_file_operations,          \
23440 +               { .proc_vs_read = &proc_##OTYPE } )
23441 +
23442 +#define VINF(NAME, MODE, OTYPE)                                \
23443 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23444 +               &proc_vx_info_file_operations,          \
23445 +               { .proc_vxi_read = &proc_##OTYPE } )
23446 +
23447 +#define NINF(NAME, MODE, OTYPE)                                \
23448 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23449 +               &proc_nx_info_file_operations,          \
23450 +               { .proc_nxi_read = &proc_##OTYPE } )
23451 +
23452 +
23453 +static struct file_operations proc_vs_info_file_operations = {
23454 +       .read =         proc_vs_info_read,
23455 +};
23456 +
23457 +static struct file_operations proc_vx_info_file_operations = {
23458 +       .read =         proc_vx_info_read,
23459 +};
23460 +
23461 +static struct dentry_operations proc_xid_dentry_operations = {
23462 +       .d_revalidate = proc_xid_revalidate,
23463 +};
23464 +
23465 +static struct vs_entry vx_base_stuff[] = {
23466 +       VINF("info",    S_IRUGO, vxi_info),
23467 +       VINF("status",  S_IRUGO, vxi_status),
23468 +       VINF("limit",   S_IRUGO, vxi_limit),
23469 +       VINF("sched",   S_IRUGO, vxi_sched),
23470 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23471 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23472 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23473 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23474 +       {}
23475 +};
23476 +
23477 +
23478 +
23479 +
23480 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23481 +       struct dentry *dentry, int id, void *ptr)
23482 +{
23483 +       dentry->d_op = &proc_xid_dentry_operations;
23484 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23485 +}
23486 +
23487 +static struct dentry *proc_xid_lookup(struct inode *dir,
23488 +       struct dentry *dentry, struct nameidata *nd)
23489 +{
23490 +       struct vs_entry *p = vx_base_stuff;
23491 +       struct dentry *error = ERR_PTR(-ENOENT);
23492 +
23493 +       for (; p->name; p++) {
23494 +               if (p->len != dentry->d_name.len)
23495 +                       continue;
23496 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23497 +                       break;
23498 +       }
23499 +       if (!p->name)
23500 +               goto out;
23501 +
23502 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23503 +out:
23504 +       return error;
23505 +}
23506 +
23507 +static int proc_xid_readdir(struct file *filp,
23508 +       void *dirent, filldir_t filldir)
23509 +{
23510 +       struct dentry *dentry = filp->f_dentry;
23511 +       struct inode *inode = dentry->d_inode;
23512 +       struct vs_entry *p = vx_base_stuff;
23513 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23514 +       int pos, index;
23515 +       u64 ino;
23516 +
23517 +       pos = filp->f_pos;
23518 +       switch (pos) {
23519 +       case 0:
23520 +               ino = inode->i_ino;
23521 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23522 +                       goto out;
23523 +               pos++;
23524 +               /* fall through */
23525 +       case 1:
23526 +               ino = parent_ino(dentry);
23527 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23528 +                       goto out;
23529 +               pos++;
23530 +               /* fall through */
23531 +       default:
23532 +               index = pos - 2;
23533 +               if (index >= size)
23534 +                       goto out;
23535 +               for (p += index; p->name; p++) {
23536 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23537 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23538 +                               goto out;
23539 +                       pos++;
23540 +               }
23541 +       }
23542 +out:
23543 +       filp->f_pos = pos;
23544 +       return 1;
23545 +}
23546 +
23547 +
23548 +
23549 +static struct file_operations proc_nx_info_file_operations = {
23550 +       .read =         proc_nx_info_read,
23551 +};
23552 +
23553 +static struct dentry_operations proc_nid_dentry_operations = {
23554 +       .d_revalidate = proc_nid_revalidate,
23555 +};
23556 +
23557 +static struct vs_entry nx_base_stuff[] = {
23558 +       NINF("info",    S_IRUGO, nxi_info),
23559 +       NINF("status",  S_IRUGO, nxi_status),
23560 +       {}
23561 +};
23562 +
23563 +
23564 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23565 +       struct dentry *dentry, int id, void *ptr)
23566 +{
23567 +       dentry->d_op = &proc_nid_dentry_operations;
23568 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23569 +}
23570 +
23571 +static struct dentry *proc_nid_lookup(struct inode *dir,
23572 +       struct dentry *dentry, struct nameidata *nd)
23573 +{
23574 +       struct vs_entry *p = nx_base_stuff;
23575 +       struct dentry *error = ERR_PTR(-ENOENT);
23576 +
23577 +       for (; p->name; p++) {
23578 +               if (p->len != dentry->d_name.len)
23579 +                       continue;
23580 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23581 +                       break;
23582 +       }
23583 +       if (!p->name)
23584 +               goto out;
23585 +
23586 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23587 +out:
23588 +       return error;
23589 +}
23590 +
23591 +static int proc_nid_readdir(struct file *filp,
23592 +       void *dirent, filldir_t filldir)
23593 +{
23594 +       struct dentry *dentry = filp->f_dentry;
23595 +       struct inode *inode = dentry->d_inode;
23596 +       struct vs_entry *p = nx_base_stuff;
23597 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23598 +       int pos, index;
23599 +       u64 ino;
23600 +
23601 +       pos = filp->f_pos;
23602 +       switch (pos) {
23603 +       case 0:
23604 +               ino = inode->i_ino;
23605 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23606 +                       goto out;
23607 +               pos++;
23608 +               /* fall through */
23609 +       case 1:
23610 +               ino = parent_ino(dentry);
23611 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23612 +                       goto out;
23613 +               pos++;
23614 +               /* fall through */
23615 +       default:
23616 +               index = pos - 2;
23617 +               if (index >= size)
23618 +                       goto out;
23619 +               for (p += index; p->name; p++) {
23620 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23621 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23622 +                               goto out;
23623 +                       pos++;
23624 +               }
23625 +       }
23626 +out:
23627 +       filp->f_pos = pos;
23628 +       return 1;
23629 +}
23630 +
23631 +
23632 +#define MAX_MULBY10    ((~0U - 9) / 10)
23633 +
23634 +static inline int atovid(const char *str, int len)
23635 +{
23636 +       int vid, c;
23637 +
23638 +       vid = 0;
23639 +       while (len-- > 0) {
23640 +               c = *str - '0';
23641 +               str++;
23642 +               if (c > 9)
23643 +                       return -1;
23644 +               if (vid >= MAX_MULBY10)
23645 +                       return -1;
23646 +               vid *= 10;
23647 +               vid += c;
23648 +               if (!vid)
23649 +                       return -1;
23650 +       }
23651 +       return vid;
23652 +}
23653 +
23654 +/* now the upper level (virtual) */
23655 +
23656 +
23657 +static struct file_operations proc_xid_file_operations = {
23658 +       .read =         generic_read_dir,
23659 +       .readdir =      proc_xid_readdir,
23660 +};
23661 +
23662 +static struct inode_operations proc_xid_inode_operations = {
23663 +       .lookup =       proc_xid_lookup,
23664 +};
23665 +
23666 +static struct vs_entry vx_virtual_stuff[] = {
23667 +       INF("info",     S_IRUGO, virtual_info),
23668 +       INF("status",   S_IRUGO, virtual_status),
23669 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23670 +};
23671 +
23672 +
23673 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23674 +       struct dentry *dentry, struct nameidata *nd)
23675 +{
23676 +       struct vs_entry *p = vx_virtual_stuff;
23677 +       struct dentry *error = ERR_PTR(-ENOENT);
23678 +       int id = 0;
23679 +
23680 +       for (; p->name; p++) {
23681 +               if (p->len != dentry->d_name.len)
23682 +                       continue;
23683 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23684 +                       break;
23685 +       }
23686 +       if (p->name)
23687 +               goto instantiate;
23688 +
23689 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23690 +       if ((id < 0) || !xid_is_hashed(id))
23691 +               goto out;
23692 +
23693 +instantiate:
23694 +       error = proc_xid_instantiate(dir, dentry, id, p);
23695 +out:
23696 +       return error;
23697 +}
23698 +
23699 +static struct file_operations proc_nid_file_operations = {
23700 +       .read =         generic_read_dir,
23701 +       .readdir =      proc_nid_readdir,
23702 +};
23703 +
23704 +static struct inode_operations proc_nid_inode_operations = {
23705 +       .lookup =       proc_nid_lookup,
23706 +};
23707 +
23708 +static struct vs_entry nx_virtnet_stuff[] = {
23709 +       INF("info",     S_IRUGO, virtnet_info),
23710 +       INF("status",   S_IRUGO, virtnet_status),
23711 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23712 +};
23713 +
23714 +
23715 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23716 +       struct dentry *dentry, struct nameidata *nd)
23717 +{
23718 +       struct vs_entry *p = nx_virtnet_stuff;
23719 +       struct dentry *error = ERR_PTR(-ENOENT);
23720 +       int id = 0;
23721 +
23722 +       for (; p->name; p++) {
23723 +               if (p->len != dentry->d_name.len)
23724 +                       continue;
23725 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23726 +                       break;
23727 +       }
23728 +       if (p->name)
23729 +               goto instantiate;
23730 +
23731 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23732 +       if ((id < 0) || !nid_is_hashed(id))
23733 +               goto out;
23734 +
23735 +instantiate:
23736 +       error = proc_nid_instantiate(dir, dentry, id, p);
23737 +out:
23738 +       return error;
23739 +}
23740 +
23741 +
23742 +#define PROC_MAXVIDS 32
23743 +
23744 +int proc_virtual_readdir(struct file *filp,
23745 +       void *dirent, filldir_t filldir)
23746 +{
23747 +       struct dentry *dentry = filp->f_dentry;
23748 +       struct inode *inode = dentry->d_inode;
23749 +       struct vs_entry *p = vx_virtual_stuff;
23750 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23751 +       int pos, index;
23752 +       unsigned int xid_array[PROC_MAXVIDS];
23753 +       char buf[PROC_NUMBUF];
23754 +       unsigned int nr_xids, i;
23755 +       u64 ino;
23756 +
23757 +       pos = filp->f_pos;
23758 +       switch (pos) {
23759 +       case 0:
23760 +               ino = inode->i_ino;
23761 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23762 +                       goto out;
23763 +               pos++;
23764 +               /* fall through */
23765 +       case 1:
23766 +               ino = parent_ino(dentry);
23767 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23768 +                       goto out;
23769 +               pos++;
23770 +               /* fall through */
23771 +       default:
23772 +               index = pos - 2;
23773 +               if (index >= size)
23774 +                       goto entries;
23775 +               for (p += index; p->name; p++) {
23776 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23777 +                               vs_proc_instantiate, 0, p))
23778 +                               goto out;
23779 +                       pos++;
23780 +               }
23781 +       entries:
23782 +               index = pos - size;
23783 +               p = &vx_virtual_stuff[size - 1];
23784 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23785 +               for (i = 0; i < nr_xids; i++) {
23786 +                       int n, xid = xid_array[i];
23787 +                       unsigned int j = PROC_NUMBUF;
23788 +
23789 +                       n = xid;
23790 +                       do
23791 +                               buf[--j] = '0' + (n % 10);
23792 +                       while (n /= 10);
23793 +
23794 +                       if (proc_fill_cache(filp, dirent, filldir,
23795 +                               buf + j, PROC_NUMBUF - j,
23796 +                               vs_proc_instantiate, xid, p))
23797 +                               goto out;
23798 +                       pos++;
23799 +               }
23800 +       }
23801 +out:
23802 +       filp->f_pos = pos;
23803 +       return 0;
23804 +}
23805 +
23806 +static int proc_virtual_getattr(struct vfsmount *mnt,
23807 +       struct dentry *dentry, struct kstat *stat)
23808 +{
23809 +       struct inode *inode = dentry->d_inode;
23810 +
23811 +       generic_fillattr(inode, stat);
23812 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23813 +       return 0;
23814 +}
23815 +
23816 +static struct file_operations proc_virtual_dir_operations = {
23817 +       .read =         generic_read_dir,
23818 +       .readdir =      proc_virtual_readdir,
23819 +};
23820 +
23821 +static struct inode_operations proc_virtual_dir_inode_operations = {
23822 +       .getattr =      proc_virtual_getattr,
23823 +       .lookup =       proc_virtual_lookup,
23824 +};
23825 +
23826 +
23827 +
23828 +
23829 +
23830 +int proc_virtnet_readdir(struct file *filp,
23831 +       void *dirent, filldir_t filldir)
23832 +{
23833 +       struct dentry *dentry = filp->f_dentry;
23834 +       struct inode *inode = dentry->d_inode;
23835 +       struct vs_entry *p = nx_virtnet_stuff;
23836 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23837 +       int pos, index;
23838 +       unsigned int nid_array[PROC_MAXVIDS];
23839 +       char buf[PROC_NUMBUF];
23840 +       unsigned int nr_nids, i;
23841 +       u64 ino;
23842 +
23843 +       pos = filp->f_pos;
23844 +       switch (pos) {
23845 +       case 0:
23846 +               ino = inode->i_ino;
23847 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23848 +                       goto out;
23849 +               pos++;
23850 +               /* fall through */
23851 +       case 1:
23852 +               ino = parent_ino(dentry);
23853 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23854 +                       goto out;
23855 +               pos++;
23856 +               /* fall through */
23857 +       default:
23858 +               index = pos - 2;
23859 +               if (index >= size)
23860 +                       goto entries;
23861 +               for (p += index; p->name; p++) {
23862 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23863 +                               vs_proc_instantiate, 0, p))
23864 +                               goto out;
23865 +                       pos++;
23866 +               }
23867 +       entries:
23868 +               index = pos - size;
23869 +               p = &nx_virtnet_stuff[size - 1];
23870 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23871 +               for (i = 0; i < nr_nids; i++) {
23872 +                       int n, nid = nid_array[i];
23873 +                       unsigned int j = PROC_NUMBUF;
23874 +
23875 +                       n = nid;
23876 +                       do
23877 +                               buf[--j] = '0' + (n % 10);
23878 +                       while (n /= 10);
23879 +
23880 +                       if (proc_fill_cache(filp, dirent, filldir,
23881 +                               buf + j, PROC_NUMBUF - j,
23882 +                               vs_proc_instantiate, nid, p))
23883 +                               goto out;
23884 +                       pos++;
23885 +               }
23886 +       }
23887 +out:
23888 +       filp->f_pos = pos;
23889 +       return 0;
23890 +}
23891 +
23892 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23893 +       struct dentry *dentry, struct kstat *stat)
23894 +{
23895 +       struct inode *inode = dentry->d_inode;
23896 +
23897 +       generic_fillattr(inode, stat);
23898 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23899 +       return 0;
23900 +}
23901 +
23902 +static struct file_operations proc_virtnet_dir_operations = {
23903 +       .read =         generic_read_dir,
23904 +       .readdir =      proc_virtnet_readdir,
23905 +};
23906 +
23907 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23908 +       .getattr =      proc_virtnet_getattr,
23909 +       .lookup =       proc_virtnet_lookup,
23910 +};
23911 +
23912 +
23913 +
23914 +void proc_vx_init(void)
23915 +{
23916 +       struct proc_dir_entry *ent;
23917 +
23918 +       ent = proc_mkdir("virtual", 0);
23919 +       if (ent) {
23920 +               ent->proc_fops = &proc_virtual_dir_operations;
23921 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23922 +       }
23923 +       proc_virtual = ent;
23924 +
23925 +       ent = proc_mkdir("virtnet", 0);
23926 +       if (ent) {
23927 +               ent->proc_fops = &proc_virtnet_dir_operations;
23928 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23929 +       }
23930 +       proc_virtnet = ent;
23931 +}
23932 +
23933 +
23934 +
23935 +
23936 +/* per pid info */
23937 +
23938 +
23939 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23940 +{
23941 +       struct vx_info *vxi;
23942 +       char *orig = buffer;
23943 +
23944 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23945 +
23946 +       vxi = task_get_vx_info(p);
23947 +       if (!vxi)
23948 +               goto out;
23949 +
23950 +       buffer += sprintf(buffer, "BCaps:\t");
23951 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23952 +       buffer += sprintf(buffer, "\n");
23953 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23954 +               (unsigned long long)vxi->vx_ccaps);
23955 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23956 +               (unsigned long long)vxi->vx_flags);
23957 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23958 +
23959 +       put_vx_info(vxi);
23960 +out:
23961 +       return buffer - orig;
23962 +}
23963 +
23964 +
23965 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23966 +{
23967 +       struct nx_info *nxi;
23968 +       struct nx_addr_v4 *v4a;
23969 +#ifdef CONFIG_IPV6
23970 +       struct nx_addr_v6 *v6a;
23971 +#endif
23972 +       char *orig = buffer;
23973 +       int i;
23974 +
23975 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23976 +
23977 +       nxi = task_get_nx_info(p);
23978 +       if (!nxi)
23979 +               goto out;
23980 +
23981 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23982 +               (unsigned long long)nxi->nx_ncaps);
23983 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23984 +               (unsigned long long)nxi->nx_flags);
23985 +
23986 +       buffer += sprintf(buffer,
23987 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23988 +               NIPQUAD(nxi->v4_bcast.s_addr));
23989 +       buffer += sprintf (buffer,
23990 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23991 +               NIPQUAD(nxi->v4_lback.s_addr));
23992 +       if (!NX_IPV4(nxi))
23993 +               goto skip_v4;
23994 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23995 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23996 +                       i, NXAV4(v4a));
23997 +skip_v4:
23998 +#ifdef CONFIG_IPV6
23999 +       if (!NX_IPV6(nxi))
24000 +               goto skip_v6;
24001 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24002 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24003 +                       i, NXAV6(v6a));
24004 +skip_v6:
24005 +#endif
24006 +       put_nx_info(nxi);
24007 +out:
24008 +       return buffer - orig;
24009 +}
24010 +
24011 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/sched.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sched.c
24012 --- linux-2.6.27.25/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
24013 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sched.c 2009-03-09 15:36:36.000000000 +0100
24014 @@ -0,0 +1,414 @@
24015 +/*
24016 + *  linux/kernel/vserver/sched.c
24017 + *
24018 + *  Virtual Server: Scheduler Support
24019 + *
24020 + *  Copyright (C) 2004-2007  Herbert Pötzl
24021 + *
24022 + *  V0.01  adapted Sam Vilains version to 2.6.3
24023 + *  V0.02  removed legacy interface
24024 + *  V0.03  changed vcmds to vxi arg
24025 + *  V0.04  removed older and legacy interfaces
24026 + *
24027 + */
24028 +
24029 +#include <linux/vs_context.h>
24030 +#include <linux/vs_sched.h>
24031 +#include <linux/vserver/sched_cmd.h>
24032 +
24033 +#include <asm/uaccess.h>
24034 +
24035 +
24036 +#define vxd_check_range(val, min, max) do {            \
24037 +       vxlprintk((val < min) || (val > max),           \
24038 +               "check_range(%ld,%ld,%ld)",             \
24039 +               (long)val, (long)min, (long)max,        \
24040 +               __FILE__, __LINE__);                    \
24041 +       } while (0)
24042 +
24043 +
24044 +void vx_update_sched_param(struct _vx_sched *sched,
24045 +       struct _vx_sched_pc *sched_pc)
24046 +{
24047 +       unsigned int set_mask = sched->update_mask;
24048 +
24049 +       if (set_mask & VXSM_FILL_RATE)
24050 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24051 +       if (set_mask & VXSM_INTERVAL)
24052 +               sched_pc->interval[0] = sched->interval[0];
24053 +       if (set_mask & VXSM_FILL_RATE2)
24054 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24055 +       if (set_mask & VXSM_INTERVAL2)
24056 +               sched_pc->interval[1] = sched->interval[1];
24057 +       if (set_mask & VXSM_TOKENS)
24058 +               sched_pc->tokens = sched->tokens;
24059 +       if (set_mask & VXSM_TOKENS_MIN)
24060 +               sched_pc->tokens_min = sched->tokens_min;
24061 +       if (set_mask & VXSM_TOKENS_MAX)
24062 +               sched_pc->tokens_max = sched->tokens_max;
24063 +       if (set_mask & VXSM_PRIO_BIAS)
24064 +               sched_pc->prio_bias = sched->prio_bias;
24065 +
24066 +       if (set_mask & VXSM_IDLE_TIME)
24067 +               sched_pc->flags |= VXSF_IDLE_TIME;
24068 +       else
24069 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24070 +
24071 +       /* reset time */
24072 +       sched_pc->norm_time = jiffies;
24073 +}
24074 +
24075 +
24076 +/*
24077 + * recalculate the context's scheduling tokens
24078 + *
24079 + * ret > 0 : number of tokens available
24080 + * ret < 0 : on hold, check delta_min[]
24081 + *          -1 only jiffies
24082 + *          -2 also idle time
24083 + *
24084 + */
24085 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24086 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24087 +{
24088 +       long delta;
24089 +       long tokens = 0;
24090 +       int flags = sched_pc->flags;
24091 +
24092 +       /* how much time did pass? */
24093 +       delta = *norm_time - sched_pc->norm_time;
24094 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24095 +       vxd_check_range(delta, 0, INT_MAX);
24096 +
24097 +       if (delta >= sched_pc->interval[0]) {
24098 +               long tokens, integral;
24099 +
24100 +               /* calc integral token part */
24101 +               tokens = delta / sched_pc->interval[0];
24102 +               integral = tokens * sched_pc->interval[0];
24103 +               tokens *= sched_pc->fill_rate[0];
24104 +#ifdef CONFIG_VSERVER_HARDCPU
24105 +               delta_min[0] = delta - integral;
24106 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24107 +#endif
24108 +               /* advance time */
24109 +               sched_pc->norm_time += delta;
24110 +
24111 +               /* add tokens */
24112 +               sched_pc->tokens += tokens;
24113 +               sched_pc->token_time += tokens;
24114 +       } else
24115 +               delta_min[0] = delta;
24116 +
24117 +#ifdef CONFIG_VSERVER_IDLETIME
24118 +       if (!(flags & VXSF_IDLE_TIME))
24119 +               goto skip_idle;
24120 +
24121 +       /* how much was the idle skip? */
24122 +       delta = *idle_time - sched_pc->idle_time;
24123 +       vxd_check_range(delta, 0, INT_MAX);
24124 +
24125 +       if (delta >= sched_pc->interval[1]) {
24126 +               long tokens, integral;
24127 +
24128 +               /* calc fair share token part */
24129 +               tokens = delta / sched_pc->interval[1];
24130 +               integral = tokens * sched_pc->interval[1];
24131 +               tokens *= sched_pc->fill_rate[1];
24132 +               delta_min[1] = delta - integral;
24133 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24134 +
24135 +               /* advance idle time */
24136 +               sched_pc->idle_time += integral;
24137 +
24138 +               /* add tokens */
24139 +               sched_pc->tokens += tokens;
24140 +               sched_pc->token_time += tokens;
24141 +       } else
24142 +               delta_min[1] = delta;
24143 +skip_idle:
24144 +#endif
24145 +
24146 +       /* clip at maximum */
24147 +       if (sched_pc->tokens > sched_pc->tokens_max)
24148 +               sched_pc->tokens = sched_pc->tokens_max;
24149 +       tokens = sched_pc->tokens;
24150 +
24151 +       if ((flags & VXSF_ONHOLD)) {
24152 +               /* can we unhold? */
24153 +               if (tokens >= sched_pc->tokens_min) {
24154 +                       flags &= ~VXSF_ONHOLD;
24155 +                       sched_pc->hold_ticks +=
24156 +                               *norm_time - sched_pc->onhold;
24157 +               } else
24158 +                       goto on_hold;
24159 +       } else {
24160 +               /* put on hold? */
24161 +               if (tokens <= 0) {
24162 +                       flags |= VXSF_ONHOLD;
24163 +                       sched_pc->onhold = *norm_time;
24164 +                       goto on_hold;
24165 +               }
24166 +       }
24167 +       sched_pc->flags = flags;
24168 +       return tokens;
24169 +
24170 +on_hold:
24171 +       tokens = sched_pc->tokens_min - tokens;
24172 +       sched_pc->flags = flags;
24173 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24174 +
24175 +#ifdef CONFIG_VSERVER_HARDCPU
24176 +       /* next interval? */
24177 +       if (!sched_pc->fill_rate[0])
24178 +               delta_min[0] = HZ;
24179 +       else if (tokens > sched_pc->fill_rate[0])
24180 +               delta_min[0] += sched_pc->interval[0] *
24181 +                       tokens / sched_pc->fill_rate[0];
24182 +       else
24183 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24184 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24185 +
24186 +#ifdef CONFIG_VSERVER_IDLETIME
24187 +       if (!(flags & VXSF_IDLE_TIME))
24188 +               return -1;
24189 +
24190 +       /* next interval? */
24191 +       if (!sched_pc->fill_rate[1])
24192 +               delta_min[1] = HZ;
24193 +       else if (tokens > sched_pc->fill_rate[1])
24194 +               delta_min[1] += sched_pc->interval[1] *
24195 +                       tokens / sched_pc->fill_rate[1];
24196 +       else
24197 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24198 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24199 +
24200 +       return -2;
24201 +#else
24202 +       return -1;
24203 +#endif /* CONFIG_VSERVER_IDLETIME */
24204 +#else
24205 +       return 0;
24206 +#endif /* CONFIG_VSERVER_HARDCPU */
24207 +}
24208 +
24209 +static inline unsigned long msec_to_ticks(unsigned long msec)
24210 +{
24211 +       return msecs_to_jiffies(msec);
24212 +}
24213 +
24214 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24215 +{
24216 +       return jiffies_to_msecs(ticks);
24217 +}
24218 +
24219 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24220 +{
24221 +       return jiffies_to_usecs(ticks);
24222 +}
24223 +
24224 +
24225 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24226 +{
24227 +       unsigned int set_mask = data->mask;
24228 +       unsigned int update_mask;
24229 +       int i, cpu;
24230 +
24231 +       /* Sanity check data values */
24232 +       if (data->tokens_max <= 0)
24233 +               data->tokens_max = HZ;
24234 +       if (data->tokens_min < 0)
24235 +               data->tokens_min = HZ / 3;
24236 +       if (data->tokens_min >= data->tokens_max)
24237 +               data->tokens_min = data->tokens_max;
24238 +
24239 +       if (data->prio_bias > MAX_PRIO_BIAS)
24240 +               data->prio_bias = MAX_PRIO_BIAS;
24241 +       if (data->prio_bias < MIN_PRIO_BIAS)
24242 +               data->prio_bias = MIN_PRIO_BIAS;
24243 +
24244 +       spin_lock(&vxi->sched.tokens_lock);
24245 +
24246 +       /* sync up on delayed updates */
24247 +       for_each_cpu_mask(cpu, vxi->sched.update)
24248 +               vx_update_sched_param(&vxi->sched,
24249 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24250 +
24251 +       if (set_mask & VXSM_FILL_RATE)
24252 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24253 +       if (set_mask & VXSM_FILL_RATE2)
24254 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24255 +       if (set_mask & VXSM_INTERVAL)
24256 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24257 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24258 +       if (set_mask & VXSM_INTERVAL2)
24259 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24260 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24261 +       if (set_mask & VXSM_TOKENS)
24262 +               vxi->sched.tokens = data->tokens;
24263 +       if (set_mask & VXSM_TOKENS_MIN)
24264 +               vxi->sched.tokens_min = data->tokens_min;
24265 +       if (set_mask & VXSM_TOKENS_MAX)
24266 +               vxi->sched.tokens_max = data->tokens_max;
24267 +       if (set_mask & VXSM_PRIO_BIAS)
24268 +               vxi->sched.prio_bias = data->prio_bias;
24269 +
24270 +       /* Sanity check rate/interval */
24271 +       for (i = 0; i < 2; i++) {
24272 +               if (data->fill_rate[i] < 0)
24273 +                       data->fill_rate[i] = 0;
24274 +               if (data->interval[i] <= 0)
24275 +                       data->interval[i] = HZ;
24276 +       }
24277 +
24278 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24279 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24280 +       vxi->sched.update_mask = update_mask;
24281 +
24282 +#ifdef CONFIG_SMP
24283 +       rmb();
24284 +       if (set_mask & VXSM_CPU_ID) {
24285 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24286 +               cpus_and(vxi->sched.update, cpu_online_map,
24287 +                       vxi->sched.update);
24288 +       } else
24289 +               vxi->sched.update = cpu_online_map;
24290 +
24291 +       /* forced reload? */
24292 +       if (set_mask & VXSM_FORCE) {
24293 +               for_each_cpu_mask(cpu, vxi->sched.update)
24294 +                       vx_update_sched_param(&vxi->sched,
24295 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24296 +               vxi->sched.update = CPU_MASK_NONE;
24297 +       }
24298 +#else
24299 +       /* on UP we update immediately */
24300 +       vx_update_sched_param(&vxi->sched,
24301 +               &vx_per_cpu(vxi, sched_pc, 0));
24302 +#endif
24303 +
24304 +       spin_unlock(&vxi->sched.tokens_lock);
24305 +       return 0;
24306 +}
24307 +
24308 +
24309 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24310 +#define COPY_PRI(C) C(prio_bias)
24311 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24312 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24313 +                   C(fill_rate[1]); C(interval[1]);
24314 +
24315 +#define COPY_VALUE(name) vc_data.name = data->name
24316 +
24317 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24318 +{
24319 +       struct vcmd_sched_v5 vc_data;
24320 +
24321 +       vc_data.mask = data->set_mask;
24322 +       COPY_IDS(COPY_VALUE);
24323 +       COPY_PRI(COPY_VALUE);
24324 +       COPY_TOK(COPY_VALUE);
24325 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24326 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24327 +       return do_set_sched(vxi, &vc_data);
24328 +}
24329 +
24330 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24331 +{
24332 +       struct vcmd_set_sched_v4 vc_data;
24333 +
24334 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24335 +               return -EFAULT;
24336 +
24337 +       return do_set_sched_v4(vxi, &vc_data);
24338 +}
24339 +
24340 +       /* latest interface is v5 */
24341 +
24342 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24343 +{
24344 +       struct vcmd_sched_v5 vc_data;
24345 +
24346 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24347 +               return -EFAULT;
24348 +
24349 +       return do_set_sched(vxi, &vc_data);
24350 +}
24351 +
24352 +
24353 +#define COPY_PRI(C) C(prio_bias)
24354 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24355 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24356 +                   C(fill_rate[1]); C(interval[1]);
24357 +
24358 +#define COPY_VALUE(name) vc_data.name = data->name
24359 +
24360 +
24361 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24362 +{
24363 +       struct vcmd_sched_v5 vc_data;
24364 +
24365 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24366 +               return -EFAULT;
24367 +
24368 +       if (vc_data.mask & VXSM_CPU_ID) {
24369 +               int cpu = vc_data.cpu_id;
24370 +               struct _vx_sched_pc *data;
24371 +
24372 +               if (!cpu_possible(cpu))
24373 +                       return -EINVAL;
24374 +
24375 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24376 +               COPY_TOK(COPY_VALUE);
24377 +               COPY_PRI(COPY_VALUE);
24378 +               COPY_FRI(COPY_VALUE);
24379 +
24380 +               if (data->flags & VXSF_IDLE_TIME)
24381 +                       vc_data.mask |= VXSM_IDLE_TIME;
24382 +       } else {
24383 +               struct _vx_sched *data = &vxi->sched;
24384 +
24385 +               COPY_TOK(COPY_VALUE);
24386 +               COPY_PRI(COPY_VALUE);
24387 +               COPY_FRI(COPY_VALUE);
24388 +       }
24389 +
24390 +       if (vc_data.mask & VXSM_MSEC) {
24391 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24392 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24393 +       }
24394 +
24395 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24396 +               return -EFAULT;
24397 +       return 0;
24398 +}
24399 +
24400 +
24401 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24402 +{
24403 +       struct vcmd_sched_info vc_data;
24404 +       int cpu;
24405 +
24406 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24407 +               return -EFAULT;
24408 +
24409 +       cpu = vc_data.cpu_id;
24410 +       if (!cpu_possible(cpu))
24411 +               return -EINVAL;
24412 +
24413 +       if (vxi) {
24414 +               struct _vx_sched_pc *sched_pc =
24415 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24416 +
24417 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24418 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24419 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24420 +               vc_data.vavavoom = sched_pc->vavavoom;
24421 +       }
24422 +       vc_data.token_usec = ticks_to_usec(1);
24423 +
24424 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24425 +               return -EFAULT;
24426 +       return 0;
24427 +}
24428 +
24429 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/sched_init.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sched_init.h
24430 --- linux-2.6.27.25/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
24431 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sched_init.h    2008-10-13 14:54:20.000000000 +0200
24432 @@ -0,0 +1,50 @@
24433 +
24434 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24435 +{
24436 +       static struct lock_class_key tokens_lock_key;
24437 +
24438 +       /* scheduling; hard code starting values as constants */
24439 +       sched->fill_rate[0]     = 1;
24440 +       sched->interval[0]      = 4;
24441 +       sched->fill_rate[1]     = 1;
24442 +       sched->interval[1]      = 8;
24443 +       sched->tokens           = HZ >> 2;
24444 +       sched->tokens_min       = HZ >> 4;
24445 +       sched->tokens_max       = HZ >> 1;
24446 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24447 +       sched->prio_bias        = 0;
24448 +
24449 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24450 +}
24451 +
24452 +static inline
24453 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24454 +{
24455 +       sched_pc->fill_rate[0]  = 1;
24456 +       sched_pc->interval[0]   = 4;
24457 +       sched_pc->fill_rate[1]  = 1;
24458 +       sched_pc->interval[1]   = 8;
24459 +       sched_pc->tokens        = HZ >> 2;
24460 +       sched_pc->tokens_min    = HZ >> 4;
24461 +       sched_pc->tokens_max    = HZ >> 1;
24462 +       sched_pc->prio_bias     = 0;
24463 +       sched_pc->vavavoom      = 0;
24464 +       sched_pc->token_time    = 0;
24465 +       sched_pc->idle_time     = 0;
24466 +       sched_pc->norm_time     = jiffies;
24467 +
24468 +       sched_pc->user_ticks = 0;
24469 +       sched_pc->sys_ticks = 0;
24470 +       sched_pc->hold_ticks = 0;
24471 +}
24472 +
24473 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24474 +{
24475 +       return;
24476 +}
24477 +
24478 +static inline
24479 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24480 +{
24481 +       return;
24482 +}
24483 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/sched_proc.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sched_proc.h
24484 --- linux-2.6.27.25/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
24485 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sched_proc.h    2008-10-13 14:54:20.000000000 +0200
24486 @@ -0,0 +1,57 @@
24487 +#ifndef _VX_SCHED_PROC_H
24488 +#define _VX_SCHED_PROC_H
24489 +
24490 +
24491 +static inline
24492 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24493 +{
24494 +       int length = 0;
24495 +
24496 +       length += sprintf(buffer,
24497 +               "FillRate:\t%8d,%d\n"
24498 +               "Interval:\t%8d,%d\n"
24499 +               "TokensMin:\t%8d\n"
24500 +               "TokensMax:\t%8d\n"
24501 +               "PrioBias:\t%8d\n",
24502 +               sched->fill_rate[0],
24503 +               sched->fill_rate[1],
24504 +               sched->interval[0],
24505 +               sched->interval[1],
24506 +               sched->tokens_min,
24507 +               sched->tokens_max,
24508 +               sched->prio_bias);
24509 +       return length;
24510 +}
24511 +
24512 +static inline
24513 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24514 +       char *buffer, int cpu)
24515 +{
24516 +       int length = 0;
24517 +
24518 +       length += sprintf(buffer + length,
24519 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24520 +               (unsigned long long)sched_pc->user_ticks,
24521 +               (unsigned long long)sched_pc->sys_ticks,
24522 +               (unsigned long long)sched_pc->hold_ticks,
24523 +               sched_pc->token_time,
24524 +               sched_pc->idle_time);
24525 +       length += sprintf(buffer + length,
24526 +               " %c%c %d %d %d %d/%d %d/%d",
24527 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24528 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24529 +               sched_pc->tokens,
24530 +               sched_pc->tokens_min,
24531 +               sched_pc->tokens_max,
24532 +               sched_pc->fill_rate[0],
24533 +               sched_pc->interval[0],
24534 +               sched_pc->fill_rate[1],
24535 +               sched_pc->interval[1]);
24536 +       length += sprintf(buffer + length,
24537 +               " %d %d\n",
24538 +               sched_pc->prio_bias,
24539 +               sched_pc->vavavoom);
24540 +       return length;
24541 +}
24542 +
24543 +#endif /* _VX_SCHED_PROC_H */
24544 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/signal.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/signal.c
24545 --- linux-2.6.27.25/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
24546 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/signal.c        2008-10-13 14:54:20.000000000 +0200
24547 @@ -0,0 +1,132 @@
24548 +/*
24549 + *  linux/kernel/vserver/signal.c
24550 + *
24551 + *  Virtual Server: Signal Support
24552 + *
24553 + *  Copyright (C) 2003-2007  Herbert Pötzl
24554 + *
24555 + *  V0.01  broken out from vcontext V0.05
24556 + *  V0.02  changed vcmds to vxi arg
24557 + *  V0.03  adjusted siginfo for kill
24558 + *
24559 + */
24560 +
24561 +#include <asm/uaccess.h>
24562 +
24563 +#include <linux/vs_context.h>
24564 +#include <linux/vs_pid.h>
24565 +#include <linux/vserver/signal_cmd.h>
24566 +
24567 +
24568 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24569 +{
24570 +       int retval, count = 0;
24571 +       struct task_struct *p;
24572 +       struct siginfo *sip = SEND_SIG_PRIV;
24573 +
24574 +       retval = -ESRCH;
24575 +       vxdprintk(VXD_CBIT(misc, 4),
24576 +               "vx_info_kill(%p[#%d],%d,%d)*",
24577 +               vxi, vxi->vx_id, pid, sig);
24578 +       read_lock(&tasklist_lock);
24579 +       switch (pid) {
24580 +       case  0:
24581 +       case -1:
24582 +               for_each_process(p) {
24583 +                       int err = 0;
24584 +
24585 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24586 +                               (pid && vxi->vx_initpid == p->pid))
24587 +                               continue;
24588 +
24589 +                       err = group_send_sig_info(sig, sip, p);
24590 +                       ++count;
24591 +                       if (err != -EPERM)
24592 +                               retval = err;
24593 +               }
24594 +               break;
24595 +
24596 +       case 1:
24597 +               if (vxi->vx_initpid) {
24598 +                       pid = vxi->vx_initpid;
24599 +                       /* for now, only SIGINT to private init ... */
24600 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24601 +                               /* ... as long as there are tasks left */
24602 +                               (atomic_read(&vxi->vx_tasks) > 1))
24603 +                               sig = SIGINT;
24604 +               }
24605 +               /* fallthrough */
24606 +       default:
24607 +               p = find_task_by_real_pid(pid);
24608 +               if (p) {
24609 +                       if (vx_task_xid(p) == vxi->vx_id)
24610 +                               retval = group_send_sig_info(sig, sip, p);
24611 +               }
24612 +               break;
24613 +       }
24614 +       read_unlock(&tasklist_lock);
24615 +       vxdprintk(VXD_CBIT(misc, 4),
24616 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24617 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24618 +       return retval;
24619 +}
24620 +
24621 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24622 +{
24623 +       struct vcmd_ctx_kill_v0 vc_data;
24624 +
24625 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24626 +               return -EFAULT;
24627 +
24628 +       /* special check to allow guest shutdown */
24629 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24630 +               /* forbid killall pid=0 when init is present */
24631 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24632 +               (vc_data.pid > 1)))
24633 +               return -EACCES;
24634 +
24635 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24636 +}
24637 +
24638 +
24639 +static int __wait_exit(struct vx_info *vxi)
24640 +{
24641 +       DECLARE_WAITQUEUE(wait, current);
24642 +       int ret = 0;
24643 +
24644 +       add_wait_queue(&vxi->vx_wait, &wait);
24645 +       set_current_state(TASK_INTERRUPTIBLE);
24646 +
24647 +wait:
24648 +       if (vx_info_state(vxi,
24649 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24650 +               goto out;
24651 +       if (signal_pending(current)) {
24652 +               ret = -ERESTARTSYS;
24653 +               goto out;
24654 +       }
24655 +       schedule();
24656 +       goto wait;
24657 +
24658 +out:
24659 +       set_current_state(TASK_RUNNING);
24660 +       remove_wait_queue(&vxi->vx_wait, &wait);
24661 +       return ret;
24662 +}
24663 +
24664 +
24665 +
24666 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24667 +{
24668 +       struct vcmd_wait_exit_v0 vc_data;
24669 +       int ret;
24670 +
24671 +       ret = __wait_exit(vxi);
24672 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24673 +       vc_data.exit_code = vxi->exit_code;
24674 +
24675 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24676 +               ret = -EFAULT;
24677 +       return ret;
24678 +}
24679 +
24680 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/space.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/space.c
24681 --- linux-2.6.27.25/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
24682 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/space.c 2008-10-31 18:15:28.000000000 +0100
24683 @@ -0,0 +1,398 @@
24684 +/*
24685 + *  linux/kernel/vserver/space.c
24686 + *
24687 + *  Virtual Server: Context Space Support
24688 + *
24689 + *  Copyright (C) 2003-2007  Herbert Pötzl
24690 + *
24691 + *  V0.01  broken out from context.c 0.07
24692 + *  V0.02  added task locking for namespace
24693 + *  V0.03  broken out vx_enter_namespace
24694 + *  V0.04  added *space support and commands
24695 + *
24696 + */
24697 +
24698 +#include <linux/utsname.h>
24699 +#include <linux/nsproxy.h>
24700 +#include <linux/err.h>
24701 +#include <asm/uaccess.h>
24702 +
24703 +#include <linux/vs_context.h>
24704 +#include <linux/vserver/space.h>
24705 +#include <linux/vserver/space_cmd.h>
24706 +
24707 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24708 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24709 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24710 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24711 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24712 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24713 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24714 +
24715 +
24716 +/* namespace functions */
24717 +
24718 +#include <linux/mnt_namespace.h>
24719 +#include <linux/user_namespace.h>
24720 +#include <linux/pid_namespace.h>
24721 +#include <linux/ipc_namespace.h>
24722 +#include <net/net_namespace.h>
24723 +
24724 +
24725 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24726 +       .mask = CLONE_FS |
24727 +               CLONE_NEWNS |
24728 +               CLONE_NEWUTS |
24729 +               CLONE_NEWIPC |
24730 +               CLONE_NEWUSER |
24731 +               0
24732 +};
24733 +
24734 +static const struct vcmd_space_mask_v1 space_mask = {
24735 +       .mask = CLONE_FS |
24736 +               CLONE_NEWNS |
24737 +               CLONE_NEWUTS |
24738 +               CLONE_NEWIPC |
24739 +               CLONE_NEWUSER |
24740 +#ifdef CONFIG_PID_NS
24741 +               CLONE_NEWPID |
24742 +#endif
24743 +#ifdef CONFIG_NET_NS
24744 +               CLONE_NEWNET |
24745 +#endif
24746 +               0
24747 +};
24748 +
24749 +static const struct vcmd_space_mask_v1 default_space_mask = {
24750 +       .mask = CLONE_FS |
24751 +               CLONE_NEWNS |
24752 +               CLONE_NEWUTS |
24753 +               CLONE_NEWIPC |
24754 +               CLONE_NEWUSER |
24755 +#ifdef CONFIG_PID_NS
24756 +//             CLONE_NEWPID |
24757 +#endif
24758 +               0
24759 +};
24760 +
24761 +/*
24762 + *     build a new nsproxy mix
24763 + *      assumes that both proxies are 'const'
24764 + *     does not touch nsproxy refcounts
24765 + *     will hold a reference on the result.
24766 + */
24767 +
24768 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24769 +       struct nsproxy *new_nsproxy, unsigned long mask)
24770 +{
24771 +       struct mnt_namespace *old_ns;
24772 +       struct uts_namespace *old_uts;
24773 +       struct ipc_namespace *old_ipc;
24774 +       struct user_namespace *old_user;
24775 +#ifdef CONFIG_PID_NS
24776 +       struct pid_namespace *old_pid;
24777 +#endif
24778 +#ifdef CONFIG_NET_NS
24779 +       struct net *old_net;
24780 +#endif
24781 +       struct nsproxy *nsproxy;
24782 +
24783 +       nsproxy = copy_nsproxy(old_nsproxy);
24784 +       if (!nsproxy)
24785 +               goto out;
24786 +
24787 +       if (mask & CLONE_NEWNS) {
24788 +               old_ns = nsproxy->mnt_ns;
24789 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24790 +               if (nsproxy->mnt_ns)
24791 +                       get_mnt_ns(nsproxy->mnt_ns);
24792 +       } else
24793 +               old_ns = NULL;
24794 +
24795 +       if (mask & CLONE_NEWUTS) {
24796 +               old_uts = nsproxy->uts_ns;
24797 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24798 +               if (nsproxy->uts_ns)
24799 +                       get_uts_ns(nsproxy->uts_ns);
24800 +       } else
24801 +               old_uts = NULL;
24802 +
24803 +       if (mask & CLONE_NEWIPC) {
24804 +               old_ipc = nsproxy->ipc_ns;
24805 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24806 +               if (nsproxy->ipc_ns)
24807 +                       get_ipc_ns(nsproxy->ipc_ns);
24808 +       } else
24809 +               old_ipc = NULL;
24810 +
24811 +       if (mask & CLONE_NEWUSER) {
24812 +               old_user = nsproxy->user_ns;
24813 +               nsproxy->user_ns = new_nsproxy->user_ns;
24814 +               if (nsproxy->user_ns)
24815 +                       get_user_ns(nsproxy->user_ns);
24816 +       } else
24817 +               old_user = NULL;
24818 +
24819 +#ifdef CONFIG_PID_NS
24820 +       if (mask & CLONE_NEWPID) {
24821 +               old_pid = nsproxy->pid_ns;
24822 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24823 +               if (nsproxy->pid_ns)
24824 +                       get_pid_ns(nsproxy->pid_ns);
24825 +       } else
24826 +               old_pid = NULL;
24827 +#endif
24828 +#ifdef CONFIG_NET_NS
24829 +       if (mask & CLONE_NEWNET) {
24830 +               old_net = nsproxy->net_ns;
24831 +               nsproxy->net_ns = new_nsproxy->net_ns;
24832 +               if (nsproxy->net_ns)
24833 +                       get_net(nsproxy->net_ns);
24834 +       } else
24835 +               old_net = NULL;
24836 +#endif
24837 +       if (old_ns)
24838 +               put_mnt_ns(old_ns);
24839 +       if (old_uts)
24840 +               put_uts_ns(old_uts);
24841 +       if (old_ipc)
24842 +               put_ipc_ns(old_ipc);
24843 +       if (old_user)
24844 +               put_user_ns(old_user);
24845 +#ifdef CONFIG_PID_NS
24846 +       if (old_pid)
24847 +               put_pid_ns(old_pid);
24848 +#endif
24849 +#ifdef CONFIG_NET_NS
24850 +       if (old_net)
24851 +               put_net(old_net);
24852 +#endif
24853 +out:
24854 +       return nsproxy;
24855 +}
24856 +
24857 +
24858 +/*
24859 + *     merge two nsproxy structs into a new one.
24860 + *     will hold a reference on the result.
24861 + */
24862 +
24863 +static inline
24864 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24865 +       struct nsproxy *proxy, unsigned long mask)
24866 +{
24867 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24868 +
24869 +       if (!proxy)
24870 +               return NULL;
24871 +
24872 +       if (mask) {
24873 +               /* vs_mix_nsproxy returns with reference */
24874 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24875 +                       proxy, mask);
24876 +       }
24877 +       get_nsproxy(proxy);
24878 +       return proxy;
24879 +}
24880 +
24881 +/*
24882 + *     merge two fs structs into a new one.
24883 + *     will take a reference on the result.
24884 + */
24885 +
24886 +static inline
24887 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24888 +       struct fs_struct *fs, unsigned long mask)
24889 +{
24890 +       if (!(mask & CLONE_FS)) {
24891 +               if (old)
24892 +                       atomic_inc(&old->count);
24893 +               return old;
24894 +       }
24895 +
24896 +       if (!fs)
24897 +               return NULL;
24898 +
24899 +       return copy_fs_struct(fs);
24900 +}
24901 +
24902 +
24903 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24904 +{
24905 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24906 +       struct fs_struct *fs, *fs_cur, *fs_new;
24907 +       int ret;
24908 +
24909 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24910 +               vxi, vxi->vx_id, mask, index);
24911 +
24912 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24913 +               return -EACCES;
24914 +
24915 +       if (!mask)
24916 +               mask = vxi->vx_nsmask[index];
24917 +
24918 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24919 +               return -EINVAL;
24920 +
24921 +       proxy = vxi->vx_nsproxy[index];
24922 +       fs = vxi->vx_fs[index];
24923 +
24924 +       task_lock(current);
24925 +       fs_cur = current->fs;
24926 +       atomic_inc(&fs_cur->count);
24927 +       proxy_cur = current->nsproxy;
24928 +       get_nsproxy(proxy_cur);
24929 +       task_unlock(current);
24930 +
24931 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24932 +       if (IS_ERR(fs_new)) {
24933 +               ret = PTR_ERR(fs_new);
24934 +               goto out_put;
24935 +       }
24936 +
24937 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24938 +       if (IS_ERR(proxy_new)) {
24939 +               ret = PTR_ERR(proxy_new);
24940 +               goto out_put_fs;
24941 +       }
24942 +
24943 +       fs_new = xchg(&current->fs, fs_new);
24944 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24945 +       ret = 0;
24946 +
24947 +       if (proxy_new)
24948 +               put_nsproxy(proxy_new);
24949 +out_put_fs:
24950 +       if (fs_new)
24951 +               put_fs_struct(fs_new);
24952 +out_put:
24953 +       if (proxy_cur)
24954 +               put_nsproxy(proxy_cur);
24955 +       if (fs_cur)
24956 +               put_fs_struct(fs_cur);
24957 +       return ret;
24958 +}
24959 +
24960 +
24961 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24962 +{
24963 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24964 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24965 +       int ret;
24966 +
24967 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24968 +               vxi, vxi->vx_id, mask, index);
24969 +#if 0
24970 +       if (!mask)
24971 +               mask = default_space_mask.mask;
24972 +#endif
24973 +       if ((mask & space_mask.mask) != mask)
24974 +               return -EINVAL;
24975 +
24976 +       proxy_vxi = vxi->vx_nsproxy[index];
24977 +       fs_vxi = vxi->vx_fs[index];
24978 +
24979 +       task_lock(current);
24980 +       fs_cur = current->fs;
24981 +       atomic_inc(&fs_cur->count);
24982 +       proxy_cur = current->nsproxy;
24983 +       get_nsproxy(proxy_cur);
24984 +       task_unlock(current);
24985 +
24986 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24987 +       if (IS_ERR(fs_new)) {
24988 +               ret = PTR_ERR(fs_new);
24989 +               goto out_put;
24990 +       }
24991 +
24992 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24993 +       if (IS_ERR(proxy_new)) {
24994 +               ret = PTR_ERR(proxy_new);
24995 +               goto out_put_fs;
24996 +       }
24997 +
24998 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24999 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25000 +       vxi->vx_nsmask[index] |= mask;
25001 +       ret = 0;
25002 +
25003 +       if (proxy_new)
25004 +               put_nsproxy(proxy_new);
25005 +out_put_fs:
25006 +       if (fs_new)
25007 +               put_fs_struct(fs_new);
25008 +out_put:
25009 +       if (proxy_cur)
25010 +               put_nsproxy(proxy_cur);
25011 +       if (fs_cur)
25012 +               put_fs_struct(fs_cur);
25013 +       return ret;
25014 +}
25015 +
25016 +
25017 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25018 +{
25019 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25020 +
25021 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25022 +               return -EFAULT;
25023 +
25024 +       return vx_enter_space(vxi, vc_data.mask, 0);
25025 +}
25026 +
25027 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25028 +{
25029 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25030 +
25031 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25032 +               return -EFAULT;
25033 +
25034 +       if (vc_data.index >= VX_SPACES)
25035 +               return -EINVAL;
25036 +
25037 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25038 +}
25039 +
25040 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25041 +{
25042 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25043 +
25044 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25045 +               return -EFAULT;
25046 +
25047 +       return vx_set_space(vxi, vc_data.mask, 0);
25048 +}
25049 +
25050 +int vc_set_space(struct vx_info *vxi, void __user *data)
25051 +{
25052 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25053 +
25054 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25055 +               return -EFAULT;
25056 +
25057 +       if (vc_data.index >= VX_SPACES)
25058 +               return -EINVAL;
25059 +
25060 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25061 +}
25062 +
25063 +int vc_get_space_mask(void __user *data, int type)
25064 +{
25065 +       const struct vcmd_space_mask_v1 *mask;
25066 +
25067 +       if (type == 0)
25068 +               mask = &space_mask_v0;
25069 +       else if (type == 1)
25070 +               mask = &space_mask;
25071 +       else
25072 +               mask = &default_space_mask;
25073 +
25074 +       vxdprintk(VXD_CBIT(space, 10),
25075 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25076 +
25077 +       if (copy_to_user(data, mask, sizeof(*mask)))
25078 +               return -EFAULT;
25079 +       return 0;
25080 +}
25081 +
25082 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/switch.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/switch.c
25083 --- linux-2.6.27.25/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
25084 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/switch.c        2008-10-31 04:42:36.000000000 +0100
25085 @@ -0,0 +1,543 @@
25086 +/*
25087 + *  linux/kernel/vserver/switch.c
25088 + *
25089 + *  Virtual Server: Syscall Switch
25090 + *
25091 + *  Copyright (C) 2003-2007  Herbert Pötzl
25092 + *
25093 + *  V0.01  syscall switch
25094 + *  V0.02  added signal to context
25095 + *  V0.03  added rlimit functions
25096 + *  V0.04  added iattr, task/xid functions
25097 + *  V0.05  added debug/history stuff
25098 + *  V0.06  added compat32 layer
25099 + *  V0.07  vcmd args and perms
25100 + *  V0.08  added status commands
25101 + *  V0.09  added tag commands
25102 + *  V0.10  added oom bias
25103 + *  V0.11  added device commands
25104 + *
25105 + */
25106 +
25107 +#include <linux/vs_context.h>
25108 +#include <linux/vs_network.h>
25109 +#include <linux/vserver/switch.h>
25110 +
25111 +#include "vci_config.h"
25112 +
25113 +
25114 +static inline
25115 +int vc_get_version(uint32_t id)
25116 +{
25117 +       return VCI_VERSION;
25118 +}
25119 +
25120 +static inline
25121 +int vc_get_vci(uint32_t id)
25122 +{
25123 +       return vci_kernel_config();
25124 +}
25125 +
25126 +#include <linux/vserver/context_cmd.h>
25127 +#include <linux/vserver/cvirt_cmd.h>
25128 +#include <linux/vserver/cacct_cmd.h>
25129 +#include <linux/vserver/limit_cmd.h>
25130 +#include <linux/vserver/network_cmd.h>
25131 +#include <linux/vserver/sched_cmd.h>
25132 +#include <linux/vserver/debug_cmd.h>
25133 +#include <linux/vserver/inode_cmd.h>
25134 +#include <linux/vserver/dlimit_cmd.h>
25135 +#include <linux/vserver/signal_cmd.h>
25136 +#include <linux/vserver/space_cmd.h>
25137 +#include <linux/vserver/tag_cmd.h>
25138 +#include <linux/vserver/device_cmd.h>
25139 +
25140 +#include <linux/vserver/inode.h>
25141 +#include <linux/vserver/dlimit.h>
25142 +
25143 +
25144 +#ifdef CONFIG_COMPAT
25145 +#define __COMPAT(name, id, data, compat)       \
25146 +       (compat) ? name ## _x32(id, data) : name(id, data)
25147 +#define __COMPAT_NO_ID(name, data, compat)     \
25148 +       (compat) ? name ## _x32(data) : name(data)
25149 +#else
25150 +#define __COMPAT(name, id, data, compat)       \
25151 +       name(id, data)
25152 +#define __COMPAT_NO_ID(name, data, compat)     \
25153 +       name(data)
25154 +#endif
25155 +
25156 +
25157 +static inline
25158 +long do_vcmd(uint32_t cmd, uint32_t id,
25159 +       struct vx_info *vxi, struct nx_info *nxi,
25160 +       void __user *data, int compat)
25161 +{
25162 +       switch (cmd) {
25163 +
25164 +       case VCMD_get_version:
25165 +               return vc_get_version(id);
25166 +       case VCMD_get_vci:
25167 +               return vc_get_vci(id);
25168 +
25169 +       case VCMD_task_xid:
25170 +               return vc_task_xid(id);
25171 +       case VCMD_vx_info:
25172 +               return vc_vx_info(vxi, data);
25173 +
25174 +       case VCMD_task_nid:
25175 +               return vc_task_nid(id);
25176 +       case VCMD_nx_info:
25177 +               return vc_nx_info(nxi, data);
25178 +
25179 +       case VCMD_task_tag:
25180 +               return vc_task_tag(id);
25181 +
25182 +       case VCMD_set_space_v1:
25183 +               return vc_set_space_v1(vxi, data);
25184 +       /* this is version 2 */
25185 +       case VCMD_set_space:
25186 +               return vc_set_space(vxi, data);
25187 +
25188 +       case VCMD_get_space_mask_v0:
25189 +               return vc_get_space_mask(data, 0);
25190 +       /* this is version 1 */
25191 +       case VCMD_get_space_mask:
25192 +               return vc_get_space_mask(data, 1);
25193 +
25194 +       case VCMD_get_space_default:
25195 +               return vc_get_space_mask(data, -1);
25196 +
25197 +#ifdef CONFIG_IA32_EMULATION
25198 +       case VCMD_get_rlimit:
25199 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25200 +       case VCMD_set_rlimit:
25201 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25202 +#else
25203 +       case VCMD_get_rlimit:
25204 +               return vc_get_rlimit(vxi, data);
25205 +       case VCMD_set_rlimit:
25206 +               return vc_set_rlimit(vxi, data);
25207 +#endif
25208 +       case VCMD_get_rlimit_mask:
25209 +               return vc_get_rlimit_mask(id, data);
25210 +       case VCMD_reset_minmax:
25211 +               return vc_reset_minmax(vxi, data);
25212 +
25213 +       case VCMD_get_vhi_name:
25214 +               return vc_get_vhi_name(vxi, data);
25215 +       case VCMD_set_vhi_name:
25216 +               return vc_set_vhi_name(vxi, data);
25217 +
25218 +       case VCMD_ctx_stat:
25219 +               return vc_ctx_stat(vxi, data);
25220 +       case VCMD_virt_stat:
25221 +               return vc_virt_stat(vxi, data);
25222 +       case VCMD_sock_stat:
25223 +               return vc_sock_stat(vxi, data);
25224 +       case VCMD_rlimit_stat:
25225 +               return vc_rlimit_stat(vxi, data);
25226 +
25227 +       case VCMD_set_cflags:
25228 +               return vc_set_cflags(vxi, data);
25229 +       case VCMD_get_cflags:
25230 +               return vc_get_cflags(vxi, data);
25231 +
25232 +       /* this is version 1 */
25233 +       case VCMD_set_ccaps:
25234 +               return vc_set_ccaps(vxi, data);
25235 +       /* this is version 1 */
25236 +       case VCMD_get_ccaps:
25237 +               return vc_get_ccaps(vxi, data);
25238 +       case VCMD_set_bcaps:
25239 +               return vc_set_bcaps(vxi, data);
25240 +       case VCMD_get_bcaps:
25241 +               return vc_get_bcaps(vxi, data);
25242 +
25243 +       case VCMD_set_badness:
25244 +               return vc_set_badness(vxi, data);
25245 +       case VCMD_get_badness:
25246 +               return vc_get_badness(vxi, data);
25247 +
25248 +       case VCMD_set_nflags:
25249 +               return vc_set_nflags(nxi, data);
25250 +       case VCMD_get_nflags:
25251 +               return vc_get_nflags(nxi, data);
25252 +
25253 +       case VCMD_set_ncaps:
25254 +               return vc_set_ncaps(nxi, data);
25255 +       case VCMD_get_ncaps:
25256 +               return vc_get_ncaps(nxi, data);
25257 +
25258 +       case VCMD_set_sched_v4:
25259 +               return vc_set_sched_v4(vxi, data);
25260 +       /* this is version 5 */
25261 +       case VCMD_set_sched:
25262 +               return vc_set_sched(vxi, data);
25263 +       case VCMD_get_sched:
25264 +               return vc_get_sched(vxi, data);
25265 +       case VCMD_sched_info:
25266 +               return vc_sched_info(vxi, data);
25267 +
25268 +       case VCMD_add_dlimit:
25269 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25270 +       case VCMD_rem_dlimit:
25271 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25272 +       case VCMD_set_dlimit:
25273 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25274 +       case VCMD_get_dlimit:
25275 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25276 +
25277 +       case VCMD_ctx_kill:
25278 +               return vc_ctx_kill(vxi, data);
25279 +
25280 +       case VCMD_wait_exit:
25281 +               return vc_wait_exit(vxi, data);
25282 +
25283 +       case VCMD_get_iattr:
25284 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25285 +       case VCMD_set_iattr:
25286 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25287 +
25288 +       case VCMD_fget_iattr:
25289 +               return vc_fget_iattr(id, data);
25290 +       case VCMD_fset_iattr:
25291 +               return vc_fset_iattr(id, data);
25292 +
25293 +       case VCMD_enter_space_v0:
25294 +               return vc_enter_space_v1(vxi, NULL);
25295 +       case VCMD_enter_space_v1:
25296 +               return vc_enter_space_v1(vxi, data);
25297 +       /* this is version 2 */
25298 +       case VCMD_enter_space:
25299 +               return vc_enter_space(vxi, data);
25300 +
25301 +       case VCMD_ctx_create_v0:
25302 +               return vc_ctx_create(id, NULL);
25303 +       case VCMD_ctx_create:
25304 +               return vc_ctx_create(id, data);
25305 +       case VCMD_ctx_migrate_v0:
25306 +               return vc_ctx_migrate(vxi, NULL);
25307 +       case VCMD_ctx_migrate:
25308 +               return vc_ctx_migrate(vxi, data);
25309 +
25310 +       case VCMD_net_create_v0:
25311 +               return vc_net_create(id, NULL);
25312 +       case VCMD_net_create:
25313 +               return vc_net_create(id, data);
25314 +       case VCMD_net_migrate:
25315 +               return vc_net_migrate(nxi, data);
25316 +
25317 +       case VCMD_tag_migrate:
25318 +               return vc_tag_migrate(id);
25319 +
25320 +       case VCMD_net_add:
25321 +               return vc_net_add(nxi, data);
25322 +       case VCMD_net_remove:
25323 +               return vc_net_remove(nxi, data);
25324 +
25325 +       case VCMD_net_add_ipv4:
25326 +               return vc_net_add_ipv4(nxi, data);
25327 +       case VCMD_net_remove_ipv4:
25328 +               return vc_net_remove_ipv4(nxi, data);
25329 +#ifdef CONFIG_IPV6
25330 +       case VCMD_net_add_ipv6:
25331 +               return vc_net_add_ipv6(nxi, data);
25332 +       case VCMD_net_remove_ipv6:
25333 +               return vc_net_remove_ipv6(nxi, data);
25334 +#endif
25335 +/*     case VCMD_add_match_ipv4:
25336 +               return vc_add_match_ipv4(nxi, data);
25337 +       case VCMD_get_match_ipv4:
25338 +               return vc_get_match_ipv4(nxi, data);
25339 +#ifdef CONFIG_IPV6
25340 +       case VCMD_add_match_ipv6:
25341 +               return vc_add_match_ipv6(nxi, data);
25342 +       case VCMD_get_match_ipv6:
25343 +               return vc_get_match_ipv6(nxi, data);
25344 +#endif */
25345 +
25346 +#ifdef CONFIG_VSERVER_DEVICE
25347 +       case VCMD_set_mapping:
25348 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25349 +       case VCMD_unset_mapping:
25350 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25351 +#endif
25352 +#ifdef CONFIG_VSERVER_HISTORY
25353 +       case VCMD_dump_history:
25354 +               return vc_dump_history(id);
25355 +       case VCMD_read_history:
25356 +               return __COMPAT(vc_read_history, id, data, compat);
25357 +#endif
25358 +#ifdef CONFIG_VSERVER_MONITOR
25359 +       case VCMD_read_monitor:
25360 +               return __COMPAT(vc_read_monitor, id, data, compat);
25361 +#endif
25362 +       default:
25363 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25364 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25365 +       }
25366 +       return -ENOSYS;
25367 +}
25368 +
25369 +
25370 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25371 +       case VCMD_ ## vcmd: perm = _perm;               \
25372 +               args = _args; flags = _flags; break
25373 +
25374 +
25375 +#define VCA_NONE       0x00
25376 +#define VCA_VXI                0x01
25377 +#define VCA_NXI                0x02
25378 +
25379 +#define VCF_NONE       0x00
25380 +#define VCF_INFO       0x01
25381 +#define VCF_ADMIN      0x02
25382 +#define VCF_ARES       0x06    /* includes admin */
25383 +#define VCF_SETUP      0x08
25384 +
25385 +#define VCF_ZIDOK      0x10    /* zero id okay */
25386 +
25387 +
25388 +static inline
25389 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25390 +{
25391 +       long ret;
25392 +       int permit = -1, state = 0;
25393 +       int perm = -1, args = 0, flags = 0;
25394 +       struct vx_info *vxi = NULL;
25395 +       struct nx_info *nxi = NULL;
25396 +
25397 +       switch (cmd) {
25398 +       /* unpriviledged commands */
25399 +       __VCMD(get_version,      0, VCA_NONE,   0);
25400 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25401 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25402 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25403 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25404 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25405 +
25406 +       /* info commands */
25407 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25408 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25409 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25410 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25411 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25412 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25413 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25414 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25415 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25416 +
25417 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25418 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25419 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25420 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25421 +
25422 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25423 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25424 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25425 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25426 +
25427 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25428 +
25429 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25430 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25431 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25432 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25433 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25434 +
25435 +       /* lower admin commands */
25436 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25437 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25438 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25439 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25440 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25441 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25442 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25443 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25444 +
25445 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25446 +       __VCMD(net_create,       5, VCA_NONE,   0);
25447 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25448 +
25449 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25450 +
25451 +       /* higher admin commands */
25452 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25453 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25454 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25455 +
25456 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25457 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25458 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25459 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25460 +
25461 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25462 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25463 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25464 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25465 +
25466 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25467 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25468 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25469 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25470 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25471 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25472 +#ifdef CONFIG_IPV6
25473 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25474 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25475 +#endif
25476 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25477 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25478 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25479 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25480 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25481 +
25482 +#ifdef CONFIG_VSERVER_DEVICE
25483 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25484 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25485 +#endif
25486 +       /* debug level admin commands */
25487 +#ifdef CONFIG_VSERVER_HISTORY
25488 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25489 +       __VCMD(read_history,     9, VCA_NONE,   0);
25490 +#endif
25491 +#ifdef CONFIG_VSERVER_MONITOR
25492 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25493 +#endif
25494 +
25495 +       default:
25496 +               perm = -1;
25497 +       }
25498 +
25499 +       vxdprintk(VXD_CBIT(switch, 0),
25500 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25501 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25502 +               VC_VERSION(cmd), id, data, compat,
25503 +               perm, args, flags);
25504 +
25505 +       ret = -ENOSYS;
25506 +       if (perm < 0)
25507 +               goto out;
25508 +
25509 +       state = 1;
25510 +       if (!capable(CAP_CONTEXT))
25511 +               goto out;
25512 +
25513 +       state = 2;
25514 +       /* moved here from the individual commands */
25515 +       ret = -EPERM;
25516 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25517 +               goto out;
25518 +
25519 +       state = 3;
25520 +       /* vcmd involves resource management  */
25521 +       ret = -EPERM;
25522 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25523 +               goto out;
25524 +
25525 +       state = 4;
25526 +       /* various legacy exceptions */
25527 +       switch (cmd) {
25528 +       /* will go away when spectator is a cap */
25529 +       case VCMD_ctx_migrate_v0:
25530 +       case VCMD_ctx_migrate:
25531 +               if (id == 1) {
25532 +                       current->xid = 1;
25533 +                       ret = 1;
25534 +                       goto out;
25535 +               }
25536 +               break;
25537 +
25538 +       /* will go away when spectator is a cap */
25539 +       case VCMD_net_migrate:
25540 +               if (id == 1) {
25541 +                       current->nid = 1;
25542 +                       ret = 1;
25543 +                       goto out;
25544 +               }
25545 +               break;
25546 +       }
25547 +
25548 +       /* vcmds are fine by default */
25549 +       permit = 1;
25550 +
25551 +       /* admin type vcmds require admin ... */
25552 +       if (flags & VCF_ADMIN)
25553 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25554 +
25555 +       /* ... but setup type vcmds override that */
25556 +       if (!permit && (flags & VCF_SETUP))
25557 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25558 +
25559 +       state = 5;
25560 +       ret = -EPERM;
25561 +       if (!permit)
25562 +               goto out;
25563 +
25564 +       state = 6;
25565 +       if (!id && (flags & VCF_ZIDOK))
25566 +               goto skip_id;
25567 +
25568 +       ret = -ESRCH;
25569 +       if (args & VCA_VXI) {
25570 +               vxi = lookup_vx_info(id);
25571 +               if (!vxi)
25572 +                       goto out;
25573 +
25574 +               if ((flags & VCF_ADMIN) &&
25575 +                       /* special case kill for shutdown */
25576 +                       (cmd != VCMD_ctx_kill) &&
25577 +                       /* can context be administrated? */
25578 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25579 +                       ret = -EACCES;
25580 +                       goto out_vxi;
25581 +               }
25582 +       }
25583 +       state = 7;
25584 +       if (args & VCA_NXI) {
25585 +               nxi = lookup_nx_info(id);
25586 +               if (!nxi)
25587 +                       goto out_vxi;
25588 +
25589 +               if ((flags & VCF_ADMIN) &&
25590 +                       /* can context be administrated? */
25591 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25592 +                       ret = -EACCES;
25593 +                       goto out_nxi;
25594 +               }
25595 +       }
25596 +skip_id:
25597 +       state = 8;
25598 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25599 +
25600 +out_nxi:
25601 +       if ((args & VCA_NXI) && nxi)
25602 +               put_nx_info(nxi);
25603 +out_vxi:
25604 +       if ((args & VCA_VXI) && vxi)
25605 +               put_vx_info(vxi);
25606 +out:
25607 +       vxdprintk(VXD_CBIT(switch, 1),
25608 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25609 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25610 +               VC_VERSION(cmd), ret, ret, state, permit);
25611 +       return ret;
25612 +}
25613 +
25614 +asmlinkage long
25615 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25616 +{
25617 +       return do_vserver(cmd, id, data, 0);
25618 +}
25619 +
25620 +#ifdef CONFIG_COMPAT
25621 +
25622 +asmlinkage long
25623 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25624 +{
25625 +       return do_vserver(cmd, id, data, 1);
25626 +}
25627 +
25628 +#endif /* CONFIG_COMPAT */
25629 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/sysctl.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sysctl.c
25630 --- linux-2.6.27.25/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
25631 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/sysctl.c        2008-10-13 14:54:20.000000000 +0200
25632 @@ -0,0 +1,244 @@
25633 +/*
25634 + *  kernel/vserver/sysctl.c
25635 + *
25636 + *  Virtual Context Support
25637 + *
25638 + *  Copyright (C) 2004-2007  Herbert Pötzl
25639 + *
25640 + *  V0.01  basic structure
25641 + *
25642 + */
25643 +
25644 +#include <linux/module.h>
25645 +#include <linux/ctype.h>
25646 +#include <linux/sysctl.h>
25647 +#include <linux/parser.h>
25648 +#include <asm/uaccess.h>
25649 +
25650 +
25651 +enum {
25652 +       CTL_DEBUG_ERROR         = 0,
25653 +       CTL_DEBUG_SWITCH        = 1,
25654 +       CTL_DEBUG_XID,
25655 +       CTL_DEBUG_NID,
25656 +       CTL_DEBUG_TAG,
25657 +       CTL_DEBUG_NET,
25658 +       CTL_DEBUG_LIMIT,
25659 +       CTL_DEBUG_CRES,
25660 +       CTL_DEBUG_DLIM,
25661 +       CTL_DEBUG_QUOTA,
25662 +       CTL_DEBUG_CVIRT,
25663 +       CTL_DEBUG_SPACE,
25664 +       CTL_DEBUG_MISC,
25665 +};
25666 +
25667 +
25668 +unsigned int vx_debug_switch   = 0;
25669 +unsigned int vx_debug_xid      = 0;
25670 +unsigned int vx_debug_nid      = 0;
25671 +unsigned int vx_debug_tag      = 0;
25672 +unsigned int vx_debug_net      = 0;
25673 +unsigned int vx_debug_limit    = 0;
25674 +unsigned int vx_debug_cres     = 0;
25675 +unsigned int vx_debug_dlim     = 0;
25676 +unsigned int vx_debug_quota    = 0;
25677 +unsigned int vx_debug_cvirt    = 0;
25678 +unsigned int vx_debug_space    = 0;
25679 +unsigned int vx_debug_misc     = 0;
25680 +
25681 +
25682 +static struct ctl_table_header *vserver_table_header;
25683 +static ctl_table vserver_root_table[];
25684 +
25685 +
25686 +void vserver_register_sysctl(void)
25687 +{
25688 +       if (!vserver_table_header) {
25689 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25690 +       }
25691 +
25692 +}
25693 +
25694 +void vserver_unregister_sysctl(void)
25695 +{
25696 +       if (vserver_table_header) {
25697 +               unregister_sysctl_table(vserver_table_header);
25698 +               vserver_table_header = NULL;
25699 +       }
25700 +}
25701 +
25702 +
25703 +static int proc_dodebug(ctl_table *table, int write,
25704 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25705 +{
25706 +       char            tmpbuf[20], *p, c;
25707 +       unsigned int    value;
25708 +       size_t          left, len;
25709 +
25710 +       if ((*ppos && !write) || !*lenp) {
25711 +               *lenp = 0;
25712 +               return 0;
25713 +       }
25714 +
25715 +       left = *lenp;
25716 +
25717 +       if (write) {
25718 +               if (!access_ok(VERIFY_READ, buffer, left))
25719 +                       return -EFAULT;
25720 +               p = (char *)buffer;
25721 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25722 +                       left--, p++;
25723 +               if (!left)
25724 +                       goto done;
25725 +
25726 +               if (left > sizeof(tmpbuf) - 1)
25727 +                       return -EINVAL;
25728 +               if (copy_from_user(tmpbuf, p, left))
25729 +                       return -EFAULT;
25730 +               tmpbuf[left] = '\0';
25731 +
25732 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25733 +                       value = 10 * value + (*p - '0');
25734 +               if (*p && !isspace(*p))
25735 +                       return -EINVAL;
25736 +               while (left && isspace(*p))
25737 +                       left--, p++;
25738 +               *(unsigned int *)table->data = value;
25739 +       } else {
25740 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25741 +                       return -EFAULT;
25742 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25743 +               if (len > left)
25744 +                       len = left;
25745 +               if (__copy_to_user(buffer, tmpbuf, len))
25746 +                       return -EFAULT;
25747 +               if ((left -= len) > 0) {
25748 +                       if (put_user('\n', (char *)buffer + len))
25749 +                               return -EFAULT;
25750 +                       left--;
25751 +               }
25752 +       }
25753 +
25754 +done:
25755 +       *lenp -= left;
25756 +       *ppos += *lenp;
25757 +       return 0;
25758 +}
25759 +
25760 +static int zero;
25761 +
25762 +#define        CTL_ENTRY(ctl, name)                            \
25763 +       {                                               \
25764 +               .ctl_name       = ctl,                  \
25765 +               .procname       = #name,                \
25766 +               .data           = &vx_ ## name,         \
25767 +               .maxlen         = sizeof(int),          \
25768 +               .mode           = 0644,                 \
25769 +               .proc_handler   = &proc_dodebug,        \
25770 +               .strategy       = &sysctl_intvec,       \
25771 +               .extra1         = &zero,                \
25772 +       }
25773 +
25774 +static ctl_table vserver_debug_table[] = {
25775 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25776 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25777 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25778 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25779 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25780 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25781 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25782 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25783 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25784 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25785 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25786 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25787 +       { .ctl_name = 0 }
25788 +};
25789 +
25790 +static ctl_table vserver_root_table[] = {
25791 +       {
25792 +               .ctl_name       = CTL_VSERVER,
25793 +               .procname       = "vserver",
25794 +               .mode           = 0555,
25795 +               .child          = vserver_debug_table
25796 +       },
25797 +       { .ctl_name = 0 }
25798 +};
25799 +
25800 +
25801 +static match_table_t tokens = {
25802 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25803 +       { CTL_DEBUG_XID,        "xid=%x"        },
25804 +       { CTL_DEBUG_NID,        "nid=%x"        },
25805 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25806 +       { CTL_DEBUG_NET,        "net=%x"        },
25807 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25808 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25809 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25810 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25811 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25812 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25813 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25814 +       { CTL_DEBUG_ERROR,      NULL            }
25815 +};
25816 +
25817 +#define        HANDLE_CASE(id, name, val)                              \
25818 +       case CTL_DEBUG_ ## id:                                  \
25819 +               vx_debug_ ## name = val;                        \
25820 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25821 +               break
25822 +
25823 +
25824 +static int __init vs_debug_setup(char *str)
25825 +{
25826 +       char *p;
25827 +       int token;
25828 +
25829 +       printk("vs_debug_setup(%s)\n", str);
25830 +       while ((p = strsep(&str, ",")) != NULL) {
25831 +               substring_t args[MAX_OPT_ARGS];
25832 +               unsigned int value;
25833 +
25834 +               if (!*p)
25835 +                       continue;
25836 +
25837 +               token = match_token(p, tokens, args);
25838 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25839 +
25840 +               switch (token) {
25841 +               HANDLE_CASE(SWITCH, switch, value);
25842 +               HANDLE_CASE(XID,    xid,    value);
25843 +               HANDLE_CASE(NID,    nid,    value);
25844 +               HANDLE_CASE(TAG,    tag,    value);
25845 +               HANDLE_CASE(NET,    net,    value);
25846 +               HANDLE_CASE(LIMIT,  limit,  value);
25847 +               HANDLE_CASE(CRES,   cres,   value);
25848 +               HANDLE_CASE(DLIM,   dlim,   value);
25849 +               HANDLE_CASE(QUOTA,  quota,  value);
25850 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25851 +               HANDLE_CASE(SPACE,  space,  value);
25852 +               HANDLE_CASE(MISC,   misc,   value);
25853 +               default:
25854 +                       return -EINVAL;
25855 +                       break;
25856 +               }
25857 +       }
25858 +       return 1;
25859 +}
25860 +
25861 +__setup("vsdebug=", vs_debug_setup);
25862 +
25863 +
25864 +
25865 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25866 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25867 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25868 +EXPORT_SYMBOL_GPL(vx_debug_net);
25869 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25870 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25871 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25872 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25873 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25874 +EXPORT_SYMBOL_GPL(vx_debug_space);
25875 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25876 +
25877 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/tag.c linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/tag.c
25878 --- linux-2.6.27.25/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
25879 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/tag.c   2008-10-13 14:54:20.000000000 +0200
25880 @@ -0,0 +1,63 @@
25881 +/*
25882 + *  linux/kernel/vserver/tag.c
25883 + *
25884 + *  Virtual Server: Shallow Tag Space
25885 + *
25886 + *  Copyright (C) 2007  Herbert Pötzl
25887 + *
25888 + *  V0.01  basic implementation
25889 + *
25890 + */
25891 +
25892 +#include <linux/sched.h>
25893 +#include <linux/vserver/debug.h>
25894 +#include <linux/vs_pid.h>
25895 +#include <linux/vs_tag.h>
25896 +
25897 +#include <linux/vserver/tag_cmd.h>
25898 +
25899 +
25900 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25901 +{
25902 +       if (!p)
25903 +               BUG();
25904 +
25905 +       vxdprintk(VXD_CBIT(tag, 5),
25906 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25907 +
25908 +       task_lock(p);
25909 +       p->tag = tag;
25910 +       task_unlock(p);
25911 +
25912 +       vxdprintk(VXD_CBIT(tag, 5),
25913 +               "moved task %p into [#%d]", p, tag);
25914 +       return 0;
25915 +}
25916 +
25917 +/* vserver syscall commands below here */
25918 +
25919 +/* taks xid and vx_info functions */
25920 +
25921 +
25922 +int vc_task_tag(uint32_t id)
25923 +{
25924 +       tag_t tag;
25925 +
25926 +       if (id) {
25927 +               struct task_struct *tsk;
25928 +               read_lock(&tasklist_lock);
25929 +               tsk = find_task_by_real_pid(id);
25930 +               tag = (tsk) ? tsk->tag : -ESRCH;
25931 +               read_unlock(&tasklist_lock);
25932 +       } else
25933 +               tag = dx_current_tag();
25934 +       return tag;
25935 +}
25936 +
25937 +
25938 +int vc_tag_migrate(uint32_t tag)
25939 +{
25940 +       return dx_migrate_task(current, tag & 0xFFFF);
25941 +}
25942 +
25943 +
25944 diff -NurpP --minimal linux-2.6.27.25/kernel/vserver/vci_config.h linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/vci_config.h
25945 --- linux-2.6.27.25/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
25946 +++ linux-2.6.27.25-vs2.3.0.36.6/kernel/vserver/vci_config.h    2008-10-31 18:16:04.000000000 +0100
25947 @@ -0,0 +1,81 @@
25948 +
25949 +/*  interface version */
25950 +
25951 +#define VCI_VERSION            0x00020304
25952 +
25953 +
25954 +enum {
25955 +       VCI_KCBIT_NO_DYNAMIC = 0,
25956 +
25957 +       VCI_KCBIT_PROC_SECURE = 4,
25958 +       VCI_KCBIT_HARDCPU = 5,
25959 +       VCI_KCBIT_IDLELIMIT = 6,
25960 +       VCI_KCBIT_IDLETIME = 7,
25961 +
25962 +       VCI_KCBIT_COWBL = 8,
25963 +       VCI_KCBIT_FULLCOWBL = 9,
25964 +       VCI_KCBIT_SPACES = 10,
25965 +       VCI_KCBIT_NETV2 = 11,
25966 +
25967 +       VCI_KCBIT_DEBUG = 16,
25968 +       VCI_KCBIT_HISTORY = 20,
25969 +       VCI_KCBIT_TAGGED = 24,
25970 +       VCI_KCBIT_PPTAG = 28,
25971 +
25972 +       VCI_KCBIT_MORE = 31,
25973 +};
25974 +
25975 +
25976 +static inline uint32_t vci_kernel_config(void)
25977 +{
25978 +       return
25979 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25980 +
25981 +       /* configured features */
25982 +#ifdef CONFIG_VSERVER_PROC_SECURE
25983 +       (1 << VCI_KCBIT_PROC_SECURE) |
25984 +#endif
25985 +#ifdef CONFIG_VSERVER_HARDCPU
25986 +       (1 << VCI_KCBIT_HARDCPU) |
25987 +#endif
25988 +#ifdef CONFIG_VSERVER_IDLELIMIT
25989 +       (1 << VCI_KCBIT_IDLELIMIT) |
25990 +#endif
25991 +#ifdef CONFIG_VSERVER_IDLETIME
25992 +       (1 << VCI_KCBIT_IDLETIME) |
25993 +#endif
25994 +#ifdef CONFIG_VSERVER_COWBL
25995 +       (1 << VCI_KCBIT_COWBL) |
25996 +       (1 << VCI_KCBIT_FULLCOWBL) |
25997 +#endif
25998 +       (1 << VCI_KCBIT_SPACES) |
25999 +       (1 << VCI_KCBIT_NETV2) |
26000 +
26001 +       /* debug options */
26002 +#ifdef CONFIG_VSERVER_DEBUG
26003 +       (1 << VCI_KCBIT_DEBUG) |
26004 +#endif
26005 +#ifdef CONFIG_VSERVER_HISTORY
26006 +       (1 << VCI_KCBIT_HISTORY) |
26007 +#endif
26008 +
26009 +       /* inode context tagging */
26010 +#if    defined(CONFIG_TAGGING_NONE)
26011 +       (0 << VCI_KCBIT_TAGGED) |
26012 +#elif  defined(CONFIG_TAGGING_UID16)
26013 +       (1 << VCI_KCBIT_TAGGED) |
26014 +#elif  defined(CONFIG_TAGGING_GID16)
26015 +       (2 << VCI_KCBIT_TAGGED) |
26016 +#elif  defined(CONFIG_TAGGING_ID24)
26017 +       (3 << VCI_KCBIT_TAGGED) |
26018 +#elif  defined(CONFIG_TAGGING_INTERN)
26019 +       (4 << VCI_KCBIT_TAGGED) |
26020 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26021 +       (5 << VCI_KCBIT_TAGGED) |
26022 +#else
26023 +       (7 << VCI_KCBIT_TAGGED) |
26024 +#endif
26025 +       (1 << VCI_KCBIT_PPTAG) |
26026 +       0;
26027 +}
26028 +
26029 diff -NurpP --minimal linux-2.6.27.25/mm/filemap_xip.c linux-2.6.27.25-vs2.3.0.36.6/mm/filemap_xip.c
26030 --- linux-2.6.27.25/mm/filemap_xip.c    2009-06-15 17:18:33.000000000 +0200
26031 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/filemap_xip.c       2009-05-15 22:57:04.000000000 +0200
26032 @@ -17,6 +17,7 @@
26033  #include <linux/sched.h>
26034  #include <linux/seqlock.h>
26035  #include <linux/mutex.h>
26036 +#include <linux/vs_memory.h>
26037  #include <asm/tlbflush.h>
26038  #include <asm/io.h>
26039  
26040 diff -NurpP --minimal linux-2.6.27.25/mm/fremap.c linux-2.6.27.25-vs2.3.0.36.6/mm/fremap.c
26041 --- linux-2.6.27.25/mm/fremap.c 2009-06-15 17:18:33.000000000 +0200
26042 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/fremap.c    2009-02-03 17:59:04.000000000 +0100
26043 @@ -16,6 +16,7 @@
26044  #include <linux/module.h>
26045  #include <linux/syscalls.h>
26046  #include <linux/mmu_notifier.h>
26047 +#include <linux/vs_memory.h>
26048  
26049  #include <asm/mmu_context.h>
26050  #include <asm/cacheflush.h>
26051 diff -NurpP --minimal linux-2.6.27.25/mm/hugetlb.c linux-2.6.27.25-vs2.3.0.36.6/mm/hugetlb.c
26052 --- linux-2.6.27.25/mm/hugetlb.c        2009-06-15 17:18:33.000000000 +0200
26053 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/hugetlb.c   2009-06-15 17:22:10.000000000 +0200
26054 @@ -23,6 +23,7 @@
26055  #include <asm/io.h>
26056  
26057  #include <linux/hugetlb.h>
26058 +#include <linux/vs_memory.h>
26059  #include "internal.h"
26060  
26061  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26062 diff -NurpP --minimal linux-2.6.27.25/mm/memory.c linux-2.6.27.25-vs2.3.0.36.6/mm/memory.c
26063 --- linux-2.6.27.25/mm/memory.c 2009-06-15 17:18:33.000000000 +0200
26064 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/memory.c    2009-05-22 00:47:40.000000000 +0200
26065 @@ -562,6 +562,9 @@ static int copy_pte_range(struct mm_stru
26066         int progress = 0;
26067         int rss[2];
26068  
26069 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26070 +               return -ENOMEM;
26071 +
26072  again:
26073         rss[1] = rss[0] = 0;
26074         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26075 @@ -2340,6 +2343,11 @@ static int do_swap_page(struct mm_struct
26076                 goto out;
26077         }
26078  
26079 +       if (!vx_rss_avail(mm, 1)) {
26080 +               ret = VM_FAULT_OOM;
26081 +               goto out;
26082 +       }
26083 +
26084         mark_page_accessed(page);
26085         lock_page(page);
26086         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
26087 @@ -2411,6 +2419,8 @@ static int do_anonymous_page(struct mm_s
26088         /* Allocate our own private page. */
26089         pte_unmap(page_table);
26090  
26091 +       if (!vx_rss_avail(mm, 1))
26092 +               goto oom;
26093         if (unlikely(anon_vma_prepare(vma)))
26094                 goto oom;
26095         page = alloc_zeroed_user_highpage_movable(vma, address);
26096 @@ -2688,6 +2698,7 @@ static inline int handle_pte_fault(struc
26097  {
26098         pte_t entry;
26099         spinlock_t *ptl;
26100 +       int ret = 0, type = VXPT_UNKNOWN;
26101  
26102         entry = *pte;
26103         if (!pte_present(entry)) {
26104 @@ -2712,9 +2723,12 @@ static inline int handle_pte_fault(struc
26105         if (unlikely(!pte_same(*pte, entry)))
26106                 goto unlock;
26107         if (write_access) {
26108 -               if (!pte_write(entry))
26109 -                       return do_wp_page(mm, vma, address,
26110 +               if (!pte_write(entry)) {
26111 +                       ret = do_wp_page(mm, vma, address,
26112                                         pte, pmd, ptl, entry);
26113 +                       type = VXPT_WRITE;
26114 +                       goto out;
26115 +               }
26116                 entry = pte_mkdirty(entry);
26117         }
26118         entry = pte_mkyoung(entry);
26119 @@ -2732,7 +2746,10 @@ static inline int handle_pte_fault(struc
26120         }
26121  unlock:
26122         pte_unmap_unlock(pte, ptl);
26123 -       return 0;
26124 +       ret = 0;
26125 +out:
26126 +       vx_page_fault(mm, vma, type, ret);
26127 +       return ret;
26128  }
26129  
26130  /*
26131 diff -NurpP --minimal linux-2.6.27.25/mm/mlock.c linux-2.6.27.25-vs2.3.0.36.6/mm/mlock.c
26132 --- linux-2.6.27.25/mm/mlock.c  2009-06-15 17:18:33.000000000 +0200
26133 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/mlock.c     2009-02-03 17:59:04.000000000 +0100
26134 @@ -12,6 +12,7 @@
26135  #include <linux/syscalls.h>
26136  #include <linux/sched.h>
26137  #include <linux/module.h>
26138 +#include <linux/vs_memory.h>
26139  
26140  int can_do_mlock(void)
26141  {
26142 @@ -76,7 +77,7 @@ success:
26143                         ret = make_pages_present(start, end);
26144         }
26145  
26146 -       mm->locked_vm -= pages;
26147 +       vx_vmlocked_sub(mm, pages);
26148  out:
26149         return ret;
26150  }
26151 @@ -132,7 +133,7 @@ static int do_mlock(unsigned long start,
26152  
26153  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26154  {
26155 -       unsigned long locked;
26156 +       unsigned long locked, grow;
26157         unsigned long lock_limit;
26158         int error = -ENOMEM;
26159  
26160 @@ -143,8 +144,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26161         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26162         start &= PAGE_MASK;
26163  
26164 -       locked = len >> PAGE_SHIFT;
26165 -       locked += current->mm->locked_vm;
26166 +       grow = len >> PAGE_SHIFT;
26167 +       if (!vx_vmlocked_avail(current->mm, grow))
26168 +               goto out;
26169 +       locked = current->mm->locked_vm + grow;
26170  
26171         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26172         lock_limit >>= PAGE_SHIFT;
26173 @@ -152,6 +155,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26174         /* check against resource limits */
26175         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26176                 error = do_mlock(start, len, 1);
26177 +out:
26178         up_write(&current->mm->mmap_sem);
26179         return error;
26180  }
26181 @@ -211,6 +215,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26182         lock_limit >>= PAGE_SHIFT;
26183  
26184         ret = -ENOMEM;
26185 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26186 +               goto out;
26187         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26188             capable(CAP_IPC_LOCK))
26189                 ret = do_mlockall(flags);
26190 diff -NurpP --minimal linux-2.6.27.25/mm/mmap.c linux-2.6.27.25-vs2.3.0.36.6/mm/mmap.c
26191 --- linux-2.6.27.25/mm/mmap.c   2009-06-15 17:18:33.000000000 +0200
26192 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/mmap.c      2009-05-15 22:57:04.000000000 +0200
26193 @@ -1221,10 +1221,10 @@ munmap_back:
26194         if (correct_wcount)
26195                 atomic_inc(&inode->i_writecount);
26196  out:
26197 -       mm->total_vm += len >> PAGE_SHIFT;
26198 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26199         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26200         if (vm_flags & VM_LOCKED) {
26201 -               mm->locked_vm += len >> PAGE_SHIFT;
26202 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26203                 make_pages_present(addr, addr + len);
26204         }
26205         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26206 @@ -1573,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
26207                 return -ENOMEM;
26208  
26209         /* Ok, everything looks good - let it rip */
26210 -       mm->total_vm += grow;
26211 +       vx_vmpages_add(mm, grow);
26212         if (vma->vm_flags & VM_LOCKED)
26213 -               mm->locked_vm += grow;
26214 +               vx_vmlocked_add(mm, grow);
26215         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26216         return 0;
26217  }
26218 @@ -1746,9 +1746,9 @@ static void remove_vma_list(struct mm_st
26219         do {
26220                 long nrpages = vma_pages(vma);
26221  
26222 -               mm->total_vm -= nrpages;
26223 +               vx_vmpages_sub(mm, nrpages);
26224                 if (vma->vm_flags & VM_LOCKED)
26225 -                       mm->locked_vm -= nrpages;
26226 +                       vx_vmlocked_sub(mm, nrpages);
26227                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26228                 vma = remove_vma(vma);
26229         } while (vma);
26230 @@ -1995,6 +1995,8 @@ unsigned long do_brk(unsigned long addr,
26231                 lock_limit >>= PAGE_SHIFT;
26232                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26233                         return -EAGAIN;
26234 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26235 +                       return -ENOMEM;
26236         }
26237  
26238         /*
26239 @@ -2021,7 +2023,8 @@ unsigned long do_brk(unsigned long addr,
26240         if (mm->map_count > sysctl_max_map_count)
26241                 return -ENOMEM;
26242  
26243 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26244 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26245 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26246                 return -ENOMEM;
26247  
26248         /* Can we just expand an old private anonymous mapping? */
26249 @@ -2046,9 +2049,9 @@ unsigned long do_brk(unsigned long addr,
26250         vma->vm_page_prot = vm_get_page_prot(flags);
26251         vma_link(mm, vma, prev, rb_link, rb_parent);
26252  out:
26253 -       mm->total_vm += len >> PAGE_SHIFT;
26254 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26255         if (flags & VM_LOCKED) {
26256 -               mm->locked_vm += len >> PAGE_SHIFT;
26257 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26258                 make_pages_present(addr, addr + len);
26259         }
26260         return addr;
26261 @@ -2081,6 +2084,11 @@ void exit_mmap(struct mm_struct *mm)
26262         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26263         tlb_finish_mmu(tlb, 0, end);
26264  
26265 +       set_mm_counter(mm, file_rss, 0);
26266 +       set_mm_counter(mm, anon_rss, 0);
26267 +       vx_vmpages_sub(mm, mm->total_vm);
26268 +       vx_vmlocked_sub(mm, mm->locked_vm);
26269 +
26270         /*
26271          * Walk the list again, actually closing and freeing it,
26272          * with preemption enabled, without holding any MM locks.
26273 @@ -2120,7 +2128,8 @@ int insert_vm_struct(struct mm_struct * 
26274         if (__vma && __vma->vm_start < vma->vm_end)
26275                 return -ENOMEM;
26276         if ((vma->vm_flags & VM_ACCOUNT) &&
26277 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26278 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26279 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26280                 return -ENOMEM;
26281         vma_link(mm, vma, prev, rb_link, rb_parent);
26282         return 0;
26283 @@ -2196,6 +2205,8 @@ int may_expand_vm(struct mm_struct *mm, 
26284  
26285         if (cur + npages > lim)
26286                 return 0;
26287 +       if (!vx_vmpages_avail(mm, npages))
26288 +               return 0;
26289         return 1;
26290  }
26291  
26292 @@ -2273,8 +2284,7 @@ int install_special_mapping(struct mm_st
26293                 return -ENOMEM;
26294         }
26295  
26296 -       mm->total_vm += len >> PAGE_SHIFT;
26297 -
26298 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26299         return 0;
26300  }
26301  
26302 diff -NurpP --minimal linux-2.6.27.25/mm/mremap.c linux-2.6.27.25-vs2.3.0.36.6/mm/mremap.c
26303 --- linux-2.6.27.25/mm/mremap.c 2009-06-15 17:18:34.000000000 +0200
26304 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/mremap.c    2009-02-03 17:59:04.000000000 +0100
26305 @@ -19,6 +19,7 @@
26306  #include <linux/security.h>
26307  #include <linux/syscalls.h>
26308  #include <linux/mmu_notifier.h>
26309 +#include <linux/vs_memory.h>
26310  
26311  #include <asm/uaccess.h>
26312  #include <asm/cacheflush.h>
26313 @@ -218,7 +219,7 @@ static unsigned long move_vma(struct vm_
26314          * If this were a serious issue, we'd add a flag to do_munmap().
26315          */
26316         hiwater_vm = mm->hiwater_vm;
26317 -       mm->total_vm += new_len >> PAGE_SHIFT;
26318 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26319         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26320  
26321         if (do_munmap(mm, old_addr, old_len) < 0) {
26322 @@ -236,7 +237,7 @@ static unsigned long move_vma(struct vm_
26323         }
26324  
26325         if (vm_flags & VM_LOCKED) {
26326 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26327 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26328                 if (new_len > old_len)
26329                         make_pages_present(new_addr + old_len,
26330                                            new_addr + new_len);
26331 @@ -347,6 +348,9 @@ unsigned long do_mremap(unsigned long ad
26332                 ret = -EAGAIN;
26333                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26334                         goto out;
26335 +               if (!vx_vmlocked_avail(current->mm,
26336 +                       (new_len - old_len) >> PAGE_SHIFT))
26337 +                       goto out;
26338         }
26339         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26340                 ret = -ENOMEM;
26341 @@ -375,10 +379,10 @@ unsigned long do_mremap(unsigned long ad
26342                         vma_adjust(vma, vma->vm_start,
26343                                 addr + new_len, vma->vm_pgoff, NULL);
26344  
26345 -                       mm->total_vm += pages;
26346 +                       vx_vmpages_add(mm, pages);
26347                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26348                         if (vma->vm_flags & VM_LOCKED) {
26349 -                               mm->locked_vm += pages;
26350 +                               vx_vmlocked_add(mm, pages);
26351                                 make_pages_present(addr + old_len,
26352                                                    addr + new_len);
26353                         }
26354 diff -NurpP --minimal linux-2.6.27.25/mm/nommu.c linux-2.6.27.25-vs2.3.0.36.6/mm/nommu.c
26355 --- linux-2.6.27.25/mm/nommu.c  2009-06-15 17:18:34.000000000 +0200
26356 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/nommu.c     2009-02-03 17:59:04.000000000 +0100
26357 @@ -1028,7 +1028,7 @@ unsigned long do_mmap_pgoff(struct file 
26358         realalloc += kobjsize(vma);
26359         askedalloc += sizeof(*vma);
26360  
26361 -       current->mm->total_vm += len >> PAGE_SHIFT;
26362 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26363  
26364         add_nommu_vma(vma);
26365  
26366 @@ -1160,7 +1160,7 @@ int do_munmap(struct mm_struct *mm, unsi
26367         kfree(vml);
26368  
26369         update_hiwater_vm(mm);
26370 -       mm->total_vm -= len >> PAGE_SHIFT;
26371 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
26372  
26373  #ifdef DEBUG
26374         show_process_blocks();
26375 @@ -1193,7 +1193,7 @@ void exit_mmap(struct mm_struct * mm)
26376                 printk("Exit_mmap:\n");
26377  #endif
26378  
26379 -               mm->total_vm = 0;
26380 +               vx_vmpages_sub(mm, mm->total_vm);
26381  
26382                 while ((tmp = mm->context.vmlist)) {
26383                         mm->context.vmlist = tmp->next;
26384 diff -NurpP --minimal linux-2.6.27.25/mm/oom_kill.c linux-2.6.27.25-vs2.3.0.36.6/mm/oom_kill.c
26385 --- linux-2.6.27.25/mm/oom_kill.c       2008-10-13 14:52:09.000000000 +0200
26386 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/oom_kill.c  2008-10-13 14:54:20.000000000 +0200
26387 @@ -27,6 +27,7 @@
26388  #include <linux/notifier.h>
26389  #include <linux/memcontrol.h>
26390  #include <linux/security.h>
26391 +#include <linux/vs_memory.h>
26392  
26393  int sysctl_panic_on_oom;
26394  int sysctl_oom_kill_allocating_task;
26395 @@ -73,6 +74,12 @@ unsigned long badness(struct task_struct
26396         points = mm->total_vm;
26397  
26398         /*
26399 +        * add points for context badness
26400 +        */
26401 +
26402 +       points += vx_badness(p, mm);
26403 +
26404 +       /*
26405          * After this unlock we can no longer dereference local variable `mm'
26406          */
26407         task_unlock(p);
26408 @@ -163,8 +170,8 @@ unsigned long badness(struct task_struct
26409         }
26410  
26411  #ifdef DEBUG
26412 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26413 -       p->pid, p->comm, points);
26414 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26415 +               task_pid_nr(p), p->xid, p->comm, points);
26416  #endif
26417         return points;
26418  }
26419 @@ -325,8 +332,8 @@ static void __oom_kill_task(struct task_
26420         }
26421  
26422         if (verbose)
26423 -               printk(KERN_ERR "Killed process %d (%s)\n",
26424 -                               task_pid_nr(p), p->comm);
26425 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26426 +                               task_pid_nr(p), p->xid, p->comm);
26427  
26428         /*
26429          * We give our sacrificial lamb high priority and access to
26430 @@ -406,8 +413,8 @@ static int oom_kill_process(struct task_
26431                 return 0;
26432         }
26433  
26434 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26435 -                                       message, task_pid_nr(p), p->comm, points);
26436 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26437 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26438  
26439         /* Try to kill a child first */
26440         list_for_each_entry(c, &p->children, sibling) {
26441 diff -NurpP --minimal linux-2.6.27.25/mm/page_alloc.c linux-2.6.27.25-vs2.3.0.36.6/mm/page_alloc.c
26442 --- linux-2.6.27.25/mm/page_alloc.c     2009-06-15 17:18:34.000000000 +0200
26443 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/page_alloc.c        2009-03-25 14:32:29.000000000 +0100
26444 @@ -46,6 +46,8 @@
26445  #include <linux/page-isolation.h>
26446  #include <linux/memcontrol.h>
26447  #include <linux/debugobjects.h>
26448 +#include <linux/vs_base.h>
26449 +#include <linux/vs_limit.h>
26450  
26451  #include <asm/tlbflush.h>
26452  #include <asm/div64.h>
26453 @@ -1823,6 +1825,9 @@ void si_meminfo(struct sysinfo *val)
26454         val->totalhigh = totalhigh_pages;
26455         val->freehigh = nr_free_highpages();
26456         val->mem_unit = PAGE_SIZE;
26457 +
26458 +       if (vx_flags(VXF_VIRT_MEM, 0))
26459 +               vx_vsi_meminfo(val);
26460  }
26461  
26462  EXPORT_SYMBOL(si_meminfo);
26463 @@ -1843,6 +1848,9 @@ void si_meminfo_node(struct sysinfo *val
26464         val->freehigh = 0;
26465  #endif
26466         val->mem_unit = PAGE_SIZE;
26467 +
26468 +       if (vx_flags(VXF_VIRT_MEM, 0))
26469 +               vx_vsi_meminfo(val);
26470  }
26471  #endif
26472  
26473 diff -NurpP --minimal linux-2.6.27.25/mm/rmap.c linux-2.6.27.25-vs2.3.0.36.6/mm/rmap.c
26474 --- linux-2.6.27.25/mm/rmap.c   2009-06-15 17:18:34.000000000 +0200
26475 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/rmap.c      2009-02-03 17:59:04.000000000 +0100
26476 @@ -50,6 +50,7 @@
26477  #include <linux/kallsyms.h>
26478  #include <linux/memcontrol.h>
26479  #include <linux/mmu_notifier.h>
26480 +#include <linux/vs_memory.h>
26481  
26482  #include <asm/tlbflush.h>
26483  
26484 diff -NurpP --minimal linux-2.6.27.25/mm/shmem.c linux-2.6.27.25-vs2.3.0.36.6/mm/shmem.c
26485 --- linux-2.6.27.25/mm/shmem.c  2008-10-13 14:52:09.000000000 +0200
26486 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/shmem.c     2008-10-13 14:54:20.000000000 +0200
26487 @@ -56,7 +56,6 @@
26488  #include <asm/pgtable.h>
26489  
26490  /* This magic number is used in glibc for posix shared memory */
26491 -#define TMPFS_MAGIC    0x01021994
26492  
26493  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
26494  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
26495 @@ -1738,7 +1737,7 @@ static int shmem_statfs(struct dentry *d
26496  {
26497         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26498  
26499 -       buf->f_type = TMPFS_MAGIC;
26500 +       buf->f_type = TMPFS_SUPER_MAGIC;
26501         buf->f_bsize = PAGE_CACHE_SIZE;
26502         buf->f_namelen = NAME_MAX;
26503         spin_lock(&sbinfo->stat_lock);
26504 @@ -2306,7 +2305,7 @@ static int shmem_fill_super(struct super
26505         sb->s_maxbytes = SHMEM_MAX_BYTES;
26506         sb->s_blocksize = PAGE_CACHE_SIZE;
26507         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26508 -       sb->s_magic = TMPFS_MAGIC;
26509 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26510         sb->s_op = &shmem_ops;
26511         sb->s_time_gran = 1;
26512  #ifdef CONFIG_TMPFS_POSIX_ACL
26513 diff -NurpP --minimal linux-2.6.27.25/mm/slab.c linux-2.6.27.25-vs2.3.0.36.6/mm/slab.c
26514 --- linux-2.6.27.25/mm/slab.c   2008-10-13 14:52:09.000000000 +0200
26515 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/slab.c      2008-10-13 14:54:20.000000000 +0200
26516 @@ -508,6 +508,8 @@ struct kmem_cache {
26517  #define STATS_INC_FREEMISS(x)  do { } while (0)
26518  #endif
26519  
26520 +#include "slab_vs.h"
26521 +
26522  #if DEBUG
26523  
26524  /*
26525 @@ -3337,6 +3339,7 @@ retry:
26526  
26527         obj = slab_get_obj(cachep, slabp, nodeid);
26528         check_slabp(cachep, slabp);
26529 +       vx_slab_alloc(cachep, flags);
26530         l3->free_objects--;
26531         /* move slabp to correct slabp list: */
26532         list_del(&slabp->list);
26533 @@ -3409,6 +3412,7 @@ __cache_alloc_node(struct kmem_cache *ca
26534         /* ___cache_alloc_node can fall back to other nodes */
26535         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26536    out:
26537 +       vx_slab_alloc(cachep, flags);
26538         local_irq_restore(save_flags);
26539         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26540  
26541 @@ -3580,6 +3584,7 @@ static inline void __cache_free(struct k
26542  
26543         check_irq_off();
26544         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26545 +       vx_slab_free(cachep);
26546  
26547         /*
26548          * Skip calling cache_free_alien() when the platform is not numa.
26549 diff -NurpP --minimal linux-2.6.27.25/mm/slab_vs.h linux-2.6.27.25-vs2.3.0.36.6/mm/slab_vs.h
26550 --- linux-2.6.27.25/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
26551 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/slab_vs.h   2008-10-13 14:54:20.000000000 +0200
26552 @@ -0,0 +1,27 @@
26553 +
26554 +#include <linux/vserver/context.h>
26555 +
26556 +#include <linux/vs_context.h>
26557 +
26558 +static inline
26559 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26560 +{
26561 +       int what = gfp_zone(cachep->gfpflags);
26562 +
26563 +       if (!current->vx_info)
26564 +               return;
26565 +
26566 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26567 +}
26568 +
26569 +static inline
26570 +void vx_slab_free(struct kmem_cache *cachep)
26571 +{
26572 +       int what = gfp_zone(cachep->gfpflags);
26573 +
26574 +       if (!current->vx_info)
26575 +               return;
26576 +
26577 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26578 +}
26579 +
26580 diff -NurpP --minimal linux-2.6.27.25/mm/swapfile.c linux-2.6.27.25-vs2.3.0.36.6/mm/swapfile.c
26581 --- linux-2.6.27.25/mm/swapfile.c       2009-06-15 17:18:34.000000000 +0200
26582 +++ linux-2.6.27.25-vs2.3.0.36.6/mm/swapfile.c  2009-02-03 17:59:04.000000000 +0100
26583 @@ -32,6 +32,8 @@
26584  #include <asm/pgtable.h>
26585  #include <asm/tlbflush.h>
26586  #include <linux/swapops.h>
26587 +#include <linux/vs_base.h>
26588 +#include <linux/vs_memory.h>
26589  
26590  static DEFINE_SPINLOCK(swap_lock);
26591  static unsigned int nr_swapfiles;
26592 @@ -1748,6 +1750,8 @@ void si_swapinfo(struct sysinfo *val)
26593         val->freeswap = nr_swap_pages + nr_to_be_unused;
26594         val->totalswap = total_swap_pages + nr_to_be_unused;
26595         spin_unlock(&swap_lock);
26596 +       if (vx_flags(VXF_VIRT_MEM, 0))
26597 +               vx_vsi_swapinfo(val);
26598  }
26599  
26600  /*
26601 diff -NurpP --minimal linux-2.6.27.25/net/core/dev.c linux-2.6.27.25-vs2.3.0.36.6/net/core/dev.c
26602 --- linux-2.6.27.25/net/core/dev.c      2009-06-15 17:18:34.000000000 +0200
26603 +++ linux-2.6.27.25-vs2.3.0.36.6/net/core/dev.c 2009-02-22 22:58:33.000000000 +0100
26604 @@ -127,6 +127,7 @@
26605  #include <linux/in.h>
26606  #include <linux/jhash.h>
26607  #include <linux/random.h>
26608 +#include <linux/vs_inet.h>
26609  
26610  #include "net-sysfs.h"
26611  
26612 @@ -925,10 +926,15 @@ int dev_change_name(struct net_device *d
26613                 strlcpy(dev->name, newname, IFNAMSIZ);
26614  
26615  rollback:
26616 -       err = device_rename(&dev->dev, dev->name);
26617 -       if (err) {
26618 -               memcpy(dev->name, oldname, IFNAMSIZ);
26619 -               return err;
26620 +       /* For now only devices in the initial network namespace
26621 +        * are in sysfs.
26622 +        */
26623 +       if (net == &init_net) {
26624 +               ret = device_rename(&dev->dev, dev->name);
26625 +               if (ret) {
26626 +                       memcpy(dev->name, oldname, IFNAMSIZ);
26627 +                       return ret;
26628 +               }
26629         }
26630  
26631         write_lock_bh(&dev_base_lock);
26632 @@ -2518,6 +2524,8 @@ static int dev_ifconf(struct net *net, c
26633  
26634         total = 0;
26635         for_each_netdev(net, dev) {
26636 +               if (!nx_dev_visible(current->nx_info, dev))
26637 +                       continue;
26638                 for (i = 0; i < NPROTO; i++) {
26639                         if (gifconf_list[i]) {
26640                                 int done;
26641 @@ -2586,6 +2594,9 @@ static void dev_seq_printf_stats(struct 
26642  {
26643         struct net_device_stats *stats = dev->get_stats(dev);
26644  
26645 +       if (!nx_dev_visible(current->nx_info, dev))
26646 +               return;
26647 +
26648         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26649                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26650                    dev->name, stats->rx_bytes, stats->rx_packets,
26651 @@ -4388,6 +4399,15 @@ int dev_change_net_namespace(struct net_
26652         if (dev->features & NETIF_F_NETNS_LOCAL)
26653                 goto out;
26654  
26655 +#ifdef CONFIG_SYSFS
26656 +       /* Don't allow real devices to be moved when sysfs
26657 +        * is enabled.
26658 +        */
26659 +       err = -EINVAL;
26660 +       if (dev->dev.parent)
26661 +               goto out;
26662 +#endif
26663 +
26664         /* Ensure the device has been registrered */
26665         err = -EINVAL;
26666         if (dev->reg_state != NETREG_REGISTERED)
26667 @@ -4445,6 +4465,8 @@ int dev_change_net_namespace(struct net_
26668          */
26669         dev_addr_discard(dev);
26670  
26671 +       netdev_unregister_kobject(dev);
26672 +
26673         /* Actually switch the network namespace */
26674         dev_net_set(dev, net);
26675  
26676 @@ -4461,7 +4483,6 @@ int dev_change_net_namespace(struct net_
26677         }
26678  
26679         /* Fixup kobjects */
26680 -       netdev_unregister_kobject(dev);
26681         err = netdev_register_kobject(dev);
26682         WARN_ON(err);
26683  
26684 diff -NurpP --minimal linux-2.6.27.25/net/core/net-sysfs.c linux-2.6.27.25-vs2.3.0.36.6/net/core/net-sysfs.c
26685 --- linux-2.6.27.25/net/core/net-sysfs.c        2008-10-13 14:52:09.000000000 +0200
26686 +++ linux-2.6.27.25-vs2.3.0.36.6/net/core/net-sysfs.c   2008-11-20 15:21:32.000000000 +0100
26687 @@ -440,6 +440,10 @@ void netdev_unregister_kobject(struct ne
26688         struct device *dev = &(net->dev);
26689  
26690         kobject_get(&dev->kobj);
26691 +
26692 +       if (dev_net(net) != &init_net)
26693 +               return;
26694 +
26695         device_del(dev);
26696  }
26697  
26698 @@ -465,6 +469,9 @@ int netdev_register_kobject(struct net_d
26699  #endif
26700  #endif /* CONFIG_SYSFS */
26701  
26702 +       if (dev_net(net) != &init_net)
26703 +               return 0;
26704 +
26705         return device_add(dev);
26706  }
26707  
26708 diff -NurpP --minimal linux-2.6.27.25/net/core/rtnetlink.c linux-2.6.27.25-vs2.3.0.36.6/net/core/rtnetlink.c
26709 --- linux-2.6.27.25/net/core/rtnetlink.c        2008-10-13 14:52:09.000000000 +0200
26710 +++ linux-2.6.27.25-vs2.3.0.36.6/net/core/rtnetlink.c   2008-10-13 14:54:20.000000000 +0200
26711 @@ -686,6 +686,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26712  
26713         idx = 0;
26714         for_each_netdev(net, dev) {
26715 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26716 +                       continue;
26717                 if (idx < s_idx)
26718                         goto cont;
26719                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26720 @@ -1219,6 +1221,9 @@ void rtmsg_ifinfo(int type, struct net_d
26721         struct sk_buff *skb;
26722         int err = -ENOBUFS;
26723  
26724 +       if (!nx_dev_visible(current->nx_info, dev))
26725 +               return;
26726 +
26727         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26728         if (skb == NULL)
26729                 goto errout;
26730 diff -NurpP --minimal linux-2.6.27.25/net/core/sock.c linux-2.6.27.25-vs2.3.0.36.6/net/core/sock.c
26731 --- linux-2.6.27.25/net/core/sock.c     2009-06-15 17:18:34.000000000 +0200
26732 +++ linux-2.6.27.25-vs2.3.0.36.6/net/core/sock.c        2009-03-25 14:32:29.000000000 +0100
26733 @@ -124,6 +124,10 @@
26734  #include <linux/ipsec.h>
26735  
26736  #include <linux/filter.h>
26737 +#include <linux/vs_socket.h>
26738 +#include <linux/vs_limit.h>
26739 +#include <linux/vs_context.h>
26740 +#include <linux/vs_network.h>
26741  
26742  #ifdef CONFIG_INET
26743  #include <net/tcp.h>
26744 @@ -899,6 +903,8 @@ static struct sock *sk_prot_alloc(struct
26745                 if (!try_module_get(prot->owner))
26746                         goto out_free_sec;
26747         }
26748 +               sock_vx_init(sk);
26749 +               sock_nx_init(sk);
26750  
26751         return sk;
26752  
26753 @@ -975,6 +981,11 @@ void sk_free(struct sock *sk)
26754                        __func__, atomic_read(&sk->sk_omem_alloc));
26755  
26756         put_net(sock_net(sk));
26757 +       vx_sock_dec(sk);
26758 +       clr_vx_info(&sk->sk_vx_info);
26759 +       sk->sk_xid = -1;
26760 +       clr_nx_info(&sk->sk_nx_info);
26761 +       sk->sk_nid = -1;
26762         sk_prot_free(sk->sk_prot_creator, sk);
26763  }
26764  
26765 @@ -1010,6 +1021,8 @@ struct sock *sk_clone(const struct sock 
26766  
26767                 /* SANITY */
26768                 get_net(sock_net(newsk));
26769 +               sock_vx_init(newsk);
26770 +               sock_nx_init(newsk);
26771                 sk_node_init(&newsk->sk_node);
26772                 sock_lock_init(newsk);
26773                 bh_lock_sock(newsk);
26774 @@ -1056,6 +1069,12 @@ struct sock *sk_clone(const struct sock 
26775                 newsk->sk_priority = 0;
26776                 atomic_set(&newsk->sk_refcnt, 2);
26777  
26778 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26779 +               newsk->sk_xid = sk->sk_xid;
26780 +               vx_sock_inc(newsk);
26781 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26782 +               newsk->sk_nid = sk->sk_nid;
26783 +
26784                 /*
26785                  * Increment the counter in the same struct proto as the master
26786                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26787 @@ -1739,6 +1758,11 @@ void sock_init_data(struct socket *sock,
26788  
26789         sk->sk_stamp = ktime_set(-1L, 0);
26790  
26791 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26792 +       sk->sk_xid = vx_current_xid();
26793 +       vx_sock_inc(sk);
26794 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26795 +       sk->sk_nid = nx_current_nid();
26796         atomic_set(&sk->sk_refcnt, 1);
26797         atomic_set(&sk->sk_drops, 0);
26798  }
26799 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/af_inet.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/af_inet.c
26800 --- linux-2.6.27.25/net/ipv4/af_inet.c  2008-10-13 14:52:09.000000000 +0200
26801 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/af_inet.c     2008-10-13 14:54:20.000000000 +0200
26802 @@ -114,6 +114,7 @@
26803  #ifdef CONFIG_IP_MROUTE
26804  #include <linux/mroute.h>
26805  #endif
26806 +#include <linux/vs_limit.h>
26807  
26808  extern void ip_mc_drop_socket(struct sock *sk);
26809  
26810 @@ -325,9 +326,12 @@ lookup_protocol:
26811         }
26812  
26813         err = -EPERM;
26814 +       if ((protocol == IPPROTO_ICMP) &&
26815 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26816 +               goto override;
26817         if (answer->capability > 0 && !capable(answer->capability))
26818                 goto out_rcu_unlock;
26819 -
26820 +override:
26821         err = -EAFNOSUPPORT;
26822         if (!inet_netns_ok(net, protocol))
26823                 goto out_rcu_unlock;
26824 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26825         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26826         struct sock *sk = sock->sk;
26827         struct inet_sock *inet = inet_sk(sk);
26828 +       struct nx_v4_sock_addr nsa;
26829         unsigned short snum;
26830         int chk_addr_ret;
26831         int err;
26832 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26833         if (addr_len < sizeof(struct sockaddr_in))
26834                 goto out;
26835  
26836 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26837 +       err = v4_map_sock_addr(inet, addr, &nsa);
26838 +       if (err)
26839 +               goto out;
26840 +
26841 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26842  
26843         /* Not specified by any standard per-se, however it breaks too
26844          * many applications when removed.  It is unfortunate since
26845 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26846         err = -EADDRNOTAVAIL;
26847         if (!sysctl_ip_nonlocal_bind &&
26848             !inet->freebind &&
26849 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26850 +           nsa.saddr != htonl(INADDR_ANY) &&
26851             chk_addr_ret != RTN_LOCAL &&
26852             chk_addr_ret != RTN_MULTICAST &&
26853             chk_addr_ret != RTN_BROADCAST)
26854 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26855         if (sk->sk_state != TCP_CLOSE || inet->num)
26856                 goto out_release_sock;
26857  
26858 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26859 +       v4_set_sock_addr(inet, &nsa);
26860         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26861                 inet->saddr = 0;  /* Use device */
26862  
26863 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26864                      peer == 1))
26865                         return -ENOTCONN;
26866                 sin->sin_port = inet->dport;
26867 -               sin->sin_addr.s_addr = inet->daddr;
26868 +               sin->sin_addr.s_addr =
26869 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26870         } else {
26871                 __be32 addr = inet->rcv_saddr;
26872                 if (!addr)
26873                         addr = inet->saddr;
26874 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26875                 sin->sin_port = inet->sport;
26876                 sin->sin_addr.s_addr = addr;
26877         }
26878 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/devinet.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/devinet.c
26879 --- linux-2.6.27.25/net/ipv4/devinet.c  2008-10-13 14:52:09.000000000 +0200
26880 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/devinet.c     2008-10-13 14:54:20.000000000 +0200
26881 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
26882         return in_dev;
26883  }
26884  
26885 +
26886  /* Called only from RTNL semaphored context. No locks. */
26887  
26888  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26889 @@ -662,6 +663,8 @@ int devinet_ioctl(struct net *net, unsig
26890                 *colon = ':';
26891  
26892         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26893 +               struct nx_info *nxi = current->nx_info;
26894 +
26895                 if (tryaddrmatch) {
26896                         /* Matthias Andree */
26897                         /* compare label and address (4.4BSD style) */
26898 @@ -670,6 +673,8 @@ int devinet_ioctl(struct net *net, unsig
26899                            This is checked above. */
26900                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26901                              ifap = &ifa->ifa_next) {
26902 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26903 +                                       continue;
26904                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26905                                     sin_orig.sin_addr.s_addr ==
26906                                                         ifa->ifa_address) {
26907 @@ -682,9 +687,12 @@ int devinet_ioctl(struct net *net, unsig
26908                    comparing just the label */
26909                 if (!ifa) {
26910                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26911 -                            ifap = &ifa->ifa_next)
26912 +                            ifap = &ifa->ifa_next) {
26913 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26914 +                                       continue;
26915                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26916                                         break;
26917 +                       }
26918                 }
26919         }
26920  
26921 @@ -835,6 +843,8 @@ static int inet_gifconf(struct net_devic
26922                 goto out;
26923  
26924         for (; ifa; ifa = ifa->ifa_next) {
26925 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26926 +                       continue;
26927                 if (!buf) {
26928                         done += sizeof(ifr);
26929                         continue;
26930 @@ -1165,6 +1175,7 @@ static int inet_dump_ifaddr(struct sk_bu
26931         struct net_device *dev;
26932         struct in_device *in_dev;
26933         struct in_ifaddr *ifa;
26934 +       struct sock *sk = skb->sk;
26935         int s_ip_idx, s_idx = cb->args[0];
26936  
26937         s_ip_idx = ip_idx = cb->args[1];
26938 @@ -1179,6 +1190,8 @@ static int inet_dump_ifaddr(struct sk_bu
26939  
26940                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26941                      ifa = ifa->ifa_next, ip_idx++) {
26942 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26943 +                               continue;
26944                         if (ip_idx < s_ip_idx)
26945                                 continue;
26946                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26947 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/fib_hash.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/fib_hash.c
26948 --- linux-2.6.27.25/net/ipv4/fib_hash.c 2008-10-13 14:52:09.000000000 +0200
26949 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/fib_hash.c    2008-10-13 14:54:20.000000000 +0200
26950 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26951         prefix  = f->fn_key;
26952         mask    = FZ_MASK(iter->zone);
26953         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26954 -       if (fi)
26955 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26956                 seq_printf(seq,
26957                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26958                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26959 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/inet_connection_sock.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/inet_connection_sock.c
26960 --- linux-2.6.27.25/net/ipv4/inet_connection_sock.c     2008-10-13 14:52:09.000000000 +0200
26961 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/inet_connection_sock.c        2008-10-13 14:54:20.000000000 +0200
26962 @@ -47,10 +47,40 @@ void inet_get_local_port_range(int *low,
26963  }
26964  EXPORT_SYMBOL(inet_get_local_port_range);
26965  
26966 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26967 +{
26968 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26969 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26970 +
26971 +       if (inet_v6_ipv6only(sk2))
26972 +               return 0;
26973 +
26974 +       if (sk1_rcv_saddr &&
26975 +           sk2_rcv_saddr &&
26976 +           sk1_rcv_saddr == sk2_rcv_saddr)
26977 +               return 1;
26978 +
26979 +       if (sk1_rcv_saddr &&
26980 +           !sk2_rcv_saddr &&
26981 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26982 +               return 1;
26983 +
26984 +       if (sk2_rcv_saddr &&
26985 +           !sk1_rcv_saddr &&
26986 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26987 +               return 1;
26988 +
26989 +       if (!sk1_rcv_saddr &&
26990 +           !sk2_rcv_saddr &&
26991 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26992 +               return 1;
26993 +
26994 +       return 0;
26995 +}
26996 +
26997  int inet_csk_bind_conflict(const struct sock *sk,
26998                            const struct inet_bind_bucket *tb)
26999  {
27000 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27001         struct sock *sk2;
27002         struct hlist_node *node;
27003         int reuse = sk->sk_reuse;
27004 @@ -70,9 +100,7 @@ int inet_csk_bind_conflict(const struct 
27005                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27006                         if (!reuse || !sk2->sk_reuse ||
27007                             sk2->sk_state == TCP_LISTEN) {
27008 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27009 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27010 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27011 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27012                                         break;
27013                         }
27014                 }
27015 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/inet_diag.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/inet_diag.c
27016 --- linux-2.6.27.25/net/ipv4/inet_diag.c        2008-10-13 14:52:09.000000000 +0200
27017 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/inet_diag.c   2008-10-13 14:54:20.000000000 +0200
27018 @@ -32,6 +32,8 @@
27019  #include <linux/stddef.h>
27020  
27021  #include <linux/inet_diag.h>
27022 +#include <linux/vs_network.h>
27023 +#include <linux/vs_inet.h>
27024  
27025  static const struct inet_diag_handler **inet_diag_table;
27026  
27027 @@ -120,8 +122,8 @@ static int inet_csk_diag_fill(struct soc
27028  
27029         r->id.idiag_sport = inet->sport;
27030         r->id.idiag_dport = inet->dport;
27031 -       r->id.idiag_src[0] = inet->rcv_saddr;
27032 -       r->id.idiag_dst[0] = inet->daddr;
27033 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27034 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27035  
27036  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27037         if (r->idiag_family == AF_INET6) {
27038 @@ -208,8 +210,8 @@ static int inet_twsk_diag_fill(struct in
27039         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27040         r->id.idiag_sport     = tw->tw_sport;
27041         r->id.idiag_dport     = tw->tw_dport;
27042 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27043 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27044 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27045 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27046         r->idiag_state        = tw->tw_substate;
27047         r->idiag_timer        = 3;
27048         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27049 @@ -266,6 +268,7 @@ static int inet_diag_get_exact(struct sk
27050         err = -EINVAL;
27051  
27052         if (req->idiag_family == AF_INET) {
27053 +               /* TODO: lback */
27054                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27055                                  req->id.idiag_dport, req->id.idiag_src[0],
27056                                  req->id.idiag_sport, req->id.idiag_if);
27057 @@ -508,6 +511,7 @@ static int inet_csk_diag_dump(struct soc
27058                 } else
27059  #endif
27060                 {
27061 +                       /* TODO: lback */
27062                         entry.saddr = &inet->rcv_saddr;
27063                         entry.daddr = &inet->daddr;
27064                 }
27065 @@ -544,6 +548,7 @@ static int inet_twsk_diag_dump(struct in
27066                 } else
27067  #endif
27068                 {
27069 +                       /* TODO: lback */
27070                         entry.saddr = &tw->tw_rcv_saddr;
27071                         entry.daddr = &tw->tw_daddr;
27072                 }
27073 @@ -590,8 +595,8 @@ static int inet_diag_fill_req(struct sk_
27074  
27075         r->id.idiag_sport = inet->sport;
27076         r->id.idiag_dport = ireq->rmt_port;
27077 -       r->id.idiag_src[0] = ireq->loc_addr;
27078 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27079 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27080 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27081         r->idiag_expires = jiffies_to_msecs(tmo);
27082         r->idiag_rqueue = 0;
27083         r->idiag_wqueue = 0;
27084 @@ -661,6 +666,7 @@ static int inet_diag_dump_reqs(struct sk
27085                                 continue;
27086  
27087                         if (bc) {
27088 +                               /* TODO: lback */
27089                                 entry.saddr =
27090  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27091                                         (entry.family == AF_INET6) ?
27092 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
27093                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
27094                                 struct inet_sock *inet = inet_sk(sk);
27095  
27096 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27097 +                                       continue;
27098                                 if (num < s_num) {
27099                                         num++;
27100                                         continue;
27101 @@ -790,6 +798,8 @@ skip_listen_ht:
27102                 sk_for_each(sk, node, &head->chain) {
27103                         struct inet_sock *inet = inet_sk(sk);
27104  
27105 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27106 +                               continue;
27107                         if (num < s_num)
27108                                 goto next_normal;
27109                         if (!(r->idiag_states & (1 << sk->sk_state)))
27110 @@ -814,6 +824,8 @@ next_normal:
27111                         inet_twsk_for_each(tw, node,
27112                                     &head->twchain) {
27113  
27114 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27115 +                                       continue;
27116                                 if (num < s_num)
27117                                         goto next_dying;
27118                                 if (r->id.idiag_sport != tw->tw_sport &&
27119 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/inet_hashtables.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/inet_hashtables.c
27120 --- linux-2.6.27.25/net/ipv4/inet_hashtables.c  2008-10-13 14:52:09.000000000 +0200
27121 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/inet_hashtables.c     2008-10-13 14:54:20.000000000 +0200
27122 @@ -21,6 +21,7 @@
27123  
27124  #include <net/inet_connection_sock.h>
27125  #include <net/inet_hashtables.h>
27126 +#include <net/route.h>
27127  #include <net/ip.h>
27128  
27129  /*
27130 @@ -163,11 +164,10 @@ static struct sock *inet_lookup_listener
27131                         const __be32 rcv_saddr = inet->rcv_saddr;
27132                         int score = sk->sk_family == PF_INET ? 1 : 0;
27133  
27134 -                       if (rcv_saddr) {
27135 -                               if (rcv_saddr != daddr)
27136 -                                       continue;
27137 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
27138                                 score += 2;
27139 -                       }
27140 +                       else
27141 +                               continue;
27142                         if (sk->sk_bound_dev_if) {
27143                                 if (sk->sk_bound_dev_if != dif)
27144                                         continue;
27145 @@ -199,7 +199,7 @@ struct sock *__inet_lookup_listener(stru
27146                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
27147  
27148                 if (inet->num == hnum && !sk->sk_node.next &&
27149 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
27150 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
27151                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
27152                     !sk->sk_bound_dev_if && net_eq(sock_net(sk), net))
27153                         goto sherry_cache;
27154 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/netfilter/nf_nat_helper.c
27155 --- linux-2.6.27.25/net/ipv4/netfilter/nf_nat_helper.c  2008-07-13 23:51:29.000000000 +0200
27156 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/netfilter/nf_nat_helper.c     2008-10-13 14:54:20.000000000 +0200
27157 @@ -18,6 +18,7 @@
27158  #include <net/tcp.h>
27159  
27160  #include <linux/netfilter_ipv4.h>
27161 +#include <net/route.h>
27162  #include <net/netfilter/nf_conntrack.h>
27163  #include <net/netfilter/nf_conntrack_helper.h>
27164  #include <net/netfilter/nf_conntrack_ecache.h>
27165 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/netfilter.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/netfilter.c
27166 --- linux-2.6.27.25/net/ipv4/netfilter.c        2008-07-13 23:51:29.000000000 +0200
27167 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/netfilter.c   2008-10-13 14:54:20.000000000 +0200
27168 @@ -4,7 +4,7 @@
27169  #include <linux/netfilter_ipv4.h>
27170  #include <linux/ip.h>
27171  #include <linux/skbuff.h>
27172 -#include <net/route.h>
27173 +// #include <net/route.h>
27174  #include <net/xfrm.h>
27175  #include <net/ip.h>
27176  #include <net/netfilter/nf_queue.h>
27177 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/raw.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/raw.c
27178 --- linux-2.6.27.25/net/ipv4/raw.c      2008-10-13 14:52:09.000000000 +0200
27179 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/raw.c 2008-10-13 14:54:20.000000000 +0200
27180 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27181  
27182                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27183                     !(inet->daddr && inet->daddr != raddr)              &&
27184 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27185 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27186                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27187                         goto found; /* gotcha */
27188         }
27189 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
27190                 icmp_out_count(net, ((struct icmphdr *)
27191                         skb_transport_header(skb))->type);
27192  
27193 +       err = -EPERM;
27194 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27195 +               sk->sk_nx_info &&
27196 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27197 +               goto error_free;
27198 +
27199         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27200                       dst_output);
27201         if (err > 0)
27202 @@ -383,6 +389,7 @@ out:
27203  
27204  error_fault:
27205         err = -EFAULT;
27206 +error_free:
27207         kfree_skb(skb);
27208  error:
27209         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
27210 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
27211                 }
27212  
27213                 security_sk_classify_flow(sk, &fl);
27214 +               if (sk->sk_nx_info) {
27215 +                       err = ip_v4_find_src(sock_net(sk),
27216 +                               sk->sk_nx_info, &rt, &fl);
27217 +
27218 +                       if (err)
27219 +                               goto done;
27220 +               }
27221                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27222         }
27223         if (err)
27224 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
27225  {
27226         struct inet_sock *inet = inet_sk(sk);
27227         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27228 +       struct nx_v4_sock_addr nsa = { 0 };
27229         int ret = -EINVAL;
27230         int chk_addr_ret;
27231  
27232         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27233                 goto out;
27234 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27235 +       v4_map_sock_addr(inet, addr, &nsa);
27236 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27237         ret = -EADDRNOTAVAIL;
27238 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27239 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27240             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27241                 goto out;
27242 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27243 +       v4_set_sock_addr(inet, &nsa);
27244         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27245                 inet->saddr = 0;  /* Use device */
27246         sk_dst_reset(sk);
27247 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
27248         /* Copy the address. */
27249         if (sin) {
27250                 sin->sin_family = AF_INET;
27251 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27252 +               sin->sin_addr.s_addr =
27253 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27254                 sin->sin_port = 0;
27255                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27256         }
27257 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
27258                 struct hlist_node *node;
27259  
27260                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27261 -                       if (sock_net(sk) == seq_file_net(seq))
27262 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27263 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27264                                 goto found;
27265         }
27266         sk = NULL;
27267 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
27268                 sk = sk_next(sk);
27269  try_again:
27270                 ;
27271 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27272 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27273 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27274  
27275         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27276                 sk = sk_head(&state->h->ht[state->bucket]);
27277 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
27278  
27279         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27280                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27281 -               i, src, srcp, dest, destp, sp->sk_state,
27282 +               i,
27283 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27284 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27285 +               sp->sk_state,
27286                 atomic_read(&sp->sk_wmem_alloc),
27287                 atomic_read(&sp->sk_rmem_alloc),
27288                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27289 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/syncookies.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/syncookies.c
27290 --- linux-2.6.27.25/net/ipv4/syncookies.c       2008-10-13 14:52:09.000000000 +0200
27291 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/syncookies.c  2008-10-13 14:54:20.000000000 +0200
27292 @@ -16,6 +16,7 @@
27293  #include <linux/cryptohash.h>
27294  #include <linux/kernel.h>
27295  #include <net/tcp.h>
27296 +#include <net/route.h>
27297  
27298  /* Timestamps: lowest 9 bits store TCP options */
27299  #define TSBITS 9
27300 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/tcp.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/tcp.c
27301 --- linux-2.6.27.25/net/ipv4/tcp.c      2009-06-15 17:18:35.000000000 +0200
27302 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/tcp.c 2009-02-22 22:58:33.000000000 +0100
27303 @@ -264,6 +264,7 @@
27304  #include <linux/cache.h>
27305  #include <linux/err.h>
27306  #include <linux/crypto.h>
27307 +#include <linux/in.h>
27308  
27309  #include <net/icmp.h>
27310  #include <net/tcp.h>
27311 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/tcp_ipv4.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/tcp_ipv4.c
27312 --- linux-2.6.27.25/net/ipv4/tcp_ipv4.c 2008-10-13 14:52:09.000000000 +0200
27313 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/tcp_ipv4.c    2008-10-13 14:54:20.000000000 +0200
27314 @@ -1886,6 +1886,12 @@ static void *listening_get_next(struct s
27315                 req = req->dl_next;
27316                 while (1) {
27317                         while (req) {
27318 +                               vxdprintk(VXD_CBIT(net, 6),
27319 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27320 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27321 +                               if (req->sk &&
27322 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27323 +                                       continue;
27324                                 if (req->rsk_ops->family == st->family) {
27325                                         cur = req;
27326                                         goto out;
27327 @@ -1910,6 +1916,10 @@ get_req:
27328         }
27329  get_sk:
27330         sk_for_each_from(sk, node) {
27331 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27332 +                       sk, sk->sk_nid, nx_current_nid());
27333 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27334 +                       continue;
27335                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27336                         cur = sk;
27337                         goto out;
27338 @@ -1960,6 +1970,11 @@ static void *established_get_first(struc
27339  
27340                 read_lock_bh(lock);
27341                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27342 +                       vxdprintk(VXD_CBIT(net, 6),
27343 +                               "sk,egf: %p [#%d] (from %d)",
27344 +                               sk, sk->sk_nid, nx_current_nid());
27345 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27346 +                               continue;
27347                         if (sk->sk_family != st->family ||
27348                             !net_eq(sock_net(sk), net)) {
27349                                 continue;
27350 @@ -1970,6 +1985,11 @@ static void *established_get_first(struc
27351                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27352                 inet_twsk_for_each(tw, node,
27353                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27354 +                       vxdprintk(VXD_CBIT(net, 6),
27355 +                               "tw: %p [#%d] (from %d)",
27356 +                               tw, tw->tw_nid, nx_current_nid());
27357 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27358 +                               continue;
27359                         if (tw->tw_family != st->family ||
27360                             !net_eq(twsk_net(tw), net)) {
27361                                 continue;
27362 @@ -1998,7 +2018,9 @@ static void *established_get_next(struct
27363                 tw = cur;
27364                 tw = tw_next(tw);
27365  get_tw:
27366 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27367 +               while (tw && (tw->tw_family != st->family ||
27368 +                       !net_eq(twsk_net(tw), net) ||
27369 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27370                         tw = tw_next(tw);
27371                 }
27372                 if (tw) {
27373 @@ -2019,6 +2041,11 @@ get_tw:
27374                 sk = sk_next(sk);
27375  
27376         sk_for_each_from(sk, node) {
27377 +               vxdprintk(VXD_CBIT(net, 6),
27378 +                       "sk,egn: %p [#%d] (from %d)",
27379 +                       sk, sk->sk_nid, nx_current_nid());
27380 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27381 +                       continue;
27382                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27383                         goto found;
27384         }
27385 @@ -2173,9 +2200,9 @@ static void get_openreq4(struct sock *sk
27386         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27387                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27388                 i,
27389 -               ireq->loc_addr,
27390 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27391                 ntohs(inet_sk(sk)->sport),
27392 -               ireq->rmt_addr,
27393 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27394                 ntohs(ireq->rmt_port),
27395                 TCP_SYN_RECV,
27396                 0, 0, /* could print option size, but that is af dependent. */
27397 @@ -2218,7 +2245,10 @@ static void get_tcp4_sock(struct sock *s
27398  
27399         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27400                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27401 -               i, src, srcp, dest, destp, sk->sk_state,
27402 +               i,
27403 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27404 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27405 +               sk->sk_state,
27406                 tp->write_seq - tp->snd_una,
27407                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27408                                              (tp->rcv_nxt - tp->copied_seq),
27409 @@ -2254,7 +2284,10 @@ static void get_timewait4_sock(struct in
27410  
27411         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27412                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27413 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27414 +               i,
27415 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27416 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27417 +               tw->tw_substate, 0, 0,
27418                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27419                 atomic_read(&tw->tw_refcnt), tw, len);
27420  }
27421 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/tcp_minisocks.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/tcp_minisocks.c
27422 --- linux-2.6.27.25/net/ipv4/tcp_minisocks.c    2008-10-13 14:52:09.000000000 +0200
27423 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/tcp_minisocks.c       2008-10-13 14:54:20.000000000 +0200
27424 @@ -26,6 +26,10 @@
27425  #include <net/inet_common.h>
27426  #include <net/xfrm.h>
27427  
27428 +#include <linux/vs_limit.h>
27429 +#include <linux/vs_socket.h>
27430 +#include <linux/vs_context.h>
27431 +
27432  #ifdef CONFIG_SYSCTL
27433  #define SYNC_INIT 0 /* let the user enable it */
27434  #else
27435 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27436                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27437                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27438  
27439 +               tw->tw_xid              = sk->sk_xid;
27440 +               tw->tw_vx_info          = NULL;
27441 +               tw->tw_nid              = sk->sk_nid;
27442 +               tw->tw_nx_info          = NULL;
27443 +
27444  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27445                 if (tw->tw_family == PF_INET6) {
27446                         struct ipv6_pinfo *np = inet6_sk(sk);
27447 diff -NurpP --minimal linux-2.6.27.25/net/ipv4/udp.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/udp.c
27448 --- linux-2.6.27.25/net/ipv4/udp.c      2009-06-15 17:18:35.000000000 +0200
27449 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv4/udp.c 2009-02-22 22:58:33.000000000 +0100
27450 @@ -234,20 +234,14 @@ fail:
27451         return error;
27452  }
27453  
27454 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27455 -{
27456 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27457 -
27458 -       return  ( !ipv6_only_sock(sk2)  &&
27459 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27460 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27461 -}
27462 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27463  
27464  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27465  {
27466         return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal);
27467  }
27468  
27469 +
27470  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27471   * harder than this. -DaveM
27472   */
27473 @@ -267,10 +261,16 @@ static struct sock *__udp4_lib_lookup(st
27474                 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
27475                                 !ipv6_only_sock(sk)) {
27476                         int score = (sk->sk_family == PF_INET ? 1 : 0);
27477 +
27478                         if (inet->rcv_saddr) {
27479                                 if (inet->rcv_saddr != daddr)
27480                                         continue;
27481                                 score+=2;
27482 +                       } else {
27483 +                               /* block non nx_info ips */
27484 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
27485 +                                       daddr, NXA_MASK_BIND))
27486 +                                       continue;
27487                         }
27488                         if (inet->daddr) {
27489                                 if (inet->daddr != saddr)
27490 @@ -296,6 +296,7 @@ static struct sock *__udp4_lib_lookup(st
27491                         }
27492                 }
27493         }
27494 +
27495         if (result)
27496                 sock_hold(result);
27497         read_unlock(&udp_hash_lock);
27498 @@ -318,7 +319,7 @@ static inline struct sock *udp_v4_mcast_
27499                     s->sk_hash != hnum                                  ||
27500                     (inet->daddr && inet->daddr != rmt_addr)            ||
27501                     (inet->dport != rmt_port && inet->dport)            ||
27502 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27503 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27504                     ipv6_only_sock(s)                                   ||
27505                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27506                         continue;
27507 @@ -655,8 +656,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27508                                                { .sport = inet->sport,
27509                                                  .dport = dport } } };
27510                 struct net *net = sock_net(sk);
27511 +               struct nx_info *nxi = sk->sk_nx_info;
27512  
27513                 security_sk_classify_flow(sk, &fl);
27514 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27515 +               if (err)
27516 +                       goto out;
27517 +
27518                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27519                 if (err) {
27520                         if (err == -ENETUNREACH)
27521 @@ -901,7 +907,8 @@ try_again:
27522         {
27523                 sin->sin_family = AF_INET;
27524                 sin->sin_port = udp_hdr(skb)->source;
27525 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27526 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27527 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27528                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27529         }
27530         if (inet->cmsg_flags)
27531 @@ -1533,6 +1540,8 @@ static struct sock *udp_get_first(struct
27532                 sk_for_each(sk, node, state->hashtable + state->bucket) {
27533                         if (!net_eq(sock_net(sk), net))
27534                                 continue;
27535 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27536 +                               continue;
27537                         if (sk->sk_family == state->family)
27538                                 goto found;
27539                 }
27540 @@ -1551,7 +1560,9 @@ static struct sock *udp_get_next(struct 
27541                 sk = sk_next(sk);
27542  try_again:
27543                 ;
27544 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27545 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27546 +               sk->sk_family != state->family ||
27547 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27548  
27549         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
27550                 sk = sk_head(state->hashtable + state->bucket);
27551 @@ -1652,7 +1663,10 @@ static void udp4_format_sock(struct sock
27552  
27553         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27554                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27555 -               bucket, src, srcp, dest, destp, sp->sk_state,
27556 +               bucket,
27557 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27558 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27559 +               sp->sk_state,
27560                 atomic_read(&sp->sk_wmem_alloc),
27561                 atomic_read(&sp->sk_rmem_alloc),
27562                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27563 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/addrconf.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/addrconf.c
27564 --- linux-2.6.27.25/net/ipv6/addrconf.c 2008-10-13 14:52:09.000000000 +0200
27565 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/addrconf.c    2008-11-21 13:32:00.000000000 +0100
27566 @@ -85,6 +85,8 @@
27567  
27568  #include <linux/proc_fs.h>
27569  #include <linux/seq_file.h>
27570 +#include <linux/vs_network.h>
27571 +#include <linux/vs_inet6.h>
27572  
27573  /* Set to 3 to get tracing... */
27574  #define ACONF_DEBUG 2
27575 @@ -1108,7 +1110,7 @@ out:
27576  
27577  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27578                        const struct in6_addr *daddr, unsigned int prefs,
27579 -                      struct in6_addr *saddr)
27580 +                      struct in6_addr *saddr, struct nx_info *nxi)
27581  {
27582         struct ipv6_saddr_score scores[2],
27583                                 *score = &scores[0], *hiscore = &scores[1];
27584 @@ -1181,6 +1183,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27585                                                dev->name);
27586                                 continue;
27587                         }
27588 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27589 +                               continue;
27590  
27591                         score->rule = -1;
27592                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27593 @@ -1364,35 +1368,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27594         return ifp;
27595  }
27596  
27597 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27598 +
27599  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27600  {
27601         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27602         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27603 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27604         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27605         int sk_ipv6only = ipv6_only_sock(sk);
27606         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27607         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27608         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27609  
27610 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27611 +       /* FIXME: needs handling for v4 ANY */
27612 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27613                 return 1;
27614  
27615         if (addr_type2 == IPV6_ADDR_ANY &&
27616 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27617 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27618 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27619                 return 1;
27620  
27621         if (addr_type == IPV6_ADDR_ANY &&
27622 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27623 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27624 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27625 +               return 1;
27626 +
27627 +       if (addr_type == IPV6_ADDR_ANY &&
27628 +           addr_type2 == IPV6_ADDR_ANY &&
27629 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27630                 return 1;
27631  
27632         if (sk2_rcv_saddr6 &&
27633 +           addr_type != IPV6_ADDR_ANY &&
27634 +           addr_type != IPV6_ADDR_ANY &&
27635             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27636                 return 1;
27637  
27638         if (addr_type == IPV6_ADDR_MAPPED &&
27639             !sk2_ipv6only &&
27640 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27641 +           ipv4_rcv_saddr_equal(sk, sk2))
27642                 return 1;
27643  
27644         return 0;
27645 @@ -2986,7 +3001,10 @@ static void if6_seq_stop(struct seq_file
27646  static int if6_seq_show(struct seq_file *seq, void *v)
27647  {
27648         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27649 -       seq_printf(seq,
27650 +
27651 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27652 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27653 +               seq_printf(seq,
27654                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
27655                    NIP6(ifp->addr),
27656                    ifp->idev->dev->ifindex,
27657 @@ -3481,6 +3499,12 @@ static int inet6_dump_addr(struct sk_buf
27658         struct ifmcaddr6 *ifmca;
27659         struct ifacaddr6 *ifaca;
27660         struct net *net = sock_net(skb->sk);
27661 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27662 +
27663 +       /* disable ipv6 on non v6 guests */
27664 +       if (nxi && !nx_info_has_v6(nxi))
27665 +               return skb->len;
27666 +
27667  
27668         s_idx = cb->args[0];
27669         s_ip_idx = ip_idx = cb->args[1];
27670 @@ -3502,6 +3526,8 @@ static int inet6_dump_addr(struct sk_buf
27671                              ifa = ifa->if_next, ip_idx++) {
27672                                 if (ip_idx < s_ip_idx)
27673                                         continue;
27674 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27675 +                                       continue;
27676                                 err = inet6_fill_ifaddr(skb, ifa,
27677                                                         NETLINK_CB(cb->skb).pid,
27678                                                         cb->nlh->nlmsg_seq,
27679 @@ -3515,6 +3541,8 @@ static int inet6_dump_addr(struct sk_buf
27680                              ifmca = ifmca->next, ip_idx++) {
27681                                 if (ip_idx < s_ip_idx)
27682                                         continue;
27683 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27684 +                                       continue;
27685                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27686                                                           NETLINK_CB(cb->skb).pid,
27687                                                           cb->nlh->nlmsg_seq,
27688 @@ -3528,6 +3556,8 @@ static int inet6_dump_addr(struct sk_buf
27689                              ifaca = ifaca->aca_next, ip_idx++) {
27690                                 if (ip_idx < s_ip_idx)
27691                                         continue;
27692 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27693 +                                       continue;
27694                                 err = inet6_fill_ifacaddr(skb, ifaca,
27695                                                           NETLINK_CB(cb->skb).pid,
27696                                                           cb->nlh->nlmsg_seq,
27697 @@ -3813,12 +3843,19 @@ static int inet6_dump_ifinfo(struct sk_b
27698         int s_idx = cb->args[0];
27699         struct net_device *dev;
27700         struct inet6_dev *idev;
27701 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27702 +
27703 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27704 +       if (skb->sk && skb->sk->sk_vx_info)
27705 +               return skb->len; */
27706  
27707         read_lock(&dev_base_lock);
27708         idx = 0;
27709         for_each_netdev(net, dev) {
27710                 if (idx < s_idx)
27711                         goto cont;
27712 +               if (!v6_dev_in_nx_info(dev, nxi))
27713 +                       goto cont;
27714                 if ((idev = in6_dev_get(dev)) == NULL)
27715                         goto cont;
27716                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27717 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/af_inet6.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/af_inet6.c
27718 --- linux-2.6.27.25/net/ipv6/af_inet6.c 2008-10-13 14:52:09.000000000 +0200
27719 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/af_inet6.c    2008-10-13 14:54:20.000000000 +0200
27720 @@ -41,6 +41,8 @@
27721  #include <linux/netdevice.h>
27722  #include <linux/icmpv6.h>
27723  #include <linux/netfilter_ipv6.h>
27724 +#include <linux/vs_inet.h>
27725 +#include <linux/vs_inet6.h>
27726  
27727  #include <net/ip.h>
27728  #include <net/ipv6.h>
27729 @@ -49,6 +51,7 @@
27730  #include <net/tcp.h>
27731  #include <net/ipip.h>
27732  #include <net/protocol.h>
27733 +#include <net/route.h>
27734  #include <net/inet_common.h>
27735  #include <net/transp_v6.h>
27736  #include <net/ip6_route.h>
27737 @@ -141,9 +144,12 @@ lookup_protocol:
27738         }
27739  
27740         err = -EPERM;
27741 +       if ((protocol == IPPROTO_ICMPV6) &&
27742 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27743 +               goto override;
27744         if (answer->capability > 0 && !capable(answer->capability))
27745                 goto out_rcu_unlock;
27746 -
27747 +override:
27748         sock->ops = answer->ops;
27749         answer_prot = answer->prot;
27750         answer_no_check = answer->no_check;
27751 @@ -242,6 +248,7 @@ int inet6_bind(struct socket *sock, stru
27752         struct inet_sock *inet = inet_sk(sk);
27753         struct ipv6_pinfo *np = inet6_sk(sk);
27754         struct net *net = sock_net(sk);
27755 +       struct nx_v6_sock_addr nsa;
27756         __be32 v4addr = 0;
27757         unsigned short snum;
27758         int addr_type = 0;
27759 @@ -253,6 +260,11 @@ int inet6_bind(struct socket *sock, stru
27760  
27761         if (addr_len < SIN6_LEN_RFC2133)
27762                 return -EINVAL;
27763 +
27764 +       err = v6_map_sock_addr(inet, addr, &nsa);
27765 +       if (err)
27766 +               return err;
27767 +
27768         addr_type = ipv6_addr_type(&addr->sin6_addr);
27769         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27770                 return -EINVAL;
27771 @@ -276,6 +288,10 @@ int inet6_bind(struct socket *sock, stru
27772                         err = -EADDRNOTAVAIL;
27773                         goto out;
27774                 }
27775 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27776 +                       err = -EADDRNOTAVAIL;
27777 +                       goto out;
27778 +               }
27779         } else {
27780                 if (addr_type != IPV6_ADDR_ANY) {
27781                         struct net_device *dev = NULL;
27782 @@ -301,6 +317,11 @@ int inet6_bind(struct socket *sock, stru
27783                                 }
27784                         }
27785  
27786 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27787 +                               err = -EADDRNOTAVAIL;
27788 +                               goto out;
27789 +                       }
27790 +
27791                         /* ipv4 addr of the socket is invalid.  Only the
27792                          * unspecified and mapped address have a v4 equivalent.
27793                          */
27794 @@ -319,6 +340,8 @@ int inet6_bind(struct socket *sock, stru
27795                 }
27796         }
27797  
27798 +       v6_set_sock_addr(inet, &nsa);
27799 +
27800         inet->rcv_saddr = v4addr;
27801         inet->saddr = v4addr;
27802  
27803 @@ -411,9 +434,11 @@ int inet6_getname(struct socket *sock, s
27804                         return -ENOTCONN;
27805                 sin->sin6_port = inet->dport;
27806                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27807 +               /* FIXME: remap lback? */
27808                 if (np->sndflow)
27809                         sin->sin6_flowinfo = np->flow_label;
27810         } else {
27811 +               /* FIXME: remap lback? */
27812                 if (ipv6_addr_any(&np->rcv_saddr))
27813                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27814                 else
27815 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/fib6_rules.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/fib6_rules.c
27816 --- linux-2.6.27.25/net/ipv6/fib6_rules.c       2008-10-13 14:52:09.000000000 +0200
27817 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/fib6_rules.c  2008-10-13 14:54:20.000000000 +0200
27818 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27819                         if (ipv6_dev_get_saddr(net,
27820                                                ip6_dst_idev(&rt->u.dst)->dev,
27821                                                &flp->fl6_dst, srcprefs,
27822 -                                              &saddr))
27823 +                                              &saddr, NULL))
27824                                 goto again;
27825                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27826                                                r->src.plen))
27827 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/inet6_hashtables.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/inet6_hashtables.c
27828 --- linux-2.6.27.25/net/ipv6/inet6_hashtables.c 2009-06-15 17:18:35.000000000 +0200
27829 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/inet6_hashtables.c    2009-05-15 22:57:04.000000000 +0200
27830 @@ -16,6 +16,7 @@
27831  
27832  #include <linux/module.h>
27833  #include <linux/random.h>
27834 +#include <linux/vs_inet6.h>
27835  
27836  #include <net/inet_connection_sock.h>
27837  #include <net/inet_hashtables.h>
27838 @@ -115,6 +116,9 @@ struct sock *inet6_lookup_listener(struc
27839                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27840                                         continue;
27841                                 score++;
27842 +                       } else {
27843 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27844 +                                       continue;
27845                         }
27846                         if (sk->sk_bound_dev_if) {
27847                                 if (sk->sk_bound_dev_if != dif)
27848 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/ip6_output.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/ip6_output.c
27849 --- linux-2.6.27.25/net/ipv6/ip6_output.c       2009-06-15 17:18:35.000000000 +0200
27850 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/ip6_output.c  2009-02-22 22:58:33.000000000 +0100
27851 @@ -937,7 +937,7 @@ static int ip6_dst_lookup_tail(struct so
27852                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27853                                          &fl->fl6_dst,
27854                                          sk ? inet6_sk(sk)->srcprefs : 0,
27855 -                                        &fl->fl6_src);
27856 +                                        &fl->fl6_src, sk->sk_nx_info);
27857                 if (err)
27858                         goto out_err_release;
27859         }
27860 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/Kconfig linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/Kconfig
27861 --- linux-2.6.27.25/net/ipv6/Kconfig    2008-10-13 14:52:09.000000000 +0200
27862 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/Kconfig       2008-10-13 14:54:20.000000000 +0200
27863 @@ -4,8 +4,8 @@
27864  
27865  #   IPv6 as module will cause a CRASH if you try to unload it
27866  menuconfig IPV6
27867 -       tristate "The IPv6 protocol"
27868 -       default m
27869 +       bool "The IPv6 protocol"
27870 +       default n
27871         ---help---
27872           This is complemental support for the IP version 6.
27873           You will still be able to do traditional IPv4 networking as well.
27874 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/ndisc.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/ndisc.c
27875 --- linux-2.6.27.25/net/ipv6/ndisc.c    2008-10-13 14:52:09.000000000 +0200
27876 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/ndisc.c       2008-10-13 14:54:20.000000000 +0200
27877 @@ -551,7 +551,7 @@ static void ndisc_send_na(struct net_dev
27878         } else {
27879                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27880                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27881 -                                      &tmpaddr))
27882 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27883                         return;
27884                 src_addr = &tmpaddr;
27885         }
27886 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/raw.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/raw.c
27887 --- linux-2.6.27.25/net/ipv6/raw.c      2008-10-13 14:52:09.000000000 +0200
27888 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/raw.c 2008-11-21 13:32:00.000000000 +0100
27889 @@ -29,6 +29,7 @@
27890  #include <linux/icmpv6.h>
27891  #include <linux/netfilter.h>
27892  #include <linux/netfilter_ipv6.h>
27893 +#include <linux/vs_inet6.h>
27894  #include <linux/skbuff.h>
27895  #include <asm/uaccess.h>
27896  #include <asm/ioctls.h>
27897 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27898                         }
27899                 }
27900  
27901 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27902 +                       err = -EADDRNOTAVAIL;
27903 +                       if (dev)
27904 +                               dev_put(dev);
27905 +                       goto out;
27906 +               }
27907 +
27908                 /* ipv4 addr of the socket is invalid.  Only the
27909                  * unspecified and mapped address have a v4 equivalent.
27910                  */
27911 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/route.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/route.c
27912 --- linux-2.6.27.25/net/ipv6/route.c    2008-10-13 14:52:09.000000000 +0200
27913 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/route.c       2008-10-13 14:54:20.000000000 +0200
27914 @@ -2191,7 +2191,8 @@ static int rt6_fill_node(struct net *net
27915                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27916                 struct in6_addr saddr_buf;
27917                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27918 -                                      dst, 0, &saddr_buf) == 0)
27919 +                       dst, 0, &saddr_buf,
27920 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27921                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27922         }
27923  
27924 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/tcp_ipv6.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/tcp_ipv6.c
27925 --- linux-2.6.27.25/net/ipv6/tcp_ipv6.c 2009-06-15 17:18:35.000000000 +0200
27926 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/tcp_ipv6.c    2009-02-03 17:59:04.000000000 +0100
27927 @@ -67,6 +67,7 @@
27928  
27929  #include <linux/crypto.h>
27930  #include <linux/scatterlist.h>
27931 +#include <linux/vs_inet6.h>
27932  
27933  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27934  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27935 @@ -155,8 +156,15 @@ static int tcp_v6_connect(struct sock *s
27936          *      connect() to INADDR_ANY means loopback (BSD'ism).
27937          */
27938  
27939 -       if(ipv6_addr_any(&usin->sin6_addr))
27940 -               usin->sin6_addr.s6_addr[15] = 0x1;
27941 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27942 +               struct nx_info *nxi =  sk->sk_nx_info;
27943 +
27944 +               if (nxi && nx_info_has_v6(nxi))
27945 +                       /* FIXME: remap lback? */
27946 +                       usin->sin6_addr = nxi->v6.ip;
27947 +               else
27948 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27949 +       }
27950  
27951         addr_type = ipv6_addr_type(&usin->sin6_addr);
27952  
27953 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/udp.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/udp.c
27954 --- linux-2.6.27.25/net/ipv6/udp.c      2009-06-15 17:18:35.000000000 +0200
27955 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/udp.c 2009-02-03 17:59:04.000000000 +0100
27956 @@ -47,6 +47,7 @@
27957  
27958  #include <linux/proc_fs.h>
27959  #include <linux/seq_file.h>
27960 +#include <linux/vs_inet6.h>
27961  #include "udp_impl.h"
27962  
27963  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27964 @@ -81,6 +82,10 @@ static struct sock *__udp6_lib_lookup(st
27965                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27966                                         continue;
27967                                 score++;
27968 +                       } else {
27969 +                               /* block non nx_info ips */
27970 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27971 +                                       continue;
27972                         }
27973                         if (!ipv6_addr_any(&np->daddr)) {
27974                                 if (!ipv6_addr_equal(&np->daddr, saddr))
27975 diff -NurpP --minimal linux-2.6.27.25/net/ipv6/xfrm6_policy.c linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/xfrm6_policy.c
27976 --- linux-2.6.27.25/net/ipv6/xfrm6_policy.c     2008-10-13 14:52:09.000000000 +0200
27977 +++ linux-2.6.27.25-vs2.3.0.36.6/net/ipv6/xfrm6_policy.c        2008-10-13 14:54:20.000000000 +0200
27978 @@ -61,7 +61,7 @@ static int xfrm6_get_saddr(xfrm_address_
27979         dev = ip6_dst_idev(dst)->dev;
27980         ipv6_dev_get_saddr(dev_net(dev), dev,
27981                            (struct in6_addr *)&daddr->a6, 0,
27982 -                          (struct in6_addr *)&saddr->a6);
27983 +                          (struct in6_addr *)&saddr->a6, NULL);
27984         dst_release(dst);
27985         return 0;
27986  }
27987 diff -NurpP --minimal linux-2.6.27.25/net/Kconfig linux-2.6.27.25-vs2.3.0.36.6/net/Kconfig
27988 --- linux-2.6.27.25/net/Kconfig 2008-10-13 14:52:09.000000000 +0200
27989 +++ linux-2.6.27.25-vs2.3.0.36.6/net/Kconfig    2008-11-20 15:21:32.000000000 +0100
27990 @@ -27,7 +27,7 @@ menu "Networking options"
27991  config NET_NS
27992         bool "Network namespace support"
27993         default n
27994 -       depends on EXPERIMENTAL && !SYSFS && NAMESPACES
27995 +       depends on EXPERIMENTAL && NAMESPACES
27996         help
27997           Allow user space to create what appear to be multiple instances
27998           of the network stack.
27999 diff -NurpP --minimal linux-2.6.27.25/net/netlink/af_netlink.c linux-2.6.27.25-vs2.3.0.36.6/net/netlink/af_netlink.c
28000 --- linux-2.6.27.25/net/netlink/af_netlink.c    2008-10-13 14:52:09.000000000 +0200
28001 +++ linux-2.6.27.25-vs2.3.0.36.6/net/netlink/af_netlink.c       2008-10-13 14:54:20.000000000 +0200
28002 @@ -55,6 +55,9 @@
28003  #include <linux/types.h>
28004  #include <linux/audit.h>
28005  #include <linux/mutex.h>
28006 +#include <linux/vs_context.h>
28007 +#include <linux/vs_network.h>
28008 +#include <linux/vs_limit.h>
28009  
28010  #include <net/net_namespace.h>
28011  #include <net/sock.h>
28012 @@ -1761,6 +1764,8 @@ static struct sock *netlink_seq_socket_i
28013                         sk_for_each(s, node, &hash->table[j]) {
28014                                 if (sock_net(s) != seq_file_net(seq))
28015                                         continue;
28016 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28017 +                                       continue;
28018                                 if (off == pos) {
28019                                         iter->link = i;
28020                                         iter->hash_idx = j;
28021 @@ -1795,7 +1800,8 @@ static void *netlink_seq_next(struct seq
28022         s = v;
28023         do {
28024                 s = sk_next(s);
28025 -       } while (s && sock_net(s) != seq_file_net(seq));
28026 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
28027 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
28028         if (s)
28029                 return s;
28030  
28031 @@ -1807,7 +1813,8 @@ static void *netlink_seq_next(struct seq
28032  
28033                 for (; j <= hash->mask; j++) {
28034                         s = sk_head(&hash->table[j]);
28035 -                       while (s && sock_net(s) != seq_file_net(seq))
28036 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
28037 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
28038                                 s = sk_next(s);
28039                         if (s) {
28040                                 iter->link = i;
28041 diff -NurpP --minimal linux-2.6.27.25/net/sctp/ipv6.c linux-2.6.27.25-vs2.3.0.36.6/net/sctp/ipv6.c
28042 --- linux-2.6.27.25/net/sctp/ipv6.c     2008-10-13 14:52:09.000000000 +0200
28043 +++ linux-2.6.27.25-vs2.3.0.36.6/net/sctp/ipv6.c        2008-10-13 14:54:20.000000000 +0200
28044 @@ -323,7 +323,8 @@ static void sctp_v6_get_saddr(struct sct
28045                                    dst ? ip6_dst_idev(dst)->dev : NULL,
28046                                    &daddr->v6.sin6_addr,
28047                                    inet6_sk(&sk->inet.sk)->srcprefs,
28048 -                                  &saddr->v6.sin6_addr);
28049 +                                  &saddr->v6.sin6_addr,
28050 +                                  asoc->base.sk->sk_nx_info);
28051                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
28052                                   NIP6(saddr->v6.sin6_addr));
28053                 return;
28054 diff -NurpP --minimal linux-2.6.27.25/net/socket.c linux-2.6.27.25-vs2.3.0.36.6/net/socket.c
28055 --- linux-2.6.27.25/net/socket.c        2009-06-15 17:18:35.000000000 +0200
28056 +++ linux-2.6.27.25-vs2.3.0.36.6/net/socket.c   2009-02-03 17:59:04.000000000 +0100
28057 @@ -96,6 +96,10 @@
28058  
28059  #include <net/sock.h>
28060  #include <linux/netfilter.h>
28061 +#include <linux/vs_base.h>
28062 +#include <linux/vs_socket.h>
28063 +#include <linux/vs_inet.h>
28064 +#include <linux/vs_inet6.h>
28065  
28066  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28067  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28068 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
28069                                  struct msghdr *msg, size_t size)
28070  {
28071         struct sock_iocb *si = kiocb_to_siocb(iocb);
28072 -       int err;
28073 +       int err, len;
28074  
28075         si->sock = sock;
28076         si->scm = NULL;
28077 @@ -561,7 +565,22 @@ static inline int __sock_sendmsg(struct 
28078         if (err)
28079                 return err;
28080  
28081 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28082 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28083 +       if (sock->sk) {
28084 +               if (len == size)
28085 +                       vx_sock_send(sock->sk, size);
28086 +               else
28087 +                       vx_sock_fail(sock->sk, size);
28088 +       }
28089 +       vxdprintk(VXD_CBIT(net, 7),
28090 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28091 +               sock, sock->sk,
28092 +               (sock->sk)?sock->sk->sk_nx_info:0,
28093 +               (sock->sk)?sock->sk->sk_vx_info:0,
28094 +               (sock->sk)?sock->sk->sk_xid:0,
28095 +               (sock->sk)?sock->sk->sk_nid:0,
28096 +               (unsigned int)size, len);
28097 +       return len;
28098  }
28099  
28100  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28101 @@ -630,7 +649,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28102  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28103                                  struct msghdr *msg, size_t size, int flags)
28104  {
28105 -       int err;
28106 +       int err, len;
28107         struct sock_iocb *si = kiocb_to_siocb(iocb);
28108  
28109         si->sock = sock;
28110 @@ -643,7 +662,18 @@ static inline int __sock_recvmsg(struct 
28111         if (err)
28112                 return err;
28113  
28114 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28115 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28116 +       if ((len >= 0) && sock->sk)
28117 +               vx_sock_recv(sock->sk, len);
28118 +       vxdprintk(VXD_CBIT(net, 7),
28119 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28120 +               sock, sock->sk,
28121 +               (sock->sk)?sock->sk->sk_nx_info:0,
28122 +               (sock->sk)?sock->sk->sk_vx_info:0,
28123 +               (sock->sk)?sock->sk->sk_xid:0,
28124 +               (sock->sk)?sock->sk->sk_nid:0,
28125 +               (unsigned int)size, len);
28126 +       return len;
28127  }
28128  
28129  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28130 @@ -1108,6 +1138,13 @@ static int __sock_create(struct net *net
28131         if (type < 0 || type >= SOCK_MAX)
28132                 return -EINVAL;
28133  
28134 +       if (!nx_check(0, VS_ADMIN)) {
28135 +               if (family == PF_INET && !current_nx_info_has_v4())
28136 +                       return -EAFNOSUPPORT;
28137 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28138 +                       return -EAFNOSUPPORT;
28139 +       }
28140 +
28141         /* Compatibility.
28142  
28143            This uglymoron is moved from INET layer to here to avoid
28144 @@ -1240,6 +1277,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28145         if (retval < 0)
28146                 goto out;
28147  
28148 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28149         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28150         if (retval < 0)
28151                 goto out_release;
28152 @@ -1281,10 +1319,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28153         err = sock_create(family, type, protocol, &sock1);
28154         if (err < 0)
28155                 goto out;
28156 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28157  
28158         err = sock_create(family, type, protocol, &sock2);
28159         if (err < 0)
28160                 goto out_release_1;
28161 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28162  
28163         err = sock1->ops->socketpair(sock1, sock2);
28164         if (err < 0)
28165 diff -NurpP --minimal linux-2.6.27.25/net/sunrpc/auth.c linux-2.6.27.25-vs2.3.0.36.6/net/sunrpc/auth.c
28166 --- linux-2.6.27.25/net/sunrpc/auth.c   2008-07-13 23:51:29.000000000 +0200
28167 +++ linux-2.6.27.25-vs2.3.0.36.6/net/sunrpc/auth.c      2008-10-13 14:54:20.000000000 +0200
28168 @@ -14,6 +14,7 @@
28169  #include <linux/hash.h>
28170  #include <linux/sunrpc/clnt.h>
28171  #include <linux/spinlock.h>
28172 +#include <linux/vs_tag.h>
28173  
28174  #ifdef RPC_DEBUG
28175  # define RPCDBG_FACILITY       RPCDBG_AUTH
28176 @@ -353,6 +354,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28177         struct auth_cred acred = {
28178                 .uid = current->fsuid,
28179                 .gid = current->fsgid,
28180 +               .tag = dx_current_tag(),
28181                 .group_info = current->group_info,
28182         };
28183         struct rpc_cred *ret;
28184 @@ -398,6 +400,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28185         struct auth_cred acred = {
28186                 .uid = 0,
28187                 .gid = 0,
28188 +               .tag = dx_current_tag(),
28189         };
28190         struct rpc_cred *ret;
28191  
28192 diff -NurpP --minimal linux-2.6.27.25/net/sunrpc/auth_unix.c linux-2.6.27.25-vs2.3.0.36.6/net/sunrpc/auth_unix.c
28193 --- linux-2.6.27.25/net/sunrpc/auth_unix.c      2008-10-13 14:52:09.000000000 +0200
28194 +++ linux-2.6.27.25-vs2.3.0.36.6/net/sunrpc/auth_unix.c 2008-10-13 14:54:20.000000000 +0200
28195 @@ -11,12 +11,14 @@
28196  #include <linux/module.h>
28197  #include <linux/sunrpc/clnt.h>
28198  #include <linux/sunrpc/auth.h>
28199 +#include <linux/vs_tag.h>
28200  
28201  #define NFS_NGROUPS    16
28202  
28203  struct unx_cred {
28204         struct rpc_cred         uc_base;
28205         gid_t                   uc_gid;
28206 +       tag_t                   uc_tag;
28207         gid_t                   uc_gids[NFS_NGROUPS];
28208  };
28209  #define uc_uid                 uc_base.cr_uid
28210 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28211                 groups = NFS_NGROUPS;
28212  
28213         cred->uc_gid = acred->gid;
28214 +       cred->uc_tag = acred->tag;
28215         for (i = 0; i < groups; i++)
28216                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28217         if (i < NFS_NGROUPS)
28218 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28219         unsigned int i;
28220  
28221  
28222 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28223 +       if (cred->uc_uid != acred->uid ||
28224 +               cred->uc_gid != acred->gid ||
28225 +               cred->uc_tag != acred->tag)
28226                 return 0;
28227  
28228         if (acred->group_info != NULL)
28229 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28230         struct rpc_clnt *clnt = task->tk_client;
28231         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28232         __be32          *base, *hold;
28233 -       int             i;
28234 +       int             i, tag;
28235  
28236         *p++ = htonl(RPC_AUTH_UNIX);
28237         base = p++;
28238 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28239          * Copy the UTS nodename captured when the client was created.
28240          */
28241         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28242 +       tag = task->tk_client->cl_tag;
28243  
28244 -       *p++ = htonl((u32) cred->uc_uid);
28245 -       *p++ = htonl((u32) cred->uc_gid);
28246 +       *p++ = htonl((u32) TAGINO_UID(tag,
28247 +               cred->uc_uid, cred->uc_tag));
28248 +       *p++ = htonl((u32) TAGINO_GID(tag,
28249 +               cred->uc_gid, cred->uc_tag));
28250         hold = p++;
28251         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28252                 *p++ = htonl((u32) cred->uc_gids[i]);
28253 diff -NurpP --minimal linux-2.6.27.25/net/sunrpc/clnt.c linux-2.6.27.25-vs2.3.0.36.6/net/sunrpc/clnt.c
28254 --- linux-2.6.27.25/net/sunrpc/clnt.c   2008-10-13 14:52:09.000000000 +0200
28255 +++ linux-2.6.27.25-vs2.3.0.36.6/net/sunrpc/clnt.c      2008-10-13 14:54:20.000000000 +0200
28256 @@ -32,6 +32,7 @@
28257  #include <linux/utsname.h>
28258  #include <linux/workqueue.h>
28259  #include <linux/in6.h>
28260 +#include <linux/vs_cvirt.h>
28261  
28262  #include <linux/sunrpc/clnt.h>
28263  #include <linux/sunrpc/rpc_pipe_fs.h>
28264 @@ -327,6 +328,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28265         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28266                 clnt->cl_chatty = 1;
28267  
28268 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28269 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28270 +               clnt->cl_tag = 1; */
28271         return clnt;
28272  }
28273  EXPORT_SYMBOL_GPL(rpc_create);
28274 diff -NurpP --minimal linux-2.6.27.25/net/unix/af_unix.c linux-2.6.27.25-vs2.3.0.36.6/net/unix/af_unix.c
28275 --- linux-2.6.27.25/net/unix/af_unix.c  2009-06-15 17:18:35.000000000 +0200
28276 +++ linux-2.6.27.25-vs2.3.0.36.6/net/unix/af_unix.c     2009-02-03 17:59:04.000000000 +0100
28277 @@ -114,6 +114,8 @@
28278  #include <linux/mount.h>
28279  #include <net/checksum.h>
28280  #include <linux/security.h>
28281 +#include <linux/vs_context.h>
28282 +#include <linux/vs_limit.h>
28283  
28284  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28285  static DEFINE_SPINLOCK(unix_table_lock);
28286 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28287                 if (!net_eq(sock_net(s), net))
28288                         continue;
28289  
28290 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28291 +                       continue;
28292                 if (u->addr->len == len &&
28293                     !memcmp(u->addr->name, sunname, len))
28294                         goto found;
28295 @@ -2103,6 +2107,8 @@ static struct sock *unix_seq_idx(struct 
28296         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28297                 if (sock_net(s) != seq_file_net(seq))
28298                         continue;
28299 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28300 +                       continue;
28301                 if (off == pos)
28302                         return s;
28303                 ++off;
28304 @@ -2128,7 +2134,8 @@ static void *unix_seq_next(struct seq_fi
28305                 sk = first_unix_socket(&iter->i);
28306         else
28307                 sk = next_unix_socket(&iter->i, sk);
28308 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28309 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28310 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28311                 sk = next_unix_socket(&iter->i, sk);
28312         return sk;
28313  }
28314 diff -NurpP --minimal linux-2.6.27.25/net/x25/af_x25.c linux-2.6.27.25-vs2.3.0.36.6/net/x25/af_x25.c
28315 --- linux-2.6.27.25/net/x25/af_x25.c    2009-06-15 17:18:35.000000000 +0200
28316 +++ linux-2.6.27.25-vs2.3.0.36.6/net/x25/af_x25.c       2009-05-15 22:57:04.000000000 +0200
28317 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
28318  
28319         x25 = x25_sk(sk);
28320  
28321 -       sock_init_data(sock, sk);
28322 +       sk->sk_socket = sock;
28323 +       sk->sk_type = sock->type;
28324 +       sk->sk_sleep = &sock->wait;
28325 +       sock->sk = sk;
28326  
28327         x25_init_timers(sk);
28328  
28329 diff -NurpP --minimal linux-2.6.27.25/scripts/checksyscalls.sh linux-2.6.27.25-vs2.3.0.36.6/scripts/checksyscalls.sh
28330 --- linux-2.6.27.25/scripts/checksyscalls.sh    2008-07-13 23:51:29.000000000 +0200
28331 +++ linux-2.6.27.25-vs2.3.0.36.6/scripts/checksyscalls.sh       2008-10-13 14:54:20.000000000 +0200
28332 @@ -108,7 +108,6 @@ cat << EOF
28333  #define __IGNORE_afs_syscall
28334  #define __IGNORE_getpmsg
28335  #define __IGNORE_putpmsg
28336 -#define __IGNORE_vserver
28337  EOF
28338  }
28339  
28340 diff -NurpP --minimal linux-2.6.27.25/security/commoncap.c linux-2.6.27.25-vs2.3.0.36.6/security/commoncap.c
28341 --- linux-2.6.27.25/security/commoncap.c        2009-06-15 17:18:35.000000000 +0200
28342 +++ linux-2.6.27.25-vs2.3.0.36.6/security/commoncap.c   2009-03-09 15:36:36.000000000 +0100
28343 @@ -26,10 +26,11 @@
28344  #include <linux/sched.h>
28345  #include <linux/prctl.h>
28346  #include <linux/securebits.h>
28347 +#include <linux/vs_context.h>
28348  
28349  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28350  {
28351 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
28352 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
28353         return 0;
28354  }
28355  
28356 @@ -50,9 +51,24 @@ EXPORT_SYMBOL(cap_netlink_recv);
28357   */
28358  int cap_capable (struct task_struct *tsk, int cap)
28359  {
28360 +       struct vx_info *vxi = tsk->vx_info;
28361 +
28362 +#if 0
28363 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28364 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28365 +               cap_raised(tsk->cap_effective, cap),
28366 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28367 +#endif
28368 +
28369 +       /* special case SETUP */
28370 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28371 +               cap_raised(tsk->cap_effective, cap))
28372 +               return 0;
28373 +
28374         /* Derived from include/linux/sched.h:capable. */
28375 -       if (cap_raised(tsk->cap_effective, cap))
28376 +       if (vx_cap_raised(vxi, tsk->cap_effective, cap))
28377                 return 0;
28378 +
28379         return -EPERM;
28380  }
28381  
28382 @@ -420,7 +436,7 @@ int cap_inode_setxattr(struct dentry *de
28383                 return 0;
28384         } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
28385                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28386 -           !capable(CAP_SYS_ADMIN))
28387 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28388                 return -EPERM;
28389         return 0;
28390  }
28391 @@ -696,7 +712,8 @@ void cap_task_reparent_to_init (struct t
28392  
28393  int cap_syslog (int type)
28394  {
28395 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28396 +       if ((type != 3 && type != 10) &&
28397 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28398                 return -EPERM;
28399         return 0;
28400  }
28401 diff -NurpP --minimal linux-2.6.27.25/security/selinux/hooks.c linux-2.6.27.25-vs2.3.0.36.6/security/selinux/hooks.c
28402 --- linux-2.6.27.25/security/selinux/hooks.c    2009-06-15 17:18:35.000000000 +0200
28403 +++ linux-2.6.27.25-vs2.3.0.36.6/security/selinux/hooks.c       2009-06-15 17:22:10.000000000 +0200
28404 @@ -64,7 +64,6 @@
28405  #include <linux/dccp.h>
28406  #include <linux/quota.h>
28407  #include <linux/un.h>          /* for Unix socket types */
28408 -#include <net/af_unix.h>       /* for Unix socket types */
28409  #include <linux/parser.h>
28410  #include <linux/nfs_mount.h>
28411  #include <net/ipv6.h>
This page took 2.016112 seconds and 2 git commands to generate.