]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.3.patch
- conflicts with util-vserver tools with broken vprocunhide
[packages/kernel.git] / linux-2.6-vs2.3.patch
1 diff -NurpP --minimal linux-2.6.27.6/arch/alpha/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/alpha/Kconfig
2 --- linux-2.6.27.6/arch/alpha/Kconfig   2008-10-13 14:51:51.000000000 +0200
3 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/alpha/kernel/entry.S linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/entry.S
14 --- linux-2.6.27.6/arch/alpha/kernel/entry.S    2008-07-13 23:51:29.000000000 +0200
15 +++ linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/entry.S 2008-10-13 14:54:20.000000000 +0200
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.6/arch/alpha/kernel/osf_sys.c linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.27.6/arch/alpha/kernel/osf_sys.c  2008-10-13 14:51:51.000000000 +0200
50 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/alpha/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.27.6/arch/alpha/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
62 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/alpha/kernel/systbls.S linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/systbls.S
72 --- linux-2.6.27.6/arch/alpha/kernel/systbls.S  2008-07-13 23:51:29.000000000 +0200
73 +++ linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/systbls.S       2008-10-13 14:54:20.000000000 +0200
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.6/arch/alpha/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/alpha/kernel/traps.c
84 --- linux-2.6.27.6/arch/alpha/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
85 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/alpha/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/alpha/mm/fault.c
97 --- linux-2.6.27.6/arch/alpha/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
98 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/arm/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/arm/Kconfig
111 --- linux-2.6.27.6/arch/arm/Kconfig     2008-10-13 14:51:51.000000000 +0200
112 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/arm/kernel/calls.S linux-2.6.27.6-vs2.3.0.36/arch/arm/kernel/calls.S
123 --- linux-2.6.27.6/arch/arm/kernel/calls.S      2008-10-13 14:51:52.000000000 +0200
124 +++ linux-2.6.27.6-vs2.3.0.36/arch/arm/kernel/calls.S   2008-10-13 14:54:20.000000000 +0200
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.6/arch/arm/kernel/process.c linux-2.6.27.6-vs2.3.0.36/arch/arm/kernel/process.c
135 --- linux-2.6.27.6/arch/arm/kernel/process.c    2008-10-13 14:51:52.000000000 +0200
136 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/arm/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/arm/kernel/traps.c
148 --- linux-2.6.27.6/arch/arm/kernel/traps.c      2008-10-13 14:51:52.000000000 +0200
149 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/arm/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/arm/mm/fault.c
162 --- linux-2.6.27.6/arch/arm/mm/fault.c  2008-07-13 23:51:29.000000000 +0200
163 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/cris/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/cris/Kconfig
175 --- linux-2.6.27.6/arch/cris/Kconfig    2008-07-13 23:51:29.000000000 +0200
176 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/frv/kernel/kernel_thread.S linux-2.6.27.6-vs2.3.0.36/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.27.6/arch/frv/kernel/kernel_thread.S      2008-07-13 23:51:29.000000000 +0200
188 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/h8300/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/h8300/Kconfig
199 --- linux-2.6.27.6/arch/h8300/Kconfig   2008-10-13 14:51:55.000000000 +0200
200 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/ia64/ia32/ia32_entry.S linux-2.6.27.6-vs2.3.0.36/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.27.6/arch/ia64/ia32/ia32_entry.S  2008-10-13 14:51:55.000000000 +0200
212 +++ linux-2.6.27.6-vs2.3.0.36/arch/ia64/ia32/ia32_entry.S       2008-10-13 14:54:20.000000000 +0200
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.6/arch/ia64/ia32/sys_ia32.c linux-2.6.27.6-vs2.3.0.36/arch/ia64/ia32/sys_ia32.c
223 --- linux-2.6.27.6/arch/ia64/ia32/sys_ia32.c    2008-10-13 14:51:55.000000000 +0200
224 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/ia64/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/ia64/Kconfig
235 --- linux-2.6.27.6/arch/ia64/Kconfig    2008-10-13 14:51:55.000000000 +0200
236 +++ linux-2.6.27.6-vs2.3.0.36/arch/ia64/Kconfig 2008-10-13 14:54:20.000000000 +0200
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.6/arch/ia64/kernel/entry.S linux-2.6.27.6-vs2.3.0.36/arch/ia64/kernel/entry.S
247 --- linux-2.6.27.6/arch/ia64/kernel/entry.S     2008-10-13 14:51:55.000000000 +0200
248 +++ linux-2.6.27.6-vs2.3.0.36/arch/ia64/kernel/entry.S  2008-10-13 14:54:20.000000000 +0200
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.6/arch/ia64/kernel/perfmon.c linux-2.6.27.6-vs2.3.0.36/arch/ia64/kernel/perfmon.c
259 --- linux-2.6.27.6/arch/ia64/kernel/perfmon.c   2008-10-13 14:51:55.000000000 +0200
260 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/ia64/kernel/process.c linux-2.6.27.6-vs2.3.0.36/arch/ia64/kernel/process.c
279 --- linux-2.6.27.6/arch/ia64/kernel/process.c   2008-10-13 14:51:55.000000000 +0200
280 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/ia64/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/ia64/kernel/ptrace.c
293 --- linux-2.6.27.6/arch/ia64/kernel/ptrace.c    2008-07-13 23:51:29.000000000 +0200
294 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/ia64/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/ia64/kernel/traps.c
304 --- linux-2.6.27.6/arch/ia64/kernel/traps.c     2008-07-13 23:51:29.000000000 +0200
305 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/ia64/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/ia64/mm/fault.c
331 --- linux-2.6.27.6/arch/ia64/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
332 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/m32r/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/m32r/kernel/traps.c
342 --- linux-2.6.27.6/arch/m32r/kernel/traps.c     2008-10-13 14:51:55.000000000 +0200
343 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/m68k/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/m68k/Kconfig
357 --- linux-2.6.27.6/arch/m68k/Kconfig    2008-10-13 14:51:55.000000000 +0200
358 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/m68k/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/m68k/kernel/ptrace.c
369 --- linux-2.6.27.6/arch/m68k/kernel/ptrace.c    2008-07-13 23:51:29.000000000 +0200
370 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/m68k/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/m68k/kernel/traps.c
389 --- linux-2.6.27.6/arch/m68k/kernel/traps.c     2008-07-13 23:51:29.000000000 +0200
390 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/m68knommu/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/m68knommu/Kconfig
403 --- linux-2.6.27.6/arch/m68knommu/Kconfig       2008-10-13 14:51:55.000000000 +0200
404 +++ linux-2.6.27.6-vs2.3.0.36/arch/m68knommu/Kconfig    2008-10-13 14:54:20.000000000 +0200
405 @@ -740,6 +740,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.6/arch/m68knommu/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/m68knommu/kernel/traps.c
415 --- linux-2.6.27.6/arch/m68knommu/kernel/traps.c        2008-10-13 14:51:55.000000000 +0200
416 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/mips/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/mips/Kconfig
430 --- linux-2.6.27.6/arch/mips/Kconfig    2008-10-13 14:51:55.000000000 +0200
431 +++ linux-2.6.27.6-vs2.3.0.36/arch/mips/Kconfig 2008-10-13 14:54:20.000000000 +0200
432 @@ -2031,6 +2031,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.6/arch/mips/kernel/linux32.c linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/linux32.c
442 --- linux-2.6.27.6/arch/mips/kernel/linux32.c   2008-10-13 14:51:56.000000000 +0200
443 +++ linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/linux32.c        2008-10-13 14:54:20.000000000 +0200
444 @@ -191,7 +191,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.6/arch/mips/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/ptrace.c
454 --- linux-2.6.27.6/arch/mips/kernel/ptrace.c    2008-10-13 14:51:56.000000000 +0200
455 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/mips/kernel/scall32-o32.S linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall32-o32.S
475 --- linux-2.6.27.6/arch/mips/kernel/scall32-o32.S       2008-10-13 14:51:56.000000000 +0200
476 +++ linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall32-o32.S    2008-10-13 14:54:20.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.6/arch/mips/kernel/scall64-64.S linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall64-64.S
487 --- linux-2.6.27.6/arch/mips/kernel/scall64-64.S        2008-10-13 14:51:56.000000000 +0200
488 +++ linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall64-64.S     2008-10-13 14:54:20.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.6/arch/mips/kernel/scall64-n32.S linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall64-n32.S
499 --- linux-2.6.27.6/arch/mips/kernel/scall64-n32.S       2008-10-13 14:51:56.000000000 +0200
500 +++ linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall64-n32.S    2008-10-13 14:54:20.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.6/arch/mips/kernel/scall64-o32.S linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall64-o32.S
511 --- linux-2.6.27.6/arch/mips/kernel/scall64-o32.S       2008-10-13 14:51:56.000000000 +0200
512 +++ linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/scall64-o32.S    2008-10-13 14:54:20.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     sys32_waitid
520         PTR     sys_ni_syscall                  /* available, was setaltroot */
521         PTR     sys_add_key                     /* 4280 */
522 diff -NurpP --minimal linux-2.6.27.6/arch/mips/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/mips/kernel/traps.c
523 --- linux-2.6.27.6/arch/mips/kernel/traps.c     2008-10-13 14:51:56.000000000 +0200
524 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/mips/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/mips/mm/fault.c
540 --- linux-2.6.27.6/arch/mips/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
541 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/parisc/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/parisc/Kconfig
553 --- linux-2.6.27.6/arch/parisc/Kconfig  2008-10-13 14:51:56.000000000 +0200
554 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/parisc/kernel/syscall_table.S linux-2.6.27.6-vs2.3.0.36/arch/parisc/kernel/syscall_table.S
565 --- linux-2.6.27.6/arch/parisc/kernel/syscall_table.S   2008-07-13 23:51:29.000000000 +0200
566 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/parisc/kernel/sys_parisc32.c linux-2.6.27.6-vs2.3.0.36/arch/parisc/kernel/sys_parisc32.c
577 --- linux-2.6.27.6/arch/parisc/kernel/sys_parisc32.c    2008-07-13 23:51:29.000000000 +0200
578 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/parisc/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/parisc/kernel/traps.c
594 --- linux-2.6.27.6/arch/parisc/kernel/traps.c   2008-07-13 23:51:29.000000000 +0200
595 +++ linux-2.6.27.6-vs2.3.0.36/arch/parisc/kernel/traps.c        2008-10-13 14:54:20.000000000 +0200
596 @@ -237,8 +237,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 @@ -270,8 +271,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.6/arch/parisc/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/parisc/mm/fault.c
620 --- linux-2.6.27.6/arch/parisc/mm/fault.c       2008-07-13 23:51:29.000000000 +0200
621 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/powerpc/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/powerpc/Kconfig
645 --- linux-2.6.27.6/arch/powerpc/Kconfig 2008-10-13 14:51:56.000000000 +0200
646 +++ linux-2.6.27.6-vs2.3.0.36/arch/powerpc/Kconfig      2008-10-13 14:54:20.000000000 +0200
647 @@ -835,6 +835,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.6/arch/powerpc/kernel/irq.c linux-2.6.27.6-vs2.3.0.36/arch/powerpc/kernel/irq.c
657 --- linux-2.6.27.6/arch/powerpc/kernel/irq.c    2008-10-13 14:51:56.000000000 +0200
658 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/powerpc/kernel/process.c linux-2.6.27.6-vs2.3.0.36/arch/powerpc/kernel/process.c
668 --- linux-2.6.27.6/arch/powerpc/kernel/process.c        2008-10-13 14:51:56.000000000 +0200
669 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/powerpc/kernel/sys_ppc32.c linux-2.6.27.6-vs2.3.0.36/arch/powerpc/kernel/sys_ppc32.c
683 --- linux-2.6.27.6/arch/powerpc/kernel/sys_ppc32.c      2008-10-13 14:51:56.000000000 +0200
684 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/powerpc/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/powerpc/kernel/traps.c
695 --- linux-2.6.27.6/arch/powerpc/kernel/traps.c  2008-10-13 14:51:56.000000000 +0200
696 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/powerpc/kernel/vdso.c linux-2.6.27.6-vs2.3.0.36/arch/powerpc/kernel/vdso.c
710 --- linux-2.6.27.6/arch/powerpc/kernel/vdso.c   2008-10-13 14:51:56.000000000 +0200
711 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/powerpc/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/powerpc/mm/fault.c
721 --- linux-2.6.27.6/arch/powerpc/mm/fault.c      2008-10-13 14:51:56.000000000 +0200
722 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/s390/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/s390/Kconfig
734 --- linux-2.6.27.6/arch/s390/Kconfig    2008-10-13 14:51:57.000000000 +0200
735 +++ linux-2.6.27.6-vs2.3.0.36/arch/s390/Kconfig 2008-10-13 14:54:20.000000000 +0200
736 @@ -587,6 +587,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.6/arch/s390/kernel/compat_linux.c linux-2.6.27.6-vs2.3.0.36/arch/s390/kernel/compat_linux.c
746 --- linux-2.6.27.6/arch/s390/kernel/compat_linux.c      2008-07-13 23:51:29.000000000 +0200
747 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/s390/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/s390/kernel/ptrace.c
758 --- linux-2.6.27.6/arch/s390/kernel/ptrace.c    2008-10-13 14:51:57.000000000 +0200
759 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/s390/kernel/syscalls.S linux-2.6.27.6-vs2.3.0.36/arch/s390/kernel/syscalls.S
769 --- linux-2.6.27.6/arch/s390/kernel/syscalls.S  2008-10-13 14:51:57.000000000 +0200
770 +++ linux-2.6.27.6-vs2.3.0.36/arch/s390/kernel/syscalls.S       2008-10-13 14:54:20.000000000 +0200
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(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.6/arch/s390/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/s390/mm/fault.c
781 --- linux-2.6.27.6/arch/s390/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
782 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sh/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/sh/Kconfig
794 --- linux-2.6.27.6/arch/sh/Kconfig      2008-10-13 14:51:57.000000000 +0200
795 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sh/kernel/irq.c linux-2.6.27.6-vs2.3.0.36/arch/sh/kernel/irq.c
806 --- linux-2.6.27.6/arch/sh/kernel/irq.c 2008-10-13 14:51:57.000000000 +0200
807 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.27.6-vs2.3.0.36/arch/sh/kernel/vsyscall/vsyscall.c
817 --- linux-2.6.27.6/arch/sh/kernel/vsyscall/vsyscall.c   2008-07-13 23:51:29.000000000 +0200
818 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sparc/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/sparc/Kconfig
828 --- linux-2.6.27.6/arch/sparc/Kconfig   2008-10-13 14:51:58.000000000 +0200
829 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sparc/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/sparc/kernel/ptrace.c
840 --- linux-2.6.27.6/arch/sparc/kernel/ptrace.c   2008-10-13 14:51:58.000000000 +0200
841 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sparc/kernel/systbls.S linux-2.6.27.6-vs2.3.0.36/arch/sparc/kernel/systbls.S
851 --- linux-2.6.27.6/arch/sparc/kernel/systbls.S  2008-10-13 14:51:58.000000000 +0200
852 +++ linux-2.6.27.6-vs2.3.0.36/arch/sparc/kernel/systbls.S       2008-10-13 14:54:20.000000000 +0200
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.6/arch/sparc/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/sparc/kernel/traps.c
863 --- linux-2.6.27.6/arch/sparc/kernel/traps.c    2008-10-13 14:51:58.000000000 +0200
864 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sparc/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/sparc/mm/fault.c
876 --- linux-2.6.27.6/arch/sparc/mm/fault.c        2008-10-13 14:51:58.000000000 +0200
877 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sparc64/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/sparc64/Kconfig
889 --- linux-2.6.27.6/arch/sparc64/Kconfig 2008-10-13 14:51:58.000000000 +0200
890 +++ linux-2.6.27.6-vs2.3.0.36/arch/sparc64/Kconfig      2008-10-13 14:54:20.000000000 +0200
891 @@ -403,6 +403,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.6/arch/sparc64/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/ptrace.c
901 --- linux-2.6.27.6/arch/sparc64/kernel/ptrace.c 2008-10-13 14:51:58.000000000 +0200
902 +++ linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
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.6/arch/sparc64/kernel/sys_sparc32.c linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/sys_sparc32.c
912 --- linux-2.6.27.6/arch/sparc64/kernel/sys_sparc32.c    2008-10-13 14:51:58.000000000 +0200
913 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/sparc64/kernel/systbls.S linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/systbls.S
924 --- linux-2.6.27.6/arch/sparc64/kernel/systbls.S        2008-10-13 14:51:58.000000000 +0200
925 +++ linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/systbls.S     2008-10-13 14:54:20.000000000 +0200
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 sys64_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.6/arch/sparc64/kernel/traps.c linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/traps.c
945 --- linux-2.6.27.6/arch/sparc64/kernel/traps.c  2008-10-13 14:51:58.000000000 +0200
946 +++ linux-2.6.27.6-vs2.3.0.36/arch/sparc64/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
947 @@ -2186,7 +2186,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.6/arch/sparc64/mm/fault.c linux-2.6.27.6-vs2.3.0.36/arch/sparc64/mm/fault.c
958 --- linux-2.6.27.6/arch/sparc64/mm/fault.c      2008-10-13 14:51:58.000000000 +0200
959 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/um/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/um/Kconfig
971 --- linux-2.6.27.6/arch/um/Kconfig      2008-07-13 23:51:29.000000000 +0200
972 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/um/kernel/trap.c linux-2.6.27.6-vs2.3.0.36/arch/um/kernel/trap.c
983 --- linux-2.6.27.6/arch/um/kernel/trap.c        2008-07-13 23:51:29.000000000 +0200
984 +++ linux-2.6.27.6-vs2.3.0.36/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.6/arch/x86/ia32/ia32entry.S linux-2.6.27.6-vs2.3.0.36/arch/x86/ia32/ia32entry.S
996 --- linux-2.6.27.6/arch/x86/ia32/ia32entry.S    2008-10-13 14:51:58.000000000 +0200
997 +++ linux-2.6.27.6-vs2.3.0.36/arch/x86/ia32/ia32entry.S 2008-10-13 14:54:20.000000000 +0200
998 @@ -772,7 +772,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.6/arch/x86/Kconfig linux-2.6.27.6-vs2.3.0.36/arch/x86/Kconfig
1008 --- linux-2.6.27.6/arch/x86/Kconfig     2008-11-17 18:07:30.000000000 +0100
1009 +++ linux-2.6.27.6-vs2.3.0.36/arch/x86/Kconfig  2008-11-17 18:20:40.000000000 +0100
1010 @@ -1808,6 +1808,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.6/arch/x86/kernel/syscall_table_32.S linux-2.6.27.6-vs2.3.0.36/arch/x86/kernel/syscall_table_32.S
1020 --- linux-2.6.27.6/arch/x86/kernel/syscall_table_32.S   2008-10-13 14:51:58.000000000 +0200
1021 +++ linux-2.6.27.6-vs2.3.0.36/arch/x86/kernel/syscall_table_32.S        2008-10-13 14:54:20.000000000 +0200
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.6/Documentation/vserver/debug.txt linux-2.6.27.6-vs2.3.0.36/Documentation/vserver/debug.txt
1032 --- linux-2.6.27.6/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
1033 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/block/Kconfig linux-2.6.27.6-vs2.3.0.36/drivers/block/Kconfig
1190 --- linux-2.6.27.6/drivers/block/Kconfig        2008-10-13 14:51:59.000000000 +0200
1191 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/block/loop.c linux-2.6.27.6-vs2.3.0.36/drivers/block/loop.c
1207 --- linux-2.6.27.6/drivers/block/loop.c 2008-07-13 23:51:29.000000000 +0200
1208 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/block/Makefile linux-2.6.27.6-vs2.3.0.36/drivers/block/Makefile
1263 --- linux-2.6.27.6/drivers/block/Makefile       2008-10-13 14:51:59.000000000 +0200
1264 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/block/vroot.c linux-2.6.27.6-vs2.3.0.36/drivers/block/vroot.c
1273 --- linux-2.6.27.6/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1274 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/char/sysrq.c linux-2.6.27.6-vs2.3.0.36/drivers/char/sysrq.c
1560 --- linux-2.6.27.6/drivers/char/sysrq.c 2008-10-13 14:51:59.000000000 +0200
1561 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/char/tty_io.c linux-2.6.27.6-vs2.3.0.36/drivers/char/tty_io.c
1615 --- linux-2.6.27.6/drivers/char/tty_io.c        2008-11-17 18:07:31.000000000 +0100
1616 +++ linux-2.6.27.6-vs2.3.0.36/drivers/char/tty_io.c     2008-10-24 02:21:46.000000000 +0200
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.6/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.27.6-vs2.3.0.36/drivers/infiniband/hw/ipath/ipath_user_pages.c
1634 --- linux-2.6.27.6/drivers/infiniband/hw/ipath/ipath_user_pages.c       2008-07-13 23:51:29.000000000 +0200
1635 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/md/dm.c linux-2.6.27.6-vs2.3.0.36/drivers/md/dm.c
1682 --- linux-2.6.27.6/drivers/md/dm.c      2008-10-13 14:52:01.000000000 +0200
1683 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/md/dm.h linux-2.6.27.6-vs2.3.0.36/drivers/md/dm.h
1758 --- linux-2.6.27.6/drivers/md/dm.h      2008-10-13 14:52:01.000000000 +0200
1759 +++ linux-2.6.27.6-vs2.3.0.36/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.6/drivers/md/dm-ioctl.c linux-2.6.27.6-vs2.3.0.36/drivers/md/dm-ioctl.c
1770 --- linux-2.6.27.6/drivers/md/dm-ioctl.c        2008-07-13 23:51:29.000000000 +0200
1771 +++ linux-2.6.27.6-vs2.3.0.36/drivers/md/dm-ioctl.c     2008-10-13 14:54:20.000000000 +0200
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 @@ -1406,8 +1417,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.6/drivers/net/tun.c linux-2.6.27.6-vs2.3.0.36/drivers/net/tun.c
1854 --- linux-2.6.27.6/drivers/net/tun.c    2008-10-13 14:52:02.000000000 +0200
1855 +++ linux-2.6.27.6-vs2.3.0.36/drivers/net/tun.c 2008-10-13 14:54:20.000000000 +0200
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 @@ -675,6 +677,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 @@ -707,6 +710,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 @@ -715,7 +721,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 @@ -726,7 +732,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 @@ -966,6 +972,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.6/fs/attr.c linux-2.6.27.6-vs2.3.0.36/fs/attr.c
1926 --- linux-2.6.27.6/fs/attr.c    2008-10-13 14:52:05.000000000 +0200
1927 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/binfmt_aout.c linux-2.6.27.6-vs2.3.0.36/fs/binfmt_aout.c
1969 --- linux-2.6.27.6/fs/binfmt_aout.c     2008-10-13 14:52:05.000000000 +0200
1970 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/binfmt_elf.c linux-2.6.27.6-vs2.3.0.36/fs/binfmt_elf.c
1980 --- linux-2.6.27.6/fs/binfmt_elf.c      2008-10-13 14:52:05.000000000 +0200
1981 +++ linux-2.6.27.6-vs2.3.0.36/fs/binfmt_elf.c   2008-10-13 14:54:20.000000000 +0200
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.6/fs/binfmt_flat.c linux-2.6.27.6-vs2.3.0.36/fs/binfmt_flat.c
1991 --- linux-2.6.27.6/fs/binfmt_flat.c     2008-10-13 14:52:05.000000000 +0200
1992 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/binfmt_som.c linux-2.6.27.6-vs2.3.0.36/fs/binfmt_som.c
2002 --- linux-2.6.27.6/fs/binfmt_som.c      2008-10-13 14:52:05.000000000 +0200
2003 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/block_dev.c linux-2.6.27.6-vs2.3.0.36/fs/block_dev.c
2013 --- linux-2.6.27.6/fs/block_dev.c       2008-10-13 14:52:05.000000000 +0200
2014 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/char_dev.c linux-2.6.27.6-vs2.3.0.36/fs/char_dev.c
2053 --- linux-2.6.27.6/fs/char_dev.c        2008-10-13 14:52:05.000000000 +0200
2054 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/dcache.c linux-2.6.27.6-vs2.3.0.36/fs/dcache.c
2088 --- linux-2.6.27.6/fs/dcache.c  2008-10-13 14:52:05.000000000 +0200
2089 +++ linux-2.6.27.6-vs2.3.0.36/fs/dcache.c       2008-10-24 03:34:52.000000000 +0200
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.6/fs/devpts/inode.c linux-2.6.27.6-vs2.3.0.36/fs/devpts/inode.c
2142 --- linux-2.6.27.6/fs/devpts/inode.c    2008-10-13 14:52:05.000000000 +0200
2143 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/exec.c linux-2.6.27.6-vs2.3.0.36/fs/exec.c
2225 --- linux-2.6.27.6/fs/exec.c    2008-10-13 14:52:05.000000000 +0200
2226 +++ linux-2.6.27.6-vs2.3.0.36/fs/exec.c 2008-10-13 14:54:20.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 @@ -1453,7 +1455,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.6/fs/ext2/balloc.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/balloc.c
2248 --- linux-2.6.27.6/fs/ext2/balloc.c     2008-07-13 23:51:29.000000000 +0200
2249 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext2/balloc.c  2008-10-13 14:54:20.000000000 +0200
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 @@ -1408,6 +1415,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 @@ -1418,8 +1426,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.6/fs/ext2/ext2.h linux-2.6.27.6-vs2.3.0.36/fs/ext2/ext2.h
2308 --- linux-2.6.27.6/fs/ext2/ext2.h       2008-07-13 23:51:29.000000000 +0200
2309 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/file.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/file.c
2319 --- linux-2.6.27.6/fs/ext2/file.c       2008-07-13 23:51:29.000000000 +0200
2320 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/ialloc.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/ialloc.c
2328 --- linux-2.6.27.6/fs/ext2/ialloc.c     2008-07-13 23:51:29.000000000 +0200
2329 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/inode.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/inode.c
2386 --- linux-2.6.27.6/fs/ext2/inode.c      2008-10-13 14:52:05.000000000 +0200
2387 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/ioctl.c
2548 --- linux-2.6.27.6/fs/ext2/ioctl.c      2008-07-13 23:51:29.000000000 +0200
2549 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/namei.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/namei.c
2582 --- linux-2.6.27.6/fs/ext2/namei.c      2008-07-13 23:51:29.000000000 +0200
2583 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/super.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/super.c
2615 --- linux-2.6.27.6/fs/ext2/super.c      2008-10-13 14:52:05.000000000 +0200
2616 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext2/super.c   2008-10-13 14:54:20.000000000 +0200
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.6/fs/ext2/symlink.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/symlink.c
2682 --- linux-2.6.27.6/fs/ext2/symlink.c    2008-07-13 23:51:29.000000000 +0200
2683 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext2/xattr.c linux-2.6.27.6-vs2.3.0.36/fs/ext2/xattr.c
2699 --- linux-2.6.27.6/fs/ext2/xattr.c      2008-07-13 23:51:29.000000000 +0200
2700 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext3/balloc.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/balloc.c
2739 --- linux-2.6.27.6/fs/ext3/balloc.c     2008-07-13 23:51:29.000000000 +0200
2740 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext3/balloc.c  2008-10-13 14:54:20.000000000 +0200
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 @@ -1714,12 +1735,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.6/fs/ext3/file.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/file.c
2848 --- linux-2.6.27.6/fs/ext3/file.c       2008-07-13 23:51:29.000000000 +0200
2849 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext3/ialloc.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/ialloc.c
2858 --- linux-2.6.27.6/fs/ext3/ialloc.c     2008-10-13 14:52:05.000000000 +0200
2859 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext3/inode.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/inode.c
2918 --- linux-2.6.27.6/fs/ext3/inode.c      2008-10-13 14:52:05.000000000 +0200
2919 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext3/inode.c   2008-10-13 14:54:20.000000000 +0200
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.6/fs/ext3/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/ioctl.c
3128 --- linux-2.6.27.6/fs/ext3/ioctl.c      2008-07-13 23:51:29.000000000 +0200
3129 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext3/namei.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/namei.c
3170 --- linux-2.6.27.6/fs/ext3/namei.c      2008-10-13 14:52:05.000000000 +0200
3171 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext3/namei.c   2008-10-13 14:54:20.000000000 +0200
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 @@ -2426,6 +2428,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 @@ -2437,4 +2440,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.6/fs/ext3/super.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/super.c
3203 --- linux-2.6.27.6/fs/ext3/super.c      2008-11-17 18:07:34.000000000 +0100
3204 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext3/super.c   2008-11-17 18:20:41.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.6/fs/ext3/symlink.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/symlink.c
3270 --- linux-2.6.27.6/fs/ext3/symlink.c    2008-07-13 23:51:29.000000000 +0200
3271 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext3/xattr.c linux-2.6.27.6-vs2.3.0.36/fs/ext3/xattr.c
3287 --- linux-2.6.27.6/fs/ext3/xattr.c      2008-07-13 23:51:29.000000000 +0200
3288 +++ linux-2.6.27.6-vs2.3.0.36/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.6/fs/ext4/balloc.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/balloc.c
3331 --- linux-2.6.27.6/fs/ext4/balloc.c     2008-10-13 14:52:05.000000000 +0200
3332 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/balloc.c  2008-10-13 14:54:20.000000000 +0200
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 @@ -865,8 +867,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 @@ -1726,6 +1730,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 @@ -1935,12 +1941,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.6/fs/ext4/ext4.h linux-2.6.27.6-vs2.3.0.36/fs/ext4/ext4.h
3381 --- linux-2.6.27.6/fs/ext4/ext4.h       2008-10-13 14:52:05.000000000 +0200
3382 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/ext4.h    2008-10-31 18:15:18.000000000 +0100
3383 @@ -242,8 +242,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 @@ -540,6 +544,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 @@ -1054,6 +1059,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.6/fs/ext4/file.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/file.c
3413 --- linux-2.6.27.6/fs/ext4/file.c       2008-10-13 14:52:05.000000000 +0200
3414 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/file.c    2008-10-13 14:54:20.000000000 +0200
3415 @@ -170,5 +170,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.6/fs/ext4/ialloc.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/ialloc.c
3423 --- linux-2.6.27.6/fs/ext4/ialloc.c     2008-10-13 14:52:05.000000000 +0200
3424 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/ialloc.c  2008-10-13 14:54:20.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 @@ -196,6 +198,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 @@ -602,6 +605,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 @@ -808,7 +817,8 @@ got:
3456          * newly created directory and file only if -o extent mount option is
3457          * specified
3458          */
3459 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3460 +       ei->i_flags = EXT4_I(dir)->i_flags &
3461 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3462         if (S_ISLNK(mode))
3463                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3464         /* dirsync only applies to directories */
3465 @@ -864,6 +874,8 @@ got:
3466  fail:
3467         ext4_std_error(sb, err);
3468  out:
3469 +       DLIMIT_FREE_INODE(inode);
3470 +out_dlimit:
3471         iput(inode);
3472         ret = ERR_PTR(err);
3473  really_out:
3474 @@ -875,6 +887,7 @@ fail_free_drop:
3475  
3476  fail_drop:
3477         DQUOT_DROP(inode);
3478 +       DLIMIT_FREE_INODE(inode);
3479         inode->i_flags |= S_NOQUOTA;
3480         inode->i_nlink = 0;
3481         iput(inode);
3482 diff -NurpP --minimal linux-2.6.27.6/fs/ext4/inode.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/inode.c
3483 --- linux-2.6.27.6/fs/ext4/inode.c      2008-10-13 14:52:05.000000000 +0200
3484 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/inode.c   2008-10-13 14:54:20.000000000 +0200
3485 @@ -36,6 +36,7 @@
3486  #include <linux/mpage.h>
3487  #include <linux/uio.h>
3488  #include <linux/bio.h>
3489 +#include <linux/vs_tag.h>
3490  #include "ext4_jbd2.h"
3491  #include "xattr.h"
3492  #include "acl.h"
3493 @@ -3483,7 +3484,7 @@ static void ext4_free_branches(handle_t 
3494  
3495  int ext4_can_truncate(struct inode *inode)
3496  {
3497 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3498 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3499                 return 0;
3500         if (S_ISREG(inode->i_mode))
3501                 return 1;
3502 @@ -3842,37 +3843,86 @@ void ext4_set_inode_flags(struct inode *
3503  {
3504         unsigned int flags = EXT4_I(inode)->i_flags;
3505  
3506 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3507 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3508 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3509 +
3510 +       if (flags & EXT4_IMMUTABLE_FL)
3511 +               inode->i_flags |= S_IMMUTABLE;
3512 +       if (flags & EXT4_IXUNLINK_FL)
3513 +               inode->i_flags |= S_IXUNLINK;
3514 +
3515         if (flags & EXT4_SYNC_FL)
3516                 inode->i_flags |= S_SYNC;
3517         if (flags & EXT4_APPEND_FL)
3518                 inode->i_flags |= S_APPEND;
3519 -       if (flags & EXT4_IMMUTABLE_FL)
3520 -               inode->i_flags |= S_IMMUTABLE;
3521         if (flags & EXT4_NOATIME_FL)
3522                 inode->i_flags |= S_NOATIME;
3523         if (flags & EXT4_DIRSYNC_FL)
3524                 inode->i_flags |= S_DIRSYNC;
3525 +
3526 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3527 +
3528 +       if (flags & EXT4_BARRIER_FL)
3529 +               inode->i_vflags |= V_BARRIER;
3530 +       if (flags & EXT4_COW_FL)
3531 +               inode->i_vflags |= V_COW;
3532  }
3533  
3534  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3535  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3536  {
3537         unsigned int flags = ei->vfs_inode.i_flags;
3538 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3539 +
3540 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3541 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3542 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3543 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3544 +
3545 +       if (flags & S_IMMUTABLE)
3546 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3547 +       if (flags & S_IXUNLINK)
3548 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3549  
3550 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3551 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3552         if (flags & S_SYNC)
3553                 ei->i_flags |= EXT4_SYNC_FL;
3554         if (flags & S_APPEND)
3555                 ei->i_flags |= EXT4_APPEND_FL;
3556 -       if (flags & S_IMMUTABLE)
3557 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3558         if (flags & S_NOATIME)
3559                 ei->i_flags |= EXT4_NOATIME_FL;
3560         if (flags & S_DIRSYNC)
3561                 ei->i_flags |= EXT4_DIRSYNC_FL;
3562 +
3563 +       if (vflags & V_BARRIER)
3564 +               ei->i_flags |= EXT4_BARRIER_FL;
3565 +       if (vflags & V_COW)
3566 +               ei->i_flags |= EXT4_COW_FL;
3567  }
3568 +
3569 +int ext4_sync_flags(struct inode *inode)
3570 +{
3571 +       struct ext4_iloc iloc;
3572 +       handle_t *handle;
3573 +       int err;
3574 +
3575 +       handle = ext4_journal_start(inode, 1);
3576 +       if (IS_ERR(handle))
3577 +               return PTR_ERR(handle);
3578 +       if (IS_SYNC(inode))
3579 +               handle->h_sync = 1;
3580 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3581 +       if (err)
3582 +               goto flags_err;
3583 +
3584 +       ext4_get_inode_flags(EXT4_I(inode));
3585 +       inode->i_ctime = CURRENT_TIME;
3586 +
3587 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3588 +flags_err:
3589 +       ext4_journal_stop(handle);
3590 +       return err;
3591 +}
3592 +
3593  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3594                                         struct ext4_inode_info *ei)
3595  {
3596 @@ -3905,6 +3955,8 @@ struct inode *ext4_iget(struct super_blo
3597         struct inode *inode;
3598         long ret;
3599         int block;
3600 +       uid_t uid;
3601 +       gid_t gid;
3602  
3603         inode = iget_locked(sb, ino);
3604         if (!inode)
3605 @@ -3925,12 +3977,17 @@ struct inode *ext4_iget(struct super_blo
3606         bh = iloc.bh;
3607         raw_inode = ext4_raw_inode(&iloc);
3608         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3609 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3610 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3611 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3612 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3613         if(!(test_opt (inode->i_sb, NO_UID32))) {
3614 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3615 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3616 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3617 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3618         }
3619 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3620 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3621 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3622 +               le16_to_cpu(raw_inode->i_raw_tag));
3623 +
3624         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3625  
3626         ei->i_state = 0;
3627 @@ -4104,6 +4161,8 @@ static int ext4_do_update_inode(handle_t
3628         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3629         struct ext4_inode_info *ei = EXT4_I(inode);
3630         struct buffer_head *bh = iloc->bh;
3631 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3632 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3633         int err = 0, rc, block;
3634  
3635         /* For fields not not tracking in the in-memory inode,
3636 @@ -4114,29 +4173,32 @@ static int ext4_do_update_inode(handle_t
3637         ext4_get_inode_flags(ei);
3638         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3639         if(!(test_opt(inode->i_sb, NO_UID32))) {
3640 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3641 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3642 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3643 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3644  /*
3645   * Fix up interoperability with old kernels. Otherwise, old inodes get
3646   * re-used with the upper 16 bits of the uid/gid intact
3647   */
3648                 if(!ei->i_dtime) {
3649                         raw_inode->i_uid_high =
3650 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3651 +                               cpu_to_le16(high_16_bits(uid));
3652                         raw_inode->i_gid_high =
3653 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3654 +                               cpu_to_le16(high_16_bits(gid));
3655                 } else {
3656                         raw_inode->i_uid_high = 0;
3657                         raw_inode->i_gid_high = 0;
3658                 }
3659         } else {
3660                 raw_inode->i_uid_low =
3661 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3662 +                       cpu_to_le16(fs_high2lowuid(uid));
3663                 raw_inode->i_gid_low =
3664 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3665 +                       cpu_to_le16(fs_high2lowgid(gid));
3666                 raw_inode->i_uid_high = 0;
3667                 raw_inode->i_gid_high = 0;
3668         }
3669 +#ifdef CONFIG_TAGGING_INTERN
3670 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3671 +#endif
3672         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3673  
3674         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3675 @@ -4300,7 +4362,8 @@ int ext4_setattr(struct dentry *dentry, 
3676                 return error;
3677  
3678         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3679 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3680 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3681 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3682                 handle_t *handle;
3683  
3684                 /* (user+group)*(old+new) structure, inode write (sb,
3685 @@ -4322,6 +4385,8 @@ int ext4_setattr(struct dentry *dentry, 
3686                         inode->i_uid = attr->ia_uid;
3687                 if (attr->ia_valid & ATTR_GID)
3688                         inode->i_gid = attr->ia_gid;
3689 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3690 +                       inode->i_tag = attr->ia_tag;
3691                 error = ext4_mark_inode_dirty(handle, inode);
3692                 ext4_journal_stop(handle);
3693         }
3694 diff -NurpP --minimal linux-2.6.27.6/fs/ext4/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/ioctl.c
3695 --- linux-2.6.27.6/fs/ext4/ioctl.c      2008-07-13 23:51:29.000000000 +0200
3696 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/ioctl.c   2008-10-13 14:54:20.000000000 +0200
3697 @@ -8,12 +8,14 @@
3698   */
3699  
3700  #include <linux/fs.h>
3701 +#include <linux/mount.h>
3702  #include <linux/jbd2.h>
3703  #include <linux/capability.h>
3704  #include <linux/time.h>
3705  #include <linux/compat.h>
3706  #include <linux/smp_lock.h>
3707  #include <linux/mount.h>
3708 +#include <linux/vs_tag.h>
3709  #include <asm/uaccess.h>
3710  #include "ext4_jbd2.h"
3711  #include "ext4.h"
3712 @@ -52,6 +54,11 @@ long ext4_ioctl(struct file *filp, unsig
3713                 if (!S_ISDIR(inode->i_mode))
3714                         flags &= ~EXT4_DIRSYNC_FL;
3715  
3716 +               if (IS_BARRIER(inode)) {
3717 +                       vxwprintk_task(1, "messing with the barrier.");
3718 +                       return -EACCES;
3719 +               }
3720 +
3721                 err = -EPERM;
3722                 mutex_lock(&inode->i_mutex);
3723                 /* Is it quota file? Do not allow user to mess with it */
3724 @@ -69,7 +76,9 @@ long ext4_ioctl(struct file *filp, unsig
3725                  *
3726                  * This test looks nicer. Thanks to Pauline Middelink
3727                  */
3728 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3729 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3730 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3731 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3732                         if (!capable(CAP_LINUX_IMMUTABLE))
3733                                 goto flags_out;
3734                 }
3735 diff -NurpP --minimal linux-2.6.27.6/fs/ext4/namei.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/namei.c
3736 --- linux-2.6.27.6/fs/ext4/namei.c      2008-10-13 14:52:05.000000000 +0200
3737 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/namei.c   2008-10-13 14:54:20.000000000 +0200
3738 @@ -34,6 +34,7 @@
3739  #include <linux/quotaops.h>
3740  #include <linux/buffer_head.h>
3741  #include <linux/bio.h>
3742 +#include <linux/vs_tag.h>
3743  #include "ext4.h"
3744  #include "ext4_jbd2.h"
3745  
3746 @@ -914,6 +915,7 @@ restart:
3747                                 if (bh)
3748                                         ll_rw_block(READ_META, 1, &bh);
3749                         }
3750 +               dx_propagate_tag(nd, inode);
3751                 }
3752                 if ((bh = bh_use[ra_ptr++]) == NULL)
3753                         goto next;
3754 @@ -2461,6 +2463,7 @@ const struct inode_operations ext4_dir_i
3755         .removexattr    = generic_removexattr,
3756  #endif
3757         .permission     = ext4_permission,
3758 +       .sync_flags     = ext4_sync_flags,
3759  };
3760  
3761  const struct inode_operations ext4_special_inode_operations = {
3762 @@ -2472,4 +2475,5 @@ const struct inode_operations ext4_speci
3763         .removexattr    = generic_removexattr,
3764  #endif
3765         .permission     = ext4_permission,
3766 +       .sync_flags     = ext4_sync_flags,
3767  };
3768 diff -NurpP --minimal linux-2.6.27.6/fs/ext4/super.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/super.c
3769 --- linux-2.6.27.6/fs/ext4/super.c      2008-10-13 14:52:05.000000000 +0200
3770 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/super.c   2008-10-13 14:54:20.000000000 +0200
3771 @@ -907,6 +907,7 @@ enum {
3772         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3773         Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
3774         Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3775 +       Opt_tag, Opt_notag, Opt_tagid
3776  };
3777  
3778  static match_table_t tokens = {
3779 @@ -967,6 +968,9 @@ static match_table_t tokens = {
3780         {Opt_resize, "resize"},
3781         {Opt_delalloc, "delalloc"},
3782         {Opt_nodelalloc, "nodelalloc"},
3783 +       {Opt_tag, "tag"},
3784 +       {Opt_notag, "notag"},
3785 +       {Opt_tagid, "tagid=%u"},
3786         {Opt_err, NULL},
3787  };
3788  
3789 @@ -1060,6 +1064,20 @@ static int parse_options(char *options, 
3790                 case Opt_nouid32:
3791                         set_opt(sbi->s_mount_opt, NO_UID32);
3792                         break;
3793 +#ifndef CONFIG_TAGGING_NONE
3794 +               case Opt_tag:
3795 +                       set_opt (sbi->s_mount_opt, TAGGED);
3796 +                       break;
3797 +               case Opt_notag:
3798 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3799 +                       break;
3800 +#endif
3801 +#ifdef CONFIG_PROPAGATE
3802 +               case Opt_tagid:
3803 +                       /* use args[0] */
3804 +                       set_opt (sbi->s_mount_opt, TAGGED);
3805 +                       break;
3806 +#endif
3807                 case Opt_nocheck:
3808                         clear_opt(sbi->s_mount_opt, CHECK);
3809                         break;
3810 @@ -2029,6 +2047,9 @@ static int ext4_fill_super(struct super_
3811                            NULL, 0))
3812                 goto failed_mount;
3813  
3814 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3815 +               sb->s_flags |= MS_TAGGED;
3816 +
3817         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3818                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3819  
3820 @@ -2988,6 +3009,13 @@ static int ext4_remount(struct super_blo
3821         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3822                 ext4_abort(sb, __func__, "Abort forced by user");
3823  
3824 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3825 +               !(sb->s_flags & MS_TAGGED)) {
3826 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3827 +                       sb->s_id);
3828 +               return -EINVAL;
3829 +       }
3830 +
3831         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3832                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3833  
3834 diff -NurpP --minimal linux-2.6.27.6/fs/ext4/symlink.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/symlink.c
3835 --- linux-2.6.27.6/fs/ext4/symlink.c    2008-07-13 23:51:29.000000000 +0200
3836 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/symlink.c 2008-10-13 14:54:20.000000000 +0200
3837 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
3838         .listxattr      = ext4_listxattr,
3839         .removexattr    = generic_removexattr,
3840  #endif
3841 +       .sync_flags     = ext4_sync_flags,
3842  };
3843  
3844  const struct inode_operations ext4_fast_symlink_inode_operations = {
3845 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
3846         .listxattr      = ext4_listxattr,
3847         .removexattr    = generic_removexattr,
3848  #endif
3849 +       .sync_flags     = ext4_sync_flags,
3850  };
3851 diff -NurpP --minimal linux-2.6.27.6/fs/ext4/xattr.c linux-2.6.27.6-vs2.3.0.36/fs/ext4/xattr.c
3852 --- linux-2.6.27.6/fs/ext4/xattr.c      2008-10-13 14:52:05.000000000 +0200
3853 +++ linux-2.6.27.6-vs2.3.0.36/fs/ext4/xattr.c   2008-10-13 14:54:20.000000000 +0200
3854 @@ -56,6 +56,7 @@
3855  #include <linux/mbcache.h>
3856  #include <linux/quotaops.h>
3857  #include <linux/rwsem.h>
3858 +#include <linux/vs_dlimit.h>
3859  #include "ext4_jbd2.h"
3860  #include "ext4.h"
3861  #include "xattr.h"
3862 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3863                 error = ext4_journal_dirty_metadata(handle, bh);
3864                 if (IS_SYNC(inode))
3865                         handle->h_sync = 1;
3866 +                       DLIMIT_FREE_BLOCK(inode, 1);
3867                 DQUOT_FREE_BLOCK(inode, 1);
3868                 ea_bdebug(bh, "refcount now=%d; releasing",
3869                           le32_to_cpu(BHDR(bh)->h_refcount));
3870 @@ -780,11 +782,14 @@ inserted:
3871                         if (new_bh == bs->bh)
3872                                 ea_bdebug(new_bh, "keeping");
3873                         else {
3874 +                               error = -ENOSPC;
3875 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3876 +                                       goto cleanup;
3877                                 /* The old block is released after updating
3878                                    the inode. */
3879                                 error = -EDQUOT;
3880                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3881 -                                       goto cleanup;
3882 +                                       goto cleanup_dlimit;
3883                                 error = ext4_journal_get_write_access(handle,
3884                                                                       new_bh);
3885                                 if (error)
3886 @@ -858,6 +863,8 @@ cleanup:
3887  
3888  cleanup_dquot:
3889         DQUOT_FREE_BLOCK(inode, 1);
3890 +cleanup_dlimit:
3891 +       DLIMIT_FREE_BLOCK(inode, 1);
3892         goto cleanup;
3893  
3894  bad_block:
3895 diff -NurpP --minimal linux-2.6.27.6/fs/fcntl.c linux-2.6.27.6-vs2.3.0.36/fs/fcntl.c
3896 --- linux-2.6.27.6/fs/fcntl.c   2008-10-13 14:52:05.000000000 +0200
3897 +++ linux-2.6.27.6-vs2.3.0.36/fs/fcntl.c        2008-10-24 04:44:48.000000000 +0200
3898 @@ -19,6 +19,7 @@
3899  #include <linux/signal.h>
3900  #include <linux/rcupdate.h>
3901  #include <linux/pid_namespace.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  #include <asm/poll.h>
3905  #include <asm/siginfo.h>
3906 @@ -102,6 +103,8 @@ asmlinkage long sys_dup3(unsigned int ol
3907  
3908         if (tofree)
3909                 filp_close(tofree, files);
3910 +       else
3911 +               vx_openfd_inc(newfd);   /* fd was unused */
3912  
3913         return newfd;
3914  
3915 @@ -335,6 +338,8 @@ asmlinkage long sys_fcntl(unsigned int f
3916         filp = fget(fd);
3917         if (!filp)
3918                 goto out;
3919 +       if (!vx_files_avail(1))
3920 +               goto out;
3921  
3922         err = security_file_fcntl(filp, cmd, arg);
3923         if (err) {
3924 diff -NurpP --minimal linux-2.6.27.6/fs/file.c linux-2.6.27.6-vs2.3.0.36/fs/file.c
3925 --- linux-2.6.27.6/fs/file.c    2008-10-13 14:52:05.000000000 +0200
3926 +++ linux-2.6.27.6-vs2.3.0.36/fs/file.c 2008-10-24 04:44:48.000000000 +0200
3927 @@ -19,6 +19,7 @@
3928  #include <linux/spinlock.h>
3929  #include <linux/rcupdate.h>
3930  #include <linux/workqueue.h>
3931 +#include <linux/vs_limit.h>
3932  
3933  struct fdtable_defer {
3934         spinlock_t lock;
3935 @@ -367,6 +368,8 @@ struct files_struct *dup_fd(struct files
3936                 struct file *f = *old_fds++;
3937                 if (f) {
3938                         get_file(f);
3939 +                       /* TODO: sum it first for check and performance */
3940 +                       vx_openfd_inc(open_files - i);
3941                 } else {
3942                         /*
3943                          * The fd may be claimed in the fd bitmap but not yet
3944 @@ -475,6 +478,7 @@ repeat:
3945         else
3946                 FD_CLR(fd, fdt->close_on_exec);
3947         error = fd;
3948 +       vx_openfd_inc(fd);
3949  #if 1
3950         /* Sanity check */
3951         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3952 diff -NurpP --minimal linux-2.6.27.6/fs/file_table.c linux-2.6.27.6-vs2.3.0.36/fs/file_table.c
3953 --- linux-2.6.27.6/fs/file_table.c      2008-10-13 14:52:05.000000000 +0200
3954 +++ linux-2.6.27.6-vs2.3.0.36/fs/file_table.c   2008-10-13 14:54:20.000000000 +0200
3955 @@ -21,6 +21,8 @@
3956  #include <linux/fsnotify.h>
3957  #include <linux/sysctl.h>
3958  #include <linux/percpu_counter.h>
3959 +#include <linux/vs_limit.h>
3960 +#include <linux/vs_context.h>
3961  
3962  #include <asm/atomic.h>
3963  
3964 @@ -126,6 +128,8 @@ struct file *get_empty_filp(void)
3965         f->f_gid = tsk->fsgid;
3966         eventpoll_init_file(f);
3967         /* f->f_version: 0 */
3968 +       f->f_xid = vx_current_xid();
3969 +       vx_files_inc(f);
3970         return f;
3971  
3972  over:
3973 @@ -276,6 +280,8 @@ void __fput(struct file *file)
3974                 cdev_put(inode->i_cdev);
3975         fops_put(file->f_op);
3976         put_pid(file->f_owner.pid);
3977 +       vx_files_dec(file);
3978 +       file->f_xid = 0;
3979         file_kill(file);
3980         if (file->f_mode & FMODE_WRITE)
3981                 drop_file_write_access(file);
3982 @@ -343,6 +349,8 @@ void put_filp(struct file *file)
3983  {
3984         if (atomic_long_dec_and_test(&file->f_count)) {
3985                 security_file_free(file);
3986 +               vx_files_dec(file);
3987 +               file->f_xid = 0;
3988                 file_kill(file);
3989                 file_free(file);
3990         }
3991 diff -NurpP --minimal linux-2.6.27.6/fs/hfsplus/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/hfsplus/ioctl.c
3992 --- linux-2.6.27.6/fs/hfsplus/ioctl.c   2008-07-13 23:51:29.000000000 +0200
3993 +++ linux-2.6.27.6-vs2.3.0.36/fs/hfsplus/ioctl.c        2008-10-13 14:54:20.000000000 +0200
3994 @@ -17,6 +17,7 @@
3995  #include <linux/mount.h>
3996  #include <linux/sched.h>
3997  #include <linux/xattr.h>
3998 +#include <linux/mount.h>
3999  #include <asm/uaccess.h>
4000  #include "hfsplus_fs.h"
4001  
4002 diff -NurpP --minimal linux-2.6.27.6/fs/inode.c linux-2.6.27.6-vs2.3.0.36/fs/inode.c
4003 --- linux-2.6.27.6/fs/inode.c   2008-10-13 14:52:05.000000000 +0200
4004 +++ linux-2.6.27.6-vs2.3.0.36/fs/inode.c        2008-10-13 14:54:20.000000000 +0200
4005 @@ -124,6 +124,9 @@ static struct inode *alloc_inode(struct 
4006                 struct address_space * const mapping = &inode->i_data;
4007  
4008                 inode->i_sb = sb;
4009 +
4010 +               /* essential because of inode slab reuse */
4011 +               inode->i_tag = 0;
4012                 inode->i_blkbits = sb->s_blocksize_bits;
4013                 inode->i_flags = 0;
4014                 atomic_set(&inode->i_count, 1);
4015 @@ -142,6 +145,7 @@ static struct inode *alloc_inode(struct 
4016                 inode->i_bdev = NULL;
4017                 inode->i_cdev = NULL;
4018                 inode->i_rdev = 0;
4019 +               inode->i_mdev = 0;
4020                 inode->dirtied_when = 0;
4021                 if (security_inode_alloc(inode)) {
4022                         if (inode->i_sb->s_op->destroy_inode)
4023 @@ -247,6 +251,8 @@ void __iget(struct inode * inode)
4024         inodes_stat.nr_unused--;
4025  }
4026  
4027 +EXPORT_SYMBOL_GPL(__iget);
4028 +
4029  /**
4030   * clear_inode - clear an inode
4031   * @inode: inode to clear
4032 @@ -1427,9 +1433,11 @@ void init_special_inode(struct inode *in
4033         if (S_ISCHR(mode)) {
4034                 inode->i_fop = &def_chr_fops;
4035                 inode->i_rdev = rdev;
4036 +               inode->i_mdev = rdev;
4037         } else if (S_ISBLK(mode)) {
4038                 inode->i_fop = &def_blk_fops;
4039                 inode->i_rdev = rdev;
4040 +               inode->i_mdev = rdev;
4041         } else if (S_ISFIFO(mode))
4042                 inode->i_fop = &def_fifo_fops;
4043         else if (S_ISSOCK(mode))
4044 diff -NurpP --minimal linux-2.6.27.6/fs/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/ioctl.c
4045 --- linux-2.6.27.6/fs/ioctl.c   2008-07-13 23:51:29.000000000 +0200
4046 +++ linux-2.6.27.6-vs2.3.0.36/fs/ioctl.c        2008-10-13 14:54:20.000000000 +0200
4047 @@ -13,6 +13,9 @@
4048  #include <linux/security.h>
4049  #include <linux/module.h>
4050  #include <linux/uaccess.h>
4051 +#include <linux/proc_fs.h>
4052 +#include <linux/vserver/inode.h>
4053 +#include <linux/vs_tag.h>
4054  
4055  #include <asm/ioctls.h>
4056  
4057 diff -NurpP --minimal linux-2.6.27.6/fs/ioprio.c linux-2.6.27.6-vs2.3.0.36/fs/ioprio.c
4058 --- linux-2.6.27.6/fs/ioprio.c  2008-10-13 14:52:05.000000000 +0200
4059 +++ linux-2.6.27.6-vs2.3.0.36/fs/ioprio.c       2008-10-13 14:54:20.000000000 +0200
4060 @@ -26,6 +26,7 @@
4061  #include <linux/syscalls.h>
4062  #include <linux/security.h>
4063  #include <linux/pid_namespace.h>
4064 +#include <linux/vs_base.h>
4065  
4066  static int set_task_ioprio(struct task_struct *task, int ioprio)
4067  {
4068 @@ -116,6 +117,8 @@ asmlinkage long sys_ioprio_set(int which
4069                         else
4070                                 pgrp = find_vpid(who);
4071                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4072 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4073 +                                       continue;
4074                                 ret = set_task_ioprio(p, ioprio);
4075                                 if (ret)
4076                                         break;
4077 @@ -205,6 +208,8 @@ asmlinkage long sys_ioprio_get(int which
4078                         else
4079                                 pgrp = find_vpid(who);
4080                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4081 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4082 +                                       continue;
4083                                 tmpio = get_task_ioprio(p);
4084                                 if (tmpio < 0)
4085                                         continue;
4086 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/acl.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/acl.c
4087 --- linux-2.6.27.6/fs/jfs/acl.c 2008-10-13 14:52:05.000000000 +0200
4088 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/acl.c      2008-10-13 14:54:20.000000000 +0200
4089 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
4090                 return rc;
4091  
4092         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4093 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4094 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4095 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4096                 if (DQUOT_TRANSFER(inode, iattr))
4097                         return -EDQUOT;
4098         }
4099 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/file.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/file.c
4100 --- linux-2.6.27.6/fs/jfs/file.c        2008-07-13 23:51:29.000000000 +0200
4101 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/file.c     2008-10-13 14:54:20.000000000 +0200
4102 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4103         .setattr        = jfs_setattr,
4104         .permission     = jfs_permission,
4105  #endif
4106 +       .sync_flags     = jfs_sync_flags,
4107  };
4108  
4109  const struct file_operations jfs_file_operations = {
4110 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/inode.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/inode.c
4111 --- linux-2.6.27.6/fs/jfs/inode.c       2008-07-13 23:51:29.000000000 +0200
4112 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/inode.c    2008-10-13 14:54:20.000000000 +0200
4113 @@ -22,6 +22,7 @@
4114  #include <linux/buffer_head.h>
4115  #include <linux/pagemap.h>
4116  #include <linux/quotaops.h>
4117 +#include <linux/vs_dlimit.h>
4118  #include "jfs_incore.h"
4119  #include "jfs_inode.h"
4120  #include "jfs_filsys.h"
4121 @@ -155,6 +156,7 @@ void jfs_delete_inode(struct inode *inod
4122                 DQUOT_INIT(inode);
4123                 DQUOT_FREE_INODE(inode);
4124                 DQUOT_DROP(inode);
4125 +               DLIMIT_FREE_INODE(inode);
4126         }
4127  
4128         clear_inode(inode);
4129 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/ioctl.c
4130 --- linux-2.6.27.6/fs/jfs/ioctl.c       2008-07-13 23:51:29.000000000 +0200
4131 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/ioctl.c    2008-10-13 14:54:20.000000000 +0200
4132 @@ -11,6 +11,7 @@
4133  #include <linux/mount.h>
4134  #include <linux/time.h>
4135  #include <linux/sched.h>
4136 +#include <linux/mount.h>
4137  #include <asm/current.h>
4138  #include <asm/uaccess.h>
4139  
4140 @@ -85,6 +86,11 @@ long jfs_ioctl(struct file *filp, unsign
4141                 if (!S_ISDIR(inode->i_mode))
4142                         flags &= ~JFS_DIRSYNC_FL;
4143  
4144 +               if (IS_BARRIER(inode)) {
4145 +                       vxwprintk_task(1, "messing with the barrier.");
4146 +                       return -EACCES;
4147 +               }
4148 +
4149                 /* Is it quota file? Do not allow user to mess with it */
4150                 if (IS_NOQUOTA(inode)) {
4151                         err = -EPERM;
4152 @@ -102,8 +108,8 @@ long jfs_ioctl(struct file *filp, unsign
4153                  * the relevant capability.
4154                  */
4155                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4156 -                       ((flags ^ oldflags) &
4157 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4158 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4159 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4160                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4161                                 mutex_unlock(&inode->i_mutex);
4162                                 err = -EPERM;
4163 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_dinode.h linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_dinode.h
4164 --- linux-2.6.27.6/fs/jfs/jfs_dinode.h  2008-07-13 23:51:29.000000000 +0200
4165 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_dinode.h       2008-10-31 18:15:18.000000000 +0100
4166 @@ -161,9 +161,13 @@ struct dinode {
4167  
4168  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4169  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4170 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4171  
4172 -#define JFS_FL_USER_VISIBLE    0x03F80000
4173 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4174 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4175 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4176 +
4177 +#define JFS_FL_USER_VISIBLE    0x07F80000
4178 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4179  #define JFS_FL_INHERIT         0x03C80000
4180  
4181  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4182 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_dtree.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_dtree.c
4183 --- linux-2.6.27.6/fs/jfs/jfs_dtree.c   2008-07-13 23:51:29.000000000 +0200
4184 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_dtree.c        2008-10-13 14:54:20.000000000 +0200
4185 @@ -102,6 +102,7 @@
4186  
4187  #include <linux/fs.h>
4188  #include <linux/quotaops.h>
4189 +#include <linux/vs_dlimit.h>
4190  #include "jfs_incore.h"
4191  #include "jfs_superblock.h"
4192  #include "jfs_filsys.h"
4193 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
4194                  */
4195                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4196                         goto clean_up;
4197 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4198 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4199 -                       goto clean_up;
4200 -               }
4201 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4202 +                       goto clean_up_dquot;
4203 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4204 +                       goto clean_up_dlimit;
4205  
4206                 /*
4207                  * Save the table, we're going to overwrite it with the
4208 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
4209  
4210         return index;
4211  
4212 +      clean_up_dlimit:
4213 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4214 +
4215 +      clean_up_dquot:
4216 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4217 +
4218        clean_up:
4219  
4220         jfs_ip->next_index--;
4221 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
4222         struct tlock *tlck;
4223         struct lv *lv;
4224         int quota_allocation = 0;
4225 +       int dlimit_allocation = 0;
4226  
4227         /* get split page */
4228         smp = split->mp;
4229 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
4230                 }
4231                 quota_allocation += n;
4232  
4233 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4234 +                       rc = -ENOSPC;
4235 +                       goto extendOut;
4236 +               }
4237 +               dlimit_allocation += n;
4238 +
4239                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4240                                     (s64) n, &nxaddr)))
4241                         goto extendOut;
4242 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
4243        freeKeyName:
4244         kfree(key.name);
4245  
4246 +       /* Rollback dlimit allocation */
4247 +       if (rc && dlimit_allocation)
4248 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4249         /* Rollback quota allocation */
4250         if (rc && quota_allocation)
4251                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4252 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4253                 release_metapage(rmp);
4254                 return -EDQUOT;
4255         }
4256 +       /* Allocate blocks to dlimit. */
4257 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4258 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4259 +               release_metapage(rmp);
4260 +               return -ENOSPC;
4261 +       }
4262  
4263         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4264  
4265 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
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         BT_MARK_DIRTY(rmp, ip);
4277         /*
4278 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4279  
4280         xlen = lengthPXD(&fp->header.self);
4281  
4282 +       /* Free dlimit allocation. */
4283 +       DLIMIT_FREE_BLOCK(ip, xlen);
4284         /* Free quota allocation. */
4285         DQUOT_FREE_BLOCK(ip, xlen);
4286  
4287 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4288  
4289                                 xlen = lengthPXD(&p->header.self);
4290  
4291 +                               /* Free dlimit allocation */
4292 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4293                                 /* Free quota allocation */
4294                                 DQUOT_FREE_BLOCK(ip, xlen);
4295  
4296 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_extent.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_extent.c
4297 --- linux-2.6.27.6/fs/jfs/jfs_extent.c  2008-07-13 23:51:29.000000000 +0200
4298 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_extent.c       2008-10-13 14:54:20.000000000 +0200
4299 @@ -18,6 +18,7 @@
4300  
4301  #include <linux/fs.h>
4302  #include <linux/quotaops.h>
4303 +#include <linux/vs_dlimit.h>
4304  #include "jfs_incore.h"
4305  #include "jfs_inode.h"
4306  #include "jfs_superblock.h"
4307 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4308                 return -EDQUOT;
4309         }
4310  
4311 +       /* Allocate blocks to dlimit. */
4312 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4313 +               DQUOT_FREE_BLOCK(ip, nxlen);
4314 +               dbFree(ip, nxaddr, (s64) nxlen);
4315 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4316 +               return -ENOSPC;
4317 +       }
4318 +
4319         /* determine the value of the extent flag */
4320         xflag = abnr ? XAD_NOTRECORDED : 0;
4321  
4322 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4323          */
4324         if (rc) {
4325                 dbFree(ip, nxaddr, nxlen);
4326 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4327                 DQUOT_FREE_BLOCK(ip, nxlen);
4328                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4329                 return (rc);
4330 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4331                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4332                 return -EDQUOT;
4333         }
4334 +       /* Allocate blocks to dlimit. */
4335 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4336 +               DQUOT_FREE_BLOCK(ip, nxlen);
4337 +               dbFree(ip, nxaddr, (s64) nxlen);
4338 +               up(&JFS_IP(ip)->commit_sem);
4339 +               return -ENOSPC;
4340 +       }
4341  
4342         delta = nxlen - xlen;
4343  
4344 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4345                 /* extend the extent */
4346                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4347                         dbFree(ip, xaddr + xlen, delta);
4348 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4349                         DQUOT_FREE_BLOCK(ip, nxlen);
4350                         goto exit;
4351                 }
4352 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4353                  */
4354                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4355                         dbFree(ip, nxaddr, nxlen);
4356 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4357                         DQUOT_FREE_BLOCK(ip, nxlen);
4358                         goto exit;
4359                 }
4360 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_filsys.h linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_filsys.h
4361 --- linux-2.6.27.6/fs/jfs/jfs_filsys.h  2008-07-13 23:51:29.000000000 +0200
4362 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_filsys.h       2008-10-13 14:54:20.000000000 +0200
4363 @@ -263,6 +263,7 @@
4364  #define JFS_NAME_MAX   255
4365  #define JFS_PATH_MAX   BPSIZE
4366  
4367 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4368  
4369  /*
4370   *     file system state (superblock state)
4371 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_imap.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_imap.c
4372 --- linux-2.6.27.6/fs/jfs/jfs_imap.c    2008-10-13 14:52:05.000000000 +0200
4373 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_imap.c 2008-10-13 14:54:20.000000000 +0200
4374 @@ -45,6 +45,7 @@
4375  #include <linux/buffer_head.h>
4376  #include <linux/pagemap.h>
4377  #include <linux/quotaops.h>
4378 +#include <linux/vs_tag.h>
4379  
4380  #include "jfs_incore.h"
4381  #include "jfs_inode.h"
4382 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
4383  {
4384         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4385         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4386 +       uid_t uid;
4387 +       gid_t gid;
4388  
4389         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4390         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4391 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
4392         }
4393         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4394  
4395 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4396 +       uid = le32_to_cpu(dip->di_uid);
4397 +       gid = le32_to_cpu(dip->di_gid);
4398 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4399 +
4400 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4401         if (sbi->uid == -1)
4402                 ip->i_uid = jfs_ip->saved_uid;
4403         else {
4404                 ip->i_uid = sbi->uid;
4405         }
4406  
4407 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4408 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4409         if (sbi->gid == -1)
4410                 ip->i_gid = jfs_ip->saved_gid;
4411         else {
4412 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
4413         dip->di_size = cpu_to_le64(ip->i_size);
4414         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4415         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4416 -       if (sbi->uid == -1)
4417 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4418 -       else
4419 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4420 -       if (sbi->gid == -1)
4421 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4422 -       else
4423 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4424 +
4425 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4426 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4427 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4428 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4429 +
4430         jfs_get_inode_flags(jfs_ip);
4431         /*
4432          * mode2 is only needed for storing the higher order bits.
4433 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_inode.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_inode.c
4434 --- linux-2.6.27.6/fs/jfs/jfs_inode.c   2008-07-13 23:51:29.000000000 +0200
4435 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_inode.c        2008-10-13 14:54:20.000000000 +0200
4436 @@ -18,6 +18,8 @@
4437  
4438  #include <linux/fs.h>
4439  #include <linux/quotaops.h>
4440 +#include <linux/vs_dlimit.h>
4441 +#include <linux/vs_tag.h>
4442  #include "jfs_incore.h"
4443  #include "jfs_inode.h"
4444  #include "jfs_filsys.h"
4445 @@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
4446  {
4447         unsigned int flags = JFS_IP(inode)->mode2;
4448  
4449 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4450 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4451 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4452 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4453  
4454         if (flags & JFS_IMMUTABLE_FL)
4455                 inode->i_flags |= S_IMMUTABLE;
4456 +       if (flags & JFS_IXUNLINK_FL)
4457 +               inode->i_flags |= S_IXUNLINK;
4458 +
4459 +       if (flags & JFS_SYNC_FL)
4460 +               inode->i_flags |= S_SYNC;
4461         if (flags & JFS_APPEND_FL)
4462                 inode->i_flags |= S_APPEND;
4463         if (flags & JFS_NOATIME_FL)
4464                 inode->i_flags |= S_NOATIME;
4465         if (flags & JFS_DIRSYNC_FL)
4466                 inode->i_flags |= S_DIRSYNC;
4467 -       if (flags & JFS_SYNC_FL)
4468 -               inode->i_flags |= S_SYNC;
4469 +
4470 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4471 +
4472 +       if (flags & JFS_BARRIER_FL)
4473 +               inode->i_vflags |= V_BARRIER;
4474 +       if (flags & JFS_COW_FL)
4475 +               inode->i_vflags |= V_COW;
4476  }
4477  
4478  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4479  {
4480         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4481 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4482 +
4483 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4484 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4485 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4486 +                          JFS_BARRIER_FL | JFS_COW_FL);
4487  
4488 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4489 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4490         if (flags & S_IMMUTABLE)
4491                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4492 +       if (flags & S_IXUNLINK)
4493 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4494 +
4495         if (flags & S_APPEND)
4496                 jfs_ip->mode2 |= JFS_APPEND_FL;
4497         if (flags & S_NOATIME)
4498 @@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
4499                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4500         if (flags & S_SYNC)
4501                 jfs_ip->mode2 |= JFS_SYNC_FL;
4502 +
4503 +       if (vflags & V_BARRIER)
4504 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4505 +       if (vflags & V_COW)
4506 +               jfs_ip->mode2 |= JFS_COW_FL;
4507 +}
4508 +
4509 +int jfs_sync_flags(struct inode *inode)
4510 +{
4511 +       jfs_get_inode_flags(JFS_IP(inode));
4512 +       inode->i_ctime = CURRENT_TIME;
4513 +       mark_inode_dirty(inode);
4514 +       return 0;
4515  }
4516  
4517  /*
4518 @@ -108,10 +140,17 @@ struct inode *ialloc(struct inode *paren
4519         jfs_inode->saved_uid = inode->i_uid;
4520         jfs_inode->saved_gid = inode->i_gid;
4521  
4522 +       inode->i_tag = dx_current_fstag(sb);
4523 +       if (DLIMIT_ALLOC_INODE(inode)) {
4524 +               iput(inode);
4525 +               return ERR_PTR(-ENOSPC);
4526 +       }
4527 +
4528         /*
4529          * Allocate inode to quota.
4530          */
4531         if (DQUOT_ALLOC_INODE(inode)) {
4532 +               DLIMIT_FREE_INODE(inode);
4533                 DQUOT_DROP(inode);
4534                 inode->i_flags |= S_NOQUOTA;
4535                 inode->i_nlink = 0;
4536 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_inode.h linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_inode.h
4537 --- linux-2.6.27.6/fs/jfs/jfs_inode.h   2008-07-13 23:51:29.000000000 +0200
4538 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_inode.h        2008-10-13 14:54:20.000000000 +0200
4539 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4540  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4541         int fh_len, int fh_type);
4542  extern void jfs_set_inode_flags(struct inode *);
4543 +extern int jfs_sync_flags(struct inode *);
4544  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4545  
4546  extern const struct address_space_operations jfs_aops;
4547 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/jfs_xtree.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_xtree.c
4548 --- linux-2.6.27.6/fs/jfs/jfs_xtree.c   2008-10-13 14:52:05.000000000 +0200
4549 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/jfs_xtree.c        2008-10-13 14:54:20.000000000 +0200
4550 @@ -23,6 +23,7 @@
4551  #include <linux/module.h>
4552  #include <linux/quotaops.h>
4553  #include <linux/seq_file.h>
4554 +#include <linux/vs_dlimit.h>
4555  #include "jfs_incore.h"
4556  #include "jfs_filsys.h"
4557  #include "jfs_metapage.h"
4558 @@ -848,7 +849,12 @@ int xtInsert(tid_t tid,            /* transaction 
4559                         hint = 0;
4560                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4561                         goto out;
4562 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4563 +                       DQUOT_FREE_BLOCK(ip, xlen);
4564 +                       goto out;
4565 +               }
4566                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4567 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4568                         DQUOT_FREE_BLOCK(ip, xlen);
4569                         goto out;
4570                 }
4571 @@ -878,6 +884,7 @@ int xtInsert(tid_t tid,             /* transaction 
4572                         /* undo data extent allocation */
4573                         if (*xaddrp == 0) {
4574                                 dbFree(ip, xaddr, (s64) xlen);
4575 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4576                                 DQUOT_FREE_BLOCK(ip, xlen);
4577                         }
4578                         return rc;
4579 @@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4580         struct tlock *tlck;
4581         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4582         int quota_allocation = 0;
4583 +       int dlimit_allocation = 0;
4584  
4585         smp = split->mp;
4586         sp = XT_PAGE(ip, smp);
4587 @@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4588  
4589         quota_allocation += lengthPXD(pxd);
4590  
4591 +       /* Allocate blocks to dlimit. */
4592 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4593 +              rc = -ENOSPC;
4594 +              goto clean_up;
4595 +       }
4596 +       dlimit_allocation += lengthPXD(pxd);
4597 +
4598         /*
4599          * allocate the new right page for the split
4600          */
4601 @@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4602  
4603        clean_up:
4604  
4605 +       /* Rollback dlimit allocation. */
4606 +       if (dlimit_allocation)
4607 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4608         /* Rollback quota allocation. */
4609         if (quota_allocation)
4610                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4611 @@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
4612                 release_metapage(rmp);
4613                 return -EDQUOT;
4614         }
4615 +       /* Allocate blocks to dlimit. */
4616 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4617 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4618 +               release_metapage(rmp);
4619 +               return -ENOSPC;
4620 +       }
4621  
4622         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4623  
4624 @@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4625         else
4626                 ip->i_size = newsize;
4627  
4628 +       /* update dlimit allocation to reflect freed blocks */
4629 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4630         /* update quota allocation to reflect freed blocks */
4631         DQUOT_FREE_BLOCK(ip, nfreed);
4632  
4633 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/namei.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/namei.c
4634 --- linux-2.6.27.6/fs/jfs/namei.c       2008-10-13 14:52:05.000000000 +0200
4635 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/namei.c    2008-10-13 14:54:20.000000000 +0200
4636 @@ -21,6 +21,7 @@
4637  #include <linux/ctype.h>
4638  #include <linux/quotaops.h>
4639  #include <linux/exportfs.h>
4640 +#include <linux/vs_tag.h>
4641  #include "jfs_incore.h"
4642  #include "jfs_superblock.h"
4643  #include "jfs_inode.h"
4644 @@ -1468,6 +1469,7 @@ static struct dentry *jfs_lookup(struct 
4645                 return ERR_CAST(ip);
4646         }
4647  
4648 +       dx_propagate_tag(nd, ip);
4649         dentry = d_splice_alias(ip, dentry);
4650  
4651         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4652 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
4653         .setattr        = jfs_setattr,
4654         .permission     = jfs_permission,
4655  #endif
4656 +       .sync_flags     = jfs_sync_flags,
4657  };
4658  
4659  const struct file_operations jfs_dir_operations = {
4660 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/super.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/super.c
4661 --- linux-2.6.27.6/fs/jfs/super.c       2008-10-13 14:52:05.000000000 +0200
4662 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/super.c    2008-10-13 14:54:20.000000000 +0200
4663 @@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
4664  enum {
4665         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4666         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4667 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4668 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4669 +       Opt_tag, Opt_notag, Opt_tagid
4670  };
4671  
4672  static match_table_t tokens = {
4673 @@ -206,6 +207,10 @@ static match_table_t tokens = {
4674         {Opt_resize, "resize=%u"},
4675         {Opt_resize_nosize, "resize"},
4676         {Opt_errors, "errors=%s"},
4677 +       {Opt_tag, "tag"},
4678 +       {Opt_notag, "notag"},
4679 +       {Opt_tagid, "tagid=%u"},
4680 +       {Opt_tag, "tagxid"},
4681         {Opt_ignore, "noquota"},
4682         {Opt_ignore, "quota"},
4683         {Opt_usrquota, "usrquota"},
4684 @@ -340,6 +345,20 @@ static int parse_options(char *options, 
4685                         }
4686                         break;
4687                 }
4688 +#ifndef CONFIG_TAGGING_NONE
4689 +               case Opt_tag:
4690 +                       *flag |= JFS_TAGGED;
4691 +                       break;
4692 +               case Opt_notag:
4693 +                       *flag &= JFS_TAGGED;
4694 +                       break;
4695 +#endif
4696 +#ifdef CONFIG_PROPAGATE
4697 +               case Opt_tagid:
4698 +                       /* use args[0] */
4699 +                       *flag |= JFS_TAGGED;
4700 +                       break;
4701 +#endif
4702                 default:
4703                         printk("jfs: Unrecognized mount option \"%s\" "
4704                                         " or missing value\n", p);
4705 @@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
4706         if (!parse_options(data, sb, &newLVSize, &flag)) {
4707                 return -EINVAL;
4708         }
4709 +
4710 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4711 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4712 +                       sb->s_id);
4713 +               return -EINVAL;
4714 +       }
4715 +
4716         if (newLVSize) {
4717                 if (sb->s_flags & MS_RDONLY) {
4718                         printk(KERN_ERR
4719 @@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
4720  #ifdef CONFIG_JFS_POSIX_ACL
4721         sb->s_flags |= MS_POSIXACL;
4722  #endif
4723 +       /* map mount option tagxid */
4724 +       if (sbi->flag & JFS_TAGGED)
4725 +               sb->s_flags |= MS_TAGGED;
4726  
4727         if (newLVSize) {
4728                 printk(KERN_ERR "resize option for remount only\n");
4729 diff -NurpP --minimal linux-2.6.27.6/fs/jfs/xattr.c linux-2.6.27.6-vs2.3.0.36/fs/jfs/xattr.c
4730 --- linux-2.6.27.6/fs/jfs/xattr.c       2008-07-13 23:51:29.000000000 +0200
4731 +++ linux-2.6.27.6-vs2.3.0.36/fs/jfs/xattr.c    2008-10-13 14:54:20.000000000 +0200
4732 @@ -23,6 +23,7 @@
4733  #include <linux/posix_acl_xattr.h>
4734  #include <linux/quotaops.h>
4735  #include <linux/security.h>
4736 +#include <linux/vs_dlimit.h>
4737  #include "jfs_incore.h"
4738  #include "jfs_superblock.h"
4739  #include "jfs_dmap.h"
4740 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
4741         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
4742                 return -EDQUOT;
4743         }
4744 +       /* Allocate new blocks to dlimit. */
4745 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
4746 +               DQUOT_FREE_BLOCK(ip, nblocks);
4747 +               return -ENOSPC;
4748 +       }
4749  
4750         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
4751         if (rc) {
4752 +               /*Rollback dlimit allocation. */
4753 +               DLIMIT_FREE_BLOCK(ip, nblocks);
4754                 /*Rollback quota allocation. */
4755                 DQUOT_FREE_BLOCK(ip, nblocks);
4756                 return rc;
4757 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
4758  
4759        failed:
4760         /* Rollback quota allocation. */
4761 +       DLIMIT_FREE_BLOCK(ip, nblocks);
4762 +       /* Rollback quota allocation. */
4763         DQUOT_FREE_BLOCK(ip, nblocks);
4764  
4765         dbFree(ip, blkno, nblocks);
4766 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
4767         s64 blkno;
4768         int rc;
4769         int quota_allocation = 0;
4770 +       int dlimit_allocation = 0;
4771  
4772         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
4773         if (ji->ea.flag == 0)
4774 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
4775  
4776                 quota_allocation = blocks_needed;
4777  
4778 +               /* Allocate new blocks to dlimit. */
4779 +               rc = -ENOSPC;
4780 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
4781 +                       goto clean_up;
4782 +               dlimit_allocation = blocks_needed;
4783 +
4784                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
4785                              &blkno);
4786                 if (rc)
4787 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
4788         return ea_size;
4789  
4790        clean_up:
4791 +       /* Rollback dlimit allocation */
4792 +       if (dlimit_allocation)
4793 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
4794         /* Rollback quota allocation */
4795         if (quota_allocation)
4796                 DQUOT_FREE_BLOCK(inode, quota_allocation);
4797 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
4798         }
4799  
4800         /* If old blocks exist, they must be removed from quota allocation. */
4801 -       if (old_blocks)
4802 +       if (old_blocks) {
4803 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
4804                 DQUOT_FREE_BLOCK(inode, old_blocks);
4805 +       }
4806  
4807         inode->i_ctime = CURRENT_TIME;
4808  
4809 diff -NurpP --minimal linux-2.6.27.6/fs/libfs.c linux-2.6.27.6-vs2.3.0.36/fs/libfs.c
4810 --- linux-2.6.27.6/fs/libfs.c   2008-10-13 14:52:05.000000000 +0200
4811 +++ linux-2.6.27.6-vs2.3.0.36/fs/libfs.c        2008-10-13 14:54:20.000000000 +0200
4812 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
4813   * both impossible due to the lock on directory.
4814   */
4815  
4816 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4817 +static inline int do_dcache_readdir_filter(struct file *filp,
4818 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4819  {
4820         struct dentry *dentry = filp->f_path.dentry;
4821         struct dentry *cursor = filp->private_data;
4822 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
4823                                 next = list_entry(p, struct dentry, d_u.d_child);
4824                                 if (d_unhashed(next) || !next->d_inode)
4825                                         continue;
4826 +                               if (filter && !filter(next))
4827 +                                       continue;
4828  
4829                                 spin_unlock(&dcache_lock);
4830                                 if (filldir(dirent, next->d_name.name, 
4831 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
4832         return 0;
4833  }
4834  
4835 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4836 +{
4837 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4838 +}
4839 +
4840 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4841 +       int (*filter)(struct dentry *))
4842 +{
4843 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4844 +}
4845 +
4846 +
4847  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4848  {
4849         return -EISDIR;
4850 @@ -823,6 +838,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4851  EXPORT_SYMBOL(dcache_dir_lseek);
4852  EXPORT_SYMBOL(dcache_dir_open);
4853  EXPORT_SYMBOL(dcache_readdir);
4854 +EXPORT_SYMBOL(dcache_readdir_filter);
4855  EXPORT_SYMBOL(generic_read_dir);
4856  EXPORT_SYMBOL(get_sb_pseudo);
4857  EXPORT_SYMBOL(simple_write_begin);
4858 diff -NurpP --minimal linux-2.6.27.6/fs/locks.c linux-2.6.27.6-vs2.3.0.36/fs/locks.c
4859 --- linux-2.6.27.6/fs/locks.c   2008-10-13 14:52:05.000000000 +0200
4860 +++ linux-2.6.27.6-vs2.3.0.36/fs/locks.c        2008-10-13 14:54:20.000000000 +0200
4861 @@ -127,6 +127,8 @@
4862  #include <linux/time.h>
4863  #include <linux/rcupdate.h>
4864  #include <linux/pid_namespace.h>
4865 +#include <linux/vs_base.h>
4866 +#include <linux/vs_limit.h>
4867  
4868  #include <asm/uaccess.h>
4869  
4870 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4871  /* Allocate an empty lock structure. */
4872  static struct file_lock *locks_alloc_lock(void)
4873  {
4874 +       if (!vx_locks_avail(1))
4875 +               return NULL;
4876         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4877  }
4878  
4879 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
4880         BUG_ON(!list_empty(&fl->fl_block));
4881         BUG_ON(!list_empty(&fl->fl_link));
4882  
4883 +       vx_locks_dec(fl);
4884         locks_release_private(fl);
4885         kmem_cache_free(filelock_cache, fl);
4886  }
4887 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
4888         fl->fl_start = fl->fl_end = 0;
4889         fl->fl_ops = NULL;
4890         fl->fl_lmops = NULL;
4891 +       fl->fl_xid = -1;
4892  }
4893  
4894  EXPORT_SYMBOL(locks_init_lock);
4895 @@ -247,6 +253,7 @@ void locks_copy_lock(struct file_lock *n
4896         new->fl_file = fl->fl_file;
4897         new->fl_ops = fl->fl_ops;
4898         new->fl_lmops = fl->fl_lmops;
4899 +       new->fl_xid = fl->fl_xid;
4900  
4901         locks_copy_private(new, fl);
4902  }
4903 @@ -285,6 +292,11 @@ static int flock_make_lock(struct file *
4904         fl->fl_flags = FL_FLOCK;
4905         fl->fl_type = type;
4906         fl->fl_end = OFFSET_MAX;
4907 +
4908 +       vxd_assert(filp->f_xid == vx_current_xid(),
4909 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4910 +       fl->fl_xid = filp->f_xid;
4911 +       vx_locks_inc(fl);
4912         
4913         *lock = fl;
4914         return 0;
4915 @@ -450,6 +462,7 @@ static int lease_init(struct file *filp,
4916  
4917         fl->fl_owner = current->files;
4918         fl->fl_pid = current->tgid;
4919 +       fl->fl_xid = vx_current_xid();
4920  
4921         fl->fl_file = filp;
4922         fl->fl_flags = FL_LEASE;
4923 @@ -469,6 +482,11 @@ static struct file_lock *lease_alloc(str
4924         if (fl == NULL)
4925                 return ERR_PTR(error);
4926  
4927 +       fl->fl_xid = vx_current_xid();
4928 +       if (filp)
4929 +               vxd_assert(filp->f_xid == fl->fl_xid,
4930 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4931 +       vx_locks_inc(fl);
4932         error = lease_init(filp, type, fl);
4933         if (error) {
4934                 locks_free_lock(fl);
4935 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4936         if (found)
4937                 cond_resched_bkl();
4938  
4939 +       new_fl->fl_xid = -1;
4940  find_conflict:
4941         for_each_lock(inode, before) {
4942                 struct file_lock *fl = *before;
4943 @@ -789,6 +808,7 @@ find_conflict:
4944                 goto out;
4945         locks_copy_lock(new_fl, request);
4946         locks_insert_lock(before, new_fl);
4947 +       vx_locks_inc(new_fl);
4948         new_fl = NULL;
4949         error = 0;
4950  
4951 @@ -799,7 +819,8 @@ out:
4952         return error;
4953  }
4954  
4955 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4956 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4957 +       struct file_lock *conflock, xid_t xid)
4958  {
4959         struct file_lock *fl;
4960         struct file_lock *new_fl = NULL;
4961 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4962         struct file_lock **before;
4963         int error, added = 0;
4964  
4965 +       vxd_assert(xid == vx_current_xid(),
4966 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4967         /*
4968          * We may need two file_lock structures for this operation,
4969          * so we get them in advance to avoid races.
4970 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4971             (request->fl_type != F_UNLCK ||
4972              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4973                 new_fl = locks_alloc_lock();
4974 +               new_fl->fl_xid = xid;
4975 +               vx_locks_inc(new_fl);
4976                 new_fl2 = locks_alloc_lock();
4977 +               new_fl2->fl_xid = xid;
4978 +               vx_locks_inc(new_fl2);
4979         }
4980  
4981         lock_kernel();
4982 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4983  int posix_lock_file(struct file *filp, struct file_lock *fl,
4984                         struct file_lock *conflock)
4985  {
4986 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4987 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4988 +               fl, conflock, filp->f_xid);
4989  }
4990  EXPORT_SYMBOL(posix_lock_file);
4991  
4992 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
4993         fl.fl_end = offset + count - 1;
4994  
4995         for (;;) {
4996 -               error = __posix_lock_file(inode, &fl, NULL);
4997 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4998                 if (error != FILE_LOCK_DEFERRED)
4999                         break;
5000                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
5001 @@ -1423,6 +1451,7 @@ int generic_setlease(struct file *filp, 
5002  
5003         locks_copy_lock(new_fl, lease);
5004         locks_insert_lock(before, new_fl);
5005 +       vx_locks_inc(new_fl);
5006  
5007         *flp = new_fl;
5008         return 0;
5009 @@ -1777,6 +1806,11 @@ int fcntl_setlk(unsigned int fd, struct 
5010         if (file_lock == NULL)
5011                 return -ENOLCK;
5012  
5013 +       vxd_assert(filp->f_xid == vx_current_xid(),
5014 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5015 +       file_lock->fl_xid = filp->f_xid;
5016 +       vx_locks_inc(file_lock);
5017 +
5018         /*
5019          * This might block, so we do it before checking the inode.
5020          */
5021 @@ -1895,6 +1929,11 @@ int fcntl_setlk64(unsigned int fd, struc
5022         if (file_lock == NULL)
5023                 return -ENOLCK;
5024  
5025 +       vxd_assert(filp->f_xid == vx_current_xid(),
5026 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5027 +       file_lock->fl_xid = filp->f_xid;
5028 +       vx_locks_inc(file_lock);
5029 +
5030         /*
5031          * This might block, so we do it before checking the inode.
5032          */
5033 @@ -2159,8 +2198,11 @@ static int locks_show(struct seq_file *f
5034  
5035         lock_get_status(f, fl, (long)f->private, "");
5036  
5037 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
5038 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
5039 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
5040 +                       continue;
5041                 lock_get_status(f, bfl, (long)f->private, " ->");
5042 +       }
5043  
5044         f->private++;
5045         return 0;
5046 diff -NurpP --minimal linux-2.6.27.6/fs/namei.c linux-2.6.27.6-vs2.3.0.36/fs/namei.c
5047 --- linux-2.6.27.6/fs/namei.c   2008-10-13 14:52:05.000000000 +0200
5048 +++ linux-2.6.27.6-vs2.3.0.36/fs/namei.c        2008-11-12 18:45:34.000000000 +0100
5049 @@ -31,6 +31,14 @@
5050  #include <linux/file.h>
5051  #include <linux/fcntl.h>
5052  #include <linux/device_cgroup.h>
5053 +#include <linux/proc_fs.h>
5054 +#include <linux/vserver/inode.h>
5055 +#include <linux/vs_base.h>
5056 +#include <linux/vs_tag.h>
5057 +#include <linux/vs_cowbl.h>
5058 +#include <linux/vs_device.h>
5059 +#include <linux/vs_context.h>
5060 +#include <linux/pid_namespace.h>
5061  #include <asm/uaccess.h>
5062  
5063  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
5064 @@ -167,6 +175,77 @@ void putname(const char *name)
5065  EXPORT_SYMBOL(putname);
5066  #endif
5067  
5068 +static inline int dx_barrier(struct inode *inode)
5069 +{
5070 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
5071 +               vxwprintk_task(1, "did hit the barrier.");
5072 +               return 1;
5073 +       }
5074 +       return 0;
5075 +}
5076 +
5077 +static int __dx_permission(struct inode *inode, int mask)
5078 +{
5079 +       if (dx_barrier(inode))
5080 +               return -EACCES;
5081 +
5082 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5083 +               /* devpts is xid tagged */
5084 +               if (S_ISDIR(inode->i_mode) ||
5085 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
5086 +                       return 0;
5087 +       }
5088 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5089 +               struct proc_dir_entry *de = PDE(inode);
5090 +
5091 +               if (de && !vx_hide_check(0, de->vx_flags))
5092 +                       goto out;
5093 +
5094 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
5095 +                       struct pid *pid;
5096 +                       struct task_struct *tsk;
5097 +
5098 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
5099 +                           vx_flags(VXF_STATE_SETUP, 0))
5100 +                               return 0;
5101 +
5102 +                       pid = PROC_I(inode)->pid;
5103 +                       if (!pid)
5104 +                               goto out;
5105 +
5106 +                       tsk = pid_task(pid, PIDTYPE_PID);
5107 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
5108 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
5109 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
5110 +                               return 0;
5111 +               }
5112 +               else {
5113 +                       /* FIXME: Should we block some entries here? */
5114 +                       return 0;
5115 +               }
5116 +       }
5117 +       else {
5118 +               if (dx_notagcheck(inode->i_sb) ||
5119 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
5120 +                            DX_IDENT))
5121 +                       return 0;
5122 +       }
5123 +
5124 +out:
5125 +       return -EACCES;
5126 +}
5127 +
5128 +int dx_permission(struct inode *inode, int mask)
5129 +{
5130 +       int ret = __dx_permission(inode, mask);
5131 +       if (unlikely(ret)) {
5132 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
5133 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
5134 +                       inode->i_ino);
5135 +       }
5136 +       return ret;
5137 +}
5138 +
5139  
5140  /**
5141   * generic_permission  -  check for access rights on a Posix-like filesystem
5142 @@ -244,10 +323,14 @@ int inode_permission(struct inode *inode
5143                 /*
5144                  * Nobody gets write access to an immutable file.
5145                  */
5146 -               if (IS_IMMUTABLE(inode))
5147 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5148                         return -EACCES;
5149         }
5150  
5151 +       retval = dx_permission(inode, mask);
5152 +       if (retval)
5153 +               return retval;
5154 +
5155         /* Ordinary permission routines do not understand MAY_APPEND. */
5156         if (inode->i_op && inode->i_op->permission) {
5157                 retval = inode->i_op->permission(inode, mask);
5158 @@ -451,6 +534,8 @@ static int exec_permission_lite(struct i
5159  {
5160         umode_t mode = inode->i_mode;
5161  
5162 +       if (dx_barrier(inode))
5163 +               return -EACCES;
5164         if (inode->i_op && inode->i_op->permission)
5165                 return -EAGAIN;
5166  
5167 @@ -773,7 +858,8 @@ static __always_inline void follow_dotdo
5168                 if (nd->path.dentry == fs->root.dentry &&
5169                     nd->path.mnt == fs->root.mnt) {
5170                          read_unlock(&fs->lock);
5171 -                       break;
5172 +                       /* for sane '/' avoid follow_mount() */
5173 +                       return;
5174                 }
5175                  read_unlock(&fs->lock);
5176                 spin_lock(&dcache_lock);
5177 @@ -810,16 +896,30 @@ static int do_lookup(struct nameidata *n
5178  {
5179         struct vfsmount *mnt = nd->path.mnt;
5180         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5181 +       struct inode *inode;
5182  
5183         if (!dentry)
5184                 goto need_lookup;
5185         if (dentry->d_op && dentry->d_op->d_revalidate)
5186                 goto need_revalidate;
5187 +       inode = dentry->d_inode;
5188 +       if (!inode)
5189 +               goto done;
5190 +
5191 +       if (__dx_permission(inode, MAY_ACCESS))
5192 +               goto hidden;
5193 +
5194  done:
5195         path->mnt = mnt;
5196         path->dentry = dentry;
5197         __follow_mount(path);
5198         return 0;
5199 +hidden:
5200 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s«.",
5201 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5202 +               vxd_path(&nd->path));
5203 +       dput(dentry);
5204 +       return -ENOENT;
5205  
5206  need_lookup:
5207         dentry = real_lookup(nd->path.dentry, name, nd);
5208 @@ -1407,7 +1507,7 @@ static int may_delete(struct inode *dir,
5209         if (IS_APPEND(dir))
5210                 return -EPERM;
5211         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5212 -           IS_IMMUTABLE(victim->d_inode))
5213 +               IS_IXORUNLINK(victim->d_inode))
5214                 return -EPERM;
5215         if (isdir) {
5216                 if (!S_ISDIR(victim->d_inode->i_mode))
5217 @@ -1551,6 +1651,14 @@ int may_open(struct nameidata *nd, int a
5218                 flag &= ~O_TRUNC;
5219         }
5220  
5221 +#ifdef CONFIG_VSERVER_COWBL
5222 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5223 +               if (IS_COW_LINK(inode))
5224 +                       return -EMLINK;
5225 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5226 +               mark_inode_dirty(inode);
5227 +       }
5228 +#endif
5229         error = vfs_permission(nd, acc_mode);
5230         if (error)
5231                 return error;
5232 @@ -1677,6 +1785,11 @@ struct file *do_filp_open(int dfd, const
5233         int will_write;
5234         int flag = open_to_namei_flags(open_flag);
5235  
5236 +#ifdef CONFIG_VSERVER_COWBL
5237 +       int rflag = flag;
5238 +       int rmode = mode;
5239 +restart:
5240 +#endif
5241         acc_mode = MAY_OPEN | ACC_MODE(flag);
5242  
5243         /* O_TRUNC implies we need access checks for write permissions */
5244 @@ -1800,6 +1913,25 @@ ok:
5245                         goto exit;
5246         }
5247         error = may_open(&nd, acc_mode, flag);
5248 +#ifdef CONFIG_VSERVER_COWBL
5249 +       if (error == -EMLINK) {
5250 +               struct dentry *dentry;
5251 +               dentry = cow_break_link(pathname);
5252 +               if (IS_ERR(dentry)) {
5253 +                       error = PTR_ERR(dentry);
5254 +                       goto exit_cow;
5255 +               }
5256 +               dput(dentry);
5257 +               if (will_write)
5258 +                       mnt_drop_write(nd.path.mnt);
5259 +               release_open_intent(&nd);
5260 +               path_put(&nd.path);
5261 +               flag = rflag;
5262 +               mode = rmode;
5263 +               goto restart;
5264 +       }
5265 +exit_cow:
5266 +#endif
5267         if (error) {
5268                 if (will_write)
5269                         mnt_drop_write(nd.path.mnt);
5270 @@ -1952,9 +2084,17 @@ int vfs_mknod(struct inode *dir, struct 
5271         if (error)
5272                 return error;
5273  
5274 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5275 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5276 +               goto okay;
5277 +
5278 +       if (!capable(CAP_MKNOD))
5279                 return -EPERM;
5280  
5281 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5282 +               return -EPERM;
5283 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5284 +               return -EPERM;
5285 +okay:
5286         if (!dir->i_op || !dir->i_op->mknod)
5287                 return -EPERM;
5288  
5289 @@ -2395,7 +2535,7 @@ int vfs_link(struct dentry *old_dentry, 
5290         /*
5291          * A link to an append-only or immutable file cannot be created.
5292          */
5293 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5294 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5295                 return -EPERM;
5296         if (!dir->i_op || !dir->i_op->link)
5297                 return -EPERM;
5298 @@ -2756,6 +2896,217 @@ int vfs_follow_link(struct nameidata *nd
5299         return __vfs_follow_link(nd, link);
5300  }
5301  
5302 +
5303 +#ifdef CONFIG_VSERVER_COWBL
5304 +
5305 +#include <linux/file.h>
5306 +
5307 +static inline
5308 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5309 +{
5310 +       loff_t ppos = 0;
5311 +
5312 +       return do_splice_direct(in, &ppos, out, len, 0);
5313 +}
5314 +
5315 +struct dentry *cow_break_link(const char *pathname)
5316 +{
5317 +       int ret, mode, pathlen, redo = 0;
5318 +       struct nameidata old_nd, dir_nd;
5319 +       struct path old_path, new_path;
5320 +       struct dentry *dir, *res = NULL;
5321 +       struct file *old_file;
5322 +       struct file *new_file;
5323 +       char *to, *path, pad='\251';
5324 +       loff_t size;
5325 +
5326 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5327 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5328 +       ret = -ENOMEM;
5329 +       if (!path)
5330 +               goto out;
5331 +
5332 +       /* old_nd will have refs to dentry and mnt */
5333 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5334 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5335 +       if (ret < 0)
5336 +               goto out_free_path;
5337 +
5338 +       old_path = old_nd.path;
5339 +       mode = old_path.dentry->d_inode->i_mode;
5340 +
5341 +       to = d_path(&old_path, path, PATH_MAX-2);
5342 +       pathlen = strlen(to);
5343 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5344 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5345 +               old_path.dentry->d_name.len);
5346 +
5347 +       to[pathlen + 1] = 0;
5348 +retry:
5349 +       to[pathlen] = pad--;
5350 +       ret = -EMLINK;
5351 +       if (pad <= '\240')
5352 +               goto out_rel_old;
5353 +
5354 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5355 +       /* dir_nd will have refs to dentry and mnt */
5356 +       ret = path_lookup(to,
5357 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5358 +       vxdprintk(VXD_CBIT(misc, 2),
5359 +               "path_lookup(new): %d", ret);
5360 +       if (ret < 0)
5361 +               goto retry;
5362 +
5363 +       /* this puppy downs the inode mutex */
5364 +       new_path.dentry = lookup_create(&dir_nd, 0);
5365 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5366 +               vxdprintk(VXD_CBIT(misc, 2),
5367 +                       "lookup_create(new): %p", new_path.dentry);
5368 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5369 +               path_put(&dir_nd.path);
5370 +               goto retry;
5371 +       }
5372 +       vxdprintk(VXD_CBIT(misc, 2),
5373 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5374 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5375 +               new_path.dentry->d_name.len);
5376 +       dir = dir_nd.path.dentry;
5377 +
5378 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5379 +       vxdprintk(VXD_CBIT(misc, 2),
5380 +               "vfs_create(new): %d", ret);
5381 +       if (ret == -EEXIST) {
5382 +               mutex_unlock(&dir->d_inode->i_mutex);
5383 +               dput(new_path.dentry);
5384 +               path_put(&dir_nd.path);
5385 +               goto retry;
5386 +       }
5387 +       else if (ret < 0)
5388 +               goto out_unlock_new;
5389 +
5390 +       /* drop out early, ret passes ENOENT */
5391 +       ret = -ENOENT;
5392 +       if ((redo = d_unhashed(old_path.dentry)))
5393 +               goto out_unlock_new;
5394 +
5395 +       new_path.mnt = dir_nd.path.mnt;
5396 +       dget(old_path.dentry);
5397 +       mntget(old_path.mnt);
5398 +       /* this one cleans up the dentry/mnt in case of failure */
5399 +       old_file = dentry_open(old_path.dentry, old_path.mnt, O_RDONLY);
5400 +       vxdprintk(VXD_CBIT(misc, 2),
5401 +               "dentry_open(old): %p", old_file);
5402 +       if (!old_file || IS_ERR(old_file)) {
5403 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5404 +               goto out_unlock_new;
5405 +       }
5406 +
5407 +       dget(new_path.dentry);
5408 +       mntget(new_path.mnt);
5409 +       /* this one cleans up the dentry/mnt in case of failure */
5410 +       new_file = dentry_open(new_path.dentry, new_path.mnt, O_WRONLY);
5411 +       vxdprintk(VXD_CBIT(misc, 2),
5412 +               "dentry_open(new): %p", new_file);
5413 +
5414 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5415 +       if (!new_file || IS_ERR(new_file))
5416 +               goto out_fput_old;
5417 +
5418 +       size = i_size_read(old_file->f_dentry->d_inode);
5419 +       ret = do_cow_splice(old_file, new_file, size);
5420 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5421 +       if (ret < 0) {
5422 +               goto out_fput_both;
5423 +       } else if (ret < size) {
5424 +               ret = -ENOSPC;
5425 +               goto out_fput_both;
5426 +       } else {
5427 +               struct inode *old_inode = old_path.dentry->d_inode;
5428 +               struct inode *new_inode = new_path.dentry->d_inode;
5429 +               struct iattr attr = {
5430 +                       .ia_uid = old_inode->i_uid,
5431 +                       .ia_gid = old_inode->i_gid,
5432 +                       .ia_valid = ATTR_UID | ATTR_GID
5433 +                       };
5434 +
5435 +               ret = inode_setattr(new_inode, &attr);
5436 +               if (ret)
5437 +                       goto out_fput_both;
5438 +       }
5439 +
5440 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5441 +
5442 +       /* drop out late */
5443 +       ret = -ENOENT;
5444 +       if ((redo = d_unhashed(old_path.dentry)))
5445 +               goto out_unlock;
5446 +
5447 +       vxdprintk(VXD_CBIT(misc, 2),
5448 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5449 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5450 +               new_path.dentry->d_name.len,
5451 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5452 +               old_path.dentry->d_name.len);
5453 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5454 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5455 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5456 +       res = new_path.dentry;
5457 +
5458 +out_unlock:
5459 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5460 +
5461 +out_fput_both:
5462 +       vxdprintk(VXD_CBIT(misc, 3),
5463 +               "fput(new_file=%p[#%ld])", new_file,
5464 +               atomic_read(&new_file->f_count));
5465 +       fput(new_file);
5466 +
5467 +out_fput_old:
5468 +       vxdprintk(VXD_CBIT(misc, 3),
5469 +               "fput(old_file=%p[#%ld])", old_file,
5470 +               atomic_read(&old_file->f_count));
5471 +       fput(old_file);
5472 +
5473 +out_unlock_new:
5474 +       mutex_unlock(&dir->d_inode->i_mutex);
5475 +       if (!ret)
5476 +               goto out_redo;
5477 +
5478 +       /* error path cleanup */
5479 +       vfs_unlink(dir->d_inode, new_path.dentry);
5480 +       dput(new_path.dentry);
5481 +
5482 +out_redo:
5483 +       if (!redo)
5484 +               goto out_rel_both;
5485 +       /* lookup dentry once again */
5486 +       path_put(&old_nd.path);
5487 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5488 +       if (ret)
5489 +               goto out_rel_both;
5490 +
5491 +       new_path.dentry = old_nd.path.dentry;
5492 +       vxdprintk(VXD_CBIT(misc, 2),
5493 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5494 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5495 +               new_path.dentry->d_name.len);
5496 +       dget(new_path.dentry);
5497 +       res = new_path.dentry;
5498 +
5499 +out_rel_both:
5500 +       path_put(&dir_nd.path);
5501 +out_rel_old:
5502 +       path_put(&old_nd.path);
5503 +out_free_path:
5504 +       kfree(path);
5505 +out:
5506 +       if (ret)
5507 +               res = ERR_PTR(ret);
5508 +       return res;
5509 +}
5510 +
5511 +#endif
5512 +
5513  /* get the link contents into pagecache */
5514  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5515  {
5516 diff -NurpP --minimal linux-2.6.27.6/fs/namespace.c linux-2.6.27.6-vs2.3.0.36/fs/namespace.c
5517 --- linux-2.6.27.6/fs/namespace.c       2008-10-13 14:52:05.000000000 +0200
5518 +++ linux-2.6.27.6-vs2.3.0.36/fs/namespace.c    2008-10-24 03:34:52.000000000 +0200
5519 @@ -27,6 +27,11 @@
5520  #include <linux/ramfs.h>
5521  #include <linux/log2.h>
5522  #include <linux/idr.h>
5523 +#include <linux/vs_base.h>
5524 +#include <linux/vs_context.h>
5525 +#include <linux/vs_tag.h>
5526 +#include <linux/vserver/space.h>
5527 +#include <linux/vserver/global.h>
5528  #include <asm/uaccess.h>
5529  #include <asm/unistd.h>
5530  #include "pnode.h"
5531 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5532                 mnt->mnt_root = dget(root);
5533                 mnt->mnt_mountpoint = mnt->mnt_root;
5534                 mnt->mnt_parent = mnt;
5535 +               mnt->mnt_tag = old->mnt_tag;
5536  
5537                 if (flag & CL_SLAVE) {
5538                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5539 @@ -685,6 +691,31 @@ static inline void mangle(struct seq_fil
5540         seq_escape(m, s, " \t\n\\");
5541  }
5542  
5543 +static int mnt_is_reachable(struct vfsmount *mnt)
5544 +{
5545 +       struct path root;
5546 +       struct dentry *point;
5547 +       int ret;
5548 +
5549 +       if (mnt == mnt->mnt_ns->root)
5550 +               return 1;
5551 +
5552 +       spin_lock(&vfsmount_lock);
5553 +       root = current->fs->root;
5554 +       point = root.dentry;
5555 +
5556 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5557 +               point = mnt->mnt_mountpoint;
5558 +               mnt = mnt->mnt_parent;
5559 +       }
5560 +
5561 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5562 +
5563 +       spin_unlock(&vfsmount_lock);
5564 +
5565 +       return ret;
5566 +}
5567 +
5568  /*
5569   * Simple .show_options callback for filesystems which don't want to
5570   * implement more complex mount option showing.
5571 @@ -757,6 +788,8 @@ static int show_sb_opts(struct seq_file 
5572                 { MS_SYNCHRONOUS, ",sync" },
5573                 { MS_DIRSYNC, ",dirsync" },
5574                 { MS_MANDLOCK, ",mand" },
5575 +               { MS_TAGGED, ",tag" },
5576 +               { MS_NOTAGCHECK, ",notagcheck" },
5577                 { 0, NULL }
5578         };
5579         const struct proc_fs_info *fs_infop;
5580 @@ -803,10 +836,20 @@ static int show_vfsmnt(struct seq_file *
5581         int err = 0;
5582         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5583  
5584 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5585 -       seq_putc(m, ' ');
5586 -       seq_path(m, &mnt_path, " \t\n\\");
5587 -       seq_putc(m, ' ');
5588 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5589 +               return SEQ_SKIP;
5590 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5591 +               return SEQ_SKIP;
5592 +
5593 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5594 +               mnt == current->fs->root.mnt) {
5595 +               seq_puts(m, "/dev/root / ");
5596 +       } else {
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 +       }
5602         show_type(m, mnt->mnt_sb);
5603         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5604         err = show_sb_opts(m, mnt->mnt_sb);
5605 @@ -836,6 +879,11 @@ static int show_mountinfo(struct seq_fil
5606         struct path root = p->root;
5607         int err = 0;
5608  
5609 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5610 +               return SEQ_SKIP;
5611 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5612 +               return SEQ_SKIP;
5613 +
5614         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5615                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5616         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5617 @@ -894,17 +942,27 @@ static int show_vfsstat(struct seq_file 
5618         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5619         int err = 0;
5620  
5621 -       /* device */
5622 -       if (mnt->mnt_devname) {
5623 -               seq_puts(m, "device ");
5624 -               mangle(m, mnt->mnt_devname);
5625 -       } else
5626 -               seq_puts(m, "no device");
5627 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5628 +               return SEQ_SKIP;
5629 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5630 +               return SEQ_SKIP;
5631  
5632 -       /* mount point */
5633 -       seq_puts(m, " mounted on ");
5634 -       seq_path(m, &mnt_path, " \t\n\\");
5635 -       seq_putc(m, ' ');
5636 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5637 +               mnt == current->fs->root.mnt) {
5638 +               seq_puts(m, "device /dev/root mounted on / ");
5639 +       } else {
5640 +               /* device */
5641 +               if (mnt->mnt_devname) {
5642 +                       seq_puts(m, "device ");
5643 +                       mangle(m, mnt->mnt_devname);
5644 +               } else
5645 +                       seq_puts(m, "no device");
5646 +
5647 +               /* mount point */
5648 +               seq_puts(m, " mounted on ");
5649 +               seq_path(m, &mnt_path, " \t\n\\");
5650 +               seq_putc(m, ' ');
5651 +       }
5652  
5653         /* file system type */
5654         seq_puts(m, "with fstype ");
5655 @@ -1143,7 +1201,7 @@ asmlinkage long sys_umount(char __user *
5656                 goto dput_and_out;
5657  
5658         retval = -EPERM;
5659 -       if (!capable(CAP_SYS_ADMIN))
5660 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5661                 goto dput_and_out;
5662  
5663         retval = do_umount(path.mnt, flags);
5664 @@ -1169,7 +1227,7 @@ asmlinkage long sys_oldumount(char __use
5665  
5666  static int mount_is_safe(struct nameidata *nd)
5667  {
5668 -       if (capable(CAP_SYS_ADMIN))
5669 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5670                 return 0;
5671         return -EPERM;
5672  #ifdef notyet
5673 @@ -1462,11 +1520,13 @@ static noinline int do_change_type(struc
5674   * noinline this do_mount helper to save do_mount stack space.
5675   */
5676  static noinline int do_loopback(struct nameidata *nd, char *old_name,
5677 -                               int recurse)
5678 +       tag_t tag, unsigned long flags, int mnt_flags)
5679  {
5680         struct nameidata old_nd;
5681         struct vfsmount *mnt = NULL;
5682         int err = mount_is_safe(nd);
5683 +       int recurse = flags & MS_REC;
5684 +
5685         if (err)
5686                 return err;
5687         if (!old_name || !*old_name)
5688 @@ -1500,6 +1560,7 @@ static noinline int do_loopback(struct n
5689                 spin_unlock(&vfsmount_lock);
5690                 release_mounts(&umount_list);
5691         }
5692 +       mnt->mnt_flags = mnt_flags;
5693  
5694  out:
5695         up_write(&namespace_sem);
5696 @@ -1531,12 +1592,12 @@ static int change_mount_flags(struct vfs
5697   * noinline this do_mount helper to save do_mount stack space.
5698   */
5699  static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags,
5700 -                     void *data)
5701 +       void *data, xid_t xid)
5702  {
5703         int err;
5704         struct super_block *sb = nd->path.mnt->mnt_sb;
5705  
5706 -       if (!capable(CAP_SYS_ADMIN))
5707 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5708                 return -EPERM;
5709  
5710         if (!check_mnt(nd->path.mnt))
5711 @@ -1577,7 +1638,7 @@ static noinline int do_move_mount(struct
5712         struct path parent_path;
5713         struct vfsmount *p;
5714         int err = 0;
5715 -       if (!capable(CAP_SYS_ADMIN))
5716 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5717                 return -EPERM;
5718         if (!old_name || !*old_name)
5719                 return -EINVAL;
5720 @@ -1660,7 +1721,7 @@ static noinline int do_new_mount(struct 
5721                 return -EINVAL;
5722  
5723         /* we need capabilities... */
5724 -       if (!capable(CAP_SYS_ADMIN))
5725 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5726                 return -EPERM;
5727  
5728         mnt = do_kern_mount(type, flags, name, data);
5729 @@ -1905,6 +1966,7 @@ long do_mount(char *dev_name, char *dir_
5730         struct nameidata nd;
5731         int retval = 0;
5732         int mnt_flags = 0;
5733 +       tag_t tag = 0;
5734  
5735         /* Discard magic */
5736         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5737 @@ -1920,6 +1982,12 @@ long do_mount(char *dev_name, char *dir_
5738         if (data_page)
5739                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5740  
5741 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5742 +               /* FIXME: bind and re-mounts get the tag flag? */
5743 +               if (flags & (MS_BIND|MS_REMOUNT))
5744 +                       flags |= MS_TAGID;
5745 +       }
5746 +
5747         /* Separate the per-mountpoint flags */
5748         if (flags & MS_NOSUID)
5749                 mnt_flags |= MNT_NOSUID;
5750 @@ -1936,6 +2004,8 @@ long do_mount(char *dev_name, char *dir_
5751         if (flags & MS_RDONLY)
5752                 mnt_flags |= MNT_READONLY;
5753  
5754 +       if (!capable(CAP_SYS_ADMIN))
5755 +               mnt_flags |= MNT_NODEV;
5756         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5757                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5758  
5759 @@ -1951,9 +2021,9 @@ long do_mount(char *dev_name, char *dir_
5760  
5761         if (flags & MS_REMOUNT)
5762                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
5763 -                                   data_page);
5764 +                                   data_page, tag);
5765         else if (flags & MS_BIND)
5766 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
5767 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
5768         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5769                 retval = do_change_type(&nd, flags);
5770         else if (flags & MS_MOVE)
5771 @@ -2022,6 +2092,7 @@ static struct mnt_namespace *dup_mnt_ns(
5772                 q = next_mnt(q, new_ns->root);
5773         }
5774         up_write(&namespace_sem);
5775 +       atomic_inc(&vs_global_mnt_ns);
5776  
5777         if (rootmnt)
5778                 mntput(rootmnt);
5779 @@ -2350,5 +2421,6 @@ void __put_mnt_ns(struct mnt_namespace *
5780         spin_unlock(&vfsmount_lock);
5781         up_write(&namespace_sem);
5782         release_mounts(&umount_list);
5783 +       atomic_dec(&vs_global_mnt_ns);
5784         kfree(ns);
5785  }
5786 diff -NurpP --minimal linux-2.6.27.6/fs/nfs/client.c linux-2.6.27.6-vs2.3.0.36/fs/nfs/client.c
5787 --- linux-2.6.27.6/fs/nfs/client.c      2008-10-13 14:52:05.000000000 +0200
5788 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfs/client.c   2008-10-13 14:54:20.000000000 +0200
5789 @@ -601,6 +601,9 @@ static int nfs_init_server_rpcclient(str
5790         if (server->flags & NFS_MOUNT_SOFT)
5791                 server->client->cl_softrtry = 1;
5792  
5793 +       server->client->cl_tag = 0;
5794 +       if (server->flags & NFS_MOUNT_TAGGED)
5795 +               server->client->cl_tag = 1;
5796         return 0;
5797  }
5798  
5799 @@ -766,6 +769,10 @@ static void nfs_server_set_fsinfo(struct
5800                 server->acdirmin = server->acdirmax = 0;
5801         }
5802  
5803 +       /* FIXME: needs fsinfo
5804 +       if (server->flags & NFS_MOUNT_TAGGED)
5805 +               sb->s_flags |= MS_TAGGED;       */
5806 +
5807         server->maxfilesize = fsinfo->maxfilesize;
5808  
5809         /* We're airborne Set socket buffersize */
5810 diff -NurpP --minimal linux-2.6.27.6/fs/nfs/dir.c linux-2.6.27.6-vs2.3.0.36/fs/nfs/dir.c
5811 --- linux-2.6.27.6/fs/nfs/dir.c 2008-10-13 14:52:05.000000000 +0200
5812 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfs/dir.c      2008-10-13 14:54:20.000000000 +0200
5813 @@ -34,6 +34,7 @@
5814  #include <linux/namei.h>
5815  #include <linux/mount.h>
5816  #include <linux/sched.h>
5817 +#include <linux/vs_tag.h>
5818  
5819  #include "nfs4_fs.h"
5820  #include "delegation.h"
5821 @@ -938,6 +939,7 @@ static struct dentry *nfs_lookup(struct 
5822         if (IS_ERR(res))
5823                 goto out_unblock_sillyrename;
5824  
5825 +       dx_propagate_tag(nd, inode);
5826  no_entry:
5827         res = d_materialise_unique(dentry, inode);
5828         if (res != NULL) {
5829 diff -NurpP --minimal linux-2.6.27.6/fs/nfs/inode.c linux-2.6.27.6-vs2.3.0.36/fs/nfs/inode.c
5830 --- linux-2.6.27.6/fs/nfs/inode.c       2008-10-13 14:52:05.000000000 +0200
5831 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfs/inode.c    2008-10-13 14:54:20.000000000 +0200
5832 @@ -37,6 +37,7 @@
5833  #include <linux/vfs.h>
5834  #include <linux/inet.h>
5835  #include <linux/nfs_xdr.h>
5836 +#include <linux/vs_tag.h>
5837  
5838  #include <asm/system.h>
5839  #include <asm/uaccess.h>
5840 @@ -314,8 +315,10 @@ nfs_fhget(struct super_block *sb, struct
5841                         nfsi->change_attr = fattr->change_attr;
5842                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5843                 inode->i_nlink = fattr->nlink;
5844 -               inode->i_uid = fattr->uid;
5845 -               inode->i_gid = fattr->gid;
5846 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5847 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5848 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5849 +                                        /* maybe fattr->xid someday */
5850                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5851                         /*
5852                          * report the blocks in 512byte units
5853 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5854                         inode->i_uid = attr->ia_uid;
5855                 if ((attr->ia_valid & ATTR_GID) != 0)
5856                         inode->i_gid = attr->ia_gid;
5857 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5858 +                       inode->i_tag = attr->ia_tag;
5859                 spin_lock(&inode->i_lock);
5860                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5861                 spin_unlock(&inode->i_lock);
5862 @@ -900,6 +905,9 @@ static int nfs_check_inode_attributes(st
5863         struct nfs_inode *nfsi = NFS_I(inode);
5864         loff_t cur_size, new_isize;
5865         unsigned long invalid = 0;
5866 +       uid_t uid;
5867 +       gid_t gid;
5868 +       tag_t tag;
5869  
5870  
5871         /* Has the inode gone and changed behind our back? */
5872 @@ -924,10 +932,15 @@ static int nfs_check_inode_attributes(st
5873         if (cur_size != new_isize && nfsi->npages == 0)
5874                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5875  
5876 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5877 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5878 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5879 +
5880         /* Have any file permissions changed? */
5881         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5882 -                       || inode->i_uid != fattr->uid
5883 -                       || inode->i_gid != fattr->gid)
5884 +                       || inode->i_uid != uid
5885 +                       || inode->i_gid != gid
5886 +                       || inode->i_tag != tag)
5887                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5888  
5889         /* Has the link count changed? */
5890 @@ -1048,6 +1061,9 @@ static int nfs_update_inode(struct inode
5891         loff_t cur_isize, new_isize;
5892         unsigned long invalid = 0;
5893         unsigned long now = jiffies;
5894 +       uid_t uid;
5895 +       gid_t gid;
5896 +       tag_t tag;
5897  
5898         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5899                         __func__, inode->i_sb->s_id, inode->i_ino,
5900 @@ -1121,15 +1137,21 @@ static int nfs_update_inode(struct inode
5901         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5902         nfsi->change_attr = fattr->change_attr;
5903  
5904 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5905 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5906 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5907 +
5908         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5909 -           inode->i_uid != fattr->uid ||
5910 -           inode->i_gid != fattr->gid)
5911 +           inode->i_uid != uid ||
5912 +           inode->i_gid != gid ||
5913 +           inode->i_tag != tag)
5914                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5915  
5916         inode->i_mode = fattr->mode;
5917         inode->i_nlink = fattr->nlink;
5918 -       inode->i_uid = fattr->uid;
5919 -       inode->i_gid = fattr->gid;
5920 +       inode->i_uid = uid;
5921 +       inode->i_gid = gid;
5922 +       inode->i_tag = tag;
5923  
5924         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5925                 /*
5926 diff -NurpP --minimal linux-2.6.27.6/fs/nfs/nfs3xdr.c linux-2.6.27.6-vs2.3.0.36/fs/nfs/nfs3xdr.c
5927 --- linux-2.6.27.6/fs/nfs/nfs3xdr.c     2008-07-13 23:51:29.000000000 +0200
5928 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfs/nfs3xdr.c  2008-10-13 14:54:20.000000000 +0200
5929 @@ -22,6 +22,7 @@
5930  #include <linux/nfs3.h>
5931  #include <linux/nfs_fs.h>
5932  #include <linux/nfsacl.h>
5933 +#include <linux/vs_tag.h>
5934  #include "internal.h"
5935  
5936  #define NFSDBG_FACILITY                NFSDBG_XDR
5937 @@ -180,7 +181,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5938  }
5939  
5940  static inline __be32 *
5941 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5942 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5943  {
5944         if (attr->ia_valid & ATTR_MODE) {
5945                 *p++ = xdr_one;
5946 @@ -188,15 +189,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5947         } else {
5948                 *p++ = xdr_zero;
5949         }
5950 -       if (attr->ia_valid & ATTR_UID) {
5951 +       if (attr->ia_valid & ATTR_UID ||
5952 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5953                 *p++ = xdr_one;
5954 -               *p++ = htonl(attr->ia_uid);
5955 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5956         } else {
5957                 *p++ = xdr_zero;
5958         }
5959 -       if (attr->ia_valid & ATTR_GID) {
5960 +       if (attr->ia_valid & ATTR_GID ||
5961 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5962                 *p++ = xdr_one;
5963 -               *p++ = htonl(attr->ia_gid);
5964 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5965         } else {
5966                 *p++ = xdr_zero;
5967         }
5968 @@ -281,7 +284,8 @@ static int
5969  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5970  {
5971         p = xdr_encode_fhandle(p, args->fh);
5972 -       p = xdr_encode_sattr(p, args->sattr);
5973 +       p = xdr_encode_sattr(p, args->sattr,
5974 +               req->rq_task->tk_client->cl_tag);
5975         *p++ = htonl(args->guard);
5976         if (args->guard)
5977                 p = xdr_encode_time3(p, &args->guardtime);
5978 @@ -386,7 +390,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5979                 *p++ = args->verifier[0];
5980                 *p++ = args->verifier[1];
5981         } else
5982 -               p = xdr_encode_sattr(p, args->sattr);
5983 +               p = xdr_encode_sattr(p, args->sattr,
5984 +                       req->rq_task->tk_client->cl_tag);
5985  
5986         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5987         return 0;
5988 @@ -400,7 +405,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5989  {
5990         p = xdr_encode_fhandle(p, args->fh);
5991         p = xdr_encode_array(p, args->name, args->len);
5992 -       p = xdr_encode_sattr(p, args->sattr);
5993 +       p = xdr_encode_sattr(p, args->sattr,
5994 +               req->rq_task->tk_client->cl_tag);
5995         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5996         return 0;
5997  }
5998 @@ -413,7 +419,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5999  {
6000         p = xdr_encode_fhandle(p, args->fromfh);
6001         p = xdr_encode_array(p, args->fromname, args->fromlen);
6002 -       p = xdr_encode_sattr(p, args->sattr);
6003 +       p = xdr_encode_sattr(p, args->sattr,
6004 +               req->rq_task->tk_client->cl_tag);
6005         *p++ = htonl(args->pathlen);
6006         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6007  
6008 @@ -431,7 +438,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6009         p = xdr_encode_fhandle(p, args->fh);
6010         p = xdr_encode_array(p, args->name, args->len);
6011         *p++ = htonl(args->type);
6012 -       p = xdr_encode_sattr(p, args->sattr);
6013 +       p = xdr_encode_sattr(p, args->sattr,
6014 +               req->rq_task->tk_client->cl_tag);
6015         if (args->type == NF3CHR || args->type == NF3BLK) {
6016                 *p++ = htonl(MAJOR(args->rdev));
6017                 *p++ = htonl(MINOR(args->rdev));
6018 diff -NurpP --minimal linux-2.6.27.6/fs/nfs/nfsroot.c linux-2.6.27.6-vs2.3.0.36/fs/nfs/nfsroot.c
6019 --- linux-2.6.27.6/fs/nfs/nfsroot.c     2008-10-13 14:52:05.000000000 +0200
6020 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfs/nfsroot.c  2008-10-13 14:54:20.000000000 +0200
6021 @@ -117,12 +117,12 @@ static int mount_port __initdata = 0;             /
6022  enum {
6023         /* Options that take integer arguments */
6024         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6025 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6026 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6027         /* Options that take no arguments */
6028         Opt_soft, Opt_hard, Opt_intr,
6029         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6030         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6031 -       Opt_acl, Opt_noacl,
6032 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6033         /* Error token */
6034         Opt_err
6035  };
6036 @@ -159,6 +159,9 @@ static match_table_t __initdata tokens =
6037         {Opt_tcp, "tcp"},
6038         {Opt_acl, "acl"},
6039         {Opt_noacl, "noacl"},
6040 +       {Opt_tag, "tag"},
6041 +       {Opt_notag, "notag"},
6042 +       {Opt_tagid, "tagid=%u"},
6043         {Opt_err, NULL}
6044         
6045  };
6046 @@ -270,6 +273,20 @@ static int __init root_nfs_parse(char *n
6047                         case Opt_noacl:
6048                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6049                                 break;
6050 +#ifndef CONFIG_TAGGING_NONE
6051 +                       case Opt_tag:
6052 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6053 +                               break;
6054 +                       case Opt_notag:
6055 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6056 +                               break;
6057 +#endif
6058 +#ifdef CONFIG_PROPAGATE
6059 +                       case Opt_tagid:
6060 +                               /* use args[0] */
6061 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6062 +                               break;
6063 +#endif
6064                         default:
6065                                 printk(KERN_WARNING "Root-NFS: unknown "
6066                                         "option: %s\n", p);
6067 diff -NurpP --minimal linux-2.6.27.6/fs/nfs/super.c linux-2.6.27.6-vs2.3.0.36/fs/nfs/super.c
6068 --- linux-2.6.27.6/fs/nfs/super.c       2008-10-13 14:52:05.000000000 +0200
6069 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfs/super.c    2008-10-13 14:54:20.000000000 +0200
6070 @@ -51,6 +51,7 @@
6071  #include <linux/nfs_xdr.h>
6072  #include <linux/magic.h>
6073  #include <linux/parser.h>
6074 +#include <linux/vs_tag.h>
6075  
6076  #include <asm/system.h>
6077  #include <asm/uaccess.h>
6078 @@ -504,6 +505,7 @@ static void nfs_show_mount_options(struc
6079                 { NFS_MOUNT_NOACL, ",noacl", "" },
6080                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6081                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
6082 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6083                 { 0, NULL, NULL }
6084         };
6085         const struct proc_nfs_info *nfs_infop;
6086 diff -NurpP --minimal linux-2.6.27.6/fs/nfsd/auth.c linux-2.6.27.6-vs2.3.0.36/fs/nfsd/auth.c
6087 --- linux-2.6.27.6/fs/nfsd/auth.c       2008-07-13 23:51:29.000000000 +0200
6088 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfsd/auth.c    2008-10-13 14:54:20.000000000 +0200
6089 @@ -10,6 +10,7 @@
6090  #include <linux/sunrpc/svcauth.h>
6091  #include <linux/nfsd/nfsd.h>
6092  #include <linux/nfsd/export.h>
6093 +#include <linux/vs_tag.h>
6094  #include "auth.h"
6095  
6096  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6097 @@ -55,19 +56,23 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6098                 get_group_info(cred.cr_group_info);
6099  
6100         if (cred.cr_uid != (uid_t) -1)
6101 -               current->fsuid = cred.cr_uid;
6102 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6103         else
6104                 current->fsuid = exp->ex_anon_uid;
6105         if (cred.cr_gid != (gid_t) -1)
6106 -               current->fsgid = cred.cr_gid;
6107 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6108         else
6109                 current->fsgid = exp->ex_anon_gid;
6110  
6111 +       /* this desperately needs a tag :) */
6112 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6113 +
6114         if (!cred.cr_group_info)
6115                 return -ENOMEM;
6116         ret = set_current_groups(cred.cr_group_info);
6117         put_group_info(cred.cr_group_info);
6118 -       if ((cred.cr_uid)) {
6119 +
6120 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
6121                 current->cap_effective =
6122                         cap_drop_nfsd_set(current->cap_effective);
6123         } else {
6124 diff -NurpP --minimal linux-2.6.27.6/fs/nfsd/nfs3xdr.c linux-2.6.27.6-vs2.3.0.36/fs/nfsd/nfs3xdr.c
6125 --- linux-2.6.27.6/fs/nfsd/nfs3xdr.c    2008-07-13 23:51:29.000000000 +0200
6126 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfsd/nfs3xdr.c 2008-10-13 14:54:20.000000000 +0200
6127 @@ -21,6 +21,7 @@
6128  #include <linux/sunrpc/svc.h>
6129  #include <linux/nfsd/nfsd.h>
6130  #include <linux/nfsd/xdr3.h>
6131 +#include <linux/vs_tag.h>
6132  #include "auth.h"
6133  
6134  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6135 @@ -108,6 +109,8 @@ static __be32 *
6136  decode_sattr3(__be32 *p, struct iattr *iap)
6137  {
6138         u32     tmp;
6139 +       uid_t   uid = 0;
6140 +       gid_t   gid = 0;
6141  
6142         iap->ia_valid = 0;
6143  
6144 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6145         }
6146         if (*p++) {
6147                 iap->ia_valid |= ATTR_UID;
6148 -               iap->ia_uid = ntohl(*p++);
6149 +               uid = ntohl(*p++);
6150         }
6151         if (*p++) {
6152                 iap->ia_valid |= ATTR_GID;
6153 -               iap->ia_gid = ntohl(*p++);
6154 +               gid = ntohl(*p++);
6155         }
6156 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6157 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6158 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6159         if (*p++) {
6160                 u64     newsize;
6161  
6162 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6163         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6164         *p++ = htonl((u32) stat->mode);
6165         *p++ = htonl((u32) stat->nlink);
6166 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6167 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6168 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6169 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6170 +               stat->uid, stat->tag)));
6171 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6172 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6173 +               stat->gid, stat->tag)));
6174         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6175                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6176         } else {
6177 diff -NurpP --minimal linux-2.6.27.6/fs/nfsd/nfs4xdr.c linux-2.6.27.6-vs2.3.0.36/fs/nfsd/nfs4xdr.c
6178 --- linux-2.6.27.6/fs/nfsd/nfs4xdr.c    2008-10-13 14:52:06.000000000 +0200
6179 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfsd/nfs4xdr.c 2008-10-13 14:54:20.000000000 +0200
6180 @@ -58,6 +58,7 @@
6181  #include <linux/nfs4_acl.h>
6182  #include <linux/sunrpc/gss_api.h>
6183  #include <linux/sunrpc/svcauth_gss.h>
6184 +#include <linux/vs_tag.h>
6185  
6186  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6187  
6188 @@ -1704,14 +1705,18 @@ out_acl:
6189                 WRITE32(stat.nlink);
6190         }
6191         if (bmval1 & FATTR4_WORD1_OWNER) {
6192 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6193 +               status = nfsd4_encode_user(rqstp,
6194 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6195 +                       stat.uid, stat.tag), &p, &buflen);
6196                 if (status == nfserr_resource)
6197                         goto out_resource;
6198                 if (status)
6199                         goto out;
6200         }
6201         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6202 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6203 +               status = nfsd4_encode_group(rqstp,
6204 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6205 +                       stat.gid, stat.tag), &p, &buflen);
6206                 if (status == nfserr_resource)
6207                         goto out_resource;
6208                 if (status)
6209 diff -NurpP --minimal linux-2.6.27.6/fs/nfsd/nfsxdr.c linux-2.6.27.6-vs2.3.0.36/fs/nfsd/nfsxdr.c
6210 --- linux-2.6.27.6/fs/nfsd/nfsxdr.c     2008-07-13 23:51:29.000000000 +0200
6211 +++ linux-2.6.27.6-vs2.3.0.36/fs/nfsd/nfsxdr.c  2008-10-13 14:54:20.000000000 +0200
6212 @@ -15,6 +15,7 @@
6213  #include <linux/nfsd/nfsd.h>
6214  #include <linux/nfsd/xdr.h>
6215  #include <linux/mm.h>
6216 +#include <linux/vs_tag.h>
6217  #include "auth.h"
6218  
6219  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6220 @@ -98,6 +99,8 @@ static __be32 *
6221  decode_sattr(__be32 *p, struct iattr *iap)
6222  {
6223         u32     tmp, tmp1;
6224 +       uid_t   uid = 0;
6225 +       gid_t   gid = 0;
6226  
6227         iap->ia_valid = 0;
6228  
6229 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6230         }
6231         if ((tmp = ntohl(*p++)) != (u32)-1) {
6232                 iap->ia_valid |= ATTR_UID;
6233 -               iap->ia_uid = tmp;
6234 +               uid = tmp;
6235         }
6236         if ((tmp = ntohl(*p++)) != (u32)-1) {
6237                 iap->ia_valid |= ATTR_GID;
6238 -               iap->ia_gid = tmp;
6239 +               gid = tmp;
6240         }
6241 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6242 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6243 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6244         if ((tmp = ntohl(*p++)) != (u32)-1) {
6245                 iap->ia_valid |= ATTR_SIZE;
6246                 iap->ia_size = tmp;
6247 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6248         *p++ = htonl(nfs_ftypes[type >> 12]);
6249         *p++ = htonl((u32) stat->mode);
6250         *p++ = htonl((u32) stat->nlink);
6251 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6252 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6253 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6254 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6255 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6256 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6257  
6258         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6259                 *p++ = htonl(NFS_MAXPATHLEN);
6260 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/dlm/dlmfs.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/dlm/dlmfs.c
6261 --- linux-2.6.27.6/fs/ocfs2/dlm/dlmfs.c 2008-10-13 14:52:06.000000000 +0200
6262 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/dlm/dlmfs.c      2008-10-13 14:54:20.000000000 +0200
6263 @@ -43,6 +43,7 @@
6264  #include <linux/init.h>
6265  #include <linux/string.h>
6266  #include <linux/backing-dev.h>
6267 +#include <linux/vs_tag.h>
6268  
6269  #include <asm/uaccess.h>
6270  
6271 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6272                 inode->i_mode = mode;
6273                 inode->i_uid = current->fsuid;
6274                 inode->i_gid = current->fsgid;
6275 +               inode->i_tag = dx_current_fstag(sb);
6276                 inode->i_blocks = 0;
6277                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6278                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6279 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6280         inode->i_mode = mode;
6281         inode->i_uid = current->fsuid;
6282         inode->i_gid = current->fsgid;
6283 +       inode->i_tag = dx_current_fstag(sb);
6284         inode->i_blocks = 0;
6285         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6286         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6287 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/dlmglue.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/dlmglue.c
6288 --- linux-2.6.27.6/fs/ocfs2/dlmglue.c   2008-10-13 14:52:06.000000000 +0200
6289 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/dlmglue.c        2008-10-13 14:54:20.000000000 +0200
6290 @@ -1846,6 +1846,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6291         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6292         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6293         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6294 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6295         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6296         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6297         lvb->lvb_iatime_packed  =
6298 @@ -1900,6 +1901,7 @@ static void ocfs2_refresh_inode_from_lvb
6299  
6300         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6301         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6302 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6303         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6304         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6305         ocfs2_unpack_timespec(&inode->i_atime,
6306 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/dlmglue.h linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/dlmglue.h
6307 --- linux-2.6.27.6/fs/ocfs2/dlmglue.h   2008-07-13 23:51:29.000000000 +0200
6308 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/dlmglue.h        2008-10-13 14:54:20.000000000 +0200
6309 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6310         __be16       lvb_inlink;
6311         __be32       lvb_iattr;
6312         __be32       lvb_igeneration;
6313 -       __be32       lvb_reserved2;
6314 +       __be16       lvb_itag;
6315 +       __be16       lvb_reserved2;
6316  };
6317  
6318  /* ocfs2_inode_lock_full() 'arg_flags' flags */
6319 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/file.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/file.c
6320 --- linux-2.6.27.6/fs/ocfs2/file.c      2008-10-13 14:52:06.000000000 +0200
6321 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/file.c   2008-10-13 14:54:20.000000000 +0200
6322 @@ -1058,13 +1058,15 @@ int ocfs2_setattr(struct dentry *dentry,
6323                 mlog(0, "uid change: %d\n", attr->ia_uid);
6324         if (attr->ia_valid & ATTR_GID)
6325                 mlog(0, "gid change: %d\n", attr->ia_gid);
6326 +       if (attr->ia_valid & ATTR_TAG)
6327 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6328         if (attr->ia_valid & ATTR_SIZE)
6329                 mlog(0, "size change...\n");
6330         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6331                 mlog(0, "time change...\n");
6332  
6333  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6334 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6335 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6336         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6337                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6338                 return 0;
6339 @@ -2227,6 +2229,7 @@ const struct inode_operations ocfs2_file
6340         .setattr        = ocfs2_setattr,
6341         .getattr        = ocfs2_getattr,
6342         .permission     = ocfs2_permission,
6343 +       .sync_flags     = ocfs2_sync_flags,
6344         .fallocate      = ocfs2_fallocate,
6345  };
6346  
6347 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/inode.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/inode.c
6348 --- linux-2.6.27.6/fs/ocfs2/inode.c     2008-07-13 23:51:29.000000000 +0200
6349 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/inode.c  2008-10-13 14:54:20.000000000 +0200
6350 @@ -28,6 +28,7 @@
6351  #include <linux/slab.h>
6352  #include <linux/highmem.h>
6353  #include <linux/pagemap.h>
6354 +#include <linux/vs_tag.h>
6355  
6356  #include <asm/byteorder.h>
6357  
6358 @@ -42,6 +43,7 @@
6359  #include "file.h"
6360  #include "heartbeat.h"
6361  #include "inode.h"
6362 +#include "ioctl.h"
6363  #include "journal.h"
6364  #include "namei.h"
6365  #include "suballoc.h"
6366 @@ -74,11 +76,13 @@ void ocfs2_set_inode_flags(struct inode 
6367  {
6368         unsigned int flags = OCFS2_I(inode)->ip_attr;
6369  
6370 -       inode->i_flags &= ~(S_IMMUTABLE |
6371 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6372                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6373  
6374         if (flags & OCFS2_IMMUTABLE_FL)
6375                 inode->i_flags |= S_IMMUTABLE;
6376 +       if (flags & OCFS2_IXUNLINK_FL)
6377 +               inode->i_flags |= S_IXUNLINK;
6378  
6379         if (flags & OCFS2_SYNC_FL)
6380                 inode->i_flags |= S_SYNC;
6381 @@ -88,25 +92,85 @@ void ocfs2_set_inode_flags(struct inode 
6382                 inode->i_flags |= S_NOATIME;
6383         if (flags & OCFS2_DIRSYNC_FL)
6384                 inode->i_flags |= S_DIRSYNC;
6385 +
6386 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6387 +
6388 +       if (flags & OCFS2_BARRIER_FL)
6389 +               inode->i_vflags |= V_BARRIER;
6390 +       if (flags & OCFS2_COW_FL)
6391 +               inode->i_vflags |= V_COW;
6392  }
6393  
6394  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6395  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6396  {
6397         unsigned int flags = oi->vfs_inode.i_flags;
6398 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6399 +
6400 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6401 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6402 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6403 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6404 +
6405 +       if (flags & S_IMMUTABLE)
6406 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6407 +       if (flags & S_IXUNLINK)
6408 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6409  
6410 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6411 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6412         if (flags & S_SYNC)
6413                 oi->ip_attr |= OCFS2_SYNC_FL;
6414         if (flags & S_APPEND)
6415                 oi->ip_attr |= OCFS2_APPEND_FL;
6416 -       if (flags & S_IMMUTABLE)
6417 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6418         if (flags & S_NOATIME)
6419                 oi->ip_attr |= OCFS2_NOATIME_FL;
6420         if (flags & S_DIRSYNC)
6421                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6422 +
6423 +       if (vflags & V_BARRIER)
6424 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6425 +       if (vflags & V_COW)
6426 +               oi->ip_attr |= OCFS2_COW_FL;
6427 +}
6428 +
6429 +int ocfs2_sync_flags(struct inode *inode)
6430 +{
6431 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6432 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6433 +       handle_t *handle = NULL;
6434 +       struct buffer_head *bh = NULL;
6435 +       int status;
6436 +
6437 +       status = ocfs2_inode_lock(inode, &bh, 1);
6438 +       if (status < 0) {
6439 +               mlog_errno(status);
6440 +               goto bail;
6441 +       }
6442 +
6443 +       status = -EROFS;
6444 +       if (IS_RDONLY(inode))
6445 +               goto bail_unlock;
6446 +
6447 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6448 +       if (IS_ERR(handle)) {
6449 +               status = PTR_ERR(handle);
6450 +               mlog_errno(status);
6451 +               goto bail_unlock;
6452 +       }
6453 +
6454 +       ocfs2_get_inode_flags(ocfs2_inode);
6455 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6456 +       if (status < 0)
6457 +               mlog_errno(status);
6458 +
6459 +       ocfs2_commit_trans(osb, handle);
6460 +bail_unlock:
6461 +       ocfs2_inode_unlock(inode, 1);
6462 +bail:
6463 +       if (bh)
6464 +               brelse(bh);
6465 +
6466 +       mlog_exit(status);
6467 +       return status;
6468  }
6469  
6470  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6471 @@ -219,6 +283,8 @@ int ocfs2_populate_inode(struct inode *i
6472         struct super_block *sb;
6473         struct ocfs2_super *osb;
6474         int status = -EINVAL;
6475 +       uid_t uid;
6476 +       gid_t gid;
6477  
6478         mlog_entry("(0x%p, size:%llu)\n", inode,
6479                    (unsigned long long)le64_to_cpu(fe->i_size));
6480 @@ -254,8 +320,12 @@ int ocfs2_populate_inode(struct inode *i
6481         inode->i_generation = le32_to_cpu(fe->i_generation);
6482         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6483         inode->i_mode = le16_to_cpu(fe->i_mode);
6484 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6485 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6486 +       uid = le32_to_cpu(fe->i_uid);
6487 +       gid = le32_to_cpu(fe->i_gid);
6488 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6489 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6490 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6491 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6492  
6493         /* Fast symlinks will have i_size but no allocated clusters. */
6494         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6495 @@ -1230,8 +1300,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6496  
6497         fe->i_size = cpu_to_le64(i_size_read(inode));
6498         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6499 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6500 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6501 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6502 +               inode->i_uid, inode->i_tag));
6503 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6504 +               inode->i_gid, inode->i_tag));
6505 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6506         fe->i_mode = cpu_to_le16(inode->i_mode);
6507         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6508         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6509 @@ -1259,16 +1332,25 @@ leave:
6510  void ocfs2_refresh_inode(struct inode *inode,
6511                          struct ocfs2_dinode *fe)
6512  {
6513 +       uid_t uid;
6514 +       gid_t gid;
6515 +
6516         spin_lock(&OCFS2_I(inode)->ip_lock);
6517  
6518         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6519         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6520 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6521 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6522         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6523         ocfs2_set_inode_flags(inode);
6524         i_size_write(inode, le64_to_cpu(fe->i_size));
6525         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6526 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6527 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6528 +       uid = le32_to_cpu(fe->i_uid);
6529 +       gid = le32_to_cpu(fe->i_gid);
6530 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6531 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6532 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6533 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6534         inode->i_mode = le16_to_cpu(fe->i_mode);
6535         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6536                 inode->i_blocks = 0;
6537 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/inode.h linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/inode.h
6538 --- linux-2.6.27.6/fs/ocfs2/inode.h     2008-07-13 23:51:29.000000000 +0200
6539 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/inode.h  2008-10-13 14:54:20.000000000 +0200
6540 @@ -143,6 +143,7 @@ int ocfs2_aio_write(struct file *file, s
6541  
6542  void ocfs2_set_inode_flags(struct inode *inode);
6543  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6544 +int ocfs2_sync_flags(struct inode *inode);
6545  
6546  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6547  {
6548 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ioctl.c
6549 --- linux-2.6.27.6/fs/ocfs2/ioctl.c     2008-07-13 23:51:29.000000000 +0200
6550 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ioctl.c  2008-10-13 14:54:20.000000000 +0200
6551 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6552         return status;
6553  }
6554  
6555 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6556 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6557                                 unsigned mask)
6558  {
6559         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6560 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6561         if (!S_ISDIR(inode->i_mode))
6562                 flags &= ~OCFS2_DIRSYNC_FL;
6563  
6564 +       if (IS_BARRIER(inode)) {
6565 +               vxwprintk_task(1, "messing with the barrier.");
6566 +               goto bail_unlock;
6567 +       }
6568 +
6569         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6570         if (IS_ERR(handle)) {
6571                 status = PTR_ERR(handle);
6572 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/ioctl.h linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ioctl.h
6573 --- linux-2.6.27.6/fs/ocfs2/ioctl.h     2008-07-13 23:51:29.000000000 +0200
6574 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ioctl.h  2008-10-13 14:54:20.000000000 +0200
6575 @@ -10,6 +10,9 @@
6576  #ifndef OCFS2_IOCTL_H
6577  #define OCFS2_IOCTL_H
6578  
6579 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6580 +                               unsigned mask);
6581 +
6582  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6583  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6584  
6585 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/namei.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/namei.c
6586 --- linux-2.6.27.6/fs/ocfs2/namei.c     2008-07-13 23:51:29.000000000 +0200
6587 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/namei.c  2008-10-13 14:54:20.000000000 +0200
6588 @@ -40,6 +40,7 @@
6589  #include <linux/types.h>
6590  #include <linux/slab.h>
6591  #include <linux/highmem.h>
6592 +#include <linux/vs_tag.h>
6593  
6594  #define MLOG_MASK_PREFIX ML_NAMEI
6595  #include <cluster/masklog.h>
6596 @@ -366,6 +367,9 @@ static int ocfs2_mknod_locked(struct ocf
6597         u64 fe_blkno = 0;
6598         u16 suballoc_bit;
6599         struct inode *inode = NULL;
6600 +       uid_t uid;
6601 +       gid_t gid;
6602 +       tag_t tag;
6603  
6604         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
6605                    (unsigned long)dev, dentry->d_name.len,
6606 @@ -425,13 +429,19 @@ static int ocfs2_mknod_locked(struct ocf
6607         fe->i_blkno = cpu_to_le64(fe_blkno);
6608         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6609         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6610 -       fe->i_uid = cpu_to_le32(current->fsuid);
6611 +
6612 +       tag = dx_current_fstag(osb->sb);
6613 +       uid = current->fsuid;
6614         if (dir->i_mode & S_ISGID) {
6615 -               fe->i_gid = cpu_to_le32(dir->i_gid);
6616 +               gid = dir->i_gid;
6617                 if (S_ISDIR(mode))
6618                         mode |= S_ISGID;
6619         } else
6620 -               fe->i_gid = cpu_to_le32(current->fsgid);
6621 +               gid = current->fsgid;
6622 +
6623 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
6624 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
6625 +       inode->i_tag = tag;
6626         fe->i_mode = cpu_to_le16(mode);
6627         if (S_ISCHR(mode) || S_ISBLK(mode))
6628                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6629 @@ -1917,5 +1927,6 @@ const struct inode_operations ocfs2_dir_
6630         .rename         = ocfs2_rename,
6631         .setattr        = ocfs2_setattr,
6632         .getattr        = ocfs2_getattr,
6633 +       .sync_flags     = ocfs2_sync_flags,
6634         .permission     = ocfs2_permission,
6635  };
6636 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/ocfs2_fs.h linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ocfs2_fs.h
6637 --- linux-2.6.27.6/fs/ocfs2/ocfs2_fs.h  2008-10-13 14:52:06.000000000 +0200
6638 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ocfs2_fs.h       2008-10-13 14:54:20.000000000 +0200
6639 @@ -195,18 +195,23 @@
6640  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6641  
6642  /* Inode attributes, keep in sync with EXT2 */
6643 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6644 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6645 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6646 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6647 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6648 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6649 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6650 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6651 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6652 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6653 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6654 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6655 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6656 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6657 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6658 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6659 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6660  
6661 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6662 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6663 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6664 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6665 +
6666 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6667 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6668 +
6669 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6670 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6671  
6672  /*
6673   * Extent record flags (e_node.leaf.flags)
6674 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/ocfs2.h linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ocfs2.h
6675 --- linux-2.6.27.6/fs/ocfs2/ocfs2.h     2008-10-13 14:52:06.000000000 +0200
6676 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/ocfs2.h  2008-10-13 14:54:20.000000000 +0200
6677 @@ -184,6 +184,7 @@ enum ocfs2_mount_options
6678         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
6679         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
6680         OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
6681 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
6682  };
6683  
6684  #define OCFS2_OSB_SOFT_RO      0x0001
6685 diff -NurpP --minimal linux-2.6.27.6/fs/ocfs2/super.c linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/super.c
6686 --- linux-2.6.27.6/fs/ocfs2/super.c     2008-10-13 14:52:06.000000000 +0200
6687 +++ linux-2.6.27.6-vs2.3.0.36/fs/ocfs2/super.c  2008-10-13 14:54:20.000000000 +0200
6688 @@ -154,6 +154,7 @@ enum {
6689         Opt_localalloc,
6690         Opt_localflocks,
6691         Opt_stack,
6692 +       Opt_tag, Opt_notag, Opt_tagid,
6693         Opt_err,
6694  };
6695  
6696 @@ -173,6 +174,9 @@ static match_table_t tokens = {
6697         {Opt_localalloc, "localalloc=%d"},
6698         {Opt_localflocks, "localflocks"},
6699         {Opt_stack, "cluster_stack=%s"},
6700 +       {Opt_tag, "tag"},
6701 +       {Opt_notag, "notag"},
6702 +       {Opt_tagid, "tagid=%u"},
6703         {Opt_err, NULL}
6704  };
6705  
6706 @@ -392,6 +396,13 @@ static int ocfs2_remount(struct super_bl
6707                 goto out;
6708         }
6709  
6710 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6711 +               !(sb->s_flags & MS_TAGGED)) {
6712 +               ret = -EINVAL;
6713 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6714 +               goto out;
6715 +       }
6716 +
6717         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6718             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6719                 ret = -EINVAL;
6720 @@ -725,6 +736,9 @@ static int ocfs2_fill_super(struct super
6721  
6722         ocfs2_complete_mount_recovery(osb);
6723  
6724 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6725 +               sb->s_flags |= MS_TAGGED;
6726 +
6727         if (ocfs2_mount_local(osb))
6728                 snprintf(nodestr, sizeof(nodestr), "local");
6729         else
6730 @@ -918,6 +932,20 @@ static int ocfs2_parse_options(struct su
6731                                OCFS2_STACK_LABEL_LEN);
6732                         mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
6733                         break;
6734 +#ifndef CONFIG_TAGGING_NONE
6735 +               case Opt_tag:
6736 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6737 +                       break;
6738 +               case Opt_notag:
6739 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6740 +                       break;
6741 +#endif
6742 +#ifdef CONFIG_PROPAGATE
6743 +               case Opt_tagid:
6744 +                       /* use args[0] */
6745 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6746 +                       break;
6747 +#endif
6748                 default:
6749                         mlog(ML_ERROR,
6750                              "Unrecognized mount option \"%s\" "
6751 diff -NurpP --minimal linux-2.6.27.6/fs/open.c linux-2.6.27.6-vs2.3.0.36/fs/open.c
6752 --- linux-2.6.27.6/fs/open.c    2008-10-13 14:52:06.000000000 +0200
6753 +++ linux-2.6.27.6-vs2.3.0.36/fs/open.c 2008-10-13 14:54:20.000000000 +0200
6754 @@ -29,22 +29,31 @@
6755  #include <linux/rcupdate.h>
6756  #include <linux/audit.h>
6757  #include <linux/falloc.h>
6758 +#include <linux/vs_base.h>
6759 +#include <linux/vs_limit.h>
6760 +#include <linux/vs_dlimit.h>
6761 +#include <linux/vs_tag.h>
6762 +#include <linux/vs_cowbl.h>
6763  
6764  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6765  {
6766         int retval = -ENODEV;
6767  
6768         if (dentry) {
6769 +               struct super_block *sb = dentry->d_sb;
6770 +
6771                 retval = -ENOSYS;
6772 -               if (dentry->d_sb->s_op->statfs) {
6773 +               if (sb->s_op->statfs) {
6774                         memset(buf, 0, sizeof(*buf));
6775                         retval = security_sb_statfs(dentry);
6776                         if (retval)
6777                                 return retval;
6778 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6779 +                       retval = sb->s_op->statfs(dentry, buf);
6780                         if (retval == 0 && buf->f_frsize == 0)
6781                                 buf->f_frsize = buf->f_bsize;
6782                 }
6783 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6784 +                       vx_vsi_statfs(sb, buf);
6785         }
6786         return retval;
6787  }
6788 @@ -625,6 +634,10 @@ asmlinkage long sys_fchmodat(int dfd, co
6789         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6790         if (error)
6791                 goto out;
6792 +
6793 +       error = cow_check_and_break(&path);
6794 +       if (error)
6795 +               goto dput_and_out;
6796         inode = path.dentry->d_inode;
6797  
6798         error = mnt_want_write(path.mnt);
6799 @@ -658,11 +671,11 @@ static int chown_common(struct dentry * 
6800         newattrs.ia_valid =  ATTR_CTIME;
6801         if (user != (uid_t) -1) {
6802                 newattrs.ia_valid |= ATTR_UID;
6803 -               newattrs.ia_uid = user;
6804 +               newattrs.ia_uid = dx_map_uid(user);
6805         }
6806         if (group != (gid_t) -1) {
6807                 newattrs.ia_valid |= ATTR_GID;
6808 -               newattrs.ia_gid = group;
6809 +               newattrs.ia_gid = dx_map_gid(group);
6810         }
6811         if (!S_ISDIR(inode->i_mode))
6812                 newattrs.ia_valid |=
6813 @@ -685,7 +698,11 @@ asmlinkage long sys_chown(const char __u
6814         error = mnt_want_write(path.mnt);
6815         if (error)
6816                 goto out_release;
6817 -       error = chown_common(path.dentry, user, group);
6818 +#ifdef CONFIG_VSERVER_COWBL
6819 +       error = cow_check_and_break(&path);
6820 +       if (!error)
6821 +#endif
6822 +               error = chown_common(path.dentry, user, group);
6823         mnt_drop_write(path.mnt);
6824  out_release:
6825         path_put(&path);
6826 @@ -710,7 +727,11 @@ asmlinkage long sys_fchownat(int dfd, co
6827         error = mnt_want_write(path.mnt);
6828         if (error)
6829                 goto out_release;
6830 -       error = chown_common(path.dentry, user, group);
6831 +#ifdef CONFIG_VSERVER_COWBL
6832 +       error = cow_check_and_break(&path);
6833 +       if (!error)
6834 +#endif
6835 +               error = chown_common(path.dentry, user, group);
6836         mnt_drop_write(path.mnt);
6837  out_release:
6838         path_put(&path);
6839 @@ -729,7 +750,11 @@ asmlinkage long sys_lchown(const char __
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 @@ -969,6 +994,7 @@ static void __put_unused_fd(struct files
6853         __FD_CLR(fd, fdt->open_fds);
6854         if (fd < files->next_fd)
6855                 files->next_fd = fd;
6856 +       vx_openfd_dec(fd);
6857  }
6858  
6859  void put_unused_fd(unsigned int fd)
6860 diff -NurpP --minimal linux-2.6.27.6/fs/proc/array.c linux-2.6.27.6-vs2.3.0.36/fs/proc/array.c
6861 --- linux-2.6.27.6/fs/proc/array.c      2008-10-13 14:52:06.000000000 +0200
6862 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/array.c   2008-10-13 14:54:20.000000000 +0200
6863 @@ -81,6 +81,8 @@
6864  #include <linux/seq_file.h>
6865  #include <linux/pid_namespace.h>
6866  #include <linux/tracehook.h>
6867 +#include <linux/vs_context.h>
6868 +#include <linux/vs_network.h>
6869  
6870  #include <asm/pgtable.h>
6871  #include <asm/processor.h>
6872 @@ -142,8 +144,9 @@ static const char *task_state_array[] = 
6873         "D (disk sleep)",       /*  2 */
6874         "T (stopped)",          /*  4 */
6875         "T (tracing stop)",     /*  8 */
6876 -       "Z (zombie)",           /* 16 */
6877 -       "X (dead)"              /* 32 */
6878 +       "H (on hold)",          /* 16 */
6879 +       "Z (zombie)",           /* 32 */
6880 +       "X (dead)",             /* 64 */
6881  };
6882  
6883  static inline const char *get_task_state(struct task_struct *tsk)
6884 @@ -164,6 +167,7 @@ static inline void task_state(struct seq
6885         struct group_info *group_info;
6886         int g;
6887         struct fdtable *fdt = NULL;
6888 +/* +   pid_t pid, ptgid, tppid, tgid; */
6889         pid_t ppid, tpid;
6890  
6891         rcu_read_lock();
6892 @@ -175,6 +179,12 @@ static inline void task_state(struct seq
6893                 if (tracer)
6894                         tpid = task_pid_nr_ns(tracer, ns);
6895         }
6896 +/*     tgid = vx_map_tgid(p->tgid);
6897 +       pid = vx_map_pid(p->pid);
6898 +       ptgid = vx_map_pid(pid_alive(p) ?
6899 +               rcu_dereference(p->real_parent)->tgid : 0);
6900 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
6901 +               rcu_dereference(p->parent)->pid : 0); */
6902         seq_printf(m,
6903                 "State:\t%s\n"
6904                 "Tgid:\t%d\n"
6905 @@ -286,7 +296,7 @@ static inline void task_sig(struct seq_f
6906  }
6907  
6908  static void render_cap_t(struct seq_file *m, const char *header,
6909 -                       kernel_cap_t *a)
6910 +                       struct vx_info *vxi, kernel_cap_t *a)
6911  {
6912         unsigned __capi;
6913  
6914 @@ -300,10 +310,10 @@ static void render_cap_t(struct seq_file
6915  
6916  static inline void task_cap(struct seq_file *m, struct task_struct *p)
6917  {
6918 -       render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
6919 -       render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
6920 -       render_cap_t(m, "CapEff:\t", &p->cap_effective);
6921 -       render_cap_t(m, "CapBnd:\t", &p->cap_bset);
6922 +       render_cap_t(m, "CapInh:\t", p->vx_info, &p->cap_inheritable);
6923 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &p->cap_permitted);
6924 +       render_cap_t(m, "CapEff:\t", p->vx_info, &p->cap_effective);
6925 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &p->cap_bset);
6926  }
6927  
6928  static inline void task_context_switch_counts(struct seq_file *m,
6929 @@ -315,6 +325,45 @@ static inline void task_context_switch_c
6930                         p->nivcsw);
6931  }
6932  
6933 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6934 +                       struct pid *pid, struct task_struct *task)
6935 +{
6936 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6937 +                       "Count:\t%u\n"
6938 +                       "uts:\t%p(%c)\n"
6939 +                       "ipc:\t%p(%c)\n"
6940 +                       "mnt:\t%p(%c)\n"
6941 +                       "pid:\t%p(%c)\n"
6942 +                       "user:\t%p(%c)\n"
6943 +                       "net:\t%p(%c)\n",
6944 +                       task->nsproxy,
6945 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6946 +                       atomic_read(&task->nsproxy->count),
6947 +                       task->nsproxy->uts_ns,
6948 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6949 +                       task->nsproxy->ipc_ns,
6950 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6951 +                       task->nsproxy->mnt_ns,
6952 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6953 +                       task->nsproxy->pid_ns,
6954 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6955 +                       task->nsproxy->user_ns,
6956 +                       (task->nsproxy->user_ns == init_task.nsproxy->user_ns ? 'I' : '-'),
6957 +                       task->nsproxy->net_ns,
6958 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6959 +       return 0;
6960 +}
6961 +
6962 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6963 +{
6964 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6965 +               return;
6966 +
6967 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6968 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6969 +}
6970 +
6971 +
6972  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6973                         struct pid *pid, struct task_struct *task)
6974  {
6975 @@ -330,6 +379,7 @@ int proc_pid_status(struct seq_file *m, 
6976         task_sig(m, task);
6977         task_cap(m, task);
6978         cpuset_task_status_allowed(m, task);
6979 +       task_vs_id(m, task);
6980  #if defined(CONFIG_S390)
6981         task_show_regs(m, task);
6982  #endif
6983 @@ -442,6 +492,17 @@ static int do_task_stat(struct seq_file 
6984         /* convert nsec -> ticks */
6985         start_time = nsec_to_clock_t(start_time);
6986  
6987 +       /* fixup start time for virt uptime */
6988 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6989 +               unsigned long long bias =
6990 +                       current->vx_info->cvirt.bias_clock;
6991 +
6992 +               if (start_time > bias)
6993 +                       start_time -= bias;
6994 +               else
6995 +                       start_time = 0;
6996 +       }
6997 +
6998         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6999  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
7000  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
7001 diff -NurpP --minimal linux-2.6.27.6/fs/proc/base.c linux-2.6.27.6-vs2.3.0.36/fs/proc/base.c
7002 --- linux-2.6.27.6/fs/proc/base.c       2008-10-13 14:52:06.000000000 +0200
7003 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/base.c    2008-10-13 14:54:20.000000000 +0200
7004 @@ -79,6 +79,8 @@
7005  #include <linux/oom.h>
7006  #include <linux/elf.h>
7007  #include <linux/pid_namespace.h>
7008 +#include <linux/vs_context.h>
7009 +#include <linux/vs_network.h>
7010  #include "internal.h"
7011  
7012  /* NOTE:
7013 @@ -1439,6 +1441,8 @@ static struct inode *proc_pid_make_inode
7014                 inode->i_uid = task->euid;
7015                 inode->i_gid = task->egid;
7016         }
7017 +       /* procfs is xid tagged */
7018 +       inode->i_tag = (tag_t)vx_task_xid(task);
7019         security_task_to_inode(task, inode);
7020  
7021  out:
7022 @@ -1979,6 +1983,13 @@ static struct dentry *proc_pident_lookup
7023         if (!task)
7024                 goto out_no_task;
7025  
7026 +       /* TODO: maybe we can come up with a generic approach? */
7027 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7028 +               (dentry->d_name.len == 5) &&
7029 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7030 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7031 +               goto out;
7032 +
7033         /*
7034          * Yes, it does not scale. And it should not. Don't add
7035          * new entries into /proc/<tgid>/ without very good reasons.
7036 @@ -2366,7 +2377,7 @@ out_iput:
7037  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7038  {
7039         struct dentry *error;
7040 -       struct task_struct *task = get_proc_task(dir);
7041 +       struct task_struct *task = get_proc_task_real(dir);
7042         const struct pid_entry *p, *last;
7043  
7044         error = ERR_PTR(-ENOENT);
7045 @@ -2449,6 +2460,9 @@ static int proc_tgid_io_accounting(struc
7046  static const struct file_operations proc_task_operations;
7047  static const struct inode_operations proc_task_inode_operations;
7048  
7049 +extern int proc_pid_vx_info(struct task_struct *, char *);
7050 +extern int proc_pid_nx_info(struct task_struct *, char *);
7051 +
7052  static const struct pid_entry tgid_base_stuff[] = {
7053         DIR("task",       S_IRUGO|S_IXUGO, task),
7054         DIR("fd",         S_IRUSR|S_IXUSR, fd),
7055 @@ -2503,6 +2517,8 @@ static const struct pid_entry tgid_base_
7056  #ifdef CONFIG_CGROUPS
7057         REG("cgroup",  S_IRUGO, cgroup),
7058  #endif
7059 +       INF("vinfo",      S_IRUGO, pid_vx_info),
7060 +       INF("ninfo",      S_IRUGO, pid_nx_info),
7061         INF("oom_score",  S_IRUGO, oom_score),
7062         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
7063  #ifdef CONFIG_AUDITSYSCALL
7064 @@ -2518,6 +2534,7 @@ static const struct pid_entry tgid_base_
7065  #ifdef CONFIG_TASK_IO_ACCOUNTING
7066         INF("io",       S_IRUGO, tgid_io_accounting),
7067  #endif
7068 +       ONE("nsproxy",  S_IRUGO, pid_nsproxy),
7069  };
7070  
7071  static int proc_tgid_base_readdir(struct file * filp,
7072 @@ -2714,7 +2731,7 @@ retry:
7073         iter.task = NULL;
7074         pid = find_ge_pid(iter.tgid, ns);
7075         if (pid) {
7076 -               iter.tgid = pid_nr_ns(pid, ns);
7077 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7078                 iter.task = pid_task(pid, PIDTYPE_PID);
7079                 /* What we to know is if the pid we have find is the
7080                  * pid of a thread_group_leader.  Testing for task
7081 @@ -2744,7 +2761,7 @@ static int proc_pid_fill_cache(struct fi
7082         struct tgid_iter iter)
7083  {
7084         char name[PROC_NUMBUF];
7085 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7086 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7087         return proc_fill_cache(filp, dirent, filldir, name, len,
7088                                 proc_pid_instantiate, iter.task, NULL);
7089  }
7090 @@ -2753,7 +2770,7 @@ static int proc_pid_fill_cache(struct fi
7091  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7092  {
7093         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7094 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7095 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7096         struct tgid_iter iter;
7097         struct pid_namespace *ns;
7098  
7099 @@ -2773,6 +2790,8 @@ int proc_pid_readdir(struct file * filp,
7100              iter.task;
7101              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7102                 filp->f_pos = iter.tgid + TGID_OFFSET;
7103 +               if (!vx_proc_task_visible(iter.task))
7104 +                       continue;
7105                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7106                         put_task_struct(iter.task);
7107                         goto out;
7108 @@ -2915,6 +2934,8 @@ static struct dentry *proc_task_lookup(s
7109         tid = name_to_int(dentry);
7110         if (tid == ~0U)
7111                 goto out;
7112 +       if (vx_current_initpid(tid))
7113 +               goto out;
7114  
7115         ns = dentry->d_sb->s_fs_info;
7116         rcu_read_lock();
7117 diff -NurpP --minimal linux-2.6.27.6/fs/proc/generic.c linux-2.6.27.6-vs2.3.0.36/fs/proc/generic.c
7118 --- linux-2.6.27.6/fs/proc/generic.c    2008-10-13 14:52:06.000000000 +0200
7119 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/generic.c 2008-10-13 14:54:20.000000000 +0200
7120 @@ -21,6 +21,7 @@
7121  #include <linux/bitops.h>
7122  #include <linux/spinlock.h>
7123  #include <linux/completion.h>
7124 +#include <linux/vserver/inode.h>
7125  #include <asm/uaccess.h>
7126  
7127  #include "internal.h"
7128 @@ -384,6 +385,8 @@ struct dentry *proc_lookup_de(struct pro
7129         for (de = de->subdir; de ; de = de->next) {
7130                 if (de->namelen != dentry->d_name.len)
7131                         continue;
7132 +                       if (!vx_hide_check(0, de->vx_flags))
7133 +                               continue;
7134                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7135                         unsigned int ino;
7136  
7137 @@ -392,6 +395,8 @@ struct dentry *proc_lookup_de(struct pro
7138                         spin_unlock(&proc_subdir_lock);
7139                         error = -EINVAL;
7140                         inode = proc_get_inode(dir->i_sb, ino, de);
7141 +                               /* generic proc entries belong to the host */
7142 +                               inode->i_tag = 0;
7143                         goto out_unlock;
7144                 }
7145         }
7146 @@ -472,6 +477,8 @@ int proc_readdir_de(struct proc_dir_entr
7147  
7148                                 /* filldir passes info to user space */
7149                                 de_get(de);
7150 +                               if (!vx_hide_check(0, de->vx_flags))
7151 +                                       goto skip;
7152                                 spin_unlock(&proc_subdir_lock);
7153                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7154                                             de->low_ino, de->mode >> 12) < 0) {
7155 @@ -479,6 +486,7 @@ int proc_readdir_de(struct proc_dir_entr
7156                                         goto out;
7157                                 }
7158                                 spin_lock(&proc_subdir_lock);
7159 +                       skip:
7160                                 filp->f_pos++;
7161                                 next = de->next;
7162                                 de_put(de);
7163 @@ -593,6 +601,7 @@ static struct proc_dir_entry *__proc_cre
7164         ent->nlink = nlink;
7165         atomic_set(&ent->count, 1);
7166         ent->pde_users = 0;
7167 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7168         spin_lock_init(&ent->pde_unload_lock);
7169         ent->pde_unload_completion = NULL;
7170         INIT_LIST_HEAD(&ent->pde_openers);
7171 @@ -616,7 +625,8 @@ struct proc_dir_entry *proc_symlink(cons
7172                                 kfree(ent->data);
7173                                 kfree(ent);
7174                                 ent = NULL;
7175 -                       }
7176 +                       } else
7177 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7178                 } else {
7179                         kfree(ent);
7180                         ent = NULL;
7181 diff -NurpP --minimal linux-2.6.27.6/fs/proc/inode.c linux-2.6.27.6-vs2.3.0.36/fs/proc/inode.c
7182 --- linux-2.6.27.6/fs/proc/inode.c      2008-10-13 14:52:06.000000000 +0200
7183 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/inode.c   2008-10-13 14:54:20.000000000 +0200
7184 @@ -469,6 +469,8 @@ struct inode *proc_get_inode(struct supe
7185                         inode->i_uid = de->uid;
7186                         inode->i_gid = de->gid;
7187                 }
7188 +               if (de->vx_flags)
7189 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7190                 if (de->size)
7191                         inode->i_size = de->size;
7192                 if (de->nlink)
7193 diff -NurpP --minimal linux-2.6.27.6/fs/proc/internal.h linux-2.6.27.6-vs2.3.0.36/fs/proc/internal.h
7194 --- linux-2.6.27.6/fs/proc/internal.h   2008-10-13 14:52:06.000000000 +0200
7195 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/internal.h        2008-10-13 14:54:20.000000000 +0200
7196 @@ -10,6 +10,7 @@
7197   */
7198  
7199  #include <linux/proc_fs.h>
7200 +#include <linux/vs_pid.h>
7201  
7202  extern struct proc_dir_entry proc_root;
7203  #ifdef CONFIG_PROC_SYSCTL
7204 @@ -55,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
7205                                 struct pid *pid, struct task_struct *task);
7206  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7207                                 struct pid *pid, struct task_struct *task);
7208 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7209 +                               struct pid *pid, struct task_struct *task);
7210 +
7211  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7212  
7213  extern const struct file_operations proc_maps_operations;
7214 @@ -75,11 +79,16 @@ static inline struct pid *proc_pid(struc
7215         return PROC_I(inode)->pid;
7216  }
7217  
7218 -static inline struct task_struct *get_proc_task(struct inode *inode)
7219 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7220  {
7221         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7222  }
7223  
7224 +static inline struct task_struct *get_proc_task(struct inode *inode)
7225 +{
7226 +       return vx_get_proc_task(inode, proc_pid(inode));
7227 +}
7228 +
7229  static inline int proc_fd(struct inode *inode)
7230  {
7231         return PROC_I(inode)->fd;
7232 diff -NurpP --minimal linux-2.6.27.6/fs/proc/proc_misc.c linux-2.6.27.6-vs2.3.0.36/fs/proc/proc_misc.c
7233 --- linux-2.6.27.6/fs/proc/proc_misc.c  2008-10-13 14:52:06.000000000 +0200
7234 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/proc_misc.c       2008-10-13 14:54:20.000000000 +0200
7235 @@ -57,6 +57,8 @@
7236  #include <asm/div64.h>
7237  #include "internal.h"
7238  
7239 +#include <linux/vs_cvirt.h>
7240 +
7241  #define LOAD_INT(x) ((x) >> FSHIFT)
7242  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
7243  /*
7244 @@ -84,22 +86,38 @@ static int proc_calc_metrics(char *page,
7245  static int loadavg_read_proc(char *page, char **start, off_t off,
7246                                  int count, int *eof, void *data)
7247  {
7248 +       unsigned long running;
7249 +       unsigned int threads;
7250         int a, b, c;
7251         int len;
7252         unsigned long seq;
7253  
7254         do {
7255                 seq = read_seqbegin(&xtime_lock);
7256 -               a = avenrun[0] + (FIXED_1/200);
7257 -               b = avenrun[1] + (FIXED_1/200);
7258 -               c = avenrun[2] + (FIXED_1/200);
7259 +               if (vx_flags(VXF_VIRT_LOAD, 0)) {
7260 +                       struct vx_info *vxi = current->vx_info;
7261 +
7262 +                       a = vxi->cvirt.load[0] + (FIXED_1/200);
7263 +                       b = vxi->cvirt.load[1] + (FIXED_1/200);
7264 +                       c = vxi->cvirt.load[2] + (FIXED_1/200);
7265 +
7266 +                       running = atomic_read(&vxi->cvirt.nr_running);
7267 +                       threads = atomic_read(&vxi->cvirt.nr_threads);
7268 +               } else {
7269 +                       a = avenrun[0] + (FIXED_1/200);
7270 +                       b = avenrun[1] + (FIXED_1/200);
7271 +                       c = avenrun[2] + (FIXED_1/200);
7272 +
7273 +                       running = nr_running();
7274 +                       threads = nr_threads;
7275 +               }
7276         } while (read_seqretry(&xtime_lock, seq));
7277  
7278         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
7279                 LOAD_INT(a), LOAD_FRAC(a),
7280                 LOAD_INT(b), LOAD_FRAC(b),
7281                 LOAD_INT(c), LOAD_FRAC(c),
7282 -               nr_running(), nr_threads,
7283 +               running, threads,
7284                 task_active_pid_ns(current)->last_pid);
7285         return proc_calc_metrics(page, start, off, count, eof, len);
7286  }
7287 @@ -115,6 +133,9 @@ static int uptime_read_proc(char *page, 
7288         do_posix_clock_monotonic_gettime(&uptime);
7289         monotonic_to_bootbased(&uptime);
7290         cputime_to_timespec(idletime, &idle);
7291 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7292 +               vx_vsi_uptime(&uptime, &idle);
7293 +
7294         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
7295                         (unsigned long) uptime.tv_sec,
7296                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7297 @@ -151,7 +172,7 @@ static int meminfo_read_proc(char *page,
7298  
7299         cached = global_page_state(NR_FILE_PAGES) -
7300                         total_swapcache_pages - i.bufferram;
7301 -       if (cached < 0)
7302 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7303                 cached = 0;
7304  
7305         get_vmalloc_info(&vmi);
7306 diff -NurpP --minimal linux-2.6.27.6/fs/proc/root.c linux-2.6.27.6-vs2.3.0.36/fs/proc/root.c
7307 --- linux-2.6.27.6/fs/proc/root.c       2008-07-13 23:51:29.000000000 +0200
7308 +++ linux-2.6.27.6-vs2.3.0.36/fs/proc/root.c    2008-11-20 00:58:27.000000000 +0100
7309 @@ -19,9 +19,14 @@
7310  #include <linux/smp_lock.h>
7311  #include <linux/mount.h>
7312  #include <linux/pid_namespace.h>
7313 +#include <linux/vserver/inode.h>
7314  
7315  #include "internal.h"
7316  
7317 +struct proc_dir_entry *proc_virtual;
7318 +
7319 +extern void proc_vx_init(void);
7320 +
7321  static int proc_test_super(struct super_block *sb, void *data)
7322  {
7323         return sb->s_fs_info == data;
7324 @@ -137,6 +142,7 @@ void __init proc_root_init(void)
7325  #endif
7326         proc_mkdir("bus", NULL);
7327         proc_sys_init();
7328 +       proc_vx_init();
7329  }
7330  
7331  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7332 @@ -209,6 +215,7 @@ struct proc_dir_entry proc_root = {
7333         .proc_iops      = &proc_root_inode_operations, 
7334         .proc_fops      = &proc_root_operations,
7335         .parent         = &proc_root,
7336 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7337  };
7338  
7339  int pid_ns_prepare_proc(struct pid_namespace *ns)
7340 diff -NurpP --minimal linux-2.6.27.6/fs/quota.c linux-2.6.27.6-vs2.3.0.36/fs/quota.c
7341 --- linux-2.6.27.6/fs/quota.c   2008-10-13 14:52:06.000000000 +0200
7342 +++ linux-2.6.27.6-vs2.3.0.36/fs/quota.c        2008-10-13 14:54:20.000000000 +0200
7343 @@ -18,6 +18,7 @@
7344  #include <linux/capability.h>
7345  #include <linux/quotaops.h>
7346  #include <linux/types.h>
7347 +#include <linux/vs_context.h>
7348  
7349  /* Check validity of generic quotactl commands */
7350  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7351 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7352         if (cmd == Q_GETQUOTA) {
7353                 if (((type == USRQUOTA && current->euid != id) ||
7354                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7355 -                   !capable(CAP_SYS_ADMIN))
7356 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7357                         return -EPERM;
7358         }
7359         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7360 -               if (!capable(CAP_SYS_ADMIN))
7361 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7362                         return -EPERM;
7363  
7364         return 0;
7365 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7366         if (cmd == Q_XGETQUOTA) {
7367                 if (((type == XQM_USRQUOTA && current->euid != id) ||
7368                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7369 -                    !capable(CAP_SYS_ADMIN))
7370 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7371                         return -EPERM;
7372         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7373 -               if (!capable(CAP_SYS_ADMIN))
7374 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7375                         return -EPERM;
7376         }
7377  
7378 @@ -334,6 +335,46 @@ static int do_quotactl(struct super_bloc
7379         return 0;
7380  }
7381  
7382 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7383 +
7384 +#include <linux/vroot.h>
7385 +#include <linux/major.h>
7386 +#include <linux/module.h>
7387 +#include <linux/kallsyms.h>
7388 +#include <linux/vserver/debug.h>
7389 +
7390 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7391 +
7392 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7393 +
7394 +int register_vroot_grb(vroot_grb_func *func) {
7395 +       int ret = -EBUSY;
7396 +
7397 +       spin_lock(&vroot_grb_lock);
7398 +       if (!vroot_get_real_bdev) {
7399 +               vroot_get_real_bdev = func;
7400 +               ret = 0;
7401 +       }
7402 +       spin_unlock(&vroot_grb_lock);
7403 +       return ret;
7404 +}
7405 +EXPORT_SYMBOL(register_vroot_grb);
7406 +
7407 +int unregister_vroot_grb(vroot_grb_func *func) {
7408 +       int ret = -EINVAL;
7409 +
7410 +       spin_lock(&vroot_grb_lock);
7411 +       if (vroot_get_real_bdev) {
7412 +               vroot_get_real_bdev = NULL;
7413 +               ret = 0;
7414 +       }
7415 +       spin_unlock(&vroot_grb_lock);
7416 +       return ret;
7417 +}
7418 +EXPORT_SYMBOL(unregister_vroot_grb);
7419 +
7420 +#endif
7421 +
7422  /*
7423   * look up a superblock on which quota ops will be performed
7424   * - use the name of a block device to find the superblock thereon
7425 @@ -351,6 +392,22 @@ static inline struct super_block *quotac
7426         putname(tmp);
7427         if (IS_ERR(bdev))
7428                 return ERR_CAST(bdev);
7429 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7430 +       if (bdev && bdev->bd_inode &&
7431 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7432 +               struct block_device *bdnew = (void *)-EINVAL;
7433 +
7434 +               if (vroot_get_real_bdev)
7435 +                       bdnew = vroot_get_real_bdev(bdev);
7436 +               else
7437 +                       vxdprintk(VXD_CBIT(misc, 0),
7438 +                                       "vroot_get_real_bdev not set");
7439 +               bdput(bdev);
7440 +               if (IS_ERR(bdnew))
7441 +                       return ERR_PTR(PTR_ERR(bdnew));
7442 +               bdev = bdnew;
7443 +       }
7444 +#endif
7445         sb = get_super(bdev);
7446         bdput(bdev);
7447         if (!sb)
7448 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/bitmap.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/bitmap.c
7449 --- linux-2.6.27.6/fs/reiserfs/bitmap.c 2008-07-13 23:51:29.000000000 +0200
7450 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/bitmap.c      2008-10-13 14:54:20.000000000 +0200
7451 @@ -13,6 +13,7 @@
7452  #include <linux/reiserfs_fs_sb.h>
7453  #include <linux/reiserfs_fs_i.h>
7454  #include <linux/quotaops.h>
7455 +#include <linux/vs_dlimit.h>
7456  
7457  #define PREALLOCATION_SIZE 9
7458  
7459 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7460         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7461  
7462         journal_mark_dirty(th, s, sbh);
7463 -       if (for_unformatted)
7464 +       if (for_unformatted) {
7465 +               DLIMIT_FREE_BLOCK(inode, 1);
7466                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7467 +       }
7468  }
7469  
7470  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7471 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7472         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7473         int passno = 0;
7474         int nr_allocated = 0;
7475 +       int blocks;
7476  
7477         determine_prealloc_size(hint);
7478         if (!hint->formatted_node) {
7479 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7480                                "reiserquota: allocating %d blocks id=%u",
7481                                amount_needed, hint->inode->i_uid);
7482  #endif
7483 -               quota_ret =
7484 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7485 -               if (quota_ret)  /* Quota exceeded? */
7486 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7487 +                       amount_needed);
7488 +               if (quota_ret)
7489                         return QUOTA_EXCEEDED;
7490 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7491 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7492 +                               amount_needed);
7493 +                       return NO_DISK_SPACE;
7494 +               }
7495 +
7496                 if (hint->preallocate && hint->prealloc_size) {
7497  #ifdef REISERQUOTA_DEBUG
7498                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7499                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7500                                        hint->prealloc_size, hint->inode->i_uid);
7501  #endif
7502 -                       quota_ret =
7503 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7504 -                                                        hint->prealloc_size);
7505 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7506 +                               hint->prealloc_size);
7507 +                       if (!quota_ret &&
7508 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7509 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7510 +                                       hint->prealloc_size);
7511 +                               quota_ret = 1;
7512 +                       }
7513                         if (quota_ret)
7514                                 hint->preallocate = hint->prealloc_size = 0;
7515                 }
7516 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7517                                                nr_allocated,
7518                                                hint->inode->i_uid);
7519  #endif
7520 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7521 +                               /* Free not allocated blocks */
7522 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7523 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7524 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7525                         }
7526                         while (nr_allocated--)
7527                                 reiserfs_free_block(hint->th, hint->inode,
7528 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7529                                REISERFS_I(hint->inode)->i_prealloc_count,
7530                                hint->inode->i_uid);
7531  #endif
7532 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7533 -                                        hint->prealloc_size - nr_allocated -
7534 -                                        REISERFS_I(hint->inode)->
7535 -                                        i_prealloc_count);
7536 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7537 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7538 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7539 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7540         }
7541  
7542         return CARRY_ON;
7543 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/file.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/file.c
7544 --- linux-2.6.27.6/fs/reiserfs/file.c   2008-07-13 23:51:29.000000000 +0200
7545 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/file.c        2008-10-13 14:54:20.000000000 +0200
7546 @@ -306,4 +306,5 @@ const struct inode_operations reiserfs_f
7547         .listxattr = reiserfs_listxattr,
7548         .removexattr = reiserfs_removexattr,
7549         .permission = reiserfs_permission,
7550 +       .sync_flags = reiserfs_sync_flags,
7551  };
7552 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/inode.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/inode.c
7553 --- linux-2.6.27.6/fs/reiserfs/inode.c  2008-10-13 14:52:06.000000000 +0200
7554 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/inode.c       2008-10-13 14:54:20.000000000 +0200
7555 @@ -18,6 +18,8 @@
7556  #include <linux/writeback.h>
7557  #include <linux/quotaops.h>
7558  #include <linux/swap.h>
7559 +#include <linux/vs_dlimit.h>
7560 +#include <linux/vs_tag.h>
7561  
7562  int reiserfs_commit_write(struct file *f, struct page *page,
7563                           unsigned from, unsigned to);
7564 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7565                  * stat data deletion */
7566                 if (!err) 
7567                         DQUOT_FREE_INODE(inode);
7568 +               DLIMIT_FREE_INODE(inode);
7569  
7570                 if (journal_end(&th, inode->i_sb, jbegin_count))
7571                         goto out;
7572 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7573         struct buffer_head *bh;
7574         struct item_head *ih;
7575         __u32 rdev;
7576 +       uid_t uid;
7577 +       gid_t gid;
7578         //int version = ITEM_VERSION_1;
7579  
7580         bh = PATH_PLAST_BUFFER(path);
7581 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7582                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7583                 unsigned long blocks;
7584  
7585 +               uid = sd_v1_uid(sd);
7586 +               gid = sd_v1_gid(sd);
7587 +
7588                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7589                 set_inode_sd_version(inode, STAT_DATA_V1);
7590                 inode->i_mode = sd_v1_mode(sd);
7591                 inode->i_nlink = sd_v1_nlink(sd);
7592 -               inode->i_uid = sd_v1_uid(sd);
7593 -               inode->i_gid = sd_v1_gid(sd);
7594                 inode->i_size = sd_v1_size(sd);
7595                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7596                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7597 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7598                 // (directories and symlinks)
7599                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7600  
7601 +               uid    = sd_v2_uid(sd);
7602 +               gid    = sd_v2_gid(sd);
7603 +
7604                 inode->i_mode = sd_v2_mode(sd);
7605                 inode->i_nlink = sd_v2_nlink(sd);
7606 -               inode->i_uid = sd_v2_uid(sd);
7607                 inode->i_size = sd_v2_size(sd);
7608 -               inode->i_gid = sd_v2_gid(sd);
7609                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7610                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7611                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7612 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7613                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7614         }
7615  
7616 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7617 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7618 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7619 +
7620         pathrelse(path);
7621         if (S_ISREG(inode->i_mode)) {
7622                 inode->i_op = &reiserfs_file_inode_operations;
7623 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7624  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7625  {
7626         struct stat_data *sd_v2 = (struct stat_data *)sd;
7627 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7628 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7629         __u16 flags;
7630  
7631 +       set_sd_v2_uid(sd_v2, uid);
7632 +       set_sd_v2_gid(sd_v2, gid);
7633         set_sd_v2_mode(sd_v2, inode->i_mode);
7634         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7635 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7636         set_sd_v2_size(sd_v2, size);
7637 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7638         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7639         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7640         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7641 @@ -1771,6 +1784,10 @@ int reiserfs_new_inode(struct reiserfs_t
7642  
7643         BUG_ON(!th->t_trans_id);
7644  
7645 +       if (DLIMIT_ALLOC_INODE(inode)) {
7646 +               err = -ENOSPC;
7647 +               goto out_bad_dlimit;
7648 +       }
7649         if (DQUOT_ALLOC_INODE(inode)) {
7650                 err = -EDQUOT;
7651                 goto out_end_trans;
7652 @@ -1956,6 +1973,9 @@ int reiserfs_new_inode(struct reiserfs_t
7653         DQUOT_FREE_INODE(inode);
7654  
7655        out_end_trans:
7656 +       DLIMIT_FREE_INODE(inode);
7657 +
7658 +      out_bad_dlimit:
7659         journal_end(th, th->t_super, th->t_blocks_allocated);
7660         /* Drop can be outside and it needs more credits so it's better to have it outside */
7661         DQUOT_DROP(inode);
7662 @@ -2842,14 +2862,19 @@ int reiserfs_commit_write(struct file *f
7663  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7664  {
7665         if (reiserfs_attrs(inode->i_sb)) {
7666 -               if (sd_attrs & REISERFS_SYNC_FL)
7667 -                       inode->i_flags |= S_SYNC;
7668 -               else
7669 -                       inode->i_flags &= ~S_SYNC;
7670                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7671                         inode->i_flags |= S_IMMUTABLE;
7672                 else
7673                         inode->i_flags &= ~S_IMMUTABLE;
7674 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7675 +                       inode->i_flags |= S_IXUNLINK;
7676 +               else
7677 +                       inode->i_flags &= ~S_IXUNLINK;
7678 +
7679 +               if (sd_attrs & REISERFS_SYNC_FL)
7680 +                       inode->i_flags |= S_SYNC;
7681 +               else
7682 +                       inode->i_flags &= ~S_SYNC;
7683                 if (sd_attrs & REISERFS_APPEND_FL)
7684                         inode->i_flags |= S_APPEND;
7685                 else
7686 @@ -2862,6 +2887,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7687                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7688                 else
7689                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7690 +
7691 +               if (sd_attrs & REISERFS_BARRIER_FL)
7692 +                       inode->i_vflags |= V_BARRIER;
7693 +               else
7694 +                       inode->i_vflags &= ~V_BARRIER;
7695 +               if (sd_attrs & REISERFS_COW_FL)
7696 +                       inode->i_vflags |= V_COW;
7697 +               else
7698 +                       inode->i_vflags &= ~V_COW;
7699         }
7700  }
7701  
7702 @@ -2872,6 +2906,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7703                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7704                 else
7705                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7706 +               if (inode->i_flags & S_IXUNLINK)
7707 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7708 +               else
7709 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7710 +
7711                 if (inode->i_flags & S_SYNC)
7712                         *sd_attrs |= REISERFS_SYNC_FL;
7713                 else
7714 @@ -2884,6 +2923,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7715                         *sd_attrs |= REISERFS_NOTAIL_FL;
7716                 else
7717                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7718 +
7719 +               if (inode->i_vflags & V_BARRIER)
7720 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7721 +               else
7722 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7723 +               if (inode->i_vflags & V_COW)
7724 +                       *sd_attrs |= REISERFS_COW_FL;
7725 +               else
7726 +                       *sd_attrs &= ~REISERFS_COW_FL;
7727         }
7728  }
7729  
7730 @@ -3051,6 +3099,22 @@ static ssize_t reiserfs_direct_IO(int rw
7731                                   reiserfs_get_blocks_direct_io, NULL);
7732  }
7733  
7734 +int reiserfs_sync_flags(struct inode *inode)
7735 +{
7736 +       u16 oldflags, newflags;
7737 +
7738 +       oldflags = REISERFS_I(inode)->i_attrs;
7739 +       newflags = oldflags;
7740 +       i_attrs_to_sd_attrs(inode, &newflags);
7741 +
7742 +       if (oldflags ^ newflags) {
7743 +               REISERFS_I(inode)->i_attrs = newflags;
7744 +               inode->i_ctime = CURRENT_TIME_SEC;
7745 +               mark_inode_dirty(inode);
7746 +       }
7747 +       return 0;
7748 +}
7749 +
7750  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7751  {
7752         struct inode *inode = dentry->d_inode;
7753 @@ -3104,9 +3168,11 @@ int reiserfs_setattr(struct dentry *dent
7754         }
7755  
7756         error = inode_change_ok(inode, attr);
7757 +
7758         if (!error) {
7759                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7760 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7761 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7762 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7763                         error = reiserfs_chown_xattrs(inode, attr);
7764  
7765                         if (!error) {
7766 @@ -3136,6 +3202,9 @@ int reiserfs_setattr(struct dentry *dent
7767                                         inode->i_uid = attr->ia_uid;
7768                                 if (attr->ia_valid & ATTR_GID)
7769                                         inode->i_gid = attr->ia_gid;
7770 +                               if ((attr->ia_valid & ATTR_TAG) &&
7771 +                                       IS_TAGGED(inode))
7772 +                                       inode->i_tag = attr->ia_tag;
7773                                 mark_inode_dirty(inode);
7774                                 error =
7775                                     journal_end(&th, inode->i_sb, jbegin_count);
7776 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/ioctl.c
7777 --- linux-2.6.27.6/fs/reiserfs/ioctl.c  2008-07-13 23:51:29.000000000 +0200
7778 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/ioctl.c       2008-10-13 14:54:20.000000000 +0200
7779 @@ -7,6 +7,7 @@
7780  #include <linux/mount.h>
7781  #include <linux/reiserfs_fs.h>
7782  #include <linux/time.h>
7783 +#include <linux/mount.h>
7784  #include <asm/uaccess.h>
7785  #include <linux/pagemap.h>
7786  #include <linux/smp_lock.h>
7787 @@ -23,7 +24,7 @@
7788  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7789                    unsigned long arg)
7790  {
7791 -       unsigned int flags;
7792 +       unsigned int flags, oldflags;
7793         int err = 0;
7794  
7795         switch (cmd) {
7796 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7797  
7798                 flags = REISERFS_I(inode)->i_attrs;
7799                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7800 +               flags &= REISERFS_FL_USER_VISIBLE;
7801                 return put_user(flags, (int __user *)arg);
7802         case REISERFS_IOC_SETFLAGS:{
7803                         if (!reiserfs_attrs(inode->i_sb))
7804 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7805                                 err = -EFAULT;
7806                                 goto setflags_out;
7807                         }
7808 +                       if (IS_BARRIER(inode)) {
7809 +                               vxwprintk_task(1, "messing with the barrier.");
7810 +                               return -EACCES;
7811 +                       }
7812                         /*
7813                          * Is it quota file? Do not allow user to mess with it
7814                          */
7815 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7816                                         goto setflags_out;
7817                                 }
7818                         }
7819 +
7820 +                       oldflags = REISERFS_I(inode)->i_attrs;
7821 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7822 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7823                         sd_attrs_to_i_attrs(flags, inode);
7824                         REISERFS_I(inode)->i_attrs = flags;
7825                         inode->i_ctime = CURRENT_TIME_SEC;
7826 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/namei.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/namei.c
7827 --- linux-2.6.27.6/fs/reiserfs/namei.c  2008-07-13 23:51:29.000000000 +0200
7828 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/namei.c       2008-10-13 14:54:20.000000000 +0200
7829 @@ -17,6 +17,7 @@
7830  #include <linux/reiserfs_acl.h>
7831  #include <linux/reiserfs_xattr.h>
7832  #include <linux/quotaops.h>
7833 +#include <linux/vs_tag.h>
7834  
7835  #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; }
7836  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7837 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7838                         reiserfs_write_unlock(dir->i_sb);
7839                         return ERR_PTR(-EACCES);
7840                 }
7841 +               dx_propagate_tag(nd, inode);
7842  
7843                 /* Propogate the priv_object flag so we know we're in the priv tree */
7844                 if (is_reiserfs_priv_object(dir))
7845 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
7846         } else {
7847                 inode->i_gid = current->fsgid;
7848         }
7849 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7850         DQUOT_INIT(inode);
7851         return 0;
7852  }
7853 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
7854         .listxattr = reiserfs_listxattr,
7855         .removexattr = reiserfs_removexattr,
7856         .permission = reiserfs_permission,
7857 +       .sync_flags = reiserfs_sync_flags,
7858  };
7859  
7860  /*
7861 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
7862         .listxattr = reiserfs_listxattr,
7863         .removexattr = reiserfs_removexattr,
7864         .permission = reiserfs_permission,
7865 +       .sync_flags = reiserfs_sync_flags,
7866  
7867  };
7868  
7869 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
7870         .listxattr = reiserfs_listxattr,
7871         .removexattr = reiserfs_removexattr,
7872         .permission = reiserfs_permission,
7873 +       .sync_flags = reiserfs_sync_flags,
7874  
7875  };
7876 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/stree.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/stree.c
7877 --- linux-2.6.27.6/fs/reiserfs/stree.c  2008-07-13 23:51:29.000000000 +0200
7878 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/stree.c       2008-10-13 14:54:20.000000000 +0200
7879 @@ -55,6 +55,7 @@
7880  #include <linux/reiserfs_fs.h>
7881  #include <linux/buffer_head.h>
7882  #include <linux/quotaops.h>
7883 +#include <linux/vs_dlimit.h>
7884  
7885  /* Does the buffer contain a disk block which is in the tree. */
7886  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7887 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7888                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7889                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7890  #endif
7891 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7892         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7893  
7894         /* Return deleted body length */
7895 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7896  #endif
7897                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7898                                                          quota_cut_bytes);
7899 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7900                         }
7901                         break;
7902                 }
7903 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7904                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7905                        quota_cut_bytes, p_s_inode->i_uid, '?');
7906  #endif
7907 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7908         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7909         return n_ret_value;
7910  }
7911 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7912                 pathrelse(p_s_search_path);
7913                 return -EDQUOT;
7914         }
7915 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7916 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7917 +               pathrelse(p_s_search_path);
7918 +               return -ENOSPC;
7919 +       }
7920         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7921                        n_pasted_size);
7922  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7923 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7924                        n_pasted_size, inode->i_uid,
7925                        key2type(&(p_s_key->on_disk_key)));
7926  #endif
7927 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7928         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7929         return retval;
7930  }
7931 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7932                         pathrelse(p_s_path);
7933                         return -EDQUOT;
7934                 }
7935 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7936 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7937 +                       pathrelse(p_s_path);
7938 +                       return -ENOSPC;
7939 +               }
7940         }
7941         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7942                        IH_SIZE + ih_item_len(p_s_ih));
7943 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7944                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7945                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7946  #endif
7947 -       if (inode)
7948 +       if (inode) {
7949 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7950                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7951 +       }
7952         return retval;
7953  }
7954 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/super.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/super.c
7955 --- linux-2.6.27.6/fs/reiserfs/super.c  2008-10-13 14:52:06.000000000 +0200
7956 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/super.c       2008-10-13 14:54:20.000000000 +0200
7957 @@ -898,6 +898,14 @@ static int reiserfs_parse_options(struct
7958                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7959                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7960  #endif
7961 +#ifndef CONFIG_TAGGING_NONE
7962 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7963 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7964 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7965 +#endif
7966 +#ifdef CONFIG_PROPAGATE
7967 +               {"tag",.arg_required = 'T',.values = NULL},
7968 +#endif
7969  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7970                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7971                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7972 @@ -1193,6 +1201,12 @@ static int reiserfs_remount(struct super
7973         handle_quota_files(s, qf_names, &qfmt);
7974  #endif
7975  
7976 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7977 +               !(s->s_flags & MS_TAGGED)) {
7978 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7979 +               return -EINVAL;
7980 +       }
7981 +
7982         handle_attrs(s);
7983  
7984         /* Add options that are safe here */
7985 @@ -1657,6 +1671,10 @@ static int reiserfs_fill_super(struct su
7986                 goto error;
7987         }
7988  
7989 +       /* map mount option tagxid */
7990 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7991 +               s->s_flags |= MS_TAGGED;
7992 +
7993         rs = SB_DISK_SUPER_BLOCK(s);
7994         /* Let's do basic sanity check to verify that underlying device is not
7995            smaller than the filesystem. If the check fails then abort and scream,
7996 diff -NurpP --minimal linux-2.6.27.6/fs/reiserfs/xattr.c linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/xattr.c
7997 --- linux-2.6.27.6/fs/reiserfs/xattr.c  2008-10-13 14:52:06.000000000 +0200
7998 +++ linux-2.6.27.6-vs2.3.0.36/fs/reiserfs/xattr.c       2008-10-13 14:54:20.000000000 +0200
7999 @@ -35,6 +35,7 @@
8000  #include <linux/namei.h>
8001  #include <linux/errno.h>
8002  #include <linux/fs.h>
8003 +#include <linux/mount.h>
8004  #include <linux/file.h>
8005  #include <linux/pagemap.h>
8006  #include <linux/xattr.h>
8007 diff -NurpP --minimal linux-2.6.27.6/fs/stat.c linux-2.6.27.6-vs2.3.0.36/fs/stat.c
8008 --- linux-2.6.27.6/fs/stat.c    2008-10-13 14:52:06.000000000 +0200
8009 +++ linux-2.6.27.6-vs2.3.0.36/fs/stat.c 2008-10-13 14:54:20.000000000 +0200
8010 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
8011         stat->nlink = inode->i_nlink;
8012         stat->uid = inode->i_uid;
8013         stat->gid = inode->i_gid;
8014 +       stat->tag = inode->i_tag;
8015         stat->rdev = inode->i_rdev;
8016         stat->atime = inode->i_atime;
8017         stat->mtime = inode->i_mtime;
8018 diff -NurpP --minimal linux-2.6.27.6/fs/super.c linux-2.6.27.6-vs2.3.0.36/fs/super.c
8019 --- linux-2.6.27.6/fs/super.c   2008-10-13 14:52:06.000000000 +0200
8020 +++ linux-2.6.27.6-vs2.3.0.36/fs/super.c        2008-10-13 14:54:20.000000000 +0200
8021 @@ -38,6 +38,9 @@
8022  #include <linux/kobject.h>
8023  #include <linux/mutex.h>
8024  #include <linux/file.h>
8025 +#include <linux/devpts_fs.h>
8026 +#include <linux/proc_fs.h>
8027 +#include <linux/vs_context.h>
8028  #include <asm/uaccess.h>
8029  #include "internal.h"
8030  
8031 @@ -887,12 +890,18 @@ struct vfsmount *
8032  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
8033  {
8034         struct vfsmount *mnt;
8035 +       struct super_block *sb;
8036         char *secdata = NULL;
8037         int error;
8038  
8039         if (!type)
8040                 return ERR_PTR(-ENODEV);
8041  
8042 +       error = -EPERM;
8043 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
8044 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
8045 +               goto out;
8046 +
8047         error = -ENOMEM;
8048         mnt = alloc_vfsmnt(name);
8049         if (!mnt)
8050 @@ -913,7 +922,14 @@ vfs_kern_mount(struct file_system_type *
8051                 goto out_free_secdata;
8052         BUG_ON(!mnt->mnt_sb);
8053  
8054 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
8055 +       sb = mnt->mnt_sb;
8056 +       error = -EPERM;
8057 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
8058 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8059 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8060 +               goto out_sb;
8061 +
8062 +       error = security_sb_kern_mount(sb, secdata);
8063         if (error)
8064                 goto out_sb;
8065  
8066 diff -NurpP --minimal linux-2.6.27.6/fs/sysfs/mount.c linux-2.6.27.6-vs2.3.0.36/fs/sysfs/mount.c
8067 --- linux-2.6.27.6/fs/sysfs/mount.c     2008-07-13 23:51:29.000000000 +0200
8068 +++ linux-2.6.27.6-vs2.3.0.36/fs/sysfs/mount.c  2008-10-13 14:54:20.000000000 +0200
8069 @@ -19,8 +19,6 @@
8070  
8071  #include "sysfs.h"
8072  
8073 -/* Random magic number */
8074 -#define SYSFS_MAGIC 0x62656572
8075  
8076  static struct vfsmount *sysfs_mount;
8077  struct super_block * sysfs_sb = NULL;
8078 @@ -46,7 +44,7 @@ static int sysfs_fill_super(struct super
8079  
8080         sb->s_blocksize = PAGE_CACHE_SIZE;
8081         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8082 -       sb->s_magic = SYSFS_MAGIC;
8083 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8084         sb->s_op = &sysfs_ops;
8085         sb->s_time_gran = 1;
8086         sysfs_sb = sb;
8087 diff -NurpP --minimal linux-2.6.27.6/fs/utimes.c linux-2.6.27.6-vs2.3.0.36/fs/utimes.c
8088 --- linux-2.6.27.6/fs/utimes.c  2008-10-13 14:52:06.000000000 +0200
8089 +++ linux-2.6.27.6-vs2.3.0.36/fs/utimes.c       2008-10-13 14:54:20.000000000 +0200
8090 @@ -8,6 +8,8 @@
8091  #include <linux/stat.h>
8092  #include <linux/utime.h>
8093  #include <linux/syscalls.h>
8094 +#include <linux/mount.h>
8095 +#include <linux/vs_cowbl.h>
8096  #include <asm/uaccess.h>
8097  #include <asm/unistd.h>
8098  
8099 diff -NurpP --minimal linux-2.6.27.6/fs/xattr.c linux-2.6.27.6-vs2.3.0.36/fs/xattr.c
8100 --- linux-2.6.27.6/fs/xattr.c   2008-10-13 14:52:06.000000000 +0200
8101 +++ linux-2.6.27.6-vs2.3.0.36/fs/xattr.c        2008-10-13 14:54:20.000000000 +0200
8102 @@ -18,6 +18,7 @@
8103  #include <linux/module.h>
8104  #include <linux/fsnotify.h>
8105  #include <linux/audit.h>
8106 +#include <linux/mount.h>
8107  #include <asm/uaccess.h>
8108  
8109  
8110 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_ioctl.c
8111 --- linux-2.6.27.6/fs/xfs/linux-2.6/xfs_ioctl.c 2008-10-13 14:52:06.000000000 +0200
8112 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_ioctl.c      2008-11-12 18:41:58.000000000 +0100
8113 @@ -806,6 +806,10 @@ xfs_merge_ioc_xflags(
8114                 xflags |= XFS_XFLAG_IMMUTABLE;
8115         else
8116                 xflags &= ~XFS_XFLAG_IMMUTABLE;
8117 +       if (flags & FS_IXUNLINK_FL)
8118 +               xflags |= XFS_XFLAG_IXUNLINK;
8119 +       else
8120 +               xflags &= ~XFS_XFLAG_IXUNLINK;
8121         if (flags & FS_APPEND_FL)
8122                 xflags |= XFS_XFLAG_APPEND;
8123         else
8124 @@ -834,6 +838,8 @@ xfs_di2lxflags(
8125  
8126         if (di_flags & XFS_DIFLAG_IMMUTABLE)
8127                 flags |= FS_IMMUTABLE_FL;
8128 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
8129 +               flags |= FS_IXUNLINK_FL;
8130         if (di_flags & XFS_DIFLAG_APPEND)
8131                 flags |= FS_APPEND_FL;
8132         if (di_flags & XFS_DIFLAG_SYNC)
8133 @@ -892,6 +898,8 @@ xfs_set_diflags(
8134         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
8135         if (xflags & XFS_XFLAG_IMMUTABLE)
8136                 di_flags |= XFS_DIFLAG_IMMUTABLE;
8137 +       if (xflags & XFS_XFLAG_IXUNLINK)
8138 +               di_flags |= XFS_DIFLAG_IXUNLINK;
8139         if (xflags & XFS_XFLAG_APPEND)
8140                 di_flags |= XFS_DIFLAG_APPEND;
8141         if (xflags & XFS_XFLAG_SYNC)
8142 @@ -934,6 +942,10 @@ xfs_diflags_to_linux(
8143                 inode->i_flags |= S_IMMUTABLE;
8144         else
8145                 inode->i_flags &= ~S_IMMUTABLE;
8146 +       if (xflags & XFS_XFLAG_IXUNLINK)
8147 +               inode->i_flags |= S_IXUNLINK;
8148 +       else
8149 +               inode->i_flags &= ~S_IXUNLINK;
8150         if (xflags & XFS_XFLAG_APPEND)
8151                 inode->i_flags |= S_APPEND;
8152         else
8153 @@ -1392,10 +1404,18 @@ xfs_ioctl(
8154         case XFS_IOC_FSGETXATTRA:
8155                 return xfs_ioc_fsgetxattr(ip, 1, arg);
8156         case XFS_IOC_FSSETXATTR:
8157 +               if (IS_BARRIER(inode)) {
8158 +                       vxwprintk_task(1, "messing with the barrier.");
8159 +                       return -XFS_ERROR(EACCES);
8160 +               }
8161                 return xfs_ioc_fssetxattr(ip, filp, arg);
8162         case XFS_IOC_GETXFLAGS:
8163                 return xfs_ioc_getxflags(ip, arg);
8164         case XFS_IOC_SETXFLAGS:
8165 +               if (IS_BARRIER(inode)) {
8166 +                       vxwprintk_task(1, "messing with the barrier.");
8167 +                       return -XFS_ERROR(EACCES);
8168 +               }
8169                 return xfs_ioc_setxflags(ip, filp, arg);
8170  
8171         case XFS_IOC_FSSETDM: {
8172 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_iops.c
8173 --- linux-2.6.27.6/fs/xfs/linux-2.6/xfs_iops.c  2008-10-13 14:52:06.000000000 +0200
8174 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_iops.c       2008-11-12 18:41:58.000000000 +0100
8175 @@ -53,6 +53,7 @@
8176  #include <linux/namei.h>
8177  #include <linux/security.h>
8178  #include <linux/falloc.h>
8179 +#include <linux/vs_tag.h>
8180  
8181  /*
8182   * Bring the atime in the XFS inode uptodate.
8183 @@ -558,6 +559,7 @@ xfs_vn_getattr(
8184         stat->nlink = ip->i_d.di_nlink;
8185         stat->uid = ip->i_d.di_uid;
8186         stat->gid = ip->i_d.di_gid;
8187 +       stat->tag = ip->i_d.di_tag;
8188         stat->ino = ip->i_ino;
8189  #if XFS_BIG_INUMS
8190         stat->ino += mp->m_inoadd;
8191 @@ -597,6 +599,12 @@ xfs_vn_getattr(
8192  }
8193  
8194  STATIC int
8195 +xfs_vn_sync_xflags(struct inode *inode)
8196 +{
8197 +       return -xfs_sync_xflags(XFS_I(inode));
8198 +}
8199 +
8200 +STATIC int
8201  xfs_vn_setattr(
8202         struct dentry   *dentry,
8203         struct iattr    *iattr)
8204 @@ -671,6 +679,7 @@ static const struct inode_operations xfs
8205         .removexattr            = generic_removexattr,
8206         .listxattr              = xfs_vn_listxattr,
8207         .fallocate              = xfs_vn_fallocate,
8208 +       .sync_flags             = xfs_vn_sync_xflags,
8209  };
8210  
8211  static const struct inode_operations xfs_dir_inode_operations = {
8212 @@ -696,6 +705,7 @@ static const struct inode_operations xfs
8213         .getxattr               = generic_getxattr,
8214         .removexattr            = generic_removexattr,
8215         .listxattr              = xfs_vn_listxattr,
8216 +       .sync_flags             = xfs_vn_sync_xflags,
8217  };
8218  
8219  static const struct inode_operations xfs_dir_ci_inode_operations = {
8220 @@ -745,6 +755,10 @@ xfs_diflags_to_iflags(
8221                 inode->i_flags |= S_IMMUTABLE;
8222         else
8223                 inode->i_flags &= ~S_IMMUTABLE;
8224 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
8225 +               inode->i_flags |= S_IXUNLINK;
8226 +       else
8227 +               inode->i_flags &= ~S_IXUNLINK;
8228         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8229                 inode->i_flags |= S_APPEND;
8230         else
8231 @@ -757,6 +771,15 @@ xfs_diflags_to_iflags(
8232                 inode->i_flags |= S_NOATIME;
8233         else
8234                 inode->i_flags &= ~S_NOATIME;
8235 +
8236 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8237 +               inode->i_vflags |= V_BARRIER;
8238 +       else
8239 +               inode->i_vflags &= ~V_BARRIER;
8240 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8241 +               inode->i_vflags |= V_COW;
8242 +       else
8243 +               inode->i_vflags &= ~V_COW;
8244  }
8245  
8246  /*
8247 @@ -777,6 +800,7 @@ xfs_setup_inode(
8248         inode->i_nlink  = ip->i_d.di_nlink;
8249         inode->i_uid    = ip->i_d.di_uid;
8250         inode->i_gid    = ip->i_d.di_gid;
8251 +       inode->i_tag    = ip->i_d.di_tag;
8252  
8253         switch (inode->i_mode & S_IFMT) {
8254         case S_IFBLK:
8255 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_linux.h
8256 --- linux-2.6.27.6/fs/xfs/linux-2.6/xfs_linux.h 2008-10-13 14:52:06.000000000 +0200
8257 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_linux.h      2008-10-13 15:35:26.000000000 +0200
8258 @@ -126,6 +126,7 @@
8259  
8260  #define current_cpu()          (raw_smp_processor_id())
8261  #define current_pid()          (current->pid)
8262 +#define current_fstag(cred,vp) (dx_current_fstag(vp->i_sb))
8263  #define current_test_flags(f)  (current->flags & (f))
8264  #define current_set_flags_nested(sp, f)                \
8265                 (*(sp) = current->flags, current->flags |= (f))
8266 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/linux-2.6/xfs_super.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_super.c
8267 --- linux-2.6.27.6/fs/xfs/linux-2.6/xfs_super.c 2008-11-17 18:07:34.000000000 +0100
8268 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/linux-2.6/xfs_super.c      2008-11-12 18:41:59.000000000 +0100
8269 @@ -147,6 +147,9 @@ xfs_args_allocate(
8270  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8271  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8272  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8273 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8274 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8275 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8276  
8277  /*
8278   * Table driven mount option parser.
8279 @@ -155,10 +158,14 @@ xfs_args_allocate(
8280   * in the future, too.
8281   */
8282  enum {
8283 +       Opt_tag, Opt_notag,
8284         Opt_barrier, Opt_nobarrier, Opt_err
8285  };
8286  
8287  static match_table_t tokens = {
8288 +       {Opt_tag, "tagxid"},
8289 +       {Opt_tag, "tag"},
8290 +       {Opt_notag, "notag"},
8291         {Opt_barrier, "barrier"},
8292         {Opt_nobarrier, "nobarrier"},
8293         {Opt_err, NULL}
8294 @@ -383,6 +390,19 @@ xfs_parseargs(
8295                 } else if (!strcmp(this_char, "irixsgid")) {
8296                         cmn_err(CE_WARN,
8297         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8298 +#ifndef CONFIG_TAGGING_NONE
8299 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8300 +                       args->flags2 |= XFSMNT2_TAGGED;
8301 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8302 +                       args->flags2 &= ~XFSMNT2_TAGGED;
8303 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8304 +                       args->flags2 |= XFSMNT2_TAGGED;
8305 +#endif
8306 +#ifdef CONFIG_PROPAGATE
8307 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8308 +                       /* use value */
8309 +                       args->flags2 |= XFSMNT2_TAGGED;
8310 +#endif
8311                 } else {
8312                         cmn_err(CE_WARN,
8313                                 "XFS: unknown mount option [%s].", this_char);
8314 @@ -1301,6 +1321,16 @@ xfs_fs_remount(
8315                 case Opt_nobarrier:
8316                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8317                         break;
8318 +               case Opt_tag:
8319 +                       if (!(sb->s_flags & MS_TAGGED)) {
8320 +                               printk(KERN_INFO
8321 +                                       "XFS: %s: tagging not permitted on remount.\n",
8322 +                                       sb->s_id);
8323 +                               return -EINVAL;
8324 +                       }
8325 +                       break;
8326 +               case Opt_notag:
8327 +                       break;
8328                 default:
8329                         /*
8330                          * Logically we would return an error here to prevent
8331 @@ -1555,6 +1585,9 @@ xfs_start_flags(
8332  
8333         if (ap->flags & XFSMNT_DMAPI)
8334                 mp->m_flags |= XFS_MOUNT_DMAPI;
8335 +
8336 +       if (ap->flags2 & XFSMNT2_TAGGED)
8337 +               mp->m_flags |= XFS_MOUNT_TAGGED;
8338         return 0;
8339  
8340  
8341 @@ -1749,6 +1782,9 @@ xfs_fs_fill_super(
8342  
8343         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
8344  
8345 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8346 +               sb->s_flags |= MS_TAGGED;
8347 +
8348         sb->s_dirt = 1;
8349         sb->s_magic = XFS_SB_MAGIC;
8350         sb->s_blocksize = mp->m_sb.sb_blocksize;
8351 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/quota/xfs_qm_syscalls.c
8352 --- linux-2.6.27.6/fs/xfs/quota/xfs_qm_syscalls.c       2008-10-13 14:52:06.000000000 +0200
8353 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/quota/xfs_qm_syscalls.c    2008-10-24 03:47:08.000000000 +0200
8354 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8355         uint            accflags;
8356         __int64_t       sbflags;
8357  
8358 -       if (!capable(CAP_SYS_ADMIN))
8359 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8360                 return XFS_ERROR(EPERM);
8361  
8362         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8363 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_clnt.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_clnt.h
8364 --- linux-2.6.27.6/fs/xfs/xfs_clnt.h    2008-10-13 14:52:06.000000000 +0200
8365 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_clnt.h 2008-10-13 14:54:20.000000000 +0200
8366 @@ -101,5 +101,6 @@ struct xfs_mount_args {
8367                                                  * I/O size in stat(2) */
8368  #define XFSMNT2_FILESTREAMS    0x00000002      /* enable the filestreams
8369                                                  * allocator */
8370 +#define XFSMNT2_TAGGED         0x10000000      /* context tagging */
8371  
8372  #endif /* __XFS_CLNT_H__ */
8373 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_dinode.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_dinode.h
8374 --- linux-2.6.27.6/fs/xfs/xfs_dinode.h  2008-07-13 23:51:29.000000000 +0200
8375 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_dinode.h       2008-11-12 18:41:59.000000000 +0100
8376 @@ -53,7 +53,9 @@ typedef struct xfs_dinode_core {
8377         __be32          di_gid;         /* owner's group id */
8378         __be32          di_nlink;       /* number of links to file */
8379         __be16          di_projid;      /* owner's project id */
8380 -       __u8            di_pad[8];      /* unused, zeroed space */
8381 +       __be16          di_tag;         /* context tagging */
8382 +       __be16          di_vflags;      /* vserver specific flags */
8383 +       __u8            di_pad[4];      /* unused, zeroed space */
8384         __be16          di_flushiter;   /* incremented on flush */
8385         xfs_timestamp_t di_atime;       /* time last accessed */
8386         xfs_timestamp_t di_mtime;       /* time last modified */
8387 @@ -136,7 +138,9 @@ typedef struct xfs_dinode
8388  #define        XFS_DI_NEXT_UNLINKED    0x1000000
8389  #define        XFS_DI_U                0x2000000
8390  #define        XFS_DI_A                0x4000000
8391 -#define        XFS_DI_NUM_BITS         27
8392 +#define        XFS_DI_TAG              0x8000000
8393 +#define        XFS_DI_VFLAGS           0x10000000
8394 +#define        XFS_DI_NUM_BITS         29
8395  #define        XFS_DI_ALL_BITS         ((1 << XFS_DI_NUM_BITS) - 1)
8396  #define        XFS_DI_CORE_BITS        (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
8397  
8398 @@ -223,6 +227,8 @@ typedef enum xfs_dinode_fmt
8399  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8400  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8401  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8402 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8403 +
8404  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8405  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8406  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8407 @@ -238,6 +244,7 @@ typedef enum xfs_dinode_fmt
8408  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8409  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8410  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8411 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8412  
8413  #ifdef CONFIG_XFS_RT
8414  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8415 @@ -250,6 +257,10 @@ typedef enum xfs_dinode_fmt
8416          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8417          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8418          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8419 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8420 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8421 +        XFS_DIFLAG_IXUNLINK)
8422 +
8423 +#define XFS_DIVFLAG_BARRIER    0x01
8424 +#define XFS_DIVFLAG_COW                0x02
8425  
8426  #endif /* __XFS_DINODE_H__ */
8427 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_fs.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_fs.h
8428 --- linux-2.6.27.6/fs/xfs/xfs_fs.h      2008-10-13 14:52:06.000000000 +0200
8429 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_fs.h   2008-10-13 14:54:20.000000000 +0200
8430 @@ -67,6 +67,9 @@ struct fsxattr {
8431  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8432  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8433  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8434 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8435 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8436 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8437  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8438  
8439  /*
8440 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8441         __s32           bs_extents;     /* number of extents            */
8442         __u32           bs_gen;         /* generation count             */
8443         __u16           bs_projid;      /* project id                   */
8444 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8445 +       __u16           bs_tag;         /* context tagging              */
8446 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8447         __u32           bs_dmevmask;    /* DMIG event mask              */
8448         __u16           bs_dmstate;     /* DMIG state info              */
8449         __u16           bs_aextents;    /* attribute number of extents  */
8450 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_ialloc.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_ialloc.c
8451 --- linux-2.6.27.6/fs/xfs/xfs_ialloc.c  2008-07-13 23:51:29.000000000 +0200
8452 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_ialloc.c       2008-11-12 18:41:59.000000000 +0100
8453 @@ -84,6 +84,8 @@ xfs_ialloc_log_di(
8454                 offsetof(xfs_dinode_t, di_next_unlinked),
8455                 offsetof(xfs_dinode_t, di_u),
8456                 offsetof(xfs_dinode_t, di_a),
8457 +               offsetof(xfs_dinode_core_t, di_tag),
8458 +               offsetof(xfs_dinode_core_t, di_vflags),
8459                 sizeof(xfs_dinode_t)
8460         };
8461  
8462 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_inode.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_inode.c
8463 --- linux-2.6.27.6/fs/xfs/xfs_inode.c   2008-10-13 14:52:06.000000000 +0200
8464 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_inode.c        2008-11-12 18:42:00.000000000 +0100
8465 @@ -249,6 +249,7 @@ xfs_inotobp(
8466         return 0;
8467  }
8468  
8469 +#include <linux/vs_tag.h>
8470  
8471  /*
8472   * This routine is called to map an inode to the buffer containing
8473 @@ -660,15 +661,25 @@ xfs_iformat_btree(
8474  void
8475  xfs_dinode_from_disk(
8476         xfs_icdinode_t          *to,
8477 -       xfs_dinode_core_t       *from)
8478 +       xfs_dinode_core_t       *from,
8479 +       int tagged)
8480  {
8481 +       uint32_t uid, gid, tag;
8482 +
8483         to->di_magic = be16_to_cpu(from->di_magic);
8484         to->di_mode = be16_to_cpu(from->di_mode);
8485         to->di_version = from ->di_version;
8486         to->di_format = from->di_format;
8487         to->di_onlink = be16_to_cpu(from->di_onlink);
8488 -       to->di_uid = be32_to_cpu(from->di_uid);
8489 -       to->di_gid = be32_to_cpu(from->di_gid);
8490 +
8491 +       uid = be32_to_cpu(from->di_uid);
8492 +       gid = be32_to_cpu(from->di_gid);
8493 +       tag = be16_to_cpu(from->di_tag);
8494 +
8495 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8496 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8497 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8498 +
8499         to->di_nlink = be32_to_cpu(from->di_nlink);
8500         to->di_projid = be16_to_cpu(from->di_projid);
8501         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8502 @@ -689,21 +700,26 @@ xfs_dinode_from_disk(
8503         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8504         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8505         to->di_flags    = be16_to_cpu(from->di_flags);
8506 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8507         to->di_gen      = be32_to_cpu(from->di_gen);
8508  }
8509  
8510  void
8511  xfs_dinode_to_disk(
8512         xfs_dinode_core_t       *to,
8513 -       xfs_icdinode_t          *from)
8514 +       xfs_icdinode_t          *from,
8515 +       int tagged)
8516  {
8517         to->di_magic = cpu_to_be16(from->di_magic);
8518         to->di_mode = cpu_to_be16(from->di_mode);
8519         to->di_version = from ->di_version;
8520         to->di_format = from->di_format;
8521         to->di_onlink = cpu_to_be16(from->di_onlink);
8522 -       to->di_uid = cpu_to_be32(from->di_uid);
8523 -       to->di_gid = cpu_to_be32(from->di_gid);
8524 +
8525 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8526 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8527 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8528 +
8529         to->di_nlink = cpu_to_be32(from->di_nlink);
8530         to->di_projid = cpu_to_be16(from->di_projid);
8531         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8532 @@ -724,12 +740,14 @@ xfs_dinode_to_disk(
8533         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8534         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8535         to->di_flags = cpu_to_be16(from->di_flags);
8536 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8537         to->di_gen = cpu_to_be32(from->di_gen);
8538  }
8539  
8540  STATIC uint
8541  _xfs_dic2xflags(
8542 -       __uint16_t              di_flags)
8543 +       __uint16_t              di_flags,
8544 +       __uint16_t              di_vflags)
8545  {
8546         uint                    flags = 0;
8547  
8548 @@ -740,6 +758,8 @@ _xfs_dic2xflags(
8549                         flags |= XFS_XFLAG_PREALLOC;
8550                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8551                         flags |= XFS_XFLAG_IMMUTABLE;
8552 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8553 +                       flags |= XFS_XFLAG_IXUNLINK;
8554                 if (di_flags & XFS_DIFLAG_APPEND)
8555                         flags |= XFS_XFLAG_APPEND;
8556                 if (di_flags & XFS_DIFLAG_SYNC)
8557 @@ -764,6 +784,10 @@ _xfs_dic2xflags(
8558                         flags |= XFS_XFLAG_FILESTREAM;
8559         }
8560  
8561 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8562 +               flags |= FS_BARRIER_FL;
8563 +       if (di_vflags & XFS_DIVFLAG_COW)
8564 +               flags |= FS_COW_FL;
8565         return flags;
8566  }
8567  
8568 @@ -773,7 +797,7 @@ xfs_ip2xflags(
8569  {
8570         xfs_icdinode_t          *dic = &ip->i_d;
8571  
8572 -       return _xfs_dic2xflags(dic->di_flags) |
8573 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8574                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8575  }
8576  
8577 @@ -783,7 +807,8 @@ xfs_dic2xflags(
8578  {
8579         xfs_dinode_core_t       *dic = &dip->di_core;
8580  
8581 -       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
8582 +       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags),
8583 +                               be16_to_cpu(dic->di_vflags)) |
8584                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8585  }
8586  
8587 @@ -878,7 +903,8 @@ xfs_iread(
8588          * Otherwise, just get the truly permanent information.
8589          */
8590         if (dip->di_core.di_mode) {
8591 -               xfs_dinode_from_disk(&ip->i_d, &dip->di_core);
8592 +               xfs_dinode_from_disk(&ip->i_d, &dip->di_core,
8593 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8594                 error = xfs_iformat(ip, dip);
8595                 if (error)  {
8596                         kmem_zone_free(xfs_inode_zone, ip);
8597 @@ -1083,6 +1109,7 @@ xfs_ialloc(
8598         ASSERT(ip->i_d.di_nlink == nlink);
8599         ip->i_d.di_uid = current_fsuid();
8600         ip->i_d.di_gid = current_fsgid();
8601 +       ip->i_d.di_tag = current_fstag(cr, ip->i_vnode);
8602         ip->i_d.di_projid = prid;
8603         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8604  
8605 @@ -1143,6 +1170,7 @@ xfs_ialloc(
8606         ip->i_d.di_dmevmask = 0;
8607         ip->i_d.di_dmstate = 0;
8608         ip->i_d.di_flags = 0;
8609 +       ip->i_d.di_vflags = 0;
8610         flags = XFS_ILOG_CORE;
8611         switch (mode & S_IFMT) {
8612         case S_IFIFO:
8613 @@ -2249,6 +2277,7 @@ xfs_ifree(
8614         }
8615         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8616         ip->i_d.di_flags = 0;
8617 +       ip->i_d.di_vflags = 0;
8618         ip->i_d.di_dmevmask = 0;
8619         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8620         ip->i_df.if_ext_max =
8621 @@ -3342,7 +3371,8 @@ xfs_iflush_int(
8622          * because if the inode is dirty at all the core must
8623          * be.
8624          */
8625 -       xfs_dinode_to_disk(&dip->di_core, &ip->i_d);
8626 +       xfs_dinode_to_disk(&dip->di_core, &ip->i_d,
8627 +               mp->m_flags & XFS_MOUNT_TAGGED);
8628  
8629         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8630         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8631 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_inode.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_inode.h
8632 --- linux-2.6.27.6/fs/xfs/xfs_inode.h   2008-10-13 14:52:06.000000000 +0200
8633 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_inode.h        2008-11-12 18:42:03.000000000 +0100
8634 @@ -173,7 +173,9 @@ typedef struct xfs_icdinode {
8635         __uint32_t      di_gid;         /* owner's group id */
8636         __uint32_t      di_nlink;       /* number of links to file */
8637         __uint16_t      di_projid;      /* owner's project id */
8638 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8639 +       __uint16_t      di_tag;         /* context tagging */
8640 +       __uint16_t      di_vflags;      /* vserver specific flags */
8641 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8642         __uint16_t      di_flushiter;   /* incremented on flush */
8643         xfs_ictimestamp_t di_atime;     /* time last accessed */
8644         xfs_ictimestamp_t di_mtime;     /* time last modified */
8645 @@ -500,9 +502,9 @@ int         xfs_ialloc(struct xfs_trans *, xfs_
8646                            xfs_nlink_t, xfs_dev_t, struct cred *, xfs_prid_t,
8647                            int, struct xfs_buf **, boolean_t *, xfs_inode_t **);
8648  void           xfs_dinode_from_disk(struct xfs_icdinode *,
8649 -                                    struct xfs_dinode_core *);
8650 +                                    struct xfs_dinode_core *, int tagged);
8651  void           xfs_dinode_to_disk(struct xfs_dinode_core *,
8652 -                                  struct xfs_icdinode *);
8653 +                                  struct xfs_icdinode *, int tagged);
8654  
8655  uint           xfs_ip2xflags(struct xfs_inode *);
8656  uint           xfs_dic2xflags(struct xfs_dinode *);
8657 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_itable.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_itable.c
8658 --- linux-2.6.27.6/fs/xfs/xfs_itable.c  2008-10-13 14:52:06.000000000 +0200
8659 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_itable.c       2008-11-12 18:42:03.000000000 +0100
8660 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
8661         buf->bs_mode = dic->di_mode;
8662         buf->bs_uid = dic->di_uid;
8663         buf->bs_gid = dic->di_gid;
8664 +       buf->bs_tag = dic->di_tag;
8665         buf->bs_size = dic->di_size;
8666         vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
8667         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
8668 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_log_recover.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_log_recover.c
8669 --- linux-2.6.27.6/fs/xfs/xfs_log_recover.c     2008-10-13 14:52:06.000000000 +0200
8670 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_log_recover.c  2008-11-12 18:42:03.000000000 +0100
8671 @@ -2417,7 +2417,8 @@ xlog_recover_do_inode_trans(
8672  
8673         /* The core is in in-core format */
8674         xfs_dinode_to_disk(&dip->di_core,
8675 -               (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8676 +               (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8677 +               mp->m_flags & XFS_MOUNT_TAGGED);
8678  
8679         /* the rest is in on-disk format */
8680         if (item->ri_buf[1].i_len > sizeof(xfs_dinode_core_t)) {
8681 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_mount.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_mount.h
8682 --- linux-2.6.27.6/fs/xfs/xfs_mount.h   2008-10-13 14:52:06.000000000 +0200
8683 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_mount.h        2008-10-13 14:54:20.000000000 +0200
8684 @@ -384,6 +384,7 @@ typedef struct xfs_mount {
8685                                                    allocator */
8686  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8687  
8688 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8689  
8690  /*
8691   * Default minimum read and write sizes.
8692 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_vnodeops.c linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_vnodeops.c
8693 --- linux-2.6.27.6/fs/xfs/xfs_vnodeops.c        2008-10-13 14:52:06.000000000 +0200
8694 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_vnodeops.c     2008-11-12 18:42:03.000000000 +0100
8695 @@ -75,6 +75,89 @@ xfs_open(
8696         return 0;
8697  }
8698  
8699 +STATIC void
8700 +xfs_get_inode_flags(
8701 +       xfs_inode_t     *ip)
8702 +{
8703 +       struct inode    *inode = VFS_I(ip);
8704 +       unsigned int    flags = inode->i_flags;
8705 +       unsigned int    vflags = inode->i_vflags;
8706 +
8707 +       if (flags & S_IMMUTABLE)
8708 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8709 +       else
8710 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8711 +       if (flags & S_IXUNLINK)
8712 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8713 +       else
8714 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8715 +
8716 +       if (vflags & V_BARRIER)
8717 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8718 +       else
8719 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8720 +       if (vflags & V_COW)
8721 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8722 +       else
8723 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8724 +}
8725 +
8726 +int
8727 +xfs_sync_xflags(
8728 +       xfs_inode_t             *ip)
8729 +{
8730 +       struct xfs_mount        *mp = ip->i_mount;
8731 +       struct xfs_trans        *tp;
8732 +       unsigned int            lock_flags = 0;
8733 +       int                     code;
8734 +
8735 +       xfs_itrace_entry(ip);
8736 +
8737 +       if (mp->m_flags & XFS_MOUNT_RDONLY)
8738 +               return XFS_ERROR(EROFS);
8739 +
8740 +       /*
8741 +        * we acquire the inode lock and do an error checking pass.
8742 +        */
8743 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8744 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8745 +       if (code)
8746 +               goto error_return;
8747 +
8748 +       lock_flags = XFS_ILOCK_EXCL;
8749 +       xfs_ilock(ip, lock_flags);
8750 +
8751 +       xfs_trans_ijoin(tp, ip, lock_flags);
8752 +       xfs_trans_ihold(tp, ip);
8753 +
8754 +       xfs_get_inode_flags(ip);
8755 +       // xfs_diflags_to_linux(ip);
8756 +
8757 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8758 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8759 +
8760 +       XFS_STATS_INC(xs_ig_attrchg);
8761 +
8762 +       /*
8763 +        * If this is a synchronous mount, make sure that the
8764 +        * transaction goes to disk before returning to the user.
8765 +        */
8766 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8767 +               xfs_trans_set_sync(tp);
8768 +       code = xfs_trans_commit(tp, 0);
8769 +       xfs_iunlock(ip, lock_flags);
8770 +
8771 +       if (code)
8772 +               return code;
8773 +       return 0;
8774 +
8775 + error_return:
8776 +       xfs_trans_cancel(tp, 0);
8777 +       if (lock_flags)
8778 +               xfs_iunlock(ip, lock_flags);
8779 +       return code;
8780 +}
8781 +
8782  int
8783  xfs_setattr(
8784         struct xfs_inode        *ip,
8785 @@ -91,6 +174,7 @@ xfs_setattr(
8786         uint                    commit_flags=0;
8787         uid_t                   uid=0, iuid=0;
8788         gid_t                   gid=0, igid=0;
8789 +       tag_t                   tag=0, itag=0;
8790         int                     timeflags = 0;
8791         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8792         int                     file_owner;
8793 @@ -238,7 +322,7 @@ xfs_setattr(
8794          * and can change the group id only to a group of which he
8795          * or she is a member.
8796          */
8797 -       if (mask & (ATTR_UID|ATTR_GID)) {
8798 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8799                 /*
8800                  * These IDs could have changed since we last looked at them.
8801                  * But, we're assured that if the ownership did change
8802 @@ -247,8 +331,10 @@ xfs_setattr(
8803                  */
8804                 iuid = ip->i_d.di_uid;
8805                 igid = ip->i_d.di_gid;
8806 +               itag = ip->i_d.di_tag;
8807                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8808                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8809 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8810  
8811                 /*
8812                  * CAP_CHOWN overrides the following restrictions:
8813 @@ -272,7 +358,9 @@ xfs_setattr(
8814                  * going to change.
8815                  */
8816                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8817 -                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
8818 +                   (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8819 +                   (XFS_IS_GQUOTA_ON(mp) && itag != tag)) {
8820 +                       /* TODO: handle tagging? */
8821                         ASSERT(tp);
8822                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
8823                                                 capable(CAP_FOWNER) ?
8824 @@ -461,7 +549,7 @@ xfs_setattr(
8825          * and can change the group id only to a group of which he
8826          * or she is a member.
8827          */
8828 -       if (mask & (ATTR_UID|ATTR_GID)) {
8829 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8830                 /*
8831                  * CAP_FSETID overrides the following restrictions:
8832                  *
8833 @@ -477,6 +565,10 @@ xfs_setattr(
8834                  * Change the ownerships and register quota modifications
8835                  * in the transaction.
8836                  */
8837 +               if (itag != tag) {
8838 +                       ip->i_d.di_tag = tag;
8839 +                       inode->i_tag = tag;
8840 +               }
8841                 if (iuid != uid) {
8842                         if (XFS_IS_UQUOTA_ON(mp)) {
8843                                 ASSERT(mask & ATTR_UID);
8844 diff -NurpP --minimal linux-2.6.27.6/fs/xfs/xfs_vnodeops.h linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_vnodeops.h
8845 --- linux-2.6.27.6/fs/xfs/xfs_vnodeops.h        2008-10-13 14:52:06.000000000 +0200
8846 +++ linux-2.6.27.6-vs2.3.0.36/fs/xfs/xfs_vnodeops.h     2008-11-12 18:42:03.000000000 +0100
8847 @@ -15,6 +15,7 @@ struct xfs_iomap;
8848  
8849  
8850  int xfs_open(struct xfs_inode *ip);
8851 +int xfs_sync_xflags(struct xfs_inode *ip);
8852  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags,
8853                 struct cred *credp);
8854  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8855 diff -NurpP --minimal linux-2.6.27.6/include/asm-generic/tlb.h linux-2.6.27.6-vs2.3.0.36/include/asm-generic/tlb.h
8856 --- linux-2.6.27.6/include/asm-generic/tlb.h    2008-07-13 23:51:29.000000000 +0200
8857 +++ linux-2.6.27.6-vs2.3.0.36/include/asm-generic/tlb.h 2008-10-13 14:54:20.000000000 +0200
8858 @@ -14,6 +14,7 @@
8859  #define _ASM_GENERIC__TLB_H
8860  
8861  #include <linux/swap.h>
8862 +#include <linux/vs_memory.h>
8863  #include <asm/pgalloc.h>
8864  #include <asm/tlbflush.h>
8865  
8866 diff -NurpP --minimal linux-2.6.27.6/include/asm-x86/unistd_64.h linux-2.6.27.6-vs2.3.0.36/include/asm-x86/unistd_64.h
8867 --- linux-2.6.27.6/include/asm-x86/unistd_64.h  2008-10-13 14:52:08.000000000 +0200
8868 +++ linux-2.6.27.6-vs2.3.0.36/include/asm-x86/unistd_64.h       2008-10-13 14:54:20.000000000 +0200
8869 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
8870  #define __NR_utimes                            235
8871  __SYSCALL(__NR_utimes, sys_utimes)
8872  #define __NR_vserver                           236
8873 -__SYSCALL(__NR_vserver, sys_ni_syscall)
8874 +__SYSCALL(__NR_vserver, sys_vserver)
8875  #define __NR_mbind                             237
8876  __SYSCALL(__NR_mbind, sys_mbind)
8877  #define __NR_set_mempolicy                     238
8878 diff -NurpP --minimal linux-2.6.27.6/include/linux/capability.h linux-2.6.27.6-vs2.3.0.36/include/linux/capability.h
8879 --- linux-2.6.27.6/include/linux/capability.h   2008-10-13 14:52:09.000000000 +0200
8880 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/capability.h        2008-10-13 14:54:20.000000000 +0200
8881 @@ -274,6 +274,7 @@ typedef struct kernel_cap_struct {
8882     arbitrary SCSI commands */
8883  /* Allow setting encryption key on loopback filesystem */
8884  /* Allow setting zone reclaim policy */
8885 +/* Allow the selection of a security context */
8886  
8887  #define CAP_SYS_ADMIN        21
8888  
8889 @@ -346,7 +347,13 @@ typedef struct kernel_cap_struct {
8890  
8891  #define CAP_MAC_ADMIN        33
8892  
8893 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8894 +/* Allow context manipulations */
8895 +/* Allow changing context info on files */
8896 +
8897 +#define CAP_CONTEXT         34
8898 +
8899 +
8900 +#define CAP_LAST_CAP         CAP_CONTEXT
8901  
8902  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8903  
8904 diff -NurpP --minimal linux-2.6.27.6/include/linux/devpts_fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/devpts_fs.h
8905 --- linux-2.6.27.6/include/linux/devpts_fs.h    2008-07-13 23:51:29.000000000 +0200
8906 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/devpts_fs.h 2008-10-13 14:54:20.000000000 +0200
8907 @@ -34,5 +34,4 @@ static inline void devpts_pty_kill(int n
8908  
8909  #endif
8910  
8911 -
8912  #endif /* _LINUX_DEVPTS_FS_H */
8913 diff -NurpP --minimal linux-2.6.27.6/include/linux/ext2_fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/ext2_fs.h
8914 --- linux-2.6.27.6/include/linux/ext2_fs.h      2008-10-13 14:52:09.000000000 +0200
8915 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/ext2_fs.h   2008-10-13 14:54:20.000000000 +0200
8916 @@ -189,8 +189,12 @@ struct ext2_group_desc
8917  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8918  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8919  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8920 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8921  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8922  
8923 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8924 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8925 +
8926  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8927  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8928  
8929 @@ -247,7 +251,7 @@ struct ext2_inode {
8930                 struct {
8931                         __u8    l_i_frag;       /* Fragment number */
8932                         __u8    l_i_fsize;      /* Fragment size */
8933 -                       __u16   i_pad1;
8934 +                       __u16   l_i_tag;        /* Context Tag */
8935                         __le16  l_i_uid_high;   /* these 2 fields    */
8936                         __le16  l_i_gid_high;   /* were reserved2[0] */
8937                         __u32   l_i_reserved2;
8938 @@ -279,6 +283,7 @@ struct ext2_inode {
8939  #define i_gid_low      i_gid
8940  #define i_uid_high     osd2.linux2.l_i_uid_high
8941  #define i_gid_high     osd2.linux2.l_i_gid_high
8942 +#define i_raw_tag      osd2.linux2.l_i_tag
8943  #define i_reserved2    osd2.linux2.l_i_reserved2
8944  #endif
8945  
8946 @@ -323,6 +328,7 @@ struct ext2_inode {
8947  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8948  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8949  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8950 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8951  
8952  
8953  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8954 diff -NurpP --minimal linux-2.6.27.6/include/linux/ext3_fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/ext3_fs.h
8955 --- linux-2.6.27.6/include/linux/ext3_fs.h      2008-10-13 14:52:09.000000000 +0200
8956 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/ext3_fs.h   2008-10-31 18:15:18.000000000 +0100
8957 @@ -173,10 +173,14 @@ struct ext3_group_desc
8958  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8959  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8960  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8961 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8962  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8963  
8964 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8965 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8966 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8967 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8968 +
8969 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8970 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8971  
8972  /*
8973   * Inode dynamic state flags
8974 @@ -292,7 +296,7 @@ struct ext3_inode {
8975                 struct {
8976                         __u8    l_i_frag;       /* Fragment number */
8977                         __u8    l_i_fsize;      /* Fragment size */
8978 -                       __u16   i_pad1;
8979 +                       __u16   l_i_tag;        /* Context Tag */
8980                         __le16  l_i_uid_high;   /* these 2 fields    */
8981                         __le16  l_i_gid_high;   /* were reserved2[0] */
8982                         __u32   l_i_reserved2;
8983 @@ -326,6 +330,7 @@ struct ext3_inode {
8984  #define i_gid_low      i_gid
8985  #define i_uid_high     osd2.linux2.l_i_uid_high
8986  #define i_gid_high     osd2.linux2.l_i_gid_high
8987 +#define i_raw_tag      osd2.linux2.l_i_tag
8988  #define i_reserved2    osd2.linux2.l_i_reserved2
8989  
8990  #elif defined(__GNU__)
8991 @@ -380,6 +385,7 @@ struct ext3_inode {
8992  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
8993  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
8994  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8995 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8996  
8997  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8998  #ifndef _LINUX_EXT2_FS_H
8999 @@ -822,6 +828,7 @@ struct buffer_head * ext3_bread (handle_
9000  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
9001         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
9002         int create, int extend_disksize);
9003 +extern int ext3_sync_flags(struct inode *inode);
9004  
9005  extern struct inode *ext3_iget(struct super_block *, unsigned long);
9006  extern int  ext3_write_inode (struct inode *, int);
9007 diff -NurpP --minimal linux-2.6.27.6/include/linux/fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/fs.h
9008 --- linux-2.6.27.6/include/linux/fs.h   2008-10-13 14:52:09.000000000 +0200
9009 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/fs.h        2008-10-31 18:18:18.000000000 +0100
9010 @@ -128,6 +128,9 @@ extern int dir_notify_enable;
9011  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
9012  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
9013  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
9014 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
9015 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
9016 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
9017  #define MS_ACTIVE      (1<<30)
9018  #define MS_NOUSER      (1<<31)
9019  
9020 @@ -154,6 +157,14 @@ extern int dir_notify_enable;
9021  #define S_NOCMTIME     128     /* Do not update file c/mtime */
9022  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
9023  #define S_PRIVATE      512     /* Inode is fs-internal */
9024 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
9025 +
9026 +/* Linux-VServer related Inode flags */
9027 +
9028 +#define V_VALID                1
9029 +#define V_XATTR                2
9030 +#define V_BARRIER      4       /* Barrier for chroot() */
9031 +#define V_COW          8       /* Copy on Write */
9032  
9033  /*
9034   * Note that nosuid etc flags are inode-specific: setting some file-system
9035 @@ -176,12 +187,15 @@ extern int dir_notify_enable;
9036  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
9037                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
9038  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
9039 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9040 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
9041 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9042 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
9043 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
9044  
9045  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
9046  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
9047  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
9048 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
9049 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
9050  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
9051  
9052  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
9053 @@ -189,6 +203,16 @@ extern int dir_notify_enable;
9054  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
9055  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
9056  
9057 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
9058 +
9059 +#ifdef CONFIG_VSERVER_COWBL
9060 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
9061 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
9062 +#else
9063 +#  define IS_COW(inode)                (0)
9064 +#  define IS_COW_LINK(inode)   (0)
9065 +#endif
9066 +
9067  /* the read-only stuff doesn't really belong here, but any other place is
9068     probably as bad and I don't want to create yet another include file. */
9069  
9070 @@ -262,11 +286,14 @@ extern int dir_notify_enable;
9071  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
9072  #define FS_EXTENT_FL                   0x00080000 /* Extents */
9073  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
9074 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
9075  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
9076  
9077 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
9078 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
9079 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
9080 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
9081  
9082 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
9083 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
9084  
9085  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
9086  #define SYNC_FILE_RANGE_WRITE          2
9087 @@ -337,6 +364,7 @@ typedef void (dio_iodone_t)(struct kiocb
9088  #define ATTR_KILL_PRIV (1 << 14)
9089  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
9090  #define ATTR_TIMES_SET (1 << 16)
9091 +#define ATTR_TAG       (1 << 17)
9092  
9093  /*
9094   * This is the Inode Attributes structure, used for notify_change().  It
9095 @@ -352,6 +380,7 @@ struct iattr {
9096         umode_t         ia_mode;
9097         uid_t           ia_uid;
9098         gid_t           ia_gid;
9099 +       tag_t           ia_tag;
9100         loff_t          ia_size;
9101         struct timespec ia_atime;
9102         struct timespec ia_mtime;
9103 @@ -365,6 +394,9 @@ struct iattr {
9104         struct file     *ia_file;
9105  };
9106  
9107 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
9108 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
9109 +
9110  /*
9111   * Includes for diskquotas.
9112   */
9113 @@ -626,7 +658,9 @@ struct inode {
9114         unsigned int            i_nlink;
9115         uid_t                   i_uid;
9116         gid_t                   i_gid;
9117 +       tag_t                   i_tag;
9118         dev_t                   i_rdev;
9119 +       dev_t                   i_mdev;
9120         u64                     i_version;
9121         loff_t                  i_size;
9122  #ifdef __NEED_I_SIZE_ORDERED
9123 @@ -674,7 +708,8 @@ struct inode {
9124         unsigned long           i_state;
9125         unsigned long           dirtied_when;   /* jiffies of first dirtying */
9126  
9127 -       unsigned int            i_flags;
9128 +       unsigned short          i_flags;
9129 +       unsigned short          i_vflags;
9130  
9131         atomic_t                i_writecount;
9132  #ifdef CONFIG_SECURITY
9133 @@ -761,12 +796,12 @@ static inline void i_size_write(struct i
9134  
9135  static inline unsigned iminor(const struct inode *inode)
9136  {
9137 -       return MINOR(inode->i_rdev);
9138 +       return MINOR(inode->i_mdev);
9139  }
9140  
9141  static inline unsigned imajor(const struct inode *inode)
9142  {
9143 -       return MAJOR(inode->i_rdev);
9144 +       return MAJOR(inode->i_mdev);
9145  }
9146  
9147  extern struct block_device *I_BDEV(struct inode *inode);
9148 @@ -824,6 +859,7 @@ struct file {
9149         loff_t                  f_pos;
9150         struct fown_struct      f_owner;
9151         unsigned int            f_uid, f_gid;
9152 +       xid_t                   f_xid;
9153         struct file_ra_state    f_ra;
9154  
9155         u64                     f_version;
9156 @@ -958,6 +994,7 @@ struct file_lock {
9157         struct file *fl_file;
9158         loff_t fl_start;
9159         loff_t fl_end;
9160 +       xid_t fl_xid;
9161  
9162         struct fasync_struct *  fl_fasync; /* for lease break notifications */
9163         unsigned long fl_break_time;    /* for nonblocking lease breaks */
9164 @@ -1287,6 +1324,7 @@ struct inode_operations {
9165         void (*truncate_range)(struct inode *, loff_t, loff_t);
9166         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
9167                           loff_t len);
9168 +       int (*sync_flags) (struct inode *);
9169  };
9170  
9171  struct seq_file;
9172 @@ -1302,6 +1340,7 @@ extern ssize_t vfs_readv(struct file *, 
9173                 unsigned long, loff_t *);
9174  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
9175                 unsigned long, loff_t *);
9176 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
9177  
9178  struct super_operations {
9179         struct inode *(*alloc_inode)(struct super_block *sb);
9180 @@ -1992,6 +2031,7 @@ extern int dcache_dir_open(struct inode 
9181  extern int dcache_dir_close(struct inode *, struct file *);
9182  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
9183  extern int dcache_readdir(struct file *, void *, filldir_t);
9184 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
9185  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
9186  extern int simple_statfs(struct dentry *, struct kstatfs *);
9187  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
9188 diff -NurpP --minimal linux-2.6.27.6/include/linux/if_tun.h linux-2.6.27.6-vs2.3.0.36/include/linux/if_tun.h
9189 --- linux-2.6.27.6/include/linux/if_tun.h       2008-10-13 14:52:09.000000000 +0200
9190 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/if_tun.h    2008-10-13 14:54:20.000000000 +0200
9191 @@ -46,6 +46,7 @@
9192  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
9193  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
9194  #define TUNGETIFF      _IOR('T', 210, unsigned int)
9195 +#define TUNSETNID     _IOW('T', 215, int)
9196  
9197  /* TUNSETIFF ifr flags */
9198  #define IFF_TUN                0x0001
9199 diff -NurpP --minimal linux-2.6.27.6/include/linux/init_task.h linux-2.6.27.6-vs2.3.0.36/include/linux/init_task.h
9200 --- linux-2.6.27.6/include/linux/init_task.h    2008-10-13 14:52:09.000000000 +0200
9201 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/init_task.h 2008-10-13 14:54:20.000000000 +0200
9202 @@ -179,6 +179,10 @@ extern struct group_info init_groups;
9203         INIT_IDS                                                        \
9204         INIT_TRACE_IRQFLAGS                                             \
9205         INIT_LOCKDEP                                                    \
9206 +       .xid            = 0,                                            \
9207 +       .vx_info        = NULL,                                         \
9208 +       .nid            = 0,                                            \
9209 +       .nx_info        = NULL,                                         \
9210  }
9211  
9212  
9213 diff -NurpP --minimal linux-2.6.27.6/include/linux/interrupt.h linux-2.6.27.6-vs2.3.0.36/include/linux/interrupt.h
9214 --- linux-2.6.27.6/include/linux/interrupt.h    2008-10-13 14:52:09.000000000 +0200
9215 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/interrupt.h 2008-10-13 14:54:20.000000000 +0200
9216 @@ -8,8 +8,8 @@
9217  #include <linux/preempt.h>
9218  #include <linux/cpumask.h>
9219  #include <linux/irqreturn.h>
9220 -#include <linux/hardirq.h>
9221  #include <linux/sched.h>
9222 +#include <linux/hardirq.h>
9223  #include <linux/irqflags.h>
9224  #include <asm/atomic.h>
9225  #include <asm/ptrace.h>
9226 diff -NurpP --minimal linux-2.6.27.6/include/linux/ipc.h linux-2.6.27.6-vs2.3.0.36/include/linux/ipc.h
9227 --- linux-2.6.27.6/include/linux/ipc.h  2008-07-13 23:51:29.000000000 +0200
9228 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/ipc.h       2008-10-13 14:54:20.000000000 +0200
9229 @@ -93,6 +93,7 @@ struct kern_ipc_perm
9230         key_t           key;
9231         uid_t           uid;
9232         gid_t           gid;
9233 +       xid_t           xid;
9234         uid_t           cuid;
9235         gid_t           cgid;
9236         mode_t          mode; 
9237 diff -NurpP --minimal linux-2.6.27.6/include/linux/Kbuild linux-2.6.27.6-vs2.3.0.36/include/linux/Kbuild
9238 --- linux-2.6.27.6/include/linux/Kbuild 2008-10-13 14:52:09.000000000 +0200
9239 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/Kbuild      2008-10-13 14:54:20.000000000 +0200
9240 @@ -369,3 +369,6 @@ unifdef-y += xattr.h
9241  unifdef-y += xfrm.h
9242  
9243  objhdr-y += version.h
9244 +
9245 +header-y += vserver/
9246 +
9247 diff -NurpP --minimal linux-2.6.27.6/include/linux/loop.h linux-2.6.27.6-vs2.3.0.36/include/linux/loop.h
9248 --- linux-2.6.27.6/include/linux/loop.h 2008-07-13 23:51:29.000000000 +0200
9249 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/loop.h      2008-10-13 14:54:20.000000000 +0200
9250 @@ -45,6 +45,7 @@ struct loop_device {
9251         struct loop_func_table *lo_encryption;
9252         __u32           lo_init[2];
9253         uid_t           lo_key_owner;   /* Who set the key */
9254 +       xid_t           lo_xid;
9255         int             (*ioctl)(struct loop_device *, int cmd, 
9256                                  unsigned long arg); 
9257  
9258 diff -NurpP --minimal linux-2.6.27.6/include/linux/magic.h linux-2.6.27.6-vs2.3.0.36/include/linux/magic.h
9259 --- linux-2.6.27.6/include/linux/magic.h        2008-07-13 23:51:29.000000000 +0200
9260 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/magic.h     2008-10-13 14:54:20.000000000 +0200
9261 @@ -3,7 +3,7 @@
9262  
9263  #define ADFS_SUPER_MAGIC       0xadf5
9264  #define AFFS_SUPER_MAGIC       0xadff
9265 -#define AFS_SUPER_MAGIC                0x5346414F
9266 +#define AFS_SUPER_MAGIC                0x5346414F
9267  #define AUTOFS_SUPER_MAGIC     0x0187
9268  #define CODA_SUPER_MAGIC       0x73757245
9269  #define EFS_SUPER_MAGIC                0x414A53
9270 @@ -26,6 +26,7 @@
9271  #define NFS_SUPER_MAGIC                0x6969
9272  #define OPENPROM_SUPER_MAGIC   0x9fa1
9273  #define PROC_SUPER_MAGIC       0x9fa0
9274 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9275  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9276  
9277  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9278 diff -NurpP --minimal linux-2.6.27.6/include/linux/major.h linux-2.6.27.6-vs2.3.0.36/include/linux/major.h
9279 --- linux-2.6.27.6/include/linux/major.h        2008-10-13 14:52:09.000000000 +0200
9280 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/major.h     2008-10-13 14:54:20.000000000 +0200
9281 @@ -15,6 +15,7 @@
9282  #define HD_MAJOR               IDE0_MAJOR
9283  #define PTY_SLAVE_MAJOR                3
9284  #define TTY_MAJOR              4
9285 +#define VROOT_MAJOR            4
9286  #define TTYAUX_MAJOR           5
9287  #define LP_MAJOR               6
9288  #define VCS_MAJOR              7
9289 diff -NurpP --minimal linux-2.6.27.6/include/linux/mm_types.h linux-2.6.27.6-vs2.3.0.36/include/linux/mm_types.h
9290 --- linux-2.6.27.6/include/linux/mm_types.h     2008-10-13 14:52:09.000000000 +0200
9291 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/mm_types.h  2008-10-13 14:54:20.000000000 +0200
9292 @@ -216,6 +216,7 @@ struct mm_struct {
9293  
9294         /* Architecture-specific MM context */
9295         mm_context_t context;
9296 +       struct vx_info *mm_vx_info;
9297  
9298         /* Swap token stuff */
9299         /*
9300 diff -NurpP --minimal linux-2.6.27.6/include/linux/mount.h linux-2.6.27.6-vs2.3.0.36/include/linux/mount.h
9301 --- linux-2.6.27.6/include/linux/mount.h        2008-10-13 14:52:09.000000000 +0200
9302 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/mount.h     2008-10-24 03:34:52.000000000 +0200
9303 @@ -37,6 +37,9 @@ struct mnt_namespace;
9304  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
9305  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
9306  
9307 +#define MNT_TAGID      0x10000
9308 +#define MNT_NOTAG      0x20000
9309 +
9310  struct vfsmount {
9311         struct list_head mnt_hash;
9312         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9313 @@ -71,6 +74,7 @@ struct vfsmount {
9314          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
9315          */
9316         atomic_t __mnt_writers;
9317 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9318  };
9319  
9320  static inline struct vfsmount *mntget(struct vfsmount *mnt)
9321 diff -NurpP --minimal linux-2.6.27.6/include/linux/net.h linux-2.6.27.6-vs2.3.0.36/include/linux/net.h
9322 --- linux-2.6.27.6/include/linux/net.h  2008-10-13 14:52:09.000000000 +0200
9323 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/net.h       2008-10-13 14:54:20.000000000 +0200
9324 @@ -68,6 +68,7 @@ struct net;
9325  #define SOCK_NOSPACE           2
9326  #define SOCK_PASSCRED          3
9327  #define SOCK_PASSSEC           4
9328 +#define SOCK_USER_SOCKET       5
9329  
9330  #ifndef ARCH_HAS_SOCKET_TYPES
9331  /**
9332 diff -NurpP --minimal linux-2.6.27.6/include/linux/nfs_mount.h linux-2.6.27.6-vs2.3.0.36/include/linux/nfs_mount.h
9333 --- linux-2.6.27.6/include/linux/nfs_mount.h    2008-07-13 23:51:29.000000000 +0200
9334 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/nfs_mount.h 2008-10-13 14:54:20.000000000 +0200
9335 @@ -63,6 +63,7 @@ struct nfs_mount_data {
9336  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9337  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9338  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9339 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9340 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9341 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9342  
9343  #endif
9344 diff -NurpP --minimal linux-2.6.27.6/include/linux/nsproxy.h linux-2.6.27.6-vs2.3.0.36/include/linux/nsproxy.h
9345 --- linux-2.6.27.6/include/linux/nsproxy.h      2008-10-13 14:52:09.000000000 +0200
9346 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/nsproxy.h   2008-10-13 14:54:20.000000000 +0200
9347 @@ -3,6 +3,7 @@
9348  
9349  #include <linux/spinlock.h>
9350  #include <linux/sched.h>
9351 +#include <linux/vserver/debug.h>
9352  
9353  struct mnt_namespace;
9354  struct uts_namespace;
9355 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9356  }
9357  
9358  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9359 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9360  void exit_task_namespaces(struct task_struct *tsk);
9361  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9362  void free_nsproxy(struct nsproxy *ns);
9363  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9364         struct fs_struct *);
9365  
9366 -static inline void put_nsproxy(struct nsproxy *ns)
9367 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9368 +
9369 +static inline void __get_nsproxy(struct nsproxy *ns,
9370 +       const char *_file, int _line)
9371  {
9372 -       if (atomic_dec_and_test(&ns->count)) {
9373 -               free_nsproxy(ns);
9374 -       }
9375 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9376 +               ns, atomic_read(&ns->count), _file, _line);
9377 +       atomic_inc(&ns->count);
9378  }
9379  
9380 -static inline void get_nsproxy(struct nsproxy *ns)
9381 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9382 +
9383 +static inline void __put_nsproxy(struct nsproxy *ns,
9384 +       const char *_file, int _line)
9385  {
9386 -       atomic_inc(&ns->count);
9387 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9388 +               ns, atomic_read(&ns->count), _file, _line);
9389 +       if (atomic_dec_and_test(&ns->count)) {
9390 +               free_nsproxy(ns);
9391 +       }
9392  }
9393  
9394  #ifdef CONFIG_CGROUP_NS
9395 diff -NurpP --minimal linux-2.6.27.6/include/linux/pid.h linux-2.6.27.6-vs2.3.0.36/include/linux/pid.h
9396 --- linux-2.6.27.6/include/linux/pid.h  2008-10-13 14:52:09.000000000 +0200
9397 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/pid.h       2008-10-13 14:54:20.000000000 +0200
9398 @@ -8,7 +8,8 @@ enum pid_type
9399         PIDTYPE_PID,
9400         PIDTYPE_PGID,
9401         PIDTYPE_SID,
9402 -       PIDTYPE_MAX
9403 +       PIDTYPE_MAX,
9404 +       PIDTYPE_REALPID
9405  };
9406  
9407  /*
9408 @@ -142,6 +143,7 @@ static inline pid_t pid_nr(struct pid *p
9409  }
9410  
9411  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9412 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9413  pid_t pid_vnr(struct pid *pid);
9414  
9415  #define do_each_pid_task(pid, type, task)                              \
9416 diff -NurpP --minimal linux-2.6.27.6/include/linux/proc_fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/proc_fs.h
9417 --- linux-2.6.27.6/include/linux/proc_fs.h      2008-10-13 14:52:09.000000000 +0200
9418 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/proc_fs.h   2008-10-13 14:54:20.000000000 +0200
9419 @@ -59,6 +59,7 @@ struct proc_dir_entry {
9420         nlink_t nlink;
9421         uid_t uid;
9422         gid_t gid;
9423 +       int vx_flags;
9424         loff_t size;
9425         const struct inode_operations *proc_iops;
9426         /*
9427 @@ -274,12 +275,18 @@ static inline void kclist_add(struct kco
9428  extern void kclist_add(struct kcore_list *, void *, size_t);
9429  #endif
9430  
9431 +struct vx_info;
9432 +struct nx_info;
9433 +
9434  union proc_op {
9435         int (*proc_get_link)(struct inode *, struct path *);
9436         int (*proc_read)(struct task_struct *task, char *page);
9437         int (*proc_show)(struct seq_file *m,
9438                 struct pid_namespace *ns, struct pid *pid,
9439                 struct task_struct *task);
9440 +       int (*proc_vs_read)(char *page);
9441 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9442 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9443  };
9444  
9445  struct ctl_table_header;
9446 @@ -287,6 +294,7 @@ struct ctl_table;
9447  
9448  struct proc_inode {
9449         struct pid *pid;
9450 +       int vx_flags;
9451         int fd;
9452         union proc_op op;
9453         struct proc_dir_entry *pde;
9454 diff -NurpP --minimal linux-2.6.27.6/include/linux/reiserfs_fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/reiserfs_fs.h
9455 --- linux-2.6.27.6/include/linux/reiserfs_fs.h  2008-10-13 14:52:09.000000000 +0200
9456 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/reiserfs_fs.h       2008-10-13 14:54:20.000000000 +0200
9457 @@ -837,6 +837,11 @@ struct stat_data_v1 {
9458  #define REISERFS_COMPR_FL     FS_COMPR_FL
9459  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9460  
9461 +/* unfortunately reiserfs sdattr is only 16 bit */
9462 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9463 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9464 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9465 +
9466  /* persistent flags that file inherits from the parent directory */
9467  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9468                                 REISERFS_SYNC_FL |      \
9469 @@ -846,6 +851,9 @@ struct stat_data_v1 {
9470                                 REISERFS_COMPR_FL |     \
9471                                 REISERFS_NOTAIL_FL )
9472  
9473 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9474 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9475 +
9476  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9477     address blocks) */
9478  struct stat_data {
9479 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
9480  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9481  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9482  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9483 +int reiserfs_sync_flags(struct inode *inode);
9484  
9485  /* namei.c */
9486  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9487 diff -NurpP --minimal linux-2.6.27.6/include/linux/reiserfs_fs_sb.h linux-2.6.27.6-vs2.3.0.36/include/linux/reiserfs_fs_sb.h
9488 --- linux-2.6.27.6/include/linux/reiserfs_fs_sb.h       2008-10-13 14:52:09.000000000 +0200
9489 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/reiserfs_fs_sb.h    2008-10-13 14:54:20.000000000 +0200
9490 @@ -455,6 +455,7 @@ enum reiserfs_mount_options {
9491         REISERFS_POSIXACL,
9492         REISERFS_BARRIER_NONE,
9493         REISERFS_BARRIER_FLUSH,
9494 +       REISERFS_TAGGED,
9495  
9496         /* Actions on error */
9497         REISERFS_ERROR_PANIC,
9498 diff -NurpP --minimal linux-2.6.27.6/include/linux/sched.h linux-2.6.27.6-vs2.3.0.36/include/linux/sched.h
9499 --- linux-2.6.27.6/include/linux/sched.h        2008-11-17 18:07:34.000000000 +0100
9500 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/sched.h     2008-11-17 18:20:41.000000000 +0100
9501 @@ -71,7 +71,6 @@ struct sched_param {
9502  #include <linux/fs_struct.h>
9503  #include <linux/compiler.h>
9504  #include <linux/completion.h>
9505 -#include <linux/pid.h>
9506  #include <linux/percpu.h>
9507  #include <linux/topology.h>
9508  #include <linux/proportions.h>
9509 @@ -88,6 +87,7 @@ struct sched_param {
9510  #include <linux/kobject.h>
9511  #include <linux/latencytop.h>
9512  #include <linux/cred.h>
9513 +#include <linux/pid.h>
9514  
9515  #include <asm/processor.h>
9516  
9517 @@ -357,25 +357,27 @@ extern void arch_unmap_area_topdown(stru
9518   * The mm counters are not protected by its page_table_lock,
9519   * so must be incremented atomically.
9520   */
9521 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9522 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9523 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9524 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9525 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9526 -
9527 +#define __set_mm_counter(mm, member, value) \
9528 +       atomic_long_set(&(mm)->_##member, value)
9529 +#define get_mm_counter(mm, member) \
9530 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9531  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
9532  /*
9533   * The mm counters are protected by its page_table_lock,
9534   * so can be incremented directly.
9535   */
9536 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9537 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9538  #define get_mm_counter(mm, member) ((mm)->_##member)
9539 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9540 -#define inc_mm_counter(mm, member) (mm)->_##member++
9541 -#define dec_mm_counter(mm, member) (mm)->_##member--
9542  
9543  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
9544  
9545 +#define set_mm_counter(mm, member, value) \
9546 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9547 +#define add_mm_counter(mm, member, value) \
9548 +       vx_ ## member ## pages_add((mm), (value))
9549 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9550 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9551 +
9552  #define get_mm_rss(mm)                                 \
9553         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9554  #define update_hiwater_rss(mm) do {                    \
9555 @@ -1196,6 +1198,14 @@ struct task_struct {
9556  #endif
9557         seccomp_t seccomp;
9558  
9559 +/* vserver context data */
9560 +       struct vx_info *vx_info;
9561 +       struct nx_info *nx_info;
9562 +
9563 +       xid_t xid;
9564 +       nid_t nid;
9565 +       tag_t tag;
9566 +
9567  /* Thread group tracking */
9568         u32 parent_exec_id;
9569         u32 self_exec_id;
9570 @@ -1382,6 +1392,11 @@ struct pid_namespace;
9571   * see also pid_nr() etc in include/linux/pid.h
9572   */
9573  
9574 +#include <linux/vserver/base.h>
9575 +#include <linux/vserver/context.h>
9576 +#include <linux/vserver/debug.h>
9577 +#include <linux/vserver/pid.h>
9578 +
9579  static inline pid_t task_pid_nr(struct task_struct *tsk)
9580  {
9581         return tsk->pid;
9582 @@ -1391,7 +1406,7 @@ pid_t task_pid_nr_ns(struct task_struct 
9583  
9584  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9585  {
9586 -       return pid_vnr(task_pid(tsk));
9587 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
9588  }
9589  
9590  
9591 @@ -1404,7 +1419,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9592  
9593  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9594  {
9595 -       return pid_vnr(task_tgid(tsk));
9596 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9597  }
9598  
9599  
9600 diff -NurpP --minimal linux-2.6.27.6/include/linux/shmem_fs.h linux-2.6.27.6-vs2.3.0.36/include/linux/shmem_fs.h
9601 --- linux-2.6.27.6/include/linux/shmem_fs.h     2008-10-13 14:52:09.000000000 +0200
9602 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/shmem_fs.h  2008-10-13 14:54:20.000000000 +0200
9603 @@ -8,6 +8,9 @@
9604  
9605  #define SHMEM_NR_DIRECT 16
9606  
9607 +#define TMPFS_SUPER_MAGIC      0x01021994
9608 +
9609 +
9610  struct shmem_inode_info {
9611         spinlock_t              lock;
9612         unsigned long           flags;
9613 diff -NurpP --minimal linux-2.6.27.6/include/linux/stat.h linux-2.6.27.6-vs2.3.0.36/include/linux/stat.h
9614 --- linux-2.6.27.6/include/linux/stat.h 2008-07-13 23:51:29.000000000 +0200
9615 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/stat.h      2008-10-13 14:54:20.000000000 +0200
9616 @@ -66,6 +66,7 @@ struct kstat {
9617         unsigned int    nlink;
9618         uid_t           uid;
9619         gid_t           gid;
9620 +       tag_t           tag;
9621         dev_t           rdev;
9622         loff_t          size;
9623         struct timespec  atime;
9624 diff -NurpP --minimal linux-2.6.27.6/include/linux/sunrpc/auth.h linux-2.6.27.6-vs2.3.0.36/include/linux/sunrpc/auth.h
9625 --- linux-2.6.27.6/include/linux/sunrpc/auth.h  2008-07-13 23:51:29.000000000 +0200
9626 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/sunrpc/auth.h       2008-10-13 14:54:20.000000000 +0200
9627 @@ -25,6 +25,7 @@
9628  struct auth_cred {
9629         uid_t   uid;
9630         gid_t   gid;
9631 +       tag_t   tag;
9632         struct group_info *group_info;
9633         unsigned char machine_cred : 1;
9634  };
9635 diff -NurpP --minimal linux-2.6.27.6/include/linux/sunrpc/clnt.h linux-2.6.27.6-vs2.3.0.36/include/linux/sunrpc/clnt.h
9636 --- linux-2.6.27.6/include/linux/sunrpc/clnt.h  2008-10-13 14:52:09.000000000 +0200
9637 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/sunrpc/clnt.h       2008-10-13 14:54:20.000000000 +0200
9638 @@ -43,7 +43,8 @@ struct rpc_clnt {
9639         unsigned int            cl_softrtry : 1,/* soft timeouts */
9640                                 cl_discrtry : 1,/* disconnect before retry */
9641                                 cl_autobind : 1,/* use getport() */
9642 -                               cl_chatty   : 1;/* be verbose */
9643 +                               cl_chatty   : 1,/* be verbose */
9644 +                               cl_tag      : 1;/* context tagging */
9645  
9646         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9647         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9648 diff -NurpP --minimal linux-2.6.27.6/include/linux/syscalls.h linux-2.6.27.6-vs2.3.0.36/include/linux/syscalls.h
9649 --- linux-2.6.27.6/include/linux/syscalls.h     2008-10-13 14:52:09.000000000 +0200
9650 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/syscalls.h  2008-10-13 14:54:20.000000000 +0200
9651 @@ -295,6 +295,8 @@ asmlinkage long sys_symlink(const char _
9652  asmlinkage long sys_unlink(const char __user *pathname);
9653  asmlinkage long sys_rename(const char __user *oldname,
9654                                 const char __user *newname);
9655 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9656 +                               umode_t mode);
9657  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9658  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9659  
9660 diff -NurpP --minimal linux-2.6.27.6/include/linux/sysctl.h linux-2.6.27.6-vs2.3.0.36/include/linux/sysctl.h
9661 --- linux-2.6.27.6/include/linux/sysctl.h       2008-10-13 14:52:09.000000000 +0200
9662 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/sysctl.h    2008-10-13 14:54:20.000000000 +0200
9663 @@ -70,6 +70,7 @@ enum
9664         CTL_ABI=9,              /* Binary emulation */
9665         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9666         CTL_ARLAN=254,          /* arlan wireless driver */
9667 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9668         CTL_S390DBF=5677,       /* s390 debug */
9669         CTL_SUNRPC=7249,        /* sunrpc debug */
9670         CTL_PM=9899,            /* frv power management */
9671 @@ -104,6 +105,7 @@ enum
9672  
9673         KERN_PANIC=15,          /* int: panic timeout */
9674         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9675 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9676  
9677         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9678         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9679 diff -NurpP --minimal linux-2.6.27.6/include/linux/sysfs.h linux-2.6.27.6-vs2.3.0.36/include/linux/sysfs.h
9680 --- linux-2.6.27.6/include/linux/sysfs.h        2008-10-13 14:52:09.000000000 +0200
9681 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/sysfs.h     2008-10-13 14:54:20.000000000 +0200
9682 @@ -17,6 +17,8 @@
9683  #include <linux/list.h>
9684  #include <asm/atomic.h>
9685  
9686 +#define SYSFS_SUPER_MAGIC      0x62656572
9687 +
9688  struct kobject;
9689  struct module;
9690  
9691 diff -NurpP --minimal linux-2.6.27.6/include/linux/time.h linux-2.6.27.6-vs2.3.0.36/include/linux/time.h
9692 --- linux-2.6.27.6/include/linux/time.h 2008-07-13 23:51:29.000000000 +0200
9693 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/time.h      2008-10-13 14:54:20.000000000 +0200
9694 @@ -179,6 +179,9 @@ static __always_inline void timespec_add
9695         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9696         a->tv_nsec = ns;
9697  }
9698 +
9699 +#include <linux/vs_time.h>
9700 +
9701  #endif /* __KERNEL__ */
9702  
9703  #define NFDBITS                        __NFDBITS
9704 diff -NurpP --minimal linux-2.6.27.6/include/linux/types.h linux-2.6.27.6-vs2.3.0.36/include/linux/types.h
9705 --- linux-2.6.27.6/include/linux/types.h        2008-07-13 23:51:29.000000000 +0200
9706 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/types.h     2008-10-13 14:54:20.000000000 +0200
9707 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9708  typedef __kernel_gid32_t       gid_t;
9709  typedef __kernel_uid16_t        uid16_t;
9710  typedef __kernel_gid16_t        gid16_t;
9711 +typedef unsigned int           xid_t;
9712 +typedef unsigned int           nid_t;
9713 +typedef unsigned int           tag_t;
9714  
9715  typedef unsigned long          uintptr_t;
9716  
9717 diff -NurpP --minimal linux-2.6.27.6/include/linux/vroot.h linux-2.6.27.6-vs2.3.0.36/include/linux/vroot.h
9718 --- linux-2.6.27.6/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9719 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vroot.h     2008-10-13 14:54:20.000000000 +0200
9720 @@ -0,0 +1,51 @@
9721 +
9722 +/*
9723 + * include/linux/vroot.h
9724 + *
9725 + * written by Herbert Pötzl, 9/11/2002
9726 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9727 + *
9728 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9729 + * Redistribution of this file is permitted under the
9730 + * GNU General Public License.
9731 + */
9732 +
9733 +#ifndef _LINUX_VROOT_H
9734 +#define _LINUX_VROOT_H
9735 +
9736 +
9737 +#ifdef __KERNEL__
9738 +
9739 +/* Possible states of device */
9740 +enum {
9741 +       Vr_unbound,
9742 +       Vr_bound,
9743 +};
9744 +
9745 +struct vroot_device {
9746 +       int             vr_number;
9747 +       int             vr_refcnt;
9748 +
9749 +       struct semaphore        vr_ctl_mutex;
9750 +       struct block_device    *vr_device;
9751 +       int                     vr_state;
9752 +};
9753 +
9754 +
9755 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9756 +
9757 +extern int register_vroot_grb(vroot_grb_func *);
9758 +extern int unregister_vroot_grb(vroot_grb_func *);
9759 +
9760 +#endif /* __KERNEL__ */
9761 +
9762 +#define MAX_VROOT_DEFAULT      8
9763 +
9764 +/*
9765 + * IOCTL commands --- we will commandeer 0x56 ('V')
9766 + */
9767 +
9768 +#define VROOT_SET_DEV          0x5600
9769 +#define VROOT_CLR_DEV          0x5601
9770 +
9771 +#endif /* _LINUX_VROOT_H */
9772 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_base.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_base.h
9773 --- linux-2.6.27.6/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9774 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_base.h   2008-10-13 14:54:20.000000000 +0200
9775 @@ -0,0 +1,10 @@
9776 +#ifndef _VS_BASE_H
9777 +#define _VS_BASE_H
9778 +
9779 +#include "vserver/base.h"
9780 +#include "vserver/check.h"
9781 +#include "vserver/debug.h"
9782 +
9783 +#else
9784 +#warning duplicate inclusion
9785 +#endif
9786 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_context.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_context.h
9787 --- linux-2.6.27.6/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9788 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_context.h        2008-10-13 14:54:20.000000000 +0200
9789 @@ -0,0 +1,227 @@
9790 +#ifndef _VS_CONTEXT_H
9791 +#define _VS_CONTEXT_H
9792 +
9793 +#include "vserver/base.h"
9794 +#include "vserver/check.h"
9795 +#include "vserver/context.h"
9796 +#include "vserver/history.h"
9797 +#include "vserver/debug.h"
9798 +
9799 +#include <linux/sched.h>
9800 +
9801 +
9802 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9803 +
9804 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9805 +       const char *_file, int _line, void *_here)
9806 +{
9807 +       if (!vxi)
9808 +               return NULL;
9809 +
9810 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9811 +               vxi, vxi ? vxi->vx_id : 0,
9812 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9813 +               _file, _line);
9814 +       __vxh_get_vx_info(vxi, _here);
9815 +
9816 +       atomic_inc(&vxi->vx_usecnt);
9817 +       return vxi;
9818 +}
9819 +
9820 +
9821 +extern void free_vx_info(struct vx_info *);
9822 +
9823 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9824 +
9825 +static inline void __put_vx_info(struct vx_info *vxi,
9826 +       const char *_file, int _line, void *_here)
9827 +{
9828 +       if (!vxi)
9829 +               return;
9830 +
9831 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9832 +               vxi, vxi ? vxi->vx_id : 0,
9833 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9834 +               _file, _line);
9835 +       __vxh_put_vx_info(vxi, _here);
9836 +
9837 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9838 +               free_vx_info(vxi);
9839 +}
9840 +
9841 +
9842 +#define init_vx_info(p, i) \
9843 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9844 +
9845 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9846 +       const char *_file, int _line, void *_here)
9847 +{
9848 +       if (vxi) {
9849 +               vxlprintk(VXD_CBIT(xid, 3),
9850 +                       "init_vx_info(%p[#%d.%d])",
9851 +                       vxi, vxi ? vxi->vx_id : 0,
9852 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9853 +                       _file, _line);
9854 +               __vxh_init_vx_info(vxi, vxp, _here);
9855 +
9856 +               atomic_inc(&vxi->vx_usecnt);
9857 +       }
9858 +       *vxp = vxi;
9859 +}
9860 +
9861 +
9862 +#define set_vx_info(p, i) \
9863 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9864 +
9865 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9866 +       const char *_file, int _line, void *_here)
9867 +{
9868 +       struct vx_info *vxo;
9869 +
9870 +       if (!vxi)
9871 +               return;
9872 +
9873 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9874 +               vxi, vxi ? vxi->vx_id : 0,
9875 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9876 +               _file, _line);
9877 +       __vxh_set_vx_info(vxi, vxp, _here);
9878 +
9879 +       atomic_inc(&vxi->vx_usecnt);
9880 +       vxo = xchg(vxp, vxi);
9881 +       BUG_ON(vxo);
9882 +}
9883 +
9884 +
9885 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9886 +
9887 +static inline void __clr_vx_info(struct vx_info **vxp,
9888 +       const char *_file, int _line, void *_here)
9889 +{
9890 +       struct vx_info *vxo;
9891 +
9892 +       vxo = xchg(vxp, NULL);
9893 +       if (!vxo)
9894 +               return;
9895 +
9896 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9897 +               vxo, vxo ? vxo->vx_id : 0,
9898 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9899 +               _file, _line);
9900 +       __vxh_clr_vx_info(vxo, vxp, _here);
9901 +
9902 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9903 +               free_vx_info(vxo);
9904 +}
9905 +
9906 +
9907 +#define claim_vx_info(v, p) \
9908 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9909 +
9910 +static inline void __claim_vx_info(struct vx_info *vxi,
9911 +       struct task_struct *task,
9912 +       const char *_file, int _line, void *_here)
9913 +{
9914 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9915 +               vxi, vxi ? vxi->vx_id : 0,
9916 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9917 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9918 +               task, _file, _line);
9919 +       __vxh_claim_vx_info(vxi, task, _here);
9920 +
9921 +       atomic_inc(&vxi->vx_tasks);
9922 +}
9923 +
9924 +
9925 +extern void unhash_vx_info(struct vx_info *);
9926 +
9927 +#define release_vx_info(v, p) \
9928 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9929 +
9930 +static inline void __release_vx_info(struct vx_info *vxi,
9931 +       struct task_struct *task,
9932 +       const char *_file, int _line, void *_here)
9933 +{
9934 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9935 +               vxi, vxi ? vxi->vx_id : 0,
9936 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9937 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9938 +               task, _file, _line);
9939 +       __vxh_release_vx_info(vxi, task, _here);
9940 +
9941 +       might_sleep();
9942 +
9943 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9944 +               unhash_vx_info(vxi);
9945 +}
9946 +
9947 +
9948 +#define task_get_vx_info(p) \
9949 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9950 +
9951 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9952 +       const char *_file, int _line, void *_here)
9953 +{
9954 +       struct vx_info *vxi;
9955 +
9956 +       task_lock(p);
9957 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9958 +               p, _file, _line);
9959 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9960 +       task_unlock(p);
9961 +       return vxi;
9962 +}
9963 +
9964 +
9965 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9966 +{
9967 +       if (waitqueue_active(&vxi->vx_wait))
9968 +               wake_up_interruptible(&vxi->vx_wait);
9969 +}
9970 +
9971 +
9972 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9973 +
9974 +static inline void __enter_vx_info(struct vx_info *vxi,
9975 +       struct vx_info_save *vxis, const char *_file, int _line)
9976 +{
9977 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9978 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9979 +               current->xid, current->vx_info, _file, _line);
9980 +       vxis->vxi = xchg(&current->vx_info, vxi);
9981 +       vxis->xid = current->xid;
9982 +       current->xid = vxi ? vxi->vx_id : 0;
9983 +}
9984 +
9985 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9986 +
9987 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9988 +       const char *_file, int _line)
9989 +{
9990 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9991 +               vxis, vxis->xid, vxis->vxi, current,
9992 +               current->xid, current->vx_info, _file, _line);
9993 +       (void)xchg(&current->vx_info, vxis->vxi);
9994 +       current->xid = vxis->xid;
9995 +}
9996 +
9997 +
9998 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9999 +{
10000 +       vxis->vxi = xchg(&current->vx_info, NULL);
10001 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10002 +}
10003 +
10004 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10005 +{
10006 +       (void)xchg(&current->xid, vxis->xid);
10007 +       (void)xchg(&current->vx_info, vxis->vxi);
10008 +}
10009 +
10010 +extern void exit_vx_info(struct task_struct *, int);
10011 +extern void exit_vx_info_early(struct task_struct *, int);
10012 +
10013 +
10014 +#else
10015 +#warning duplicate inclusion
10016 +#endif
10017 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_cowbl.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_cowbl.h
10018 --- linux-2.6.27.6/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
10019 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_cowbl.h  2008-10-13 14:54:20.000000000 +0200
10020 @@ -0,0 +1,47 @@
10021 +#ifndef _VS_COWBL_H
10022 +#define _VS_COWBL_H
10023 +
10024 +#include <linux/fs.h>
10025 +#include <linux/dcache.h>
10026 +#include <linux/namei.h>
10027 +
10028 +extern struct dentry *cow_break_link(const char *pathname);
10029 +
10030 +static inline int cow_check_and_break(struct path *path)
10031 +{
10032 +       struct inode *inode = path->dentry->d_inode;
10033 +       int error = 0;
10034 +
10035 +       /* do we need this check? */
10036 +       if (IS_RDONLY(inode))
10037 +               return -EROFS;
10038 +
10039 +       if (IS_COW(inode)) {
10040 +               if (IS_COW_LINK(inode)) {
10041 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
10042 +                       char *pp, *buf;
10043 +
10044 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
10045 +                       if (!buf) {
10046 +                               return -ENOMEM;
10047 +                       }
10048 +                       pp = d_path(path, buf, PATH_MAX);
10049 +                       new_dentry = cow_break_link(pp);
10050 +                       kfree(buf);
10051 +                       if (!IS_ERR(new_dentry)) {
10052 +                               path->dentry = new_dentry;
10053 +                               dput(old_dentry);
10054 +                       } else
10055 +                               error = PTR_ERR(new_dentry);
10056 +               } else {
10057 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
10058 +                       inode->i_ctime = CURRENT_TIME;
10059 +                       mark_inode_dirty(inode);
10060 +               }
10061 +       }
10062 +       return error;
10063 +}
10064 +
10065 +#else
10066 +#warning duplicate inclusion
10067 +#endif
10068 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_cvirt.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_cvirt.h
10069 --- linux-2.6.27.6/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
10070 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_cvirt.h  2008-10-13 14:54:20.000000000 +0200
10071 @@ -0,0 +1,50 @@
10072 +#ifndef _VS_CVIRT_H
10073 +#define _VS_CVIRT_H
10074 +
10075 +#include "vserver/cvirt.h"
10076 +#include "vserver/context.h"
10077 +#include "vserver/base.h"
10078 +#include "vserver/check.h"
10079 +#include "vserver/debug.h"
10080 +
10081 +
10082 +static inline void vx_activate_task(struct task_struct *p)
10083 +{
10084 +       struct vx_info *vxi;
10085 +
10086 +       if ((vxi = p->vx_info)) {
10087 +               vx_update_load(vxi);
10088 +               atomic_inc(&vxi->cvirt.nr_running);
10089 +       }
10090 +}
10091 +
10092 +static inline void vx_deactivate_task(struct task_struct *p)
10093 +{
10094 +       struct vx_info *vxi;
10095 +
10096 +       if ((vxi = p->vx_info)) {
10097 +               vx_update_load(vxi);
10098 +               atomic_dec(&vxi->cvirt.nr_running);
10099 +       }
10100 +}
10101 +
10102 +static inline void vx_uninterruptible_inc(struct task_struct *p)
10103 +{
10104 +       struct vx_info *vxi;
10105 +
10106 +       if ((vxi = p->vx_info))
10107 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
10108 +}
10109 +
10110 +static inline void vx_uninterruptible_dec(struct task_struct *p)
10111 +{
10112 +       struct vx_info *vxi;
10113 +
10114 +       if ((vxi = p->vx_info))
10115 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
10116 +}
10117 +
10118 +
10119 +#else
10120 +#warning duplicate inclusion
10121 +#endif
10122 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_device.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_device.h
10123 --- linux-2.6.27.6/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
10124 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_device.h 2008-10-13 14:54:20.000000000 +0200
10125 @@ -0,0 +1,45 @@
10126 +#ifndef _VS_DEVICE_H
10127 +#define _VS_DEVICE_H
10128 +
10129 +#include "vserver/base.h"
10130 +#include "vserver/device.h"
10131 +#include "vserver/debug.h"
10132 +
10133 +
10134 +#ifdef CONFIG_VSERVER_DEVICE
10135 +
10136 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
10137 +
10138 +#define vs_device_perm(v, d, m, p) \
10139 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
10140 +
10141 +#else
10142 +
10143 +static inline
10144 +int vs_map_device(struct vx_info *vxi,
10145 +       dev_t device, dev_t *target, umode_t mode)
10146 +{
10147 +       if (target)
10148 +               *target = device;
10149 +       return ~0;
10150 +}
10151 +
10152 +#define vs_device_perm(v, d, m, p) ((p) == (p))
10153 +
10154 +#endif
10155 +
10156 +
10157 +#define vs_map_chrdev(d, t, p) \
10158 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
10159 +#define vs_map_blkdev(d, t, p) \
10160 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
10161 +
10162 +#define vs_chrdev_perm(d, p) \
10163 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
10164 +#define vs_blkdev_perm(d, p) \
10165 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
10166 +
10167 +
10168 +#else
10169 +#warning duplicate inclusion
10170 +#endif
10171 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_dlimit.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_dlimit.h
10172 --- linux-2.6.27.6/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
10173 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_dlimit.h 2008-10-13 14:54:20.000000000 +0200
10174 @@ -0,0 +1,211 @@
10175 +#ifndef _VS_DLIMIT_H
10176 +#define _VS_DLIMIT_H
10177 +
10178 +#include <linux/fs.h>
10179 +
10180 +#include "vserver/dlimit.h"
10181 +#include "vserver/base.h"
10182 +#include "vserver/debug.h"
10183 +
10184 +
10185 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10186 +
10187 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10188 +       const char *_file, int _line)
10189 +{
10190 +       if (!dli)
10191 +               return NULL;
10192 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10193 +               dli, dli ? dli->dl_tag : 0,
10194 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10195 +               _file, _line);
10196 +       atomic_inc(&dli->dl_usecnt);
10197 +       return dli;
10198 +}
10199 +
10200 +
10201 +#define free_dl_info(i) \
10202 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10203 +
10204 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10205 +
10206 +static inline void __put_dl_info(struct dl_info *dli,
10207 +       const char *_file, int _line)
10208 +{
10209 +       if (!dli)
10210 +               return;
10211 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10212 +               dli, dli ? dli->dl_tag : 0,
10213 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10214 +               _file, _line);
10215 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10216 +               free_dl_info(dli);
10217 +}
10218 +
10219 +
10220 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10221 +
10222 +static inline int __dl_alloc_space(struct super_block *sb,
10223 +       tag_t tag, dlsize_t nr, const char *file, int line)
10224 +{
10225 +       struct dl_info *dli = NULL;
10226 +       int ret = 0;
10227 +
10228 +       if (nr == 0)
10229 +               goto out;
10230 +       dli = locate_dl_info(sb, tag);
10231 +       if (!dli)
10232 +               goto out;
10233 +
10234 +       spin_lock(&dli->dl_lock);
10235 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10236 +       if (!ret)
10237 +               dli->dl_space_used += nr;
10238 +       spin_unlock(&dli->dl_lock);
10239 +       put_dl_info(dli);
10240 +out:
10241 +       vxlprintk(VXD_CBIT(dlim, 1),
10242 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10243 +               sb, tag, __dlimit_char(dli), (long long)nr,
10244 +               ret, file, line);
10245 +       return ret;
10246 +}
10247 +
10248 +static inline void __dl_free_space(struct super_block *sb,
10249 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10250 +{
10251 +       struct dl_info *dli = NULL;
10252 +
10253 +       if (nr == 0)
10254 +               goto out;
10255 +       dli = locate_dl_info(sb, tag);
10256 +       if (!dli)
10257 +               goto out;
10258 +
10259 +       spin_lock(&dli->dl_lock);
10260 +       if (dli->dl_space_used > nr)
10261 +               dli->dl_space_used -= nr;
10262 +       else
10263 +               dli->dl_space_used = 0;
10264 +       spin_unlock(&dli->dl_lock);
10265 +       put_dl_info(dli);
10266 +out:
10267 +       vxlprintk(VXD_CBIT(dlim, 1),
10268 +               "FREE  (%p,#%d)%c %lld bytes",
10269 +               sb, tag, __dlimit_char(dli), (long long)nr,
10270 +               _file, _line);
10271 +}
10272 +
10273 +static inline int __dl_alloc_inode(struct super_block *sb,
10274 +       tag_t tag, const char *_file, int _line)
10275 +{
10276 +       struct dl_info *dli;
10277 +       int ret = 0;
10278 +
10279 +       dli = locate_dl_info(sb, tag);
10280 +       if (!dli)
10281 +               goto out;
10282 +
10283 +       spin_lock(&dli->dl_lock);
10284 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10285 +       if (!ret)
10286 +               dli->dl_inodes_used++;
10287 +       spin_unlock(&dli->dl_lock);
10288 +       put_dl_info(dli);
10289 +out:
10290 +       vxlprintk(VXD_CBIT(dlim, 0),
10291 +               "ALLOC (%p,#%d)%c inode (%d)",
10292 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10293 +       return ret;
10294 +}
10295 +
10296 +static inline void __dl_free_inode(struct super_block *sb,
10297 +       tag_t tag, const char *_file, int _line)
10298 +{
10299 +       struct dl_info *dli;
10300 +
10301 +       dli = locate_dl_info(sb, tag);
10302 +       if (!dli)
10303 +               goto out;
10304 +
10305 +       spin_lock(&dli->dl_lock);
10306 +       if (dli->dl_inodes_used > 1)
10307 +               dli->dl_inodes_used--;
10308 +       else
10309 +               dli->dl_inodes_used = 0;
10310 +       spin_unlock(&dli->dl_lock);
10311 +       put_dl_info(dli);
10312 +out:
10313 +       vxlprintk(VXD_CBIT(dlim, 0),
10314 +               "FREE  (%p,#%d)%c inode",
10315 +               sb, tag, __dlimit_char(dli), _file, _line);
10316 +}
10317 +
10318 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10319 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10320 +       const char *_file, int _line)
10321 +{
10322 +       struct dl_info *dli;
10323 +       uint64_t broot, bfree;
10324 +
10325 +       dli = locate_dl_info(sb, tag);
10326 +       if (!dli)
10327 +               return;
10328 +
10329 +       spin_lock(&dli->dl_lock);
10330 +       broot = (dli->dl_space_total -
10331 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10332 +               >> sb->s_blocksize_bits;
10333 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10334 +                       >> sb->s_blocksize_bits;
10335 +       spin_unlock(&dli->dl_lock);
10336 +
10337 +       vxlprintk(VXD_CBIT(dlim, 2),
10338 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10339 +               (long long)bfree, (long long)broot,
10340 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10341 +               _file, _line);
10342 +       if (free_blocks) {
10343 +               if (*free_blocks > bfree)
10344 +                       *free_blocks = bfree;
10345 +       }
10346 +       if (root_blocks) {
10347 +               if (*root_blocks > broot)
10348 +                       *root_blocks = broot;
10349 +       }
10350 +       put_dl_info(dli);
10351 +}
10352 +
10353 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
10354 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10355 +               __FILE__, __LINE__ )
10356 +
10357 +#define DLIMIT_FREE_SPACE(in, bytes) \
10358 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10359 +               __FILE__, __LINE__ )
10360 +
10361 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
10362 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
10363 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10364 +               __FILE__, __LINE__ )
10365 +
10366 +#define DLIMIT_FREE_BLOCK(in, nr) \
10367 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
10368 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10369 +               __FILE__, __LINE__ )
10370 +
10371 +
10372 +#define DLIMIT_ALLOC_INODE(in) \
10373 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10374 +
10375 +#define DLIMIT_FREE_INODE(in) \
10376 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10377 +
10378 +
10379 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
10380 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10381 +
10382 +
10383 +#else
10384 +#warning duplicate inclusion
10385 +#endif
10386 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/base.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/base.h
10387 --- linux-2.6.27.6/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10388 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/base.h      2008-10-13 14:54:20.000000000 +0200
10389 @@ -0,0 +1,157 @@
10390 +#ifndef _VX_BASE_H
10391 +#define _VX_BASE_H
10392 +
10393 +
10394 +/* context state changes */
10395 +
10396 +enum {
10397 +       VSC_STARTUP = 1,
10398 +       VSC_SHUTDOWN,
10399 +
10400 +       VSC_NETUP,
10401 +       VSC_NETDOWN,
10402 +};
10403 +
10404 +
10405 +
10406 +#define vx_task_xid(t) ((t)->xid)
10407 +
10408 +#define vx_current_xid() vx_task_xid(current)
10409 +
10410 +#define current_vx_info() (current->vx_info)
10411 +
10412 +
10413 +#define nx_task_nid(t) ((t)->nid)
10414 +
10415 +#define nx_current_nid() nx_task_nid(current)
10416 +
10417 +#define current_nx_info() (current->nx_info)
10418 +
10419 +
10420 +/* generic flag merging */
10421 +
10422 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10423 +
10424 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10425 +
10426 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10427 +
10428 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10429 +
10430 +
10431 +/* context flags */
10432 +
10433 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10434 +
10435 +#define vx_current_flags()     __vx_flags(current->vx_info)
10436 +
10437 +#define vx_info_flags(v, m, f) \
10438 +       vs_check_flags(__vx_flags(v), m, f)
10439 +
10440 +#define task_vx_flags(t, m, f) \
10441 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10442 +
10443 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
10444 +
10445 +
10446 +/* context caps */
10447 +
10448 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10449 +
10450 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
10451 +
10452 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10453 +
10454 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
10455 +
10456 +
10457 +
10458 +/* network flags */
10459 +
10460 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10461 +
10462 +#define nx_current_flags()     __nx_flags(current->nx_info)
10463 +
10464 +#define nx_info_flags(n, m, f) \
10465 +       vs_check_flags(__nx_flags(n), m, f)
10466 +
10467 +#define task_nx_flags(t, m, f) \
10468 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10469 +
10470 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
10471 +
10472 +
10473 +/* network caps */
10474 +
10475 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10476 +
10477 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
10478 +
10479 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10480 +
10481 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
10482 +
10483 +
10484 +/* context mask capabilities */
10485 +
10486 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10487 +
10488 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10489 +
10490 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
10491 +
10492 +
10493 +/* context bcap mask */
10494 +
10495 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10496 +
10497 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
10498 +
10499 +
10500 +/* mask given bcaps */
10501 +
10502 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10503 +
10504 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
10505 +
10506 +
10507 +/* masked cap_bset */
10508 +
10509 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10510 +
10511 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
10512 +
10513 +#if 0
10514 +#define vx_info_mbcap(v, b) \
10515 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10516 +       vx_info_bcaps(v, b) : (b))
10517 +
10518 +#define task_vx_mbcap(t, b) \
10519 +       vx_info_mbcap((t)->vx_info, (t)->b)
10520 +
10521 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10522 +#endif
10523 +
10524 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10525 +
10526 +#define vx_capable(b, c) (capable(b) || \
10527 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
10528 +
10529 +#define nx_capable(b, c) (capable(b) || \
10530 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
10531 +
10532 +#define vx_current_initpid(n) \
10533 +       (current->vx_info && \
10534 +       (current->vx_info->vx_initpid == (n)))
10535 +
10536 +
10537 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10538 +
10539 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10540 +
10541 +
10542 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10543 +
10544 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10545 +
10546 +#endif
10547 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cacct_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct_cmd.h
10548 --- linux-2.6.27.6/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
10549 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct_cmd.h 2008-10-13 14:54:20.000000000 +0200
10550 @@ -0,0 +1,23 @@
10551 +#ifndef _VX_CACCT_CMD_H
10552 +#define _VX_CACCT_CMD_H
10553 +
10554 +
10555 +/* virtual host info name commands */
10556 +
10557 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10558 +
10559 +struct vcmd_sock_stat_v0 {
10560 +       uint32_t field;
10561 +       uint32_t count[3];
10562 +       uint64_t total[3];
10563 +};
10564 +
10565 +
10566 +#ifdef __KERNEL__
10567 +
10568 +#include <linux/compiler.h>
10569 +
10570 +extern int vc_sock_stat(struct vx_info *, void __user *);
10571 +
10572 +#endif /* __KERNEL__ */
10573 +#endif /* _VX_CACCT_CMD_H */
10574 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cacct_def.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct_def.h
10575 --- linux-2.6.27.6/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
10576 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct_def.h 2008-10-13 14:54:20.000000000 +0200
10577 @@ -0,0 +1,43 @@
10578 +#ifndef _VX_CACCT_DEF_H
10579 +#define _VX_CACCT_DEF_H
10580 +
10581 +#include <asm/atomic.h>
10582 +#include <linux/vserver/cacct.h>
10583 +
10584 +
10585 +struct _vx_sock_acc {
10586 +       atomic_long_t count;
10587 +       atomic_long_t total;
10588 +};
10589 +
10590 +/* context sub struct */
10591 +
10592 +struct _vx_cacct {
10593 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10594 +       atomic_t slab[8];
10595 +       atomic_t page[6][8];
10596 +};
10597 +
10598 +#ifdef CONFIG_VSERVER_DEBUG
10599 +
10600 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10601 +{
10602 +       int i, j;
10603 +
10604 +       printk("\t_vx_cacct:");
10605 +       for (i = 0; i < 6; i++) {
10606 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10607 +
10608 +               printk("\t [%d] =", i);
10609 +               for (j = 0; j < 3; j++) {
10610 +                       printk(" [%d] = %8lu, %8lu", j,
10611 +                               atomic_long_read(&ptr[j].count),
10612 +                               atomic_long_read(&ptr[j].total));
10613 +               }
10614 +               printk("\n");
10615 +       }
10616 +}
10617 +
10618 +#endif
10619 +
10620 +#endif /* _VX_CACCT_DEF_H */
10621 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cacct.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct.h
10622 --- linux-2.6.27.6/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
10623 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct.h     2008-10-13 14:54:20.000000000 +0200
10624 @@ -0,0 +1,15 @@
10625 +#ifndef _VX_CACCT_H
10626 +#define _VX_CACCT_H
10627 +
10628 +
10629 +enum sock_acc_field {
10630 +       VXA_SOCK_UNSPEC = 0,
10631 +       VXA_SOCK_UNIX,
10632 +       VXA_SOCK_INET,
10633 +       VXA_SOCK_INET6,
10634 +       VXA_SOCK_PACKET,
10635 +       VXA_SOCK_OTHER,
10636 +       VXA_SOCK_SIZE   /* array size */
10637 +};
10638 +
10639 +#endif /* _VX_CACCT_H */
10640 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cacct_int.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct_int.h
10641 --- linux-2.6.27.6/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
10642 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cacct_int.h 2008-10-13 14:54:20.000000000 +0200
10643 @@ -0,0 +1,21 @@
10644 +#ifndef _VX_CACCT_INT_H
10645 +#define _VX_CACCT_INT_H
10646 +
10647 +
10648 +#ifdef __KERNEL__
10649 +
10650 +static inline
10651 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10652 +{
10653 +       return atomic_long_read(&cacct->sock[type][pos].count);
10654 +}
10655 +
10656 +
10657 +static inline
10658 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10659 +{
10660 +       return atomic_long_read(&cacct->sock[type][pos].total);
10661 +}
10662 +
10663 +#endif /* __KERNEL__ */
10664 +#endif /* _VX_CACCT_INT_H */
10665 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/check.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/check.h
10666 --- linux-2.6.27.6/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10667 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/check.h     2008-10-13 14:54:20.000000000 +0200
10668 @@ -0,0 +1,89 @@
10669 +#ifndef _VS_CHECK_H
10670 +#define _VS_CHECK_H
10671 +
10672 +
10673 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10674 +
10675 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10676 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10677 +#else
10678 +#define MIN_D_CONTEXT  65536
10679 +#endif
10680 +
10681 +/* check conditions */
10682 +
10683 +#define VS_ADMIN       0x0001
10684 +#define VS_WATCH       0x0002
10685 +#define VS_HIDE                0x0004
10686 +#define VS_HOSTID      0x0008
10687 +
10688 +#define VS_IDENT       0x0010
10689 +#define VS_EQUIV       0x0020
10690 +#define VS_PARENT      0x0040
10691 +#define VS_CHILD       0x0080
10692 +
10693 +#define VS_ARG_MASK    0x00F0
10694 +
10695 +#define VS_DYNAMIC     0x0100
10696 +#define VS_STATIC      0x0200
10697 +
10698 +#define VS_ATR_MASK    0x0F00
10699 +
10700 +#ifdef CONFIG_VSERVER_PRIVACY
10701 +#define VS_ADMIN_P     (0)
10702 +#define VS_WATCH_P     (0)
10703 +#else
10704 +#define VS_ADMIN_P     VS_ADMIN
10705 +#define VS_WATCH_P     VS_WATCH
10706 +#endif
10707 +
10708 +#define VS_HARDIRQ     0x1000
10709 +#define VS_SOFTIRQ     0x2000
10710 +#define VS_IRQ         0x4000
10711 +
10712 +#define VS_IRQ_MASK    0xF000
10713 +
10714 +#include <linux/hardirq.h>
10715 +
10716 +/*
10717 + * check current context for ADMIN/WATCH and
10718 + * optionally against supplied argument
10719 + */
10720 +static inline int __vs_check(int cid, int id, unsigned int mode)
10721 +{
10722 +       if (mode & VS_ARG_MASK) {
10723 +               if ((mode & VS_IDENT) && (id == cid))
10724 +                       return 1;
10725 +       }
10726 +       if (mode & VS_ATR_MASK) {
10727 +               if ((mode & VS_DYNAMIC) &&
10728 +                       (id >= MIN_D_CONTEXT) &&
10729 +                       (id <= MAX_S_CONTEXT))
10730 +                       return 1;
10731 +               if ((mode & VS_STATIC) &&
10732 +                       (id > 1) && (id < MIN_D_CONTEXT))
10733 +                       return 1;
10734 +       }
10735 +       if (mode & VS_IRQ_MASK) {
10736 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10737 +                       return 1;
10738 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10739 +                       return 1;
10740 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10741 +                       return 1;
10742 +       }
10743 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10744 +               ((mode & VS_WATCH) && (cid == 1)) ||
10745 +               ((mode & VS_HOSTID) && (id == 0)));
10746 +}
10747 +
10748 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10749 +
10750 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10751 +
10752 +
10753 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10754 +
10755 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10756 +
10757 +#endif
10758 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/context_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/context_cmd.h
10759 --- linux-2.6.27.6/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10760 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/context_cmd.h       2008-10-13 14:54:20.000000000 +0200
10761 @@ -0,0 +1,128 @@
10762 +#ifndef _VX_CONTEXT_CMD_H
10763 +#define _VX_CONTEXT_CMD_H
10764 +
10765 +
10766 +/* vinfo commands */
10767 +
10768 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10769 +
10770 +#ifdef __KERNEL__
10771 +extern int vc_task_xid(uint32_t);
10772 +
10773 +#endif /* __KERNEL__ */
10774 +
10775 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10776 +
10777 +struct vcmd_vx_info_v0 {
10778 +       uint32_t xid;
10779 +       uint32_t initpid;
10780 +       /* more to come */
10781 +};
10782 +
10783 +#ifdef __KERNEL__
10784 +extern int vc_vx_info(struct vx_info *, void __user *);
10785 +
10786 +#endif /* __KERNEL__ */
10787 +
10788 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10789 +
10790 +struct vcmd_ctx_stat_v0 {
10791 +       uint32_t usecnt;
10792 +       uint32_t tasks;
10793 +       /* more to come */
10794 +};
10795 +
10796 +#ifdef __KERNEL__
10797 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10798 +
10799 +#endif /* __KERNEL__ */
10800 +
10801 +/* context commands */
10802 +
10803 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10804 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10805 +
10806 +struct vcmd_ctx_create {
10807 +       uint64_t flagword;
10808 +};
10809 +
10810 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10811 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10812 +
10813 +struct vcmd_ctx_migrate {
10814 +       uint64_t flagword;
10815 +};
10816 +
10817 +#ifdef __KERNEL__
10818 +extern int vc_ctx_create(uint32_t, void __user *);
10819 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10820 +
10821 +#endif /* __KERNEL__ */
10822 +
10823 +
10824 +/* flag commands */
10825 +
10826 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10827 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10828 +
10829 +struct vcmd_ctx_flags_v0 {
10830 +       uint64_t flagword;
10831 +       uint64_t mask;
10832 +};
10833 +
10834 +#ifdef __KERNEL__
10835 +extern int vc_get_cflags(struct vx_info *, void __user *);
10836 +extern int vc_set_cflags(struct vx_info *, void __user *);
10837 +
10838 +#endif /* __KERNEL__ */
10839 +
10840 +
10841 +/* context caps commands */
10842 +
10843 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10844 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10845 +
10846 +struct vcmd_ctx_caps_v1 {
10847 +       uint64_t ccaps;
10848 +       uint64_t cmask;
10849 +};
10850 +
10851 +#ifdef __KERNEL__
10852 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10853 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10854 +
10855 +#endif /* __KERNEL__ */
10856 +
10857 +
10858 +/* bcaps commands */
10859 +
10860 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10861 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10862 +
10863 +struct vcmd_bcaps {
10864 +       uint64_t bcaps;
10865 +       uint64_t bmask;
10866 +};
10867 +
10868 +#ifdef __KERNEL__
10869 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10870 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10871 +
10872 +#endif /* __KERNEL__ */
10873 +
10874 +
10875 +/* OOM badness */
10876 +
10877 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10878 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10879 +
10880 +struct vcmd_badness_v0 {
10881 +       int64_t bias;
10882 +};
10883 +
10884 +#ifdef __KERNEL__
10885 +extern int vc_get_badness(struct vx_info *, void __user *);
10886 +extern int vc_set_badness(struct vx_info *, void __user *);
10887 +
10888 +#endif /* __KERNEL__ */
10889 +#endif /* _VX_CONTEXT_CMD_H */
10890 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/context.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/context.h
10891 --- linux-2.6.27.6/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10892 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/context.h   2008-10-31 18:15:28.000000000 +0100
10893 @@ -0,0 +1,178 @@
10894 +#ifndef _VX_CONTEXT_H
10895 +#define _VX_CONTEXT_H
10896 +
10897 +#include <linux/types.h>
10898 +#include <linux/capability.h>
10899 +
10900 +
10901 +/* context flags */
10902 +
10903 +#define VXF_INFO_SCHED         0x00000002
10904 +#define VXF_INFO_NPROC         0x00000004
10905 +#define VXF_INFO_PRIVATE       0x00000008
10906 +
10907 +#define VXF_INFO_INIT          0x00000010
10908 +#define VXF_INFO_HIDE          0x00000020
10909 +#define VXF_INFO_ULIMIT                0x00000040
10910 +#define VXF_INFO_NSPACE                0x00000080
10911 +
10912 +#define VXF_SCHED_HARD         0x00000100
10913 +#define VXF_SCHED_PRIO         0x00000200
10914 +#define VXF_SCHED_PAUSE                0x00000400
10915 +
10916 +#define VXF_VIRT_MEM           0x00010000
10917 +#define VXF_VIRT_UPTIME                0x00020000
10918 +#define VXF_VIRT_CPU           0x00040000
10919 +#define VXF_VIRT_LOAD          0x00080000
10920 +#define VXF_VIRT_TIME          0x00100000
10921 +
10922 +#define VXF_HIDE_MOUNT         0x01000000
10923 +/* was VXF_HIDE_NETIF          0x02000000 */
10924 +#define VXF_HIDE_VINFO         0x04000000
10925 +
10926 +#define VXF_STATE_SETUP                (1ULL << 32)
10927 +#define VXF_STATE_INIT         (1ULL << 33)
10928 +#define VXF_STATE_ADMIN                (1ULL << 34)
10929 +
10930 +#define VXF_SC_HELPER          (1ULL << 36)
10931 +#define VXF_REBOOT_KILL                (1ULL << 37)
10932 +#define VXF_PERSISTENT         (1ULL << 38)
10933 +
10934 +#define VXF_FORK_RSS           (1ULL << 48)
10935 +#define VXF_PROLIFIC           (1ULL << 49)
10936 +
10937 +#define VXF_IGNEG_NICE         (1ULL << 52)
10938 +
10939 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10940 +
10941 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10942 +
10943 +
10944 +/* context migration */
10945 +
10946 +#define VXM_SET_INIT           0x00000001
10947 +#define VXM_SET_REAPER         0x00000002
10948 +
10949 +/* context caps */
10950 +
10951 +#define VXC_CAP_MASK           0x00000000
10952 +
10953 +#define VXC_SET_UTSNAME                0x00000001
10954 +#define VXC_SET_RLIMIT         0x00000002
10955 +
10956 +/* was VXC_RAW_ICMP            0x00000100 */
10957 +#define VXC_SYSLOG             0x00001000
10958 +
10959 +#define VXC_SECURE_MOUNT       0x00010000
10960 +#define VXC_SECURE_REMOUNT     0x00020000
10961 +#define VXC_BINARY_MOUNT       0x00040000
10962 +
10963 +#define VXC_QUOTA_CTL          0x00100000
10964 +#define VXC_ADMIN_MAPPER       0x00200000
10965 +#define VXC_ADMIN_CLOOP                0x00400000
10966 +
10967 +#define VXC_KTHREAD            0x01000000
10968 +
10969 +
10970 +#ifdef __KERNEL__
10971 +
10972 +#include <linux/list.h>
10973 +#include <linux/spinlock.h>
10974 +#include <linux/rcupdate.h>
10975 +
10976 +#include "limit_def.h"
10977 +#include "sched_def.h"
10978 +#include "cvirt_def.h"
10979 +#include "cacct_def.h"
10980 +#include "device_def.h"
10981 +
10982 +#define VX_SPACES      2
10983 +
10984 +struct _vx_info_pc {
10985 +       struct _vx_sched_pc sched_pc;
10986 +       struct _vx_cvirt_pc cvirt_pc;
10987 +};
10988 +
10989 +struct vx_info {
10990 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10991 +       xid_t vx_id;                            /* context id */
10992 +       atomic_t vx_usecnt;                     /* usage count */
10993 +       atomic_t vx_tasks;                      /* tasks count */
10994 +       struct vx_info *vx_parent;              /* parent context */
10995 +       int vx_state;                           /* context state */
10996 +
10997 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10998 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10999 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
11000 +
11001 +       uint64_t vx_flags;                      /* context flags */
11002 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11003 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11004 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
11005 +
11006 +       struct task_struct *vx_reaper;          /* guest reaper process */
11007 +       pid_t vx_initpid;                       /* PID of guest init */
11008 +       int64_t vx_badness_bias;                /* OOM points bias */
11009 +
11010 +       struct _vx_limit limit;                 /* vserver limits */
11011 +       struct _vx_sched sched;                 /* vserver scheduler */
11012 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11013 +       struct _vx_cacct cacct;                 /* context accounting */
11014 +
11015 +       struct _vx_device dmap;                 /* default device map targets */
11016 +
11017 +#ifndef CONFIG_SMP
11018 +       struct _vx_info_pc info_pc;             /* per cpu data */
11019 +#else
11020 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11021 +#endif
11022 +
11023 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11024 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11025 +       int exit_code;                          /* last process exit code */
11026 +
11027 +       char vx_name[65];                       /* vserver name */
11028 +};
11029 +
11030 +#ifndef CONFIG_SMP
11031 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11032 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11033 +#else
11034 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11035 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11036 +#endif
11037 +
11038 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11039 +
11040 +
11041 +struct vx_info_save {
11042 +       struct vx_info *vxi;
11043 +       xid_t xid;
11044 +};
11045 +
11046 +
11047 +/* status flags */
11048 +
11049 +#define VXS_HASHED     0x0001
11050 +#define VXS_PAUSED     0x0010
11051 +#define VXS_SHUTDOWN   0x0100
11052 +#define VXS_HELPER     0x1000
11053 +#define VXS_RELEASED   0x8000
11054 +
11055 +
11056 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11057 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11058 +
11059 +extern struct vx_info *lookup_vx_info(int);
11060 +extern struct vx_info *lookup_or_create_vx_info(int);
11061 +
11062 +extern int get_xid_list(int, unsigned int *, int);
11063 +extern int xid_is_hashed(xid_t);
11064 +
11065 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11066 +
11067 +extern long vs_state_change(struct vx_info *, unsigned int);
11068 +
11069 +
11070 +#endif /* __KERNEL__ */
11071 +#endif /* _VX_CONTEXT_H */
11072 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cvirt_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cvirt_cmd.h
11073 --- linux-2.6.27.6/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
11074 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cvirt_cmd.h 2008-10-13 14:54:20.000000000 +0200
11075 @@ -0,0 +1,53 @@
11076 +#ifndef _VX_CVIRT_CMD_H
11077 +#define _VX_CVIRT_CMD_H
11078 +
11079 +
11080 +/* virtual host info name commands */
11081 +
11082 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11083 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11084 +
11085 +struct vcmd_vhi_name_v0 {
11086 +       uint32_t field;
11087 +       char name[65];
11088 +};
11089 +
11090 +
11091 +enum vhi_name_field {
11092 +       VHIN_CONTEXT = 0,
11093 +       VHIN_SYSNAME,
11094 +       VHIN_NODENAME,
11095 +       VHIN_RELEASE,
11096 +       VHIN_VERSION,
11097 +       VHIN_MACHINE,
11098 +       VHIN_DOMAINNAME,
11099 +};
11100 +
11101 +
11102 +#ifdef __KERNEL__
11103 +
11104 +#include <linux/compiler.h>
11105 +
11106 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11107 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11108 +
11109 +#endif /* __KERNEL__ */
11110 +
11111 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11112 +
11113 +struct vcmd_virt_stat_v0 {
11114 +       uint64_t offset;
11115 +       uint64_t uptime;
11116 +       uint32_t nr_threads;
11117 +       uint32_t nr_running;
11118 +       uint32_t nr_uninterruptible;
11119 +       uint32_t nr_onhold;
11120 +       uint32_t nr_forks;
11121 +       uint32_t load[3];
11122 +};
11123 +
11124 +#ifdef __KERNEL__
11125 +extern int vc_virt_stat(struct vx_info *, void __user *);
11126 +
11127 +#endif /* __KERNEL__ */
11128 +#endif /* _VX_CVIRT_CMD_H */
11129 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cvirt_def.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cvirt_def.h
11130 --- linux-2.6.27.6/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
11131 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cvirt_def.h 2008-10-13 14:54:20.000000000 +0200
11132 @@ -0,0 +1,80 @@
11133 +#ifndef _VX_CVIRT_DEF_H
11134 +#define _VX_CVIRT_DEF_H
11135 +
11136 +#include <linux/jiffies.h>
11137 +#include <linux/spinlock.h>
11138 +#include <linux/wait.h>
11139 +#include <linux/time.h>
11140 +#include <asm/atomic.h>
11141 +
11142 +
11143 +struct _vx_usage_stat {
11144 +       uint64_t user;
11145 +       uint64_t nice;
11146 +       uint64_t system;
11147 +       uint64_t softirq;
11148 +       uint64_t irq;
11149 +       uint64_t idle;
11150 +       uint64_t iowait;
11151 +};
11152 +
11153 +struct _vx_syslog {
11154 +       wait_queue_head_t log_wait;
11155 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11156 +
11157 +       unsigned long log_start;        /* next char to be read by syslog() */
11158 +       unsigned long con_start;        /* next char to be sent to consoles */
11159 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11160 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11161 +
11162 +       char log_buf[1024];
11163 +};
11164 +
11165 +
11166 +/* context sub struct */
11167 +
11168 +struct _vx_cvirt {
11169 +       atomic_t nr_threads;            /* number of current threads */
11170 +       atomic_t nr_running;            /* number of running threads */
11171 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11172 +
11173 +       atomic_t nr_onhold;             /* processes on hold */
11174 +       uint32_t onhold_last;           /* jiffies when put on hold */
11175 +
11176 +       struct timeval bias_tv;         /* time offset to the host */
11177 +       struct timespec bias_idle;
11178 +       struct timespec bias_uptime;    /* context creation point */
11179 +       uint64_t bias_clock;            /* offset in clock_t */
11180 +
11181 +       spinlock_t load_lock;           /* lock for the load averages */
11182 +       atomic_t load_updates;          /* nr of load updates done so far */
11183 +       uint32_t load_last;             /* last time load was calculated */
11184 +       uint32_t load[3];               /* load averages 1,5,15 */
11185 +
11186 +       atomic_t total_forks;           /* number of forks so far */
11187 +
11188 +       struct _vx_syslog syslog;
11189 +};
11190 +
11191 +struct _vx_cvirt_pc {
11192 +       struct _vx_usage_stat cpustat;
11193 +};
11194 +
11195 +
11196 +#ifdef CONFIG_VSERVER_DEBUG
11197 +
11198 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11199 +{
11200 +       printk("\t_vx_cvirt:\n");
11201 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11202 +               atomic_read(&cvirt->nr_threads),
11203 +               atomic_read(&cvirt->nr_running),
11204 +               atomic_read(&cvirt->nr_uninterruptible),
11205 +               atomic_read(&cvirt->nr_onhold));
11206 +       /* add rest here */
11207 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11208 +}
11209 +
11210 +#endif
11211 +
11212 +#endif /* _VX_CVIRT_DEF_H */
11213 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/cvirt.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cvirt.h
11214 --- linux-2.6.27.6/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
11215 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/cvirt.h     2008-10-13 14:54:20.000000000 +0200
11216 @@ -0,0 +1,20 @@
11217 +#ifndef _VX_CVIRT_H
11218 +#define _VX_CVIRT_H
11219 +
11220 +
11221 +#ifdef __KERNEL__
11222 +
11223 +struct timespec;
11224 +
11225 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11226 +
11227 +
11228 +struct vx_info;
11229 +
11230 +void vx_update_load(struct vx_info *);
11231 +
11232 +
11233 +int vx_do_syslog(int, char __user *, int);
11234 +
11235 +#endif /* __KERNEL__ */
11236 +#endif /* _VX_CVIRT_H */
11237 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/debug_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/debug_cmd.h
11238 --- linux-2.6.27.6/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
11239 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/debug_cmd.h 2008-10-13 14:54:20.000000000 +0200
11240 @@ -0,0 +1,58 @@
11241 +#ifndef _VX_DEBUG_CMD_H
11242 +#define _VX_DEBUG_CMD_H
11243 +
11244 +
11245 +/* debug commands */
11246 +
11247 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11248 +
11249 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11250 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11251 +
11252 +struct  vcmd_read_history_v0 {
11253 +       uint32_t index;
11254 +       uint32_t count;
11255 +       char __user *data;
11256 +};
11257 +
11258 +struct  vcmd_read_monitor_v0 {
11259 +       uint32_t index;
11260 +       uint32_t count;
11261 +       char __user *data;
11262 +};
11263 +
11264 +
11265 +#ifdef __KERNEL__
11266 +
11267 +#ifdef CONFIG_COMPAT
11268 +
11269 +#include <asm/compat.h>
11270 +
11271 +struct vcmd_read_history_v0_x32 {
11272 +       uint32_t index;
11273 +       uint32_t count;
11274 +       compat_uptr_t data_ptr;
11275 +};
11276 +
11277 +struct vcmd_read_monitor_v0_x32 {
11278 +       uint32_t index;
11279 +       uint32_t count;
11280 +       compat_uptr_t data_ptr;
11281 +};
11282 +
11283 +#endif  /* CONFIG_COMPAT */
11284 +
11285 +extern int vc_dump_history(uint32_t);
11286 +
11287 +extern int vc_read_history(uint32_t, void __user *);
11288 +extern int vc_read_monitor(uint32_t, void __user *);
11289 +
11290 +#ifdef CONFIG_COMPAT
11291 +
11292 +extern int vc_read_history_x32(uint32_t, void __user *);
11293 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11294 +
11295 +#endif  /* CONFIG_COMPAT */
11296 +
11297 +#endif /* __KERNEL__ */
11298 +#endif /* _VX_DEBUG_CMD_H */
11299 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/debug.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/debug.h
11300 --- linux-2.6.27.6/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
11301 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/debug.h     2008-10-13 14:54:20.000000000 +0200
11302 @@ -0,0 +1,127 @@
11303 +#ifndef _VX_DEBUG_H
11304 +#define _VX_DEBUG_H
11305 +
11306 +
11307 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11308 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11309 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11310 +
11311 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11312 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11313 +#define VXF_DEV                "%p[%lu,%d:%d]"
11314 +
11315 +
11316 +#define vxd_path(p)                                            \
11317 +       ({ static char _buffer[PATH_MAX];                       \
11318 +          d_path(p, _buffer, sizeof(_buffer)); })
11319 +
11320 +#define vxd_cond_path(n)                                       \
11321 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11322 +
11323 +
11324 +#ifdef CONFIG_VSERVER_DEBUG
11325 +
11326 +extern unsigned int vx_debug_switch;
11327 +extern unsigned int vx_debug_xid;
11328 +extern unsigned int vx_debug_nid;
11329 +extern unsigned int vx_debug_tag;
11330 +extern unsigned int vx_debug_net;
11331 +extern unsigned int vx_debug_limit;
11332 +extern unsigned int vx_debug_cres;
11333 +extern unsigned int vx_debug_dlim;
11334 +extern unsigned int vx_debug_quota;
11335 +extern unsigned int vx_debug_cvirt;
11336 +extern unsigned int vx_debug_space;
11337 +extern unsigned int vx_debug_misc;
11338 +
11339 +
11340 +#define VX_LOGLEVEL    "vxD: "
11341 +#define VX_PROC_FMT    "%p: "
11342 +#define VX_PROCESS     current
11343 +
11344 +#define vxdprintk(c, f, x...)                                  \
11345 +       do {                                                    \
11346 +               if (c)                                          \
11347 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11348 +                               VX_PROCESS , ##x);              \
11349 +       } while (0)
11350 +
11351 +#define vxlprintk(c, f, x...)                                  \
11352 +       do {                                                    \
11353 +               if (c)                                          \
11354 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11355 +       } while (0)
11356 +
11357 +#define vxfprintk(c, f, x...)                                  \
11358 +       do {                                                    \
11359 +               if (c)                                          \
11360 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11361 +       } while (0)
11362 +
11363 +
11364 +struct vx_info;
11365 +
11366 +void dump_vx_info(struct vx_info *, int);
11367 +void dump_vx_info_inactive(int);
11368 +
11369 +#else  /* CONFIG_VSERVER_DEBUG */
11370 +
11371 +#define vx_debug_switch 0
11372 +#define vx_debug_xid   0
11373 +#define vx_debug_nid   0
11374 +#define vx_debug_tag   0
11375 +#define vx_debug_net   0
11376 +#define vx_debug_limit 0
11377 +#define vx_debug_cres  0
11378 +#define vx_debug_dlim  0
11379 +#define vx_debug_cvirt 0
11380 +
11381 +#define vxdprintk(x...) do { } while (0)
11382 +#define vxlprintk(x...) do { } while (0)
11383 +#define vxfprintk(x...) do { } while (0)
11384 +
11385 +#endif /* CONFIG_VSERVER_DEBUG */
11386 +
11387 +
11388 +#ifdef CONFIG_VSERVER_WARN
11389 +
11390 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11391 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11392 +#define VX_WARN_XID    "[xid #%u] "
11393 +#define VX_WARN_NID    "[nid #%u] "
11394 +#define VX_WARN_TAG    "[tag #%u] "
11395 +
11396 +#define vxwprintk(c, f, x...)                                  \
11397 +       do {                                                    \
11398 +               if (c)                                          \
11399 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11400 +       } while (0)
11401 +
11402 +#else  /* CONFIG_VSERVER_WARN */
11403 +
11404 +#define vxwprintk(x...) do { } while (0)
11405 +
11406 +#endif /* CONFIG_VSERVER_WARN */
11407 +
11408 +#define vxwprintk_task(c, f, x...)                             \
11409 +       vxwprintk(c, VX_WARN_TASK f,                            \
11410 +               current->comm, current->pid,                    \
11411 +               current->xid, current->nid, current->tag, ##x)
11412 +#define vxwprintk_xid(c, f, x...)                              \
11413 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11414 +#define vxwprintk_nid(c, f, x...)                              \
11415 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11416 +#define vxwprintk_tag(c, f, x...)                              \
11417 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11418 +
11419 +#ifdef CONFIG_VSERVER_DEBUG
11420 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11421 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11422 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11423 +#else
11424 +#define vxd_assert_lock(l)     do { } while (0)
11425 +#define vxd_assert(c, f, x...) do { } while (0)
11426 +#endif
11427 +
11428 +
11429 +#endif /* _VX_DEBUG_H */
11430 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/device_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/device_cmd.h
11431 --- linux-2.6.27.6/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
11432 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/device_cmd.h        2008-10-13 14:54:20.000000000 +0200
11433 @@ -0,0 +1,44 @@
11434 +#ifndef _VX_DEVICE_CMD_H
11435 +#define _VX_DEVICE_CMD_H
11436 +
11437 +
11438 +/*  device vserver commands */
11439 +
11440 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11441 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11442 +
11443 +struct vcmd_set_mapping_v0 {
11444 +       const char __user *device;
11445 +       const char __user *target;
11446 +       uint32_t flags;
11447 +};
11448 +
11449 +
11450 +#ifdef __KERNEL__
11451 +
11452 +#ifdef CONFIG_COMPAT
11453 +
11454 +#include <asm/compat.h>
11455 +
11456 +struct vcmd_set_mapping_v0_x32 {
11457 +       compat_uptr_t device_ptr;
11458 +       compat_uptr_t target_ptr;
11459 +       uint32_t flags;
11460 +};
11461 +
11462 +#endif /* CONFIG_COMPAT */
11463 +
11464 +#include <linux/compiler.h>
11465 +
11466 +extern int vc_set_mapping(struct vx_info *, void __user *);
11467 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11468 +
11469 +#ifdef CONFIG_COMPAT
11470 +
11471 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11472 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11473 +
11474 +#endif /* CONFIG_COMPAT */
11475 +
11476 +#endif /* __KERNEL__ */
11477 +#endif /* _VX_DEVICE_CMD_H */
11478 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/device_def.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/device_def.h
11479 --- linux-2.6.27.6/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
11480 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/device_def.h        2008-10-13 14:54:20.000000000 +0200
11481 @@ -0,0 +1,17 @@
11482 +#ifndef _VX_DEVICE_DEF_H
11483 +#define _VX_DEVICE_DEF_H
11484 +
11485 +#include <linux/types.h>
11486 +
11487 +struct vx_dmap_target {
11488 +       dev_t target;
11489 +       uint32_t flags;
11490 +};
11491 +
11492 +struct _vx_device {
11493 +#ifdef CONFIG_VSERVER_DEVICE
11494 +       struct vx_dmap_target targets[2];
11495 +#endif
11496 +};
11497 +
11498 +#endif /* _VX_DEVICE_DEF_H */
11499 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/device.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/device.h
11500 --- linux-2.6.27.6/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
11501 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/device.h    2008-10-13 14:54:20.000000000 +0200
11502 @@ -0,0 +1,15 @@
11503 +#ifndef _VX_DEVICE_H
11504 +#define _VX_DEVICE_H
11505 +
11506 +
11507 +#define DATTR_CREATE   0x00000001
11508 +#define DATTR_OPEN     0x00000002
11509 +
11510 +#define DATTR_REMAP    0x00000010
11511 +
11512 +#define DATTR_MASK     0x00000013
11513 +
11514 +
11515 +#else  /* _VX_DEVICE_H */
11516 +#warning duplicate inclusion
11517 +#endif /* _VX_DEVICE_H */
11518 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/dlimit_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/dlimit_cmd.h
11519 --- linux-2.6.27.6/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11520 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/dlimit_cmd.h        2008-10-13 14:54:20.000000000 +0200
11521 @@ -0,0 +1,74 @@
11522 +#ifndef _VX_DLIMIT_CMD_H
11523 +#define _VX_DLIMIT_CMD_H
11524 +
11525 +
11526 +/*  dlimit vserver commands */
11527 +
11528 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11529 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11530 +
11531 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11532 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11533 +
11534 +struct vcmd_ctx_dlimit_base_v0 {
11535 +       const char __user *name;
11536 +       uint32_t flags;
11537 +};
11538 +
11539 +struct vcmd_ctx_dlimit_v0 {
11540 +       const char __user *name;
11541 +       uint32_t space_used;                    /* used space in kbytes */
11542 +       uint32_t space_total;                   /* maximum space in kbytes */
11543 +       uint32_t inodes_used;                   /* used inodes */
11544 +       uint32_t inodes_total;                  /* maximum inodes */
11545 +       uint32_t reserved;                      /* reserved for root in % */
11546 +       uint32_t flags;
11547 +};
11548 +
11549 +#define CDLIM_UNSET            ((uint32_t)0UL)
11550 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11551 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11552 +
11553 +#ifdef __KERNEL__
11554 +
11555 +#ifdef CONFIG_COMPAT
11556 +
11557 +#include <asm/compat.h>
11558 +
11559 +struct vcmd_ctx_dlimit_base_v0_x32 {
11560 +       compat_uptr_t name_ptr;
11561 +       uint32_t flags;
11562 +};
11563 +
11564 +struct vcmd_ctx_dlimit_v0_x32 {
11565 +       compat_uptr_t name_ptr;
11566 +       uint32_t space_used;                    /* used space in kbytes */
11567 +       uint32_t space_total;                   /* maximum space in kbytes */
11568 +       uint32_t inodes_used;                   /* used inodes */
11569 +       uint32_t inodes_total;                  /* maximum inodes */
11570 +       uint32_t reserved;                      /* reserved for root in % */
11571 +       uint32_t flags;
11572 +};
11573 +
11574 +#endif /* CONFIG_COMPAT */
11575 +
11576 +#include <linux/compiler.h>
11577 +
11578 +extern int vc_add_dlimit(uint32_t, void __user *);
11579 +extern int vc_rem_dlimit(uint32_t, void __user *);
11580 +
11581 +extern int vc_set_dlimit(uint32_t, void __user *);
11582 +extern int vc_get_dlimit(uint32_t, void __user *);
11583 +
11584 +#ifdef CONFIG_COMPAT
11585 +
11586 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11587 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11588 +
11589 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11590 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11591 +
11592 +#endif /* CONFIG_COMPAT */
11593 +
11594 +#endif /* __KERNEL__ */
11595 +#endif /* _VX_DLIMIT_CMD_H */
11596 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/dlimit.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/dlimit.h
11597 --- linux-2.6.27.6/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
11598 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/dlimit.h    2008-10-13 14:54:20.000000000 +0200
11599 @@ -0,0 +1,54 @@
11600 +#ifndef _VX_DLIMIT_H
11601 +#define _VX_DLIMIT_H
11602 +
11603 +#include "switch.h"
11604 +
11605 +
11606 +#ifdef __KERNEL__
11607 +
11608 +/*      keep in sync with CDLIM_INFINITY       */
11609 +
11610 +#define DLIM_INFINITY          (~0ULL)
11611 +
11612 +#include <linux/spinlock.h>
11613 +#include <linux/rcupdate.h>
11614 +
11615 +struct super_block;
11616 +
11617 +struct dl_info {
11618 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11619 +       struct rcu_head dl_rcu;                 /* the rcu head */
11620 +       tag_t dl_tag;                           /* context tag */
11621 +       atomic_t dl_usecnt;                     /* usage count */
11622 +       atomic_t dl_refcnt;                     /* reference count */
11623 +
11624 +       struct super_block *dl_sb;              /* associated superblock */
11625 +
11626 +       spinlock_t dl_lock;                     /* protect the values */
11627 +
11628 +       unsigned long long dl_space_used;       /* used space in bytes */
11629 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11630 +       unsigned long dl_inodes_used;           /* used inodes */
11631 +       unsigned long dl_inodes_total;          /* maximum inodes */
11632 +
11633 +       unsigned int dl_nrlmult;                /* non root limit mult */
11634 +};
11635 +
11636 +struct rcu_head;
11637 +
11638 +extern void rcu_free_dl_info(struct rcu_head *);
11639 +extern void unhash_dl_info(struct dl_info *);
11640 +
11641 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11642 +
11643 +
11644 +struct kstatfs;
11645 +
11646 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11647 +
11648 +typedef uint64_t dlsize_t;
11649 +
11650 +#endif /* __KERNEL__ */
11651 +#else  /* _VX_DLIMIT_H */
11652 +#warning duplicate inclusion
11653 +#endif /* _VX_DLIMIT_H */
11654 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/global.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/global.h
11655 --- linux-2.6.27.6/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11656 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/global.h    2008-10-13 14:54:20.000000000 +0200
11657 @@ -0,0 +1,20 @@
11658 +#ifndef _VX_GLOBAL_H
11659 +#define _VX_GLOBAL_H
11660 +
11661 +
11662 +extern atomic_t vx_global_ctotal;
11663 +extern atomic_t vx_global_cactive;
11664 +
11665 +extern atomic_t nx_global_ctotal;
11666 +extern atomic_t nx_global_cactive;
11667 +
11668 +extern atomic_t vs_global_nsproxy;
11669 +extern atomic_t vs_global_fs;
11670 +extern atomic_t vs_global_mnt_ns;
11671 +extern atomic_t vs_global_uts_ns;
11672 +extern atomic_t vs_global_ipc_ns;
11673 +extern atomic_t vs_global_user_ns;
11674 +extern atomic_t vs_global_pid_ns;
11675 +
11676 +
11677 +#endif /* _VX_GLOBAL_H */
11678 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/history.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/history.h
11679 --- linux-2.6.27.6/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11680 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/history.h   2008-10-13 14:54:20.000000000 +0200
11681 @@ -0,0 +1,197 @@
11682 +#ifndef _VX_HISTORY_H
11683 +#define _VX_HISTORY_H
11684 +
11685 +
11686 +enum {
11687 +       VXH_UNUSED = 0,
11688 +       VXH_THROW_OOPS = 1,
11689 +
11690 +       VXH_GET_VX_INFO,
11691 +       VXH_PUT_VX_INFO,
11692 +       VXH_INIT_VX_INFO,
11693 +       VXH_SET_VX_INFO,
11694 +       VXH_CLR_VX_INFO,
11695 +       VXH_CLAIM_VX_INFO,
11696 +       VXH_RELEASE_VX_INFO,
11697 +       VXH_ALLOC_VX_INFO,
11698 +       VXH_DEALLOC_VX_INFO,
11699 +       VXH_HASH_VX_INFO,
11700 +       VXH_UNHASH_VX_INFO,
11701 +       VXH_LOC_VX_INFO,
11702 +       VXH_LOOKUP_VX_INFO,
11703 +       VXH_CREATE_VX_INFO,
11704 +};
11705 +
11706 +struct _vxhe_vxi {
11707 +       struct vx_info *ptr;
11708 +       unsigned xid;
11709 +       unsigned usecnt;
11710 +       unsigned tasks;
11711 +};
11712 +
11713 +struct _vxhe_set_clr {
11714 +       void *data;
11715 +};
11716 +
11717 +struct _vxhe_loc_lookup {
11718 +       unsigned arg;
11719 +};
11720 +
11721 +struct _vx_hist_entry {
11722 +       void *loc;
11723 +       unsigned short seq;
11724 +       unsigned short type;
11725 +       struct _vxhe_vxi vxi;
11726 +       union {
11727 +               struct _vxhe_set_clr sc;
11728 +               struct _vxhe_loc_lookup ll;
11729 +       };
11730 +};
11731 +
11732 +#ifdef CONFIG_VSERVER_HISTORY
11733 +
11734 +extern unsigned volatile int vxh_active;
11735 +
11736 +struct _vx_hist_entry *vxh_advance(void *loc);
11737 +
11738 +
11739 +static inline
11740 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11741 +{
11742 +       entry->vxi.ptr = vxi;
11743 +       if (vxi) {
11744 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11745 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11746 +               entry->vxi.xid = vxi->vx_id;
11747 +       }
11748 +}
11749 +
11750 +
11751 +#define        __HERE__ current_text_addr()
11752 +
11753 +#define __VXH_BODY(__type, __data, __here)     \
11754 +       struct _vx_hist_entry *entry;           \
11755 +                                               \
11756 +       preempt_disable();                      \
11757 +       entry = vxh_advance(__here);            \
11758 +       __data;                                 \
11759 +       entry->type = __type;                   \
11760 +       preempt_enable();
11761 +
11762 +
11763 +       /* pass vxi only */
11764 +
11765 +#define __VXH_SMPL                             \
11766 +       __vxh_copy_vxi(entry, vxi)
11767 +
11768 +static inline
11769 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11770 +{
11771 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11772 +}
11773 +
11774 +       /* pass vxi and data (void *) */
11775 +
11776 +#define __VXH_DATA                             \
11777 +       __vxh_copy_vxi(entry, vxi);             \
11778 +       entry->sc.data = data
11779 +
11780 +static inline
11781 +void   __vxh_data(struct vx_info *vxi, void *data,
11782 +                       int __type, void *__here)
11783 +{
11784 +       __VXH_BODY(__type, __VXH_DATA, __here)
11785 +}
11786 +
11787 +       /* pass vxi and arg (long) */
11788 +
11789 +#define __VXH_LONG                             \
11790 +       __vxh_copy_vxi(entry, vxi);             \
11791 +       entry->ll.arg = arg
11792 +
11793 +static inline
11794 +void   __vxh_long(struct vx_info *vxi, long arg,
11795 +                       int __type, void *__here)
11796 +{
11797 +       __VXH_BODY(__type, __VXH_LONG, __here)
11798 +}
11799 +
11800 +
11801 +static inline
11802 +void   __vxh_throw_oops(void *__here)
11803 +{
11804 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11805 +       /* prevent further acquisition */
11806 +       vxh_active = 0;
11807 +}
11808 +
11809 +
11810 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11811 +
11812 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11813 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11814 +
11815 +#define __vxh_init_vx_info(v, d, h) \
11816 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11817 +#define __vxh_set_vx_info(v, d, h) \
11818 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11819 +#define __vxh_clr_vx_info(v, d, h) \
11820 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11821 +
11822 +#define __vxh_claim_vx_info(v, d, h) \
11823 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11824 +#define __vxh_release_vx_info(v, d, h) \
11825 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11826 +
11827 +#define vxh_alloc_vx_info(v) \
11828 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11829 +#define vxh_dealloc_vx_info(v) \
11830 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11831 +
11832 +#define vxh_hash_vx_info(v) \
11833 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11834 +#define vxh_unhash_vx_info(v) \
11835 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11836 +
11837 +#define vxh_loc_vx_info(v, l) \
11838 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11839 +#define vxh_lookup_vx_info(v, l) \
11840 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11841 +#define vxh_create_vx_info(v, l) \
11842 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11843 +
11844 +extern void vxh_dump_history(void);
11845 +
11846 +
11847 +#else  /* CONFIG_VSERVER_HISTORY */
11848 +
11849 +#define        __HERE__        0
11850 +
11851 +#define vxh_throw_oops()               do { } while (0)
11852 +
11853 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11854 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11855 +
11856 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11857 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11858 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11859 +
11860 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11861 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11862 +
11863 +#define vxh_alloc_vx_info(v)           do { } while (0)
11864 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11865 +
11866 +#define vxh_hash_vx_info(v)            do { } while (0)
11867 +#define vxh_unhash_vx_info(v)          do { } while (0)
11868 +
11869 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11870 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11871 +#define vxh_create_vx_info(v, l)       do { } while (0)
11872 +
11873 +#define vxh_dump_history()             do { } while (0)
11874 +
11875 +
11876 +#endif /* CONFIG_VSERVER_HISTORY */
11877 +
11878 +#endif /* _VX_HISTORY_H */
11879 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/inode_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/inode_cmd.h
11880 --- linux-2.6.27.6/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11881 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/inode_cmd.h 2008-10-13 14:54:20.000000000 +0200
11882 @@ -0,0 +1,59 @@
11883 +#ifndef _VX_INODE_CMD_H
11884 +#define _VX_INODE_CMD_H
11885 +
11886 +
11887 +/*  inode vserver commands */
11888 +
11889 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11890 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11891 +
11892 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11893 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11894 +
11895 +struct vcmd_ctx_iattr_v1 {
11896 +       const char __user *name;
11897 +       uint32_t tag;
11898 +       uint32_t flags;
11899 +       uint32_t mask;
11900 +};
11901 +
11902 +struct vcmd_ctx_fiattr_v0 {
11903 +       uint32_t tag;
11904 +       uint32_t flags;
11905 +       uint32_t mask;
11906 +};
11907 +
11908 +
11909 +#ifdef __KERNEL__
11910 +
11911 +
11912 +#ifdef CONFIG_COMPAT
11913 +
11914 +#include <asm/compat.h>
11915 +
11916 +struct vcmd_ctx_iattr_v1_x32 {
11917 +       compat_uptr_t name_ptr;
11918 +       uint32_t tag;
11919 +       uint32_t flags;
11920 +       uint32_t mask;
11921 +};
11922 +
11923 +#endif /* CONFIG_COMPAT */
11924 +
11925 +#include <linux/compiler.h>
11926 +
11927 +extern int vc_get_iattr(void __user *);
11928 +extern int vc_set_iattr(void __user *);
11929 +
11930 +extern int vc_fget_iattr(uint32_t, void __user *);
11931 +extern int vc_fset_iattr(uint32_t, void __user *);
11932 +
11933 +#ifdef CONFIG_COMPAT
11934 +
11935 +extern int vc_get_iattr_x32(void __user *);
11936 +extern int vc_set_iattr_x32(void __user *);
11937 +
11938 +#endif /* CONFIG_COMPAT */
11939 +
11940 +#endif /* __KERNEL__ */
11941 +#endif /* _VX_INODE_CMD_H */
11942 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/inode.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/inode.h
11943 --- linux-2.6.27.6/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11944 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/inode.h     2008-10-13 14:54:20.000000000 +0200
11945 @@ -0,0 +1,38 @@
11946 +#ifndef _VX_INODE_H
11947 +#define _VX_INODE_H
11948 +
11949 +
11950 +#define IATTR_TAG      0x01000000
11951 +
11952 +#define IATTR_ADMIN    0x00000001
11953 +#define IATTR_WATCH    0x00000002
11954 +#define IATTR_HIDE     0x00000004
11955 +#define IATTR_FLAGS    0x00000007
11956 +
11957 +#define IATTR_BARRIER  0x00010000
11958 +#define IATTR_IXUNLINK 0x00020000
11959 +#define IATTR_IMMUTABLE 0x00040000
11960 +
11961 +#ifdef __KERNEL__
11962 +
11963 +
11964 +#ifdef CONFIG_VSERVER_PROC_SECURE
11965 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11966 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11967 +#else
11968 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11969 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11970 +#endif
11971 +
11972 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11973 +
11974 +#endif /* __KERNEL__ */
11975 +
11976 +/* inode ioctls */
11977 +
11978 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11979 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11980 +
11981 +#else  /* _VX_INODE_H */
11982 +#warning duplicate inclusion
11983 +#endif /* _VX_INODE_H */
11984 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/Kbuild linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/Kbuild
11985 --- linux-2.6.27.6/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11986 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/Kbuild      2008-10-13 14:54:20.000000000 +0200
11987 @@ -0,0 +1,8 @@
11988 +
11989 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11990 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11991 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11992 +       debug_cmd.h device_cmd.h
11993 +
11994 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11995 +
11996 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/limit_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit_cmd.h
11997 --- linux-2.6.27.6/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11998 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit_cmd.h 2008-10-13 14:54:20.000000000 +0200
11999 @@ -0,0 +1,69 @@
12000 +#ifndef _VX_LIMIT_CMD_H
12001 +#define _VX_LIMIT_CMD_H
12002 +
12003 +
12004 +/*  rlimit vserver commands */
12005 +
12006 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12007 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12008 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12009 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12010 +
12011 +struct vcmd_ctx_rlimit_v0 {
12012 +       uint32_t id;
12013 +       uint64_t minimum;
12014 +       uint64_t softlimit;
12015 +       uint64_t maximum;
12016 +};
12017 +
12018 +struct vcmd_ctx_rlimit_mask_v0 {
12019 +       uint32_t minimum;
12020 +       uint32_t softlimit;
12021 +       uint32_t maximum;
12022 +};
12023 +
12024 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12025 +
12026 +struct vcmd_rlimit_stat_v0 {
12027 +       uint32_t id;
12028 +       uint32_t hits;
12029 +       uint64_t value;
12030 +       uint64_t minimum;
12031 +       uint64_t maximum;
12032 +};
12033 +
12034 +#define CRLIM_UNSET            (0ULL)
12035 +#define CRLIM_INFINITY         (~0ULL)
12036 +#define CRLIM_KEEP             (~1ULL)
12037 +
12038 +#ifdef __KERNEL__
12039 +
12040 +#ifdef CONFIG_IA32_EMULATION
12041 +
12042 +struct vcmd_ctx_rlimit_v0_x32 {
12043 +       uint32_t id;
12044 +       uint64_t minimum;
12045 +       uint64_t softlimit;
12046 +       uint64_t maximum;
12047 +} __attribute__ ((aligned (4)));
12048 +
12049 +#endif /* CONFIG_IA32_EMULATION */
12050 +
12051 +#include <linux/compiler.h>
12052 +
12053 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12054 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12055 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12056 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12057 +
12058 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12059 +
12060 +#ifdef CONFIG_IA32_EMULATION
12061 +
12062 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12063 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12064 +
12065 +#endif /* CONFIG_IA32_EMULATION */
12066 +
12067 +#endif /* __KERNEL__ */
12068 +#endif /* _VX_LIMIT_CMD_H */
12069 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/limit_def.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit_def.h
12070 --- linux-2.6.27.6/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
12071 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit_def.h 2008-10-13 14:54:20.000000000 +0200
12072 @@ -0,0 +1,47 @@
12073 +#ifndef _VX_LIMIT_DEF_H
12074 +#define _VX_LIMIT_DEF_H
12075 +
12076 +#include <asm/atomic.h>
12077 +#include <asm/resource.h>
12078 +
12079 +#include "limit.h"
12080 +
12081 +
12082 +struct _vx_res_limit {
12083 +       rlim_t soft;            /* Context soft limit */
12084 +       rlim_t hard;            /* Context hard limit */
12085 +
12086 +       rlim_atomic_t rcur;     /* Current value */
12087 +       rlim_t rmin;            /* Context minimum */
12088 +       rlim_t rmax;            /* Context maximum */
12089 +
12090 +       atomic_t lhit;          /* Limit hits */
12091 +};
12092 +
12093 +/* context sub struct */
12094 +
12095 +struct _vx_limit {
12096 +       struct _vx_res_limit res[NUM_LIMITS];
12097 +};
12098 +
12099 +#ifdef CONFIG_VSERVER_DEBUG
12100 +
12101 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12102 +{
12103 +       int i;
12104 +
12105 +       printk("\t_vx_limit:");
12106 +       for (i = 0; i < NUM_LIMITS; i++) {
12107 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12108 +                       i, (unsigned long)__rlim_get(limit, i),
12109 +                       (unsigned long)__rlim_rmin(limit, i),
12110 +                       (unsigned long)__rlim_rmax(limit, i),
12111 +                       (long)__rlim_soft(limit, i),
12112 +                       (long)__rlim_hard(limit, i),
12113 +                       atomic_read(&__rlim_lhit(limit, i)));
12114 +       }
12115 +}
12116 +
12117 +#endif
12118 +
12119 +#endif /* _VX_LIMIT_DEF_H */
12120 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/limit.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit.h
12121 --- linux-2.6.27.6/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
12122 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit.h     2008-10-13 14:54:20.000000000 +0200
12123 @@ -0,0 +1,70 @@
12124 +#ifndef _VX_LIMIT_H
12125 +#define _VX_LIMIT_H
12126 +
12127 +#define VLIMIT_NSOCK   16
12128 +#define VLIMIT_OPENFD  17
12129 +#define VLIMIT_ANON    18
12130 +#define VLIMIT_SHMEM   19
12131 +#define VLIMIT_SEMARY  20
12132 +#define VLIMIT_NSEMS   21
12133 +#define VLIMIT_DENTRY  22
12134 +#define VLIMIT_MAPPED  23
12135 +
12136 +
12137 +#ifdef __KERNEL__
12138 +
12139 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12140 +
12141 +/*     keep in sync with CRLIM_INFINITY */
12142 +
12143 +#define        VLIM_INFINITY   (~0ULL)
12144 +
12145 +#include <asm/atomic.h>
12146 +#include <asm/resource.h>
12147 +
12148 +#ifndef RLIM_INFINITY
12149 +#warning RLIM_INFINITY is undefined
12150 +#endif
12151 +
12152 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12153 +
12154 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12155 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12156 +
12157 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12158 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12159 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12160 +
12161 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12162 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12163 +
12164 +typedef atomic_long_t rlim_atomic_t;
12165 +typedef unsigned long rlim_t;
12166 +
12167 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12168 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12169 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12170 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12171 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12172 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12173 +
12174 +
12175 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12176 +#define        VX_VLIM(r) ((long long)(long)(r))
12177 +#define        VX_RLIM(v) ((rlim_t)(v))
12178 +#else
12179 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12180 +               ? VLIM_INFINITY : (long long)(r))
12181 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12182 +               ? RLIM_INFINITY : (rlim_t)(v))
12183 +#endif
12184 +
12185 +struct sysinfo;
12186 +
12187 +void vx_vsi_meminfo(struct sysinfo *);
12188 +void vx_vsi_swapinfo(struct sysinfo *);
12189 +
12190 +#define NUM_LIMITS     24
12191 +
12192 +#endif /* __KERNEL__ */
12193 +#endif /* _VX_LIMIT_H */
12194 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/limit_int.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit_int.h
12195 --- linux-2.6.27.6/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
12196 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/limit_int.h 2008-10-13 14:54:20.000000000 +0200
12197 @@ -0,0 +1,198 @@
12198 +#ifndef _VX_LIMIT_INT_H
12199 +#define _VX_LIMIT_INT_H
12200 +
12201 +#include "context.h"
12202 +
12203 +#ifdef __KERNEL__
12204 +
12205 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12206 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12207 +
12208 +extern const char *vlimit_name[NUM_LIMITS];
12209 +
12210 +static inline void __vx_acc_cres(struct vx_info *vxi,
12211 +       int res, int dir, void *_data, char *_file, int _line)
12212 +{
12213 +       if (VXD_RCRES_COND(res))
12214 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12215 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12216 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12217 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12218 +       if (!vxi)
12219 +               return;
12220 +
12221 +       if (dir > 0)
12222 +               __rlim_inc(&vxi->limit, res);
12223 +       else
12224 +               __rlim_dec(&vxi->limit, res);
12225 +}
12226 +
12227 +static inline void __vx_add_cres(struct vx_info *vxi,
12228 +       int res, int amount, void *_data, char *_file, int _line)
12229 +{
12230 +       if (VXD_RCRES_COND(res))
12231 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12232 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12233 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12234 +                       amount, _data, _file, _line);
12235 +       if (amount == 0)
12236 +               return;
12237 +       if (!vxi)
12238 +               return;
12239 +       __rlim_add(&vxi->limit, res, amount);
12240 +}
12241 +
12242 +static inline
12243 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12244 +{
12245 +       int cond = (value > __rlim_rmax(limit, res));
12246 +
12247 +       if (cond)
12248 +               __rlim_rmax(limit, res) = value;
12249 +       return cond;
12250 +}
12251 +
12252 +static inline
12253 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12254 +{
12255 +       int cond = (value < __rlim_rmin(limit, res));
12256 +
12257 +       if (cond)
12258 +               __rlim_rmin(limit, res) = value;
12259 +       return cond;
12260 +}
12261 +
12262 +static inline
12263 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12264 +{
12265 +       if (!__vx_cres_adjust_max(limit, res, value))
12266 +               __vx_cres_adjust_min(limit, res, value);
12267 +}
12268 +
12269 +
12270 +/*     return values:
12271 +        +1 ... no limit hit
12272 +        -1 ... over soft limit
12273 +         0 ... over hard limit         */
12274 +
12275 +static inline int __vx_cres_avail(struct vx_info *vxi,
12276 +       int res, int num, char *_file, int _line)
12277 +{
12278 +       struct _vx_limit *limit;
12279 +       rlim_t value;
12280 +
12281 +       if (VXD_RLIMIT_COND(res))
12282 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12283 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12284 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12285 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12286 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12287 +                       num, _file, _line);
12288 +       if (!vxi)
12289 +               return 1;
12290 +
12291 +       limit = &vxi->limit;
12292 +       value = __rlim_get(limit, res);
12293 +
12294 +       if (!__vx_cres_adjust_max(limit, res, value))
12295 +               __vx_cres_adjust_min(limit, res, value);
12296 +
12297 +       if (num == 0)
12298 +               return 1;
12299 +
12300 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12301 +               return -1;
12302 +       if (value + num <= __rlim_soft(limit, res))
12303 +               return -1;
12304 +
12305 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12306 +               return 1;
12307 +       if (value + num <= __rlim_hard(limit, res))
12308 +               return 1;
12309 +
12310 +       __rlim_hit(limit, res);
12311 +       return 0;
12312 +}
12313 +
12314 +
12315 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12316 +
12317 +static inline
12318 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12319 +{
12320 +       rlim_t value, sum = 0;
12321 +       int res;
12322 +
12323 +       while ((res = *array++)) {
12324 +               value = __rlim_get(limit, res);
12325 +               __vx_cres_fixup(limit, res, value);
12326 +               sum += value;
12327 +       }
12328 +       return sum;
12329 +}
12330 +
12331 +static inline
12332 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12333 +{
12334 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12335 +       int res = *array;
12336 +
12337 +       if (value == __rlim_get(limit, res))
12338 +               return value;
12339 +
12340 +       __rlim_set(limit, res, value);
12341 +       /* now adjust min/max */
12342 +       if (!__vx_cres_adjust_max(limit, res, value))
12343 +               __vx_cres_adjust_min(limit, res, value);
12344 +
12345 +       return value;
12346 +}
12347 +
12348 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12349 +       const int *array, int num, char *_file, int _line)
12350 +{
12351 +       struct _vx_limit *limit;
12352 +       rlim_t value = 0;
12353 +       int res;
12354 +
12355 +       if (num == 0)
12356 +               return 1;
12357 +       if (!vxi)
12358 +               return 1;
12359 +
12360 +       limit = &vxi->limit;
12361 +       res = *array;
12362 +       value = __vx_cres_array_sum(limit, array + 1);
12363 +
12364 +       __rlim_set(limit, res, value);
12365 +       __vx_cres_fixup(limit, res, value);
12366 +
12367 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12368 +}
12369 +
12370 +
12371 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12372 +{
12373 +       rlim_t value;
12374 +       int res;
12375 +
12376 +       /* complex resources first */
12377 +       if ((id < 0) || (id == RLIMIT_RSS))
12378 +               __vx_cres_array_fixup(limit, VLA_RSS);
12379 +
12380 +       for (res = 0; res < NUM_LIMITS; res++) {
12381 +               if ((id > 0) && (res != id))
12382 +                       continue;
12383 +
12384 +               value = __rlim_get(limit, res);
12385 +               __vx_cres_fixup(limit, res, value);
12386 +
12387 +               /* not supposed to happen, maybe warn? */
12388 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12389 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12390 +       }
12391 +}
12392 +
12393 +
12394 +#endif /* __KERNEL__ */
12395 +#endif /* _VX_LIMIT_INT_H */
12396 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/monitor.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/monitor.h
12397 --- linux-2.6.27.6/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
12398 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/monitor.h   2008-10-13 14:54:20.000000000 +0200
12399 @@ -0,0 +1,96 @@
12400 +#ifndef _VX_MONITOR_H
12401 +#define _VX_MONITOR_H
12402 +
12403 +#include <linux/types.h>
12404 +
12405 +enum {
12406 +       VXM_UNUSED = 0,
12407 +
12408 +       VXM_SYNC = 0x10,
12409 +
12410 +       VXM_UPDATE = 0x20,
12411 +       VXM_UPDATE_1,
12412 +       VXM_UPDATE_2,
12413 +
12414 +       VXM_RQINFO_1 = 0x24,
12415 +       VXM_RQINFO_2,
12416 +
12417 +       VXM_ACTIVATE = 0x40,
12418 +       VXM_DEACTIVATE,
12419 +       VXM_IDLE,
12420 +
12421 +       VXM_HOLD = 0x44,
12422 +       VXM_UNHOLD,
12423 +
12424 +       VXM_MIGRATE = 0x48,
12425 +       VXM_RESCHED,
12426 +
12427 +       /* all other bits are flags */
12428 +       VXM_SCHED = 0x80,
12429 +};
12430 +
12431 +struct _vxm_update_1 {
12432 +       uint32_t tokens_max;
12433 +       uint32_t fill_rate;
12434 +       uint32_t interval;
12435 +};
12436 +
12437 +struct _vxm_update_2 {
12438 +       uint32_t tokens_min;
12439 +       uint32_t fill_rate;
12440 +       uint32_t interval;
12441 +};
12442 +
12443 +struct _vxm_rqinfo_1 {
12444 +       uint16_t running;
12445 +       uint16_t onhold;
12446 +       uint16_t iowait;
12447 +       uint16_t uintr;
12448 +       uint32_t idle_tokens;
12449 +};
12450 +
12451 +struct _vxm_rqinfo_2 {
12452 +       uint32_t norm_time;
12453 +       uint32_t idle_time;
12454 +       uint32_t idle_skip;
12455 +};
12456 +
12457 +struct _vxm_sched {
12458 +       uint32_t tokens;
12459 +       uint32_t norm_time;
12460 +       uint32_t idle_time;
12461 +};
12462 +
12463 +struct _vxm_task {
12464 +       uint16_t pid;
12465 +       uint16_t state;
12466 +};
12467 +
12468 +struct _vxm_event {
12469 +       uint32_t jif;
12470 +       union {
12471 +               uint32_t seq;
12472 +               uint32_t sec;
12473 +       };
12474 +       union {
12475 +               uint32_t tokens;
12476 +               uint32_t nsec;
12477 +               struct _vxm_task tsk;
12478 +       };
12479 +};
12480 +
12481 +struct _vx_mon_entry {
12482 +       uint16_t type;
12483 +       uint16_t xid;
12484 +       union {
12485 +               struct _vxm_event ev;
12486 +               struct _vxm_sched sd;
12487 +               struct _vxm_update_1 u1;
12488 +               struct _vxm_update_2 u2;
12489 +               struct _vxm_rqinfo_1 q1;
12490 +               struct _vxm_rqinfo_2 q2;
12491 +       };
12492 +};
12493 +
12494 +
12495 +#endif /* _VX_MONITOR_H */
12496 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/network_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/network_cmd.h
12497 --- linux-2.6.27.6/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
12498 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/network_cmd.h       2008-10-13 14:54:20.000000000 +0200
12499 @@ -0,0 +1,150 @@
12500 +#ifndef _VX_NETWORK_CMD_H
12501 +#define _VX_NETWORK_CMD_H
12502 +
12503 +
12504 +/* vinfo commands */
12505 +
12506 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12507 +
12508 +#ifdef __KERNEL__
12509 +extern int vc_task_nid(uint32_t);
12510 +
12511 +#endif /* __KERNEL__ */
12512 +
12513 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12514 +
12515 +struct vcmd_nx_info_v0 {
12516 +       uint32_t nid;
12517 +       /* more to come */
12518 +};
12519 +
12520 +#ifdef __KERNEL__
12521 +extern int vc_nx_info(struct nx_info *, void __user *);
12522 +
12523 +#endif /* __KERNEL__ */
12524 +
12525 +#include <linux/in.h>
12526 +#include <linux/in6.h>
12527 +
12528 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12529 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12530 +
12531 +struct  vcmd_net_create {
12532 +       uint64_t flagword;
12533 +};
12534 +
12535 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12536 +
12537 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12538 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12539 +
12540 +struct vcmd_net_addr_v0 {
12541 +       uint16_t type;
12542 +       uint16_t count;
12543 +       struct in_addr ip[4];
12544 +       struct in_addr mask[4];
12545 +};
12546 +
12547 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12548 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12549 +
12550 +struct vcmd_net_addr_ipv4_v1 {
12551 +       uint16_t type;
12552 +       uint16_t flags;
12553 +       struct in_addr ip;
12554 +       struct in_addr mask;
12555 +};
12556 +
12557 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12558 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12559 +
12560 +struct vcmd_net_addr_ipv6_v1 {
12561 +       uint16_t type;
12562 +       uint16_t flags;
12563 +       uint32_t prefix;
12564 +       struct in6_addr ip;
12565 +       struct in6_addr mask;
12566 +};
12567 +
12568 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12569 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12570 +
12571 +struct vcmd_match_ipv4_v0 {
12572 +       uint16_t type;
12573 +       uint16_t flags;
12574 +       uint16_t parent;
12575 +       uint16_t prefix;
12576 +       struct in_addr ip;
12577 +       struct in_addr ip2;
12578 +       struct in_addr mask;
12579 +};
12580 +
12581 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12582 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12583 +
12584 +struct vcmd_match_ipv6_v0 {
12585 +       uint16_t type;
12586 +       uint16_t flags;
12587 +       uint16_t parent;
12588 +       uint16_t prefix;
12589 +       struct in6_addr ip;
12590 +       struct in6_addr ip2;
12591 +       struct in6_addr mask;
12592 +};
12593 +
12594 +
12595 +#ifdef __KERNEL__
12596 +extern int vc_net_create(uint32_t, void __user *);
12597 +extern int vc_net_migrate(struct nx_info *, void __user *);
12598 +
12599 +extern int vc_net_add(struct nx_info *, void __user *);
12600 +extern int vc_net_remove(struct nx_info *, void __user *);
12601 +
12602 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12603 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12604 +
12605 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12606 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12607 +
12608 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12609 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12610 +
12611 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12612 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12613 +
12614 +#endif /* __KERNEL__ */
12615 +
12616 +
12617 +/* flag commands */
12618 +
12619 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12620 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12621 +
12622 +struct vcmd_net_flags_v0 {
12623 +       uint64_t flagword;
12624 +       uint64_t mask;
12625 +};
12626 +
12627 +#ifdef __KERNEL__
12628 +extern int vc_get_nflags(struct nx_info *, void __user *);
12629 +extern int vc_set_nflags(struct nx_info *, void __user *);
12630 +
12631 +#endif /* __KERNEL__ */
12632 +
12633 +
12634 +/* network caps commands */
12635 +
12636 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12637 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12638 +
12639 +struct vcmd_net_caps_v0 {
12640 +       uint64_t ncaps;
12641 +       uint64_t cmask;
12642 +};
12643 +
12644 +#ifdef __KERNEL__
12645 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12646 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12647 +
12648 +#endif /* __KERNEL__ */
12649 +#endif /* _VX_CONTEXT_CMD_H */
12650 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/network.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/network.h
12651 --- linux-2.6.27.6/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12652 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/network.h   2008-10-13 14:54:20.000000000 +0200
12653 @@ -0,0 +1,146 @@
12654 +#ifndef _VX_NETWORK_H
12655 +#define _VX_NETWORK_H
12656 +
12657 +#include <linux/types.h>
12658 +
12659 +
12660 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12661 +
12662 +
12663 +/* network flags */
12664 +
12665 +#define NXF_INFO_PRIVATE       0x00000008
12666 +
12667 +#define NXF_SINGLE_IP          0x00000100
12668 +#define NXF_LBACK_REMAP                0x00000200
12669 +#define NXF_LBACK_ALLOW                0x00000400
12670 +
12671 +#define NXF_HIDE_NETIF         0x02000000
12672 +#define NXF_HIDE_LBACK         0x04000000
12673 +
12674 +#define NXF_STATE_SETUP                (1ULL << 32)
12675 +#define NXF_STATE_ADMIN                (1ULL << 34)
12676 +
12677 +#define NXF_SC_HELPER          (1ULL << 36)
12678 +#define NXF_PERSISTENT         (1ULL << 38)
12679 +
12680 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12681 +
12682 +
12683 +#define        NXF_INIT_SET            (__nxf_init_set())
12684 +
12685 +static inline uint64_t __nxf_init_set(void) {
12686 +       return    NXF_STATE_ADMIN
12687 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12688 +               | NXF_LBACK_REMAP
12689 +               | NXF_HIDE_LBACK
12690 +#endif
12691 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12692 +               | NXF_SINGLE_IP
12693 +#endif
12694 +               | NXF_HIDE_NETIF;
12695 +}
12696 +
12697 +
12698 +/* network caps */
12699 +
12700 +#define NXC_TUN_CREATE         0x00000001
12701 +
12702 +#define NXC_RAW_ICMP           0x00000100
12703 +
12704 +
12705 +/* address types */
12706 +
12707 +#define NXA_TYPE_IPV4          0x0001
12708 +#define NXA_TYPE_IPV6          0x0002
12709 +
12710 +#define NXA_TYPE_NONE          0x0000
12711 +#define NXA_TYPE_ANY           0x00FF
12712 +
12713 +#define NXA_TYPE_ADDR          0x0010
12714 +#define NXA_TYPE_MASK          0x0020
12715 +#define NXA_TYPE_RANGE         0x0040
12716 +
12717 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12718 +
12719 +#define NXA_MOD_BCAST          0x0100
12720 +#define NXA_MOD_LBACK          0x0200
12721 +
12722 +#define NXA_LOOPBACK           0x1000
12723 +
12724 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12725 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12726 +
12727 +#ifdef __KERNEL__
12728 +
12729 +#include <linux/list.h>
12730 +#include <linux/spinlock.h>
12731 +#include <linux/rcupdate.h>
12732 +#include <linux/in.h>
12733 +#include <linux/in6.h>
12734 +#include <asm/atomic.h>
12735 +
12736 +struct nx_addr_v4 {
12737 +       struct nx_addr_v4 *next;
12738 +       struct in_addr ip[2];
12739 +       struct in_addr mask;
12740 +       uint16_t type;
12741 +       uint16_t flags;
12742 +};
12743 +
12744 +struct nx_addr_v6 {
12745 +       struct nx_addr_v6 *next;
12746 +       struct in6_addr ip;
12747 +       struct in6_addr mask;
12748 +       uint32_t prefix;
12749 +       uint16_t type;
12750 +       uint16_t flags;
12751 +};
12752 +
12753 +struct nx_info {
12754 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12755 +       nid_t nx_id;                    /* vnet id */
12756 +       atomic_t nx_usecnt;             /* usage count */
12757 +       atomic_t nx_tasks;              /* tasks count */
12758 +       int nx_state;                   /* context state */
12759 +
12760 +       uint64_t nx_flags;              /* network flag word */
12761 +       uint64_t nx_ncaps;              /* network capabilities */
12762 +
12763 +       struct in_addr v4_lback;        /* Loopback address */
12764 +       struct in_addr v4_bcast;        /* Broadcast address */
12765 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12766 +#ifdef CONFIG_IPV6
12767 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12768 +#endif
12769 +       char nx_name[65];               /* network context name */
12770 +};
12771 +
12772 +
12773 +/* status flags */
12774 +
12775 +#define NXS_HASHED      0x0001
12776 +#define NXS_SHUTDOWN    0x0100
12777 +#define NXS_RELEASED    0x8000
12778 +
12779 +extern struct nx_info *lookup_nx_info(int);
12780 +
12781 +extern int get_nid_list(int, unsigned int *, int);
12782 +extern int nid_is_hashed(nid_t);
12783 +
12784 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12785 +
12786 +extern long vs_net_change(struct nx_info *, unsigned int);
12787 +
12788 +struct sock;
12789 +
12790 +
12791 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12792 +#ifdef  CONFIG_IPV6
12793 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12794 +#else
12795 +#define NX_IPV6(n)     (0)
12796 +#endif
12797 +
12798 +#endif /* __KERNEL__ */
12799 +#endif /* _VX_NETWORK_H */
12800 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/percpu.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/percpu.h
12801 --- linux-2.6.27.6/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12802 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/percpu.h    2008-10-13 14:54:20.000000000 +0200
12803 @@ -0,0 +1,14 @@
12804 +#ifndef _VX_PERCPU_H
12805 +#define _VX_PERCPU_H
12806 +
12807 +#include "cvirt_def.h"
12808 +#include "sched_def.h"
12809 +
12810 +struct _vx_percpu {
12811 +       struct _vx_cvirt_pc cvirt;
12812 +       struct _vx_sched_pc sched;
12813 +};
12814 +
12815 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12816 +
12817 +#endif /* _VX_PERCPU_H */
12818 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/pid.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/pid.h
12819 --- linux-2.6.27.6/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12820 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/pid.h       2008-10-13 14:54:20.000000000 +0200
12821 @@ -0,0 +1,51 @@
12822 +#ifndef _VSERVER_PID_H
12823 +#define _VSERVER_PID_H
12824 +
12825 +/* pid faking stuff */
12826 +
12827 +#define vx_info_map_pid(v, p) \
12828 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12829 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12830 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12831 +#define vx_map_tgid(p) vx_map_pid(p)
12832 +
12833 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12834 +       const char *func, const char *file, int line)
12835 +{
12836 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12837 +               vxfprintk(VXD_CBIT(cvirt, 2),
12838 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12839 +                       vxi, (long long)vxi->vx_flags, pid,
12840 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12841 +                       func, file, line);
12842 +               if (pid == 0)
12843 +                       return 0;
12844 +               if (pid == vxi->vx_initpid)
12845 +                       return 1;
12846 +       }
12847 +       return pid;
12848 +}
12849 +
12850 +#define vx_info_rmap_pid(v, p) \
12851 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12852 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12853 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12854 +
12855 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12856 +       const char *func, const char *file, int line)
12857 +{
12858 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12859 +               vxfprintk(VXD_CBIT(cvirt, 2),
12860 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12861 +                       vxi, (long long)vxi->vx_flags, pid,
12862 +                       (pid == 1) ? vxi->vx_initpid : pid,
12863 +                       func, file, line);
12864 +               if ((pid == 1) && vxi->vx_initpid)
12865 +                       return vxi->vx_initpid;
12866 +               if (pid == vxi->vx_initpid)
12867 +                       return ~0U;
12868 +       }
12869 +       return pid;
12870 +}
12871 +
12872 +#endif
12873 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/sched_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/sched_cmd.h
12874 --- linux-2.6.27.6/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12875 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/sched_cmd.h 2008-10-13 14:54:20.000000000 +0200
12876 @@ -0,0 +1,108 @@
12877 +#ifndef _VX_SCHED_CMD_H
12878 +#define _VX_SCHED_CMD_H
12879 +
12880 +
12881 +/*  sched vserver commands */
12882 +
12883 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12884 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12885 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12886 +
12887 +struct vcmd_set_sched_v2 {
12888 +       int32_t fill_rate;
12889 +       int32_t interval;
12890 +       int32_t tokens;
12891 +       int32_t tokens_min;
12892 +       int32_t tokens_max;
12893 +       uint64_t cpu_mask;
12894 +};
12895 +
12896 +struct vcmd_set_sched_v3 {
12897 +       uint32_t set_mask;
12898 +       int32_t fill_rate;
12899 +       int32_t interval;
12900 +       int32_t tokens;
12901 +       int32_t tokens_min;
12902 +       int32_t tokens_max;
12903 +       int32_t priority_bias;
12904 +};
12905 +
12906 +struct vcmd_set_sched_v4 {
12907 +       uint32_t set_mask;
12908 +       int32_t fill_rate;
12909 +       int32_t interval;
12910 +       int32_t tokens;
12911 +       int32_t tokens_min;
12912 +       int32_t tokens_max;
12913 +       int32_t prio_bias;
12914 +       int32_t cpu_id;
12915 +       int32_t bucket_id;
12916 +};
12917 +
12918 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12919 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12920 +
12921 +struct vcmd_sched_v5 {
12922 +       uint32_t mask;
12923 +       int32_t cpu_id;
12924 +       int32_t bucket_id;
12925 +       int32_t fill_rate[2];
12926 +       int32_t interval[2];
12927 +       int32_t tokens;
12928 +       int32_t tokens_min;
12929 +       int32_t tokens_max;
12930 +       int32_t prio_bias;
12931 +};
12932 +
12933 +#define VXSM_FILL_RATE         0x0001
12934 +#define VXSM_INTERVAL          0x0002
12935 +#define VXSM_FILL_RATE2                0x0004
12936 +#define VXSM_INTERVAL2         0x0008
12937 +#define VXSM_TOKENS            0x0010
12938 +#define VXSM_TOKENS_MIN                0x0020
12939 +#define VXSM_TOKENS_MAX                0x0040
12940 +#define VXSM_PRIO_BIAS         0x0100
12941 +
12942 +#define VXSM_IDLE_TIME         0x0200
12943 +#define VXSM_FORCE             0x0400
12944 +
12945 +#define        VXSM_V3_MASK            0x0173
12946 +#define        VXSM_SET_MASK           0x01FF
12947 +
12948 +#define VXSM_CPU_ID            0x1000
12949 +#define VXSM_BUCKET_ID         0x2000
12950 +
12951 +#define VXSM_MSEC              0x4000
12952 +
12953 +#define SCHED_KEEP             (-2)    /* only for v2 */
12954 +
12955 +#ifdef __KERNEL__
12956 +
12957 +#include <linux/compiler.h>
12958 +
12959 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12960 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12961 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12962 +extern int vc_set_sched(struct vx_info *, void __user *);
12963 +extern int vc_get_sched(struct vx_info *, void __user *);
12964 +
12965 +#endif /* __KERNEL__ */
12966 +
12967 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12968 +
12969 +struct vcmd_sched_info {
12970 +       int32_t cpu_id;
12971 +       int32_t bucket_id;
12972 +       uint64_t user_msec;
12973 +       uint64_t sys_msec;
12974 +       uint64_t hold_msec;
12975 +       uint32_t token_usec;
12976 +       int32_t vavavoom;
12977 +};
12978 +
12979 +#ifdef __KERNEL__
12980 +
12981 +extern int vc_sched_info(struct vx_info *, void __user *);
12982 +
12983 +#endif /* __KERNEL__ */
12984 +#endif /* _VX_SCHED_CMD_H */
12985 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/sched_def.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/sched_def.h
12986 --- linux-2.6.27.6/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12987 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/sched_def.h 2008-10-13 14:54:20.000000000 +0200
12988 @@ -0,0 +1,68 @@
12989 +#ifndef _VX_SCHED_DEF_H
12990 +#define _VX_SCHED_DEF_H
12991 +
12992 +#include <linux/spinlock.h>
12993 +#include <linux/jiffies.h>
12994 +#include <linux/cpumask.h>
12995 +#include <asm/atomic.h>
12996 +#include <asm/param.h>
12997 +
12998 +
12999 +/* context sub struct */
13000 +
13001 +struct _vx_sched {
13002 +       spinlock_t tokens_lock;         /* lock for token bucket */
13003 +
13004 +       int tokens;                     /* number of CPU tokens */
13005 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13006 +       int interval[2];                /* Divisor:   per Y jiffies   */
13007 +       int tokens_min;                 /* Limit:     minimum for unhold */
13008 +       int tokens_max;                 /* Limit:     no more than N tokens */
13009 +
13010 +       int prio_bias;                  /* bias offset for priority */
13011 +
13012 +       unsigned update_mask;           /* which features should be updated */
13013 +       cpumask_t update;               /* CPUs which should update */
13014 +};
13015 +
13016 +struct _vx_sched_pc {
13017 +       int tokens;                     /* number of CPU tokens */
13018 +       int flags;                      /* bucket flags */
13019 +
13020 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13021 +       int interval[2];                /* Divisor:   per Y jiffies   */
13022 +       int tokens_min;                 /* Limit:     minimum for unhold */
13023 +       int tokens_max;                 /* Limit:     no more than N tokens */
13024 +
13025 +       int prio_bias;                  /* bias offset for priority */
13026 +       int vavavoom;                   /* last calculated vavavoom */
13027 +
13028 +       unsigned long norm_time;        /* last time accounted */
13029 +       unsigned long idle_time;        /* non linear time for fair sched */
13030 +       unsigned long token_time;       /* token time for accounting */
13031 +       unsigned long onhold;           /* jiffies when put on hold */
13032 +
13033 +       uint64_t user_ticks;            /* token tick events */
13034 +       uint64_t sys_ticks;             /* token tick events */
13035 +       uint64_t hold_ticks;            /* token ticks paused */
13036 +};
13037 +
13038 +
13039 +#define VXSF_ONHOLD    0x0001
13040 +#define VXSF_IDLE_TIME 0x0100
13041 +
13042 +#ifdef CONFIG_VSERVER_DEBUG
13043 +
13044 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13045 +{
13046 +       printk("\t_vx_sched:\n");
13047 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
13048 +               sched->fill_rate[0], sched->interval[0],
13049 +               sched->fill_rate[1], sched->interval[1],
13050 +               sched->tokens_min, sched->tokens_max);
13051 +       printk("\t priority = %4d\n", sched->prio_bias);
13052 +}
13053 +
13054 +#endif
13055 +
13056 +#endif /* _VX_SCHED_DEF_H */
13057 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/sched.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/sched.h
13058 --- linux-2.6.27.6/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
13059 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/sched.h     2008-10-13 14:54:20.000000000 +0200
13060 @@ -0,0 +1,26 @@
13061 +#ifndef _VX_SCHED_H
13062 +#define _VX_SCHED_H
13063 +
13064 +
13065 +#ifdef __KERNEL__
13066 +
13067 +struct timespec;
13068 +
13069 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13070 +
13071 +
13072 +struct vx_info;
13073 +
13074 +void vx_update_load(struct vx_info *);
13075 +
13076 +
13077 +int vx_tokens_recalc(struct _vx_sched_pc *,
13078 +       unsigned long *, unsigned long *, int [2]);
13079 +
13080 +void vx_update_sched_param(struct _vx_sched *sched,
13081 +       struct _vx_sched_pc *sched_pc);
13082 +
13083 +#endif /* __KERNEL__ */
13084 +#else  /* _VX_SCHED_H */
13085 +#warning duplicate inclusion
13086 +#endif /* _VX_SCHED_H */
13087 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/signal_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/signal_cmd.h
13088 --- linux-2.6.27.6/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
13089 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/signal_cmd.h        2008-10-13 14:54:20.000000000 +0200
13090 @@ -0,0 +1,43 @@
13091 +#ifndef _VX_SIGNAL_CMD_H
13092 +#define _VX_SIGNAL_CMD_H
13093 +
13094 +
13095 +/*  signalling vserver commands */
13096 +
13097 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13098 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13099 +
13100 +struct vcmd_ctx_kill_v0 {
13101 +       int32_t pid;
13102 +       int32_t sig;
13103 +};
13104 +
13105 +struct vcmd_wait_exit_v0 {
13106 +       int32_t reboot_cmd;
13107 +       int32_t exit_code;
13108 +};
13109 +
13110 +#ifdef __KERNEL__
13111 +
13112 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13113 +extern int vc_wait_exit(struct vx_info *, void __user *);
13114 +
13115 +#endif /* __KERNEL__ */
13116 +
13117 +/*  process alteration commands */
13118 +
13119 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13120 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13121 +
13122 +struct vcmd_pflags_v0 {
13123 +       uint32_t flagword;
13124 +       uint32_t mask;
13125 +};
13126 +
13127 +#ifdef __KERNEL__
13128 +
13129 +extern int vc_get_pflags(uint32_t pid, void __user *);
13130 +extern int vc_set_pflags(uint32_t pid, void __user *);
13131 +
13132 +#endif /* __KERNEL__ */
13133 +#endif /* _VX_SIGNAL_CMD_H */
13134 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/signal.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/signal.h
13135 --- linux-2.6.27.6/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
13136 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/signal.h    2008-10-13 14:54:20.000000000 +0200
13137 @@ -0,0 +1,14 @@
13138 +#ifndef _VX_SIGNAL_H
13139 +#define _VX_SIGNAL_H
13140 +
13141 +
13142 +#ifdef __KERNEL__
13143 +
13144 +struct vx_info;
13145 +
13146 +int vx_info_kill(struct vx_info *, int, int);
13147 +
13148 +#endif /* __KERNEL__ */
13149 +#else  /* _VX_SIGNAL_H */
13150 +#warning duplicate inclusion
13151 +#endif /* _VX_SIGNAL_H */
13152 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/space_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/space_cmd.h
13153 --- linux-2.6.27.6/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
13154 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/space_cmd.h 2008-10-31 03:49:36.000000000 +0100
13155 @@ -0,0 +1,38 @@
13156 +#ifndef _VX_SPACE_CMD_H
13157 +#define _VX_SPACE_CMD_H
13158 +
13159 +
13160 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13161 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13162 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13163 +
13164 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13165 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13166 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13167 +
13168 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13169 +
13170 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13171 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13172 +
13173 +
13174 +struct vcmd_space_mask_v1 {
13175 +       uint64_t mask;
13176 +};
13177 +
13178 +struct vcmd_space_mask_v2 {
13179 +       uint64_t mask;
13180 +       uint32_t index;
13181 +};
13182 +
13183 +
13184 +#ifdef __KERNEL__
13185 +
13186 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13187 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13188 +extern int vc_enter_space(struct vx_info *, void __user *);
13189 +extern int vc_set_space(struct vx_info *, void __user *);
13190 +extern int vc_get_space_mask(void __user *, int);
13191 +
13192 +#endif /* __KERNEL__ */
13193 +#endif /* _VX_SPACE_CMD_H */
13194 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/space.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/space.h
13195 --- linux-2.6.27.6/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
13196 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/space.h     2008-10-31 04:02:02.000000000 +0100
13197 @@ -0,0 +1,12 @@
13198 +#ifndef _VX_SPACE_H
13199 +#define _VX_SPACE_H
13200 +
13201 +#include <linux/types.h>
13202 +
13203 +struct vx_info;
13204 +
13205 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13206 +
13207 +#else  /* _VX_SPACE_H */
13208 +#warning duplicate inclusion
13209 +#endif /* _VX_SPACE_H */
13210 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/switch.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/switch.h
13211 --- linux-2.6.27.6/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
13212 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/switch.h    2008-10-13 14:54:20.000000000 +0200
13213 @@ -0,0 +1,100 @@
13214 +#ifndef _VX_SWITCH_H
13215 +#define _VX_SWITCH_H
13216 +
13217 +#include <linux/types.h>
13218 +
13219 +
13220 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13221 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13222 +#define VC_VERSION(c)          ((c) & 0xFFF)
13223 +
13224 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13225 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13226 +
13227 +/*
13228 +
13229 +  Syscall Matrix V2.8
13230 +
13231 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13232 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13233 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13234 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13235 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13236 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13237 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13238 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13239 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13240 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13241 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13242 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13243 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13244 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13245 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13246 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13247 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13248 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13249 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13250 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13251 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13252 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13253 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13254 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13255 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13256 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13257 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13258 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13259 +
13260 +*/
13261 +
13262 +#define VC_CAT_VERSION         0
13263 +
13264 +#define VC_CAT_VSETUP          1
13265 +#define VC_CAT_VHOST           2
13266 +
13267 +#define VC_CAT_DEVICE          6
13268 +
13269 +#define VC_CAT_VPROC           9
13270 +#define VC_CAT_PROCALT         10
13271 +#define VC_CAT_PROCMIG         11
13272 +#define VC_CAT_PROCTRL         12
13273 +
13274 +#define VC_CAT_SCHED           14
13275 +#define VC_CAT_MEMCTRL         20
13276 +
13277 +#define VC_CAT_VNET            25
13278 +#define VC_CAT_NETALT          26
13279 +#define VC_CAT_NETMIG          27
13280 +#define VC_CAT_NETCTRL         28
13281 +
13282 +#define VC_CAT_TAGMIG          35
13283 +#define VC_CAT_DLIMIT          36
13284 +#define VC_CAT_INODE           38
13285 +
13286 +#define VC_CAT_VSTAT           40
13287 +#define VC_CAT_VINFO           46
13288 +#define VC_CAT_EVENT           48
13289 +
13290 +#define VC_CAT_FLAGS           52
13291 +#define VC_CAT_VSPACE          54
13292 +#define VC_CAT_DEBUG           56
13293 +#define VC_CAT_RLIMIT          60
13294 +
13295 +#define VC_CAT_SYSTEST         61
13296 +#define VC_CAT_COMPAT          63
13297 +
13298 +/*  query version */
13299 +
13300 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13301 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13302 +
13303 +
13304 +#ifdef __KERNEL__
13305 +
13306 +#include <linux/errno.h>
13307 +
13308 +
13309 +#else  /* __KERNEL__ */
13310 +#define __user
13311 +#endif /* __KERNEL__ */
13312 +
13313 +#endif /* _VX_SWITCH_H */
13314 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/tag_cmd.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/tag_cmd.h
13315 --- linux-2.6.27.6/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
13316 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/tag_cmd.h   2008-10-13 14:54:20.000000000 +0200
13317 @@ -0,0 +1,22 @@
13318 +#ifndef _VX_TAG_CMD_H
13319 +#define _VX_TAG_CMD_H
13320 +
13321 +
13322 +/* vinfo commands */
13323 +
13324 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13325 +
13326 +#ifdef __KERNEL__
13327 +extern int vc_task_tag(uint32_t);
13328 +
13329 +#endif /* __KERNEL__ */
13330 +
13331 +/* context commands */
13332 +
13333 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13334 +
13335 +#ifdef __KERNEL__
13336 +extern int vc_tag_migrate(uint32_t);
13337 +
13338 +#endif /* __KERNEL__ */
13339 +#endif /* _VX_TAG_CMD_H */
13340 diff -NurpP --minimal linux-2.6.27.6/include/linux/vserver/tag.h linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/tag.h
13341 --- linux-2.6.27.6/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
13342 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vserver/tag.h       2008-10-24 03:34:52.000000000 +0200
13343 @@ -0,0 +1,143 @@
13344 +#ifndef _DX_TAG_H
13345 +#define _DX_TAG_H
13346 +
13347 +#include <linux/types.h>
13348 +
13349 +
13350 +#define DX_TAG(in)     (IS_TAGGED(in))
13351 +
13352 +
13353 +#ifdef CONFIG_TAG_NFSD
13354 +#define DX_TAG_NFSD    1
13355 +#else
13356 +#define DX_TAG_NFSD    0
13357 +#endif
13358 +
13359 +
13360 +#ifdef CONFIG_TAGGING_NONE
13361 +
13362 +#define MAX_UID                0xFFFFFFFF
13363 +#define MAX_GID                0xFFFFFFFF
13364 +
13365 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13366 +
13367 +#define TAGINO_UID(cond, uid, tag)     (uid)
13368 +#define TAGINO_GID(cond, gid, tag)     (gid)
13369 +
13370 +#endif
13371 +
13372 +
13373 +#ifdef CONFIG_TAGGING_GID16
13374 +
13375 +#define MAX_UID                0xFFFFFFFF
13376 +#define MAX_GID                0x0000FFFF
13377 +
13378 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13379 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13380 +
13381 +#define TAGINO_UID(cond, uid, tag)     (uid)
13382 +#define TAGINO_GID(cond, gid, tag)     \
13383 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13384 +
13385 +#endif
13386 +
13387 +
13388 +#ifdef CONFIG_TAGGING_ID24
13389 +
13390 +#define MAX_UID                0x00FFFFFF
13391 +#define MAX_GID                0x00FFFFFF
13392 +
13393 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13394 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13395 +
13396 +#define TAGINO_UID(cond, uid, tag)     \
13397 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13398 +#define TAGINO_GID(cond, gid, tag)     \
13399 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13400 +
13401 +#endif
13402 +
13403 +
13404 +#ifdef CONFIG_TAGGING_UID16
13405 +
13406 +#define MAX_UID                0x0000FFFF
13407 +#define MAX_GID                0xFFFFFFFF
13408 +
13409 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13410 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13411 +
13412 +#define TAGINO_UID(cond, uid, tag)     \
13413 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13414 +#define TAGINO_GID(cond, gid, tag)     (gid)
13415 +
13416 +#endif
13417 +
13418 +
13419 +#ifdef CONFIG_TAGGING_INTERN
13420 +
13421 +#define MAX_UID                0xFFFFFFFF
13422 +#define MAX_GID                0xFFFFFFFF
13423 +
13424 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13425 +       ((cond) ? (tag) : 0)
13426 +
13427 +#define TAGINO_UID(cond, uid, tag)     (uid)
13428 +#define TAGINO_GID(cond, gid, tag)     (gid)
13429 +
13430 +#endif
13431 +
13432 +
13433 +#ifndef CONFIG_TAGGING_NONE
13434 +#define dx_current_fstag(sb)   \
13435 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13436 +#else
13437 +#define dx_current_fstag(sb)   (0)
13438 +#endif
13439 +
13440 +#ifndef CONFIG_TAGGING_INTERN
13441 +#define TAGINO_TAG(cond, tag)  (0)
13442 +#else
13443 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13444 +#endif
13445 +
13446 +#define INOTAG_UID(cond, uid, gid)     \
13447 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13448 +#define INOTAG_GID(cond, uid, gid)     \
13449 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13450 +
13451 +
13452 +static inline uid_t dx_map_uid(uid_t uid)
13453 +{
13454 +       if ((uid > MAX_UID) && (uid != -1))
13455 +               uid = -2;
13456 +       return (uid & MAX_UID);
13457 +}
13458 +
13459 +static inline gid_t dx_map_gid(gid_t gid)
13460 +{
13461 +       if ((gid > MAX_GID) && (gid != -1))
13462 +               gid = -2;
13463 +       return (gid & MAX_GID);
13464 +}
13465 +
13466 +struct peer_tag {
13467 +       int32_t xid;
13468 +       int32_t nid;
13469 +};
13470 +
13471 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13472 +
13473 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13474 +                unsigned long *flags);
13475 +
13476 +#ifdef CONFIG_PROPAGATE
13477 +
13478 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13479 +
13480 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13481 +
13482 +#else
13483 +#define dx_propagate_tag(n, i) do { } while (0)
13484 +#endif
13485 +
13486 +#endif /* _DX_TAG_H */
13487 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_inet6.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_inet6.h
13488 --- linux-2.6.27.6/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
13489 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_inet6.h  2008-11-16 17:35:20.000000000 +0100
13490 @@ -0,0 +1,246 @@
13491 +#ifndef _VS_INET6_H
13492 +#define _VS_INET6_H
13493 +
13494 +#include "vserver/base.h"
13495 +#include "vserver/network.h"
13496 +#include "vserver/debug.h"
13497 +
13498 +#include <net/ipv6.h>
13499 +
13500 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
13501 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
13502 +
13503 +
13504 +#ifdef CONFIG_IPV6
13505 +
13506 +static inline
13507 +int v6_addr_match(struct nx_addr_v6 *nxa,
13508 +       const struct in6_addr *addr, uint16_t mask)
13509 +{
13510 +       int ret = 0;
13511 +
13512 +       switch (nxa->type & mask) {
13513 +       case NXA_TYPE_MASK:
13514 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13515 +               break;
13516 +       case NXA_TYPE_ADDR:
13517 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13518 +               break;
13519 +       case NXA_TYPE_ANY:
13520 +               ret = 1;
13521 +               break;
13522 +       }
13523 +       vxdprintk(VXD_CBIT(net, 0),
13524 +               "v6_addr_match(%p" NXAV6_FMT ", " NIP6_FMT ", %04x) = %d",
13525 +               nxa, NXAV6(nxa), NIP6(*addr), mask, ret);
13526 +       return ret;
13527 +}
13528 +
13529 +static inline
13530 +int v6_addr_in_nx_info(struct nx_info *nxi,
13531 +       const struct in6_addr *addr, uint16_t mask)
13532 +{
13533 +       struct nx_addr_v6 *nxa;
13534 +       int ret = 1;
13535 +
13536 +       if (!nxi)
13537 +               goto out;
13538 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13539 +               if (v6_addr_match(nxa, addr, mask))
13540 +                       goto out;
13541 +       ret = 0;
13542 +out:
13543 +       vxdprintk(VXD_CBIT(net, 0),
13544 +               "v6_addr_in_nx_info(%p[#%u]," NIP6_FMT ",%04x) = %d",
13545 +               nxi, nxi ? nxi->nx_id : 0, NIP6(*addr), mask, ret);
13546 +       return ret;
13547 +}
13548 +
13549 +static inline
13550 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13551 +{
13552 +       /* FIXME: needs full range checks */
13553 +       return v6_addr_match(nxa, &addr->ip, mask);
13554 +}
13555 +
13556 +static inline
13557 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13558 +{
13559 +       struct nx_addr_v6 *ptr;
13560 +
13561 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13562 +               if (v6_nx_addr_match(ptr, nxa, mask))
13563 +                       return 1;
13564 +       return 0;
13565 +}
13566 +
13567 +
13568 +/*
13569 + *     Check if a given address matches for a socket
13570 + *
13571 + *     nxi:            the socket's nx_info if any
13572 + *     addr:           to be verified address
13573 + */
13574 +static inline
13575 +int v6_sock_addr_match (
13576 +       struct nx_info *nxi,
13577 +       struct inet_sock *inet,
13578 +       struct in6_addr *addr)
13579 +{
13580 +       struct sock *sk = &inet->sk;
13581 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13582 +
13583 +       if (!ipv6_addr_any(addr) &&
13584 +               ipv6_addr_equal(saddr, addr))
13585 +               return 1;
13586 +       if (ipv6_addr_any(saddr))
13587 +               return v6_addr_in_nx_info(nxi, addr, -1);
13588 +       return 0;
13589 +}
13590 +
13591 +/*
13592 + *     check if address is covered by socket
13593 + *
13594 + *     sk:     the socket to check against
13595 + *     addr:   the address in question (must be != 0)
13596 + */
13597 +
13598 +static inline
13599 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13600 +{
13601 +       struct nx_info *nxi = sk->sk_nx_info;
13602 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13603 +
13604 +       vxdprintk(VXD_CBIT(net, 5),
13605 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
13606 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
13607 +               (sk->sk_socket?sk->sk_socket->flags:0));
13608 +
13609 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13610 +               return v6_addr_match(nxa, saddr, -1);
13611 +       } else if (nxi) {               /* match against nx_info */
13612 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13613 +       } else {                        /* unrestricted any socket */
13614 +               return 1;
13615 +       }
13616 +}
13617 +
13618 +
13619 +/* inet related checks and helpers */
13620 +
13621 +
13622 +struct in_ifaddr;
13623 +struct net_device;
13624 +struct sock;
13625 +
13626 +
13627 +#include <linux/netdevice.h>
13628 +#include <linux/inetdevice.h>
13629 +#include <net/inet_timewait_sock.h>
13630 +
13631 +
13632 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13633 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13634 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13635 +
13636 +
13637 +
13638 +static inline
13639 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13640 +{
13641 +       if (!nxi)
13642 +               return 1;
13643 +       if (!ifa)
13644 +               return 0;
13645 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13646 +}
13647 +
13648 +static inline
13649 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13650 +{
13651 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13652 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13653 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13654 +
13655 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13656 +               return 1;
13657 +       if (v6_ifa_in_nx_info(ifa, nxi))
13658 +               return 1;
13659 +       return 0;
13660 +}
13661 +
13662 +
13663 +struct nx_v6_sock_addr {
13664 +       struct in6_addr saddr;  /* Address used for validation */
13665 +       struct in6_addr baddr;  /* Address used for socket bind */
13666 +};
13667 +
13668 +static inline
13669 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13670 +       struct nx_v6_sock_addr *nsa)
13671 +{
13672 +       // struct sock *sk = &inet->sk;
13673 +       // struct nx_info *nxi = sk->sk_nx_info;
13674 +       struct in6_addr saddr = addr->sin6_addr;
13675 +       struct in6_addr baddr = saddr;
13676 +
13677 +       nsa->saddr = saddr;
13678 +       nsa->baddr = baddr;
13679 +       return 0;
13680 +}
13681 +
13682 +static inline
13683 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13684 +{
13685 +       // struct sock *sk = &inet->sk;
13686 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13687 +
13688 +       // *saddr = nsa->baddr;
13689 +       // inet->saddr = nsa->baddr;
13690 +}
13691 +
13692 +static inline
13693 +int nx_info_has_v6(struct nx_info *nxi)
13694 +{
13695 +       if (!nxi)
13696 +               return 1;
13697 +       if (NX_IPV6(nxi))
13698 +               return 1;
13699 +       return 0;
13700 +}
13701 +
13702 +#else /* CONFIG_IPV6 */
13703 +
13704 +static inline
13705 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13706 +{
13707 +       return 1;
13708 +}
13709 +
13710 +
13711 +static inline
13712 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13713 +{
13714 +       return 1;
13715 +}
13716 +
13717 +static inline
13718 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13719 +{
13720 +       return 1;
13721 +}
13722 +
13723 +static inline
13724 +int nx_info_has_v6(struct nx_info *nxi)
13725 +{
13726 +       return 0;
13727 +}
13728 +
13729 +#endif /* CONFIG_IPV6 */
13730 +
13731 +#define current_nx_info_has_v6() \
13732 +       nx_info_has_v6(current_nx_info())
13733 +
13734 +#else
13735 +#warning duplicate inclusion
13736 +#endif
13737 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_inet.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_inet.h
13738 --- linux-2.6.27.6/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13739 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_inet.h   2008-10-13 14:54:20.000000000 +0200
13740 @@ -0,0 +1,342 @@
13741 +#ifndef _VS_INET_H
13742 +#define _VS_INET_H
13743 +
13744 +#include "vserver/base.h"
13745 +#include "vserver/network.h"
13746 +#include "vserver/debug.h"
13747 +
13748 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13749 +
13750 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13751 +                       NIPQUAD((a)->mask), (a)->type
13752 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13753 +
13754 +
13755 +static inline
13756 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13757 +{
13758 +       __be32 ip = nxa->ip[0].s_addr;
13759 +       __be32 mask = nxa->mask.s_addr;
13760 +       __be32 bcast = ip | ~mask;
13761 +       int ret = 0;
13762 +
13763 +       switch (nxa->type & tmask) {
13764 +       case NXA_TYPE_MASK:
13765 +               ret = (ip == (addr & mask));
13766 +               break;
13767 +       case NXA_TYPE_ADDR:
13768 +               ret = 3;
13769 +               if (addr == ip)
13770 +                       break;
13771 +               /* fall through to broadcast */
13772 +       case NXA_MOD_BCAST:
13773 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13774 +               break;
13775 +       case NXA_TYPE_RANGE:
13776 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13777 +                       (nxa->ip[1].s_addr > addr));
13778 +               break;
13779 +       case NXA_TYPE_ANY:
13780 +               ret = 2;
13781 +               break;
13782 +       }
13783 +
13784 +       vxdprintk(VXD_CBIT(net, 0),
13785 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13786 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13787 +       return ret;
13788 +}
13789 +
13790 +static inline
13791 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13792 +{
13793 +       struct nx_addr_v4 *nxa;
13794 +       int ret = 1;
13795 +
13796 +       if (!nxi)
13797 +               goto out;
13798 +
13799 +       ret = 2;
13800 +       /* allow 127.0.0.1 when remapping lback */
13801 +       if ((tmask & NXA_LOOPBACK) &&
13802 +               (addr == IPI_LOOPBACK) &&
13803 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13804 +               goto out;
13805 +       ret = 3;
13806 +       /* check for lback address */
13807 +       if ((tmask & NXA_MOD_LBACK) &&
13808 +               (nxi->v4_lback.s_addr == addr))
13809 +               goto out;
13810 +       ret = 4;
13811 +       /* check for broadcast address */
13812 +       if ((tmask & NXA_MOD_BCAST) &&
13813 +               (nxi->v4_bcast.s_addr == addr))
13814 +               goto out;
13815 +       ret = 5;
13816 +       /* check for v4 addresses */
13817 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13818 +               if (v4_addr_match(nxa, addr, tmask))
13819 +                       goto out;
13820 +       ret = 0;
13821 +out:
13822 +       vxdprintk(VXD_CBIT(net, 0),
13823 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13824 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13825 +       return ret;
13826 +}
13827 +
13828 +static inline
13829 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13830 +{
13831 +       /* FIXME: needs full range checks */
13832 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13833 +}
13834 +
13835 +static inline
13836 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13837 +{
13838 +       struct nx_addr_v4 *ptr;
13839 +
13840 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13841 +               if (v4_nx_addr_match(ptr, nxa, mask))
13842 +                       return 1;
13843 +       return 0;
13844 +}
13845 +
13846 +#include <net/inet_sock.h>
13847 +
13848 +/*
13849 + *     Check if a given address matches for a socket
13850 + *
13851 + *     nxi:            the socket's nx_info if any
13852 + *     addr:           to be verified address
13853 + */
13854 +static inline
13855 +int v4_sock_addr_match (
13856 +       struct nx_info *nxi,
13857 +       struct inet_sock *inet,
13858 +       __be32 addr)
13859 +{
13860 +       __be32 saddr = inet->rcv_saddr;
13861 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13862 +
13863 +       if (addr && (saddr == addr || bcast == addr))
13864 +               return 1;
13865 +       if (!saddr)
13866 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13867 +       return 0;
13868 +}
13869 +
13870 +
13871 +/* inet related checks and helpers */
13872 +
13873 +
13874 +struct in_ifaddr;
13875 +struct net_device;
13876 +struct sock;
13877 +
13878 +#ifdef CONFIG_INET
13879 +
13880 +#include <linux/netdevice.h>
13881 +#include <linux/inetdevice.h>
13882 +#include <net/inet_sock.h>
13883 +#include <net/inet_timewait_sock.h>
13884 +
13885 +
13886 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13887 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13888 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13889 +
13890 +
13891 +/*
13892 + *     check if address is covered by socket
13893 + *
13894 + *     sk:     the socket to check against
13895 + *     addr:   the address in question (must be != 0)
13896 + */
13897 +
13898 +static inline
13899 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13900 +{
13901 +       struct nx_info *nxi = sk->sk_nx_info;
13902 +       __be32 saddr = inet_rcv_saddr(sk);
13903 +
13904 +       vxdprintk(VXD_CBIT(net, 5),
13905 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13906 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13907 +               (sk->sk_socket?sk->sk_socket->flags:0));
13908 +
13909 +       if (saddr) {            /* direct address match */
13910 +               return v4_addr_match(nxa, saddr, -1);
13911 +       } else if (nxi) {       /* match against nx_info */
13912 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13913 +       } else {                /* unrestricted any socket */
13914 +               return 1;
13915 +       }
13916 +}
13917 +
13918 +
13919 +
13920 +static inline
13921 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13922 +{
13923 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13924 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13925 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13926 +
13927 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13928 +               return 1;
13929 +       if (dev_in_nx_info(dev, nxi))
13930 +               return 1;
13931 +       return 0;
13932 +}
13933 +
13934 +
13935 +static inline
13936 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13937 +{
13938 +       if (!nxi)
13939 +               return 1;
13940 +       if (!ifa)
13941 +               return 0;
13942 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13943 +}
13944 +
13945 +static inline
13946 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13947 +{
13948 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13949 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13950 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13951 +
13952 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13953 +               return 1;
13954 +       if (v4_ifa_in_nx_info(ifa, nxi))
13955 +               return 1;
13956 +       return 0;
13957 +}
13958 +
13959 +
13960 +struct nx_v4_sock_addr {
13961 +       __be32 saddr;   /* Address used for validation */
13962 +       __be32 baddr;   /* Address used for socket bind */
13963 +};
13964 +
13965 +static inline
13966 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13967 +       struct nx_v4_sock_addr *nsa)
13968 +{
13969 +       struct sock *sk = &inet->sk;
13970 +       struct nx_info *nxi = sk->sk_nx_info;
13971 +       __be32 saddr = addr->sin_addr.s_addr;
13972 +       __be32 baddr = saddr;
13973 +
13974 +       vxdprintk(VXD_CBIT(net, 3),
13975 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13976 +               sk, sk->sk_nx_info, sk->sk_socket,
13977 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13978 +               NIPQUAD(saddr));
13979 +
13980 +       if (nxi) {
13981 +               if (saddr == INADDR_ANY) {
13982 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13983 +                               baddr = nxi->v4.ip[0].s_addr;
13984 +               } else if (saddr == IPI_LOOPBACK) {
13985 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13986 +                               baddr = nxi->v4_lback.s_addr;
13987 +               } else {        /* normal address bind */
13988 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13989 +                               return -EADDRNOTAVAIL;
13990 +               }
13991 +       }
13992 +
13993 +       vxdprintk(VXD_CBIT(net, 3),
13994 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13995 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13996 +
13997 +       nsa->saddr = saddr;
13998 +       nsa->baddr = baddr;
13999 +       return 0;
14000 +}
14001 +
14002 +static inline
14003 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
14004 +{
14005 +       inet->saddr = nsa->baddr;
14006 +       inet->rcv_saddr = nsa->baddr;
14007 +}
14008 +
14009 +
14010 +/*
14011 + *      helper to simplify inet_lookup_listener
14012 + *
14013 + *      nxi:   the socket's nx_info if any
14014 + *      addr:  to be verified address
14015 + *      saddr: socket address
14016 + */
14017 +static inline int v4_inet_addr_match (
14018 +       struct nx_info *nxi,
14019 +       __be32 addr,
14020 +       __be32 saddr)
14021 +{
14022 +       if (addr && (saddr == addr))
14023 +               return 1;
14024 +       if (!saddr)
14025 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
14026 +       return 0;
14027 +}
14028 +
14029 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
14030 +{
14031 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
14032 +               (addr == nxi->v4_lback.s_addr))
14033 +               return IPI_LOOPBACK;
14034 +       return addr;
14035 +}
14036 +
14037 +static inline
14038 +int nx_info_has_v4(struct nx_info *nxi)
14039 +{
14040 +       if (!nxi)
14041 +               return 1;
14042 +       if (NX_IPV4(nxi))
14043 +               return 1;
14044 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14045 +               return 1;
14046 +       return 0;
14047 +}
14048 +
14049 +#else /* CONFIG_INET */
14050 +
14051 +static inline
14052 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
14053 +{
14054 +       return 1;
14055 +}
14056 +
14057 +static inline
14058 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14059 +{
14060 +       return 1;
14061 +}
14062 +
14063 +static inline
14064 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14065 +{
14066 +       return 1;
14067 +}
14068 +
14069 +static inline
14070 +int nx_info_has_v4(struct nx_info *nxi)
14071 +{
14072 +       return 0;
14073 +}
14074 +
14075 +#endif /* CONFIG_INET */
14076 +
14077 +#define current_nx_info_has_v4() \
14078 +       nx_info_has_v4(current_nx_info())
14079 +
14080 +#else
14081 +// #warning duplicate inclusion
14082 +#endif
14083 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_limit.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_limit.h
14084 --- linux-2.6.27.6/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
14085 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_limit.h  2008-10-13 14:54:20.000000000 +0200
14086 @@ -0,0 +1,140 @@
14087 +#ifndef _VS_LIMIT_H
14088 +#define _VS_LIMIT_H
14089 +
14090 +#include "vserver/limit.h"
14091 +#include "vserver/base.h"
14092 +#include "vserver/context.h"
14093 +#include "vserver/debug.h"
14094 +#include "vserver/context.h"
14095 +#include "vserver/limit_int.h"
14096 +
14097 +
14098 +#define vx_acc_cres(v, d, p, r) \
14099 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14100 +
14101 +#define vx_acc_cres_cond(x, d, p, r) \
14102 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14103 +       r, d, p, __FILE__, __LINE__)
14104 +
14105 +
14106 +#define vx_add_cres(v, a, p, r) \
14107 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
14108 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
14109 +
14110 +#define vx_add_cres_cond(x, a, p, r) \
14111 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14112 +       r, a, p, __FILE__, __LINE__)
14113 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
14114 +
14115 +
14116 +/* process and file limits */
14117 +
14118 +#define vx_nproc_inc(p) \
14119 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
14120 +
14121 +#define vx_nproc_dec(p) \
14122 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
14123 +
14124 +#define vx_files_inc(f) \
14125 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
14126 +
14127 +#define vx_files_dec(f) \
14128 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
14129 +
14130 +#define vx_locks_inc(l) \
14131 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
14132 +
14133 +#define vx_locks_dec(l) \
14134 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
14135 +
14136 +#define vx_openfd_inc(f) \
14137 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
14138 +
14139 +#define vx_openfd_dec(f) \
14140 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
14141 +
14142 +
14143 +#define vx_cres_avail(v, n, r) \
14144 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14145 +
14146 +
14147 +#define vx_nproc_avail(n) \
14148 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
14149 +
14150 +#define vx_files_avail(n) \
14151 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
14152 +
14153 +#define vx_locks_avail(n) \
14154 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
14155 +
14156 +#define vx_openfd_avail(n) \
14157 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
14158 +
14159 +
14160 +/* dentry limits */
14161 +
14162 +#define vx_dentry_inc(d) do {                                          \
14163 +       if (atomic_read(&d->d_count) == 1)                              \
14164 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
14165 +       } while (0)
14166 +
14167 +#define vx_dentry_dec(d) do {                                          \
14168 +       if (atomic_read(&d->d_count) == 0)                              \
14169 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
14170 +       } while (0)
14171 +
14172 +#define vx_dentry_avail(n) \
14173 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
14174 +
14175 +
14176 +/* socket limits */
14177 +
14178 +#define vx_sock_inc(s) \
14179 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14180 +
14181 +#define vx_sock_dec(s) \
14182 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14183 +
14184 +#define vx_sock_avail(n) \
14185 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
14186 +
14187 +
14188 +/* ipc resource limits */
14189 +
14190 +#define vx_ipcmsg_add(v, u, a) \
14191 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14192 +
14193 +#define vx_ipcmsg_sub(v, u, a) \
14194 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14195 +
14196 +#define vx_ipcmsg_avail(v, a) \
14197 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14198 +
14199 +
14200 +#define vx_ipcshm_add(v, k, a) \
14201 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14202 +
14203 +#define vx_ipcshm_sub(v, k, a) \
14204 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14205 +
14206 +#define vx_ipcshm_avail(v, a) \
14207 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14208 +
14209 +
14210 +#define vx_semary_inc(a) \
14211 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
14212 +
14213 +#define vx_semary_dec(a) \
14214 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
14215 +
14216 +
14217 +#define vx_nsems_add(a,n) \
14218 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14219 +
14220 +#define vx_nsems_sub(a,n) \
14221 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14222 +
14223 +
14224 +#else
14225 +#warning duplicate inclusion
14226 +#endif
14227 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_memory.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_memory.h
14228 --- linux-2.6.27.6/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
14229 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_memory.h 2008-10-13 14:54:20.000000000 +0200
14230 @@ -0,0 +1,159 @@
14231 +#ifndef _VS_MEMORY_H
14232 +#define _VS_MEMORY_H
14233 +
14234 +#include "vserver/limit.h"
14235 +#include "vserver/base.h"
14236 +#include "vserver/context.h"
14237 +#include "vserver/debug.h"
14238 +#include "vserver/context.h"
14239 +#include "vserver/limit_int.h"
14240 +
14241 +
14242 +#define __acc_add_long(a, v)   (*(v) += (a))
14243 +#define __acc_inc_long(v)      (++*(v))
14244 +#define __acc_dec_long(v)      (--*(v))
14245 +
14246 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14247 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14248 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14249 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14250 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14251 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14252 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14253 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14254 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14255 +
14256 +
14257 +#define vx_acc_page(m, d, v, r) do {                                   \
14258 +       if ((d) > 0)                                                    \
14259 +               __acc_inc_long(&(m)->v);                                \
14260 +       else                                                            \
14261 +               __acc_dec_long(&(m)->v);                                \
14262 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14263 +} while (0)
14264 +
14265 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14266 +       if ((d) > 0)                                                    \
14267 +               __acc_inc_atomic(&(m)->v);                              \
14268 +       else                                                            \
14269 +               __acc_dec_atomic(&(m)->v);                              \
14270 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14271 +} while (0)
14272 +
14273 +
14274 +#define vx_acc_pages(m, p, v, r) do {                                  \
14275 +       unsigned long __p = (p);                                        \
14276 +       __acc_add_long(__p, &(m)->v);                                   \
14277 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14278 +} while (0)
14279 +
14280 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14281 +       unsigned long __p = (p);                                        \
14282 +       __acc_add_atomic(__p, &(m)->v);                                 \
14283 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14284 +} while (0)
14285 +
14286 +
14287 +
14288 +#define vx_acc_vmpage(m, d) \
14289 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14290 +#define vx_acc_vmlpage(m, d) \
14291 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14292 +#define vx_acc_file_rsspage(m, d) \
14293 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14294 +#define vx_acc_anon_rsspage(m, d) \
14295 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14296 +
14297 +#define vx_acc_vmpages(m, p) \
14298 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14299 +#define vx_acc_vmlpages(m, p) \
14300 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14301 +#define vx_acc_file_rsspages(m, p) \
14302 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14303 +#define vx_acc_anon_rsspages(m, p) \
14304 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14305 +
14306 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14307 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14308 +
14309 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14310 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14311 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14312 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14313 +
14314 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14315 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14316 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14317 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14318 +
14319 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14320 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14321 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14322 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14323 +
14324 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14325 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14326 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14327 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14328 +
14329 +
14330 +#define vx_pages_avail(m, p, r) \
14331 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14332 +
14333 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14334 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14335 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14336 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14337 +
14338 +#define vx_rss_avail(m, p) \
14339 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14340 +
14341 +
14342 +enum {
14343 +       VXPT_UNKNOWN = 0,
14344 +       VXPT_ANON,
14345 +       VXPT_NONE,
14346 +       VXPT_FILE,
14347 +       VXPT_SWAP,
14348 +       VXPT_WRITE
14349 +};
14350 +
14351 +#if 0
14352 +#define        vx_page_fault(mm, vma, type, ret)
14353 +#else
14354 +
14355 +static inline
14356 +void __vx_page_fault(struct mm_struct *mm,
14357 +       struct vm_area_struct *vma, int type, int ret)
14358 +{
14359 +       struct vx_info *vxi = mm->mm_vx_info;
14360 +       int what;
14361 +/*
14362 +       static char *page_type[6] =
14363 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14364 +       static char *page_what[4] =
14365 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14366 +*/
14367 +
14368 +       if (!vxi)
14369 +               return;
14370 +
14371 +       what = (ret & 0x3);
14372 +
14373 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14374 +               type, what, ret, page_type[type], page_what[what]);
14375 +*/
14376 +       if (ret & VM_FAULT_WRITE)
14377 +               what |= 0x4;
14378 +       atomic_inc(&vxi->cacct.page[type][what]);
14379 +}
14380 +
14381 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14382 +#endif
14383 +
14384 +
14385 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14386 +
14387 +#else
14388 +#warning duplicate inclusion
14389 +#endif
14390 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_network.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_network.h
14391 --- linux-2.6.27.6/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
14392 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_network.h        2008-10-13 14:54:20.000000000 +0200
14393 @@ -0,0 +1,169 @@
14394 +#ifndef _NX_VS_NETWORK_H
14395 +#define _NX_VS_NETWORK_H
14396 +
14397 +#include "vserver/context.h"
14398 +#include "vserver/network.h"
14399 +#include "vserver/base.h"
14400 +#include "vserver/check.h"
14401 +#include "vserver/debug.h"
14402 +
14403 +#include <linux/sched.h>
14404 +
14405 +
14406 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14407 +
14408 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14409 +       const char *_file, int _line)
14410 +{
14411 +       if (!nxi)
14412 +               return NULL;
14413 +
14414 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14415 +               nxi, nxi ? nxi->nx_id : 0,
14416 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14417 +               _file, _line);
14418 +
14419 +       atomic_inc(&nxi->nx_usecnt);
14420 +       return nxi;
14421 +}
14422 +
14423 +
14424 +extern void free_nx_info(struct nx_info *);
14425 +
14426 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14427 +
14428 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14429 +{
14430 +       if (!nxi)
14431 +               return;
14432 +
14433 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14434 +               nxi, nxi ? nxi->nx_id : 0,
14435 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14436 +               _file, _line);
14437 +
14438 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14439 +               free_nx_info(nxi);
14440 +}
14441 +
14442 +
14443 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14444 +
14445 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14446 +               const char *_file, int _line)
14447 +{
14448 +       if (nxi) {
14449 +               vxlprintk(VXD_CBIT(nid, 3),
14450 +                       "init_nx_info(%p[#%d.%d])",
14451 +                       nxi, nxi ? nxi->nx_id : 0,
14452 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14453 +                       _file, _line);
14454 +
14455 +               atomic_inc(&nxi->nx_usecnt);
14456 +       }
14457 +       *nxp = nxi;
14458 +}
14459 +
14460 +
14461 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14462 +
14463 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14464 +       const char *_file, int _line)
14465 +{
14466 +       struct nx_info *nxo;
14467 +
14468 +       if (!nxi)
14469 +               return;
14470 +
14471 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14472 +               nxi, nxi ? nxi->nx_id : 0,
14473 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14474 +               _file, _line);
14475 +
14476 +       atomic_inc(&nxi->nx_usecnt);
14477 +       nxo = xchg(nxp, nxi);
14478 +       BUG_ON(nxo);
14479 +}
14480 +
14481 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14482 +
14483 +static inline void __clr_nx_info(struct nx_info **nxp,
14484 +       const char *_file, int _line)
14485 +{
14486 +       struct nx_info *nxo;
14487 +
14488 +       nxo = xchg(nxp, NULL);
14489 +       if (!nxo)
14490 +               return;
14491 +
14492 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14493 +               nxo, nxo ? nxo->nx_id : 0,
14494 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14495 +               _file, _line);
14496 +
14497 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14498 +               free_nx_info(nxo);
14499 +}
14500 +
14501 +
14502 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14503 +
14504 +static inline void __claim_nx_info(struct nx_info *nxi,
14505 +       struct task_struct *task, const char *_file, int _line)
14506 +{
14507 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14508 +               nxi, nxi ? nxi->nx_id : 0,
14509 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14510 +               nxi?atomic_read(&nxi->nx_tasks):0,
14511 +               task, _file, _line);
14512 +
14513 +       atomic_inc(&nxi->nx_tasks);
14514 +}
14515 +
14516 +
14517 +extern void unhash_nx_info(struct nx_info *);
14518 +
14519 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14520 +
14521 +static inline void __release_nx_info(struct nx_info *nxi,
14522 +       struct task_struct *task, const char *_file, int _line)
14523 +{
14524 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14525 +               nxi, nxi ? nxi->nx_id : 0,
14526 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14527 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14528 +               task, _file, _line);
14529 +
14530 +       might_sleep();
14531 +
14532 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14533 +               unhash_nx_info(nxi);
14534 +}
14535 +
14536 +
14537 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14538 +
14539 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14540 +       const char *_file, int _line)
14541 +{
14542 +       struct nx_info *nxi;
14543 +
14544 +       task_lock(p);
14545 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14546 +               p, _file, _line);
14547 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14548 +       task_unlock(p);
14549 +       return nxi;
14550 +}
14551 +
14552 +
14553 +static inline void exit_nx_info(struct task_struct *p)
14554 +{
14555 +       if (p->nx_info)
14556 +               release_nx_info(p->nx_info, p);
14557 +}
14558 +
14559 +
14560 +#else
14561 +#warning duplicate inclusion
14562 +#endif
14563 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_pid.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_pid.h
14564 --- linux-2.6.27.6/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
14565 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_pid.h    2008-10-13 14:54:20.000000000 +0200
14566 @@ -0,0 +1,95 @@
14567 +#ifndef _VS_PID_H
14568 +#define _VS_PID_H
14569 +
14570 +#include "vserver/base.h"
14571 +#include "vserver/check.h"
14572 +#include "vserver/context.h"
14573 +#include "vserver/debug.h"
14574 +#include "vserver/pid.h"
14575 +#include <linux/pid_namespace.h>
14576 +
14577 +
14578 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14579 +
14580 +static inline
14581 +int vx_proc_task_visible(struct task_struct *task)
14582 +{
14583 +       if ((task->pid == 1) &&
14584 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14585 +               /* show a blend through init */
14586 +               goto visible;
14587 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14588 +               goto visible;
14589 +       return 0;
14590 +visible:
14591 +       return 1;
14592 +}
14593 +
14594 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14595 +
14596 +#if 0
14597 +
14598 +static inline
14599 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14600 +{
14601 +       struct task_struct *task = find_task_by_real_pid(pid);
14602 +
14603 +       if (task && !vx_proc_task_visible(task)) {
14604 +               vxdprintk(VXD_CBIT(misc, 6),
14605 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14606 +                       task, task->xid, task->pid,
14607 +                       current, current->xid, current->pid);
14608 +               task = NULL;
14609 +       }
14610 +       return task;
14611 +}
14612 +
14613 +#endif
14614 +
14615 +static inline
14616 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14617 +{
14618 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14619 +
14620 +       if (task && !vx_proc_task_visible(task)) {
14621 +               vxdprintk(VXD_CBIT(misc, 6),
14622 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14623 +                       task, task->xid, task->pid,
14624 +                       current, current->xid, current->pid);
14625 +               put_task_struct(task);
14626 +               task = NULL;
14627 +       }
14628 +       return task;
14629 +}
14630 +
14631 +#if 0
14632 +
14633 +static inline
14634 +struct task_struct *vx_child_reaper(struct task_struct *p)
14635 +{
14636 +       struct vx_info *vxi = p->vx_info;
14637 +       struct task_struct *reaper = child_reaper(p);
14638 +
14639 +       if (!vxi)
14640 +               goto out;
14641 +
14642 +       BUG_ON(!p->vx_info->vx_reaper);
14643 +
14644 +       /* child reaper for the guest reaper */
14645 +       if (vxi->vx_reaper == p)
14646 +               goto out;
14647 +
14648 +       reaper = vxi->vx_reaper;
14649 +out:
14650 +       vxdprintk(VXD_CBIT(xid, 7),
14651 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14652 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14653 +       return reaper;
14654 +}
14655 +
14656 +#endif
14657 +
14658 +
14659 +#else
14660 +#warning duplicate inclusion
14661 +#endif
14662 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_sched.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_sched.h
14663 --- linux-2.6.27.6/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
14664 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_sched.h  2008-10-13 14:54:20.000000000 +0200
14665 @@ -0,0 +1,110 @@
14666 +#ifndef _VS_SCHED_H
14667 +#define _VS_SCHED_H
14668 +
14669 +#include "vserver/base.h"
14670 +#include "vserver/context.h"
14671 +#include "vserver/sched.h"
14672 +
14673 +
14674 +#define VAVAVOOM_RATIO          50
14675 +
14676 +#define MAX_PRIO_BIAS           20
14677 +#define MIN_PRIO_BIAS          -20
14678 +
14679 +
14680 +#ifdef CONFIG_VSERVER_HARDCPU
14681 +
14682 +/*
14683 + * effective_prio - return the priority that is based on the static
14684 + * priority but is modified by bonuses/penalties.
14685 + *
14686 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14687 + * into a -4 ... 0 ... +4 bonus/penalty range.
14688 + *
14689 + * Additionally, we scale another amount based on the number of
14690 + * CPU tokens currently held by the context, if the process is
14691 + * part of a context (and the appropriate SCHED flag is set).
14692 + * This ranges from -5 ... 0 ... +15, quadratically.
14693 + *
14694 + * So, the total bonus is -9 .. 0 .. +19
14695 + * We use ~50% of the full 0...39 priority range so that:
14696 + *
14697 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14698 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14699 + *    unless that context is far exceeding its CPU allocation.
14700 + *
14701 + * Both properties are important to certain workloads.
14702 + */
14703 +static inline
14704 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14705 +{
14706 +       int vavavoom, max;
14707 +
14708 +       /* lots of tokens = lots of vavavoom
14709 +        *      no tokens = no vavavoom      */
14710 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14711 +               max = sched_pc->tokens_max;
14712 +               vavavoom = max - vavavoom;
14713 +               max = max * max;
14714 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14715 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14716 +               return vavavoom;
14717 +       }
14718 +       return 0;
14719 +}
14720 +
14721 +
14722 +static inline
14723 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14724 +{
14725 +       struct vx_info *vxi = p->vx_info;
14726 +       struct _vx_sched_pc *sched_pc;
14727 +
14728 +       if (!vxi)
14729 +               return prio;
14730 +
14731 +       sched_pc = &vx_cpu(vxi, sched_pc);
14732 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14733 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14734 +
14735 +               sched_pc->vavavoom = vavavoom;
14736 +               prio += vavavoom;
14737 +       }
14738 +       prio += sched_pc->prio_bias;
14739 +       return prio;
14740 +}
14741 +
14742 +#else /* !CONFIG_VSERVER_HARDCPU */
14743 +
14744 +static inline
14745 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14746 +{
14747 +       struct vx_info *vxi = p->vx_info;
14748 +
14749 +       if (vxi)
14750 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14751 +       return prio;
14752 +}
14753 +
14754 +#endif /* CONFIG_VSERVER_HARDCPU */
14755 +
14756 +
14757 +static inline void vx_account_user(struct vx_info *vxi,
14758 +       cputime_t cputime, int nice)
14759 +{
14760 +       if (!vxi)
14761 +               return;
14762 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14763 +}
14764 +
14765 +static inline void vx_account_system(struct vx_info *vxi,
14766 +       cputime_t cputime, int idle)
14767 +{
14768 +       if (!vxi)
14769 +               return;
14770 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14771 +}
14772 +
14773 +#else
14774 +#warning duplicate inclusion
14775 +#endif
14776 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_socket.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_socket.h
14777 --- linux-2.6.27.6/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14778 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_socket.h 2008-10-13 14:54:20.000000000 +0200
14779 @@ -0,0 +1,67 @@
14780 +#ifndef _VS_SOCKET_H
14781 +#define _VS_SOCKET_H
14782 +
14783 +#include "vserver/debug.h"
14784 +#include "vserver/base.h"
14785 +#include "vserver/cacct.h"
14786 +#include "vserver/context.h"
14787 +#include "vserver/tag.h"
14788 +
14789 +
14790 +/* socket accounting */
14791 +
14792 +#include <linux/socket.h>
14793 +
14794 +static inline int vx_sock_type(int family)
14795 +{
14796 +       switch (family) {
14797 +       case PF_UNSPEC:
14798 +               return VXA_SOCK_UNSPEC;
14799 +       case PF_UNIX:
14800 +               return VXA_SOCK_UNIX;
14801 +       case PF_INET:
14802 +               return VXA_SOCK_INET;
14803 +       case PF_INET6:
14804 +               return VXA_SOCK_INET6;
14805 +       case PF_PACKET:
14806 +               return VXA_SOCK_PACKET;
14807 +       default:
14808 +               return VXA_SOCK_OTHER;
14809 +       }
14810 +}
14811 +
14812 +#define vx_acc_sock(v, f, p, s) \
14813 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14814 +
14815 +static inline void __vx_acc_sock(struct vx_info *vxi,
14816 +       int family, int pos, int size, char *file, int line)
14817 +{
14818 +       if (vxi) {
14819 +               int type = vx_sock_type(family);
14820 +
14821 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14822 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14823 +       }
14824 +}
14825 +
14826 +#define vx_sock_recv(sk, s) \
14827 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14828 +#define vx_sock_send(sk, s) \
14829 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14830 +#define vx_sock_fail(sk, s) \
14831 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14832 +
14833 +
14834 +#define sock_vx_init(s) do {           \
14835 +       (s)->sk_xid = 0;                \
14836 +       (s)->sk_vx_info = NULL;         \
14837 +       } while (0)
14838 +
14839 +#define sock_nx_init(s) do {           \
14840 +       (s)->sk_nid = 0;                \
14841 +       (s)->sk_nx_info = NULL;         \
14842 +       } while (0)
14843 +
14844 +#else
14845 +#warning duplicate inclusion
14846 +#endif
14847 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_tag.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_tag.h
14848 --- linux-2.6.27.6/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14849 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_tag.h    2008-10-24 03:34:52.000000000 +0200
14850 @@ -0,0 +1,47 @@
14851 +#ifndef _VS_TAG_H
14852 +#define _VS_TAG_H
14853 +
14854 +#include <linux/vserver/tag.h>
14855 +
14856 +/* check conditions */
14857 +
14858 +#define DX_ADMIN       0x0001
14859 +#define DX_WATCH       0x0002
14860 +#define DX_HOSTID      0x0008
14861 +
14862 +#define DX_IDENT       0x0010
14863 +
14864 +#define DX_ARG_MASK    0x0010
14865 +
14866 +
14867 +#define dx_task_tag(t) ((t)->tag)
14868 +
14869 +#define dx_current_tag() dx_task_tag(current)
14870 +
14871 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14872 +
14873 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14874 +
14875 +
14876 +/*
14877 + * check current context for ADMIN/WATCH and
14878 + * optionally against supplied argument
14879 + */
14880 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14881 +{
14882 +       if (mode & DX_ARG_MASK) {
14883 +               if ((mode & DX_IDENT) && (id == cid))
14884 +                       return 1;
14885 +       }
14886 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14887 +               ((mode & DX_WATCH) && (cid == 1)) ||
14888 +               ((mode & DX_HOSTID) && (id == 0)));
14889 +}
14890 +
14891 +struct inode;
14892 +int dx_permission(struct inode *inode, int mask);
14893 +
14894 +
14895 +#else
14896 +#warning duplicate inclusion
14897 +#endif
14898 diff -NurpP --minimal linux-2.6.27.6/include/linux/vs_time.h linux-2.6.27.6-vs2.3.0.36/include/linux/vs_time.h
14899 --- linux-2.6.27.6/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14900 +++ linux-2.6.27.6-vs2.3.0.36/include/linux/vs_time.h   2008-10-13 14:54:20.000000000 +0200
14901 @@ -0,0 +1,19 @@
14902 +#ifndef _VS_TIME_H
14903 +#define _VS_TIME_H
14904 +
14905 +
14906 +/* time faking stuff */
14907 +
14908 +#ifdef CONFIG_VSERVER_VTIME
14909 +
14910 +extern void vx_gettimeofday(struct timeval *tv);
14911 +extern int vx_settimeofday(struct timespec *ts);
14912 +
14913 +#else
14914 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14915 +#define        vx_settimeofday(t)      do_settimeofday(t)
14916 +#endif
14917 +
14918 +#else
14919 +#warning duplicate inclusion
14920 +#endif
14921 diff -NurpP --minimal linux-2.6.27.6/include/net/addrconf.h linux-2.6.27.6-vs2.3.0.36/include/net/addrconf.h
14922 --- linux-2.6.27.6/include/net/addrconf.h       2008-10-13 14:52:09.000000000 +0200
14923 +++ linux-2.6.27.6-vs2.3.0.36/include/net/addrconf.h    2008-10-13 14:54:20.000000000 +0200
14924 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14925                                                struct net_device *dev,
14926                                                const struct in6_addr *daddr,
14927                                                unsigned int srcprefs,
14928 -                                              struct in6_addr *saddr);
14929 +                                              struct in6_addr *saddr,
14930 +                                              struct nx_info *nxi);
14931  extern int                     ipv6_get_lladdr(struct net_device *dev,
14932                                                 struct in6_addr *addr,
14933                                                 unsigned char banned_flags);
14934 diff -NurpP --minimal linux-2.6.27.6/include/net/af_unix.h linux-2.6.27.6-vs2.3.0.36/include/net/af_unix.h
14935 --- linux-2.6.27.6/include/net/af_unix.h        2008-11-17 18:07:34.000000000 +0100
14936 +++ linux-2.6.27.6-vs2.3.0.36/include/net/af_unix.h     2008-11-17 18:20:41.000000000 +0100
14937 @@ -4,6 +4,7 @@
14938  #include <linux/socket.h>
14939  #include <linux/un.h>
14940  #include <linux/mutex.h>
14941 +#include <linux/vs_base.h>
14942  #include <net/sock.h>
14943  
14944  extern void unix_inflight(struct file *fp);
14945 diff -NurpP --minimal linux-2.6.27.6/include/net/inet_sock.h linux-2.6.27.6-vs2.3.0.36/include/net/inet_sock.h
14946 --- linux-2.6.27.6/include/net/inet_sock.h      2008-10-13 14:52:09.000000000 +0200
14947 +++ linux-2.6.27.6-vs2.3.0.36/include/net/inet_sock.h   2008-10-13 14:54:20.000000000 +0200
14948 @@ -24,7 +24,7 @@
14949  #include <net/flow.h>
14950  #include <net/sock.h>
14951  #include <net/request_sock.h>
14952 -#include <net/route.h>
14953 +// #include <net/route.h>
14954  #include <net/netns/hash.h>
14955  
14956  /** struct ip_options - IP Options
14957 @@ -195,11 +195,6 @@ static inline int inet_sk_ehashfn(const 
14958  }
14959  
14960  
14961 -static inline int inet_iif(const struct sk_buff *skb)
14962 -{
14963 -       return skb->rtable->rt_iif;
14964 -}
14965 -
14966  static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
14967  {
14968         struct request_sock *req = reqsk_alloc(ops);
14969 diff -NurpP --minimal linux-2.6.27.6/include/net/inet_timewait_sock.h linux-2.6.27.6-vs2.3.0.36/include/net/inet_timewait_sock.h
14970 --- linux-2.6.27.6/include/net/inet_timewait_sock.h     2008-10-13 14:52:09.000000000 +0200
14971 +++ linux-2.6.27.6-vs2.3.0.36/include/net/inet_timewait_sock.h  2008-10-13 14:54:20.000000000 +0200
14972 @@ -15,15 +15,14 @@
14973  #ifndef _INET_TIMEWAIT_SOCK_
14974  #define _INET_TIMEWAIT_SOCK_
14975  
14976 +// #include <net/inet_sock.h>
14977 +#include <net/sock.h>
14978  
14979  #include <linux/list.h>
14980  #include <linux/module.h>
14981  #include <linux/timer.h>
14982  #include <linux/types.h>
14983  #include <linux/workqueue.h>
14984 -
14985 -#include <net/inet_sock.h>
14986 -#include <net/sock.h>
14987  #include <net/tcp_states.h>
14988  #include <net/timewait_sock.h>
14989  
14990 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14991  #define tw_hash                        __tw_common.skc_hash
14992  #define tw_prot                        __tw_common.skc_prot
14993  #define tw_net                 __tw_common.skc_net
14994 +#define tw_xid                 __tw_common.skc_xid
14995 +#define tw_vx_info             __tw_common.skc_vx_info
14996 +#define tw_nid                 __tw_common.skc_nid
14997 +#define tw_nx_info             __tw_common.skc_nx_info
14998         int                     tw_timeout;
14999         volatile unsigned char  tw_substate;
15000         /* 3 bits hole, try to pack */
15001 diff -NurpP --minimal linux-2.6.27.6/include/net/route.h linux-2.6.27.6-vs2.3.0.36/include/net/route.h
15002 --- linux-2.6.27.6/include/net/route.h  2008-10-13 14:52:09.000000000 +0200
15003 +++ linux-2.6.27.6-vs2.3.0.36/include/net/route.h       2008-10-13 14:54:20.000000000 +0200
15004 @@ -28,6 +28,7 @@
15005  #include <net/inetpeer.h>
15006  #include <net/flow.h>
15007  #include <net/sock.h>
15008 +// #include <linux/in.h>
15009  #include <linux/in_route.h>
15010  #include <linux/rtnetlink.h>
15011  #include <linux/route.h>
15012 @@ -85,6 +86,11 @@ struct ip_rt_acct
15013         __u32   i_packets;
15014  };
15015  
15016 +static inline int inet_iif(const struct sk_buff *skb)
15017 +{
15018 +       return skb->rtable->rt_iif;
15019 +}
15020 +
15021  struct rt_cache_stat 
15022  {
15023          unsigned int in_hit;
15024 @@ -135,6 +141,9 @@ static inline void ip_rt_put(struct rtab
15025                 dst_release(&rt->u.dst);
15026  }
15027  
15028 +#include <linux/vs_base.h>
15029 +#include <linux/vs_inet.h>
15030 +
15031  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15032  
15033  extern const __u8 ip_tos2prio[16];
15034 @@ -144,6 +153,9 @@ static inline char rt_tos2priority(u8 to
15035         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15036  }
15037  
15038 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
15039 +       struct rtable **, struct flowi *);
15040 +
15041  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15042                                    __be32 src, u32 tos, int oif, u8 protocol,
15043                                    __be16 sport, __be16 dport, struct sock *sk,
15044 @@ -161,7 +173,21 @@ static inline int ip_route_connect(struc
15045  
15046         int err;
15047         struct net *net = sock_net(sk);
15048 -       if (!dst || !src) {
15049 +       struct nx_info *nx_info = current->nx_info;
15050 +
15051 +       if (sk)
15052 +               nx_info = sk->sk_nx_info;
15053 +
15054 +       vxdprintk(VXD_CBIT(net, 4),
15055 +               "ip_route_connect(%p) %p,%p;%lx",
15056 +               sk, nx_info, sk->sk_socket,
15057 +               (sk->sk_socket?sk->sk_socket->flags:0));
15058 +
15059 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
15060 +       if (err)
15061 +               return err;
15062 +
15063 +       if (!fl.fl4_dst || !fl.fl4_src) {
15064                 err = __ip_route_output_key(net, rp, &fl);
15065                 if (err)
15066                         return err;
15067 diff -NurpP --minimal linux-2.6.27.6/include/net/sock.h linux-2.6.27.6-vs2.3.0.36/include/net/sock.h
15068 --- linux-2.6.27.6/include/net/sock.h   2008-10-13 14:52:09.000000000 +0200
15069 +++ linux-2.6.27.6-vs2.3.0.36/include/net/sock.h        2008-10-13 14:54:20.000000000 +0200
15070 @@ -128,6 +128,10 @@ struct sock_common {
15071  #ifdef CONFIG_NET_NS
15072         struct net              *skc_net;
15073  #endif
15074 +       xid_t                   skc_xid;
15075 +       struct vx_info          *skc_vx_info;
15076 +       nid_t                   skc_nid;
15077 +       struct nx_info          *skc_nx_info;
15078  };
15079  
15080  /**
15081 @@ -211,6 +215,10 @@ struct sock {
15082  #define sk_hash                        __sk_common.skc_hash
15083  #define sk_prot                        __sk_common.skc_prot
15084  #define sk_net                 __sk_common.skc_net
15085 +#define sk_xid                 __sk_common.skc_xid
15086 +#define sk_vx_info             __sk_common.skc_vx_info
15087 +#define sk_nid                 __sk_common.skc_nid
15088 +#define sk_nx_info             __sk_common.skc_nx_info
15089         unsigned char           sk_shutdown : 2,
15090                                 sk_no_check : 2,
15091                                 sk_userlocks : 4;
15092 diff -NurpP --minimal linux-2.6.27.6/init/main.c linux-2.6.27.6-vs2.3.0.36/init/main.c
15093 --- linux-2.6.27.6/init/main.c  2008-10-13 14:52:09.000000000 +0200
15094 +++ linux-2.6.27.6-vs2.3.0.36/init/main.c       2008-10-13 14:54:20.000000000 +0200
15095 @@ -60,6 +60,7 @@
15096  #include <linux/sched.h>
15097  #include <linux/signal.h>
15098  #include <linux/idr.h>
15099 +#include <linux/vserver/percpu.h>
15100  
15101  #include <asm/io.h>
15102  #include <asm/bugs.h>
15103 @@ -391,12 +392,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15104  
15105  static void __init setup_per_cpu_areas(void)
15106  {
15107 -       unsigned long size, i;
15108 +       unsigned long size, vspc, i;
15109         char *ptr;
15110         unsigned long nr_possible_cpus = num_possible_cpus();
15111  
15112 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15113 +
15114         /* Copy section for each CPU (we discard the original) */
15115 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15116 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15117         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15118  
15119         for_each_possible_cpu(i) {
15120 diff -NurpP --minimal linux-2.6.27.6/ipc/mqueue.c linux-2.6.27.6-vs2.3.0.36/ipc/mqueue.c
15121 --- linux-2.6.27.6/ipc/mqueue.c 2008-10-13 14:52:09.000000000 +0200
15122 +++ linux-2.6.27.6-vs2.3.0.36/ipc/mqueue.c      2008-10-13 14:54:20.000000000 +0200
15123 @@ -31,6 +31,8 @@
15124  #include <linux/mutex.h>
15125  #include <linux/nsproxy.h>
15126  #include <linux/pid.h>
15127 +#include <linux/vs_context.h>
15128 +#include <linux/vs_limit.h>
15129  
15130  #include <net/sock.h>
15131  #include "util.h"
15132 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
15133         struct sigevent notify;
15134         struct pid* notify_owner;
15135         struct user_struct *user;       /* user who created, for accounting */
15136 +       struct vx_info *vxi;
15137         struct sock *notify_sock;
15138         struct sk_buff *notify_cookie;
15139  
15140 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
15141                         struct mqueue_inode_info *info;
15142                         struct task_struct *p = current;
15143                         struct user_struct *u = p->user;
15144 +                       struct vx_info *vxi = p->vx_info;
15145                         unsigned long mq_bytes, mq_msg_tblsz;
15146  
15147                         inode->i_fop = &mqueue_file_operations;
15148 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
15149                         info->notify_owner = NULL;
15150                         info->qsize = 0;
15151                         info->user = NULL;      /* set when all is ok */
15152 +                       info->vxi = NULL;
15153                         memset(&info->attr, 0, sizeof(info->attr));
15154                         info->attr.mq_maxmsg = DFLT_MSGMAX;
15155                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
15156 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
15157                         spin_lock(&mq_lock);
15158                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15159                             u->mq_bytes + mq_bytes >
15160 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15161 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15162 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15163                                 spin_unlock(&mq_lock);
15164                                 goto out_inode;
15165                         }
15166                         u->mq_bytes += mq_bytes;
15167 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15168                         spin_unlock(&mq_lock);
15169  
15170                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15171                         if (!info->messages) {
15172                                 spin_lock(&mq_lock);
15173                                 u->mq_bytes -= mq_bytes;
15174 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15175                                 spin_unlock(&mq_lock);
15176                                 goto out_inode;
15177                         }
15178                         /* all is ok */
15179                         info->user = get_uid(u);
15180 +                       info->vxi = get_vx_info(vxi);
15181                 } else if (S_ISDIR(mode)) {
15182                         inc_nlink(inode);
15183                         /* Some things misbehave if size == 0 on a directory */
15184 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
15185                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15186         user = info->user;
15187         if (user) {
15188 +               struct vx_info *vxi = info->vxi;
15189 +
15190                 spin_lock(&mq_lock);
15191                 user->mq_bytes -= mq_bytes;
15192 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15193                 queues_count--;
15194                 spin_unlock(&mq_lock);
15195 +               put_vx_info(vxi);
15196                 free_uid(user);
15197         }
15198  }
15199 diff -NurpP --minimal linux-2.6.27.6/ipc/msg.c linux-2.6.27.6-vs2.3.0.36/ipc/msg.c
15200 --- linux-2.6.27.6/ipc/msg.c    2008-07-13 23:51:29.000000000 +0200
15201 +++ linux-2.6.27.6-vs2.3.0.36/ipc/msg.c 2008-10-13 14:54:20.000000000 +0200
15202 @@ -38,6 +38,7 @@
15203  #include <linux/rwsem.h>
15204  #include <linux/nsproxy.h>
15205  #include <linux/ipc_namespace.h>
15206 +#include <linux/vs_base.h>
15207  
15208  #include <asm/current.h>
15209  #include <asm/uaccess.h>
15210 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
15211  
15212         msq->q_perm.mode = msgflg & S_IRWXUGO;
15213         msq->q_perm.key = key;
15214 +       msq->q_perm.xid = vx_current_xid();
15215  
15216         msq->q_perm.security = NULL;
15217         retval = security_msg_queue_alloc(msq);
15218 diff -NurpP --minimal linux-2.6.27.6/ipc/namespace.c linux-2.6.27.6-vs2.3.0.36/ipc/namespace.c
15219 --- linux-2.6.27.6/ipc/namespace.c      2008-07-13 23:51:29.000000000 +0200
15220 +++ linux-2.6.27.6-vs2.3.0.36/ipc/namespace.c   2008-10-13 14:54:20.000000000 +0200
15221 @@ -9,6 +9,8 @@
15222  #include <linux/rcupdate.h>
15223  #include <linux/nsproxy.h>
15224  #include <linux/slab.h>
15225 +#include <linux/vs_base.h>
15226 +#include <linux/vserver/global.h>
15227  
15228  #include "util.h"
15229  
15230 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
15231         register_ipcns_notifier(ns);
15232  
15233         kref_init(&ns->kref);
15234 +       atomic_inc(&vs_global_ipc_ns);
15235         return ns;
15236  }
15237  
15238 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
15239         sem_exit_ns(ns);
15240         msg_exit_ns(ns);
15241         shm_exit_ns(ns);
15242 +       atomic_dec(&vs_global_ipc_ns);
15243         kfree(ns);
15244         atomic_dec(&nr_ipc_ns);
15245  
15246 diff -NurpP --minimal linux-2.6.27.6/ipc/sem.c linux-2.6.27.6-vs2.3.0.36/ipc/sem.c
15247 --- linux-2.6.27.6/ipc/sem.c    2008-10-13 14:52:09.000000000 +0200
15248 +++ linux-2.6.27.6-vs2.3.0.36/ipc/sem.c 2008-10-13 14:54:20.000000000 +0200
15249 @@ -83,6 +83,8 @@
15250  #include <linux/rwsem.h>
15251  #include <linux/nsproxy.h>
15252  #include <linux/ipc_namespace.h>
15253 +#include <linux/vs_base.h>
15254 +#include <linux/vs_limit.h>
15255  
15256  #include <asm/uaccess.h>
15257  #include "util.h"
15258 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
15259  
15260         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15261         sma->sem_perm.key = key;
15262 +       sma->sem_perm.xid = vx_current_xid();
15263  
15264         sma->sem_perm.security = NULL;
15265         retval = security_sem_alloc(sma);
15266 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
15267                 return id;
15268         }
15269         ns->used_sems += nsems;
15270 +       /* FIXME: obsoleted? */
15271 +       vx_semary_inc(sma);
15272 +       vx_nsems_add(sma, nsems);
15273  
15274         sma->sem_base = (struct sem *) &sma[1];
15275         INIT_LIST_HEAD(&sma->sem_pending);
15276 diff -NurpP --minimal linux-2.6.27.6/ipc/shm.c linux-2.6.27.6-vs2.3.0.36/ipc/shm.c
15277 --- linux-2.6.27.6/ipc/shm.c    2008-10-13 14:52:09.000000000 +0200
15278 +++ linux-2.6.27.6-vs2.3.0.36/ipc/shm.c 2008-10-13 14:54:20.000000000 +0200
15279 @@ -39,6 +39,8 @@
15280  #include <linux/nsproxy.h>
15281  #include <linux/mount.h>
15282  #include <linux/ipc_namespace.h>
15283 +#include <linux/vs_context.h>
15284 +#include <linux/vs_limit.h>
15285  
15286  #include <asm/uaccess.h>
15287  
15288 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
15289   */
15290  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15291  {
15292 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15293 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15294 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15295 +
15296 +       vx_ipcshm_sub(vxi, shp, numpages);
15297 +       ns->shm_tot -= numpages;
15298 +
15299         shm_rmid(ns, shp);
15300         shm_unlock(shp);
15301         if (!is_file_hugepages(shp->shm_file))
15302 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
15303                                                 shp->mlock_user);
15304         fput (shp->shm_file);
15305         security_shm_free(shp);
15306 +       put_vx_info(vxi);
15307         ipc_rcu_putref(shp);
15308  }
15309  
15310 @@ -347,11 +355,15 @@ static int newseg(struct ipc_namespace *
15311         if (ns->shm_tot + numpages > ns->shm_ctlall)
15312                 return -ENOSPC;
15313  
15314 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15315 +               return -ENOSPC;
15316 +
15317         shp = ipc_rcu_alloc(sizeof(*shp));
15318         if (!shp)
15319                 return -ENOMEM;
15320  
15321         shp->shm_perm.key = key;
15322 +       shp->shm_perm.xid = vx_current_xid();
15323         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15324         shp->mlock_user = NULL;
15325  
15326 @@ -404,6 +416,7 @@ static int newseg(struct ipc_namespace *
15327         ns->shm_tot += numpages;
15328         error = shp->shm_perm.id;
15329         shm_unlock(shp);
15330 +       vx_ipcshm_add(current->vx_info, key, numpages);
15331         return error;
15332  
15333  no_id:
15334 diff -NurpP --minimal linux-2.6.27.6/kernel/capability.c linux-2.6.27.6-vs2.3.0.36/kernel/capability.c
15335 --- linux-2.6.27.6/kernel/capability.c  2008-10-13 14:52:09.000000000 +0200
15336 +++ linux-2.6.27.6-vs2.3.0.36/kernel/capability.c       2008-10-13 14:54:20.000000000 +0200
15337 @@ -13,6 +13,7 @@
15338  #include <linux/security.h>
15339  #include <linux/syscalls.h>
15340  #include <linux/pid_namespace.h>
15341 +#include <linux/vs_context.h>
15342  #include <asm/uaccess.h>
15343  
15344  /*
15345 @@ -166,6 +167,8 @@ static inline int cap_set_pg(int pgrp_nr
15346  
15347         pgrp = find_vpid(pgrp_nr);
15348         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
15349 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
15350 +                       continue;
15351                 target = g;
15352                 while_each_thread(g, target) {
15353                         if (!security_capset_check(target, effective,
15354 @@ -486,6 +489,8 @@ asmlinkage long sys_capset(cap_user_head
15355         return ret;
15356  }
15357  
15358 +#include <linux/vserver/base.h>
15359 +
15360  /**
15361   * capable - Determine if the current task has a superior capability in effect
15362   * @cap: The capability to be tested for
15363 @@ -498,6 +503,9 @@ asmlinkage long sys_capset(cap_user_head
15364   */
15365  int capable(int cap)
15366  {
15367 +       /* here for now so we don't require task locking */
15368 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15369 +               return 0;
15370         if (has_capability(current, cap)) {
15371                 current->flags |= PF_SUPERPRIV;
15372                 return 1;
15373 diff -NurpP --minimal linux-2.6.27.6/kernel/compat.c linux-2.6.27.6-vs2.3.0.36/kernel/compat.c
15374 --- linux-2.6.27.6/kernel/compat.c      2008-07-13 23:51:29.000000000 +0200
15375 +++ linux-2.6.27.6-vs2.3.0.36/kernel/compat.c   2008-10-13 14:54:20.000000000 +0200
15376 @@ -845,7 +845,7 @@ asmlinkage long compat_sys_time(compat_t
15377         compat_time_t i;
15378         struct timeval tv;
15379  
15380 -       do_gettimeofday(&tv);
15381 +       vx_gettimeofday(&tv);
15382         i = tv.tv_sec;
15383  
15384         if (tloc) {
15385 @@ -869,7 +869,7 @@ asmlinkage long compat_sys_stime(compat_
15386         if (err)
15387                 return err;
15388  
15389 -       do_settimeofday(&tv);
15390 +       vx_settimeofday(&tv);
15391         return 0;
15392  }
15393  
15394 diff -NurpP --minimal linux-2.6.27.6/kernel/exit.c linux-2.6.27.6-vs2.3.0.36/kernel/exit.c
15395 --- linux-2.6.27.6/kernel/exit.c        2008-10-13 14:52:09.000000000 +0200
15396 +++ linux-2.6.27.6-vs2.3.0.36/kernel/exit.c     2008-10-13 14:54:20.000000000 +0200
15397 @@ -47,6 +47,11 @@
15398  #include <linux/blkdev.h>
15399  #include <linux/task_io_accounting_ops.h>
15400  #include <linux/tracehook.h>
15401 +#include <linux/vs_limit.h>
15402 +#include <linux/vs_context.h>
15403 +#include <linux/vs_network.h>
15404 +#include <linux/vs_pid.h>
15405 +#include <linux/vserver/global.h>
15406  
15407  #include <asm/uaccess.h>
15408  #include <asm/unistd.h>
15409 @@ -485,9 +490,11 @@ static void close_files(struct files_str
15410                                         filp_close(file, files);
15411                                         cond_resched();
15412                                 }
15413 +                               vx_openfd_dec(i);
15414                         }
15415                         i++;
15416                         set >>= 1;
15417 +                       cond_resched();
15418                 }
15419         }
15420  }
15421 @@ -554,6 +561,7 @@ void put_fs_struct(struct fs_struct *fs)
15422         if (atomic_dec_and_test(&fs->count)) {
15423                 path_put(&fs->root);
15424                 path_put(&fs->pwd);
15425 +               atomic_dec(&vs_global_fs);
15426                 kmem_cache_free(fs_cachep, fs);
15427         }
15428  }
15429 @@ -1122,6 +1130,10 @@ NORET_TYPE void do_exit(long code)
15430         if (tsk->splice_pipe)
15431                 __free_pipe_info(tsk->splice_pipe);
15432  
15433 +       /* needs to stay after exit_notify() */
15434 +       exit_vx_info(tsk, code);
15435 +       exit_nx_info(tsk);
15436 +
15437         preempt_disable();
15438         /* causes final put_task_struct in finish_task_switch(). */
15439         tsk->state = TASK_DEAD;
15440 diff -NurpP --minimal linux-2.6.27.6/kernel/fork.c linux-2.6.27.6-vs2.3.0.36/kernel/fork.c
15441 --- linux-2.6.27.6/kernel/fork.c        2008-10-13 14:52:09.000000000 +0200
15442 +++ linux-2.6.27.6-vs2.3.0.36/kernel/fork.c     2008-10-13 14:54:20.000000000 +0200
15443 @@ -58,6 +58,11 @@
15444  #include <linux/tty.h>
15445  #include <linux/proc_fs.h>
15446  #include <linux/blkdev.h>
15447 +#include <linux/vs_context.h>
15448 +#include <linux/vs_network.h>
15449 +#include <linux/vs_limit.h>
15450 +#include <linux/vs_memory.h>
15451 +#include <linux/vserver/global.h>
15452  
15453  #include <asm/pgtable.h>
15454  #include <asm/pgalloc.h>
15455 @@ -135,6 +140,8 @@ void free_task(struct task_struct *tsk)
15456         prop_local_destroy_single(&tsk->dirties);
15457         free_thread_info(tsk->stack);
15458         rt_mutex_debug_task_free(tsk);
15459 +       clr_vx_info(&tsk->vx_info);
15460 +       clr_nx_info(&tsk->nx_info);
15461         free_task_struct(tsk);
15462  }
15463  EXPORT_SYMBOL(free_task);
15464 @@ -274,6 +281,8 @@ static int dup_mmap(struct mm_struct *mm
15465         mm->free_area_cache = oldmm->mmap_base;
15466         mm->cached_hole_size = ~0UL;
15467         mm->map_count = 0;
15468 +       __set_mm_counter(mm, file_rss, 0);
15469 +       __set_mm_counter(mm, anon_rss, 0);
15470         cpus_clear(mm->cpu_vm_mask);
15471         mm->mm_rb = RB_ROOT;
15472         rb_link = &mm->mm_rb.rb_node;
15473 @@ -285,7 +294,7 @@ static int dup_mmap(struct mm_struct *mm
15474  
15475                 if (mpnt->vm_flags & VM_DONTCOPY) {
15476                         long pages = vma_pages(mpnt);
15477 -                       mm->total_vm -= pages;
15478 +                       vx_vmpages_sub(mm, pages);
15479                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15480                                                                 -pages);
15481                         continue;
15482 @@ -404,8 +413,8 @@ static struct mm_struct * mm_init(struct
15483                                   : MMF_DUMP_FILTER_DEFAULT;
15484         mm->core_state = NULL;
15485         mm->nr_ptes = 0;
15486 -       set_mm_counter(mm, file_rss, 0);
15487 -       set_mm_counter(mm, anon_rss, 0);
15488 +       __set_mm_counter(mm, file_rss, 0);
15489 +       __set_mm_counter(mm, anon_rss, 0);
15490         spin_lock_init(&mm->page_table_lock);
15491         rwlock_init(&mm->ioctx_list_lock);
15492         mm->ioctx_list = NULL;
15493 @@ -416,6 +425,7 @@ static struct mm_struct * mm_init(struct
15494         if (likely(!mm_alloc_pgd(mm))) {
15495                 mm->def_flags = 0;
15496                 mmu_notifier_mm_init(mm);
15497 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15498                 return mm;
15499         }
15500  
15501 @@ -449,6 +459,7 @@ void __mmdrop(struct mm_struct *mm)
15502         mm_free_pgd(mm);
15503         destroy_context(mm);
15504         mmu_notifier_mm_destroy(mm);
15505 +       clr_vx_info(&mm->mm_vx_info);
15506         free_mm(mm);
15507  }
15508  EXPORT_SYMBOL_GPL(__mmdrop);
15509 @@ -565,6 +576,7 @@ struct mm_struct *dup_mm(struct task_str
15510                 goto fail_nomem;
15511  
15512         memcpy(mm, oldmm, sizeof(*mm));
15513 +       mm->mm_vx_info = NULL;
15514  
15515         /* Initializing for Swap token stuff */
15516         mm->token_priority = 0;
15517 @@ -598,6 +610,7 @@ fail_nocontext:
15518          * If init_new_context() failed, we cannot use mmput() to free the mm
15519          * because it calls destroy_context()
15520          */
15521 +       clr_vx_info(&mm->mm_vx_info);
15522         mm_free_pgd(mm);
15523         free_mm(mm);
15524         return NULL;
15525 @@ -661,6 +674,7 @@ static struct fs_struct *__copy_fs_struc
15526                 fs->pwd = old->pwd;
15527                 path_get(&old->pwd);
15528                 read_unlock(&old->lock);
15529 +               atomic_inc(&vs_global_fs);
15530         }
15531         return fs;
15532  }
15533 @@ -904,6 +918,8 @@ static struct task_struct *copy_process(
15534         int retval;
15535         struct task_struct *p;
15536         int cgroup_callbacks_done = 0;
15537 +       struct vx_info *vxi;
15538 +       struct nx_info *nxi;
15539  
15540         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15541                 return ERR_PTR(-EINVAL);
15542 @@ -938,12 +954,28 @@ static struct task_struct *copy_process(
15543         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15544         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15545  #endif
15546 +       init_vx_info(&p->vx_info, current->vx_info);
15547 +       init_nx_info(&p->nx_info, current->nx_info);
15548 +
15549 +       /* check vserver memory */
15550 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15551 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15552 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15553 +               else
15554 +                       goto bad_fork_free;
15555 +       }
15556 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15557 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15558 +                       goto bad_fork_cleanup_vm;
15559 +       }
15560         retval = -EAGAIN;
15561 +       if (!vx_nproc_avail(1))
15562 +               goto bad_fork_cleanup_vm;
15563         if (atomic_read(&p->user->processes) >=
15564                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15565                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15566                     p->user != current->nsproxy->user_ns->root_user)
15567 -                       goto bad_fork_free;
15568 +                       goto bad_fork_cleanup_vm;
15569         }
15570  
15571         atomic_inc(&p->user->__count);
15572 @@ -1241,6 +1273,18 @@ static struct task_struct *copy_process(
15573  
15574         total_forks++;
15575         spin_unlock(&current->sighand->siglock);
15576 +
15577 +       /* p is copy of current */
15578 +       vxi = p->vx_info;
15579 +       if (vxi) {
15580 +               claim_vx_info(vxi, p);
15581 +               atomic_inc(&vxi->cvirt.nr_threads);
15582 +               atomic_inc(&vxi->cvirt.total_forks);
15583 +               vx_nproc_inc(p);
15584 +       }
15585 +       nxi = p->nx_info;
15586 +       if (nxi)
15587 +               claim_nx_info(nxi, p);
15588         write_unlock_irq(&tasklist_lock);
15589         proc_fork_connector(p);
15590         cgroup_post_fork(p);
15591 @@ -1287,6 +1331,9 @@ bad_fork_cleanup_count:
15592         put_group_info(p->group_info);
15593         atomic_dec(&p->user->processes);
15594         free_uid(p->user);
15595 +bad_fork_cleanup_vm:
15596 +       if (p->mm && !(clone_flags & CLONE_VM))
15597 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15598  bad_fork_free:
15599         free_task(p);
15600  fork_out:
15601 diff -NurpP --minimal linux-2.6.27.6/kernel/kthread.c linux-2.6.27.6-vs2.3.0.36/kernel/kthread.c
15602 --- linux-2.6.27.6/kernel/kthread.c     2008-10-13 14:52:09.000000000 +0200
15603 +++ linux-2.6.27.6-vs2.3.0.36/kernel/kthread.c  2008-10-13 14:54:20.000000000 +0200
15604 @@ -13,6 +13,7 @@
15605  #include <linux/file.h>
15606  #include <linux/module.h>
15607  #include <linux/mutex.h>
15608 +#include <linux/vs_pid.h>
15609  
15610  #define KTHREAD_NICE_LEVEL (-5)
15611  
15612 @@ -98,7 +99,7 @@ static void create_kthread(struct kthrea
15613                 struct sched_param param = { .sched_priority = 0 };
15614                 wait_for_completion(&create->started);
15615                 read_lock(&tasklist_lock);
15616 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15617 +               create->result = find_task_by_real_pid(pid);
15618                 read_unlock(&tasklist_lock);
15619                 /*
15620                  * root may have changed our (kthreadd's) priority or CPU mask.
15621 diff -NurpP --minimal linux-2.6.27.6/kernel/Makefile linux-2.6.27.6-vs2.3.0.36/kernel/Makefile
15622 --- linux-2.6.27.6/kernel/Makefile      2008-10-13 14:52:09.000000000 +0200
15623 +++ linux-2.6.27.6-vs2.3.0.36/kernel/Makefile   2008-10-13 14:54:20.000000000 +0200
15624 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15625  CFLAGS_REMOVE_sched.o = -mno-spe -pg
15626  endif
15627  
15628 +obj-y += vserver/
15629  obj-$(CONFIG_PROFILING) += profile.o
15630  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15631  obj-$(CONFIG_STACKTRACE) += stacktrace.o
15632 diff -NurpP --minimal linux-2.6.27.6/kernel/nsproxy.c linux-2.6.27.6-vs2.3.0.36/kernel/nsproxy.c
15633 --- linux-2.6.27.6/kernel/nsproxy.c     2008-10-13 14:52:09.000000000 +0200
15634 +++ linux-2.6.27.6-vs2.3.0.36/kernel/nsproxy.c  2008-10-13 14:54:20.000000000 +0200
15635 @@ -19,6 +19,8 @@
15636  #include <linux/mnt_namespace.h>
15637  #include <linux/utsname.h>
15638  #include <linux/pid_namespace.h>
15639 +#include <linux/vserver/global.h>
15640 +#include <linux/vserver/debug.h>
15641  #include <net/net_namespace.h>
15642  #include <linux/ipc_namespace.h>
15643  
15644 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15645         if (ns) {
15646                 memcpy(ns, orig, sizeof(struct nsproxy));
15647                 atomic_set(&ns->count, 1);
15648 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15649 +                       orig, atomic_read(&orig->count), ns);
15650 +               atomic_inc(&vs_global_nsproxy);
15651         }
15652         return ns;
15653  }
15654 @@ -46,47 +51,51 @@ static inline struct nsproxy *clone_nspr
15655   * Return the newly created nsproxy.  Do not attach this to the task,
15656   * leave it to the caller to do proper locking and attach it to task.
15657   */
15658 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15659 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15660 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15661 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15662  {
15663         struct nsproxy *new_nsp;
15664         int err;
15665  
15666 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15667 +       vxdprintk(VXD_CBIT(space, 4),
15668 +               "unshare_namespaces(0x%08lx,%p,%p)",
15669 +               flags, orig, new_fs);
15670 +
15671 +       new_nsp = clone_nsproxy(orig);
15672         if (!new_nsp)
15673                 return ERR_PTR(-ENOMEM);
15674  
15675 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15676 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15677         if (IS_ERR(new_nsp->mnt_ns)) {
15678                 err = PTR_ERR(new_nsp->mnt_ns);
15679                 goto out_ns;
15680         }
15681  
15682 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15683 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15684         if (IS_ERR(new_nsp->uts_ns)) {
15685                 err = PTR_ERR(new_nsp->uts_ns);
15686                 goto out_uts;
15687         }
15688  
15689 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15690 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15691         if (IS_ERR(new_nsp->ipc_ns)) {
15692                 err = PTR_ERR(new_nsp->ipc_ns);
15693                 goto out_ipc;
15694         }
15695  
15696 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15697 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15698         if (IS_ERR(new_nsp->pid_ns)) {
15699                 err = PTR_ERR(new_nsp->pid_ns);
15700                 goto out_pid;
15701         }
15702  
15703 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
15704 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15705         if (IS_ERR(new_nsp->user_ns)) {
15706                 err = PTR_ERR(new_nsp->user_ns);
15707                 goto out_user;
15708         }
15709  
15710 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15711 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15712         if (IS_ERR(new_nsp->net_ns)) {
15713                 err = PTR_ERR(new_nsp->net_ns);
15714                 goto out_net;
15715 @@ -114,6 +123,37 @@ out_ns:
15716         return ERR_PTR(err);
15717  }
15718  
15719 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15720 +                       struct fs_struct *new_fs)
15721 +{
15722 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15723 +}
15724 +
15725 +/*
15726 + * copies the nsproxy, setting refcount to 1, and grabbing a
15727 + * reference to all contained namespaces.
15728 + */
15729 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15730 +{
15731 +       struct nsproxy *ns = clone_nsproxy(orig);
15732 +
15733 +       if (ns) {
15734 +               if (ns->mnt_ns)
15735 +                       get_mnt_ns(ns->mnt_ns);
15736 +               if (ns->uts_ns)
15737 +                       get_uts_ns(ns->uts_ns);
15738 +               if (ns->ipc_ns)
15739 +                       get_ipc_ns(ns->ipc_ns);
15740 +               if (ns->pid_ns)
15741 +                       get_pid_ns(ns->pid_ns);
15742 +               if (ns->user_ns)
15743 +                       get_user_ns(ns->user_ns);
15744 +               if (ns->net_ns)
15745 +                       get_net(ns->net_ns);
15746 +       }
15747 +       return ns;
15748 +}
15749 +
15750  /*
15751   * called from clone.  This now handles copy for nsproxy and all
15752   * namespaces therein.
15753 @@ -121,9 +161,12 @@ out_ns:
15754  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15755  {
15756         struct nsproxy *old_ns = tsk->nsproxy;
15757 -       struct nsproxy *new_ns;
15758 +       struct nsproxy *new_ns = NULL;
15759         int err = 0;
15760  
15761 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15762 +               flags, tsk, old_ns);
15763 +
15764         if (!old_ns)
15765                 return 0;
15766  
15767 @@ -160,6 +203,9 @@ int copy_namespaces(unsigned long flags,
15768  
15769  out:
15770         put_nsproxy(old_ns);
15771 +       vxdprintk(VXD_CBIT(space, 3),
15772 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15773 +               flags, tsk, old_ns, err, new_ns);
15774         return err;
15775  }
15776  
15777 @@ -175,7 +221,9 @@ void free_nsproxy(struct nsproxy *ns)
15778                 put_pid_ns(ns->pid_ns);
15779         if (ns->user_ns)
15780                 put_user_ns(ns->user_ns);
15781 -       put_net(ns->net_ns);
15782 +       if (ns->net_ns)
15783 +               put_net(ns->net_ns);
15784 +       atomic_dec(&vs_global_nsproxy);
15785         kmem_cache_free(nsproxy_cachep, ns);
15786  }
15787  
15788 @@ -188,6 +236,10 @@ int unshare_nsproxy_namespaces(unsigned 
15789  {
15790         int err = 0;
15791  
15792 +       vxdprintk(VXD_CBIT(space, 4),
15793 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15794 +               unshare_flags, current->nsproxy);
15795 +
15796         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15797                                CLONE_NEWUSER | CLONE_NEWNET)))
15798                 return 0;
15799 diff -NurpP --minimal linux-2.6.27.6/kernel/pid.c linux-2.6.27.6-vs2.3.0.36/kernel/pid.c
15800 --- linux-2.6.27.6/kernel/pid.c 2008-10-13 14:52:09.000000000 +0200
15801 +++ linux-2.6.27.6-vs2.3.0.36/kernel/pid.c      2008-10-13 14:54:20.000000000 +0200
15802 @@ -36,6 +36,8 @@
15803  #include <linux/pid_namespace.h>
15804  #include <linux/init_task.h>
15805  #include <linux/syscalls.h>
15806 +#include <linux/vs_pid.h>
15807 +#include <linux/vserver/global.h>
15808  
15809  #define pid_hashfn(nr, ns)     \
15810         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15811 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15812  
15813  struct pid *find_vpid(int nr)
15814  {
15815 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15816 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15817  }
15818  EXPORT_SYMBOL_GPL(find_vpid);
15819  
15820 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15821  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15822  {
15823         struct task_struct *result = NULL;
15824 +
15825 +       if (type == PIDTYPE_REALPID)
15826 +               type = PIDTYPE_PID;
15827         if (pid) {
15828                 struct hlist_node *first;
15829                 first = rcu_dereference(pid->tasks[type].first);
15830 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15831  
15832  struct task_struct *find_task_by_vpid(pid_t vnr)
15833  {
15834 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15835 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15836                         current->nsproxy->pid_ns);
15837  }
15838  EXPORT_SYMBOL(find_task_by_vpid);
15839  
15840  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15841  {
15842 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15843 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15844  }
15845  EXPORT_SYMBOL(find_task_by_pid_ns);
15846  
15847 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15848  }
15849  EXPORT_SYMBOL_GPL(find_get_pid);
15850  
15851 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15852 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15853  {
15854         struct upid *upid;
15855         pid_t nr = 0;
15856 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15857         return nr;
15858  }
15859  
15860 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15861 +{
15862 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15863 +}
15864 +
15865  pid_t pid_vnr(struct pid *pid)
15866  {
15867         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15868 diff -NurpP --minimal linux-2.6.27.6/kernel/pid_namespace.c linux-2.6.27.6-vs2.3.0.36/kernel/pid_namespace.c
15869 --- linux-2.6.27.6/kernel/pid_namespace.c       2008-10-13 14:52:09.000000000 +0200
15870 +++ linux-2.6.27.6-vs2.3.0.36/kernel/pid_namespace.c    2008-10-13 14:54:20.000000000 +0200
15871 @@ -13,6 +13,7 @@
15872  #include <linux/syscalls.h>
15873  #include <linux/err.h>
15874  #include <linux/acct.h>
15875 +#include <linux/vserver/global.h>
15876  
15877  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15878  
15879 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15880                 goto out_free_map;
15881  
15882         kref_init(&ns->kref);
15883 +       atomic_inc(&vs_global_pid_ns);
15884         ns->level = level;
15885  
15886         set_bit(0, ns->pidmap[0].page);
15887 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15888  
15889         for (i = 0; i < PIDMAP_ENTRIES; i++)
15890                 kfree(ns->pidmap[i].page);
15891 +       atomic_dec(&vs_global_pid_ns);
15892         kmem_cache_free(pid_ns_cachep, ns);
15893  }
15894  
15895 diff -NurpP --minimal linux-2.6.27.6/kernel/posix-timers.c linux-2.6.27.6-vs2.3.0.36/kernel/posix-timers.c
15896 --- linux-2.6.27.6/kernel/posix-timers.c        2008-10-13 14:52:09.000000000 +0200
15897 +++ linux-2.6.27.6-vs2.3.0.36/kernel/posix-timers.c     2008-10-13 14:54:20.000000000 +0200
15898 @@ -46,6 +46,7 @@
15899  #include <linux/wait.h>
15900  #include <linux/workqueue.h>
15901  #include <linux/module.h>
15902 +#include <linux/vs_context.h>
15903  
15904  /*
15905   * Management arrays for POSIX timers.  Timers are kept in slab memory
15906 @@ -298,6 +299,12 @@ void do_schedule_next_timer(struct sigin
15907  
15908  int posix_timer_event(struct k_itimer *timr, int si_private)
15909  {
15910 +       struct vx_info_save vxis;
15911 +       struct vx_info *vxi;
15912 +       int ret;
15913 +
15914 +       vxi = task_get_vx_info(timr->it_process);
15915 +       enter_vx_info(vxi, &vxis);
15916         /*
15917          * FIXME: if ->sigq is queued we can race with
15918          * dequeue_signal()->do_schedule_next_timer().
15919 @@ -318,10 +325,11 @@ int posix_timer_event(struct k_itimer *t
15920  
15921         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
15922                 struct task_struct *leader;
15923 -               int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15924 +
15925 +               ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15926  
15927                 if (likely(ret >= 0))
15928 -                       return ret;
15929 +                       goto out;
15930  
15931                 timr->it_sigev_notify = SIGEV_SIGNAL;
15932                 leader = timr->it_process->group_leader;
15933 @@ -329,7 +337,11 @@ int posix_timer_event(struct k_itimer *t
15934                 timr->it_process = leader;
15935         }
15936  
15937 -       return send_sigqueue(timr->sigq, timr->it_process, 1);
15938 +       ret = send_sigqueue(timr->sigq, timr->it_process, 1);
15939 +out:
15940 +       leave_vx_info(&vxis);
15941 +       put_vx_info(vxi);
15942 +       return ret;
15943  }
15944  EXPORT_SYMBOL_GPL(posix_timer_event);
15945  
15946 diff -NurpP --minimal linux-2.6.27.6/kernel/printk.c linux-2.6.27.6-vs2.3.0.36/kernel/printk.c
15947 --- linux-2.6.27.6/kernel/printk.c      2008-10-13 14:52:09.000000000 +0200
15948 +++ linux-2.6.27.6-vs2.3.0.36/kernel/printk.c   2008-10-13 14:54:20.000000000 +0200
15949 @@ -32,6 +32,7 @@
15950  #include <linux/security.h>
15951  #include <linux/bootmem.h>
15952  #include <linux/syscalls.h>
15953 +#include <linux/vs_cvirt.h>
15954  
15955  #include <asm/uaccess.h>
15956  
15957 @@ -291,18 +292,13 @@ int do_syslog(int type, char __user *buf
15958         unsigned i, j, limit, count;
15959         int do_clear = 0;
15960         char c;
15961 -       int error = 0;
15962 +       int error;
15963  
15964         error = security_syslog(type);
15965         if (error)
15966                 return error;
15967  
15968 -       switch (type) {
15969 -       case 0:         /* Close log */
15970 -               break;
15971 -       case 1:         /* Open log */
15972 -               break;
15973 -       case 2:         /* Read from log */
15974 +       if ((type >= 2) && (type <= 4)) {
15975                 error = -EINVAL;
15976                 if (!buf || len < 0)
15977                         goto out;
15978 @@ -313,6 +309,16 @@ int do_syslog(int type, char __user *buf
15979                         error = -EFAULT;
15980                         goto out;
15981                 }
15982 +       }
15983 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15984 +               return vx_do_syslog(type, buf, len);
15985 +
15986 +       switch (type) {
15987 +       case 0:         /* Close log */
15988 +               break;
15989 +       case 1:         /* Open log */
15990 +               break;
15991 +       case 2:         /* Read from log */
15992                 error = wait_event_interruptible(log_wait,
15993                                                         (log_start - log_end));
15994                 if (error)
15995 @@ -337,16 +343,6 @@ int do_syslog(int type, char __user *buf
15996                 do_clear = 1;
15997                 /* FALL THRU */
15998         case 3:         /* Read last kernel messages */
15999 -               error = -EINVAL;
16000 -               if (!buf || len < 0)
16001 -                       goto out;
16002 -               error = 0;
16003 -               if (!len)
16004 -                       goto out;
16005 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16006 -                       error = -EFAULT;
16007 -                       goto out;
16008 -               }
16009                 count = len;
16010                 if (count > log_buf_len)
16011                         count = log_buf_len;
16012 diff -NurpP --minimal linux-2.6.27.6/kernel/ptrace.c linux-2.6.27.6-vs2.3.0.36/kernel/ptrace.c
16013 --- linux-2.6.27.6/kernel/ptrace.c      2008-10-13 14:52:09.000000000 +0200
16014 +++ linux-2.6.27.6-vs2.3.0.36/kernel/ptrace.c   2008-10-13 14:54:20.000000000 +0200
16015 @@ -21,6 +21,7 @@
16016  #include <linux/audit.h>
16017  #include <linux/pid_namespace.h>
16018  #include <linux/syscalls.h>
16019 +#include <linux/vs_context.h>
16020  
16021  #include <asm/pgtable.h>
16022  #include <asm/uaccess.h>
16023 @@ -139,6 +140,11 @@ int __ptrace_may_access(struct task_stru
16024                 dumpable = get_dumpable(task->mm);
16025         if (!dumpable && !capable(CAP_SYS_PTRACE))
16026                 return -EPERM;
16027 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16028 +               return -EPERM;
16029 +       if (!vx_check(task->xid, VS_IDENT) &&
16030 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16031 +               return -EACCES;
16032  
16033         return security_ptrace_may_access(task, mode);
16034  }
16035 @@ -567,6 +573,10 @@ asmlinkage long sys_ptrace(long request,
16036                 goto out;
16037         }
16038  
16039 +       ret = -EPERM;
16040 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16041 +               goto out_put_task_struct;
16042 +
16043         if (request == PTRACE_ATTACH) {
16044                 ret = ptrace_attach(child);
16045                 /*
16046 diff -NurpP --minimal linux-2.6.27.6/kernel/sched.c linux-2.6.27.6-vs2.3.0.36/kernel/sched.c
16047 --- linux-2.6.27.6/kernel/sched.c       2008-10-13 14:52:09.000000000 +0200
16048 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sched.c    2008-10-13 14:54:20.000000000 +0200
16049 @@ -71,6 +71,8 @@
16050  #include <linux/debugfs.h>
16051  #include <linux/ctype.h>
16052  #include <linux/ftrace.h>
16053 +#include <linux/vs_sched.h>
16054 +#include <linux/vs_cvirt.h>
16055  
16056  #include <asm/tlb.h>
16057  #include <asm/irq_regs.h>
16058 @@ -497,6 +499,16 @@ struct root_domain {
16059  static struct root_domain def_root_domain;
16060  
16061  #endif
16062 +       unsigned long norm_time;
16063 +       unsigned long idle_time;
16064 +#ifdef CONFIG_VSERVER_IDLETIME
16065 +       int idle_skip;
16066 +#endif
16067 +#ifdef CONFIG_VSERVER_HARDCPU
16068 +       struct list_head hold_queue;
16069 +       unsigned long nr_onhold;
16070 +       int idle_tokens;
16071 +#endif
16072  
16073  /*
16074   * This is the main, per-CPU runqueue data structure.
16075 @@ -1640,6 +1652,7 @@ static void update_avg(u64 *avg, u64 sam
16076  
16077  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
16078  {
16079 +       // BUG_ON(p->state & TASK_ONHOLD);
16080         sched_info_queued(p);
16081         p->sched_class->enqueue_task(rq, p, wakeup);
16082         p->se.on_rq = 1;
16083 @@ -1837,6 +1850,9 @@ struct migration_req {
16084         struct completion done;
16085  };
16086  
16087 +#include "sched_mon.h"
16088 +
16089 +
16090  /*
16091   * The task's runqueue lock must be held.
16092   * Returns true if you have to wait for migration thread.
16093 @@ -1846,6 +1862,7 @@ migrate_task(struct task_struct *p, int 
16094  {
16095         struct rq *rq = task_rq(p);
16096  
16097 +       vxm_migrate_task(p, rq, dest_cpu);
16098         /*
16099          * If the task is not on a runqueue (and not running), then
16100          * it is sufficient to simply update the task's cpu field.
16101 @@ -2242,6 +2259,12 @@ static int try_to_wake_up(struct task_st
16102                 /* might preempt at this point */
16103                 rq = task_rq_lock(p, &flags);
16104                 old_state = p->state;
16105 +
16106 +       /* we need to unhold suspended tasks
16107 +       if (old_state & TASK_ONHOLD) {
16108 +               vx_unhold_task(p, rq);
16109 +               old_state = p->state;
16110 +       } */
16111                 if (!(old_state & state))
16112                         goto out;
16113                 if (p->se.on_rq)
16114 @@ -4067,13 +4090,16 @@ unsigned long long task_sched_runtime(st
16115  void account_user_time(struct task_struct *p, cputime_t cputime)
16116  {
16117         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16118 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16119         cputime64_t tmp;
16120 +       int nice = (TASK_NICE(p) > 0);
16121  
16122         p->utime = cputime_add(p->utime, cputime);
16123 +       vx_account_user(vxi, cputime, nice);
16124  
16125         /* Add user time to cpustat. */
16126         tmp = cputime_to_cputime64(cputime);
16127 -       if (TASK_NICE(p) > 0)
16128 +       if (nice)
16129                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16130         else
16131                 cpustat->user = cputime64_add(cpustat->user, tmp);
16132 @@ -4120,6 +4146,7 @@ void account_system_time(struct task_str
16133                          cputime_t cputime)
16134  {
16135         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16136 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16137         struct rq *rq = this_rq();
16138         cputime64_t tmp;
16139  
16140 @@ -4129,6 +4156,7 @@ void account_system_time(struct task_str
16141         }
16142  
16143         p->stime = cputime_add(p->stime, cputime);
16144 +       vx_account_system(vxi, cputime, (p == rq->idle));
16145  
16146         /* Add system time to cpustat. */
16147         tmp = cputime_to_cputime64(cputime);
16148 @@ -4963,7 +4991,7 @@ asmlinkage long sys_nice(int increment)
16149                 nice = 19;
16150  
16151         if (increment < 0 && !can_nice(current, nice))
16152 -               return -EPERM;
16153 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16154  
16155         retval = security_task_setnice(current, nice);
16156         if (retval)
16157 diff -NurpP --minimal linux-2.6.27.6/kernel/sched_fair.c linux-2.6.27.6-vs2.3.0.36/kernel/sched_fair.c
16158 --- linux-2.6.27.6/kernel/sched_fair.c  2008-10-13 14:52:09.000000000 +0200
16159 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sched_fair.c       2008-10-13 14:54:20.000000000 +0200
16160 @@ -724,6 +724,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16161         check_spread(cfs_rq, se);
16162         if (se != cfs_rq->curr)
16163                 __enqueue_entity(cfs_rq, se);
16164 +
16165 +       if (entity_is_task(se))
16166 +               vx_activate_task(task_of(se));
16167  }
16168  
16169  static void
16170 @@ -750,6 +753,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16171  
16172         if (se != cfs_rq->curr)
16173                 __dequeue_entity(cfs_rq, se);
16174 +       if (entity_is_task(se))
16175 +               vx_deactivate_task(task_of(se));
16176         account_entity_dequeue(cfs_rq, se);
16177  }
16178  
16179 diff -NurpP --minimal linux-2.6.27.6/kernel/sched_hard.h linux-2.6.27.6-vs2.3.0.36/kernel/sched_hard.h
16180 --- linux-2.6.27.6/kernel/sched_hard.h  1970-01-01 01:00:00.000000000 +0100
16181 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sched_hard.h       2008-10-13 14:54:20.000000000 +0200
16182 @@ -0,0 +1,324 @@
16183 +
16184 +#ifdef CONFIG_VSERVER_IDLELIMIT
16185 +
16186 +/*
16187 + * vx_idle_resched - reschedule after maxidle
16188 + */
16189 +static inline
16190 +void vx_idle_resched(struct rq *rq)
16191 +{
16192 +       /* maybe have a better criterion for paused */
16193 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16194 +               set_need_resched();
16195 +}
16196 +
16197 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16198 +
16199 +#define vx_idle_resched(rq)
16200 +
16201 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16202 +
16203 +
16204 +
16205 +#ifdef CONFIG_VSERVER_IDLETIME
16206 +
16207 +#define vx_set_rq_min_skip(rq, min)            \
16208 +       (rq)->idle_skip = (min)
16209 +
16210 +#define vx_save_min_skip(ret, min, val)                \
16211 +       __vx_save_min_skip(ret, min, val)
16212 +
16213 +static inline
16214 +void __vx_save_min_skip(int ret, int *min, int val)
16215 +{
16216 +       if (ret > -2)
16217 +               return;
16218 +       if ((*min > val) || !*min)
16219 +               *min = val;
16220 +}
16221 +
16222 +static inline
16223 +int vx_try_skip(struct rq *rq, int cpu)
16224 +{
16225 +       /* artificially advance time */
16226 +       if (rq->idle_skip > 0) {
16227 +               vxdprintk(list_empty(&rq->hold_queue),
16228 +                       "hold queue empty on cpu %d", cpu);
16229 +               rq->idle_time += rq->idle_skip;
16230 +               vxm_idle_skip(rq, cpu);
16231 +               return 1;
16232 +       }
16233 +       return 0;
16234 +}
16235 +
16236 +#else /* !CONFIG_VSERVER_IDLETIME */
16237 +
16238 +#define vx_set_rq_min_skip(rq, min)            \
16239 +       ({ int dummy = (min); dummy; })
16240 +
16241 +#define vx_save_min_skip(ret, min, val)
16242 +
16243 +static inline
16244 +int vx_try_skip(struct rq *rq, int cpu)
16245 +{
16246 +       return 0;
16247 +}
16248 +
16249 +#endif /* CONFIG_VSERVER_IDLETIME */
16250 +
16251 +
16252 +
16253 +#ifdef CONFIG_VSERVER_HARDCPU
16254 +
16255 +#define vx_set_rq_max_idle(rq, max)            \
16256 +       (rq)->idle_tokens = (max)
16257 +
16258 +#define vx_save_max_idle(ret, min, val)                \
16259 +       __vx_save_max_idle(ret, min, val)
16260 +
16261 +static inline
16262 +void __vx_save_max_idle(int ret, int *min, int val)
16263 +{
16264 +       if (*min > val)
16265 +               *min = val;
16266 +}
16267 +
16268 +
16269 +/*
16270 + * vx_hold_task - put a task on the hold queue
16271 + */
16272 +static inline
16273 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16274 +{
16275 +       __deactivate_task(p, rq);
16276 +       p->state |= TASK_ONHOLD;
16277 +       /* a new one on hold */
16278 +       rq->nr_onhold++;
16279 +       vxm_hold_task(p, rq);
16280 +       list_add_tail(&p->run_list, &rq->hold_queue);
16281 +}
16282 +
16283 +/*
16284 + * vx_unhold_task - put a task back to the runqueue
16285 + */
16286 +static inline
16287 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16288 +{
16289 +       list_del(&p->run_list);
16290 +       /* one less waiting */
16291 +       rq->nr_onhold--;
16292 +       p->state &= ~TASK_ONHOLD;
16293 +       enqueue_task(p, rq->expired);
16294 +       inc_nr_running(p, rq);
16295 +       vxm_unhold_task(p, rq);
16296 +
16297 +       if (p->static_prio < rq->best_expired_prio)
16298 +               rq->best_expired_prio = p->static_prio;
16299 +}
16300 +
16301 +unsigned long nr_onhold(void)
16302 +{
16303 +       unsigned long i, sum = 0;
16304 +
16305 +       for_each_online_cpu(i)
16306 +               sum += cpu_rq(i)->nr_onhold;
16307 +
16308 +       return sum;
16309 +}
16310 +
16311 +
16312 +
16313 +static inline
16314 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16315 +{
16316 +       return sched_pc->tokens;
16317 +}
16318 +
16319 +static inline
16320 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16321 +{
16322 +       sched_pc->tokens--;
16323 +}
16324 +
16325 +static inline
16326 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16327 +{
16328 +       struct vx_info *vxi = p->vx_info;
16329 +
16330 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16331 +               struct _vx_sched_pc *sched_pc =
16332 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16333 +               int tokens;
16334 +
16335 +               /* maybe we can simplify that to decrement
16336 +                  the token counter unconditional? */
16337 +
16338 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16339 +                       __vx_consume_token(sched_pc);
16340 +
16341 +               /* for tokens > 0, one token was consumed */
16342 +               if (tokens < 2)
16343 +                       slice = 0;
16344 +       }
16345 +       vxm_need_resched(p, slice, cpu);
16346 +       return (slice == 0);
16347 +}
16348 +
16349 +
16350 +#define vx_set_rq_time(rq, time) do {  \
16351 +       rq->norm_time = time;           \
16352 +} while (0)
16353 +
16354 +
16355 +static inline
16356 +void vx_try_unhold(struct rq *rq, int cpu)
16357 +{
16358 +       struct vx_info *vxi = NULL;
16359 +       struct list_head *l, *n;
16360 +       int maxidle = HZ;
16361 +       int minskip = 0;
16362 +
16363 +       /* nothing to do? what about pause? */
16364 +       if (list_empty(&rq->hold_queue))
16365 +               return;
16366 +
16367 +       list_for_each_safe(l, n, &rq->hold_queue) {
16368 +               int ret, delta_min[2];
16369 +               struct _vx_sched_pc *sched_pc;
16370 +               struct task_struct *p;
16371 +
16372 +               p = list_entry(l, struct task_struct, run_list);
16373 +               /* don't bother with same context */
16374 +               if (vxi == p->vx_info)
16375 +                       continue;
16376 +
16377 +               vxi = p->vx_info;
16378 +               /* ignore paused contexts */
16379 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16380 +                       continue;
16381 +
16382 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16383 +
16384 +               /* recalc tokens */
16385 +               vxm_sched_info(sched_pc, vxi, cpu);
16386 +               ret = vx_tokens_recalc(sched_pc,
16387 +                       &rq->norm_time, &rq->idle_time, delta_min);
16388 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16389 +
16390 +               if (ret > 0) {
16391 +                       /* we found a runable context */
16392 +                       vx_unhold_task(p, rq);
16393 +                       break;
16394 +               }
16395 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16396 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16397 +       }
16398 +       vx_set_rq_max_idle(rq, maxidle);
16399 +       vx_set_rq_min_skip(rq, minskip);
16400 +       vxm_rq_max_min(rq, cpu);
16401 +}
16402 +
16403 +
16404 +static inline
16405 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16406 +{
16407 +       struct vx_info *vxi = next->vx_info;
16408 +       struct _vx_sched_pc *sched_pc;
16409 +       int delta_min[2];
16410 +       int flags, ret;
16411 +
16412 +       if (!vxi)
16413 +               return 1;
16414 +
16415 +       flags = vxi->vx_flags;
16416 +
16417 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16418 +               goto put_on_hold;
16419 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16420 +               return 1;
16421 +
16422 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16423 +#ifdef CONFIG_SMP
16424 +       /* update scheduler params */
16425 +       if (cpu_isset(cpu, vxi->sched.update)) {
16426 +               vx_update_sched_param(&vxi->sched, sched_pc);
16427 +               vxm_update_sched(sched_pc, vxi, cpu);
16428 +               cpu_clear(cpu, vxi->sched.update);
16429 +       }
16430 +#endif
16431 +       vxm_sched_info(sched_pc, vxi, cpu);
16432 +       ret  = vx_tokens_recalc(sched_pc,
16433 +               &rq->norm_time, &rq->idle_time, delta_min);
16434 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16435 +
16436 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16437 +               return 1;
16438 +
16439 +       if (unlikely(ret < 0)) {
16440 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16441 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16442 +               vxm_rq_max_min(rq, cpu);
16443 +       put_on_hold:
16444 +               vx_hold_task(next, rq);
16445 +               return 0;
16446 +       }
16447 +       return 1;
16448 +}
16449 +
16450 +
16451 +#else /* CONFIG_VSERVER_HARDCPU */
16452 +
16453 +static inline
16454 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16455 +{
16456 +       return;
16457 +}
16458 +
16459 +static inline
16460 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16461 +{
16462 +       return;
16463 +}
16464 +
16465 +unsigned long nr_onhold(void)
16466 +{
16467 +       return 0;
16468 +}
16469 +
16470 +
16471 +static inline
16472 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16473 +{
16474 +       return (slice == 0);
16475 +}
16476 +
16477 +
16478 +#define vx_set_rq_time(rq, time)
16479 +
16480 +static inline
16481 +void vx_try_unhold(struct rq *rq, int cpu)
16482 +{
16483 +       return;
16484 +}
16485 +
16486 +static inline
16487 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16488 +{
16489 +       struct vx_info *vxi = next->vx_info;
16490 +       struct _vx_sched_pc *sched_pc;
16491 +       int delta_min[2];
16492 +       int ret;
16493 +
16494 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16495 +               return 1;
16496 +
16497 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16498 +       vxm_sched_info(sched_pc, vxi, cpu);
16499 +       ret  = vx_tokens_recalc(sched_pc,
16500 +               &rq->norm_time, &rq->idle_time, delta_min);
16501 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16502 +       return 1;
16503 +}
16504 +
16505 +#endif /* CONFIG_VSERVER_HARDCPU */
16506 +
16507 diff -NurpP --minimal linux-2.6.27.6/kernel/sched_mon.h linux-2.6.27.6-vs2.3.0.36/kernel/sched_mon.h
16508 --- linux-2.6.27.6/kernel/sched_mon.h   1970-01-01 01:00:00.000000000 +0100
16509 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sched_mon.h        2008-10-13 14:54:20.000000000 +0200
16510 @@ -0,0 +1,200 @@
16511 +
16512 +#include <linux/vserver/monitor.h>
16513 +
16514 +#ifdef  CONFIG_VSERVER_MONITOR
16515 +
16516 +#ifdef CONFIG_VSERVER_HARDCPU
16517 +#define HARDCPU(x) (x)
16518 +#else
16519 +#define HARDCPU(x) (0)
16520 +#endif
16521 +
16522 +#ifdef CONFIG_VSERVER_IDLETIME
16523 +#define IDLETIME(x) (x)
16524 +#else
16525 +#define IDLETIME(x) (0)
16526 +#endif
16527 +
16528 +struct _vx_mon_entry *vxm_advance(int cpu);
16529 +
16530 +
16531 +static inline
16532 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16533 +{
16534 +       entry->type = type;
16535 +       entry->xid = xid;
16536 +}
16537 +
16538 +static inline
16539 +void   __vxm_sync(int cpu)
16540 +{
16541 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16542 +
16543 +       __vxm_basic(entry, 0, VXM_SYNC);
16544 +       entry->ev.sec = xtime.tv_sec;
16545 +       entry->ev.nsec = xtime.tv_nsec;
16546 +}
16547 +
16548 +static inline
16549 +void   __vxm_task(struct task_struct *p, int type)
16550 +{
16551 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16552 +
16553 +       __vxm_basic(entry, p->xid, type);
16554 +       entry->ev.tsk.pid = p->pid;
16555 +       entry->ev.tsk.state = p->state;
16556 +}
16557 +
16558 +static inline
16559 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16560 +{
16561 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16562 +
16563 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16564 +       entry->sd.tokens = s->tokens;
16565 +       entry->sd.norm_time = s->norm_time;
16566 +       entry->sd.idle_time = s->idle_time;
16567 +}
16568 +
16569 +static inline
16570 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16571 +{
16572 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16573 +
16574 +       entry->type = VXM_RQINFO_1;
16575 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16576 +       entry->q1.running = q->nr_running;
16577 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16578 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16579 +       entry->q1.uintr = q->nr_uninterruptible;
16580 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16581 +}
16582 +
16583 +static inline
16584 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16585 +{
16586 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16587 +
16588 +       entry->type = VXM_RQINFO_2;
16589 +       entry->xid = (unsigned long)q & 0xffff;
16590 +       entry->q2.norm_time = q->norm_time;
16591 +       entry->q2.idle_time = q->idle_time;
16592 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16593 +}
16594 +
16595 +static inline
16596 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16597 +{
16598 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16599 +
16600 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16601 +       entry->ev.tokens = s->tokens;
16602 +}
16603 +
16604 +static inline
16605 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16606 +{
16607 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16608 +
16609 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16610 +       entry->u1.tokens_max = s->tokens_max;
16611 +       entry->u1.fill_rate = s->fill_rate[0];
16612 +       entry->u1.interval = s->interval[0];
16613 +}
16614 +
16615 +static inline
16616 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16617 +{
16618 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16619 +
16620 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16621 +       entry->u2.tokens_min = s->tokens_min;
16622 +       entry->u2.fill_rate = s->fill_rate[1];
16623 +       entry->u2.interval = s->interval[1];
16624 +}
16625 +
16626 +
16627 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16628 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16629 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16630 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16631 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16632 +
16633 +static inline
16634 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16635 +{
16636 +       __vxm_task(p, VXM_MIGRATE);
16637 +       __vxm_rqinfo1(rq, task_cpu(p));
16638 +       __vxm_rqinfo2(rq, task_cpu(p));
16639 +}
16640 +
16641 +static inline
16642 +void   vxm_idle_skip(struct rq *rq, int cpu)
16643 +{
16644 +       __vxm_rqinfo1(rq, cpu);
16645 +       __vxm_rqinfo2(rq, cpu);
16646 +}
16647 +
16648 +static inline
16649 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16650 +{
16651 +       if (slice)
16652 +               return;
16653 +
16654 +       __vxm_task(p, VXM_RESCHED);
16655 +}
16656 +
16657 +static inline
16658 +void   vxm_sync(unsigned long now, int cpu)
16659 +{
16660 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16661 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16662 +               return;
16663 +
16664 +       __vxm_sync(cpu);
16665 +}
16666 +
16667 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16668 +
16669 +static inline
16670 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16671 +       struct vx_info *vxi, int cpu)
16672 +{
16673 +       __vxm_sched(s, vxi, cpu);
16674 +       __vxm_rqinfo2(rq, cpu);
16675 +}
16676 +
16677 +static inline
16678 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16679 +{
16680 +       __vxm_sched(s, vxi, cpu);
16681 +       __vxm_update(s, vxi, cpu);
16682 +       __vxm_update1(s, vxi, cpu);
16683 +       __vxm_update2(s, vxi, cpu);
16684 +}
16685 +
16686 +static inline
16687 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16688 +{
16689 +       __vxm_rqinfo1(rq, cpu);
16690 +       __vxm_rqinfo2(rq, cpu);
16691 +}
16692 +
16693 +#else  /* CONFIG_VSERVER_MONITOR */
16694 +
16695 +#define        vxm_activate_task(t,q)          do { } while (0)
16696 +#define        vxm_activate_idle(t,q)          do { } while (0)
16697 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16698 +#define        vxm_hold_task(t,q)              do { } while (0)
16699 +#define        vxm_unhold_task(t,q)            do { } while (0)
16700 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16701 +#define        vxm_idle_skip(q,c)              do { } while (0)
16702 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16703 +#define        vxm_sync(s,c)                   do { } while (0)
16704 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16705 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16706 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16707 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16708 +
16709 +#endif /* CONFIG_VSERVER_MONITOR */
16710 +
16711 diff -NurpP --minimal linux-2.6.27.6/kernel/signal.c linux-2.6.27.6-vs2.3.0.36/kernel/signal.c
16712 --- linux-2.6.27.6/kernel/signal.c      2008-10-13 14:52:09.000000000 +0200
16713 +++ linux-2.6.27.6-vs2.3.0.36/kernel/signal.c   2008-11-20 15:05:42.000000000 +0100
16714 @@ -27,6 +27,8 @@
16715  #include <linux/freezer.h>
16716  #include <linux/pid_namespace.h>
16717  #include <linux/nsproxy.h>
16718 +#include <linux/vs_context.h>
16719 +#include <linux/vs_pid.h>
16720  
16721  #include <asm/param.h>
16722  #include <asm/uaccess.h>
16723 @@ -571,6 +573,14 @@ static int check_kill_permission(int sig
16724         if (!valid_signal(sig))
16725                 return -EINVAL;
16726  
16727 +       if ((info != SEND_SIG_NOINFO) &&
16728 +               (is_si_special(info) || !SI_FROMUSER(info)))
16729 +               goto skip;
16730 +
16731 +       vxdprintk(VXD_CBIT(misc, 7),
16732 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16733 +               sig, info, t, vx_task_xid(t), t->pid);
16734 +
16735         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16736                 return 0;
16737  
16738 @@ -595,6 +605,18 @@ static int check_kill_permission(int sig
16739                 }
16740         }
16741  
16742 +       error = -EPERM;
16743 +       if (t->pid == 1 && current->xid)
16744 +               return error;
16745 +
16746 +       error = -ESRCH;
16747 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16748 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16749 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16750 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16751 +               return error;
16752 +       }
16753 +skip:
16754         return security_task_kill(t, info, sig, 0);
16755  }
16756  
16757 @@ -1051,7 +1073,7 @@ int kill_pid_info(int sig, struct siginf
16758         rcu_read_lock();
16759  retry:
16760         p = pid_task(pid, PIDTYPE_PID);
16761 -       if (p) {
16762 +       if (p && vx_check(vx_task_xid(p), VS_WATCH | VS_IDENT)) {
16763                 error = group_send_sig_info(sig, info, p);
16764                 if (unlikely(error == -ESRCH))
16765                         /*
16766 @@ -1089,7 +1111,7 @@ int kill_pid_info_as_uid(int sig, struct
16767  
16768         read_lock(&tasklist_lock);
16769         p = pid_task(pid, PIDTYPE_PID);
16770 -       if (!p) {
16771 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16772                 ret = -ESRCH;
16773                 goto out_unlock;
16774         }
16775 @@ -1141,7 +1163,10 @@ static int kill_something_info(int sig, 
16776                 struct task_struct * p;
16777  
16778                 for_each_process(p) {
16779 -                       if (p->pid > 1 && !same_thread_group(p, current)) {
16780 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16781 +                               task_pid_vnr(p) > 1 &&
16782 +                               !same_thread_group(p, current) &&
16783 +                               !vx_current_initpid(p->pid)) {
16784                                 int err = group_send_sig_info(sig, info, p);
16785                                 ++count;
16786                                 if (err != -EPERM)
16787 @@ -1814,6 +1839,11 @@ relock:
16788                     !signal_group_exit(signal))
16789                         continue;
16790  
16791 +               /* virtual init is protected against user signals */
16792 +               if ((info->si_code == SI_USER) &&
16793 +                       vx_current_initpid(current->pid))
16794 +                       continue;
16795 +
16796                 if (sig_kernel_stop(signr)) {
16797                         /*
16798                          * The default action is to stop all threads in
16799 diff -NurpP --minimal linux-2.6.27.6/kernel/softirq.c linux-2.6.27.6-vs2.3.0.36/kernel/softirq.c
16800 --- linux-2.6.27.6/kernel/softirq.c     2008-10-13 14:52:09.000000000 +0200
16801 +++ linux-2.6.27.6-vs2.3.0.36/kernel/softirq.c  2008-10-13 14:54:20.000000000 +0200
16802 @@ -21,6 +21,7 @@
16803  #include <linux/rcupdate.h>
16804  #include <linux/smp.h>
16805  #include <linux/tick.h>
16806 +#include <linux/vs_context.h>
16807  
16808  #include <asm/irq.h>
16809  /*
16810 diff -NurpP --minimal linux-2.6.27.6/kernel/sys.c linux-2.6.27.6-vs2.3.0.36/kernel/sys.c
16811 --- linux-2.6.27.6/kernel/sys.c 2008-10-13 14:52:09.000000000 +0200
16812 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sys.c      2008-10-13 14:54:20.000000000 +0200
16813 @@ -38,6 +38,7 @@
16814  #include <linux/syscalls.h>
16815  #include <linux/kprobes.h>
16816  #include <linux/user_namespace.h>
16817 +#include <linux/vs_pid.h>
16818  
16819  #include <asm/uaccess.h>
16820  #include <asm/io.h>
16821 @@ -122,7 +123,10 @@ static int set_one_prio(struct task_stru
16822                 goto out;
16823         }
16824         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16825 -               error = -EACCES;
16826 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16827 +                       error = 0;
16828 +               else
16829 +                       error = -EACCES;
16830                 goto out;
16831         }
16832         no_nice = security_task_setnice(p, niceval);
16833 @@ -170,6 +174,8 @@ asmlinkage long sys_setpriority(int whic
16834                         else
16835                                 pgrp = task_pgrp(current);
16836                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16837 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16838 +                                       continue;
16839                                 error = set_one_prio(p, niceval, error);
16840                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16841                         break;
16842 @@ -230,6 +236,8 @@ asmlinkage long sys_getpriority(int whic
16843                         else
16844                                 pgrp = task_pgrp(current);
16845                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16846 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16847 +                                       continue;
16848                                 niceval = 20 - task_nice(p);
16849                                 if (niceval > retval)
16850                                         retval = niceval;
16851 @@ -339,6 +347,9 @@ void kernel_power_off(void)
16852         machine_power_off();
16853  }
16854  EXPORT_SYMBOL_GPL(kernel_power_off);
16855 +
16856 +long vs_reboot(unsigned int, void __user *);
16857 +
16858  /*
16859   * Reboot system call: for obvious reasons only root may call it,
16860   * and even root needs to set up some magic numbers in the registers
16861 @@ -369,6 +380,9 @@ asmlinkage long sys_reboot(int magic1, i
16862         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16863                 cmd = LINUX_REBOOT_CMD_HALT;
16864  
16865 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16866 +               return vs_reboot(cmd, arg);
16867 +
16868         lock_kernel();
16869         switch (cmd) {
16870         case LINUX_REBOOT_CMD_RESTART:
16871 @@ -1344,7 +1358,7 @@ asmlinkage long sys_sethostname(char __u
16872         int errno;
16873         char tmp[__NEW_UTS_LEN];
16874  
16875 -       if (!capable(CAP_SYS_ADMIN))
16876 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16877                 return -EPERM;
16878         if (len < 0 || len > __NEW_UTS_LEN)
16879                 return -EINVAL;
16880 @@ -1389,7 +1403,7 @@ asmlinkage long sys_setdomainname(char _
16881         int errno;
16882         char tmp[__NEW_UTS_LEN];
16883  
16884 -       if (!capable(CAP_SYS_ADMIN))
16885 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16886                 return -EPERM;
16887         if (len < 0 || len > __NEW_UTS_LEN)
16888                 return -EINVAL;
16889 @@ -1456,7 +1470,7 @@ asmlinkage long sys_setrlimit(unsigned i
16890                 return -EINVAL;
16891         old_rlim = current->signal->rlim + resource;
16892         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16893 -           !capable(CAP_SYS_RESOURCE))
16894 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16895                 return -EPERM;
16896         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16897                 return -EPERM;
16898 diff -NurpP --minimal linux-2.6.27.6/kernel/sysctl.c linux-2.6.27.6-vs2.3.0.36/kernel/sysctl.c
16899 --- linux-2.6.27.6/kernel/sysctl.c      2008-10-13 14:52:09.000000000 +0200
16900 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sysctl.c   2008-10-13 14:54:20.000000000 +0200
16901 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16902  #ifdef CONFIG_MODULES
16903  extern char modprobe_path[];
16904  #endif
16905 +extern char vshelper_path[];
16906  #ifdef CONFIG_CHR_DEV_SG
16907  extern int sg_big_buff;
16908  #endif
16909 @@ -500,6 +501,15 @@ static struct ctl_table kern_table[] = {
16910                 .strategy       = &sysctl_string,
16911         },
16912  #endif
16913 +       {
16914 +               .ctl_name       = KERN_VSHELPER,
16915 +               .procname       = "vshelper",
16916 +               .data           = &vshelper_path,
16917 +               .maxlen         = 256,
16918 +               .mode           = 0644,
16919 +               .proc_handler   = &proc_dostring,
16920 +               .strategy       = &sysctl_string,
16921 +       },
16922  #ifdef CONFIG_CHR_DEV_SG
16923         {
16924                 .ctl_name       = KERN_SG_BIG_BUFF,
16925 diff -NurpP --minimal linux-2.6.27.6/kernel/sysctl_check.c linux-2.6.27.6-vs2.3.0.36/kernel/sysctl_check.c
16926 --- linux-2.6.27.6/kernel/sysctl_check.c        2008-10-13 14:52:09.000000000 +0200
16927 +++ linux-2.6.27.6-vs2.3.0.36/kernel/sysctl_check.c     2008-10-13 14:54:20.000000000 +0200
16928 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16929  
16930         { KERN_PANIC,                   "panic" },
16931         { KERN_REALROOTDEV,             "real-root-dev" },
16932 +       { KERN_VSHELPER,                "vshelper", },
16933  
16934         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16935         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16936 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
16937         {}
16938  };
16939  
16940 +static struct trans_ctl_table trans_vserver_table[] = {
16941 +       { 1,    "debug_switch" },
16942 +       { 2,    "debug_xid" },
16943 +       { 3,    "debug_nid" },
16944 +       { 4,    "debug_tag" },
16945 +       { 5,    "debug_net" },
16946 +       { 6,    "debug_limit" },
16947 +       { 7,    "debug_cres" },
16948 +       { 8,    "debug_dlim" },
16949 +       { 9,    "debug_quota" },
16950 +       { 10,   "debug_cvirt" },
16951 +       { 11,   "debug_space" },
16952 +       { 12,   "debug_misc" },
16953 +       {}
16954 +};
16955 +
16956  static const struct trans_ctl_table trans_root_table[] = {
16957         { CTL_KERN,     "kernel",       trans_kern_table },
16958         { CTL_VM,       "vm",           trans_vm_table },
16959 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
16960         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16961         { CTL_PM,       "pm",           trans_pm_table },
16962         { CTL_FRV,      "frv",          trans_frv_table },
16963 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16964         {}
16965  };
16966  
16967 diff -NurpP --minimal linux-2.6.27.6/kernel/time.c linux-2.6.27.6-vs2.3.0.36/kernel/time.c
16968 --- linux-2.6.27.6/kernel/time.c        2008-07-13 23:51:29.000000000 +0200
16969 +++ linux-2.6.27.6-vs2.3.0.36/kernel/time.c     2008-10-13 14:54:20.000000000 +0200
16970 @@ -62,6 +62,7 @@ EXPORT_SYMBOL(sys_tz);
16971  asmlinkage long sys_time(time_t __user * tloc)
16972  {
16973         time_t i = get_seconds();
16974 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16975  
16976         if (tloc) {
16977                 if (put_user(i,tloc))
16978 @@ -91,7 +92,7 @@ asmlinkage long sys_stime(time_t __user 
16979         if (err)
16980                 return err;
16981  
16982 -       do_settimeofday(&tv);
16983 +       vx_settimeofday(&tv);
16984         return 0;
16985  }
16986  
16987 @@ -102,7 +103,7 @@ asmlinkage long sys_gettimeofday(struct 
16988  {
16989         if (likely(tv != NULL)) {
16990                 struct timeval ktv;
16991 -               do_gettimeofday(&ktv);
16992 +               vx_gettimeofday(&ktv);
16993                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16994                         return -EFAULT;
16995         }
16996 @@ -177,7 +178,7 @@ int do_sys_settimeofday(struct timespec 
16997                 /* SMP safe, again the code in arch/foo/time.c should
16998                  * globally block out interrupts when it runs.
16999                  */
17000 -               return do_settimeofday(tv);
17001 +               return vx_settimeofday(tv);
17002         }
17003         return 0;
17004  }
17005 @@ -309,7 +310,7 @@ void getnstimeofday(struct timespec *tv)
17006  {
17007         struct timeval x;
17008  
17009 -       do_gettimeofday(&x);
17010 +       vx_gettimeofday(&x);
17011         tv->tv_sec = x.tv_sec;
17012         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17013  }
17014 diff -NurpP --minimal linux-2.6.27.6/kernel/timer.c linux-2.6.27.6-vs2.3.0.36/kernel/timer.c
17015 --- linux-2.6.27.6/kernel/timer.c       2008-10-13 14:52:09.000000000 +0200
17016 +++ linux-2.6.27.6-vs2.3.0.36/kernel/timer.c    2008-10-13 14:54:20.000000000 +0200
17017 @@ -37,6 +37,10 @@
17018  #include <linux/delay.h>
17019  #include <linux/tick.h>
17020  #include <linux/kallsyms.h>
17021 +#include <linux/vs_base.h>
17022 +#include <linux/vs_cvirt.h>
17023 +#include <linux/vs_pid.h>
17024 +#include <linux/vserver/sched.h>
17025  
17026  #include <asm/uaccess.h>
17027  #include <asm/unistd.h>
17028 @@ -1081,12 +1085,6 @@ asmlinkage unsigned long sys_alarm(unsig
17029  
17030  #endif
17031  
17032 -#ifndef __alpha__
17033 -
17034 -/*
17035 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17036 - * should be moved into arch/i386 instead?
17037 - */
17038  
17039  /**
17040   * sys_getpid - return the thread group id of the current process
17041 @@ -1115,10 +1113,23 @@ asmlinkage long sys_getppid(void)
17042         rcu_read_lock();
17043         pid = task_tgid_vnr(current->real_parent);
17044         rcu_read_unlock();
17045 +       return vx_map_pid(pid);
17046 +}
17047  
17048 -       return pid;
17049 +#ifdef __alpha__
17050 +
17051 +/*
17052 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17053 + */
17054 +
17055 +asmlinkage long do_getxpid(long *ppid)
17056 +{
17057 +       *ppid = sys_getppid();
17058 +       return sys_getpid();
17059  }
17060  
17061 +#else /* _alpha_ */
17062 +
17063  asmlinkage long sys_getuid(void)
17064  {
17065         /* Only we change this so SMP safe */
17066 @@ -1289,6 +1300,8 @@ int do_sysinfo(struct sysinfo *info)
17067                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17068                         tp.tv_sec++;
17069                 }
17070 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17071 +                       vx_vsi_uptime(&tp, NULL);
17072                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17073  
17074                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17075 diff -NurpP --minimal linux-2.6.27.6/kernel/user.c linux-2.6.27.6-vs2.3.0.36/kernel/user.c
17076 --- linux-2.6.27.6/kernel/user.c        2008-07-13 23:51:29.000000000 +0200
17077 +++ linux-2.6.27.6-vs2.3.0.36/kernel/user.c     2008-10-13 14:54:20.000000000 +0200
17078 @@ -243,12 +243,15 @@ static struct kobj_type uids_ktype = {
17079  };
17080  
17081  /* create /sys/kernel/uids/<uid>/cpu_share file for this user */
17082 -static int uids_user_create(struct user_struct *up)
17083 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17084  {
17085         struct kobject *kobj = &up->kobj;
17086 -       int error;
17087 +       int error = 0;
17088  
17089         memset(kobj, 0, sizeof(struct kobject));
17090 +       if (ns != &init_user_ns)
17091 +               goto done;
17092 +
17093         kobj->kset = uids_kset;
17094         error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
17095         if (error) {
17096 @@ -272,7 +275,7 @@ int __init uids_sysfs_init(void)
17097         if (!uids_kset)
17098                 return -ENOMEM;
17099  
17100 -       return uids_user_create(&root_user);
17101 +       return uids_user_create(NULL, &root_user);
17102  }
17103  
17104  /* work function to remove sysfs directory for a user and free up
17105 @@ -302,9 +305,11 @@ static void remove_user_sysfs_dir(struct
17106         if (!remove_user)
17107                 goto done;
17108  
17109 -       kobject_uevent(&up->kobj, KOBJ_REMOVE);
17110 -       kobject_del(&up->kobj);
17111 -       kobject_put(&up->kobj);
17112 +       if (up->kobj.name) {
17113 +               kobject_uevent(&up->kobj, KOBJ_REMOVE);
17114 +               kobject_del(&up->kobj);
17115 +               kobject_put(&up->kobj);
17116 +       }
17117  
17118         sched_destroy_user(up);
17119         key_put(up->uid_keyring);
17120 @@ -332,7 +337,8 @@ static inline void free_user(struct user
17121  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
17122  
17123  int uids_sysfs_init(void) { return 0; }
17124 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17125 +static inline int uids_user_create(struct user_namespace *ns,
17126 +       struct user_struct *up) { return 0; }
17127  static inline void uids_mutex_lock(void) { }
17128  static inline void uids_mutex_unlock(void) { }
17129  
17130 @@ -409,7 +415,7 @@ struct user_struct *alloc_uid(struct use
17131                 if (sched_create_user(new) < 0)
17132                         goto out_free_user;
17133  
17134 -               if (uids_user_create(new))
17135 +               if (uids_user_create(ns, new))
17136                         goto out_destoy_sched;
17137  
17138                 /*
17139 diff -NurpP --minimal linux-2.6.27.6/kernel/user_namespace.c linux-2.6.27.6-vs2.3.0.36/kernel/user_namespace.c
17140 --- linux-2.6.27.6/kernel/user_namespace.c      2008-10-13 14:52:09.000000000 +0200
17141 +++ linux-2.6.27.6-vs2.3.0.36/kernel/user_namespace.c   2008-10-13 14:54:20.000000000 +0200
17142 @@ -9,6 +9,7 @@
17143  #include <linux/nsproxy.h>
17144  #include <linux/slab.h>
17145  #include <linux/user_namespace.h>
17146 +#include <linux/vserver/global.h>
17147  
17148  /*
17149   * Clone a new ns copying an original user ns, setting refcount to 1
17150 @@ -26,6 +27,7 @@ static struct user_namespace *clone_user
17151                 return ERR_PTR(-ENOMEM);
17152  
17153         kref_init(&ns->kref);
17154 +       atomic_inc(&vs_global_user_ns);
17155  
17156         for (n = 0; n < UIDHASH_SZ; ++n)
17157                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17158 @@ -71,6 +73,7 @@ void free_user_ns(struct kref *kref)
17159  
17160         ns = container_of(kref, struct user_namespace, kref);
17161         release_uids(ns);
17162 +       atomic_dec(&vs_global_user_ns);
17163         kfree(ns);
17164  }
17165  EXPORT_SYMBOL(free_user_ns);
17166 diff -NurpP --minimal linux-2.6.27.6/kernel/utsname.c linux-2.6.27.6-vs2.3.0.36/kernel/utsname.c
17167 --- linux-2.6.27.6/kernel/utsname.c     2008-10-13 14:52:09.000000000 +0200
17168 +++ linux-2.6.27.6-vs2.3.0.36/kernel/utsname.c  2008-10-13 14:54:20.000000000 +0200
17169 @@ -14,6 +14,7 @@
17170  #include <linux/utsname.h>
17171  #include <linux/err.h>
17172  #include <linux/slab.h>
17173 +#include <linux/vserver/global.h>
17174  
17175  /*
17176   * Clone a new ns copying an original utsname, setting refcount to 1
17177 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17178         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17179         up_read(&uts_sem);
17180         kref_init(&ns->kref);
17181 +       atomic_inc(&vs_global_uts_ns);
17182         return ns;
17183  }
17184  
17185 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17186         struct uts_namespace *ns;
17187  
17188         ns = container_of(kref, struct uts_namespace, kref);
17189 +       atomic_dec(&vs_global_uts_ns);
17190         kfree(ns);
17191  }
17192 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/cacct.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cacct.c
17193 --- linux-2.6.27.6/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
17194 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cacct.c    2008-10-13 14:54:20.000000000 +0200
17195 @@ -0,0 +1,42 @@
17196 +/*
17197 + *  linux/kernel/vserver/cacct.c
17198 + *
17199 + *  Virtual Server: Context Accounting
17200 + *
17201 + *  Copyright (C) 2006-2007 Herbert Pötzl
17202 + *
17203 + *  V0.01  added accounting stats
17204 + *
17205 + */
17206 +
17207 +#include <linux/types.h>
17208 +#include <linux/vs_context.h>
17209 +#include <linux/vserver/cacct_cmd.h>
17210 +#include <linux/vserver/cacct_int.h>
17211 +
17212 +#include <asm/errno.h>
17213 +#include <asm/uaccess.h>
17214 +
17215 +
17216 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17217 +{
17218 +       struct vcmd_sock_stat_v0 vc_data;
17219 +       int j, field;
17220 +
17221 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17222 +               return -EFAULT;
17223 +
17224 +       field = vc_data.field;
17225 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17226 +               return -EINVAL;
17227 +
17228 +       for (j = 0; j < 3; j++) {
17229 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17230 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17231 +       }
17232 +
17233 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17234 +               return -EFAULT;
17235 +       return 0;
17236 +}
17237 +
17238 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/cacct_init.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cacct_init.h
17239 --- linux-2.6.27.6/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
17240 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cacct_init.h       2008-10-13 14:54:20.000000000 +0200
17241 @@ -0,0 +1,25 @@
17242 +
17243 +
17244 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17245 +{
17246 +       int i, j;
17247 +
17248 +
17249 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17250 +               for (j = 0; j < 3; j++) {
17251 +                       atomic_set(&cacct->sock[i][j].count, 0);
17252 +                       atomic_set(&cacct->sock[i][j].total, 0);
17253 +               }
17254 +       }
17255 +       for (i = 0; i < 8; i++)
17256 +               atomic_set(&cacct->slab[i], 0);
17257 +       for (i = 0; i < 5; i++)
17258 +               for (j = 0; j < 4; j++)
17259 +                       atomic_set(&cacct->page[i][j], 0);
17260 +}
17261 +
17262 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17263 +{
17264 +       return;
17265 +}
17266 +
17267 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/cacct_proc.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cacct_proc.h
17268 --- linux-2.6.27.6/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
17269 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cacct_proc.h       2008-10-13 14:54:20.000000000 +0200
17270 @@ -0,0 +1,53 @@
17271 +#ifndef _VX_CACCT_PROC_H
17272 +#define _VX_CACCT_PROC_H
17273 +
17274 +#include <linux/vserver/cacct_int.h>
17275 +
17276 +
17277 +#define VX_SOCKA_TOP   \
17278 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17279 +
17280 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17281 +{
17282 +       int i, j, length = 0;
17283 +       static char *type[VXA_SOCK_SIZE] = {
17284 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17285 +       };
17286 +
17287 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17288 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17289 +               length += sprintf(buffer + length, "%s:", type[i]);
17290 +               for (j = 0; j < 3; j++) {
17291 +                       length += sprintf(buffer + length,
17292 +                               "\t%10lu/%-10lu",
17293 +                               vx_sock_count(cacct, i, j),
17294 +                               vx_sock_total(cacct, i, j));
17295 +               }
17296 +               buffer[length++] = '\n';
17297 +       }
17298 +
17299 +       length += sprintf(buffer + length, "\n");
17300 +       length += sprintf(buffer + length,
17301 +               "slab:\t %8u %8u %8u %8u\n",
17302 +               atomic_read(&cacct->slab[1]),
17303 +               atomic_read(&cacct->slab[4]),
17304 +               atomic_read(&cacct->slab[0]),
17305 +               atomic_read(&cacct->slab[2]));
17306 +
17307 +       length += sprintf(buffer + length, "\n");
17308 +       for (i = 0; i < 5; i++) {
17309 +               length += sprintf(buffer + length,
17310 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17311 +                       atomic_read(&cacct->page[i][0]),
17312 +                       atomic_read(&cacct->page[i][1]),
17313 +                       atomic_read(&cacct->page[i][2]),
17314 +                       atomic_read(&cacct->page[i][3]),
17315 +                       atomic_read(&cacct->page[i][4]),
17316 +                       atomic_read(&cacct->page[i][5]),
17317 +                       atomic_read(&cacct->page[i][6]),
17318 +                       atomic_read(&cacct->page[i][7]));
17319 +       }
17320 +       return length;
17321 +}
17322 +
17323 +#endif /* _VX_CACCT_PROC_H */
17324 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/context.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/context.c
17325 --- linux-2.6.27.6/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
17326 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/context.c  2008-10-31 03:56:55.000000000 +0100
17327 @@ -0,0 +1,1018 @@
17328 +/*
17329 + *  linux/kernel/vserver/context.c
17330 + *
17331 + *  Virtual Server: Context Support
17332 + *
17333 + *  Copyright (C) 2003-2007  Herbert Pötzl
17334 + *
17335 + *  V0.01  context helper
17336 + *  V0.02  vx_ctx_kill syscall command
17337 + *  V0.03  replaced context_info calls
17338 + *  V0.04  redesign of struct (de)alloc
17339 + *  V0.05  rlimit basic implementation
17340 + *  V0.06  task_xid and info commands
17341 + *  V0.07  context flags and caps
17342 + *  V0.08  switch to RCU based hash
17343 + *  V0.09  revert to non RCU for now
17344 + *  V0.10  and back to working RCU hash
17345 + *  V0.11  and back to locking again
17346 + *  V0.12  referenced context store
17347 + *  V0.13  separate per cpu data
17348 + *  V0.14  changed vcmds to vxi arg
17349 + *  V0.15  added context stat
17350 + *  V0.16  have __create claim() the vxi
17351 + *  V0.17  removed older and legacy stuff
17352 + *
17353 + */
17354 +
17355 +#include <linux/slab.h>
17356 +#include <linux/types.h>
17357 +#include <linux/security.h>
17358 +#include <linux/pid_namespace.h>
17359 +
17360 +#include <linux/vserver/context.h>
17361 +#include <linux/vserver/network.h>
17362 +#include <linux/vserver/debug.h>
17363 +#include <linux/vserver/limit.h>
17364 +#include <linux/vserver/limit_int.h>
17365 +#include <linux/vserver/space.h>
17366 +
17367 +#include <linux/vs_context.h>
17368 +#include <linux/vs_limit.h>
17369 +#include <linux/vs_pid.h>
17370 +#include <linux/vserver/context_cmd.h>
17371 +
17372 +#include "cvirt_init.h"
17373 +#include "cacct_init.h"
17374 +#include "limit_init.h"
17375 +#include "sched_init.h"
17376 +
17377 +
17378 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17379 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17380 +
17381 +
17382 +/*     now inactive context structures */
17383 +
17384 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17385 +
17386 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17387 +
17388 +
17389 +/*     __alloc_vx_info()
17390 +
17391 +       * allocate an initialized vx_info struct
17392 +       * doesn't make it visible (hash)                        */
17393 +
17394 +static struct vx_info *__alloc_vx_info(xid_t xid)
17395 +{
17396 +       struct vx_info *new = NULL;
17397 +       int cpu;
17398 +
17399 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17400 +
17401 +       /* would this benefit from a slab cache? */
17402 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17403 +       if (!new)
17404 +               return 0;
17405 +
17406 +       memset(new, 0, sizeof(struct vx_info));
17407 +#ifdef CONFIG_SMP
17408 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17409 +       if (!new->ptr_pc)
17410 +               goto error;
17411 +#endif
17412 +       new->vx_id = xid;
17413 +       INIT_HLIST_NODE(&new->vx_hlist);
17414 +       atomic_set(&new->vx_usecnt, 0);
17415 +       atomic_set(&new->vx_tasks, 0);
17416 +       new->vx_parent = NULL;
17417 +       new->vx_state = 0;
17418 +       init_waitqueue_head(&new->vx_wait);
17419 +
17420 +       /* prepare reaper */
17421 +       get_task_struct(init_pid_ns.child_reaper);
17422 +       new->vx_reaper = init_pid_ns.child_reaper;
17423 +       new->vx_badness_bias = 0;
17424 +
17425 +       /* rest of init goes here */
17426 +       vx_info_init_limit(&new->limit);
17427 +       vx_info_init_sched(&new->sched);
17428 +       vx_info_init_cvirt(&new->cvirt);
17429 +       vx_info_init_cacct(&new->cacct);
17430 +
17431 +       /* per cpu data structures */
17432 +       for_each_possible_cpu(cpu) {
17433 +               vx_info_init_sched_pc(
17434 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17435 +               vx_info_init_cvirt_pc(
17436 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17437 +       }
17438 +
17439 +       new->vx_flags = VXF_INIT_SET;
17440 +       cap_set_init_eff(new->vx_bcaps);
17441 +       new->vx_ccaps = 0;
17442 +       // new->vx_cap_bset = current->cap_bset;
17443 +
17444 +       new->reboot_cmd = 0;
17445 +       new->exit_code = 0;
17446 +
17447 +       vxdprintk(VXD_CBIT(xid, 0),
17448 +               "alloc_vx_info(%d) = %p", xid, new);
17449 +       vxh_alloc_vx_info(new);
17450 +       atomic_inc(&vx_global_ctotal);
17451 +       return new;
17452 +#ifdef CONFIG_SMP
17453 +error:
17454 +       kfree(new);
17455 +       return 0;
17456 +#endif
17457 +}
17458 +
17459 +/*     __dealloc_vx_info()
17460 +
17461 +       * final disposal of vx_info                             */
17462 +
17463 +static void __dealloc_vx_info(struct vx_info *vxi)
17464 +{
17465 +       struct vx_info_save vxis;
17466 +       int cpu;
17467 +
17468 +       vxdprintk(VXD_CBIT(xid, 0),
17469 +               "dealloc_vx_info(%p)", vxi);
17470 +       vxh_dealloc_vx_info(vxi);
17471 +
17472 +#ifdef CONFIG_VSERVER_WARN
17473 +       enter_vx_info(vxi, &vxis);
17474 +       vx_info_exit_limit(&vxi->limit);
17475 +       vx_info_exit_sched(&vxi->sched);
17476 +       vx_info_exit_cvirt(&vxi->cvirt);
17477 +       vx_info_exit_cacct(&vxi->cacct);
17478 +
17479 +       for_each_possible_cpu(cpu) {
17480 +               vx_info_exit_sched_pc(
17481 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17482 +               vx_info_exit_cvirt_pc(
17483 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17484 +       }
17485 +       leave_vx_info(&vxis);
17486 +#endif
17487 +
17488 +       vxi->vx_id = -1;
17489 +       vxi->vx_state |= VXS_RELEASED;
17490 +
17491 +#ifdef CONFIG_SMP
17492 +       free_percpu(vxi->ptr_pc);
17493 +#endif
17494 +       kfree(vxi);
17495 +       atomic_dec(&vx_global_ctotal);
17496 +}
17497 +
17498 +static void __shutdown_vx_info(struct vx_info *vxi)
17499 +{
17500 +       struct nsproxy *nsproxy;
17501 +       struct fs_struct *fs;
17502 +       int index;
17503 +
17504 +       might_sleep();
17505 +
17506 +       vxi->vx_state |= VXS_SHUTDOWN;
17507 +       vs_state_change(vxi, VSC_SHUTDOWN);
17508 +
17509 +       for (index = 0; index < VX_SPACES; index++) {
17510 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17511 +               if (nsproxy)
17512 +                       put_nsproxy(nsproxy);
17513 +
17514 +               fs = xchg(&vxi->vx_fs[index], NULL);
17515 +               if (fs)
17516 +                       put_fs_struct(fs);
17517 +       }
17518 +}
17519 +
17520 +/* exported stuff */
17521 +
17522 +void free_vx_info(struct vx_info *vxi)
17523 +{
17524 +       unsigned long flags;
17525 +       unsigned index;
17526 +
17527 +       /* check for reference counts first */
17528 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17529 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17530 +
17531 +       /* context must not be hashed */
17532 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17533 +
17534 +       /* context shutdown is mandatory */
17535 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17536 +
17537 +       /* nsproxy and fs check */
17538 +       for (index = 0; index < VX_SPACES; index++) {
17539 +               BUG_ON(vxi->vx_nsproxy[index]);
17540 +               BUG_ON(vxi->vx_fs[index]);
17541 +       }
17542 +
17543 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17544 +       hlist_del(&vxi->vx_hlist);
17545 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17546 +
17547 +       __dealloc_vx_info(vxi);
17548 +}
17549 +
17550 +
17551 +/*     hash table for vx_info hash */
17552 +
17553 +#define VX_HASH_SIZE   13
17554 +
17555 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17556 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17557 +
17558 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17559 +
17560 +
17561 +static inline unsigned int __hashval(xid_t xid)
17562 +{
17563 +       return (xid % VX_HASH_SIZE);
17564 +}
17565 +
17566 +
17567 +
17568 +/*     __hash_vx_info()
17569 +
17570 +       * add the vxi to the global hash table
17571 +       * requires the hash_lock to be held                     */
17572 +
17573 +static inline void __hash_vx_info(struct vx_info *vxi)
17574 +{
17575 +       struct hlist_head *head;
17576 +
17577 +       vxd_assert_lock(&vx_info_hash_lock);
17578 +       vxdprintk(VXD_CBIT(xid, 4),
17579 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17580 +       vxh_hash_vx_info(vxi);
17581 +
17582 +       /* context must not be hashed */
17583 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17584 +
17585 +       vxi->vx_state |= VXS_HASHED;
17586 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17587 +       hlist_add_head(&vxi->vx_hlist, head);
17588 +       atomic_inc(&vx_global_cactive);
17589 +}
17590 +
17591 +/*     __unhash_vx_info()
17592 +
17593 +       * remove the vxi from the global hash table
17594 +       * requires the hash_lock to be held                     */
17595 +
17596 +static inline void __unhash_vx_info(struct vx_info *vxi)
17597 +{
17598 +       unsigned long flags;
17599 +
17600 +       vxd_assert_lock(&vx_info_hash_lock);
17601 +       vxdprintk(VXD_CBIT(xid, 4),
17602 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17603 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17604 +       vxh_unhash_vx_info(vxi);
17605 +
17606 +       /* context must be hashed */
17607 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17608 +       /* but without tasks */
17609 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17610 +
17611 +       vxi->vx_state &= ~VXS_HASHED;
17612 +       hlist_del_init(&vxi->vx_hlist);
17613 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17614 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17615 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17616 +       atomic_dec(&vx_global_cactive);
17617 +}
17618 +
17619 +
17620 +/*     __lookup_vx_info()
17621 +
17622 +       * requires the hash_lock to be held
17623 +       * doesn't increment the vx_refcnt                       */
17624 +
17625 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17626 +{
17627 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17628 +       struct hlist_node *pos;
17629 +       struct vx_info *vxi;
17630 +
17631 +       vxd_assert_lock(&vx_info_hash_lock);
17632 +       hlist_for_each(pos, head) {
17633 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17634 +
17635 +               if (vxi->vx_id == xid)
17636 +                       goto found;
17637 +       }
17638 +       vxi = NULL;
17639 +found:
17640 +       vxdprintk(VXD_CBIT(xid, 0),
17641 +               "__lookup_vx_info(#%u): %p[#%u]",
17642 +               xid, vxi, vxi ? vxi->vx_id : 0);
17643 +       vxh_lookup_vx_info(vxi, xid);
17644 +       return vxi;
17645 +}
17646 +
17647 +
17648 +/*     __create_vx_info()
17649 +
17650 +       * create the requested context
17651 +       * get(), claim() and hash it                            */
17652 +
17653 +static struct vx_info *__create_vx_info(int id)
17654 +{
17655 +       struct vx_info *new, *vxi = NULL;
17656 +
17657 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17658 +
17659 +       if (!(new = __alloc_vx_info(id)))
17660 +               return ERR_PTR(-ENOMEM);
17661 +
17662 +       /* required to make dynamic xids unique */
17663 +       spin_lock(&vx_info_hash_lock);
17664 +
17665 +       /* static context requested */
17666 +       if ((vxi = __lookup_vx_info(id))) {
17667 +               vxdprintk(VXD_CBIT(xid, 0),
17668 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17669 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17670 +                       vxi = ERR_PTR(-EBUSY);
17671 +               else
17672 +                       vxi = ERR_PTR(-EEXIST);
17673 +               goto out_unlock;
17674 +       }
17675 +       /* new context */
17676 +       vxdprintk(VXD_CBIT(xid, 0),
17677 +               "create_vx_info(%d) = %p (new)", id, new);
17678 +       claim_vx_info(new, NULL);
17679 +       __hash_vx_info(get_vx_info(new));
17680 +       vxi = new, new = NULL;
17681 +
17682 +out_unlock:
17683 +       spin_unlock(&vx_info_hash_lock);
17684 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17685 +       if (new)
17686 +               __dealloc_vx_info(new);
17687 +       return vxi;
17688 +}
17689 +
17690 +
17691 +/*     exported stuff                                          */
17692 +
17693 +
17694 +void unhash_vx_info(struct vx_info *vxi)
17695 +{
17696 +       __shutdown_vx_info(vxi);
17697 +       spin_lock(&vx_info_hash_lock);
17698 +       __unhash_vx_info(vxi);
17699 +       spin_unlock(&vx_info_hash_lock);
17700 +       __wakeup_vx_info(vxi);
17701 +}
17702 +
17703 +
17704 +/*     lookup_vx_info()
17705 +
17706 +       * search for a vx_info and get() it
17707 +       * negative id means current                             */
17708 +
17709 +struct vx_info *lookup_vx_info(int id)
17710 +{
17711 +       struct vx_info *vxi = NULL;
17712 +
17713 +       if (id < 0) {
17714 +               vxi = get_vx_info(current->vx_info);
17715 +       } else if (id > 1) {
17716 +               spin_lock(&vx_info_hash_lock);
17717 +               vxi = get_vx_info(__lookup_vx_info(id));
17718 +               spin_unlock(&vx_info_hash_lock);
17719 +       }
17720 +       return vxi;
17721 +}
17722 +
17723 +/*     xid_is_hashed()
17724 +
17725 +       * verify that xid is still hashed                       */
17726 +
17727 +int xid_is_hashed(xid_t xid)
17728 +{
17729 +       int hashed;
17730 +
17731 +       spin_lock(&vx_info_hash_lock);
17732 +       hashed = (__lookup_vx_info(xid) != NULL);
17733 +       spin_unlock(&vx_info_hash_lock);
17734 +       return hashed;
17735 +}
17736 +
17737 +#ifdef CONFIG_PROC_FS
17738 +
17739 +/*     get_xid_list()
17740 +
17741 +       * get a subset of hashed xids for proc
17742 +       * assumes size is at least one                          */
17743 +
17744 +int get_xid_list(int index, unsigned int *xids, int size)
17745 +{
17746 +       int hindex, nr_xids = 0;
17747 +
17748 +       /* only show current and children */
17749 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17750 +               if (index > 0)
17751 +                       return 0;
17752 +               xids[nr_xids] = vx_current_xid();
17753 +               return 1;
17754 +       }
17755 +
17756 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17757 +               struct hlist_head *head = &vx_info_hash[hindex];
17758 +               struct hlist_node *pos;
17759 +
17760 +               spin_lock(&vx_info_hash_lock);
17761 +               hlist_for_each(pos, head) {
17762 +                       struct vx_info *vxi;
17763 +
17764 +                       if (--index > 0)
17765 +                               continue;
17766 +
17767 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17768 +                       xids[nr_xids] = vxi->vx_id;
17769 +                       if (++nr_xids >= size) {
17770 +                               spin_unlock(&vx_info_hash_lock);
17771 +                               goto out;
17772 +                       }
17773 +               }
17774 +               /* keep the lock time short */
17775 +               spin_unlock(&vx_info_hash_lock);
17776 +       }
17777 +out:
17778 +       return nr_xids;
17779 +}
17780 +#endif
17781 +
17782 +#ifdef CONFIG_VSERVER_DEBUG
17783 +
17784 +void   dump_vx_info_inactive(int level)
17785 +{
17786 +       struct hlist_node *entry, *next;
17787 +
17788 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17789 +               struct vx_info *vxi =
17790 +                       list_entry(entry, struct vx_info, vx_hlist);
17791 +
17792 +               dump_vx_info(vxi, level);
17793 +       }
17794 +}
17795 +
17796 +#endif
17797 +
17798 +#if 0
17799 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17800 +{
17801 +       struct user_struct *new_user, *old_user;
17802 +
17803 +       if (!p || !vxi)
17804 +               BUG();
17805 +
17806 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17807 +               return -EACCES;
17808 +
17809 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17810 +       if (!new_user)
17811 +               return -ENOMEM;
17812 +
17813 +       old_user = p->user;
17814 +       if (new_user != old_user) {
17815 +               atomic_inc(&new_user->processes);
17816 +               atomic_dec(&old_user->processes);
17817 +               p->user = new_user;
17818 +       }
17819 +       free_uid(old_user);
17820 +       return 0;
17821 +}
17822 +#endif
17823 +
17824 +#if 0
17825 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17826 +{
17827 +       // p->cap_effective &= vxi->vx_cap_bset;
17828 +       p->cap_effective =
17829 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17830 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17831 +       p->cap_inheritable =
17832 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17833 +       // p->cap_permitted &= vxi->vx_cap_bset;
17834 +       p->cap_permitted =
17835 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17836 +}
17837 +#endif
17838 +
17839 +
17840 +#include <linux/file.h>
17841 +#include <linux/fdtable.h>
17842 +
17843 +static int vx_openfd_task(struct task_struct *tsk)
17844 +{
17845 +       struct files_struct *files = tsk->files;
17846 +       struct fdtable *fdt;
17847 +       const unsigned long *bptr;
17848 +       int count, total;
17849 +
17850 +       /* no rcu_read_lock() because of spin_lock() */
17851 +       spin_lock(&files->file_lock);
17852 +       fdt = files_fdtable(files);
17853 +       bptr = fdt->open_fds->fds_bits;
17854 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17855 +       for (total = 0; count > 0; count--) {
17856 +               if (*bptr)
17857 +                       total += hweight_long(*bptr);
17858 +               bptr++;
17859 +       }
17860 +       spin_unlock(&files->file_lock);
17861 +       return total;
17862 +}
17863 +
17864 +
17865 +/*     for *space compatibility */
17866 +
17867 +asmlinkage long sys_unshare(unsigned long);
17868 +
17869 +/*
17870 + *     migrate task to new context
17871 + *     gets vxi, puts old_vxi on change
17872 + *     optionally unshares namespaces (hack)
17873 + */
17874 +
17875 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17876 +{
17877 +       struct vx_info *old_vxi;
17878 +       int ret = 0;
17879 +
17880 +       if (!p || !vxi)
17881 +               BUG();
17882 +
17883 +       vxdprintk(VXD_CBIT(xid, 5),
17884 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17885 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17886 +
17887 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17888 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17889 +               return -EACCES;
17890 +
17891 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17892 +               return -EFAULT;
17893 +
17894 +       old_vxi = task_get_vx_info(p);
17895 +       if (old_vxi == vxi)
17896 +               goto out;
17897 +
17898 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17899 +       {
17900 +               int openfd;
17901 +
17902 +               task_lock(p);
17903 +               openfd = vx_openfd_task(p);
17904 +
17905 +               if (old_vxi) {
17906 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17907 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17908 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17909 +                       /* FIXME: what about the struct files here? */
17910 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17911 +                       /* account for the executable */
17912 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17913 +               }
17914 +               atomic_inc(&vxi->cvirt.nr_threads);
17915 +               atomic_inc(&vxi->cvirt.nr_running);
17916 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17917 +               /* FIXME: what about the struct files here? */
17918 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17919 +               /* account for the executable */
17920 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17921 +
17922 +               if (old_vxi) {
17923 +                       release_vx_info(old_vxi, p);
17924 +                       clr_vx_info(&p->vx_info);
17925 +               }
17926 +               claim_vx_info(vxi, p);
17927 +               set_vx_info(&p->vx_info, vxi);
17928 +               p->xid = vxi->vx_id;
17929 +
17930 +               vxdprintk(VXD_CBIT(xid, 5),
17931 +                       "moved task %p into vxi:%p[#%d]",
17932 +                       p, vxi, vxi->vx_id);
17933 +
17934 +               // vx_mask_cap_bset(vxi, p);
17935 +               task_unlock(p);
17936 +
17937 +               /* hack for *spaces to provide compatibility */
17938 +               if (unshare) {
17939 +                       struct nsproxy *old_nsp, *new_nsp;
17940 +
17941 +                       ret = unshare_nsproxy_namespaces(
17942 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17943 +                               &new_nsp, NULL);
17944 +                       if (ret)
17945 +                               goto out;
17946 +
17947 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17948 +                       vx_set_space(vxi,
17949 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17950 +                       put_nsproxy(old_nsp);
17951 +               }
17952 +       }
17953 +out:
17954 +       put_vx_info(old_vxi);
17955 +       return ret;
17956 +}
17957 +
17958 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17959 +{
17960 +       struct task_struct *old_reaper;
17961 +
17962 +       if (!vxi)
17963 +               return -EINVAL;
17964 +
17965 +       vxdprintk(VXD_CBIT(xid, 6),
17966 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17967 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17968 +
17969 +       old_reaper = vxi->vx_reaper;
17970 +       if (old_reaper == p)
17971 +               return 0;
17972 +
17973 +       /* set new child reaper */
17974 +       get_task_struct(p);
17975 +       vxi->vx_reaper = p;
17976 +       put_task_struct(old_reaper);
17977 +       return 0;
17978 +}
17979 +
17980 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17981 +{
17982 +       if (!vxi)
17983 +               return -EINVAL;
17984 +
17985 +       vxdprintk(VXD_CBIT(xid, 6),
17986 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17987 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17988 +
17989 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17990 +       vxi->vx_initpid = p->tgid;
17991 +       return 0;
17992 +}
17993 +
17994 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17995 +{
17996 +       vxdprintk(VXD_CBIT(xid, 6),
17997 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17998 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17999 +
18000 +       vxi->exit_code = code;
18001 +       vxi->vx_initpid = 0;
18002 +}
18003 +
18004 +
18005 +void vx_set_persistent(struct vx_info *vxi)
18006 +{
18007 +       vxdprintk(VXD_CBIT(xid, 6),
18008 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18009 +
18010 +       get_vx_info(vxi);
18011 +       claim_vx_info(vxi, NULL);
18012 +}
18013 +
18014 +void vx_clear_persistent(struct vx_info *vxi)
18015 +{
18016 +       vxdprintk(VXD_CBIT(xid, 6),
18017 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18018 +
18019 +       release_vx_info(vxi, NULL);
18020 +       put_vx_info(vxi);
18021 +}
18022 +
18023 +void vx_update_persistent(struct vx_info *vxi)
18024 +{
18025 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18026 +               vx_set_persistent(vxi);
18027 +       else
18028 +               vx_clear_persistent(vxi);
18029 +}
18030 +
18031 +
18032 +/*     task must be current or locked          */
18033 +
18034 +void   exit_vx_info(struct task_struct *p, int code)
18035 +{
18036 +       struct vx_info *vxi = p->vx_info;
18037 +
18038 +       if (vxi) {
18039 +               atomic_dec(&vxi->cvirt.nr_threads);
18040 +               vx_nproc_dec(p);
18041 +
18042 +               vxi->exit_code = code;
18043 +               release_vx_info(vxi, p);
18044 +       }
18045 +}
18046 +
18047 +void   exit_vx_info_early(struct task_struct *p, int code)
18048 +{
18049 +       struct vx_info *vxi = p->vx_info;
18050 +
18051 +       if (vxi) {
18052 +               if (vxi->vx_initpid == p->tgid)
18053 +                       vx_exit_init(vxi, p, code);
18054 +               if (vxi->vx_reaper == p)
18055 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18056 +       }
18057 +}
18058 +
18059 +
18060 +/* vserver syscall commands below here */
18061 +
18062 +/* taks xid and vx_info functions */
18063 +
18064 +#include <asm/uaccess.h>
18065 +
18066 +
18067 +int vc_task_xid(uint32_t id)
18068 +{
18069 +       xid_t xid;
18070 +
18071 +       if (id) {
18072 +               struct task_struct *tsk;
18073 +
18074 +               read_lock(&tasklist_lock);
18075 +               tsk = find_task_by_real_pid(id);
18076 +               xid = (tsk) ? tsk->xid : -ESRCH;
18077 +               read_unlock(&tasklist_lock);
18078 +       } else
18079 +               xid = vx_current_xid();
18080 +       return xid;
18081 +}
18082 +
18083 +
18084 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18085 +{
18086 +       struct vcmd_vx_info_v0 vc_data;
18087 +
18088 +       vc_data.xid = vxi->vx_id;
18089 +       vc_data.initpid = vxi->vx_initpid;
18090 +
18091 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18092 +               return -EFAULT;
18093 +       return 0;
18094 +}
18095 +
18096 +
18097 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18098 +{
18099 +       struct vcmd_ctx_stat_v0 vc_data;
18100 +
18101 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18102 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18103 +
18104 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18105 +               return -EFAULT;
18106 +       return 0;
18107 +}
18108 +
18109 +
18110 +/* context functions */
18111 +
18112 +int vc_ctx_create(uint32_t xid, void __user *data)
18113 +{
18114 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18115 +       struct vx_info *new_vxi;
18116 +       int ret;
18117 +
18118 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18119 +               return -EFAULT;
18120 +
18121 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18122 +               return -EINVAL;
18123 +
18124 +       new_vxi = __create_vx_info(xid);
18125 +       if (IS_ERR(new_vxi))
18126 +               return PTR_ERR(new_vxi);
18127 +
18128 +       /* initial flags */
18129 +       new_vxi->vx_flags = vc_data.flagword;
18130 +
18131 +       ret = -ENOEXEC;
18132 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18133 +               goto out;
18134 +
18135 +       ret = vx_migrate_task(current, new_vxi, (!data));
18136 +       if (ret)
18137 +               goto out;
18138 +
18139 +       /* return context id on success */
18140 +       ret = new_vxi->vx_id;
18141 +
18142 +       /* get a reference for persistent contexts */
18143 +       if ((vc_data.flagword & VXF_PERSISTENT))
18144 +               vx_set_persistent(new_vxi);
18145 +out:
18146 +       release_vx_info(new_vxi, NULL);
18147 +       put_vx_info(new_vxi);
18148 +       return ret;
18149 +}
18150 +
18151 +
18152 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18153 +{
18154 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18155 +       int ret;
18156 +
18157 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18158 +               return -EFAULT;
18159 +
18160 +       ret = vx_migrate_task(current, vxi, 0);
18161 +       if (ret)
18162 +               return ret;
18163 +       if (vc_data.flagword & VXM_SET_INIT)
18164 +               ret = vx_set_init(vxi, current);
18165 +       if (ret)
18166 +               return ret;
18167 +       if (vc_data.flagword & VXM_SET_REAPER)
18168 +               ret = vx_set_reaper(vxi, current);
18169 +       return ret;
18170 +}
18171 +
18172 +
18173 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18174 +{
18175 +       struct vcmd_ctx_flags_v0 vc_data;
18176 +
18177 +       vc_data.flagword = vxi->vx_flags;
18178 +
18179 +       /* special STATE flag handling */
18180 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18181 +
18182 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18183 +               return -EFAULT;
18184 +       return 0;
18185 +}
18186 +
18187 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18188 +{
18189 +       struct vcmd_ctx_flags_v0 vc_data;
18190 +       uint64_t mask, trigger;
18191 +
18192 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18193 +               return -EFAULT;
18194 +
18195 +       /* special STATE flag handling */
18196 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18197 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18198 +
18199 +       if (vxi == current->vx_info) {
18200 +               /* if (trigger & VXF_STATE_SETUP)
18201 +                       vx_mask_cap_bset(vxi, current); */
18202 +               if (trigger & VXF_STATE_INIT) {
18203 +                       int ret;
18204 +
18205 +                       ret = vx_set_init(vxi, current);
18206 +                       if (ret)
18207 +                               return ret;
18208 +                       ret = vx_set_reaper(vxi, current);
18209 +                       if (ret)
18210 +                               return ret;
18211 +               }
18212 +       }
18213 +
18214 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18215 +               vc_data.flagword, mask);
18216 +       if (trigger & VXF_PERSISTENT)
18217 +               vx_update_persistent(vxi);
18218 +
18219 +       return 0;
18220 +}
18221 +
18222 +
18223 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18224 +{
18225 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18226 +
18227 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18228 +       return v;
18229 +}
18230 +
18231 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18232 +{
18233 +       kernel_cap_t c = __cap_empty_set;
18234 +
18235 +       c.cap[0] = v & 0xFFFFFFFF;
18236 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18237 +
18238 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18239 +       return c;
18240 +}
18241 +
18242 +
18243 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18244 +{
18245 +       if (bcaps)
18246 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18247 +       if (ccaps)
18248 +               *ccaps = vxi->vx_ccaps;
18249 +
18250 +       return 0;
18251 +}
18252 +
18253 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18254 +{
18255 +       struct vcmd_ctx_caps_v1 vc_data;
18256 +       int ret;
18257 +
18258 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18259 +       if (ret)
18260 +               return ret;
18261 +       vc_data.cmask = ~0ULL;
18262 +
18263 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18264 +               return -EFAULT;
18265 +       return 0;
18266 +}
18267 +
18268 +static int do_set_caps(struct vx_info *vxi,
18269 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18270 +{
18271 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18272 +
18273 +#if 0
18274 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18275 +               bcaps, bmask, ccaps, cmask);
18276 +#endif
18277 +       vxi->vx_bcaps = cap_t_from_caps(
18278 +               vs_mask_flags(bcold, bcaps, bmask));
18279 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18280 +
18281 +       return 0;
18282 +}
18283 +
18284 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18285 +{
18286 +       struct vcmd_ctx_caps_v1 vc_data;
18287 +
18288 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18289 +               return -EFAULT;
18290 +
18291 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18292 +}
18293 +
18294 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18295 +{
18296 +       struct vcmd_bcaps vc_data;
18297 +       int ret;
18298 +
18299 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18300 +       if (ret)
18301 +               return ret;
18302 +       vc_data.bmask = ~0ULL;
18303 +
18304 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18305 +               return -EFAULT;
18306 +       return 0;
18307 +}
18308 +
18309 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18310 +{
18311 +       struct vcmd_bcaps vc_data;
18312 +
18313 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18314 +               return -EFAULT;
18315 +
18316 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18317 +}
18318 +
18319 +
18320 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18321 +{
18322 +       struct vcmd_badness_v0 vc_data;
18323 +
18324 +       vc_data.bias = vxi->vx_badness_bias;
18325 +
18326 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18327 +               return -EFAULT;
18328 +       return 0;
18329 +}
18330 +
18331 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18332 +{
18333 +       struct vcmd_badness_v0 vc_data;
18334 +
18335 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18336 +               return -EFAULT;
18337 +
18338 +       vxi->vx_badness_bias = vc_data.bias;
18339 +       return 0;
18340 +}
18341 +
18342 +#include <linux/module.h>
18343 +
18344 +EXPORT_SYMBOL_GPL(free_vx_info);
18345 +
18346 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/cvirt.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cvirt.c
18347 --- linux-2.6.27.6/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
18348 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cvirt.c    2008-10-31 03:49:36.000000000 +0100
18349 @@ -0,0 +1,300 @@
18350 +/*
18351 + *  linux/kernel/vserver/cvirt.c
18352 + *
18353 + *  Virtual Server: Context Virtualization
18354 + *
18355 + *  Copyright (C) 2004-2007  Herbert Pötzl
18356 + *
18357 + *  V0.01  broken out from limit.c
18358 + *  V0.02  added utsname stuff
18359 + *  V0.03  changed vcmds to vxi arg
18360 + *
18361 + */
18362 +
18363 +#include <linux/types.h>
18364 +#include <linux/utsname.h>
18365 +#include <linux/vs_cvirt.h>
18366 +#include <linux/vserver/switch.h>
18367 +#include <linux/vserver/cvirt_cmd.h>
18368 +
18369 +#include <asm/uaccess.h>
18370 +
18371 +
18372 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18373 +{
18374 +       struct vx_info *vxi = current->vx_info;
18375 +
18376 +       set_normalized_timespec(uptime,
18377 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18378 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18379 +       if (!idle)
18380 +               return;
18381 +       set_normalized_timespec(idle,
18382 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18383 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18384 +       return;
18385 +}
18386 +
18387 +uint64_t vx_idle_jiffies(void)
18388 +{
18389 +       return init_task.utime + init_task.stime;
18390 +}
18391 +
18392 +
18393 +
18394 +static inline uint32_t __update_loadavg(uint32_t load,
18395 +       int wsize, int delta, int n)
18396 +{
18397 +       unsigned long long calc, prev;
18398 +
18399 +       /* just set it to n */
18400 +       if (unlikely(delta >= wsize))
18401 +               return (n << FSHIFT);
18402 +
18403 +       calc = delta * n;
18404 +       calc <<= FSHIFT;
18405 +       prev = (wsize - delta);
18406 +       prev *= load;
18407 +       calc += prev;
18408 +       do_div(calc, wsize);
18409 +       return calc;
18410 +}
18411 +
18412 +
18413 +void vx_update_load(struct vx_info *vxi)
18414 +{
18415 +       uint32_t now, last, delta;
18416 +       unsigned int nr_running, nr_uninterruptible;
18417 +       unsigned int total;
18418 +       unsigned long flags;
18419 +
18420 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18421 +
18422 +       now = jiffies;
18423 +       last = vxi->cvirt.load_last;
18424 +       delta = now - last;
18425 +
18426 +       if (delta < 5*HZ)
18427 +               goto out;
18428 +
18429 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18430 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18431 +       total = nr_running + nr_uninterruptible;
18432 +
18433 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18434 +               60*HZ, delta, total);
18435 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18436 +               5*60*HZ, delta, total);
18437 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18438 +               15*60*HZ, delta, total);
18439 +
18440 +       vxi->cvirt.load_last = now;
18441 +out:
18442 +       atomic_inc(&vxi->cvirt.load_updates);
18443 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18444 +}
18445 +
18446 +
18447 +/*
18448 + * Commands to do_syslog:
18449 + *
18450 + *      0 -- Close the log.  Currently a NOP.
18451 + *      1 -- Open the log. Currently a NOP.
18452 + *      2 -- Read from the log.
18453 + *      3 -- Read all messages remaining in the ring buffer.
18454 + *      4 -- Read and clear all messages remaining in the ring buffer
18455 + *      5 -- Clear ring buffer.
18456 + *      6 -- Disable printk's to console
18457 + *      7 -- Enable printk's to console
18458 + *      8 -- Set level of messages printed to console
18459 + *      9 -- Return number of unread characters in the log buffer
18460 + *     10 -- Return size of the log buffer
18461 + */
18462 +int vx_do_syslog(int type, char __user *buf, int len)
18463 +{
18464 +       int error = 0;
18465 +       int do_clear = 0;
18466 +       struct vx_info *vxi = current->vx_info;
18467 +       struct _vx_syslog *log;
18468 +
18469 +       if (!vxi)
18470 +               return -EINVAL;
18471 +       log = &vxi->cvirt.syslog;
18472 +
18473 +       switch (type) {
18474 +       case 0:         /* Close log */
18475 +       case 1:         /* Open log */
18476 +               break;
18477 +       case 2:         /* Read from log */
18478 +               error = wait_event_interruptible(log->log_wait,
18479 +                       (log->log_start - log->log_end));
18480 +               if (error)
18481 +                       break;
18482 +               spin_lock_irq(&log->logbuf_lock);
18483 +               spin_unlock_irq(&log->logbuf_lock);
18484 +               break;
18485 +       case 4:         /* Read/clear last kernel messages */
18486 +               do_clear = 1;
18487 +               /* fall through */
18488 +       case 3:         /* Read last kernel messages */
18489 +               return 0;
18490 +
18491 +       case 5:         /* Clear ring buffer */
18492 +               return 0;
18493 +
18494 +       case 6:         /* Disable logging to console */
18495 +       case 7:         /* Enable logging to console */
18496 +       case 8:         /* Set level of messages printed to console */
18497 +               break;
18498 +
18499 +       case 9:         /* Number of chars in the log buffer */
18500 +               return 0;
18501 +       case 10:        /* Size of the log buffer */
18502 +               return 0;
18503 +       default:
18504 +               error = -EINVAL;
18505 +               break;
18506 +       }
18507 +       return error;
18508 +}
18509 +
18510 +
18511 +/* virtual host info names */
18512 +
18513 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18514 +{
18515 +       struct nsproxy *nsproxy;
18516 +       struct uts_namespace *uts;
18517 +
18518 +       if (id == VHIN_CONTEXT)
18519 +               return vxi->vx_name;
18520 +
18521 +       nsproxy = vxi->vx_nsproxy[0];
18522 +       if (!nsproxy)
18523 +               return NULL;
18524 +
18525 +       uts = nsproxy->uts_ns;
18526 +       if (!uts)
18527 +               return NULL;
18528 +
18529 +       switch (id) {
18530 +       case VHIN_SYSNAME:
18531 +               return uts->name.sysname;
18532 +       case VHIN_NODENAME:
18533 +               return uts->name.nodename;
18534 +       case VHIN_RELEASE:
18535 +               return uts->name.release;
18536 +       case VHIN_VERSION:
18537 +               return uts->name.version;
18538 +       case VHIN_MACHINE:
18539 +               return uts->name.machine;
18540 +       case VHIN_DOMAINNAME:
18541 +               return uts->name.domainname;
18542 +       default:
18543 +               return NULL;
18544 +       }
18545 +       return NULL;
18546 +}
18547 +
18548 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18549 +{
18550 +       struct vcmd_vhi_name_v0 vc_data;
18551 +       char *name;
18552 +
18553 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18554 +               return -EFAULT;
18555 +
18556 +       name = vx_vhi_name(vxi, vc_data.field);
18557 +       if (!name)
18558 +               return -EINVAL;
18559 +
18560 +       memcpy(name, vc_data.name, 65);
18561 +       return 0;
18562 +}
18563 +
18564 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18565 +{
18566 +       struct vcmd_vhi_name_v0 vc_data;
18567 +       char *name;
18568 +
18569 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18570 +               return -EFAULT;
18571 +
18572 +       name = vx_vhi_name(vxi, vc_data.field);
18573 +       if (!name)
18574 +               return -EINVAL;
18575 +
18576 +       memcpy(vc_data.name, name, 65);
18577 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18578 +               return -EFAULT;
18579 +       return 0;
18580 +}
18581 +
18582 +
18583 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18584 +{
18585 +       struct vcmd_virt_stat_v0 vc_data;
18586 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18587 +       struct timespec uptime;
18588 +
18589 +       do_posix_clock_monotonic_gettime(&uptime);
18590 +       set_normalized_timespec(&uptime,
18591 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18592 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18593 +
18594 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18595 +       vc_data.uptime = timespec_to_ns(&uptime);
18596 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18597 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18598 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18599 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18600 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18601 +       vc_data.load[0] = cvirt->load[0];
18602 +       vc_data.load[1] = cvirt->load[1];
18603 +       vc_data.load[2] = cvirt->load[2];
18604 +
18605 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18606 +               return -EFAULT;
18607 +       return 0;
18608 +}
18609 +
18610 +
18611 +#ifdef CONFIG_VSERVER_VTIME
18612 +
18613 +/* virtualized time base */
18614 +
18615 +void vx_gettimeofday(struct timeval *tv)
18616 +{
18617 +       do_gettimeofday(tv);
18618 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18619 +               return;
18620 +
18621 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18622 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18623 +
18624 +       if (tv->tv_usec >= USEC_PER_SEC) {
18625 +               tv->tv_sec++;
18626 +               tv->tv_usec -= USEC_PER_SEC;
18627 +       } else if (tv->tv_usec < 0) {
18628 +               tv->tv_sec--;
18629 +               tv->tv_usec += USEC_PER_SEC;
18630 +       }
18631 +}
18632 +
18633 +int vx_settimeofday(struct timespec *ts)
18634 +{
18635 +       struct timeval tv;
18636 +
18637 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18638 +               return do_settimeofday(ts);
18639 +
18640 +       do_gettimeofday(&tv);
18641 +       current->vx_info->cvirt.bias_tv.tv_sec =
18642 +               ts->tv_sec - tv.tv_sec;
18643 +       current->vx_info->cvirt.bias_tv.tv_usec =
18644 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18645 +       return 0;
18646 +}
18647 +
18648 +#endif
18649 +
18650 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/cvirt_init.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cvirt_init.h
18651 --- linux-2.6.27.6/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
18652 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cvirt_init.h       2008-10-13 14:54:20.000000000 +0200
18653 @@ -0,0 +1,69 @@
18654 +
18655 +
18656 +extern uint64_t vx_idle_jiffies(void);
18657 +
18658 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18659 +{
18660 +       uint64_t idle_jiffies = vx_idle_jiffies();
18661 +       uint64_t nsuptime;
18662 +
18663 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18664 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18665 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18666 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18667 +       cvirt->bias_tv.tv_sec = 0;
18668 +       cvirt->bias_tv.tv_usec = 0;
18669 +
18670 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18671 +       atomic_set(&cvirt->nr_threads, 0);
18672 +       atomic_set(&cvirt->nr_running, 0);
18673 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18674 +       atomic_set(&cvirt->nr_onhold, 0);
18675 +
18676 +       spin_lock_init(&cvirt->load_lock);
18677 +       cvirt->load_last = jiffies;
18678 +       atomic_set(&cvirt->load_updates, 0);
18679 +       cvirt->load[0] = 0;
18680 +       cvirt->load[1] = 0;
18681 +       cvirt->load[2] = 0;
18682 +       atomic_set(&cvirt->total_forks, 0);
18683 +
18684 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18685 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18686 +       cvirt->syslog.log_start = 0;
18687 +       cvirt->syslog.log_end = 0;
18688 +       cvirt->syslog.con_start = 0;
18689 +       cvirt->syslog.logged_chars = 0;
18690 +}
18691 +
18692 +static inline
18693 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18694 +{
18695 +       // cvirt_pc->cpustat = { 0 };
18696 +}
18697 +
18698 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18699 +{
18700 +       int value;
18701 +
18702 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18703 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18704 +               cvirt, value);
18705 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18706 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18707 +               cvirt, value);
18708 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18709 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18710 +               cvirt, value);
18711 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18712 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18713 +               cvirt, value);
18714 +       return;
18715 +}
18716 +
18717 +static inline
18718 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18719 +{
18720 +       return;
18721 +}
18722 +
18723 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/cvirt_proc.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cvirt_proc.h
18724 --- linux-2.6.27.6/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
18725 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/cvirt_proc.h       2008-10-13 14:54:20.000000000 +0200
18726 @@ -0,0 +1,135 @@
18727 +#ifndef _VX_CVIRT_PROC_H
18728 +#define _VX_CVIRT_PROC_H
18729 +
18730 +#include <linux/nsproxy.h>
18731 +#include <linux/mnt_namespace.h>
18732 +#include <linux/ipc_namespace.h>
18733 +#include <linux/utsname.h>
18734 +#include <linux/ipc.h>
18735 +
18736 +
18737 +static inline
18738 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18739 +{
18740 +       struct mnt_namespace *ns;
18741 +       struct uts_namespace *uts;
18742 +       struct ipc_namespace *ipc;
18743 +       struct path path;
18744 +       char *pstr, *root;
18745 +       int length = 0;
18746 +
18747 +       if (!nsproxy)
18748 +               goto out;
18749 +
18750 +       length += sprintf(buffer + length,
18751 +               "NSProxy:\t%p [%p,%p,%p]\n",
18752 +               nsproxy, nsproxy->mnt_ns,
18753 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18754 +
18755 +       ns = nsproxy->mnt_ns;
18756 +       if (!ns)
18757 +               goto skip_ns;
18758 +
18759 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18760 +       if (!pstr)
18761 +               goto skip_ns;
18762 +
18763 +       path.mnt = ns->root;
18764 +       path.dentry = ns->root->mnt_root;
18765 +       root = d_path(&path, pstr, PATH_MAX - 2);
18766 +       length += sprintf(buffer + length,
18767 +               "Namespace:\t%p [#%u]\n"
18768 +               "RootPath:\t%s\n",
18769 +               ns, atomic_read(&ns->count),
18770 +               root);
18771 +       kfree(pstr);
18772 +skip_ns:
18773 +
18774 +       uts = nsproxy->uts_ns;
18775 +       if (!uts)
18776 +               goto skip_uts;
18777 +
18778 +       length += sprintf(buffer + length,
18779 +               "SysName:\t%.*s\n"
18780 +               "NodeName:\t%.*s\n"
18781 +               "Release:\t%.*s\n"
18782 +               "Version:\t%.*s\n"
18783 +               "Machine:\t%.*s\n"
18784 +               "DomainName:\t%.*s\n",
18785 +               __NEW_UTS_LEN, uts->name.sysname,
18786 +               __NEW_UTS_LEN, uts->name.nodename,
18787 +               __NEW_UTS_LEN, uts->name.release,
18788 +               __NEW_UTS_LEN, uts->name.version,
18789 +               __NEW_UTS_LEN, uts->name.machine,
18790 +               __NEW_UTS_LEN, uts->name.domainname);
18791 +skip_uts:
18792 +
18793 +       ipc = nsproxy->ipc_ns;
18794 +       if (!ipc)
18795 +               goto skip_ipc;
18796 +
18797 +       length += sprintf(buffer + length,
18798 +               "SEMS:\t\t%d %d %d %d  %d\n"
18799 +               "MSG:\t\t%d %d %d\n"
18800 +               "SHM:\t\t%lu %lu  %d %d\n",
18801 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18802 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18803 +               ipc->used_sems,
18804 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18805 +               (unsigned long)ipc->shm_ctlmax,
18806 +               (unsigned long)ipc->shm_ctlall,
18807 +               ipc->shm_ctlmni, ipc->shm_tot);
18808 +skip_ipc:
18809 +out:
18810 +       return length;
18811 +}
18812 +
18813 +
18814 +#include <linux/sched.h>
18815 +
18816 +#define LOAD_INT(x) ((x) >> FSHIFT)
18817 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18818 +
18819 +static inline
18820 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18821 +{
18822 +       int length = 0;
18823 +       int a, b, c;
18824 +
18825 +       length += sprintf(buffer + length,
18826 +               "BiasUptime:\t%lu.%02lu\n",
18827 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18828 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18829 +
18830 +       a = cvirt->load[0] + (FIXED_1 / 200);
18831 +       b = cvirt->load[1] + (FIXED_1 / 200);
18832 +       c = cvirt->load[2] + (FIXED_1 / 200);
18833 +       length += sprintf(buffer + length,
18834 +               "nr_threads:\t%d\n"
18835 +               "nr_running:\t%d\n"
18836 +               "nr_unintr:\t%d\n"
18837 +               "nr_onhold:\t%d\n"
18838 +               "load_updates:\t%d\n"
18839 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18840 +               "total_forks:\t%d\n",
18841 +               atomic_read(&cvirt->nr_threads),
18842 +               atomic_read(&cvirt->nr_running),
18843 +               atomic_read(&cvirt->nr_uninterruptible),
18844 +               atomic_read(&cvirt->nr_onhold),
18845 +               atomic_read(&cvirt->load_updates),
18846 +               LOAD_INT(a), LOAD_FRAC(a),
18847 +               LOAD_INT(b), LOAD_FRAC(b),
18848 +               LOAD_INT(c), LOAD_FRAC(c),
18849 +               atomic_read(&cvirt->total_forks));
18850 +       return length;
18851 +}
18852 +
18853 +static inline
18854 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18855 +       char *buffer, int cpu)
18856 +{
18857 +       int length = 0;
18858 +       return length;
18859 +}
18860 +
18861 +#endif /* _VX_CVIRT_PROC_H */
18862 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/debug.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/debug.c
18863 --- linux-2.6.27.6/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
18864 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/debug.c    2008-10-13 14:54:20.000000000 +0200
18865 @@ -0,0 +1,32 @@
18866 +/*
18867 + *  kernel/vserver/debug.c
18868 + *
18869 + *  Copyright (C) 2005-2007 Herbert Pötzl
18870 + *
18871 + *  V0.01  vx_info dump support
18872 + *
18873 + */
18874 +
18875 +#include <linux/module.h>
18876 +
18877 +#include <linux/vserver/context.h>
18878 +
18879 +
18880 +void   dump_vx_info(struct vx_info *vxi, int level)
18881 +{
18882 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18883 +               atomic_read(&vxi->vx_usecnt),
18884 +               atomic_read(&vxi->vx_tasks),
18885 +               vxi->vx_state);
18886 +       if (level > 0) {
18887 +               __dump_vx_limit(&vxi->limit);
18888 +               __dump_vx_sched(&vxi->sched);
18889 +               __dump_vx_cvirt(&vxi->cvirt);
18890 +               __dump_vx_cacct(&vxi->cacct);
18891 +       }
18892 +       printk("---\n");
18893 +}
18894 +
18895 +
18896 +EXPORT_SYMBOL_GPL(dump_vx_info);
18897 +
18898 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/device.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/device.c
18899 --- linux-2.6.27.6/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
18900 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/device.c   2008-10-13 14:54:20.000000000 +0200
18901 @@ -0,0 +1,443 @@
18902 +/*
18903 + *  linux/kernel/vserver/device.c
18904 + *
18905 + *  Linux-VServer: Device Support
18906 + *
18907 + *  Copyright (C) 2006  Herbert Pötzl
18908 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18909 + *
18910 + *  V0.01  device mapping basics
18911 + *  V0.02  added defaults
18912 + *
18913 + */
18914 +
18915 +#include <linux/slab.h>
18916 +#include <linux/rcupdate.h>
18917 +#include <linux/fs.h>
18918 +#include <linux/namei.h>
18919 +#include <linux/hash.h>
18920 +
18921 +#include <asm/errno.h>
18922 +#include <asm/uaccess.h>
18923 +#include <linux/vserver/base.h>
18924 +#include <linux/vserver/debug.h>
18925 +#include <linux/vserver/context.h>
18926 +#include <linux/vserver/device.h>
18927 +#include <linux/vserver/device_cmd.h>
18928 +
18929 +
18930 +#define DMAP_HASH_BITS 4
18931 +
18932 +
18933 +struct vs_mapping {
18934 +       union {
18935 +               struct hlist_node hlist;
18936 +               struct list_head list;
18937 +       } u;
18938 +#define dm_hlist       u.hlist
18939 +#define dm_list                u.list
18940 +       xid_t xid;
18941 +       dev_t device;
18942 +       struct vx_dmap_target target;
18943 +};
18944 +
18945 +
18946 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18947 +
18948 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18949 +
18950 +static struct vx_dmap_target dmap_defaults[2] = {
18951 +       { .flags = DATTR_OPEN },
18952 +       { .flags = DATTR_OPEN },
18953 +};
18954 +
18955 +
18956 +struct kmem_cache *dmap_cachep __read_mostly;
18957 +
18958 +int __init dmap_cache_init(void)
18959 +{
18960 +       dmap_cachep = kmem_cache_create("dmap_cache",
18961 +               sizeof(struct vs_mapping), 0,
18962 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18963 +       return 0;
18964 +}
18965 +
18966 +__initcall(dmap_cache_init);
18967 +
18968 +
18969 +static inline unsigned int __hashval(dev_t dev, int bits)
18970 +{
18971 +       return hash_long((unsigned long)dev, bits);
18972 +}
18973 +
18974 +
18975 +/*     __hash_mapping()
18976 + *     add the mapping to the hash table
18977 + */
18978 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18979 +{
18980 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18981 +       struct hlist_head *head, *hash = dmap_main_hash;
18982 +       int device = vdm->device;
18983 +
18984 +       spin_lock(hash_lock);
18985 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18986 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18987 +
18988 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18989 +       hlist_add_head(&vdm->dm_hlist, head);
18990 +       spin_unlock(hash_lock);
18991 +}
18992 +
18993 +
18994 +static inline int __mode_to_default(umode_t mode)
18995 +{
18996 +       switch (mode) {
18997 +       case S_IFBLK:
18998 +               return 0;
18999 +       case S_IFCHR:
19000 +               return 1;
19001 +       default:
19002 +               BUG();
19003 +       }
19004 +}
19005 +
19006 +
19007 +/*     __set_default()
19008 + *     set a default
19009 + */
19010 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19011 +       struct vx_dmap_target *vdmt)
19012 +{
19013 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19014 +       spin_lock(hash_lock);
19015 +
19016 +       if (vxi)
19017 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19018 +       else
19019 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19020 +
19021 +
19022 +       spin_unlock(hash_lock);
19023 +
19024 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19025 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19026 +}
19027 +
19028 +
19029 +/*     __remove_default()
19030 + *     remove a default
19031 + */
19032 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19033 +{
19034 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19035 +       spin_lock(hash_lock);
19036 +
19037 +       if (vxi)
19038 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19039 +       else    /* remove == reset */
19040 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19041 +
19042 +       spin_unlock(hash_lock);
19043 +       return 0;
19044 +}
19045 +
19046 +
19047 +/*     __find_mapping()
19048 + *     find a mapping in the hash table
19049 + *
19050 + *     caller must hold hash_lock
19051 + */
19052 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19053 +       struct vs_mapping **local, struct vs_mapping **global)
19054 +{
19055 +       struct hlist_head *hash = dmap_main_hash;
19056 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19057 +       struct hlist_node *pos;
19058 +       struct vs_mapping *vdm;
19059 +
19060 +       *local = NULL;
19061 +       if (global)
19062 +               *global = NULL;
19063 +
19064 +       hlist_for_each(pos, head) {
19065 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19066 +
19067 +               if ((vdm->device == device) &&
19068 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19069 +                       if (vdm->xid == xid) {
19070 +                               *local = vdm;
19071 +                               return 1;
19072 +                       } else if (global && vdm->xid == 0)
19073 +                               *global = vdm;
19074 +               }
19075 +       }
19076 +
19077 +       if (global && *global)
19078 +               return 0;
19079 +       else
19080 +               return -ENOENT;
19081 +}
19082 +
19083 +
19084 +/*     __lookup_mapping()
19085 + *     find a mapping and store the result in target and flags
19086 + */
19087 +static inline int __lookup_mapping(struct vx_info *vxi,
19088 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19089 +{
19090 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19091 +       struct vs_mapping *vdm, *global;
19092 +       struct vx_dmap_target *vdmt;
19093 +       int ret = 0;
19094 +       xid_t xid = vxi->vx_id;
19095 +       int index;
19096 +
19097 +       spin_lock(hash_lock);
19098 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19099 +               ret = 1;
19100 +               vdmt = &vdm->target;
19101 +               goto found;
19102 +       }
19103 +
19104 +       index = __mode_to_default(mode);
19105 +       if (vxi && vxi->dmap.targets[index].flags) {
19106 +               ret = 2;
19107 +               vdmt = &vxi->dmap.targets[index];
19108 +       } else if (global) {
19109 +               ret = 3;
19110 +               vdmt = &global->target;
19111 +               goto found;
19112 +       } else {
19113 +               ret = 4;
19114 +               vdmt = &dmap_defaults[index];
19115 +       }
19116 +
19117 +found:
19118 +       if (target && (vdmt->flags & DATTR_REMAP))
19119 +               *target = vdmt->target;
19120 +       else if (target)
19121 +               *target = device;
19122 +       if (flags)
19123 +               *flags = vdmt->flags;
19124 +
19125 +       spin_unlock(hash_lock);
19126 +
19127 +       return ret;
19128 +}
19129 +
19130 +
19131 +/*     __remove_mapping()
19132 + *     remove a mapping from the hash table
19133 + */
19134 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19135 +       umode_t mode)
19136 +{
19137 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19138 +       struct vs_mapping *vdm = NULL;
19139 +       int ret = 0;
19140 +
19141 +       spin_lock(hash_lock);
19142 +
19143 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19144 +               NULL);
19145 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19146 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19147 +       if (ret < 0)
19148 +               goto out;
19149 +       hlist_del(&vdm->dm_hlist);
19150 +
19151 +out:
19152 +       spin_unlock(hash_lock);
19153 +       if (vdm)
19154 +               kmem_cache_free(dmap_cachep, vdm);
19155 +       return ret;
19156 +}
19157 +
19158 +
19159 +
19160 +int vs_map_device(struct vx_info *vxi,
19161 +       dev_t device, dev_t *target, umode_t mode)
19162 +{
19163 +       int ret, flags = DATTR_MASK;
19164 +
19165 +       if (!vxi) {
19166 +               if (target)
19167 +                       *target = device;
19168 +               goto out;
19169 +       }
19170 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19171 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19172 +               device, target ? *target : 0, flags, mode, ret);
19173 +out:
19174 +       return (flags & DATTR_MASK);
19175 +}
19176 +
19177 +
19178 +
19179 +static int do_set_mapping(struct vx_info *vxi,
19180 +       dev_t device, dev_t target, int flags, umode_t mode)
19181 +{
19182 +       if (device) {
19183 +               struct vs_mapping *new;
19184 +
19185 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19186 +               if (!new)
19187 +                       return -ENOMEM;
19188 +
19189 +               INIT_HLIST_NODE(&new->dm_hlist);
19190 +               new->device = device;
19191 +               new->target.target = target;
19192 +               new->target.flags = flags | mode;
19193 +               new->xid = (vxi ? vxi->vx_id : 0);
19194 +
19195 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19196 +               __hash_mapping(vxi, new);
19197 +       } else {
19198 +               struct vx_dmap_target new = {
19199 +                       .target = target,
19200 +                       .flags = flags | mode,
19201 +               };
19202 +               __set_default(vxi, mode, &new);
19203 +       }
19204 +       return 0;
19205 +}
19206 +
19207 +
19208 +static int do_unset_mapping(struct vx_info *vxi,
19209 +       dev_t device, dev_t target, int flags, umode_t mode)
19210 +{
19211 +       int ret = -EINVAL;
19212 +
19213 +       if (device) {
19214 +               ret = __remove_mapping(vxi, device, mode);
19215 +               if (ret < 0)
19216 +                       goto out;
19217 +       } else {
19218 +               ret = __remove_default(vxi, mode);
19219 +               if (ret < 0)
19220 +                       goto out;
19221 +       }
19222 +
19223 +out:
19224 +       return ret;
19225 +}
19226 +
19227 +
19228 +static inline int __user_device(const char __user *name, dev_t *dev,
19229 +       umode_t *mode)
19230 +{
19231 +       struct nameidata nd;
19232 +       int ret;
19233 +
19234 +       if (!name) {
19235 +               *dev = 0;
19236 +               return 0;
19237 +       }
19238 +       ret = user_lpath(name, &nd.path);
19239 +       if (ret)
19240 +               return ret;
19241 +       if (nd.path.dentry->d_inode) {
19242 +               *dev = nd.path.dentry->d_inode->i_rdev;
19243 +               *mode = nd.path.dentry->d_inode->i_mode;
19244 +       }
19245 +       path_put(&nd.path);
19246 +       return 0;
19247 +}
19248 +
19249 +static inline int __mapping_mode(dev_t device, dev_t target,
19250 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19251 +{
19252 +       if (device)
19253 +               *mode = device_mode & S_IFMT;
19254 +       else if (target)
19255 +               *mode = target_mode & S_IFMT;
19256 +       else
19257 +               return -EINVAL;
19258 +
19259 +       /* if both given, device and target mode have to match */
19260 +       if (device && target &&
19261 +               ((device_mode ^ target_mode) & S_IFMT))
19262 +               return -EINVAL;
19263 +       return 0;
19264 +}
19265 +
19266 +
19267 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19268 +       const char __user *target_path, int flags, int set)
19269 +{
19270 +       dev_t device = ~0, target = ~0;
19271 +       umode_t device_mode = 0, target_mode = 0, mode;
19272 +       int ret;
19273 +
19274 +       ret = __user_device(device_path, &device, &device_mode);
19275 +       if (ret)
19276 +               return ret;
19277 +       ret = __user_device(target_path, &target, &target_mode);
19278 +       if (ret)
19279 +               return ret;
19280 +
19281 +       ret = __mapping_mode(device, target,
19282 +               device_mode, target_mode, &mode);
19283 +       if (ret)
19284 +               return ret;
19285 +
19286 +       if (set)
19287 +               return do_set_mapping(vxi, device, target,
19288 +                       flags, mode);
19289 +       else
19290 +               return do_unset_mapping(vxi, device, target,
19291 +                       flags, mode);
19292 +}
19293 +
19294 +
19295 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19296 +{
19297 +       struct vcmd_set_mapping_v0 vc_data;
19298 +
19299 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19300 +               return -EFAULT;
19301 +
19302 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19303 +               vc_data.flags, 1);
19304 +}
19305 +
19306 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19307 +{
19308 +       struct vcmd_set_mapping_v0 vc_data;
19309 +
19310 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19311 +               return -EFAULT;
19312 +
19313 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19314 +               vc_data.flags, 0);
19315 +}
19316 +
19317 +
19318 +#ifdef CONFIG_COMPAT
19319 +
19320 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19321 +{
19322 +       struct vcmd_set_mapping_v0_x32 vc_data;
19323 +
19324 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19325 +               return -EFAULT;
19326 +
19327 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19328 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19329 +}
19330 +
19331 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19332 +{
19333 +       struct vcmd_set_mapping_v0_x32 vc_data;
19334 +
19335 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19336 +               return -EFAULT;
19337 +
19338 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19339 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19340 +}
19341 +
19342 +#endif /* CONFIG_COMPAT */
19343 +
19344 +
19345 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/dlimit.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/dlimit.c
19346 --- linux-2.6.27.6/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
19347 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/dlimit.c   2008-10-13 14:54:20.000000000 +0200
19348 @@ -0,0 +1,522 @@
19349 +/*
19350 + *  linux/kernel/vserver/dlimit.c
19351 + *
19352 + *  Virtual Server: Context Disk Limits
19353 + *
19354 + *  Copyright (C) 2004-2007  Herbert Pötzl
19355 + *
19356 + *  V0.01  initial version
19357 + *  V0.02  compat32 splitup
19358 + *
19359 + */
19360 +
19361 +#include <linux/statfs.h>
19362 +#include <linux/sched.h>
19363 +#include <linux/namei.h>
19364 +#include <linux/vs_tag.h>
19365 +#include <linux/vs_dlimit.h>
19366 +#include <linux/vserver/dlimit_cmd.h>
19367 +
19368 +#include <asm/uaccess.h>
19369 +
19370 +/*     __alloc_dl_info()
19371 +
19372 +       * allocate an initialized dl_info struct
19373 +       * doesn't make it visible (hash)                        */
19374 +
19375 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19376 +{
19377 +       struct dl_info *new = NULL;
19378 +
19379 +       vxdprintk(VXD_CBIT(dlim, 5),
19380 +               "alloc_dl_info(%p,%d)*", sb, tag);
19381 +
19382 +       /* would this benefit from a slab cache? */
19383 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19384 +       if (!new)
19385 +               return 0;
19386 +
19387 +       memset(new, 0, sizeof(struct dl_info));
19388 +       new->dl_tag = tag;
19389 +       new->dl_sb = sb;
19390 +       INIT_RCU_HEAD(&new->dl_rcu);
19391 +       INIT_HLIST_NODE(&new->dl_hlist);
19392 +       spin_lock_init(&new->dl_lock);
19393 +       atomic_set(&new->dl_refcnt, 0);
19394 +       atomic_set(&new->dl_usecnt, 0);
19395 +
19396 +       /* rest of init goes here */
19397 +
19398 +       vxdprintk(VXD_CBIT(dlim, 4),
19399 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19400 +       return new;
19401 +}
19402 +
19403 +/*     __dealloc_dl_info()
19404 +
19405 +       * final disposal of dl_info                             */
19406 +
19407 +static void __dealloc_dl_info(struct dl_info *dli)
19408 +{
19409 +       vxdprintk(VXD_CBIT(dlim, 4),
19410 +               "dealloc_dl_info(%p)", dli);
19411 +
19412 +       dli->dl_hlist.next = LIST_POISON1;
19413 +       dli->dl_tag = -1;
19414 +       dli->dl_sb = 0;
19415 +
19416 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19417 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19418 +
19419 +       kfree(dli);
19420 +}
19421 +
19422 +
19423 +/*     hash table for dl_info hash */
19424 +
19425 +#define DL_HASH_SIZE   13
19426 +
19427 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19428 +
19429 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19430 +
19431 +
19432 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19433 +{
19434 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19435 +}
19436 +
19437 +
19438 +
19439 +/*     __hash_dl_info()
19440 +
19441 +       * add the dli to the global hash table
19442 +       * requires the hash_lock to be held                     */
19443 +
19444 +static inline void __hash_dl_info(struct dl_info *dli)
19445 +{
19446 +       struct hlist_head *head;
19447 +
19448 +       vxdprintk(VXD_CBIT(dlim, 6),
19449 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19450 +       get_dl_info(dli);
19451 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19452 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19453 +}
19454 +
19455 +/*     __unhash_dl_info()
19456 +
19457 +       * remove the dli from the global hash table
19458 +       * requires the hash_lock to be held                     */
19459 +
19460 +static inline void __unhash_dl_info(struct dl_info *dli)
19461 +{
19462 +       vxdprintk(VXD_CBIT(dlim, 6),
19463 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19464 +       hlist_del_rcu(&dli->dl_hlist);
19465 +       put_dl_info(dli);
19466 +}
19467 +
19468 +
19469 +/*     __lookup_dl_info()
19470 +
19471 +       * requires the rcu_read_lock()
19472 +       * doesn't increment the dl_refcnt                       */
19473 +
19474 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19475 +{
19476 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19477 +       struct hlist_node *pos;
19478 +       struct dl_info *dli;
19479 +
19480 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19481 +
19482 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19483 +                       return dli;
19484 +               }
19485 +       }
19486 +       return NULL;
19487 +}
19488 +
19489 +
19490 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19491 +{
19492 +       struct dl_info *dli;
19493 +
19494 +       rcu_read_lock();
19495 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19496 +       vxdprintk(VXD_CBIT(dlim, 7),
19497 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19498 +       rcu_read_unlock();
19499 +       return dli;
19500 +}
19501 +
19502 +void rcu_free_dl_info(struct rcu_head *head)
19503 +{
19504 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19505 +       int usecnt, refcnt;
19506 +
19507 +       BUG_ON(!dli || !head);
19508 +
19509 +       usecnt = atomic_read(&dli->dl_usecnt);
19510 +       BUG_ON(usecnt < 0);
19511 +
19512 +       refcnt = atomic_read(&dli->dl_refcnt);
19513 +       BUG_ON(refcnt < 0);
19514 +
19515 +       vxdprintk(VXD_CBIT(dlim, 3),
19516 +               "rcu_free_dl_info(%p)", dli);
19517 +       if (!usecnt)
19518 +               __dealloc_dl_info(dli);
19519 +       else
19520 +               printk("!!! rcu didn't free\n");
19521 +}
19522 +
19523 +
19524 +
19525 +
19526 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19527 +       uint32_t flags, int add)
19528 +{
19529 +       struct path path;
19530 +       int ret;
19531 +
19532 +       ret = user_lpath(name, &path);
19533 +       if (!ret) {
19534 +               struct super_block *sb;
19535 +               struct dl_info *dli;
19536 +
19537 +               ret = -EINVAL;
19538 +               if (!path.dentry->d_inode)
19539 +                       goto out_release;
19540 +               if (!(sb = path.dentry->d_inode->i_sb))
19541 +                       goto out_release;
19542 +
19543 +               if (add) {
19544 +                       dli = __alloc_dl_info(sb, id);
19545 +                       spin_lock(&dl_info_hash_lock);
19546 +
19547 +                       ret = -EEXIST;
19548 +                       if (__lookup_dl_info(sb, id))
19549 +                               goto out_unlock;
19550 +                       __hash_dl_info(dli);
19551 +                       dli = NULL;
19552 +               } else {
19553 +                       spin_lock(&dl_info_hash_lock);
19554 +                       dli = __lookup_dl_info(sb, id);
19555 +
19556 +                       ret = -ESRCH;
19557 +                       if (!dli)
19558 +                               goto out_unlock;
19559 +                       __unhash_dl_info(dli);
19560 +               }
19561 +               ret = 0;
19562 +       out_unlock:
19563 +               spin_unlock(&dl_info_hash_lock);
19564 +               if (add && dli)
19565 +                       __dealloc_dl_info(dli);
19566 +       out_release:
19567 +               path_put(&path);
19568 +       }
19569 +       return ret;
19570 +}
19571 +
19572 +int vc_add_dlimit(uint32_t id, void __user *data)
19573 +{
19574 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19575 +
19576 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19577 +               return -EFAULT;
19578 +
19579 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19580 +}
19581 +
19582 +int vc_rem_dlimit(uint32_t id, void __user *data)
19583 +{
19584 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19585 +
19586 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19587 +               return -EFAULT;
19588 +
19589 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19590 +}
19591 +
19592 +#ifdef CONFIG_COMPAT
19593 +
19594 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19595 +{
19596 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19597 +
19598 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19599 +               return -EFAULT;
19600 +
19601 +       return do_addrem_dlimit(id,
19602 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19603 +}
19604 +
19605 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19606 +{
19607 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19608 +
19609 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19610 +               return -EFAULT;
19611 +
19612 +       return do_addrem_dlimit(id,
19613 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19614 +}
19615 +
19616 +#endif /* CONFIG_COMPAT */
19617 +
19618 +
19619 +static inline
19620 +int do_set_dlimit(uint32_t id, const char __user *name,
19621 +       uint32_t space_used, uint32_t space_total,
19622 +       uint32_t inodes_used, uint32_t inodes_total,
19623 +       uint32_t reserved, uint32_t flags)
19624 +{
19625 +       struct path path;
19626 +       int ret;
19627 +
19628 +       ret = user_lpath(name, &path);
19629 +       if (!ret) {
19630 +               struct super_block *sb;
19631 +               struct dl_info *dli;
19632 +
19633 +               ret = -EINVAL;
19634 +               if (!path.dentry->d_inode)
19635 +                       goto out_release;
19636 +               if (!(sb = path.dentry->d_inode->i_sb))
19637 +                       goto out_release;
19638 +               if ((reserved != CDLIM_KEEP &&
19639 +                       reserved > 100) ||
19640 +                       (inodes_used != CDLIM_KEEP &&
19641 +                       inodes_used > inodes_total) ||
19642 +                       (space_used != CDLIM_KEEP &&
19643 +                       space_used > space_total))
19644 +                       goto out_release;
19645 +
19646 +               ret = -ESRCH;
19647 +               dli = locate_dl_info(sb, id);
19648 +               if (!dli)
19649 +                       goto out_release;
19650 +
19651 +               spin_lock(&dli->dl_lock);
19652 +
19653 +               if (inodes_used != CDLIM_KEEP)
19654 +                       dli->dl_inodes_used = inodes_used;
19655 +               if (inodes_total != CDLIM_KEEP)
19656 +                       dli->dl_inodes_total = inodes_total;
19657 +               if (space_used != CDLIM_KEEP) {
19658 +                       dli->dl_space_used = space_used;
19659 +                       dli->dl_space_used <<= 10;
19660 +               }
19661 +               if (space_total == CDLIM_INFINITY)
19662 +                       dli->dl_space_total = DLIM_INFINITY;
19663 +               else if (space_total != CDLIM_KEEP) {
19664 +                       dli->dl_space_total = space_total;
19665 +                       dli->dl_space_total <<= 10;
19666 +               }
19667 +               if (reserved != CDLIM_KEEP)
19668 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19669 +
19670 +               spin_unlock(&dli->dl_lock);
19671 +
19672 +               put_dl_info(dli);
19673 +               ret = 0;
19674 +
19675 +       out_release:
19676 +               path_put(&path);
19677 +       }
19678 +       return ret;
19679 +}
19680 +
19681 +int vc_set_dlimit(uint32_t id, void __user *data)
19682 +{
19683 +       struct vcmd_ctx_dlimit_v0 vc_data;
19684 +
19685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19686 +               return -EFAULT;
19687 +
19688 +       return do_set_dlimit(id, vc_data.name,
19689 +               vc_data.space_used, vc_data.space_total,
19690 +               vc_data.inodes_used, vc_data.inodes_total,
19691 +               vc_data.reserved, vc_data.flags);
19692 +}
19693 +
19694 +#ifdef CONFIG_COMPAT
19695 +
19696 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19697 +{
19698 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19699 +
19700 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19701 +               return -EFAULT;
19702 +
19703 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19704 +               vc_data.space_used, vc_data.space_total,
19705 +               vc_data.inodes_used, vc_data.inodes_total,
19706 +               vc_data.reserved, vc_data.flags);
19707 +}
19708 +
19709 +#endif /* CONFIG_COMPAT */
19710 +
19711 +
19712 +static inline
19713 +int do_get_dlimit(uint32_t id, const char __user *name,
19714 +       uint32_t *space_used, uint32_t *space_total,
19715 +       uint32_t *inodes_used, uint32_t *inodes_total,
19716 +       uint32_t *reserved, uint32_t *flags)
19717 +{
19718 +       struct path path;
19719 +       int ret;
19720 +
19721 +       ret = user_lpath(name, &path);
19722 +       if (!ret) {
19723 +               struct super_block *sb;
19724 +               struct dl_info *dli;
19725 +
19726 +               ret = -EINVAL;
19727 +               if (!path.dentry->d_inode)
19728 +                       goto out_release;
19729 +               if (!(sb = path.dentry->d_inode->i_sb))
19730 +                       goto out_release;
19731 +
19732 +               ret = -ESRCH;
19733 +               dli = locate_dl_info(sb, id);
19734 +               if (!dli)
19735 +                       goto out_release;
19736 +
19737 +               spin_lock(&dli->dl_lock);
19738 +               *inodes_used = dli->dl_inodes_used;
19739 +               *inodes_total = dli->dl_inodes_total;
19740 +               *space_used = dli->dl_space_used >> 10;
19741 +               if (dli->dl_space_total == DLIM_INFINITY)
19742 +                       *space_total = CDLIM_INFINITY;
19743 +               else
19744 +                       *space_total = dli->dl_space_total >> 10;
19745 +
19746 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19747 +               spin_unlock(&dli->dl_lock);
19748 +
19749 +               put_dl_info(dli);
19750 +               ret = -EFAULT;
19751 +
19752 +               ret = 0;
19753 +       out_release:
19754 +               path_put(&path);
19755 +       }
19756 +       return ret;
19757 +}
19758 +
19759 +
19760 +int vc_get_dlimit(uint32_t id, void __user *data)
19761 +{
19762 +       struct vcmd_ctx_dlimit_v0 vc_data;
19763 +       int ret;
19764 +
19765 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19766 +               return -EFAULT;
19767 +
19768 +       ret = do_get_dlimit(id, vc_data.name,
19769 +               &vc_data.space_used, &vc_data.space_total,
19770 +               &vc_data.inodes_used, &vc_data.inodes_total,
19771 +               &vc_data.reserved, &vc_data.flags);
19772 +       if (ret)
19773 +               return ret;
19774 +
19775 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19776 +               return -EFAULT;
19777 +       return 0;
19778 +}
19779 +
19780 +#ifdef CONFIG_COMPAT
19781 +
19782 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19783 +{
19784 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19785 +       int ret;
19786 +
19787 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19788 +               return -EFAULT;
19789 +
19790 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19791 +               &vc_data.space_used, &vc_data.space_total,
19792 +               &vc_data.inodes_used, &vc_data.inodes_total,
19793 +               &vc_data.reserved, &vc_data.flags);
19794 +       if (ret)
19795 +               return ret;
19796 +
19797 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19798 +               return -EFAULT;
19799 +       return 0;
19800 +}
19801 +
19802 +#endif /* CONFIG_COMPAT */
19803 +
19804 +
19805 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19806 +{
19807 +       struct dl_info *dli;
19808 +       __u64 blimit, bfree, bavail;
19809 +       __u32 ifree;
19810 +
19811 +       dli = locate_dl_info(sb, dx_current_tag());
19812 +       if (!dli)
19813 +               return;
19814 +
19815 +       spin_lock(&dli->dl_lock);
19816 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19817 +               goto no_ilim;
19818 +
19819 +       /* reduce max inodes available to limit */
19820 +       if (buf->f_files > dli->dl_inodes_total)
19821 +               buf->f_files = dli->dl_inodes_total;
19822 +
19823 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19824 +       /* reduce free inodes to min */
19825 +       if (ifree < buf->f_ffree)
19826 +               buf->f_ffree = ifree;
19827 +
19828 +no_ilim:
19829 +       if (dli->dl_space_total == DLIM_INFINITY)
19830 +               goto no_blim;
19831 +
19832 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19833 +
19834 +       if (dli->dl_space_total < dli->dl_space_used)
19835 +               bfree = 0;
19836 +       else
19837 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19838 +                       >> sb->s_blocksize_bits;
19839 +
19840 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19841 +       if (bavail < dli->dl_space_used)
19842 +               bavail = 0;
19843 +       else
19844 +               bavail = (bavail - dli->dl_space_used)
19845 +                       >> sb->s_blocksize_bits;
19846 +
19847 +       /* reduce max space available to limit */
19848 +       if (buf->f_blocks > blimit)
19849 +               buf->f_blocks = blimit;
19850 +
19851 +       /* reduce free space to min */
19852 +       if (bfree < buf->f_bfree)
19853 +               buf->f_bfree = bfree;
19854 +
19855 +       /* reduce avail space to min */
19856 +       if (bavail < buf->f_bavail)
19857 +               buf->f_bavail = bavail;
19858 +
19859 +no_blim:
19860 +       spin_unlock(&dli->dl_lock);
19861 +       put_dl_info(dli);
19862 +
19863 +       return;
19864 +}
19865 +
19866 +#include <linux/module.h>
19867 +
19868 +EXPORT_SYMBOL_GPL(locate_dl_info);
19869 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19870 +
19871 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/helper.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/helper.c
19872 --- linux-2.6.27.6/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
19873 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/helper.c   2008-10-13 14:54:20.000000000 +0200
19874 @@ -0,0 +1,199 @@
19875 +/*
19876 + *  linux/kernel/vserver/helper.c
19877 + *
19878 + *  Virtual Context Support
19879 + *
19880 + *  Copyright (C) 2004-2007  Herbert Pötzl
19881 + *
19882 + *  V0.01  basic helper
19883 + *
19884 + */
19885 +
19886 +#include <linux/kmod.h>
19887 +#include <linux/reboot.h>
19888 +#include <linux/vs_context.h>
19889 +#include <linux/vs_network.h>
19890 +#include <linux/vserver/signal.h>
19891 +
19892 +
19893 +char vshelper_path[255] = "/sbin/vshelper";
19894 +
19895 +
19896 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19897 +{
19898 +       int ret;
19899 +
19900 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19901 +               printk( KERN_WARNING
19902 +                       "%s: (%s %s) returned %s with %d\n",
19903 +                       name, argv[1], argv[2],
19904 +                       sync ? "sync" : "async", ret);
19905 +       }
19906 +       vxdprintk(VXD_CBIT(switch, 4),
19907 +               "%s: (%s %s) returned %s with %d",
19908 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19909 +       return ret;
19910 +}
19911 +
19912 +/*
19913 + *      vshelper path is set via /proc/sys
19914 + *      invoked by vserver sys_reboot(), with
19915 + *      the following arguments
19916 + *
19917 + *      argv [0] = vshelper_path;
19918 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19919 + *      argv [2] = context identifier
19920 + *
19921 + *      envp [*] = type-specific parameters
19922 + */
19923 +
19924 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19925 +{
19926 +       char id_buf[8], cmd_buf[16];
19927 +       char uid_buf[16], pid_buf[16];
19928 +       int ret;
19929 +
19930 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19931 +       char *envp[] = {"HOME=/", "TERM=linux",
19932 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19933 +                       uid_buf, pid_buf, cmd_buf, 0};
19934 +
19935 +       if (vx_info_state(vxi, VXS_HELPER))
19936 +               return -EAGAIN;
19937 +       vxi->vx_state |= VXS_HELPER;
19938 +
19939 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19940 +
19941 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19942 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
19943 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19944 +
19945 +       switch (cmd) {
19946 +       case LINUX_REBOOT_CMD_RESTART:
19947 +               argv[1] = "restart";
19948 +               break;
19949 +
19950 +       case LINUX_REBOOT_CMD_HALT:
19951 +               argv[1] = "halt";
19952 +               break;
19953 +
19954 +       case LINUX_REBOOT_CMD_POWER_OFF:
19955 +               argv[1] = "poweroff";
19956 +               break;
19957 +
19958 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19959 +               argv[1] = "swsusp";
19960 +               break;
19961 +
19962 +       default:
19963 +               vxi->vx_state &= ~VXS_HELPER;
19964 +               return 0;
19965 +       }
19966 +
19967 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19968 +       vxi->vx_state &= ~VXS_HELPER;
19969 +       __wakeup_vx_info(vxi);
19970 +       return (ret) ? -EPERM : 0;
19971 +}
19972 +
19973 +
19974 +long vs_reboot(unsigned int cmd, void __user *arg)
19975 +{
19976 +       struct vx_info *vxi = current->vx_info;
19977 +       long ret = 0;
19978 +
19979 +       vxdprintk(VXD_CBIT(misc, 5),
19980 +               "vs_reboot(%p[#%d],%d)",
19981 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19982 +
19983 +       ret = vs_reboot_helper(vxi, cmd, arg);
19984 +       if (ret)
19985 +               return ret;
19986 +
19987 +       vxi->reboot_cmd = cmd;
19988 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19989 +               switch (cmd) {
19990 +               case LINUX_REBOOT_CMD_RESTART:
19991 +               case LINUX_REBOOT_CMD_HALT:
19992 +               case LINUX_REBOOT_CMD_POWER_OFF:
19993 +                       vx_info_kill(vxi, 0, SIGKILL);
19994 +                       vx_info_kill(vxi, 1, SIGKILL);
19995 +               default:
19996 +                       break;
19997 +               }
19998 +       }
19999 +       return 0;
20000 +}
20001 +
20002 +
20003 +/*
20004 + *      argv [0] = vshelper_path;
20005 + *      argv [1] = action: "startup", "shutdown"
20006 + *      argv [2] = context identifier
20007 + *
20008 + *      envp [*] = type-specific parameters
20009 + */
20010 +
20011 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20012 +{
20013 +       char id_buf[8], cmd_buf[16];
20014 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20015 +       char *envp[] = {"HOME=/", "TERM=linux",
20016 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20017 +
20018 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20019 +               return 0;
20020 +
20021 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20022 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20023 +
20024 +       switch (cmd) {
20025 +       case VSC_STARTUP:
20026 +               argv[1] = "startup";
20027 +               break;
20028 +       case VSC_SHUTDOWN:
20029 +               argv[1] = "shutdown";
20030 +               break;
20031 +       default:
20032 +               return 0;
20033 +       }
20034 +
20035 +       return do_vshelper(vshelper_path, argv, envp, 1);
20036 +}
20037 +
20038 +
20039 +/*
20040 + *      argv [0] = vshelper_path;
20041 + *      argv [1] = action: "netup", "netdown"
20042 + *      argv [2] = context identifier
20043 + *
20044 + *      envp [*] = type-specific parameters
20045 + */
20046 +
20047 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20048 +{
20049 +       char id_buf[8], cmd_buf[16];
20050 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20051 +       char *envp[] = {"HOME=/", "TERM=linux",
20052 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20053 +
20054 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20055 +               return 0;
20056 +
20057 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20058 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20059 +
20060 +       switch (cmd) {
20061 +       case VSC_NETUP:
20062 +               argv[1] = "netup";
20063 +               break;
20064 +       case VSC_NETDOWN:
20065 +               argv[1] = "netdown";
20066 +               break;
20067 +       default:
20068 +               return 0;
20069 +       }
20070 +
20071 +       return do_vshelper(vshelper_path, argv, envp, 1);
20072 +}
20073 +
20074 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/history.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/history.c
20075 --- linux-2.6.27.6/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
20076 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/history.c  2008-10-13 14:54:20.000000000 +0200
20077 @@ -0,0 +1,258 @@
20078 +/*
20079 + *  kernel/vserver/history.c
20080 + *
20081 + *  Virtual Context History Backtrace
20082 + *
20083 + *  Copyright (C) 2004-2007  Herbert Pötzl
20084 + *
20085 + *  V0.01  basic structure
20086 + *  V0.02  hash/unhash and trace
20087 + *  V0.03  preemption fixes
20088 + *
20089 + */
20090 +
20091 +#include <linux/module.h>
20092 +#include <asm/uaccess.h>
20093 +
20094 +#include <linux/vserver/context.h>
20095 +#include <linux/vserver/debug.h>
20096 +#include <linux/vserver/debug_cmd.h>
20097 +#include <linux/vserver/history.h>
20098 +
20099 +
20100 +#ifdef CONFIG_VSERVER_HISTORY
20101 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20102 +#else
20103 +#define VXH_SIZE       64
20104 +#endif
20105 +
20106 +struct _vx_history {
20107 +       unsigned int counter;
20108 +
20109 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20110 +};
20111 +
20112 +
20113 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20114 +
20115 +unsigned volatile int vxh_active = 1;
20116 +
20117 +static atomic_t sequence = ATOMIC_INIT(0);
20118 +
20119 +
20120 +/*     vxh_advance()
20121 +
20122 +       * requires disabled preemption                          */
20123 +
20124 +struct _vx_hist_entry *vxh_advance(void *loc)
20125 +{
20126 +       unsigned int cpu = smp_processor_id();
20127 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20128 +       struct _vx_hist_entry *entry;
20129 +       unsigned int index;
20130 +
20131 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20132 +       entry = &hist->entry[index];
20133 +
20134 +       entry->seq = atomic_inc_return(&sequence);
20135 +       entry->loc = loc;
20136 +       return entry;
20137 +}
20138 +
20139 +EXPORT_SYMBOL_GPL(vxh_advance);
20140 +
20141 +
20142 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20143 +
20144 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20145 +
20146 +
20147 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20148 +
20149 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20150 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20151 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20152 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20153 +
20154 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20155 +{
20156 +       switch (e->type) {
20157 +       case VXH_THROW_OOPS:
20158 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20159 +               break;
20160 +
20161 +       case VXH_GET_VX_INFO:
20162 +       case VXH_PUT_VX_INFO:
20163 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20164 +                       VXH_LOC_ARGS(e),
20165 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20166 +                       VXH_VXI_ARGS(e));
20167 +               break;
20168 +
20169 +       case VXH_INIT_VX_INFO:
20170 +       case VXH_SET_VX_INFO:
20171 +       case VXH_CLR_VX_INFO:
20172 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20173 +                       VXH_LOC_ARGS(e),
20174 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20175 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20176 +                       VXH_VXI_ARGS(e), e->sc.data);
20177 +               break;
20178 +
20179 +       case VXH_CLAIM_VX_INFO:
20180 +       case VXH_RELEASE_VX_INFO:
20181 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20182 +                       VXH_LOC_ARGS(e),
20183 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20184 +                       VXH_VXI_ARGS(e), e->sc.data);
20185 +               break;
20186 +
20187 +       case VXH_ALLOC_VX_INFO:
20188 +       case VXH_DEALLOC_VX_INFO:
20189 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20190 +                       VXH_LOC_ARGS(e),
20191 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20192 +                       VXH_VXI_ARGS(e));
20193 +               break;
20194 +
20195 +       case VXH_HASH_VX_INFO:
20196 +       case VXH_UNHASH_VX_INFO:
20197 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20198 +                       VXH_LOC_ARGS(e),
20199 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20200 +                       VXH_VXI_ARGS(e));
20201 +               break;
20202 +
20203 +       case VXH_LOC_VX_INFO:
20204 +       case VXH_LOOKUP_VX_INFO:
20205 +       case VXH_CREATE_VX_INFO:
20206 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20207 +                       VXH_LOC_ARGS(e),
20208 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20209 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20210 +                       e->ll.arg, VXH_VXI_ARGS(e));
20211 +               break;
20212 +       }
20213 +}
20214 +
20215 +static void __vxh_dump_history(void)
20216 +{
20217 +       unsigned int i, cpu;
20218 +
20219 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20220 +               atomic_read(&sequence), NR_CPUS);
20221 +
20222 +       for (i = 0; i < VXH_SIZE; i++) {
20223 +               for_each_online_cpu(cpu) {
20224 +                       struct _vx_history *hist =
20225 +                               &per_cpu(vx_history_buffer, cpu);
20226 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20227 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20228 +
20229 +                       vxh_dump_entry(entry, cpu);
20230 +               }
20231 +       }
20232 +}
20233 +
20234 +void   vxh_dump_history(void)
20235 +{
20236 +       vxh_active = 0;
20237 +#ifdef CONFIG_SMP
20238 +       local_irq_enable();
20239 +       smp_send_stop();
20240 +       local_irq_disable();
20241 +#endif
20242 +       __vxh_dump_history();
20243 +}
20244 +
20245 +
20246 +/* vserver syscall commands below here */
20247 +
20248 +
20249 +int vc_dump_history(uint32_t id)
20250 +{
20251 +       vxh_active = 0;
20252 +       __vxh_dump_history();
20253 +       vxh_active = 1;
20254 +
20255 +       return 0;
20256 +}
20257 +
20258 +
20259 +int do_read_history(struct __user _vx_hist_entry *data,
20260 +       int cpu, uint32_t *index, uint32_t *count)
20261 +{
20262 +       int pos, ret = 0;
20263 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20264 +       int end = hist->counter;
20265 +       int start = end - VXH_SIZE + 2;
20266 +       int idx = *index;
20267 +
20268 +       /* special case: get current pos */
20269 +       if (!*count) {
20270 +               *index = end;
20271 +               return 0;
20272 +       }
20273 +
20274 +       /* have we lost some data? */
20275 +       if (idx < start)
20276 +               idx = start;
20277 +
20278 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20279 +               struct _vx_hist_entry *entry =
20280 +                       &hist->entry[idx % VXH_SIZE];
20281 +
20282 +               /* send entry to userspace */
20283 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20284 +               if (ret)
20285 +                       break;
20286 +       }
20287 +       /* save new index and count */
20288 +       *index = idx;
20289 +       *count = pos;
20290 +       return ret ? ret : (*index < end);
20291 +}
20292 +
20293 +int vc_read_history(uint32_t id, void __user *data)
20294 +{
20295 +       struct vcmd_read_history_v0 vc_data;
20296 +       int ret;
20297 +
20298 +       if (id >= NR_CPUS)
20299 +               return -EINVAL;
20300 +
20301 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20302 +               return -EFAULT;
20303 +
20304 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20305 +               id, &vc_data.index, &vc_data.count);
20306 +
20307 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20308 +               return -EFAULT;
20309 +       return ret;
20310 +}
20311 +
20312 +#ifdef CONFIG_COMPAT
20313 +
20314 +int vc_read_history_x32(uint32_t id, void __user *data)
20315 +{
20316 +       struct vcmd_read_history_v0_x32 vc_data;
20317 +       int ret;
20318 +
20319 +       if (id >= NR_CPUS)
20320 +               return -EINVAL;
20321 +
20322 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20323 +               return -EFAULT;
20324 +
20325 +       ret = do_read_history((struct __user _vx_hist_entry *)
20326 +               compat_ptr(vc_data.data_ptr),
20327 +               id, &vc_data.index, &vc_data.count);
20328 +
20329 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20330 +               return -EFAULT;
20331 +       return ret;
20332 +}
20333 +
20334 +#endif /* CONFIG_COMPAT */
20335 +
20336 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/inet.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/inet.c
20337 --- linux-2.6.27.6/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
20338 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/inet.c     2008-10-13 14:54:20.000000000 +0200
20339 @@ -0,0 +1,225 @@
20340 +
20341 +#include <linux/in.h>
20342 +#include <linux/inetdevice.h>
20343 +#include <linux/vs_inet.h>
20344 +#include <linux/vs_inet6.h>
20345 +#include <linux/vserver/debug.h>
20346 +#include <net/route.h>
20347 +#include <net/addrconf.h>
20348 +
20349 +
20350 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20351 +{
20352 +       int ret = 0;
20353 +
20354 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20355 +               ret = 1;
20356 +       else {
20357 +               struct nx_addr_v4 *ptr;
20358 +
20359 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20360 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20361 +                               ret = 1;
20362 +                               break;
20363 +                       }
20364 +               }
20365 +       }
20366 +
20367 +       vxdprintk(VXD_CBIT(net, 2),
20368 +               "nx_v4_addr_conflict(%p,%p): %d",
20369 +               nxi1, nxi2, ret);
20370 +
20371 +       return ret;
20372 +}
20373 +
20374 +
20375 +#ifdef CONFIG_IPV6
20376 +
20377 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20378 +{
20379 +       int ret = 0;
20380 +
20381 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20382 +               ret = 1;
20383 +       else {
20384 +               struct nx_addr_v6 *ptr;
20385 +
20386 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20387 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20388 +                               ret = 1;
20389 +                               break;
20390 +                       }
20391 +               }
20392 +       }
20393 +
20394 +       vxdprintk(VXD_CBIT(net, 2),
20395 +               "nx_v6_addr_conflict(%p,%p): %d",
20396 +               nxi1, nxi2, ret);
20397 +
20398 +       return ret;
20399 +}
20400 +
20401 +#endif
20402 +
20403 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20404 +{
20405 +       struct in_device *in_dev;
20406 +       struct in_ifaddr **ifap;
20407 +       struct in_ifaddr *ifa;
20408 +       int ret = 0;
20409 +
20410 +       if (!dev)
20411 +               goto out;
20412 +       in_dev = in_dev_get(dev);
20413 +       if (!in_dev)
20414 +               goto out;
20415 +
20416 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20417 +               ifap = &ifa->ifa_next) {
20418 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20419 +                       ret = 1;
20420 +                       break;
20421 +               }
20422 +       }
20423 +       in_dev_put(in_dev);
20424 +out:
20425 +       return ret;
20426 +}
20427 +
20428 +
20429 +#ifdef CONFIG_IPV6
20430 +
20431 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20432 +{
20433 +       struct inet6_dev *in_dev;
20434 +       struct inet6_ifaddr **ifap;
20435 +       struct inet6_ifaddr *ifa;
20436 +       int ret = 0;
20437 +
20438 +       if (!dev)
20439 +               goto out;
20440 +       in_dev = in6_dev_get(dev);
20441 +       if (!in_dev)
20442 +               goto out;
20443 +
20444 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20445 +               ifap = &ifa->if_next) {
20446 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20447 +                       ret = 1;
20448 +                       break;
20449 +               }
20450 +       }
20451 +       in6_dev_put(in_dev);
20452 +out:
20453 +       return ret;
20454 +}
20455 +
20456 +#endif
20457 +
20458 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20459 +{
20460 +       int ret = 1;
20461 +
20462 +       if (!nxi)
20463 +               goto out;
20464 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20465 +               goto out;
20466 +#ifdef CONFIG_IPV6
20467 +       ret = 2;
20468 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20469 +               goto out;
20470 +#endif
20471 +       ret = 0;
20472 +out:
20473 +       vxdprintk(VXD_CBIT(net, 3),
20474 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20475 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20476 +       return ret;
20477 +}
20478 +
20479 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20480 +       struct rtable **rp, struct flowi *fl)
20481 +{
20482 +       if (!nxi)
20483 +               return 0;
20484 +
20485 +       /* FIXME: handle lback only case */
20486 +       if (!NX_IPV4(nxi))
20487 +               return -EPERM;
20488 +
20489 +       vxdprintk(VXD_CBIT(net, 4),
20490 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20491 +               nxi, nxi ? nxi->nx_id : 0,
20492 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20493 +
20494 +       /* single IP is unconditional */
20495 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20496 +               (fl->fl4_src == INADDR_ANY))
20497 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20498 +
20499 +       if (fl->fl4_src == INADDR_ANY) {
20500 +               struct nx_addr_v4 *ptr;
20501 +               __be32 found = 0;
20502 +               int err;
20503 +
20504 +               err = __ip_route_output_key(net, rp, fl);
20505 +               if (!err) {
20506 +                       found = (*rp)->rt_src;
20507 +                       ip_rt_put(*rp);
20508 +                       vxdprintk(VXD_CBIT(net, 4),
20509 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20510 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20511 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20512 +                               goto found;
20513 +               }
20514 +
20515 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20516 +                       __be32 primary = ptr->ip[0].s_addr;
20517 +                       __be32 mask = ptr->mask.s_addr;
20518 +                       __be32 neta = primary & mask;
20519 +
20520 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20521 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20522 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20523 +                               NIPQUAD(mask), NIPQUAD(neta));
20524 +                       if ((found & mask) != neta)
20525 +                               continue;
20526 +
20527 +                       fl->fl4_src = primary;
20528 +                       err = __ip_route_output_key(net, rp, fl);
20529 +                       vxdprintk(VXD_CBIT(net, 4),
20530 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20531 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20532 +                       if (!err) {
20533 +                               found = (*rp)->rt_src;
20534 +                               ip_rt_put(*rp);
20535 +                               if (found == primary)
20536 +                                       goto found;
20537 +                       }
20538 +               }
20539 +               /* still no source ip? */
20540 +               found = ipv4_is_loopback(fl->fl4_dst)
20541 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20542 +       found:
20543 +               /* assign src ip to flow */
20544 +               fl->fl4_src = found;
20545 +
20546 +       } else {
20547 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20548 +                       return -EPERM;
20549 +       }
20550 +
20551 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20552 +               if (ipv4_is_loopback(fl->fl4_dst))
20553 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20554 +               if (ipv4_is_loopback(fl->fl4_src))
20555 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20556 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20557 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20558 +               return -EPERM;
20559 +
20560 +       return 0;
20561 +}
20562 +
20563 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20564 +
20565 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/init.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/init.c
20566 --- linux-2.6.27.6/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
20567 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/init.c     2008-10-13 14:54:20.000000000 +0200
20568 @@ -0,0 +1,45 @@
20569 +/*
20570 + *  linux/kernel/init.c
20571 + *
20572 + *  Virtual Server Init
20573 + *
20574 + *  Copyright (C) 2004-2007  Herbert Pötzl
20575 + *
20576 + *  V0.01  basic structure
20577 + *
20578 + */
20579 +
20580 +#include <linux/init.h>
20581 +
20582 +int    vserver_register_sysctl(void);
20583 +void   vserver_unregister_sysctl(void);
20584 +
20585 +
20586 +static int __init init_vserver(void)
20587 +{
20588 +       int ret = 0;
20589 +
20590 +#ifdef CONFIG_VSERVER_DEBUG
20591 +       vserver_register_sysctl();
20592 +#endif
20593 +       return ret;
20594 +}
20595 +
20596 +
20597 +static void __exit exit_vserver(void)
20598 +{
20599 +
20600 +#ifdef CONFIG_VSERVER_DEBUG
20601 +       vserver_unregister_sysctl();
20602 +#endif
20603 +       return;
20604 +}
20605 +
20606 +/* FIXME: GFP_ZONETYPES gone
20607 +long vx_slab[GFP_ZONETYPES]; */
20608 +long vx_area;
20609 +
20610 +
20611 +module_init(init_vserver);
20612 +module_exit(exit_vserver);
20613 +
20614 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/inode.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/inode.c
20615 --- linux-2.6.27.6/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
20616 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/inode.c    2008-10-24 03:34:52.000000000 +0200
20617 @@ -0,0 +1,422 @@
20618 +/*
20619 + *  linux/kernel/vserver/inode.c
20620 + *
20621 + *  Virtual Server: File System Support
20622 + *
20623 + *  Copyright (C) 2004-2007  Herbert Pötzl
20624 + *
20625 + *  V0.01  separated from vcontext V0.05
20626 + *  V0.02  moved to tag (instead of xid)
20627 + *
20628 + */
20629 +
20630 +#include <linux/tty.h>
20631 +#include <linux/proc_fs.h>
20632 +#include <linux/devpts_fs.h>
20633 +#include <linux/fs.h>
20634 +#include <linux/file.h>
20635 +#include <linux/mount.h>
20636 +#include <linux/parser.h>
20637 +#include <linux/namei.h>
20638 +#include <linux/vserver/inode.h>
20639 +#include <linux/vserver/inode_cmd.h>
20640 +#include <linux/vs_base.h>
20641 +#include <linux/vs_tag.h>
20642 +
20643 +#include <asm/uaccess.h>
20644 +
20645 +
20646 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20647 +{
20648 +       struct proc_dir_entry *entry;
20649 +
20650 +       if (!in || !in->i_sb)
20651 +               return -ESRCH;
20652 +
20653 +       *flags = IATTR_TAG
20654 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20655 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20656 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20657 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20658 +
20659 +       if (S_ISDIR(in->i_mode))
20660 +               *mask |= IATTR_BARRIER;
20661 +
20662 +       if (IS_TAGGED(in)) {
20663 +               *tag = in->i_tag;
20664 +               *mask |= IATTR_TAG;
20665 +       }
20666 +
20667 +       switch (in->i_sb->s_magic) {
20668 +       case PROC_SUPER_MAGIC:
20669 +               entry = PROC_I(in)->pde;
20670 +
20671 +               /* check for specific inodes? */
20672 +               if (entry)
20673 +                       *mask |= IATTR_FLAGS;
20674 +               if (entry)
20675 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20676 +               else
20677 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20678 +               break;
20679 +
20680 +       case DEVPTS_SUPER_MAGIC:
20681 +               *tag = in->i_tag;
20682 +               *mask |= IATTR_TAG;
20683 +               break;
20684 +
20685 +       default:
20686 +               break;
20687 +       }
20688 +       return 0;
20689 +}
20690 +
20691 +int vc_get_iattr(void __user *data)
20692 +{
20693 +       struct path path;
20694 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20695 +       int ret;
20696 +
20697 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20698 +               return -EFAULT;
20699 +
20700 +       ret = user_lpath(vc_data.name, &path);
20701 +       if (!ret) {
20702 +               ret = __vc_get_iattr(path.dentry->d_inode,
20703 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20704 +               path_put(&path);
20705 +       }
20706 +       if (ret)
20707 +               return ret;
20708 +
20709 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20710 +               ret = -EFAULT;
20711 +       return ret;
20712 +}
20713 +
20714 +#ifdef CONFIG_COMPAT
20715 +
20716 +int vc_get_iattr_x32(void __user *data)
20717 +{
20718 +       struct path path;
20719 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20720 +       int ret;
20721 +
20722 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20723 +               return -EFAULT;
20724 +
20725 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20726 +       if (!ret) {
20727 +               ret = __vc_get_iattr(path.dentry->d_inode,
20728 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20729 +               path_put(&path);
20730 +       }
20731 +       if (ret)
20732 +               return ret;
20733 +
20734 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20735 +               ret = -EFAULT;
20736 +       return ret;
20737 +}
20738 +
20739 +#endif /* CONFIG_COMPAT */
20740 +
20741 +
20742 +int vc_fget_iattr(uint32_t fd, void __user *data)
20743 +{
20744 +       struct file *filp;
20745 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20746 +       int ret;
20747 +
20748 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20749 +               return -EFAULT;
20750 +
20751 +       filp = fget(fd);
20752 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20753 +               return -EBADF;
20754 +
20755 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20756 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20757 +
20758 +       fput(filp);
20759 +
20760 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20761 +               ret = -EFAULT;
20762 +       return ret;
20763 +}
20764 +
20765 +
20766 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20767 +{
20768 +       struct inode *in = de->d_inode;
20769 +       int error = 0, is_proc = 0, has_tag = 0;
20770 +       struct iattr attr = { 0 };
20771 +
20772 +       if (!in || !in->i_sb)
20773 +               return -ESRCH;
20774 +
20775 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20776 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20777 +               return -EINVAL;
20778 +
20779 +       has_tag = IS_TAGGED(in) ||
20780 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20781 +       if ((*mask & IATTR_TAG) && !has_tag)
20782 +               return -EINVAL;
20783 +
20784 +       mutex_lock(&in->i_mutex);
20785 +       if (*mask & IATTR_TAG) {
20786 +               attr.ia_tag = *tag;
20787 +               attr.ia_valid |= ATTR_TAG;
20788 +       }
20789 +
20790 +       if (*mask & IATTR_FLAGS) {
20791 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20792 +               unsigned int iflags = PROC_I(in)->vx_flags;
20793 +
20794 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20795 +                       | (*flags & IATTR_FLAGS);
20796 +               PROC_I(in)->vx_flags = iflags;
20797 +               if (entry)
20798 +                       entry->vx_flags = iflags;
20799 +       }
20800 +
20801 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20802 +               if (*mask & IATTR_IMMUTABLE) {
20803 +                       if (*flags & IATTR_IMMUTABLE)
20804 +                               in->i_flags |= S_IMMUTABLE;
20805 +                       else
20806 +                               in->i_flags &= ~S_IMMUTABLE;
20807 +               }
20808 +               if (*mask & IATTR_IXUNLINK) {
20809 +                       if (*flags & IATTR_IXUNLINK)
20810 +                               in->i_flags |= S_IXUNLINK;
20811 +                       else
20812 +                               in->i_flags &= ~S_IXUNLINK;
20813 +               }
20814 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20815 +                       if (*flags & IATTR_BARRIER)
20816 +                               in->i_vflags |= V_BARRIER;
20817 +                       else
20818 +                               in->i_vflags &= ~V_BARRIER;
20819 +               }
20820 +               if (in->i_op && in->i_op->sync_flags) {
20821 +                       error = in->i_op->sync_flags(in);
20822 +                       if (error)
20823 +                               goto out;
20824 +               }
20825 +       }
20826 +
20827 +       if (attr.ia_valid) {
20828 +               if (in->i_op && in->i_op->setattr)
20829 +                       error = in->i_op->setattr(de, &attr);
20830 +               else {
20831 +                       error = inode_change_ok(in, &attr);
20832 +                       if (!error)
20833 +                               error = inode_setattr(in, &attr);
20834 +               }
20835 +       }
20836 +
20837 +out:
20838 +       mutex_unlock(&in->i_mutex);
20839 +       return error;
20840 +}
20841 +
20842 +int vc_set_iattr(void __user *data)
20843 +{
20844 +       struct path path;
20845 +       struct vcmd_ctx_iattr_v1 vc_data;
20846 +       int ret;
20847 +
20848 +       if (!capable(CAP_LINUX_IMMUTABLE))
20849 +               return -EPERM;
20850 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20851 +               return -EFAULT;
20852 +
20853 +       ret = user_lpath(vc_data.name, &path);
20854 +       if (!ret) {
20855 +               ret = __vc_set_iattr(path.dentry,
20856 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20857 +               path_put(&path);
20858 +       }
20859 +
20860 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20861 +               ret = -EFAULT;
20862 +       return ret;
20863 +}
20864 +
20865 +#ifdef CONFIG_COMPAT
20866 +
20867 +int vc_set_iattr_x32(void __user *data)
20868 +{
20869 +       struct path path;
20870 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20871 +       int ret;
20872 +
20873 +       if (!capable(CAP_LINUX_IMMUTABLE))
20874 +               return -EPERM;
20875 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20876 +               return -EFAULT;
20877 +
20878 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20879 +       if (!ret) {
20880 +               ret = __vc_set_iattr(path.dentry,
20881 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20882 +               path_put(&path);
20883 +       }
20884 +
20885 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20886 +               ret = -EFAULT;
20887 +       return ret;
20888 +}
20889 +
20890 +#endif /* CONFIG_COMPAT */
20891 +
20892 +int vc_fset_iattr(uint32_t fd, void __user *data)
20893 +{
20894 +       struct file *filp;
20895 +       struct vcmd_ctx_fiattr_v0 vc_data;
20896 +       int ret;
20897 +
20898 +       if (!capable(CAP_LINUX_IMMUTABLE))
20899 +               return -EPERM;
20900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20901 +               return -EFAULT;
20902 +
20903 +       filp = fget(fd);
20904 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20905 +               return -EBADF;
20906 +
20907 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20908 +               &vc_data.flags, &vc_data.mask);
20909 +
20910 +       fput(filp);
20911 +
20912 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20913 +               return -EFAULT;
20914 +       return ret;
20915 +}
20916 +
20917 +
20918 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20919 +
20920 +static match_table_t tokens = {
20921 +       {Opt_notagcheck, "notagcheck"},
20922 +#ifdef CONFIG_PROPAGATE
20923 +       {Opt_notag, "notag"},
20924 +       {Opt_tag, "tag"},
20925 +       {Opt_tagid, "tagid=%u"},
20926 +#endif
20927 +       {Opt_err, NULL}
20928 +};
20929 +
20930 +
20931 +static void __dx_parse_remove(char *string, char *opt)
20932 +{
20933 +       char *p = strstr(string, opt);
20934 +       char *q = p;
20935 +
20936 +       if (p) {
20937 +               while (*q != '\0' && *q != ',')
20938 +                       q++;
20939 +               while (*q)
20940 +                       *p++ = *q++;
20941 +               while (*p)
20942 +                       *p++ = '\0';
20943 +       }
20944 +}
20945 +
20946 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20947 +                unsigned long *flags)
20948 +{
20949 +       int set = 0;
20950 +       substring_t args[MAX_OPT_ARGS];
20951 +       int token, option = 0;
20952 +       char *s, *p, *opts;
20953 +
20954 +       if (!string)
20955 +               return 0;
20956 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20957 +       if (!s)
20958 +               return 0;
20959 +
20960 +       opts = s;
20961 +       while ((p = strsep(&opts, ",")) != NULL) {
20962 +               token = match_token(p, tokens, args);
20963 +
20964 +               vxdprintk(VXD_CBIT(tag, 7),
20965 +                       "dx_parse_tag(»%s«): %d:#%d",
20966 +                       p, token, option);
20967 +
20968 +               switch (token) {
20969 +#ifdef CONFIG_PROPAGATE
20970 +               case Opt_tag:
20971 +                       if (tag)
20972 +                               *tag = 0;
20973 +                       if (remove)
20974 +                               __dx_parse_remove(s, "tag");
20975 +                       *mnt_flags |= MNT_TAGID;
20976 +                       set |= MNT_TAGID;
20977 +                       break;
20978 +               case Opt_notag:
20979 +                       if (remove)
20980 +                               __dx_parse_remove(s, "notag");
20981 +                       *mnt_flags |= MNT_NOTAG;
20982 +                       set |= MNT_NOTAG;
20983 +                       break;
20984 +               case Opt_tagid:
20985 +                       if (tag && !match_int(args, &option))
20986 +                               *tag = option;
20987 +                       if (remove)
20988 +                               __dx_parse_remove(s, "tagid");
20989 +                       *mnt_flags |= MNT_TAGID;
20990 +                       set |= MNT_TAGID;
20991 +                       break;
20992 +#endif
20993 +               case Opt_notagcheck:
20994 +                       if (remove)
20995 +                               __dx_parse_remove(s, "notagcheck");
20996 +                       *flags |= MS_NOTAGCHECK;
20997 +                       set |= MS_NOTAGCHECK;
20998 +                       break;
20999 +               }
21000 +       }
21001 +       if (set)
21002 +               strcpy(string, s);
21003 +       kfree(s);
21004 +       return set;
21005 +}
21006 +
21007 +#ifdef CONFIG_PROPAGATE
21008 +
21009 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21010 +{
21011 +       tag_t new_tag = 0;
21012 +       struct vfsmount *mnt;
21013 +       int propagate;
21014 +
21015 +       if (!nd)
21016 +               return;
21017 +       mnt = nd->path.mnt;
21018 +       if (!mnt)
21019 +               return;
21020 +
21021 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21022 +       if (propagate)
21023 +               new_tag = mnt->mnt_tag;
21024 +
21025 +       vxdprintk(VXD_CBIT(tag, 7),
21026 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21027 +               inode, inode->i_ino, inode->i_tag,
21028 +               new_tag, (propagate) ? 1 : 0);
21029 +
21030 +       if (propagate)
21031 +               inode->i_tag = new_tag;
21032 +}
21033 +
21034 +#include <linux/module.h>
21035 +
21036 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21037 +
21038 +#endif /* CONFIG_PROPAGATE */
21039 +
21040 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/Kconfig linux-2.6.27.6-vs2.3.0.36/kernel/vserver/Kconfig
21041 --- linux-2.6.27.6/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
21042 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/Kconfig    2008-10-13 14:54:20.000000000 +0200
21043 @@ -0,0 +1,251 @@
21044 +#
21045 +# Linux VServer configuration
21046 +#
21047 +
21048 +menu "Linux VServer"
21049 +
21050 +config VSERVER_AUTO_LBACK
21051 +       bool    "Automatically Assign Loopback IP"
21052 +       default y
21053 +       help
21054 +         Automatically assign a guest specific loopback
21055 +         IP and add it to the kernel network stack on
21056 +         startup.
21057 +
21058 +config VSERVER_AUTO_SINGLE
21059 +       bool    "Automatic Single IP Special Casing"
21060 +       depends on EXPERIMENTAL
21061 +       default y
21062 +       help
21063 +         This allows network contexts with a single IP to
21064 +         automatically remap 0.0.0.0 bindings to that IP,
21065 +         avoiding further network checks and improving
21066 +         performance.
21067 +
21068 +         (note: such guests do not allow to change the ip
21069 +          on the fly and do not show loopback addresses)
21070 +
21071 +config VSERVER_COWBL
21072 +       bool    "Enable COW Immutable Link Breaking"
21073 +       default y
21074 +       help
21075 +         This enables the COW (Copy-On-Write) link break code.
21076 +         It allows you to treat unified files like normal files
21077 +         when writing to them (which will implicitely break the
21078 +         link and create a copy of the unified file)
21079 +
21080 +config VSERVER_VTIME
21081 +       bool    "Enable Virtualized Guest Time"
21082 +       depends on EXPERIMENTAL
21083 +       default n
21084 +       help
21085 +         This enables per guest time offsets to allow for
21086 +         adjusting the system clock individually per guest.
21087 +         this adds some overhead to the time functions and
21088 +         therefore should not be enabled without good reason.
21089 +
21090 +config VSERVER_DEVICE
21091 +       bool    "Enable Guest Device Mapping"
21092 +       depends on EXPERIMENTAL
21093 +       default n
21094 +       help
21095 +         This enables generic device remapping.
21096 +
21097 +config VSERVER_PROC_SECURE
21098 +       bool    "Enable Proc Security"
21099 +       depends on PROC_FS
21100 +       default y
21101 +       help
21102 +         This configures ProcFS security to initially hide
21103 +         non-process entries for all contexts except the main and
21104 +         spectator context (i.e. for all guests), which is a secure
21105 +         default.
21106 +
21107 +         (note: on 1.2x the entries were visible by default)
21108 +
21109 +config VSERVER_HARDCPU
21110 +       bool    "Enable Hard CPU Limits"
21111 +       default y
21112 +       help
21113 +         Activate the Hard CPU Limits
21114 +
21115 +         This will compile in code that allows the Token Bucket
21116 +         Scheduler to put processes on hold when a context's
21117 +         tokens are depleted (provided that its per-context
21118 +         sched_hard flag is set).
21119 +
21120 +         Processes belonging to that context will not be able
21121 +         to consume CPU resources again until a per-context
21122 +         configured minimum of tokens has been reached.
21123 +
21124 +config VSERVER_IDLETIME
21125 +       bool    "Avoid idle CPUs by skipping Time"
21126 +       depends on VSERVER_HARDCPU
21127 +       default y
21128 +       help
21129 +         This option allows the scheduler to artificially
21130 +         advance time (per cpu) when otherwise the idle
21131 +         task would be scheduled, thus keeping the cpu
21132 +         busy and sharing the available resources among
21133 +         certain contexts.
21134 +
21135 +config VSERVER_IDLELIMIT
21136 +       bool    "Limit the IDLE task"
21137 +       depends on VSERVER_HARDCPU
21138 +       default n
21139 +       help
21140 +         Limit the idle slices, so the the next context
21141 +         will be scheduled as soon as possible.
21142 +
21143 +         This might improve interactivity and latency, but
21144 +         will also marginally increase scheduling overhead.
21145 +
21146 +choice
21147 +       prompt  "Persistent Inode Tagging"
21148 +       default TAGGING_ID24
21149 +       help
21150 +         This adds persistent context information to filesystems
21151 +         mounted with the tagxid option. Tagging is a requirement
21152 +         for per-context disk limits and per-context quota.
21153 +
21154 +
21155 +config TAGGING_NONE
21156 +       bool    "Disabled"
21157 +       help
21158 +         do not store per-context information in inodes.
21159 +
21160 +config TAGGING_UID16
21161 +       bool    "UID16/GID32"
21162 +       help
21163 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21164 +
21165 +config TAGGING_GID16
21166 +       bool    "UID32/GID16"
21167 +       help
21168 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21169 +
21170 +config TAGGING_ID24
21171 +       bool    "UID24/GID24"
21172 +       help
21173 +         uses the upper 8bit from UID and GID for XID tagging
21174 +         which leaves 24bit for UID/GID each, which should be
21175 +         more than sufficient for normal use.
21176 +
21177 +config TAGGING_INTERN
21178 +       bool    "UID32/GID32"
21179 +       help
21180 +         this uses otherwise reserved inode fields in the on
21181 +         disk representation, which limits the use to a few
21182 +         filesystems (currently ext2 and ext3)
21183 +
21184 +endchoice
21185 +
21186 +config TAG_NFSD
21187 +       bool    "Tag NFSD User Auth and Files"
21188 +       default n
21189 +       help
21190 +         Enable this if you do want the in-kernel NFS
21191 +         Server to use the tagging specified above.
21192 +         (will require patched clients too)
21193 +
21194 +config VSERVER_PRIVACY
21195 +       bool    "Honor Privacy Aspects of Guests"
21196 +       default n
21197 +       help
21198 +         When enabled, most context checks will disallow
21199 +         access to structures assigned to a specific context,
21200 +         like ptys or loop devices.
21201 +
21202 +config VSERVER_CONTEXTS
21203 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21204 +       range 1 65533
21205 +       default "768"   if 64BIT
21206 +       default "256"
21207 +       help
21208 +         This setting will optimize certain data structures
21209 +         and memory allocations according to the expected
21210 +         maximum.
21211 +
21212 +         note: this is not a strict upper limit.
21213 +
21214 +config VSERVER_WARN
21215 +       bool    "VServer Warnings"
21216 +       default y
21217 +       help
21218 +         This enables various runtime warnings, which will
21219 +         notify about potential manipulation attempts or
21220 +         resource shortage. It is generally considered to
21221 +         be a good idea to have that enabled.
21222 +
21223 +config VSERVER_DEBUG
21224 +       bool    "VServer Debugging Code"
21225 +       default n
21226 +       help
21227 +         Set this to yes if you want to be able to activate
21228 +         debugging output at runtime. It adds a very small
21229 +         overhead to all vserver related functions and
21230 +         increases the kernel size by about 20k.
21231 +
21232 +config VSERVER_HISTORY
21233 +       bool    "VServer History Tracing"
21234 +       depends on VSERVER_DEBUG
21235 +       default n
21236 +       help
21237 +         Set this to yes if you want to record the history of
21238 +         linux-vserver activities, so they can be replayed in
21239 +         the event of a kernel panic or oops.
21240 +
21241 +config VSERVER_HISTORY_SIZE
21242 +       int     "Per-CPU History Size (32-65536)"
21243 +       depends on VSERVER_HISTORY
21244 +       range 32 65536
21245 +       default 64
21246 +       help
21247 +         This allows you to specify the number of entries in
21248 +         the per-CPU history buffer.
21249 +
21250 +config VSERVER_MONITOR
21251 +       bool    "VServer Scheduling Monitor"
21252 +       depends on VSERVER_DISABLED
21253 +       default n
21254 +       help
21255 +         Set this to yes if you want to record the scheduling
21256 +         decisions, so that they can be relayed to userspace
21257 +         for detailed analysis.
21258 +
21259 +config VSERVER_MONITOR_SIZE
21260 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21261 +       depends on VSERVER_MONITOR
21262 +       range 32 65536
21263 +       default 1024
21264 +       help
21265 +         This allows you to specify the number of entries in
21266 +         the per-CPU scheduling monitor buffer.
21267 +
21268 +config VSERVER_MONITOR_SYNC
21269 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21270 +       depends on VSERVER_MONITOR
21271 +       range 0 65536
21272 +       default 256
21273 +       help
21274 +         This allows you to specify the interval in ticks
21275 +         when a time sync entry is inserted.
21276 +
21277 +endmenu
21278 +
21279 +
21280 +config VSERVER
21281 +       bool
21282 +       default y
21283 +       select NAMESPACES
21284 +       select UTS_NS
21285 +       select IPC_NS
21286 +       select USER_NS
21287 +       select SYSVIPC
21288 +
21289 +config VSERVER_SECURITY
21290 +       bool
21291 +       depends on SECURITY
21292 +       default y
21293 +       select SECURITY_CAPABILITIES
21294 +
21295 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/limit.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/limit.c
21296 --- linux-2.6.27.6/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
21297 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/limit.c    2008-10-13 14:54:20.000000000 +0200
21298 @@ -0,0 +1,319 @@
21299 +/*
21300 + *  linux/kernel/vserver/limit.c
21301 + *
21302 + *  Virtual Server: Context Limits
21303 + *
21304 + *  Copyright (C) 2004-2007  Herbert Pötzl
21305 + *
21306 + *  V0.01  broken out from vcontext V0.05
21307 + *  V0.02  changed vcmds to vxi arg
21308 + *
21309 + */
21310 +
21311 +#include <linux/sched.h>
21312 +#include <linux/module.h>
21313 +#include <linux/vs_limit.h>
21314 +#include <linux/vserver/limit.h>
21315 +#include <linux/vserver/limit_cmd.h>
21316 +
21317 +#include <asm/uaccess.h>
21318 +
21319 +
21320 +const char *vlimit_name[NUM_LIMITS] = {
21321 +       [RLIMIT_CPU]            = "CPU",
21322 +       [RLIMIT_RSS]            = "RSS",
21323 +       [RLIMIT_NPROC]          = "NPROC",
21324 +       [RLIMIT_NOFILE]         = "NOFILE",
21325 +       [RLIMIT_MEMLOCK]        = "VML",
21326 +       [RLIMIT_AS]             = "VM",
21327 +       [RLIMIT_LOCKS]          = "LOCKS",
21328 +       [RLIMIT_SIGPENDING]     = "SIGP",
21329 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21330 +
21331 +       [VLIMIT_NSOCK]          = "NSOCK",
21332 +       [VLIMIT_OPENFD]         = "OPENFD",
21333 +       [VLIMIT_ANON]           = "ANON",
21334 +       [VLIMIT_SHMEM]          = "SHMEM",
21335 +       [VLIMIT_DENTRY]         = "DENTRY",
21336 +};
21337 +
21338 +EXPORT_SYMBOL_GPL(vlimit_name);
21339 +
21340 +#define MASK_ENTRY(x)  (1 << (x))
21341 +
21342 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21343 +               /* minimum */
21344 +       0
21345 +       ,       /* softlimit */
21346 +       MASK_ENTRY( RLIMIT_RSS          ) |
21347 +       MASK_ENTRY( VLIMIT_ANON         ) |
21348 +       0
21349 +       ,       /* maximum */
21350 +       MASK_ENTRY( RLIMIT_RSS          ) |
21351 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21352 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21353 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21354 +       MASK_ENTRY( RLIMIT_AS           ) |
21355 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21356 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21357 +
21358 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21359 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21360 +       MASK_ENTRY( VLIMIT_ANON         ) |
21361 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21362 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21363 +       0
21364 +};
21365 +               /* accounting only */
21366 +uint32_t account_mask =
21367 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21368 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21369 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21370 +       0;
21371 +
21372 +
21373 +static int is_valid_vlimit(int id)
21374 +{
21375 +       uint32_t mask = vlimit_mask.minimum |
21376 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21377 +       return mask & (1 << id);
21378 +}
21379 +
21380 +static int is_accounted_vlimit(int id)
21381 +{
21382 +       if (is_valid_vlimit(id))
21383 +               return 1;
21384 +       return account_mask & (1 << id);
21385 +}
21386 +
21387 +
21388 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21389 +{
21390 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21391 +       return VX_VLIM(limit);
21392 +}
21393 +
21394 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21395 +{
21396 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21397 +       return VX_VLIM(limit);
21398 +}
21399 +
21400 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21401 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21402 +{
21403 +       if (!is_valid_vlimit(id))
21404 +               return -EINVAL;
21405 +
21406 +       if (minimum)
21407 +               *minimum = CRLIM_UNSET;
21408 +       if (softlimit)
21409 +               *softlimit = vc_get_soft(vxi, id);
21410 +       if (maximum)
21411 +               *maximum = vc_get_hard(vxi, id);
21412 +       return 0;
21413 +}
21414 +
21415 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21416 +{
21417 +       struct vcmd_ctx_rlimit_v0 vc_data;
21418 +       int ret;
21419 +
21420 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21421 +               return -EFAULT;
21422 +
21423 +       ret = do_get_rlimit(vxi, vc_data.id,
21424 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21425 +       if (ret)
21426 +               return ret;
21427 +
21428 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21429 +               return -EFAULT;
21430 +       return 0;
21431 +}
21432 +
21433 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21434 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21435 +{
21436 +       if (!is_valid_vlimit(id))
21437 +               return -EINVAL;
21438 +
21439 +       if (maximum != CRLIM_KEEP)
21440 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21441 +       if (softlimit != CRLIM_KEEP)
21442 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21443 +
21444 +       /* clamp soft limit */
21445 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21446 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21447 +
21448 +       return 0;
21449 +}
21450 +
21451 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21452 +{
21453 +       struct vcmd_ctx_rlimit_v0 vc_data;
21454 +
21455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21456 +               return -EFAULT;
21457 +
21458 +       return do_set_rlimit(vxi, vc_data.id,
21459 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21460 +}
21461 +
21462 +#ifdef CONFIG_IA32_EMULATION
21463 +
21464 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21465 +{
21466 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21467 +
21468 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21469 +               return -EFAULT;
21470 +
21471 +       return do_set_rlimit(vxi, vc_data.id,
21472 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21473 +}
21474 +
21475 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21476 +{
21477 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21478 +       int ret;
21479 +
21480 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21481 +               return -EFAULT;
21482 +
21483 +       ret = do_get_rlimit(vxi, vc_data.id,
21484 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21485 +       if (ret)
21486 +               return ret;
21487 +
21488 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21489 +               return -EFAULT;
21490 +       return 0;
21491 +}
21492 +
21493 +#endif /* CONFIG_IA32_EMULATION */
21494 +
21495 +
21496 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21497 +{
21498 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21499 +               return -EFAULT;
21500 +       return 0;
21501 +}
21502 +
21503 +
21504 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21505 +{
21506 +       rlim_t value;
21507 +       int lim;
21508 +
21509 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21510 +               value = __rlim_get(limit, lim);
21511 +               __rlim_rmax(limit, lim) = value;
21512 +               __rlim_rmin(limit, lim) = value;
21513 +       }
21514 +}
21515 +
21516 +
21517 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21518 +{
21519 +       vx_reset_minmax(&vxi->limit);
21520 +       return 0;
21521 +}
21522 +
21523 +
21524 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21525 +{
21526 +       struct vcmd_rlimit_stat_v0 vc_data;
21527 +       struct _vx_limit *limit = &vxi->limit;
21528 +       int id;
21529 +
21530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21531 +               return -EFAULT;
21532 +
21533 +       id = vc_data.id;
21534 +       if (!is_accounted_vlimit(id))
21535 +               return -EINVAL;
21536 +
21537 +       vx_limit_fixup(limit, id);
21538 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21539 +       vc_data.value = __rlim_get(limit, id);
21540 +       vc_data.minimum = __rlim_rmin(limit, id);
21541 +       vc_data.maximum = __rlim_rmax(limit, id);
21542 +
21543 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21544 +               return -EFAULT;
21545 +       return 0;
21546 +}
21547 +
21548 +
21549 +void vx_vsi_meminfo(struct sysinfo *val)
21550 +{
21551 +       struct vx_info *vxi = current->vx_info;
21552 +       unsigned long totalram, freeram;
21553 +       rlim_t v;
21554 +
21555 +       /* we blindly accept the max */
21556 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21557 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21558 +
21559 +       /* total minus used equals free */
21560 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21561 +       freeram = (v < totalram) ? totalram - v : 0;
21562 +
21563 +       val->totalram = totalram;
21564 +       val->freeram = freeram;
21565 +       val->bufferram = 0;
21566 +       val->totalhigh = 0;
21567 +       val->freehigh = 0;
21568 +       return;
21569 +}
21570 +
21571 +void vx_vsi_swapinfo(struct sysinfo *val)
21572 +{
21573 +       struct vx_info *vxi = current->vx_info;
21574 +       unsigned long totalswap, freeswap;
21575 +       rlim_t v, w;
21576 +
21577 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21578 +       if (v == RLIM_INFINITY) {
21579 +               val->freeswap = val->totalswap;
21580 +               return;
21581 +       }
21582 +
21583 +       /* we blindly accept the max */
21584 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21585 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21586 +
21587 +       /* currently 'used' swap */
21588 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21589 +       w -= (w > v) ? v : w;
21590 +
21591 +       /* total minus used equals free */
21592 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21593 +
21594 +       val->totalswap = totalswap;
21595 +       val->freeswap = freeswap;
21596 +       return;
21597 +}
21598 +
21599 +
21600 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21601 +{
21602 +       struct vx_info *vxi = mm->mm_vx_info;
21603 +       unsigned long points;
21604 +       rlim_t v, w;
21605 +
21606 +       if (!vxi)
21607 +               return 0;
21608 +
21609 +       points = vxi->vx_badness_bias;
21610 +
21611 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21612 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21613 +       points += (v > w) ? (v - w) : 0;
21614 +
21615 +       return points;
21616 +}
21617 +
21618 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/limit_init.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/limit_init.h
21619 --- linux-2.6.27.6/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
21620 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/limit_init.h       2008-10-13 14:54:20.000000000 +0200
21621 @@ -0,0 +1,31 @@
21622 +
21623 +
21624 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21625 +{
21626 +       int lim;
21627 +
21628 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21629 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21630 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21631 +               __rlim_set(limit, lim, 0);
21632 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21633 +               __rlim_rmin(limit, lim) = 0;
21634 +               __rlim_rmax(limit, lim) = 0;
21635 +       }
21636 +}
21637 +
21638 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21639 +{
21640 +       rlim_t value;
21641 +       int lim;
21642 +
21643 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21644 +               if ((1 << lim) & VLIM_NOCHECK)
21645 +                       continue;
21646 +               value = __rlim_get(limit, lim);
21647 +               vxwprintk_xid(value,
21648 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21649 +                       limit, vlimit_name[lim], lim, (long)value);
21650 +       }
21651 +}
21652 +
21653 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/limit_proc.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/limit_proc.h
21654 --- linux-2.6.27.6/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
21655 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/limit_proc.h       2008-10-13 14:54:20.000000000 +0200
21656 @@ -0,0 +1,57 @@
21657 +#ifndef _VX_LIMIT_PROC_H
21658 +#define _VX_LIMIT_PROC_H
21659 +
21660 +#include <linux/vserver/limit_int.h>
21661 +
21662 +
21663 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21664 +#define VX_LIMIT_TOP   \
21665 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21666 +
21667 +#define VX_LIMIT_ARG(r)                                \
21668 +       (unsigned long)__rlim_get(limit, r),    \
21669 +       (unsigned long)__rlim_rmin(limit, r),   \
21670 +       (unsigned long)__rlim_rmax(limit, r),   \
21671 +       VX_VLIM(__rlim_soft(limit, r)),         \
21672 +       VX_VLIM(__rlim_hard(limit, r)),         \
21673 +       atomic_read(&__rlim_lhit(limit, r))
21674 +
21675 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21676 +{
21677 +       vx_limit_fixup(limit, -1);
21678 +       return sprintf(buffer, VX_LIMIT_TOP
21679 +               "PROC"  VX_LIMIT_FMT
21680 +               "VM"    VX_LIMIT_FMT
21681 +               "VML"   VX_LIMIT_FMT
21682 +               "RSS"   VX_LIMIT_FMT
21683 +               "ANON"  VX_LIMIT_FMT
21684 +               "RMAP"  VX_LIMIT_FMT
21685 +               "FILES" VX_LIMIT_FMT
21686 +               "OFD"   VX_LIMIT_FMT
21687 +               "LOCKS" VX_LIMIT_FMT
21688 +               "SOCK"  VX_LIMIT_FMT
21689 +               "MSGQ"  VX_LIMIT_FMT
21690 +               "SHM"   VX_LIMIT_FMT
21691 +               "SEMA"  VX_LIMIT_FMT
21692 +               "SEMS"  VX_LIMIT_FMT
21693 +               "DENT"  VX_LIMIT_FMT,
21694 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21695 +               VX_LIMIT_ARG(RLIMIT_AS),
21696 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21697 +               VX_LIMIT_ARG(RLIMIT_RSS),
21698 +               VX_LIMIT_ARG(VLIMIT_ANON),
21699 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21700 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21701 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21702 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21703 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21704 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21705 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21706 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21707 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21708 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21709 +}
21710 +
21711 +#endif /* _VX_LIMIT_PROC_H */
21712 +
21713 +
21714 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/Makefile linux-2.6.27.6-vs2.3.0.36/kernel/vserver/Makefile
21715 --- linux-2.6.27.6/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
21716 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/Makefile   2008-10-13 14:54:20.000000000 +0200
21717 @@ -0,0 +1,18 @@
21718 +#
21719 +# Makefile for the Linux vserver routines.
21720 +#
21721 +
21722 +
21723 +obj-y          += vserver.o
21724 +
21725 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21726 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21727 +                  dlimit.o tag.o
21728 +
21729 +vserver-$(CONFIG_INET) += inet.o
21730 +vserver-$(CONFIG_PROC_FS) += proc.o
21731 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21732 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21733 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21734 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21735 +
21736 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/monitor.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/monitor.c
21737 --- linux-2.6.27.6/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
21738 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/monitor.c  2008-10-13 14:54:20.000000000 +0200
21739 @@ -0,0 +1,138 @@
21740 +/*
21741 + *  kernel/vserver/monitor.c
21742 + *
21743 + *  Virtual Context Scheduler Monitor
21744 + *
21745 + *  Copyright (C) 2006-2007 Herbert Pötzl
21746 + *
21747 + *  V0.01  basic design
21748 + *
21749 + */
21750 +
21751 +#include <linux/module.h>
21752 +#include <linux/jiffies.h>
21753 +#include <asm/uaccess.h>
21754 +#include <asm/atomic.h>
21755 +
21756 +#include <linux/vserver/monitor.h>
21757 +#include <linux/vserver/debug_cmd.h>
21758 +
21759 +
21760 +#ifdef CONFIG_VSERVER_MONITOR
21761 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21762 +#else
21763 +#define VXM_SIZE       64
21764 +#endif
21765 +
21766 +struct _vx_monitor {
21767 +       unsigned int counter;
21768 +
21769 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21770 +};
21771 +
21772 +
21773 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21774 +
21775 +unsigned volatile int vxm_active = 1;
21776 +
21777 +static atomic_t sequence = ATOMIC_INIT(0);
21778 +
21779 +
21780 +/*     vxm_advance()
21781 +
21782 +       * requires disabled preemption                          */
21783 +
21784 +struct _vx_mon_entry *vxm_advance(int cpu)
21785 +{
21786 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21787 +       struct _vx_mon_entry *entry;
21788 +       unsigned int index;
21789 +
21790 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21791 +       entry = &mon->entry[index];
21792 +
21793 +       entry->ev.seq = atomic_inc_return(&sequence);
21794 +       entry->ev.jif = jiffies;
21795 +       return entry;
21796 +}
21797 +
21798 +EXPORT_SYMBOL_GPL(vxm_advance);
21799 +
21800 +
21801 +int do_read_monitor(struct __user _vx_mon_entry *data,
21802 +       int cpu, uint32_t *index, uint32_t *count)
21803 +{
21804 +       int pos, ret = 0;
21805 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21806 +       int end = mon->counter;
21807 +       int start = end - VXM_SIZE + 2;
21808 +       int idx = *index;
21809 +
21810 +       /* special case: get current pos */
21811 +       if (!*count) {
21812 +               *index = end;
21813 +               return 0;
21814 +       }
21815 +
21816 +       /* have we lost some data? */
21817 +       if (idx < start)
21818 +               idx = start;
21819 +
21820 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21821 +               struct _vx_mon_entry *entry =
21822 +                       &mon->entry[idx % VXM_SIZE];
21823 +
21824 +               /* send entry to userspace */
21825 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21826 +               if (ret)
21827 +                       break;
21828 +       }
21829 +       /* save new index and count */
21830 +       *index = idx;
21831 +       *count = pos;
21832 +       return ret ? ret : (*index < end);
21833 +}
21834 +
21835 +int vc_read_monitor(uint32_t id, void __user *data)
21836 +{
21837 +       struct vcmd_read_monitor_v0 vc_data;
21838 +       int ret;
21839 +
21840 +       if (id >= NR_CPUS)
21841 +               return -EINVAL;
21842 +
21843 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21844 +               return -EFAULT;
21845 +
21846 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21847 +               id, &vc_data.index, &vc_data.count);
21848 +
21849 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21850 +               return -EFAULT;
21851 +       return ret;
21852 +}
21853 +
21854 +#ifdef CONFIG_COMPAT
21855 +
21856 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21857 +{
21858 +       struct vcmd_read_monitor_v0_x32 vc_data;
21859 +       int ret;
21860 +
21861 +       if (id >= NR_CPUS)
21862 +               return -EINVAL;
21863 +
21864 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21865 +               return -EFAULT;
21866 +
21867 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21868 +               compat_ptr(vc_data.data_ptr),
21869 +               id, &vc_data.index, &vc_data.count);
21870 +
21871 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21872 +               return -EFAULT;
21873 +       return ret;
21874 +}
21875 +
21876 +#endif /* CONFIG_COMPAT */
21877 +
21878 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/network.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/network.c
21879 --- linux-2.6.27.6/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
21880 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/network.c  2008-10-13 14:54:20.000000000 +0200
21881 @@ -0,0 +1,864 @@
21882 +/*
21883 + *  linux/kernel/vserver/network.c
21884 + *
21885 + *  Virtual Server: Network Support
21886 + *
21887 + *  Copyright (C) 2003-2007  Herbert Pötzl
21888 + *
21889 + *  V0.01  broken out from vcontext V0.05
21890 + *  V0.02  cleaned up implementation
21891 + *  V0.03  added equiv nx commands
21892 + *  V0.04  switch to RCU based hash
21893 + *  V0.05  and back to locking again
21894 + *  V0.06  changed vcmds to nxi arg
21895 + *  V0.07  have __create claim() the nxi
21896 + *
21897 + */
21898 +
21899 +#include <linux/err.h>
21900 +#include <linux/slab.h>
21901 +#include <linux/rcupdate.h>
21902 +
21903 +#include <linux/vs_network.h>
21904 +#include <linux/vs_pid.h>
21905 +#include <linux/vserver/network_cmd.h>
21906 +
21907 +
21908 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21909 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21910 +
21911 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21912 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21913 +
21914 +
21915 +static int __init init_network(void)
21916 +{
21917 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21918 +               sizeof(struct nx_addr_v4), 0,
21919 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21920 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21921 +               sizeof(struct nx_addr_v6), 0,
21922 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21923 +       return 0;
21924 +}
21925 +
21926 +
21927 +/*     __alloc_nx_addr_v4()                                    */
21928 +
21929 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21930 +{
21931 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21932 +               nx_addr_v4_cachep, GFP_KERNEL);
21933 +
21934 +       if (!IS_ERR(nxa))
21935 +               memset(nxa, 0, sizeof(*nxa));
21936 +       return nxa;
21937 +}
21938 +
21939 +/*     __dealloc_nx_addr_v4()                                  */
21940 +
21941 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21942 +{
21943 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21944 +}
21945 +
21946 +/*     __dealloc_nx_addr_v4_all()                              */
21947 +
21948 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21949 +{
21950 +       while (nxa) {
21951 +               struct nx_addr_v4 *next = nxa->next;
21952 +
21953 +               __dealloc_nx_addr_v4(nxa);
21954 +               nxa = next;
21955 +       }
21956 +}
21957 +
21958 +
21959 +#ifdef CONFIG_IPV6
21960 +
21961 +/*     __alloc_nx_addr_v6()                                    */
21962 +
21963 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21964 +{
21965 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21966 +               nx_addr_v6_cachep, GFP_KERNEL);
21967 +
21968 +       if (!IS_ERR(nxa))
21969 +               memset(nxa, 0, sizeof(*nxa));
21970 +       return nxa;
21971 +}
21972 +
21973 +/*     __dealloc_nx_addr_v6()                                  */
21974 +
21975 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21976 +{
21977 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21978 +}
21979 +
21980 +/*     __dealloc_nx_addr_v6_all()                              */
21981 +
21982 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21983 +{
21984 +       while (nxa) {
21985 +               struct nx_addr_v6 *next = nxa->next;
21986 +
21987 +               __dealloc_nx_addr_v6(nxa);
21988 +               nxa = next;
21989 +       }
21990 +}
21991 +
21992 +#endif /* CONFIG_IPV6 */
21993 +
21994 +/*     __alloc_nx_info()
21995 +
21996 +       * allocate an initialized nx_info struct
21997 +       * doesn't make it visible (hash)                        */
21998 +
21999 +static struct nx_info *__alloc_nx_info(nid_t nid)
22000 +{
22001 +       struct nx_info *new = NULL;
22002 +
22003 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22004 +
22005 +       /* would this benefit from a slab cache? */
22006 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22007 +       if (!new)
22008 +               return 0;
22009 +
22010 +       memset(new, 0, sizeof(struct nx_info));
22011 +       new->nx_id = nid;
22012 +       INIT_HLIST_NODE(&new->nx_hlist);
22013 +       atomic_set(&new->nx_usecnt, 0);
22014 +       atomic_set(&new->nx_tasks, 0);
22015 +       new->nx_state = 0;
22016 +
22017 +       new->nx_flags = NXF_INIT_SET;
22018 +
22019 +       /* rest of init goes here */
22020 +
22021 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22022 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22023 +
22024 +       vxdprintk(VXD_CBIT(nid, 0),
22025 +               "alloc_nx_info(%d) = %p", nid, new);
22026 +       atomic_inc(&nx_global_ctotal);
22027 +       return new;
22028 +}
22029 +
22030 +/*     __dealloc_nx_info()
22031 +
22032 +       * final disposal of nx_info                             */
22033 +
22034 +static void __dealloc_nx_info(struct nx_info *nxi)
22035 +{
22036 +       vxdprintk(VXD_CBIT(nid, 0),
22037 +               "dealloc_nx_info(%p)", nxi);
22038 +
22039 +       nxi->nx_hlist.next = LIST_POISON1;
22040 +       nxi->nx_id = -1;
22041 +
22042 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22043 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22044 +
22045 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22046 +
22047 +       nxi->nx_state |= NXS_RELEASED;
22048 +       kfree(nxi);
22049 +       atomic_dec(&nx_global_ctotal);
22050 +}
22051 +
22052 +static void __shutdown_nx_info(struct nx_info *nxi)
22053 +{
22054 +       nxi->nx_state |= NXS_SHUTDOWN;
22055 +       vs_net_change(nxi, VSC_NETDOWN);
22056 +}
22057 +
22058 +/*     exported stuff                                          */
22059 +
22060 +void free_nx_info(struct nx_info *nxi)
22061 +{
22062 +       /* context shutdown is mandatory */
22063 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22064 +
22065 +       /* context must not be hashed */
22066 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22067 +
22068 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22069 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22070 +
22071 +       __dealloc_nx_info(nxi);
22072 +}
22073 +
22074 +
22075 +void __nx_set_lback(struct nx_info *nxi)
22076 +{
22077 +       int nid = nxi->nx_id;
22078 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22079 +
22080 +       nxi->v4_lback.s_addr = lback;
22081 +}
22082 +
22083 +extern int __nx_inet_add_lback(__be32 addr);
22084 +extern int __nx_inet_del_lback(__be32 addr);
22085 +
22086 +
22087 +/*     hash table for nx_info hash */
22088 +
22089 +#define NX_HASH_SIZE   13
22090 +
22091 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22092 +
22093 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22094 +
22095 +
22096 +static inline unsigned int __hashval(nid_t nid)
22097 +{
22098 +       return (nid % NX_HASH_SIZE);
22099 +}
22100 +
22101 +
22102 +
22103 +/*     __hash_nx_info()
22104 +
22105 +       * add the nxi to the global hash table
22106 +       * requires the hash_lock to be held                     */
22107 +
22108 +static inline void __hash_nx_info(struct nx_info *nxi)
22109 +{
22110 +       struct hlist_head *head;
22111 +
22112 +       vxd_assert_lock(&nx_info_hash_lock);
22113 +       vxdprintk(VXD_CBIT(nid, 4),
22114 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22115 +
22116 +       /* context must not be hashed */
22117 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22118 +
22119 +       nxi->nx_state |= NXS_HASHED;
22120 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22121 +       hlist_add_head(&nxi->nx_hlist, head);
22122 +       atomic_inc(&nx_global_cactive);
22123 +}
22124 +
22125 +/*     __unhash_nx_info()
22126 +
22127 +       * remove the nxi from the global hash table
22128 +       * requires the hash_lock to be held                     */
22129 +
22130 +static inline void __unhash_nx_info(struct nx_info *nxi)
22131 +{
22132 +       vxd_assert_lock(&nx_info_hash_lock);
22133 +       vxdprintk(VXD_CBIT(nid, 4),
22134 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22135 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22136 +
22137 +       /* context must be hashed */
22138 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22139 +       /* but without tasks */
22140 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22141 +
22142 +       nxi->nx_state &= ~NXS_HASHED;
22143 +       hlist_del(&nxi->nx_hlist);
22144 +       atomic_dec(&nx_global_cactive);
22145 +}
22146 +
22147 +
22148 +/*     __lookup_nx_info()
22149 +
22150 +       * requires the hash_lock to be held
22151 +       * doesn't increment the nx_refcnt                       */
22152 +
22153 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22154 +{
22155 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22156 +       struct hlist_node *pos;
22157 +       struct nx_info *nxi;
22158 +
22159 +       vxd_assert_lock(&nx_info_hash_lock);
22160 +       hlist_for_each(pos, head) {
22161 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22162 +
22163 +               if (nxi->nx_id == nid)
22164 +                       goto found;
22165 +       }
22166 +       nxi = NULL;
22167 +found:
22168 +       vxdprintk(VXD_CBIT(nid, 0),
22169 +               "__lookup_nx_info(#%u): %p[#%u]",
22170 +               nid, nxi, nxi ? nxi->nx_id : 0);
22171 +       return nxi;
22172 +}
22173 +
22174 +
22175 +/*     __create_nx_info()
22176 +
22177 +       * create the requested context
22178 +       * get(), claim() and hash it                            */
22179 +
22180 +static struct nx_info *__create_nx_info(int id)
22181 +{
22182 +       struct nx_info *new, *nxi = NULL;
22183 +
22184 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22185 +
22186 +       if (!(new = __alloc_nx_info(id)))
22187 +               return ERR_PTR(-ENOMEM);
22188 +
22189 +       /* required to make dynamic xids unique */
22190 +       spin_lock(&nx_info_hash_lock);
22191 +
22192 +       /* static context requested */
22193 +       if ((nxi = __lookup_nx_info(id))) {
22194 +               vxdprintk(VXD_CBIT(nid, 0),
22195 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22196 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22197 +                       nxi = ERR_PTR(-EBUSY);
22198 +               else
22199 +                       nxi = ERR_PTR(-EEXIST);
22200 +               goto out_unlock;
22201 +       }
22202 +       /* new context */
22203 +       vxdprintk(VXD_CBIT(nid, 0),
22204 +               "create_nx_info(%d) = %p (new)", id, new);
22205 +       claim_nx_info(new, NULL);
22206 +       __nx_set_lback(new);
22207 +       __hash_nx_info(get_nx_info(new));
22208 +       nxi = new, new = NULL;
22209 +
22210 +out_unlock:
22211 +       spin_unlock(&nx_info_hash_lock);
22212 +       if (new)
22213 +               __dealloc_nx_info(new);
22214 +       return nxi;
22215 +}
22216 +
22217 +
22218 +
22219 +/*     exported stuff                                          */
22220 +
22221 +
22222 +void unhash_nx_info(struct nx_info *nxi)
22223 +{
22224 +       __shutdown_nx_info(nxi);
22225 +       spin_lock(&nx_info_hash_lock);
22226 +       __unhash_nx_info(nxi);
22227 +       spin_unlock(&nx_info_hash_lock);
22228 +}
22229 +
22230 +/*     lookup_nx_info()
22231 +
22232 +       * search for a nx_info and get() it
22233 +       * negative id means current                             */
22234 +
22235 +struct nx_info *lookup_nx_info(int id)
22236 +{
22237 +       struct nx_info *nxi = NULL;
22238 +
22239 +       if (id < 0) {
22240 +               nxi = get_nx_info(current->nx_info);
22241 +       } else if (id > 1) {
22242 +               spin_lock(&nx_info_hash_lock);
22243 +               nxi = get_nx_info(__lookup_nx_info(id));
22244 +               spin_unlock(&nx_info_hash_lock);
22245 +       }
22246 +       return nxi;
22247 +}
22248 +
22249 +/*     nid_is_hashed()
22250 +
22251 +       * verify that nid is still hashed                       */
22252 +
22253 +int nid_is_hashed(nid_t nid)
22254 +{
22255 +       int hashed;
22256 +
22257 +       spin_lock(&nx_info_hash_lock);
22258 +       hashed = (__lookup_nx_info(nid) != NULL);
22259 +       spin_unlock(&nx_info_hash_lock);
22260 +       return hashed;
22261 +}
22262 +
22263 +
22264 +#ifdef CONFIG_PROC_FS
22265 +
22266 +/*     get_nid_list()
22267 +
22268 +       * get a subset of hashed nids for proc
22269 +       * assumes size is at least one                          */
22270 +
22271 +int get_nid_list(int index, unsigned int *nids, int size)
22272 +{
22273 +       int hindex, nr_nids = 0;
22274 +
22275 +       /* only show current and children */
22276 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22277 +               if (index > 0)
22278 +                       return 0;
22279 +               nids[nr_nids] = nx_current_nid();
22280 +               return 1;
22281 +       }
22282 +
22283 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22284 +               struct hlist_head *head = &nx_info_hash[hindex];
22285 +               struct hlist_node *pos;
22286 +
22287 +               spin_lock(&nx_info_hash_lock);
22288 +               hlist_for_each(pos, head) {
22289 +                       struct nx_info *nxi;
22290 +
22291 +                       if (--index > 0)
22292 +                               continue;
22293 +
22294 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22295 +                       nids[nr_nids] = nxi->nx_id;
22296 +                       if (++nr_nids >= size) {
22297 +                               spin_unlock(&nx_info_hash_lock);
22298 +                               goto out;
22299 +                       }
22300 +               }
22301 +               /* keep the lock time short */
22302 +               spin_unlock(&nx_info_hash_lock);
22303 +       }
22304 +out:
22305 +       return nr_nids;
22306 +}
22307 +#endif
22308 +
22309 +
22310 +/*
22311 + *     migrate task to new network
22312 + *     gets nxi, puts old_nxi on change
22313 + */
22314 +
22315 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22316 +{
22317 +       struct nx_info *old_nxi;
22318 +       int ret = 0;
22319 +
22320 +       if (!p || !nxi)
22321 +               BUG();
22322 +
22323 +       vxdprintk(VXD_CBIT(nid, 5),
22324 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22325 +               p, nxi, nxi->nx_id,
22326 +               atomic_read(&nxi->nx_usecnt),
22327 +               atomic_read(&nxi->nx_tasks));
22328 +
22329 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22330 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22331 +               return -EACCES;
22332 +
22333 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22334 +               return -EFAULT;
22335 +
22336 +       /* maybe disallow this completely? */
22337 +       old_nxi = task_get_nx_info(p);
22338 +       if (old_nxi == nxi)
22339 +               goto out;
22340 +
22341 +       task_lock(p);
22342 +       if (old_nxi)
22343 +               clr_nx_info(&p->nx_info);
22344 +       claim_nx_info(nxi, p);
22345 +       set_nx_info(&p->nx_info, nxi);
22346 +       p->nid = nxi->nx_id;
22347 +       task_unlock(p);
22348 +
22349 +       vxdprintk(VXD_CBIT(nid, 5),
22350 +               "moved task %p into nxi:%p[#%d]",
22351 +               p, nxi, nxi->nx_id);
22352 +
22353 +       if (old_nxi)
22354 +               release_nx_info(old_nxi, p);
22355 +       ret = 0;
22356 +out:
22357 +       put_nx_info(old_nxi);
22358 +       return ret;
22359 +}
22360 +
22361 +
22362 +void nx_set_persistent(struct nx_info *nxi)
22363 +{
22364 +       vxdprintk(VXD_CBIT(nid, 6),
22365 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22366 +
22367 +       get_nx_info(nxi);
22368 +       claim_nx_info(nxi, NULL);
22369 +}
22370 +
22371 +void nx_clear_persistent(struct nx_info *nxi)
22372 +{
22373 +       vxdprintk(VXD_CBIT(nid, 6),
22374 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22375 +
22376 +       release_nx_info(nxi, NULL);
22377 +       put_nx_info(nxi);
22378 +}
22379 +
22380 +void nx_update_persistent(struct nx_info *nxi)
22381 +{
22382 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22383 +               nx_set_persistent(nxi);
22384 +       else
22385 +               nx_clear_persistent(nxi);
22386 +}
22387 +
22388 +/* vserver syscall commands below here */
22389 +
22390 +/* taks nid and nx_info functions */
22391 +
22392 +#include <asm/uaccess.h>
22393 +
22394 +
22395 +int vc_task_nid(uint32_t id)
22396 +{
22397 +       nid_t nid;
22398 +
22399 +       if (id) {
22400 +               struct task_struct *tsk;
22401 +
22402 +               read_lock(&tasklist_lock);
22403 +               tsk = find_task_by_real_pid(id);
22404 +               nid = (tsk) ? tsk->nid : -ESRCH;
22405 +               read_unlock(&tasklist_lock);
22406 +       } else
22407 +               nid = nx_current_nid();
22408 +       return nid;
22409 +}
22410 +
22411 +
22412 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22413 +{
22414 +       struct vcmd_nx_info_v0 vc_data;
22415 +
22416 +       vc_data.nid = nxi->nx_id;
22417 +
22418 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22419 +               return -EFAULT;
22420 +       return 0;
22421 +}
22422 +
22423 +
22424 +/* network functions */
22425 +
22426 +int vc_net_create(uint32_t nid, void __user *data)
22427 +{
22428 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22429 +       struct nx_info *new_nxi;
22430 +       int ret;
22431 +
22432 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22433 +               return -EFAULT;
22434 +
22435 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22436 +               return -EINVAL;
22437 +
22438 +       new_nxi = __create_nx_info(nid);
22439 +       if (IS_ERR(new_nxi))
22440 +               return PTR_ERR(new_nxi);
22441 +
22442 +       /* initial flags */
22443 +       new_nxi->nx_flags = vc_data.flagword;
22444 +
22445 +       ret = -ENOEXEC;
22446 +       if (vs_net_change(new_nxi, VSC_NETUP))
22447 +               goto out;
22448 +
22449 +       ret = nx_migrate_task(current, new_nxi);
22450 +       if (ret)
22451 +               goto out;
22452 +
22453 +       /* return context id on success */
22454 +       ret = new_nxi->nx_id;
22455 +
22456 +       /* get a reference for persistent contexts */
22457 +       if ((vc_data.flagword & NXF_PERSISTENT))
22458 +               nx_set_persistent(new_nxi);
22459 +out:
22460 +       release_nx_info(new_nxi, NULL);
22461 +       put_nx_info(new_nxi);
22462 +       return ret;
22463 +}
22464 +
22465 +
22466 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22467 +{
22468 +       return nx_migrate_task(current, nxi);
22469 +}
22470 +
22471 +
22472 +
22473 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22474 +       uint16_t type, uint16_t flags)
22475 +{
22476 +       struct nx_addr_v4 *nxa = &nxi->v4;
22477 +
22478 +       if (NX_IPV4(nxi)) {
22479 +               /* locate last entry */
22480 +               for (; nxa->next; nxa = nxa->next);
22481 +               nxa->next = __alloc_nx_addr_v4();
22482 +               nxa = nxa->next;
22483 +
22484 +               if (IS_ERR(nxa))
22485 +                       return PTR_ERR(nxa);
22486 +       }
22487 +
22488 +       if (nxi->v4.next)
22489 +               /* remove single ip for ip list */
22490 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22491 +
22492 +       nxa->ip[0].s_addr = ip;
22493 +       nxa->ip[1].s_addr = ip2;
22494 +       nxa->mask.s_addr = mask;
22495 +       nxa->type = type;
22496 +       nxa->flags = flags;
22497 +       return 0;
22498 +}
22499 +
22500 +
22501 +int vc_net_add(struct nx_info *nxi, void __user *data)
22502 +{
22503 +       struct vcmd_net_addr_v0 vc_data;
22504 +       int index, ret = 0;
22505 +
22506 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22507 +               return -EFAULT;
22508 +
22509 +       switch (vc_data.type) {
22510 +       case NXA_TYPE_IPV4:
22511 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22512 +                       return -EINVAL;
22513 +
22514 +               index = 0;
22515 +               while (index < vc_data.count) {
22516 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22517 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22518 +                       if (ret)
22519 +                               return ret;
22520 +                       index++;
22521 +               }
22522 +               ret = index;
22523 +               break;
22524 +
22525 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22526 +               nxi->v4_bcast = vc_data.ip[0];
22527 +               ret = 1;
22528 +               break;
22529 +
22530 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22531 +               nxi->v4_lback = vc_data.ip[0];
22532 +               ret = 1;
22533 +               break;
22534 +
22535 +       default:
22536 +               ret = -EINVAL;
22537 +               break;
22538 +       }
22539 +       return ret;
22540 +}
22541 +
22542 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22543 +{
22544 +       struct vcmd_net_addr_v0 vc_data;
22545 +
22546 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22547 +               return -EFAULT;
22548 +
22549 +       switch (vc_data.type) {
22550 +       case NXA_TYPE_ANY:
22551 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22552 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22553 +               break;
22554 +
22555 +       default:
22556 +               return -EINVAL;
22557 +       }
22558 +       return 0;
22559 +}
22560 +
22561 +
22562 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22563 +{
22564 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22565 +
22566 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22567 +               return -EFAULT;
22568 +
22569 +       switch (vc_data.type) {
22570 +       case NXA_TYPE_ADDR:
22571 +       case NXA_TYPE_RANGE:
22572 +       case NXA_TYPE_MASK:
22573 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22574 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22575 +
22576 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22577 +               nxi->v4_bcast = vc_data.ip;
22578 +               break;
22579 +
22580 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22581 +               nxi->v4_lback = vc_data.ip;
22582 +               break;
22583 +
22584 +       default:
22585 +               return -EINVAL;
22586 +       }
22587 +       return 0;
22588 +}
22589 +
22590 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22591 +{
22592 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22593 +
22594 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22595 +               return -EFAULT;
22596 +
22597 +       switch (vc_data.type) {
22598 +/*     case NXA_TYPE_ADDR:
22599 +               break;          */
22600 +
22601 +       case NXA_TYPE_ANY:
22602 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22603 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22604 +               break;
22605 +
22606 +       default:
22607 +               return -EINVAL;
22608 +       }
22609 +       return 0;
22610 +}
22611 +
22612 +
22613 +#ifdef CONFIG_IPV6
22614 +
22615 +int do_add_v6_addr(struct nx_info *nxi,
22616 +       struct in6_addr *ip, struct in6_addr *mask,
22617 +       uint32_t prefix, uint16_t type, uint16_t flags)
22618 +{
22619 +       struct nx_addr_v6 *nxa = &nxi->v6;
22620 +
22621 +       if (NX_IPV6(nxi)) {
22622 +               /* locate last entry */
22623 +               for (; nxa->next; nxa = nxa->next);
22624 +               nxa->next = __alloc_nx_addr_v6();
22625 +               nxa = nxa->next;
22626 +
22627 +               if (IS_ERR(nxa))
22628 +                       return PTR_ERR(nxa);
22629 +       }
22630 +
22631 +       nxa->ip = *ip;
22632 +       nxa->mask = *mask;
22633 +       nxa->prefix = prefix;
22634 +       nxa->type = type;
22635 +       nxa->flags = flags;
22636 +       return 0;
22637 +}
22638 +
22639 +
22640 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22641 +{
22642 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22643 +
22644 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22645 +               return -EFAULT;
22646 +
22647 +       switch (vc_data.type) {
22648 +       case NXA_TYPE_ADDR:
22649 +       case NXA_TYPE_MASK:
22650 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22651 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22652 +       default:
22653 +               return -EINVAL;
22654 +       }
22655 +       return 0;
22656 +}
22657 +
22658 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22659 +{
22660 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22661 +
22662 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22663 +               return -EFAULT;
22664 +
22665 +       switch (vc_data.type) {
22666 +       case NXA_TYPE_ANY:
22667 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22668 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22669 +               break;
22670 +
22671 +       default:
22672 +               return -EINVAL;
22673 +       }
22674 +       return 0;
22675 +}
22676 +
22677 +#endif /* CONFIG_IPV6 */
22678 +
22679 +
22680 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22681 +{
22682 +       struct vcmd_net_flags_v0 vc_data;
22683 +
22684 +       vc_data.flagword = nxi->nx_flags;
22685 +
22686 +       /* special STATE flag handling */
22687 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22688 +
22689 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22690 +               return -EFAULT;
22691 +       return 0;
22692 +}
22693 +
22694 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22695 +{
22696 +       struct vcmd_net_flags_v0 vc_data;
22697 +       uint64_t mask, trigger;
22698 +
22699 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22700 +               return -EFAULT;
22701 +
22702 +       /* special STATE flag handling */
22703 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22704 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22705 +
22706 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22707 +               vc_data.flagword, mask);
22708 +       if (trigger & NXF_PERSISTENT)
22709 +               nx_update_persistent(nxi);
22710 +
22711 +       return 0;
22712 +}
22713 +
22714 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22715 +{
22716 +       struct vcmd_net_caps_v0 vc_data;
22717 +
22718 +       vc_data.ncaps = nxi->nx_ncaps;
22719 +       vc_data.cmask = ~0ULL;
22720 +
22721 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22722 +               return -EFAULT;
22723 +       return 0;
22724 +}
22725 +
22726 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22727 +{
22728 +       struct vcmd_net_caps_v0 vc_data;
22729 +
22730 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22731 +               return -EFAULT;
22732 +
22733 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22734 +               vc_data.ncaps, vc_data.cmask);
22735 +       return 0;
22736 +}
22737 +
22738 +
22739 +#include <linux/module.h>
22740 +
22741 +module_init(init_network);
22742 +
22743 +EXPORT_SYMBOL_GPL(free_nx_info);
22744 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22745 +
22746 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/proc.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/proc.c
22747 --- linux-2.6.27.6/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
22748 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/proc.c     2008-10-31 18:15:28.000000000 +0100
22749 @@ -0,0 +1,1092 @@
22750 +/*
22751 + *  linux/kernel/vserver/proc.c
22752 + *
22753 + *  Virtual Context Support
22754 + *
22755 + *  Copyright (C) 2003-2007  Herbert Pötzl
22756 + *
22757 + *  V0.01  basic structure
22758 + *  V0.02  adaptation vs1.3.0
22759 + *  V0.03  proc permissions
22760 + *  V0.04  locking/generic
22761 + *  V0.05  next generation procfs
22762 + *  V0.06  inode validation
22763 + *  V0.07  generic rewrite vid
22764 + *  V0.08  remove inode type
22765 + *
22766 + */
22767 +
22768 +#include <linux/proc_fs.h>
22769 +#include <asm/unistd.h>
22770 +
22771 +#include <linux/vs_context.h>
22772 +#include <linux/vs_network.h>
22773 +#include <linux/vs_cvirt.h>
22774 +
22775 +#include <linux/in.h>
22776 +#include <linux/inetdevice.h>
22777 +#include <linux/vs_inet.h>
22778 +#include <linux/vs_inet6.h>
22779 +
22780 +#include <linux/vserver/global.h>
22781 +
22782 +#include "cvirt_proc.h"
22783 +#include "cacct_proc.h"
22784 +#include "limit_proc.h"
22785 +#include "sched_proc.h"
22786 +#include "vci_config.h"
22787 +
22788 +
22789 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22790 +{
22791 +       unsigned __capi;
22792 +
22793 +       CAP_FOR_EACH_U32(__capi) {
22794 +               buffer += sprintf(buffer, "%08x",
22795 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22796 +       }
22797 +       return buffer;
22798 +}
22799 +
22800 +
22801 +static struct proc_dir_entry *proc_virtual;
22802 +
22803 +static struct proc_dir_entry *proc_virtnet;
22804 +
22805 +
22806 +/* first the actual feeds */
22807 +
22808 +
22809 +static int proc_vci(char *buffer)
22810 +{
22811 +       return sprintf(buffer,
22812 +               "VCIVersion:\t%04x:%04x\n"
22813 +               "VCISyscall:\t%d\n"
22814 +               "VCIKernel:\t%08x\n",
22815 +               VCI_VERSION >> 16,
22816 +               VCI_VERSION & 0xFFFF,
22817 +               __NR_vserver,
22818 +               vci_kernel_config());
22819 +}
22820 +
22821 +static int proc_virtual_info(char *buffer)
22822 +{
22823 +       return proc_vci(buffer);
22824 +}
22825 +
22826 +static int proc_virtual_status(char *buffer)
22827 +{
22828 +       return sprintf(buffer,
22829 +               "#CTotal:\t%d\n"
22830 +               "#CActive:\t%d\n"
22831 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22832 +               atomic_read(&vx_global_ctotal),
22833 +               atomic_read(&vx_global_cactive),
22834 +               atomic_read(&vs_global_nsproxy),
22835 +               atomic_read(&vs_global_fs),
22836 +               atomic_read(&vs_global_mnt_ns),
22837 +               atomic_read(&vs_global_uts_ns),
22838 +               atomic_read(&vs_global_ipc_ns),
22839 +               atomic_read(&vs_global_user_ns),
22840 +               atomic_read(&vs_global_pid_ns));
22841 +}
22842 +
22843 +
22844 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22845 +{
22846 +       int length;
22847 +
22848 +       length = sprintf(buffer,
22849 +               "ID:\t%d\n"
22850 +               "Info:\t%p\n"
22851 +               "Init:\t%d\n"
22852 +               "OOM:\t%lld\n",
22853 +               vxi->vx_id,
22854 +               vxi,
22855 +               vxi->vx_initpid,
22856 +               vxi->vx_badness_bias);
22857 +       return length;
22858 +}
22859 +
22860 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22861 +{
22862 +       char *orig = buffer;
22863 +
22864 +       buffer += sprintf(buffer,
22865 +               "UseCnt:\t%d\n"
22866 +               "Tasks:\t%d\n"
22867 +               "Flags:\t%016llx\n",
22868 +               atomic_read(&vxi->vx_usecnt),
22869 +               atomic_read(&vxi->vx_tasks),
22870 +               (unsigned long long)vxi->vx_flags);
22871 +
22872 +       buffer += sprintf(buffer, "BCaps:\t");
22873 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22874 +       buffer += sprintf(buffer, "\n");
22875 +
22876 +       buffer += sprintf(buffer,
22877 +               "CCaps:\t%016llx\n"
22878 +               "Spaces:\t%08lx %08lx\n",
22879 +               (unsigned long long)vxi->vx_ccaps,
22880 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22881 +       return buffer - orig;
22882 +}
22883 +
22884 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22885 +{
22886 +       return vx_info_proc_limit(&vxi->limit, buffer);
22887 +}
22888 +
22889 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22890 +{
22891 +       int cpu, length;
22892 +
22893 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22894 +       for_each_online_cpu(cpu) {
22895 +               length += vx_info_proc_sched_pc(
22896 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22897 +                       buffer + length, cpu);
22898 +       }
22899 +       return length;
22900 +}
22901 +
22902 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22903 +{
22904 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22905 +}
22906 +
22907 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22908 +{
22909 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22910 +}
22911 +
22912 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22913 +{
22914 +       int cpu, length;
22915 +
22916 +       vx_update_load(vxi);
22917 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22918 +       for_each_online_cpu(cpu) {
22919 +               length += vx_info_proc_cvirt_pc(
22920 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22921 +                       buffer + length, cpu);
22922 +       }
22923 +       return length;
22924 +}
22925 +
22926 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22927 +{
22928 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22929 +}
22930 +
22931 +
22932 +static int proc_virtnet_info(char *buffer)
22933 +{
22934 +       return proc_vci(buffer);
22935 +}
22936 +
22937 +static int proc_virtnet_status(char *buffer)
22938 +{
22939 +       return sprintf(buffer,
22940 +               "#CTotal:\t%d\n"
22941 +               "#CActive:\t%d\n",
22942 +               atomic_read(&nx_global_ctotal),
22943 +               atomic_read(&nx_global_cactive));
22944 +}
22945 +
22946 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22947 +{
22948 +       struct nx_addr_v4 *v4a;
22949 +#ifdef CONFIG_IPV6
22950 +       struct nx_addr_v6 *v6a;
22951 +#endif
22952 +       int length, i;
22953 +
22954 +       length = sprintf(buffer,
22955 +               "ID:\t%d\n"
22956 +               "Info:\t%p\n"
22957 +               "Bcast:\t" NIPQUAD_FMT "\n"
22958 +               "Lback:\t" NIPQUAD_FMT "\n",
22959 +               nxi->nx_id,
22960 +               nxi,
22961 +               NIPQUAD(nxi->v4_bcast.s_addr),
22962 +               NIPQUAD(nxi->v4_lback.s_addr));
22963 +
22964 +       if (!NX_IPV4(nxi))
22965 +               goto skip_v4;
22966 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22967 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22968 +                       i, NXAV4(v4a));
22969 +skip_v4:
22970 +#ifdef CONFIG_IPV6
22971 +       if (!NX_IPV6(nxi))
22972 +               goto skip_v6;
22973 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22974 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22975 +                       i, NXAV6(v6a));
22976 +skip_v6:
22977 +#endif
22978 +       return length;
22979 +}
22980 +
22981 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22982 +{
22983 +       int length;
22984 +
22985 +       length = sprintf(buffer,
22986 +               "UseCnt:\t%d\n"
22987 +               "Tasks:\t%d\n"
22988 +               "Flags:\t%016llx\n"
22989 +               "NCaps:\t%016llx\n",
22990 +               atomic_read(&nxi->nx_usecnt),
22991 +               atomic_read(&nxi->nx_tasks),
22992 +               (unsigned long long)nxi->nx_flags,
22993 +               (unsigned long long)nxi->nx_ncaps);
22994 +       return length;
22995 +}
22996 +
22997 +
22998 +
22999 +/* here the inode helpers */
23000 +
23001 +struct vs_entry {
23002 +       int len;
23003 +       char *name;
23004 +       mode_t mode;
23005 +       struct inode_operations *iop;
23006 +       struct file_operations *fop;
23007 +       union proc_op op;
23008 +};
23009 +
23010 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23011 +{
23012 +       struct inode *inode = new_inode(sb);
23013 +
23014 +       if (!inode)
23015 +               goto out;
23016 +
23017 +       inode->i_mode = p->mode;
23018 +       if (p->iop)
23019 +               inode->i_op = p->iop;
23020 +       if (p->fop)
23021 +               inode->i_fop = p->fop;
23022 +
23023 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23024 +       inode->i_flags |= S_IMMUTABLE;
23025 +
23026 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23027 +
23028 +       inode->i_uid = 0;
23029 +       inode->i_gid = 0;
23030 +       inode->i_tag = 0;
23031 +out:
23032 +       return inode;
23033 +}
23034 +
23035 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23036 +       struct dentry *dentry, int id, void *ptr)
23037 +{
23038 +       struct vs_entry *p = ptr;
23039 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23040 +       struct dentry *error = ERR_PTR(-EINVAL);
23041 +
23042 +       if (!inode)
23043 +               goto out;
23044 +
23045 +       PROC_I(inode)->op = p->op;
23046 +       PROC_I(inode)->fd = id;
23047 +       d_add(dentry, inode);
23048 +       error = NULL;
23049 +out:
23050 +       return error;
23051 +}
23052 +
23053 +/* Lookups */
23054 +
23055 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23056 +
23057 +/*
23058 + * Fill a directory entry.
23059 + *
23060 + * If possible create the dcache entry and derive our inode number and
23061 + * file type from dcache entry.
23062 + *
23063 + * Since all of the proc inode numbers are dynamically generated, the inode
23064 + * numbers do not exist until the inode is cache.  This means creating the
23065 + * the dcache entry in readdir is necessary to keep the inode numbers
23066 + * reported by readdir in sync with the inode numbers reported
23067 + * by stat.
23068 + */
23069 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23070 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23071 +{
23072 +       struct dentry *child, *dir = filp->f_dentry;
23073 +       struct inode *inode;
23074 +       struct qstr qname;
23075 +       ino_t ino = 0;
23076 +       unsigned type = DT_UNKNOWN;
23077 +
23078 +       qname.name = name;
23079 +       qname.len  = len;
23080 +       qname.hash = full_name_hash(name, len);
23081 +
23082 +       child = d_lookup(dir, &qname);
23083 +       if (!child) {
23084 +               struct dentry *new;
23085 +               new = d_alloc(dir, &qname);
23086 +               if (new) {
23087 +                       child = instantiate(dir->d_inode, new, id, ptr);
23088 +                       if (child)
23089 +                               dput(new);
23090 +                       else
23091 +                               child = new;
23092 +               }
23093 +       }
23094 +       if (!child || IS_ERR(child) || !child->d_inode)
23095 +               goto end_instantiate;
23096 +       inode = child->d_inode;
23097 +       if (inode) {
23098 +               ino = inode->i_ino;
23099 +               type = inode->i_mode >> 12;
23100 +       }
23101 +       dput(child);
23102 +end_instantiate:
23103 +       if (!ino)
23104 +               ino = find_inode_number(dir, &qname);
23105 +       if (!ino)
23106 +               ino = 1;
23107 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23108 +}
23109 +
23110 +
23111 +
23112 +/* get and revalidate vx_info/xid */
23113 +
23114 +static inline
23115 +struct vx_info *get_proc_vx_info(struct inode *inode)
23116 +{
23117 +       return lookup_vx_info(PROC_I(inode)->fd);
23118 +}
23119 +
23120 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23121 +{
23122 +       struct inode *inode = dentry->d_inode;
23123 +       xid_t xid = PROC_I(inode)->fd;
23124 +
23125 +       if (!xid || xid_is_hashed(xid))
23126 +               return 1;
23127 +       d_drop(dentry);
23128 +       return 0;
23129 +}
23130 +
23131 +
23132 +/* get and revalidate nx_info/nid */
23133 +
23134 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23135 +{
23136 +       struct inode *inode = dentry->d_inode;
23137 +       nid_t nid = PROC_I(inode)->fd;
23138 +
23139 +       if (!nid || nid_is_hashed(nid))
23140 +               return 1;
23141 +       d_drop(dentry);
23142 +       return 0;
23143 +}
23144 +
23145 +
23146 +
23147 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23148 +
23149 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23150 +                         size_t count, loff_t *ppos)
23151 +{
23152 +       struct inode *inode = file->f_dentry->d_inode;
23153 +       unsigned long page;
23154 +       ssize_t length = 0;
23155 +
23156 +       if (count > PROC_BLOCK_SIZE)
23157 +               count = PROC_BLOCK_SIZE;
23158 +
23159 +       /* fade that out as soon as stable */
23160 +       WARN_ON(PROC_I(inode)->fd);
23161 +
23162 +       if (!(page = __get_free_page(GFP_KERNEL)))
23163 +               return -ENOMEM;
23164 +
23165 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23166 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23167 +
23168 +       if (length >= 0)
23169 +               length = simple_read_from_buffer(buf, count, ppos,
23170 +                       (char *)page, length);
23171 +
23172 +       free_page(page);
23173 +       return length;
23174 +}
23175 +
23176 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23177 +                         size_t count, loff_t *ppos)
23178 +{
23179 +       struct inode *inode = file->f_dentry->d_inode;
23180 +       struct vx_info *vxi = NULL;
23181 +       xid_t xid = PROC_I(inode)->fd;
23182 +       unsigned long page;
23183 +       ssize_t length = 0;
23184 +
23185 +       if (count > PROC_BLOCK_SIZE)
23186 +               count = PROC_BLOCK_SIZE;
23187 +
23188 +       /* fade that out as soon as stable */
23189 +       WARN_ON(!xid);
23190 +       vxi = lookup_vx_info(xid);
23191 +       if (!vxi)
23192 +               goto out;
23193 +
23194 +       length = -ENOMEM;
23195 +       if (!(page = __get_free_page(GFP_KERNEL)))
23196 +               goto out_put;
23197 +
23198 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23199 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23200 +
23201 +       if (length >= 0)
23202 +               length = simple_read_from_buffer(buf, count, ppos,
23203 +                       (char *)page, length);
23204 +
23205 +       free_page(page);
23206 +out_put:
23207 +       put_vx_info(vxi);
23208 +out:
23209 +       return length;
23210 +}
23211 +
23212 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23213 +                         size_t count, loff_t *ppos)
23214 +{
23215 +       struct inode *inode = file->f_dentry->d_inode;
23216 +       struct nx_info *nxi = NULL;
23217 +       nid_t nid = PROC_I(inode)->fd;
23218 +       unsigned long page;
23219 +       ssize_t length = 0;
23220 +
23221 +       if (count > PROC_BLOCK_SIZE)
23222 +               count = PROC_BLOCK_SIZE;
23223 +
23224 +       /* fade that out as soon as stable */
23225 +       WARN_ON(!nid);
23226 +       nxi = lookup_nx_info(nid);
23227 +       if (!nxi)
23228 +               goto out;
23229 +
23230 +       length = -ENOMEM;
23231 +       if (!(page = __get_free_page(GFP_KERNEL)))
23232 +               goto out_put;
23233 +
23234 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23235 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23236 +
23237 +       if (length >= 0)
23238 +               length = simple_read_from_buffer(buf, count, ppos,
23239 +                       (char *)page, length);
23240 +
23241 +       free_page(page);
23242 +out_put:
23243 +       put_nx_info(nxi);
23244 +out:
23245 +       return length;
23246 +}
23247 +
23248 +
23249 +
23250 +/* here comes the lower level */
23251 +
23252 +
23253 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23254 +       .len  = sizeof(NAME) - 1,       \
23255 +       .name = (NAME),                 \
23256 +       .mode = MODE,                   \
23257 +       .iop  = IOP,                    \
23258 +       .fop  = FOP,                    \
23259 +       .op   = OP,                     \
23260 +}
23261 +
23262 +
23263 +#define DIR(NAME, MODE, OTYPE)                         \
23264 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23265 +               &proc_ ## OTYPE ## _inode_operations,   \
23266 +               &proc_ ## OTYPE ## _file_operations, { } )
23267 +
23268 +#define INF(NAME, MODE, OTYPE)                         \
23269 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23270 +               &proc_vs_info_file_operations,          \
23271 +               { .proc_vs_read = &proc_##OTYPE } )
23272 +
23273 +#define VINF(NAME, MODE, OTYPE)                                \
23274 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23275 +               &proc_vx_info_file_operations,          \
23276 +               { .proc_vxi_read = &proc_##OTYPE } )
23277 +
23278 +#define NINF(NAME, MODE, OTYPE)                                \
23279 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23280 +               &proc_nx_info_file_operations,          \
23281 +               { .proc_nxi_read = &proc_##OTYPE } )
23282 +
23283 +
23284 +static struct file_operations proc_vs_info_file_operations = {
23285 +       .read =         proc_vs_info_read,
23286 +};
23287 +
23288 +static struct file_operations proc_vx_info_file_operations = {
23289 +       .read =         proc_vx_info_read,
23290 +};
23291 +
23292 +static struct dentry_operations proc_xid_dentry_operations = {
23293 +       .d_revalidate = proc_xid_revalidate,
23294 +};
23295 +
23296 +static struct vs_entry vx_base_stuff[] = {
23297 +       VINF("info",    S_IRUGO, vxi_info),
23298 +       VINF("status",  S_IRUGO, vxi_status),
23299 +       VINF("limit",   S_IRUGO, vxi_limit),
23300 +       VINF("sched",   S_IRUGO, vxi_sched),
23301 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23302 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23303 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23304 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23305 +       {}
23306 +};
23307 +
23308 +
23309 +
23310 +
23311 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23312 +       struct dentry *dentry, int id, void *ptr)
23313 +{
23314 +       dentry->d_op = &proc_xid_dentry_operations;
23315 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23316 +}
23317 +
23318 +static struct dentry *proc_xid_lookup(struct inode *dir,
23319 +       struct dentry *dentry, struct nameidata *nd)
23320 +{
23321 +       struct vs_entry *p = vx_base_stuff;
23322 +       struct dentry *error = ERR_PTR(-ENOENT);
23323 +
23324 +       for (; p->name; p++) {
23325 +               if (p->len != dentry->d_name.len)
23326 +                       continue;
23327 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23328 +                       break;
23329 +       }
23330 +       if (!p->name)
23331 +               goto out;
23332 +
23333 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23334 +out:
23335 +       return error;
23336 +}
23337 +
23338 +static int proc_xid_readdir(struct file *filp,
23339 +       void *dirent, filldir_t filldir)
23340 +{
23341 +       struct dentry *dentry = filp->f_dentry;
23342 +       struct inode *inode = dentry->d_inode;
23343 +       struct vs_entry *p = vx_base_stuff;
23344 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23345 +       int pos, index;
23346 +       u64 ino;
23347 +
23348 +       pos = filp->f_pos;
23349 +       switch (pos) {
23350 +       case 0:
23351 +               ino = inode->i_ino;
23352 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23353 +                       goto out;
23354 +               pos++;
23355 +               /* fall through */
23356 +       case 1:
23357 +               ino = parent_ino(dentry);
23358 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23359 +                       goto out;
23360 +               pos++;
23361 +               /* fall through */
23362 +       default:
23363 +               index = pos - 2;
23364 +               if (index >= size)
23365 +                       goto out;
23366 +               for (p += index; p->name; p++) {
23367 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23368 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23369 +                               goto out;
23370 +                       pos++;
23371 +               }
23372 +       }
23373 +out:
23374 +       filp->f_pos = pos;
23375 +       return 1;
23376 +}
23377 +
23378 +
23379 +
23380 +static struct file_operations proc_nx_info_file_operations = {
23381 +       .read =         proc_nx_info_read,
23382 +};
23383 +
23384 +static struct dentry_operations proc_nid_dentry_operations = {
23385 +       .d_revalidate = proc_nid_revalidate,
23386 +};
23387 +
23388 +static struct vs_entry nx_base_stuff[] = {
23389 +       NINF("info",    S_IRUGO, nxi_info),
23390 +       NINF("status",  S_IRUGO, nxi_status),
23391 +       {}
23392 +};
23393 +
23394 +
23395 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23396 +       struct dentry *dentry, int id, void *ptr)
23397 +{
23398 +       dentry->d_op = &proc_nid_dentry_operations;
23399 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23400 +}
23401 +
23402 +static struct dentry *proc_nid_lookup(struct inode *dir,
23403 +       struct dentry *dentry, struct nameidata *nd)
23404 +{
23405 +       struct vs_entry *p = nx_base_stuff;
23406 +       struct dentry *error = ERR_PTR(-ENOENT);
23407 +
23408 +       for (; p->name; p++) {
23409 +               if (p->len != dentry->d_name.len)
23410 +                       continue;
23411 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23412 +                       break;
23413 +       }
23414 +       if (!p->name)
23415 +               goto out;
23416 +
23417 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23418 +out:
23419 +       return error;
23420 +}
23421 +
23422 +static int proc_nid_readdir(struct file *filp,
23423 +       void *dirent, filldir_t filldir)
23424 +{
23425 +       struct dentry *dentry = filp->f_dentry;
23426 +       struct inode *inode = dentry->d_inode;
23427 +       struct vs_entry *p = nx_base_stuff;
23428 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23429 +       int pos, index;
23430 +       u64 ino;
23431 +
23432 +       pos = filp->f_pos;
23433 +       switch (pos) {
23434 +       case 0:
23435 +               ino = inode->i_ino;
23436 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23437 +                       goto out;
23438 +               pos++;
23439 +               /* fall through */
23440 +       case 1:
23441 +               ino = parent_ino(dentry);
23442 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23443 +                       goto out;
23444 +               pos++;
23445 +               /* fall through */
23446 +       default:
23447 +               index = pos - 2;
23448 +               if (index >= size)
23449 +                       goto out;
23450 +               for (p += index; p->name; p++) {
23451 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23452 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23453 +                               goto out;
23454 +                       pos++;
23455 +               }
23456 +       }
23457 +out:
23458 +       filp->f_pos = pos;
23459 +       return 1;
23460 +}
23461 +
23462 +
23463 +#define MAX_MULBY10    ((~0U - 9) / 10)
23464 +
23465 +static inline int atovid(const char *str, int len)
23466 +{
23467 +       int vid, c;
23468 +
23469 +       vid = 0;
23470 +       while (len-- > 0) {
23471 +               c = *str - '0';
23472 +               str++;
23473 +               if (c > 9)
23474 +                       return -1;
23475 +               if (vid >= MAX_MULBY10)
23476 +                       return -1;
23477 +               vid *= 10;
23478 +               vid += c;
23479 +               if (!vid)
23480 +                       return -1;
23481 +       }
23482 +       return vid;
23483 +}
23484 +
23485 +/* now the upper level (virtual) */
23486 +
23487 +
23488 +static struct file_operations proc_xid_file_operations = {
23489 +       .read =         generic_read_dir,
23490 +       .readdir =      proc_xid_readdir,
23491 +};
23492 +
23493 +static struct inode_operations proc_xid_inode_operations = {
23494 +       .lookup =       proc_xid_lookup,
23495 +};
23496 +
23497 +static struct vs_entry vx_virtual_stuff[] = {
23498 +       INF("info",     S_IRUGO, virtual_info),
23499 +       INF("status",   S_IRUGO, virtual_status),
23500 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23501 +};
23502 +
23503 +
23504 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23505 +       struct dentry *dentry, struct nameidata *nd)
23506 +{
23507 +       struct vs_entry *p = vx_virtual_stuff;
23508 +       struct dentry *error = ERR_PTR(-ENOENT);
23509 +       int id = 0;
23510 +
23511 +       for (; p->name; p++) {
23512 +               if (p->len != dentry->d_name.len)
23513 +                       continue;
23514 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23515 +                       break;
23516 +       }
23517 +       if (p->name)
23518 +               goto instantiate;
23519 +
23520 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23521 +       if ((id < 0) || !xid_is_hashed(id))
23522 +               goto out;
23523 +
23524 +instantiate:
23525 +       error = proc_xid_instantiate(dir, dentry, id, p);
23526 +out:
23527 +       return error;
23528 +}
23529 +
23530 +static struct file_operations proc_nid_file_operations = {
23531 +       .read =         generic_read_dir,
23532 +       .readdir =      proc_nid_readdir,
23533 +};
23534 +
23535 +static struct inode_operations proc_nid_inode_operations = {
23536 +       .lookup =       proc_nid_lookup,
23537 +};
23538 +
23539 +static struct vs_entry nx_virtnet_stuff[] = {
23540 +       INF("info",     S_IRUGO, virtnet_info),
23541 +       INF("status",   S_IRUGO, virtnet_status),
23542 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23543 +};
23544 +
23545 +
23546 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23547 +       struct dentry *dentry, struct nameidata *nd)
23548 +{
23549 +       struct vs_entry *p = nx_virtnet_stuff;
23550 +       struct dentry *error = ERR_PTR(-ENOENT);
23551 +       int id = 0;
23552 +
23553 +       for (; p->name; p++) {
23554 +               if (p->len != dentry->d_name.len)
23555 +                       continue;
23556 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23557 +                       break;
23558 +       }
23559 +       if (p->name)
23560 +               goto instantiate;
23561 +
23562 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23563 +       if ((id < 0) || !nid_is_hashed(id))
23564 +               goto out;
23565 +
23566 +instantiate:
23567 +       error = proc_nid_instantiate(dir, dentry, id, p);
23568 +out:
23569 +       return error;
23570 +}
23571 +
23572 +
23573 +#define PROC_MAXVIDS 32
23574 +
23575 +int proc_virtual_readdir(struct file *filp,
23576 +       void *dirent, filldir_t filldir)
23577 +{
23578 +       struct dentry *dentry = filp->f_dentry;
23579 +       struct inode *inode = dentry->d_inode;
23580 +       struct vs_entry *p = vx_virtual_stuff;
23581 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23582 +       int pos, index;
23583 +       unsigned int xid_array[PROC_MAXVIDS];
23584 +       char buf[PROC_NUMBUF];
23585 +       unsigned int nr_xids, i;
23586 +       u64 ino;
23587 +
23588 +       pos = filp->f_pos;
23589 +       switch (pos) {
23590 +       case 0:
23591 +               ino = inode->i_ino;
23592 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23593 +                       goto out;
23594 +               pos++;
23595 +               /* fall through */
23596 +       case 1:
23597 +               ino = parent_ino(dentry);
23598 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23599 +                       goto out;
23600 +               pos++;
23601 +               /* fall through */
23602 +       default:
23603 +               index = pos - 2;
23604 +               if (index >= size)
23605 +                       goto entries;
23606 +               for (p += index; p->name; p++) {
23607 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23608 +                               vs_proc_instantiate, 0, p))
23609 +                               goto out;
23610 +                       pos++;
23611 +               }
23612 +       entries:
23613 +               index = pos - size;
23614 +               p = &vx_virtual_stuff[size - 1];
23615 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23616 +               for (i = 0; i < nr_xids; i++) {
23617 +                       int n, xid = xid_array[i];
23618 +                       unsigned int j = PROC_NUMBUF;
23619 +
23620 +                       n = xid;
23621 +                       do
23622 +                               buf[--j] = '0' + (n % 10);
23623 +                       while (n /= 10);
23624 +
23625 +                       if (proc_fill_cache(filp, dirent, filldir,
23626 +                               buf + j, PROC_NUMBUF - j,
23627 +                               vs_proc_instantiate, xid, p))
23628 +                               goto out;
23629 +                       pos++;
23630 +               }
23631 +       }
23632 +out:
23633 +       filp->f_pos = pos;
23634 +       return 0;
23635 +}
23636 +
23637 +static int proc_virtual_getattr(struct vfsmount *mnt,
23638 +       struct dentry *dentry, struct kstat *stat)
23639 +{
23640 +       struct inode *inode = dentry->d_inode;
23641 +
23642 +       generic_fillattr(inode, stat);
23643 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23644 +       return 0;
23645 +}
23646 +
23647 +static struct file_operations proc_virtual_dir_operations = {
23648 +       .read =         generic_read_dir,
23649 +       .readdir =      proc_virtual_readdir,
23650 +};
23651 +
23652 +static struct inode_operations proc_virtual_dir_inode_operations = {
23653 +       .getattr =      proc_virtual_getattr,
23654 +       .lookup =       proc_virtual_lookup,
23655 +};
23656 +
23657 +
23658 +
23659 +
23660 +
23661 +int proc_virtnet_readdir(struct file *filp,
23662 +       void *dirent, filldir_t filldir)
23663 +{
23664 +       struct dentry *dentry = filp->f_dentry;
23665 +       struct inode *inode = dentry->d_inode;
23666 +       struct vs_entry *p = nx_virtnet_stuff;
23667 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23668 +       int pos, index;
23669 +       unsigned int nid_array[PROC_MAXVIDS];
23670 +       char buf[PROC_NUMBUF];
23671 +       unsigned int nr_nids, i;
23672 +       u64 ino;
23673 +
23674 +       pos = filp->f_pos;
23675 +       switch (pos) {
23676 +       case 0:
23677 +               ino = inode->i_ino;
23678 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23679 +                       goto out;
23680 +               pos++;
23681 +               /* fall through */
23682 +       case 1:
23683 +               ino = parent_ino(dentry);
23684 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23685 +                       goto out;
23686 +               pos++;
23687 +               /* fall through */
23688 +       default:
23689 +               index = pos - 2;
23690 +               if (index >= size)
23691 +                       goto entries;
23692 +               for (p += index; p->name; p++) {
23693 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23694 +                               vs_proc_instantiate, 0, p))
23695 +                               goto out;
23696 +                       pos++;
23697 +               }
23698 +       entries:
23699 +               index = pos - size;
23700 +               p = &nx_virtnet_stuff[size - 1];
23701 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23702 +               for (i = 0; i < nr_nids; i++) {
23703 +                       int n, nid = nid_array[i];
23704 +                       unsigned int j = PROC_NUMBUF;
23705 +
23706 +                       n = nid;
23707 +                       do
23708 +                               buf[--j] = '0' + (n % 10);
23709 +                       while (n /= 10);
23710 +
23711 +                       if (proc_fill_cache(filp, dirent, filldir,
23712 +                               buf + j, PROC_NUMBUF - j,
23713 +                               vs_proc_instantiate, nid, p))
23714 +                               goto out;
23715 +                       pos++;
23716 +               }
23717 +       }
23718 +out:
23719 +       filp->f_pos = pos;
23720 +       return 0;
23721 +}
23722 +
23723 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23724 +       struct dentry *dentry, struct kstat *stat)
23725 +{
23726 +       struct inode *inode = dentry->d_inode;
23727 +
23728 +       generic_fillattr(inode, stat);
23729 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23730 +       return 0;
23731 +}
23732 +
23733 +static struct file_operations proc_virtnet_dir_operations = {
23734 +       .read =         generic_read_dir,
23735 +       .readdir =      proc_virtnet_readdir,
23736 +};
23737 +
23738 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23739 +       .getattr =      proc_virtnet_getattr,
23740 +       .lookup =       proc_virtnet_lookup,
23741 +};
23742 +
23743 +
23744 +
23745 +void proc_vx_init(void)
23746 +{
23747 +       struct proc_dir_entry *ent;
23748 +
23749 +       ent = proc_mkdir("virtual", 0);
23750 +       if (ent) {
23751 +               ent->proc_fops = &proc_virtual_dir_operations;
23752 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23753 +       }
23754 +       proc_virtual = ent;
23755 +
23756 +       ent = proc_mkdir("virtnet", 0);
23757 +       if (ent) {
23758 +               ent->proc_fops = &proc_virtnet_dir_operations;
23759 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23760 +       }
23761 +       proc_virtnet = ent;
23762 +}
23763 +
23764 +
23765 +
23766 +
23767 +/* per pid info */
23768 +
23769 +
23770 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23771 +{
23772 +       struct vx_info *vxi;
23773 +       char *orig = buffer;
23774 +
23775 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23776 +
23777 +       vxi = task_get_vx_info(p);
23778 +       if (!vxi)
23779 +               goto out;
23780 +
23781 +       buffer += sprintf(buffer, "BCaps:\t");
23782 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23783 +       buffer += sprintf(buffer, "\n");
23784 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23785 +               (unsigned long long)vxi->vx_ccaps);
23786 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23787 +               (unsigned long long)vxi->vx_flags);
23788 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23789 +
23790 +       put_vx_info(vxi);
23791 +out:
23792 +       return buffer - orig;
23793 +}
23794 +
23795 +
23796 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23797 +{
23798 +       struct nx_info *nxi;
23799 +       struct nx_addr_v4 *v4a;
23800 +#ifdef CONFIG_IPV6
23801 +       struct nx_addr_v6 *v6a;
23802 +#endif
23803 +       char *orig = buffer;
23804 +       int i;
23805 +
23806 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23807 +
23808 +       nxi = task_get_nx_info(p);
23809 +       if (!nxi)
23810 +               goto out;
23811 +
23812 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23813 +               (unsigned long long)nxi->nx_ncaps);
23814 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23815 +               (unsigned long long)nxi->nx_flags);
23816 +
23817 +       buffer += sprintf(buffer,
23818 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23819 +               NIPQUAD(nxi->v4_bcast.s_addr));
23820 +       buffer += sprintf (buffer,
23821 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23822 +               NIPQUAD(nxi->v4_lback.s_addr));
23823 +       if (!NX_IPV4(nxi))
23824 +               goto skip_v4;
23825 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23826 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23827 +                       i, NXAV4(v4a));
23828 +skip_v4:
23829 +#ifdef CONFIG_IPV6
23830 +       if (!NX_IPV6(nxi))
23831 +               goto skip_v6;
23832 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23833 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23834 +                       i, NXAV6(v6a));
23835 +skip_v6:
23836 +#endif
23837 +       put_nx_info(nxi);
23838 +out:
23839 +       return buffer - orig;
23840 +}
23841 +
23842 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/sched.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sched.c
23843 --- linux-2.6.27.6/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
23844 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sched.c    2008-10-13 14:54:20.000000000 +0200
23845 @@ -0,0 +1,413 @@
23846 +/*
23847 + *  linux/kernel/vserver/sched.c
23848 + *
23849 + *  Virtual Server: Scheduler Support
23850 + *
23851 + *  Copyright (C) 2004-2007  Herbert Pötzl
23852 + *
23853 + *  V0.01  adapted Sam Vilains version to 2.6.3
23854 + *  V0.02  removed legacy interface
23855 + *  V0.03  changed vcmds to vxi arg
23856 + *  V0.04  removed older and legacy interfaces
23857 + *
23858 + */
23859 +
23860 +#include <linux/vs_context.h>
23861 +#include <linux/vs_sched.h>
23862 +#include <linux/vserver/sched_cmd.h>
23863 +
23864 +#include <asm/uaccess.h>
23865 +
23866 +
23867 +#define vxd_check_range(val, min, max) do {            \
23868 +       vxlprintk((val < min) || (val > max),           \
23869 +               "check_range(%ld,%ld,%ld)",             \
23870 +               (long)val, (long)min, (long)max,        \
23871 +               __FILE__, __LINE__);                    \
23872 +       } while (0)
23873 +
23874 +
23875 +void vx_update_sched_param(struct _vx_sched *sched,
23876 +       struct _vx_sched_pc *sched_pc)
23877 +{
23878 +       unsigned int set_mask = sched->update_mask;
23879 +
23880 +       if (set_mask & VXSM_FILL_RATE)
23881 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23882 +       if (set_mask & VXSM_INTERVAL)
23883 +               sched_pc->interval[0] = sched->interval[0];
23884 +       if (set_mask & VXSM_FILL_RATE2)
23885 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23886 +       if (set_mask & VXSM_INTERVAL2)
23887 +               sched_pc->interval[1] = sched->interval[1];
23888 +       if (set_mask & VXSM_TOKENS)
23889 +               sched_pc->tokens = sched->tokens;
23890 +       if (set_mask & VXSM_TOKENS_MIN)
23891 +               sched_pc->tokens_min = sched->tokens_min;
23892 +       if (set_mask & VXSM_TOKENS_MAX)
23893 +               sched_pc->tokens_max = sched->tokens_max;
23894 +       if (set_mask & VXSM_PRIO_BIAS)
23895 +               sched_pc->prio_bias = sched->prio_bias;
23896 +
23897 +       if (set_mask & VXSM_IDLE_TIME)
23898 +               sched_pc->flags |= VXSF_IDLE_TIME;
23899 +       else
23900 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23901 +
23902 +       /* reset time */
23903 +       sched_pc->norm_time = jiffies;
23904 +}
23905 +
23906 +
23907 +/*
23908 + * recalculate the context's scheduling tokens
23909 + *
23910 + * ret > 0 : number of tokens available
23911 + * ret < 0 : on hold, check delta_min[]
23912 + *          -1 only jiffies
23913 + *          -2 also idle time
23914 + *
23915 + */
23916 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23917 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23918 +{
23919 +       long delta;
23920 +       long tokens = 0;
23921 +       int flags = sched_pc->flags;
23922 +
23923 +       /* how much time did pass? */
23924 +       delta = *norm_time - sched_pc->norm_time;
23925 +       vxd_check_range(delta, 0, INT_MAX);
23926 +
23927 +       if (delta >= sched_pc->interval[0]) {
23928 +               long tokens, integral;
23929 +
23930 +               /* calc integral token part */
23931 +               tokens = delta / sched_pc->interval[0];
23932 +               integral = tokens * sched_pc->interval[0];
23933 +               tokens *= sched_pc->fill_rate[0];
23934 +#ifdef CONFIG_VSERVER_HARDCPU
23935 +               delta_min[0] = delta - integral;
23936 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23937 +#endif
23938 +               /* advance time */
23939 +               sched_pc->norm_time += delta;
23940 +
23941 +               /* add tokens */
23942 +               sched_pc->tokens += tokens;
23943 +               sched_pc->token_time += tokens;
23944 +       } else
23945 +               delta_min[0] = delta;
23946 +
23947 +#ifdef CONFIG_VSERVER_IDLETIME
23948 +       if (!(flags & VXSF_IDLE_TIME))
23949 +               goto skip_idle;
23950 +
23951 +       /* how much was the idle skip? */
23952 +       delta = *idle_time - sched_pc->idle_time;
23953 +       vxd_check_range(delta, 0, INT_MAX);
23954 +
23955 +       if (delta >= sched_pc->interval[1]) {
23956 +               long tokens, integral;
23957 +
23958 +               /* calc fair share token part */
23959 +               tokens = delta / sched_pc->interval[1];
23960 +               integral = tokens * sched_pc->interval[1];
23961 +               tokens *= sched_pc->fill_rate[1];
23962 +               delta_min[1] = delta - integral;
23963 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23964 +
23965 +               /* advance idle time */
23966 +               sched_pc->idle_time += integral;
23967 +
23968 +               /* add tokens */
23969 +               sched_pc->tokens += tokens;
23970 +               sched_pc->token_time += tokens;
23971 +       } else
23972 +               delta_min[1] = delta;
23973 +skip_idle:
23974 +#endif
23975 +
23976 +       /* clip at maximum */
23977 +       if (sched_pc->tokens > sched_pc->tokens_max)
23978 +               sched_pc->tokens = sched_pc->tokens_max;
23979 +       tokens = sched_pc->tokens;
23980 +
23981 +       if ((flags & VXSF_ONHOLD)) {
23982 +               /* can we unhold? */
23983 +               if (tokens >= sched_pc->tokens_min) {
23984 +                       flags &= ~VXSF_ONHOLD;
23985 +                       sched_pc->hold_ticks +=
23986 +                               *norm_time - sched_pc->onhold;
23987 +               } else
23988 +                       goto on_hold;
23989 +       } else {
23990 +               /* put on hold? */
23991 +               if (tokens <= 0) {
23992 +                       flags |= VXSF_ONHOLD;
23993 +                       sched_pc->onhold = *norm_time;
23994 +                       goto on_hold;
23995 +               }
23996 +       }
23997 +       sched_pc->flags = flags;
23998 +       return tokens;
23999 +
24000 +on_hold:
24001 +       tokens = sched_pc->tokens_min - tokens;
24002 +       sched_pc->flags = flags;
24003 +       BUG_ON(tokens < 0);
24004 +
24005 +#ifdef CONFIG_VSERVER_HARDCPU
24006 +       /* next interval? */
24007 +       if (!sched_pc->fill_rate[0])
24008 +               delta_min[0] = HZ;
24009 +       else if (tokens > sched_pc->fill_rate[0])
24010 +               delta_min[0] += sched_pc->interval[0] *
24011 +                       tokens / sched_pc->fill_rate[0];
24012 +       else
24013 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24014 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24015 +
24016 +#ifdef CONFIG_VSERVER_IDLETIME
24017 +       if (!(flags & VXSF_IDLE_TIME))
24018 +               return -1;
24019 +
24020 +       /* next interval? */
24021 +       if (!sched_pc->fill_rate[1])
24022 +               delta_min[1] = HZ;
24023 +       else if (tokens > sched_pc->fill_rate[1])
24024 +               delta_min[1] += sched_pc->interval[1] *
24025 +                       tokens / sched_pc->fill_rate[1];
24026 +       else
24027 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24028 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24029 +
24030 +       return -2;
24031 +#else
24032 +       return -1;
24033 +#endif /* CONFIG_VSERVER_IDLETIME */
24034 +#else
24035 +       return 0;
24036 +#endif /* CONFIG_VSERVER_HARDCPU */
24037 +}
24038 +
24039 +static inline unsigned long msec_to_ticks(unsigned long msec)
24040 +{
24041 +       return msecs_to_jiffies(msec);
24042 +}
24043 +
24044 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24045 +{
24046 +       return jiffies_to_msecs(ticks);
24047 +}
24048 +
24049 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24050 +{
24051 +       return jiffies_to_usecs(ticks);
24052 +}
24053 +
24054 +
24055 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24056 +{
24057 +       unsigned int set_mask = data->mask;
24058 +       unsigned int update_mask;
24059 +       int i, cpu;
24060 +
24061 +       /* Sanity check data values */
24062 +       if (data->tokens_max <= 0)
24063 +               data->tokens_max = HZ;
24064 +       if (data->tokens_min < 0)
24065 +               data->tokens_min = HZ / 3;
24066 +       if (data->tokens_min >= data->tokens_max)
24067 +               data->tokens_min = data->tokens_max;
24068 +
24069 +       if (data->prio_bias > MAX_PRIO_BIAS)
24070 +               data->prio_bias = MAX_PRIO_BIAS;
24071 +       if (data->prio_bias < MIN_PRIO_BIAS)
24072 +               data->prio_bias = MIN_PRIO_BIAS;
24073 +
24074 +       spin_lock(&vxi->sched.tokens_lock);
24075 +
24076 +       /* sync up on delayed updates */
24077 +       for_each_cpu_mask(cpu, vxi->sched.update)
24078 +               vx_update_sched_param(&vxi->sched,
24079 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24080 +
24081 +       if (set_mask & VXSM_FILL_RATE)
24082 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24083 +       if (set_mask & VXSM_FILL_RATE2)
24084 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24085 +       if (set_mask & VXSM_INTERVAL)
24086 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24087 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24088 +       if (set_mask & VXSM_INTERVAL2)
24089 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24090 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24091 +       if (set_mask & VXSM_TOKENS)
24092 +               vxi->sched.tokens = data->tokens;
24093 +       if (set_mask & VXSM_TOKENS_MIN)
24094 +               vxi->sched.tokens_min = data->tokens_min;
24095 +       if (set_mask & VXSM_TOKENS_MAX)
24096 +               vxi->sched.tokens_max = data->tokens_max;
24097 +       if (set_mask & VXSM_PRIO_BIAS)
24098 +               vxi->sched.prio_bias = data->prio_bias;
24099 +
24100 +       /* Sanity check rate/interval */
24101 +       for (i = 0; i < 2; i++) {
24102 +               if (data->fill_rate[i] < 0)
24103 +                       data->fill_rate[i] = 0;
24104 +               if (data->interval[i] <= 0)
24105 +                       data->interval[i] = HZ;
24106 +       }
24107 +
24108 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24109 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24110 +       vxi->sched.update_mask = update_mask;
24111 +
24112 +#ifdef CONFIG_SMP
24113 +       rmb();
24114 +       if (set_mask & VXSM_CPU_ID) {
24115 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24116 +               cpus_and(vxi->sched.update, cpu_online_map,
24117 +                       vxi->sched.update);
24118 +       } else
24119 +               vxi->sched.update = cpu_online_map;
24120 +
24121 +       /* forced reload? */
24122 +       if (set_mask & VXSM_FORCE) {
24123 +               for_each_cpu_mask(cpu, vxi->sched.update)
24124 +                       vx_update_sched_param(&vxi->sched,
24125 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24126 +               vxi->sched.update = CPU_MASK_NONE;
24127 +       }
24128 +#else
24129 +       /* on UP we update immediately */
24130 +       vx_update_sched_param(&vxi->sched,
24131 +               &vx_per_cpu(vxi, sched_pc, 0));
24132 +#endif
24133 +
24134 +       spin_unlock(&vxi->sched.tokens_lock);
24135 +       return 0;
24136 +}
24137 +
24138 +
24139 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24140 +#define COPY_PRI(C) C(prio_bias)
24141 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24142 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24143 +                   C(fill_rate[1]); C(interval[1]);
24144 +
24145 +#define COPY_VALUE(name) vc_data.name = data->name
24146 +
24147 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24148 +{
24149 +       struct vcmd_sched_v5 vc_data;
24150 +
24151 +       vc_data.mask = data->set_mask;
24152 +       COPY_IDS(COPY_VALUE);
24153 +       COPY_PRI(COPY_VALUE);
24154 +       COPY_TOK(COPY_VALUE);
24155 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24156 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24157 +       return do_set_sched(vxi, &vc_data);
24158 +}
24159 +
24160 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24161 +{
24162 +       struct vcmd_set_sched_v4 vc_data;
24163 +
24164 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24165 +               return -EFAULT;
24166 +
24167 +       return do_set_sched_v4(vxi, &vc_data);
24168 +}
24169 +
24170 +       /* latest interface is v5 */
24171 +
24172 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24173 +{
24174 +       struct vcmd_sched_v5 vc_data;
24175 +
24176 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24177 +               return -EFAULT;
24178 +
24179 +       return do_set_sched(vxi, &vc_data);
24180 +}
24181 +
24182 +
24183 +#define COPY_PRI(C) C(prio_bias)
24184 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24185 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24186 +                   C(fill_rate[1]); C(interval[1]);
24187 +
24188 +#define COPY_VALUE(name) vc_data.name = data->name
24189 +
24190 +
24191 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24192 +{
24193 +       struct vcmd_sched_v5 vc_data;
24194 +
24195 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24196 +               return -EFAULT;
24197 +
24198 +       if (vc_data.mask & VXSM_CPU_ID) {
24199 +               int cpu = vc_data.cpu_id;
24200 +               struct _vx_sched_pc *data;
24201 +
24202 +               if (!cpu_possible(cpu))
24203 +                       return -EINVAL;
24204 +
24205 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24206 +               COPY_TOK(COPY_VALUE);
24207 +               COPY_PRI(COPY_VALUE);
24208 +               COPY_FRI(COPY_VALUE);
24209 +
24210 +               if (data->flags & VXSF_IDLE_TIME)
24211 +                       vc_data.mask |= VXSM_IDLE_TIME;
24212 +       } else {
24213 +               struct _vx_sched *data = &vxi->sched;
24214 +
24215 +               COPY_TOK(COPY_VALUE);
24216 +               COPY_PRI(COPY_VALUE);
24217 +               COPY_FRI(COPY_VALUE);
24218 +       }
24219 +
24220 +       if (vc_data.mask & VXSM_MSEC) {
24221 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24222 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24223 +       }
24224 +
24225 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24226 +               return -EFAULT;
24227 +       return 0;
24228 +}
24229 +
24230 +
24231 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24232 +{
24233 +       struct vcmd_sched_info vc_data;
24234 +       int cpu;
24235 +
24236 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24237 +               return -EFAULT;
24238 +
24239 +       cpu = vc_data.cpu_id;
24240 +       if (!cpu_possible(cpu))
24241 +               return -EINVAL;
24242 +
24243 +       if (vxi) {
24244 +               struct _vx_sched_pc *sched_pc =
24245 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24246 +
24247 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24248 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24249 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24250 +               vc_data.vavavoom = sched_pc->vavavoom;
24251 +       }
24252 +       vc_data.token_usec = ticks_to_usec(1);
24253 +
24254 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24255 +               return -EFAULT;
24256 +       return 0;
24257 +}
24258 +
24259 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/sched_init.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sched_init.h
24260 --- linux-2.6.27.6/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
24261 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sched_init.h       2008-10-13 14:54:20.000000000 +0200
24262 @@ -0,0 +1,50 @@
24263 +
24264 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24265 +{
24266 +       static struct lock_class_key tokens_lock_key;
24267 +
24268 +       /* scheduling; hard code starting values as constants */
24269 +       sched->fill_rate[0]     = 1;
24270 +       sched->interval[0]      = 4;
24271 +       sched->fill_rate[1]     = 1;
24272 +       sched->interval[1]      = 8;
24273 +       sched->tokens           = HZ >> 2;
24274 +       sched->tokens_min       = HZ >> 4;
24275 +       sched->tokens_max       = HZ >> 1;
24276 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24277 +       sched->prio_bias        = 0;
24278 +
24279 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24280 +}
24281 +
24282 +static inline
24283 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24284 +{
24285 +       sched_pc->fill_rate[0]  = 1;
24286 +       sched_pc->interval[0]   = 4;
24287 +       sched_pc->fill_rate[1]  = 1;
24288 +       sched_pc->interval[1]   = 8;
24289 +       sched_pc->tokens        = HZ >> 2;
24290 +       sched_pc->tokens_min    = HZ >> 4;
24291 +       sched_pc->tokens_max    = HZ >> 1;
24292 +       sched_pc->prio_bias     = 0;
24293 +       sched_pc->vavavoom      = 0;
24294 +       sched_pc->token_time    = 0;
24295 +       sched_pc->idle_time     = 0;
24296 +       sched_pc->norm_time     = jiffies;
24297 +
24298 +       sched_pc->user_ticks = 0;
24299 +       sched_pc->sys_ticks = 0;
24300 +       sched_pc->hold_ticks = 0;
24301 +}
24302 +
24303 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24304 +{
24305 +       return;
24306 +}
24307 +
24308 +static inline
24309 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24310 +{
24311 +       return;
24312 +}
24313 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/sched_proc.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sched_proc.h
24314 --- linux-2.6.27.6/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
24315 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sched_proc.h       2008-10-13 14:54:20.000000000 +0200
24316 @@ -0,0 +1,57 @@
24317 +#ifndef _VX_SCHED_PROC_H
24318 +#define _VX_SCHED_PROC_H
24319 +
24320 +
24321 +static inline
24322 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24323 +{
24324 +       int length = 0;
24325 +
24326 +       length += sprintf(buffer,
24327 +               "FillRate:\t%8d,%d\n"
24328 +               "Interval:\t%8d,%d\n"
24329 +               "TokensMin:\t%8d\n"
24330 +               "TokensMax:\t%8d\n"
24331 +               "PrioBias:\t%8d\n",
24332 +               sched->fill_rate[0],
24333 +               sched->fill_rate[1],
24334 +               sched->interval[0],
24335 +               sched->interval[1],
24336 +               sched->tokens_min,
24337 +               sched->tokens_max,
24338 +               sched->prio_bias);
24339 +       return length;
24340 +}
24341 +
24342 +static inline
24343 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24344 +       char *buffer, int cpu)
24345 +{
24346 +       int length = 0;
24347 +
24348 +       length += sprintf(buffer + length,
24349 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24350 +               (unsigned long long)sched_pc->user_ticks,
24351 +               (unsigned long long)sched_pc->sys_ticks,
24352 +               (unsigned long long)sched_pc->hold_ticks,
24353 +               sched_pc->token_time,
24354 +               sched_pc->idle_time);
24355 +       length += sprintf(buffer + length,
24356 +               " %c%c %d %d %d %d/%d %d/%d",
24357 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24358 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24359 +               sched_pc->tokens,
24360 +               sched_pc->tokens_min,
24361 +               sched_pc->tokens_max,
24362 +               sched_pc->fill_rate[0],
24363 +               sched_pc->interval[0],
24364 +               sched_pc->fill_rate[1],
24365 +               sched_pc->interval[1]);
24366 +       length += sprintf(buffer + length,
24367 +               " %d %d\n",
24368 +               sched_pc->prio_bias,
24369 +               sched_pc->vavavoom);
24370 +       return length;
24371 +}
24372 +
24373 +#endif /* _VX_SCHED_PROC_H */
24374 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/signal.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/signal.c
24375 --- linux-2.6.27.6/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
24376 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/signal.c   2008-10-13 14:54:20.000000000 +0200
24377 @@ -0,0 +1,132 @@
24378 +/*
24379 + *  linux/kernel/vserver/signal.c
24380 + *
24381 + *  Virtual Server: Signal Support
24382 + *
24383 + *  Copyright (C) 2003-2007  Herbert Pötzl
24384 + *
24385 + *  V0.01  broken out from vcontext V0.05
24386 + *  V0.02  changed vcmds to vxi arg
24387 + *  V0.03  adjusted siginfo for kill
24388 + *
24389 + */
24390 +
24391 +#include <asm/uaccess.h>
24392 +
24393 +#include <linux/vs_context.h>
24394 +#include <linux/vs_pid.h>
24395 +#include <linux/vserver/signal_cmd.h>
24396 +
24397 +
24398 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24399 +{
24400 +       int retval, count = 0;
24401 +       struct task_struct *p;
24402 +       struct siginfo *sip = SEND_SIG_PRIV;
24403 +
24404 +       retval = -ESRCH;
24405 +       vxdprintk(VXD_CBIT(misc, 4),
24406 +               "vx_info_kill(%p[#%d],%d,%d)*",
24407 +               vxi, vxi->vx_id, pid, sig);
24408 +       read_lock(&tasklist_lock);
24409 +       switch (pid) {
24410 +       case  0:
24411 +       case -1:
24412 +               for_each_process(p) {
24413 +                       int err = 0;
24414 +
24415 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24416 +                               (pid && vxi->vx_initpid == p->pid))
24417 +                               continue;
24418 +
24419 +                       err = group_send_sig_info(sig, sip, p);
24420 +                       ++count;
24421 +                       if (err != -EPERM)
24422 +                               retval = err;
24423 +               }
24424 +               break;
24425 +
24426 +       case 1:
24427 +               if (vxi->vx_initpid) {
24428 +                       pid = vxi->vx_initpid;
24429 +                       /* for now, only SIGINT to private init ... */
24430 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24431 +                               /* ... as long as there are tasks left */
24432 +                               (atomic_read(&vxi->vx_tasks) > 1))
24433 +                               sig = SIGINT;
24434 +               }
24435 +               /* fallthrough */
24436 +       default:
24437 +               p = find_task_by_real_pid(pid);
24438 +               if (p) {
24439 +                       if (vx_task_xid(p) == vxi->vx_id)
24440 +                               retval = group_send_sig_info(sig, sip, p);
24441 +               }
24442 +               break;
24443 +       }
24444 +       read_unlock(&tasklist_lock);
24445 +       vxdprintk(VXD_CBIT(misc, 4),
24446 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24447 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24448 +       return retval;
24449 +}
24450 +
24451 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24452 +{
24453 +       struct vcmd_ctx_kill_v0 vc_data;
24454 +
24455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24456 +               return -EFAULT;
24457 +
24458 +       /* special check to allow guest shutdown */
24459 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24460 +               /* forbid killall pid=0 when init is present */
24461 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24462 +               (vc_data.pid > 1)))
24463 +               return -EACCES;
24464 +
24465 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24466 +}
24467 +
24468 +
24469 +static int __wait_exit(struct vx_info *vxi)
24470 +{
24471 +       DECLARE_WAITQUEUE(wait, current);
24472 +       int ret = 0;
24473 +
24474 +       add_wait_queue(&vxi->vx_wait, &wait);
24475 +       set_current_state(TASK_INTERRUPTIBLE);
24476 +
24477 +wait:
24478 +       if (vx_info_state(vxi,
24479 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24480 +               goto out;
24481 +       if (signal_pending(current)) {
24482 +               ret = -ERESTARTSYS;
24483 +               goto out;
24484 +       }
24485 +       schedule();
24486 +       goto wait;
24487 +
24488 +out:
24489 +       set_current_state(TASK_RUNNING);
24490 +       remove_wait_queue(&vxi->vx_wait, &wait);
24491 +       return ret;
24492 +}
24493 +
24494 +
24495 +
24496 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24497 +{
24498 +       struct vcmd_wait_exit_v0 vc_data;
24499 +       int ret;
24500 +
24501 +       ret = __wait_exit(vxi);
24502 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24503 +       vc_data.exit_code = vxi->exit_code;
24504 +
24505 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24506 +               ret = -EFAULT;
24507 +       return ret;
24508 +}
24509 +
24510 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/space.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/space.c
24511 --- linux-2.6.27.6/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
24512 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/space.c    2008-10-31 18:15:28.000000000 +0100
24513 @@ -0,0 +1,398 @@
24514 +/*
24515 + *  linux/kernel/vserver/space.c
24516 + *
24517 + *  Virtual Server: Context Space Support
24518 + *
24519 + *  Copyright (C) 2003-2007  Herbert Pötzl
24520 + *
24521 + *  V0.01  broken out from context.c 0.07
24522 + *  V0.02  added task locking for namespace
24523 + *  V0.03  broken out vx_enter_namespace
24524 + *  V0.04  added *space support and commands
24525 + *
24526 + */
24527 +
24528 +#include <linux/utsname.h>
24529 +#include <linux/nsproxy.h>
24530 +#include <linux/err.h>
24531 +#include <asm/uaccess.h>
24532 +
24533 +#include <linux/vs_context.h>
24534 +#include <linux/vserver/space.h>
24535 +#include <linux/vserver/space_cmd.h>
24536 +
24537 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24538 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24539 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24540 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24541 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24542 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24543 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24544 +
24545 +
24546 +/* namespace functions */
24547 +
24548 +#include <linux/mnt_namespace.h>
24549 +#include <linux/user_namespace.h>
24550 +#include <linux/pid_namespace.h>
24551 +#include <linux/ipc_namespace.h>
24552 +#include <net/net_namespace.h>
24553 +
24554 +
24555 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24556 +       .mask = CLONE_FS |
24557 +               CLONE_NEWNS |
24558 +               CLONE_NEWUTS |
24559 +               CLONE_NEWIPC |
24560 +               CLONE_NEWUSER |
24561 +               0
24562 +};
24563 +
24564 +static const struct vcmd_space_mask_v1 space_mask = {
24565 +       .mask = CLONE_FS |
24566 +               CLONE_NEWNS |
24567 +               CLONE_NEWUTS |
24568 +               CLONE_NEWIPC |
24569 +               CLONE_NEWUSER |
24570 +#ifdef CONFIG_PID_NS
24571 +               CLONE_NEWPID |
24572 +#endif
24573 +#ifdef CONFIG_NET_NS
24574 +               CLONE_NEWNET |
24575 +#endif
24576 +               0
24577 +};
24578 +
24579 +static const struct vcmd_space_mask_v1 default_space_mask = {
24580 +       .mask = CLONE_FS |
24581 +               CLONE_NEWNS |
24582 +               CLONE_NEWUTS |
24583 +               CLONE_NEWIPC |
24584 +               CLONE_NEWUSER |
24585 +#ifdef CONFIG_PID_NS
24586 +//             CLONE_NEWPID |
24587 +#endif
24588 +               0
24589 +};
24590 +
24591 +/*
24592 + *     build a new nsproxy mix
24593 + *      assumes that both proxies are 'const'
24594 + *     does not touch nsproxy refcounts
24595 + *     will hold a reference on the result.
24596 + */
24597 +
24598 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24599 +       struct nsproxy *new_nsproxy, unsigned long mask)
24600 +{
24601 +       struct mnt_namespace *old_ns;
24602 +       struct uts_namespace *old_uts;
24603 +       struct ipc_namespace *old_ipc;
24604 +       struct user_namespace *old_user;
24605 +#ifdef CONFIG_PID_NS
24606 +       struct pid_namespace *old_pid;
24607 +#endif
24608 +#ifdef CONFIG_NET_NS
24609 +       struct net *old_net;
24610 +#endif
24611 +       struct nsproxy *nsproxy;
24612 +
24613 +       nsproxy = copy_nsproxy(old_nsproxy);
24614 +       if (!nsproxy)
24615 +               goto out;
24616 +
24617 +       if (mask & CLONE_NEWNS) {
24618 +               old_ns = nsproxy->mnt_ns;
24619 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24620 +               if (nsproxy->mnt_ns)
24621 +                       get_mnt_ns(nsproxy->mnt_ns);
24622 +       } else
24623 +               old_ns = NULL;
24624 +
24625 +       if (mask & CLONE_NEWUTS) {
24626 +               old_uts = nsproxy->uts_ns;
24627 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24628 +               if (nsproxy->uts_ns)
24629 +                       get_uts_ns(nsproxy->uts_ns);
24630 +       } else
24631 +               old_uts = NULL;
24632 +
24633 +       if (mask & CLONE_NEWIPC) {
24634 +               old_ipc = nsproxy->ipc_ns;
24635 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24636 +               if (nsproxy->ipc_ns)
24637 +                       get_ipc_ns(nsproxy->ipc_ns);
24638 +       } else
24639 +               old_ipc = NULL;
24640 +
24641 +       if (mask & CLONE_NEWUSER) {
24642 +               old_user = nsproxy->user_ns;
24643 +               nsproxy->user_ns = new_nsproxy->user_ns;
24644 +               if (nsproxy->user_ns)
24645 +                       get_user_ns(nsproxy->user_ns);
24646 +       } else
24647 +               old_user = NULL;
24648 +
24649 +#ifdef CONFIG_PID_NS
24650 +       if (mask & CLONE_NEWPID) {
24651 +               old_pid = nsproxy->pid_ns;
24652 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24653 +               if (nsproxy->pid_ns)
24654 +                       get_pid_ns(nsproxy->pid_ns);
24655 +       } else
24656 +               old_pid = NULL;
24657 +#endif
24658 +#ifdef CONFIG_NET_NS
24659 +       if (mask & CLONE_NEWNET) {
24660 +               old_net = nsproxy->net_ns;
24661 +               nsproxy->net_ns = new_nsproxy->net_ns;
24662 +               if (nsproxy->net_ns)
24663 +                       get_net(nsproxy->net_ns);
24664 +       } else
24665 +               old_net = NULL;
24666 +#endif
24667 +       if (old_ns)
24668 +               put_mnt_ns(old_ns);
24669 +       if (old_uts)
24670 +               put_uts_ns(old_uts);
24671 +       if (old_ipc)
24672 +               put_ipc_ns(old_ipc);
24673 +       if (old_user)
24674 +               put_user_ns(old_user);
24675 +#ifdef CONFIG_PID_NS
24676 +       if (old_pid)
24677 +               put_pid_ns(old_pid);
24678 +#endif
24679 +#ifdef CONFIG_NET_NS
24680 +       if (old_net)
24681 +               put_net(old_net);
24682 +#endif
24683 +out:
24684 +       return nsproxy;
24685 +}
24686 +
24687 +
24688 +/*
24689 + *     merge two nsproxy structs into a new one.
24690 + *     will hold a reference on the result.
24691 + */
24692 +
24693 +static inline
24694 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24695 +       struct nsproxy *proxy, unsigned long mask)
24696 +{
24697 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24698 +
24699 +       if (!proxy)
24700 +               return NULL;
24701 +
24702 +       if (mask) {
24703 +               /* vs_mix_nsproxy returns with reference */
24704 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24705 +                       proxy, mask);
24706 +       }
24707 +       get_nsproxy(proxy);
24708 +       return proxy;
24709 +}
24710 +
24711 +/*
24712 + *     merge two fs structs into a new one.
24713 + *     will take a reference on the result.
24714 + */
24715 +
24716 +static inline
24717 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24718 +       struct fs_struct *fs, unsigned long mask)
24719 +{
24720 +       if (!(mask & CLONE_FS)) {
24721 +               if (old)
24722 +                       atomic_inc(&old->count);
24723 +               return old;
24724 +       }
24725 +
24726 +       if (!fs)
24727 +               return NULL;
24728 +
24729 +       return copy_fs_struct(fs);
24730 +}
24731 +
24732 +
24733 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24734 +{
24735 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24736 +       struct fs_struct *fs, *fs_cur, *fs_new;
24737 +       int ret;
24738 +
24739 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24740 +               vxi, vxi->vx_id, mask, index);
24741 +
24742 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24743 +               return -EACCES;
24744 +
24745 +       if (!mask)
24746 +               mask = vxi->vx_nsmask[index];
24747 +
24748 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24749 +               return -EINVAL;
24750 +
24751 +       proxy = vxi->vx_nsproxy[index];
24752 +       fs = vxi->vx_fs[index];
24753 +
24754 +       task_lock(current);
24755 +       fs_cur = current->fs;
24756 +       atomic_inc(&fs_cur->count);
24757 +       proxy_cur = current->nsproxy;
24758 +       get_nsproxy(proxy_cur);
24759 +       task_unlock(current);
24760 +
24761 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24762 +       if (IS_ERR(fs_new)) {
24763 +               ret = PTR_ERR(fs_new);
24764 +               goto out_put;
24765 +       }
24766 +
24767 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24768 +       if (IS_ERR(proxy_new)) {
24769 +               ret = PTR_ERR(proxy_new);
24770 +               goto out_put_fs;
24771 +       }
24772 +
24773 +       fs_new = xchg(&current->fs, fs_new);
24774 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24775 +       ret = 0;
24776 +
24777 +       if (proxy_new)
24778 +               put_nsproxy(proxy_new);
24779 +out_put_fs:
24780 +       if (fs_new)
24781 +               put_fs_struct(fs_new);
24782 +out_put:
24783 +       if (proxy_cur)
24784 +               put_nsproxy(proxy_cur);
24785 +       if (fs_cur)
24786 +               put_fs_struct(fs_cur);
24787 +       return ret;
24788 +}
24789 +
24790 +
24791 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24792 +{
24793 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24794 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24795 +       int ret;
24796 +
24797 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24798 +               vxi, vxi->vx_id, mask, index);
24799 +#if 0
24800 +       if (!mask)
24801 +               mask = default_space_mask.mask;
24802 +#endif
24803 +       if ((mask & space_mask.mask) != mask)
24804 +               return -EINVAL;
24805 +
24806 +       proxy_vxi = vxi->vx_nsproxy[index];
24807 +       fs_vxi = vxi->vx_fs[index];
24808 +
24809 +       task_lock(current);
24810 +       fs_cur = current->fs;
24811 +       atomic_inc(&fs_cur->count);
24812 +       proxy_cur = current->nsproxy;
24813 +       get_nsproxy(proxy_cur);
24814 +       task_unlock(current);
24815 +
24816 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24817 +       if (IS_ERR(fs_new)) {
24818 +               ret = PTR_ERR(fs_new);
24819 +               goto out_put;
24820 +       }
24821 +
24822 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24823 +       if (IS_ERR(proxy_new)) {
24824 +               ret = PTR_ERR(proxy_new);
24825 +               goto out_put_fs;
24826 +       }
24827 +
24828 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24829 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24830 +       vxi->vx_nsmask[index] |= mask;
24831 +       ret = 0;
24832 +
24833 +       if (proxy_new)
24834 +               put_nsproxy(proxy_new);
24835 +out_put_fs:
24836 +       if (fs_new)
24837 +               put_fs_struct(fs_new);
24838 +out_put:
24839 +       if (proxy_cur)
24840 +               put_nsproxy(proxy_cur);
24841 +       if (fs_cur)
24842 +               put_fs_struct(fs_cur);
24843 +       return ret;
24844 +}
24845 +
24846 +
24847 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24848 +{
24849 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24850 +
24851 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24852 +               return -EFAULT;
24853 +
24854 +       return vx_enter_space(vxi, vc_data.mask, 0);
24855 +}
24856 +
24857 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24858 +{
24859 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24860 +
24861 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24862 +               return -EFAULT;
24863 +
24864 +       if (vc_data.index >= VX_SPACES)
24865 +               return -EINVAL;
24866 +
24867 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24868 +}
24869 +
24870 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24871 +{
24872 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24873 +
24874 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24875 +               return -EFAULT;
24876 +
24877 +       return vx_set_space(vxi, vc_data.mask, 0);
24878 +}
24879 +
24880 +int vc_set_space(struct vx_info *vxi, void __user *data)
24881 +{
24882 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24883 +
24884 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24885 +               return -EFAULT;
24886 +
24887 +       if (vc_data.index >= VX_SPACES)
24888 +               return -EINVAL;
24889 +
24890 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24891 +}
24892 +
24893 +int vc_get_space_mask(void __user *data, int type)
24894 +{
24895 +       const struct vcmd_space_mask_v1 *mask;
24896 +
24897 +       if (type == 0)
24898 +               mask = &space_mask_v0;
24899 +       else if (type == 1)
24900 +               mask = &space_mask;
24901 +       else
24902 +               mask = &default_space_mask;
24903 +
24904 +       vxdprintk(VXD_CBIT(space, 10),
24905 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24906 +
24907 +       if (copy_to_user(data, mask, sizeof(*mask)))
24908 +               return -EFAULT;
24909 +       return 0;
24910 +}
24911 +
24912 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/switch.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/switch.c
24913 --- linux-2.6.27.6/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
24914 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/switch.c   2008-10-31 04:42:36.000000000 +0100
24915 @@ -0,0 +1,543 @@
24916 +/*
24917 + *  linux/kernel/vserver/switch.c
24918 + *
24919 + *  Virtual Server: Syscall Switch
24920 + *
24921 + *  Copyright (C) 2003-2007  Herbert Pötzl
24922 + *
24923 + *  V0.01  syscall switch
24924 + *  V0.02  added signal to context
24925 + *  V0.03  added rlimit functions
24926 + *  V0.04  added iattr, task/xid functions
24927 + *  V0.05  added debug/history stuff
24928 + *  V0.06  added compat32 layer
24929 + *  V0.07  vcmd args and perms
24930 + *  V0.08  added status commands
24931 + *  V0.09  added tag commands
24932 + *  V0.10  added oom bias
24933 + *  V0.11  added device commands
24934 + *
24935 + */
24936 +
24937 +#include <linux/vs_context.h>
24938 +#include <linux/vs_network.h>
24939 +#include <linux/vserver/switch.h>
24940 +
24941 +#include "vci_config.h"
24942 +
24943 +
24944 +static inline
24945 +int vc_get_version(uint32_t id)
24946 +{
24947 +       return VCI_VERSION;
24948 +}
24949 +
24950 +static inline
24951 +int vc_get_vci(uint32_t id)
24952 +{
24953 +       return vci_kernel_config();
24954 +}
24955 +
24956 +#include <linux/vserver/context_cmd.h>
24957 +#include <linux/vserver/cvirt_cmd.h>
24958 +#include <linux/vserver/cacct_cmd.h>
24959 +#include <linux/vserver/limit_cmd.h>
24960 +#include <linux/vserver/network_cmd.h>
24961 +#include <linux/vserver/sched_cmd.h>
24962 +#include <linux/vserver/debug_cmd.h>
24963 +#include <linux/vserver/inode_cmd.h>
24964 +#include <linux/vserver/dlimit_cmd.h>
24965 +#include <linux/vserver/signal_cmd.h>
24966 +#include <linux/vserver/space_cmd.h>
24967 +#include <linux/vserver/tag_cmd.h>
24968 +#include <linux/vserver/device_cmd.h>
24969 +
24970 +#include <linux/vserver/inode.h>
24971 +#include <linux/vserver/dlimit.h>
24972 +
24973 +
24974 +#ifdef CONFIG_COMPAT
24975 +#define __COMPAT(name, id, data, compat)       \
24976 +       (compat) ? name ## _x32(id, data) : name(id, data)
24977 +#define __COMPAT_NO_ID(name, data, compat)     \
24978 +       (compat) ? name ## _x32(data) : name(data)
24979 +#else
24980 +#define __COMPAT(name, id, data, compat)       \
24981 +       name(id, data)
24982 +#define __COMPAT_NO_ID(name, data, compat)     \
24983 +       name(data)
24984 +#endif
24985 +
24986 +
24987 +static inline
24988 +long do_vcmd(uint32_t cmd, uint32_t id,
24989 +       struct vx_info *vxi, struct nx_info *nxi,
24990 +       void __user *data, int compat)
24991 +{
24992 +       switch (cmd) {
24993 +
24994 +       case VCMD_get_version:
24995 +               return vc_get_version(id);
24996 +       case VCMD_get_vci:
24997 +               return vc_get_vci(id);
24998 +
24999 +       case VCMD_task_xid:
25000 +               return vc_task_xid(id);
25001 +       case VCMD_vx_info:
25002 +               return vc_vx_info(vxi, data);
25003 +
25004 +       case VCMD_task_nid:
25005 +               return vc_task_nid(id);
25006 +       case VCMD_nx_info:
25007 +               return vc_nx_info(nxi, data);
25008 +
25009 +       case VCMD_task_tag:
25010 +               return vc_task_tag(id);
25011 +
25012 +       case VCMD_set_space_v1:
25013 +               return vc_set_space_v1(vxi, data);
25014 +       /* this is version 2 */
25015 +       case VCMD_set_space:
25016 +               return vc_set_space(vxi, data);
25017 +
25018 +       case VCMD_get_space_mask_v0:
25019 +               return vc_get_space_mask(data, 0);
25020 +       /* this is version 1 */
25021 +       case VCMD_get_space_mask:
25022 +               return vc_get_space_mask(data, 1);
25023 +
25024 +       case VCMD_get_space_default:
25025 +               return vc_get_space_mask(data, -1);
25026 +
25027 +#ifdef CONFIG_IA32_EMULATION
25028 +       case VCMD_get_rlimit:
25029 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25030 +       case VCMD_set_rlimit:
25031 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25032 +#else
25033 +       case VCMD_get_rlimit:
25034 +               return vc_get_rlimit(vxi, data);
25035 +       case VCMD_set_rlimit:
25036 +               return vc_set_rlimit(vxi, data);
25037 +#endif
25038 +       case VCMD_get_rlimit_mask:
25039 +               return vc_get_rlimit_mask(id, data);
25040 +       case VCMD_reset_minmax:
25041 +               return vc_reset_minmax(vxi, data);
25042 +
25043 +       case VCMD_get_vhi_name:
25044 +               return vc_get_vhi_name(vxi, data);
25045 +       case VCMD_set_vhi_name:
25046 +               return vc_set_vhi_name(vxi, data);
25047 +
25048 +       case VCMD_ctx_stat:
25049 +               return vc_ctx_stat(vxi, data);
25050 +       case VCMD_virt_stat:
25051 +               return vc_virt_stat(vxi, data);
25052 +       case VCMD_sock_stat:
25053 +               return vc_sock_stat(vxi, data);
25054 +       case VCMD_rlimit_stat:
25055 +               return vc_rlimit_stat(vxi, data);
25056 +
25057 +       case VCMD_set_cflags:
25058 +               return vc_set_cflags(vxi, data);
25059 +       case VCMD_get_cflags:
25060 +               return vc_get_cflags(vxi, data);
25061 +
25062 +       /* this is version 1 */
25063 +       case VCMD_set_ccaps:
25064 +               return vc_set_ccaps(vxi, data);
25065 +       /* this is version 1 */
25066 +       case VCMD_get_ccaps:
25067 +               return vc_get_ccaps(vxi, data);
25068 +       case VCMD_set_bcaps:
25069 +               return vc_set_bcaps(vxi, data);
25070 +       case VCMD_get_bcaps:
25071 +               return vc_get_bcaps(vxi, data);
25072 +
25073 +       case VCMD_set_badness:
25074 +               return vc_set_badness(vxi, data);
25075 +       case VCMD_get_badness:
25076 +               return vc_get_badness(vxi, data);
25077 +
25078 +       case VCMD_set_nflags:
25079 +               return vc_set_nflags(nxi, data);
25080 +       case VCMD_get_nflags:
25081 +               return vc_get_nflags(nxi, data);
25082 +
25083 +       case VCMD_set_ncaps:
25084 +               return vc_set_ncaps(nxi, data);
25085 +       case VCMD_get_ncaps:
25086 +               return vc_get_ncaps(nxi, data);
25087 +
25088 +       case VCMD_set_sched_v4:
25089 +               return vc_set_sched_v4(vxi, data);
25090 +       /* this is version 5 */
25091 +       case VCMD_set_sched:
25092 +               return vc_set_sched(vxi, data);
25093 +       case VCMD_get_sched:
25094 +               return vc_get_sched(vxi, data);
25095 +       case VCMD_sched_info:
25096 +               return vc_sched_info(vxi, data);
25097 +
25098 +       case VCMD_add_dlimit:
25099 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25100 +       case VCMD_rem_dlimit:
25101 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25102 +       case VCMD_set_dlimit:
25103 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25104 +       case VCMD_get_dlimit:
25105 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25106 +
25107 +       case VCMD_ctx_kill:
25108 +               return vc_ctx_kill(vxi, data);
25109 +
25110 +       case VCMD_wait_exit:
25111 +               return vc_wait_exit(vxi, data);
25112 +
25113 +       case VCMD_get_iattr:
25114 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25115 +       case VCMD_set_iattr:
25116 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25117 +
25118 +       case VCMD_fget_iattr:
25119 +               return vc_fget_iattr(id, data);
25120 +       case VCMD_fset_iattr:
25121 +               return vc_fset_iattr(id, data);
25122 +
25123 +       case VCMD_enter_space_v0:
25124 +               return vc_enter_space_v1(vxi, NULL);
25125 +       case VCMD_enter_space_v1:
25126 +               return vc_enter_space_v1(vxi, data);
25127 +       /* this is version 2 */
25128 +       case VCMD_enter_space:
25129 +               return vc_enter_space(vxi, data);
25130 +
25131 +       case VCMD_ctx_create_v0:
25132 +               return vc_ctx_create(id, NULL);
25133 +       case VCMD_ctx_create:
25134 +               return vc_ctx_create(id, data);
25135 +       case VCMD_ctx_migrate_v0:
25136 +               return vc_ctx_migrate(vxi, NULL);
25137 +       case VCMD_ctx_migrate:
25138 +               return vc_ctx_migrate(vxi, data);
25139 +
25140 +       case VCMD_net_create_v0:
25141 +               return vc_net_create(id, NULL);
25142 +       case VCMD_net_create:
25143 +               return vc_net_create(id, data);
25144 +       case VCMD_net_migrate:
25145 +               return vc_net_migrate(nxi, data);
25146 +
25147 +       case VCMD_tag_migrate:
25148 +               return vc_tag_migrate(id);
25149 +
25150 +       case VCMD_net_add:
25151 +               return vc_net_add(nxi, data);
25152 +       case VCMD_net_remove:
25153 +               return vc_net_remove(nxi, data);
25154 +
25155 +       case VCMD_net_add_ipv4:
25156 +               return vc_net_add_ipv4(nxi, data);
25157 +       case VCMD_net_remove_ipv4:
25158 +               return vc_net_remove_ipv4(nxi, data);
25159 +#ifdef CONFIG_IPV6
25160 +       case VCMD_net_add_ipv6:
25161 +               return vc_net_add_ipv6(nxi, data);
25162 +       case VCMD_net_remove_ipv6:
25163 +               return vc_net_remove_ipv6(nxi, data);
25164 +#endif
25165 +/*     case VCMD_add_match_ipv4:
25166 +               return vc_add_match_ipv4(nxi, data);
25167 +       case VCMD_get_match_ipv4:
25168 +               return vc_get_match_ipv4(nxi, data);
25169 +#ifdef CONFIG_IPV6
25170 +       case VCMD_add_match_ipv6:
25171 +               return vc_add_match_ipv6(nxi, data);
25172 +       case VCMD_get_match_ipv6:
25173 +               return vc_get_match_ipv6(nxi, data);
25174 +#endif */
25175 +
25176 +#ifdef CONFIG_VSERVER_DEVICE
25177 +       case VCMD_set_mapping:
25178 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25179 +       case VCMD_unset_mapping:
25180 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25181 +#endif
25182 +#ifdef CONFIG_VSERVER_HISTORY
25183 +       case VCMD_dump_history:
25184 +               return vc_dump_history(id);
25185 +       case VCMD_read_history:
25186 +               return __COMPAT(vc_read_history, id, data, compat);
25187 +#endif
25188 +#ifdef CONFIG_VSERVER_MONITOR
25189 +       case VCMD_read_monitor:
25190 +               return __COMPAT(vc_read_monitor, id, data, compat);
25191 +#endif
25192 +       default:
25193 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25194 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25195 +       }
25196 +       return -ENOSYS;
25197 +}
25198 +
25199 +
25200 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25201 +       case VCMD_ ## vcmd: perm = _perm;               \
25202 +               args = _args; flags = _flags; break
25203 +
25204 +
25205 +#define VCA_NONE       0x00
25206 +#define VCA_VXI                0x01
25207 +#define VCA_NXI                0x02
25208 +
25209 +#define VCF_NONE       0x00
25210 +#define VCF_INFO       0x01
25211 +#define VCF_ADMIN      0x02
25212 +#define VCF_ARES       0x06    /* includes admin */
25213 +#define VCF_SETUP      0x08
25214 +
25215 +#define VCF_ZIDOK      0x10    /* zero id okay */
25216 +
25217 +
25218 +static inline
25219 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25220 +{
25221 +       long ret;
25222 +       int permit = -1, state = 0;
25223 +       int perm = -1, args = 0, flags = 0;
25224 +       struct vx_info *vxi = NULL;
25225 +       struct nx_info *nxi = NULL;
25226 +
25227 +       switch (cmd) {
25228 +       /* unpriviledged commands */
25229 +       __VCMD(get_version,      0, VCA_NONE,   0);
25230 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25231 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25232 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25233 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25234 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25235 +
25236 +       /* info commands */
25237 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25238 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25239 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25240 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25241 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25242 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25243 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25244 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25245 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25246 +
25247 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25248 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25249 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25250 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25251 +
25252 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25253 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25254 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25255 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25256 +
25257 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25258 +
25259 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25260 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25261 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25262 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25263 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25264 +
25265 +       /* lower admin commands */
25266 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25267 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25268 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25269 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25270 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25271 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25272 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25273 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25274 +
25275 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25276 +       __VCMD(net_create,       5, VCA_NONE,   0);
25277 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25278 +
25279 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25280 +
25281 +       /* higher admin commands */
25282 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25283 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25284 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25285 +
25286 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25287 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25288 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25289 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25290 +
25291 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25292 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25293 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25294 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25295 +
25296 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25297 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25298 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25299 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25300 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25301 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25302 +#ifdef CONFIG_IPV6
25303 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25304 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25305 +#endif
25306 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25307 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25308 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25309 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25310 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25311 +
25312 +#ifdef CONFIG_VSERVER_DEVICE
25313 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25314 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25315 +#endif
25316 +       /* debug level admin commands */
25317 +#ifdef CONFIG_VSERVER_HISTORY
25318 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25319 +       __VCMD(read_history,     9, VCA_NONE,   0);
25320 +#endif
25321 +#ifdef CONFIG_VSERVER_MONITOR
25322 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25323 +#endif
25324 +
25325 +       default:
25326 +               perm = -1;
25327 +       }
25328 +
25329 +       vxdprintk(VXD_CBIT(switch, 0),
25330 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25331 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25332 +               VC_VERSION(cmd), id, data, compat,
25333 +               perm, args, flags);
25334 +
25335 +       ret = -ENOSYS;
25336 +       if (perm < 0)
25337 +               goto out;
25338 +
25339 +       state = 1;
25340 +       if (!capable(CAP_CONTEXT))
25341 +               goto out;
25342 +
25343 +       state = 2;
25344 +       /* moved here from the individual commands */
25345 +       ret = -EPERM;
25346 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25347 +               goto out;
25348 +
25349 +       state = 3;
25350 +       /* vcmd involves resource management  */
25351 +       ret = -EPERM;
25352 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25353 +               goto out;
25354 +
25355 +       state = 4;
25356 +       /* various legacy exceptions */
25357 +       switch (cmd) {
25358 +       /* will go away when spectator is a cap */
25359 +       case VCMD_ctx_migrate_v0:
25360 +       case VCMD_ctx_migrate:
25361 +               if (id == 1) {
25362 +                       current->xid = 1;
25363 +                       ret = 1;
25364 +                       goto out;
25365 +               }
25366 +               break;
25367 +
25368 +       /* will go away when spectator is a cap */
25369 +       case VCMD_net_migrate:
25370 +               if (id == 1) {
25371 +                       current->nid = 1;
25372 +                       ret = 1;
25373 +                       goto out;
25374 +               }
25375 +               break;
25376 +       }
25377 +
25378 +       /* vcmds are fine by default */
25379 +       permit = 1;
25380 +
25381 +       /* admin type vcmds require admin ... */
25382 +       if (flags & VCF_ADMIN)
25383 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25384 +
25385 +       /* ... but setup type vcmds override that */
25386 +       if (!permit && (flags & VCF_SETUP))
25387 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25388 +
25389 +       state = 5;
25390 +       ret = -EPERM;
25391 +       if (!permit)
25392 +               goto out;
25393 +
25394 +       state = 6;
25395 +       if (!id && (flags & VCF_ZIDOK))
25396 +               goto skip_id;
25397 +
25398 +       ret = -ESRCH;
25399 +       if (args & VCA_VXI) {
25400 +               vxi = lookup_vx_info(id);
25401 +               if (!vxi)
25402 +                       goto out;
25403 +
25404 +               if ((flags & VCF_ADMIN) &&
25405 +                       /* special case kill for shutdown */
25406 +                       (cmd != VCMD_ctx_kill) &&
25407 +                       /* can context be administrated? */
25408 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25409 +                       ret = -EACCES;
25410 +                       goto out_vxi;
25411 +               }
25412 +       }
25413 +       state = 7;
25414 +       if (args & VCA_NXI) {
25415 +               nxi = lookup_nx_info(id);
25416 +               if (!nxi)
25417 +                       goto out_vxi;
25418 +
25419 +               if ((flags & VCF_ADMIN) &&
25420 +                       /* can context be administrated? */
25421 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25422 +                       ret = -EACCES;
25423 +                       goto out_nxi;
25424 +               }
25425 +       }
25426 +skip_id:
25427 +       state = 8;
25428 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25429 +
25430 +out_nxi:
25431 +       if ((args & VCA_NXI) && nxi)
25432 +               put_nx_info(nxi);
25433 +out_vxi:
25434 +       if ((args & VCA_VXI) && vxi)
25435 +               put_vx_info(vxi);
25436 +out:
25437 +       vxdprintk(VXD_CBIT(switch, 1),
25438 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25439 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25440 +               VC_VERSION(cmd), ret, ret, state, permit);
25441 +       return ret;
25442 +}
25443 +
25444 +asmlinkage long
25445 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25446 +{
25447 +       return do_vserver(cmd, id, data, 0);
25448 +}
25449 +
25450 +#ifdef CONFIG_COMPAT
25451 +
25452 +asmlinkage long
25453 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25454 +{
25455 +       return do_vserver(cmd, id, data, 1);
25456 +}
25457 +
25458 +#endif /* CONFIG_COMPAT */
25459 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/sysctl.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sysctl.c
25460 --- linux-2.6.27.6/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
25461 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/sysctl.c   2008-10-13 14:54:20.000000000 +0200
25462 @@ -0,0 +1,244 @@
25463 +/*
25464 + *  kernel/vserver/sysctl.c
25465 + *
25466 + *  Virtual Context Support
25467 + *
25468 + *  Copyright (C) 2004-2007  Herbert Pötzl
25469 + *
25470 + *  V0.01  basic structure
25471 + *
25472 + */
25473 +
25474 +#include <linux/module.h>
25475 +#include <linux/ctype.h>
25476 +#include <linux/sysctl.h>
25477 +#include <linux/parser.h>
25478 +#include <asm/uaccess.h>
25479 +
25480 +
25481 +enum {
25482 +       CTL_DEBUG_ERROR         = 0,
25483 +       CTL_DEBUG_SWITCH        = 1,
25484 +       CTL_DEBUG_XID,
25485 +       CTL_DEBUG_NID,
25486 +       CTL_DEBUG_TAG,
25487 +       CTL_DEBUG_NET,
25488 +       CTL_DEBUG_LIMIT,
25489 +       CTL_DEBUG_CRES,
25490 +       CTL_DEBUG_DLIM,
25491 +       CTL_DEBUG_QUOTA,
25492 +       CTL_DEBUG_CVIRT,
25493 +       CTL_DEBUG_SPACE,
25494 +       CTL_DEBUG_MISC,
25495 +};
25496 +
25497 +
25498 +unsigned int vx_debug_switch   = 0;
25499 +unsigned int vx_debug_xid      = 0;
25500 +unsigned int vx_debug_nid      = 0;
25501 +unsigned int vx_debug_tag      = 0;
25502 +unsigned int vx_debug_net      = 0;
25503 +unsigned int vx_debug_limit    = 0;
25504 +unsigned int vx_debug_cres     = 0;
25505 +unsigned int vx_debug_dlim     = 0;
25506 +unsigned int vx_debug_quota    = 0;
25507 +unsigned int vx_debug_cvirt    = 0;
25508 +unsigned int vx_debug_space    = 0;
25509 +unsigned int vx_debug_misc     = 0;
25510 +
25511 +
25512 +static struct ctl_table_header *vserver_table_header;
25513 +static ctl_table vserver_root_table[];
25514 +
25515 +
25516 +void vserver_register_sysctl(void)
25517 +{
25518 +       if (!vserver_table_header) {
25519 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25520 +       }
25521 +
25522 +}
25523 +
25524 +void vserver_unregister_sysctl(void)
25525 +{
25526 +       if (vserver_table_header) {
25527 +               unregister_sysctl_table(vserver_table_header);
25528 +               vserver_table_header = NULL;
25529 +       }
25530 +}
25531 +
25532 +
25533 +static int proc_dodebug(ctl_table *table, int write,
25534 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25535 +{
25536 +       char            tmpbuf[20], *p, c;
25537 +       unsigned int    value;
25538 +       size_t          left, len;
25539 +
25540 +       if ((*ppos && !write) || !*lenp) {
25541 +               *lenp = 0;
25542 +               return 0;
25543 +       }
25544 +
25545 +       left = *lenp;
25546 +
25547 +       if (write) {
25548 +               if (!access_ok(VERIFY_READ, buffer, left))
25549 +                       return -EFAULT;
25550 +               p = (char *)buffer;
25551 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25552 +                       left--, p++;
25553 +               if (!left)
25554 +                       goto done;
25555 +
25556 +               if (left > sizeof(tmpbuf) - 1)
25557 +                       return -EINVAL;
25558 +               if (copy_from_user(tmpbuf, p, left))
25559 +                       return -EFAULT;
25560 +               tmpbuf[left] = '\0';
25561 +
25562 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25563 +                       value = 10 * value + (*p - '0');
25564 +               if (*p && !isspace(*p))
25565 +                       return -EINVAL;
25566 +               while (left && isspace(*p))
25567 +                       left--, p++;
25568 +               *(unsigned int *)table->data = value;
25569 +       } else {
25570 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25571 +                       return -EFAULT;
25572 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25573 +               if (len > left)
25574 +                       len = left;
25575 +               if (__copy_to_user(buffer, tmpbuf, len))
25576 +                       return -EFAULT;
25577 +               if ((left -= len) > 0) {
25578 +                       if (put_user('\n', (char *)buffer + len))
25579 +                               return -EFAULT;
25580 +                       left--;
25581 +               }
25582 +       }
25583 +
25584 +done:
25585 +       *lenp -= left;
25586 +       *ppos += *lenp;
25587 +       return 0;
25588 +}
25589 +
25590 +static int zero;
25591 +
25592 +#define        CTL_ENTRY(ctl, name)                            \
25593 +       {                                               \
25594 +               .ctl_name       = ctl,                  \
25595 +               .procname       = #name,                \
25596 +               .data           = &vx_ ## name,         \
25597 +               .maxlen         = sizeof(int),          \
25598 +               .mode           = 0644,                 \
25599 +               .proc_handler   = &proc_dodebug,        \
25600 +               .strategy       = &sysctl_intvec,       \
25601 +               .extra1         = &zero,                \
25602 +       }
25603 +
25604 +static ctl_table vserver_debug_table[] = {
25605 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25606 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25607 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25608 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25609 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25610 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25611 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25612 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25613 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25614 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25615 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25616 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25617 +       { .ctl_name = 0 }
25618 +};
25619 +
25620 +static ctl_table vserver_root_table[] = {
25621 +       {
25622 +               .ctl_name       = CTL_VSERVER,
25623 +               .procname       = "vserver",
25624 +               .mode           = 0555,
25625 +               .child          = vserver_debug_table
25626 +       },
25627 +       { .ctl_name = 0 }
25628 +};
25629 +
25630 +
25631 +static match_table_t tokens = {
25632 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25633 +       { CTL_DEBUG_XID,        "xid=%x"        },
25634 +       { CTL_DEBUG_NID,        "nid=%x"        },
25635 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25636 +       { CTL_DEBUG_NET,        "net=%x"        },
25637 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25638 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25639 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25640 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25641 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25642 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25643 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25644 +       { CTL_DEBUG_ERROR,      NULL            }
25645 +};
25646 +
25647 +#define        HANDLE_CASE(id, name, val)                              \
25648 +       case CTL_DEBUG_ ## id:                                  \
25649 +               vx_debug_ ## name = val;                        \
25650 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25651 +               break
25652 +
25653 +
25654 +static int __init vs_debug_setup(char *str)
25655 +{
25656 +       char *p;
25657 +       int token;
25658 +
25659 +       printk("vs_debug_setup(%s)\n", str);
25660 +       while ((p = strsep(&str, ",")) != NULL) {
25661 +               substring_t args[MAX_OPT_ARGS];
25662 +               unsigned int value;
25663 +
25664 +               if (!*p)
25665 +                       continue;
25666 +
25667 +               token = match_token(p, tokens, args);
25668 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25669 +
25670 +               switch (token) {
25671 +               HANDLE_CASE(SWITCH, switch, value);
25672 +               HANDLE_CASE(XID,    xid,    value);
25673 +               HANDLE_CASE(NID,    nid,    value);
25674 +               HANDLE_CASE(TAG,    tag,    value);
25675 +               HANDLE_CASE(NET,    net,    value);
25676 +               HANDLE_CASE(LIMIT,  limit,  value);
25677 +               HANDLE_CASE(CRES,   cres,   value);
25678 +               HANDLE_CASE(DLIM,   dlim,   value);
25679 +               HANDLE_CASE(QUOTA,  quota,  value);
25680 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25681 +               HANDLE_CASE(SPACE,  space,  value);
25682 +               HANDLE_CASE(MISC,   misc,   value);
25683 +               default:
25684 +                       return -EINVAL;
25685 +                       break;
25686 +               }
25687 +       }
25688 +       return 1;
25689 +}
25690 +
25691 +__setup("vsdebug=", vs_debug_setup);
25692 +
25693 +
25694 +
25695 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25696 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25697 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25698 +EXPORT_SYMBOL_GPL(vx_debug_net);
25699 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25700 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25701 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25702 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25703 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25704 +EXPORT_SYMBOL_GPL(vx_debug_space);
25705 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25706 +
25707 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/tag.c linux-2.6.27.6-vs2.3.0.36/kernel/vserver/tag.c
25708 --- linux-2.6.27.6/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
25709 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/tag.c      2008-10-13 14:54:20.000000000 +0200
25710 @@ -0,0 +1,63 @@
25711 +/*
25712 + *  linux/kernel/vserver/tag.c
25713 + *
25714 + *  Virtual Server: Shallow Tag Space
25715 + *
25716 + *  Copyright (C) 2007  Herbert Pötzl
25717 + *
25718 + *  V0.01  basic implementation
25719 + *
25720 + */
25721 +
25722 +#include <linux/sched.h>
25723 +#include <linux/vserver/debug.h>
25724 +#include <linux/vs_pid.h>
25725 +#include <linux/vs_tag.h>
25726 +
25727 +#include <linux/vserver/tag_cmd.h>
25728 +
25729 +
25730 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25731 +{
25732 +       if (!p)
25733 +               BUG();
25734 +
25735 +       vxdprintk(VXD_CBIT(tag, 5),
25736 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25737 +
25738 +       task_lock(p);
25739 +       p->tag = tag;
25740 +       task_unlock(p);
25741 +
25742 +       vxdprintk(VXD_CBIT(tag, 5),
25743 +               "moved task %p into [#%d]", p, tag);
25744 +       return 0;
25745 +}
25746 +
25747 +/* vserver syscall commands below here */
25748 +
25749 +/* taks xid and vx_info functions */
25750 +
25751 +
25752 +int vc_task_tag(uint32_t id)
25753 +{
25754 +       tag_t tag;
25755 +
25756 +       if (id) {
25757 +               struct task_struct *tsk;
25758 +               read_lock(&tasklist_lock);
25759 +               tsk = find_task_by_real_pid(id);
25760 +               tag = (tsk) ? tsk->tag : -ESRCH;
25761 +               read_unlock(&tasklist_lock);
25762 +       } else
25763 +               tag = dx_current_tag();
25764 +       return tag;
25765 +}
25766 +
25767 +
25768 +int vc_tag_migrate(uint32_t tag)
25769 +{
25770 +       return dx_migrate_task(current, tag & 0xFFFF);
25771 +}
25772 +
25773 +
25774 diff -NurpP --minimal linux-2.6.27.6/kernel/vserver/vci_config.h linux-2.6.27.6-vs2.3.0.36/kernel/vserver/vci_config.h
25775 --- linux-2.6.27.6/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
25776 +++ linux-2.6.27.6-vs2.3.0.36/kernel/vserver/vci_config.h       2008-10-31 18:16:04.000000000 +0100
25777 @@ -0,0 +1,81 @@
25778 +
25779 +/*  interface version */
25780 +
25781 +#define VCI_VERSION            0x00020304
25782 +
25783 +
25784 +enum {
25785 +       VCI_KCBIT_NO_DYNAMIC = 0,
25786 +
25787 +       VCI_KCBIT_PROC_SECURE = 4,
25788 +       VCI_KCBIT_HARDCPU = 5,
25789 +       VCI_KCBIT_IDLELIMIT = 6,
25790 +       VCI_KCBIT_IDLETIME = 7,
25791 +
25792 +       VCI_KCBIT_COWBL = 8,
25793 +       VCI_KCBIT_FULLCOWBL = 9,
25794 +       VCI_KCBIT_SPACES = 10,
25795 +       VCI_KCBIT_NETV2 = 11,
25796 +
25797 +       VCI_KCBIT_DEBUG = 16,
25798 +       VCI_KCBIT_HISTORY = 20,
25799 +       VCI_KCBIT_TAGGED = 24,
25800 +       VCI_KCBIT_PPTAG = 28,
25801 +
25802 +       VCI_KCBIT_MORE = 31,
25803 +};
25804 +
25805 +
25806 +static inline uint32_t vci_kernel_config(void)
25807 +{
25808 +       return
25809 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25810 +
25811 +       /* configured features */
25812 +#ifdef CONFIG_VSERVER_PROC_SECURE
25813 +       (1 << VCI_KCBIT_PROC_SECURE) |
25814 +#endif
25815 +#ifdef CONFIG_VSERVER_HARDCPU
25816 +       (1 << VCI_KCBIT_HARDCPU) |
25817 +#endif
25818 +#ifdef CONFIG_VSERVER_IDLELIMIT
25819 +       (1 << VCI_KCBIT_IDLELIMIT) |
25820 +#endif
25821 +#ifdef CONFIG_VSERVER_IDLETIME
25822 +       (1 << VCI_KCBIT_IDLETIME) |
25823 +#endif
25824 +#ifdef CONFIG_VSERVER_COWBL
25825 +       (1 << VCI_KCBIT_COWBL) |
25826 +       (1 << VCI_KCBIT_FULLCOWBL) |
25827 +#endif
25828 +       (1 << VCI_KCBIT_SPACES) |
25829 +       (1 << VCI_KCBIT_NETV2) |
25830 +
25831 +       /* debug options */
25832 +#ifdef CONFIG_VSERVER_DEBUG
25833 +       (1 << VCI_KCBIT_DEBUG) |
25834 +#endif
25835 +#ifdef CONFIG_VSERVER_HISTORY
25836 +       (1 << VCI_KCBIT_HISTORY) |
25837 +#endif
25838 +
25839 +       /* inode context tagging */
25840 +#if    defined(CONFIG_TAGGING_NONE)
25841 +       (0 << VCI_KCBIT_TAGGED) |
25842 +#elif  defined(CONFIG_TAGGING_UID16)
25843 +       (1 << VCI_KCBIT_TAGGED) |
25844 +#elif  defined(CONFIG_TAGGING_GID16)
25845 +       (2 << VCI_KCBIT_TAGGED) |
25846 +#elif  defined(CONFIG_TAGGING_ID24)
25847 +       (3 << VCI_KCBIT_TAGGED) |
25848 +#elif  defined(CONFIG_TAGGING_INTERN)
25849 +       (4 << VCI_KCBIT_TAGGED) |
25850 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25851 +       (5 << VCI_KCBIT_TAGGED) |
25852 +#else
25853 +       (7 << VCI_KCBIT_TAGGED) |
25854 +#endif
25855 +       (1 << VCI_KCBIT_PPTAG) |
25856 +       0;
25857 +}
25858 +
25859 diff -NurpP --minimal linux-2.6.27.6/mm/filemap_xip.c linux-2.6.27.6-vs2.3.0.36/mm/filemap_xip.c
25860 --- linux-2.6.27.6/mm/filemap_xip.c     2008-10-13 14:52:09.000000000 +0200
25861 +++ linux-2.6.27.6-vs2.3.0.36/mm/filemap_xip.c  2008-10-13 14:54:20.000000000 +0200
25862 @@ -17,6 +17,7 @@
25863  #include <linux/sched.h>
25864  #include <linux/seqlock.h>
25865  #include <linux/mutex.h>
25866 +#include <linux/vs_memory.h>
25867  #include <asm/tlbflush.h>
25868  #include <asm/io.h>
25869  
25870 diff -NurpP --minimal linux-2.6.27.6/mm/fremap.c linux-2.6.27.6-vs2.3.0.36/mm/fremap.c
25871 --- linux-2.6.27.6/mm/fremap.c  2008-10-13 14:52:09.000000000 +0200
25872 +++ linux-2.6.27.6-vs2.3.0.36/mm/fremap.c       2008-10-13 14:54:20.000000000 +0200
25873 @@ -16,6 +16,7 @@
25874  #include <linux/module.h>
25875  #include <linux/syscalls.h>
25876  #include <linux/mmu_notifier.h>
25877 +#include <linux/vs_memory.h>
25878  
25879  #include <asm/mmu_context.h>
25880  #include <asm/cacheflush.h>
25881 diff -NurpP --minimal linux-2.6.27.6/mm/hugetlb.c linux-2.6.27.6-vs2.3.0.36/mm/hugetlb.c
25882 --- linux-2.6.27.6/mm/hugetlb.c 2008-11-17 18:07:34.000000000 +0100
25883 +++ linux-2.6.27.6-vs2.3.0.36/mm/hugetlb.c      2008-11-17 18:20:41.000000000 +0100
25884 @@ -23,6 +23,7 @@
25885  #include <asm/io.h>
25886  
25887  #include <linux/hugetlb.h>
25888 +#include <linux/vs_memory.h>
25889  #include "internal.h"
25890  
25891  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25892 diff -NurpP --minimal linux-2.6.27.6/mm/memory.c linux-2.6.27.6-vs2.3.0.36/mm/memory.c
25893 --- linux-2.6.27.6/mm/memory.c  2008-10-13 14:52:09.000000000 +0200
25894 +++ linux-2.6.27.6-vs2.3.0.36/mm/memory.c       2008-10-13 14:54:20.000000000 +0200
25895 @@ -562,6 +562,9 @@ static int copy_pte_range(struct mm_stru
25896         int progress = 0;
25897         int rss[2];
25898  
25899 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25900 +               return -ENOMEM;
25901 +
25902  again:
25903         rss[1] = rss[0] = 0;
25904         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25905 @@ -2294,6 +2297,11 @@ static int do_swap_page(struct mm_struct
25906                 goto out;
25907         }
25908  
25909 +       if (!vx_rss_avail(mm, 1)) {
25910 +               ret = VM_FAULT_OOM;
25911 +               goto out;
25912 +       }
25913 +
25914         mark_page_accessed(page);
25915         lock_page(page);
25916         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
25917 @@ -2365,6 +2373,8 @@ static int do_anonymous_page(struct mm_s
25918         /* Allocate our own private page. */
25919         pte_unmap(page_table);
25920  
25921 +       if (!vx_rss_avail(mm, 1))
25922 +               goto oom;
25923         if (unlikely(anon_vma_prepare(vma)))
25924                 goto oom;
25925         page = alloc_zeroed_user_highpage_movable(vma, address);
25926 @@ -2626,6 +2636,7 @@ static inline int handle_pte_fault(struc
25927  {
25928         pte_t entry;
25929         spinlock_t *ptl;
25930 +       int ret = 0, type = VXPT_UNKNOWN;
25931  
25932         entry = *pte;
25933         if (!pte_present(entry)) {
25934 @@ -2650,9 +2661,12 @@ static inline int handle_pte_fault(struc
25935         if (unlikely(!pte_same(*pte, entry)))
25936                 goto unlock;
25937         if (write_access) {
25938 -               if (!pte_write(entry))
25939 -                       return do_wp_page(mm, vma, address,
25940 +               if (!pte_write(entry)) {
25941 +                       ret = do_wp_page(mm, vma, address,
25942                                         pte, pmd, ptl, entry);
25943 +                       type = VXPT_WRITE;
25944 +                       goto out;
25945 +               }
25946                 entry = pte_mkdirty(entry);
25947         }
25948         entry = pte_mkyoung(entry);
25949 @@ -2670,7 +2684,10 @@ static inline int handle_pte_fault(struc
25950         }
25951  unlock:
25952         pte_unmap_unlock(pte, ptl);
25953 -       return 0;
25954 +       ret = 0;
25955 +out:
25956 +       vx_page_fault(mm, vma, type, ret);
25957 +       return ret;
25958  }
25959  
25960  /*
25961 diff -NurpP --minimal linux-2.6.27.6/mm/mlock.c linux-2.6.27.6-vs2.3.0.36/mm/mlock.c
25962 --- linux-2.6.27.6/mm/mlock.c   2008-10-13 14:52:09.000000000 +0200
25963 +++ linux-2.6.27.6-vs2.3.0.36/mm/mlock.c        2008-10-13 14:54:20.000000000 +0200
25964 @@ -12,6 +12,7 @@
25965  #include <linux/syscalls.h>
25966  #include <linux/sched.h>
25967  #include <linux/module.h>
25968 +#include <linux/vs_memory.h>
25969  
25970  int can_do_mlock(void)
25971  {
25972 @@ -76,7 +77,7 @@ success:
25973                         ret = make_pages_present(start, end);
25974         }
25975  
25976 -       mm->locked_vm -= pages;
25977 +       vx_vmlocked_sub(mm, pages);
25978  out:
25979         return ret;
25980  }
25981 @@ -132,7 +133,7 @@ static int do_mlock(unsigned long start,
25982  
25983  asmlinkage long sys_mlock(unsigned long start, size_t len)
25984  {
25985 -       unsigned long locked;
25986 +       unsigned long locked, grow;
25987         unsigned long lock_limit;
25988         int error = -ENOMEM;
25989  
25990 @@ -143,8 +144,10 @@ asmlinkage long sys_mlock(unsigned long 
25991         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25992         start &= PAGE_MASK;
25993  
25994 -       locked = len >> PAGE_SHIFT;
25995 -       locked += current->mm->locked_vm;
25996 +       grow = len >> PAGE_SHIFT;
25997 +       if (!vx_vmlocked_avail(current->mm, grow))
25998 +               goto out;
25999 +       locked = current->mm->locked_vm + grow;
26000  
26001         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26002         lock_limit >>= PAGE_SHIFT;
26003 @@ -152,6 +155,7 @@ asmlinkage long sys_mlock(unsigned long 
26004         /* check against resource limits */
26005         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26006                 error = do_mlock(start, len, 1);
26007 +out:
26008         up_write(&current->mm->mmap_sem);
26009         return error;
26010  }
26011 @@ -211,6 +215,8 @@ asmlinkage long sys_mlockall(int flags)
26012         lock_limit >>= PAGE_SHIFT;
26013  
26014         ret = -ENOMEM;
26015 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26016 +               goto out;
26017         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26018             capable(CAP_IPC_LOCK))
26019                 ret = do_mlockall(flags);
26020 diff -NurpP --minimal linux-2.6.27.6/mm/mmap.c linux-2.6.27.6-vs2.3.0.36/mm/mmap.c
26021 --- linux-2.6.27.6/mm/mmap.c    2008-10-13 14:52:09.000000000 +0200
26022 +++ linux-2.6.27.6-vs2.3.0.36/mm/mmap.c 2008-10-13 14:54:20.000000000 +0200
26023 @@ -1221,10 +1221,10 @@ munmap_back:
26024         if (correct_wcount)
26025                 atomic_inc(&inode->i_writecount);
26026  out:
26027 -       mm->total_vm += len >> PAGE_SHIFT;
26028 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26029         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26030         if (vm_flags & VM_LOCKED) {
26031 -               mm->locked_vm += len >> PAGE_SHIFT;
26032 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26033                 make_pages_present(addr, addr + len);
26034         }
26035         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26036 @@ -1573,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
26037                 return -ENOMEM;
26038  
26039         /* Ok, everything looks good - let it rip */
26040 -       mm->total_vm += grow;
26041 +       vx_vmpages_add(mm, grow);
26042         if (vma->vm_flags & VM_LOCKED)
26043 -               mm->locked_vm += grow;
26044 +               vx_vmlocked_add(mm, grow);
26045         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26046         return 0;
26047  }
26048 @@ -1746,9 +1746,9 @@ static void remove_vma_list(struct mm_st
26049         do {
26050                 long nrpages = vma_pages(vma);
26051  
26052 -               mm->total_vm -= nrpages;
26053 +               vx_vmpages_sub(mm, nrpages);
26054                 if (vma->vm_flags & VM_LOCKED)
26055 -                       mm->locked_vm -= nrpages;
26056 +                       vx_vmlocked_sub(mm, nrpages);
26057                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26058                 vma = remove_vma(vma);
26059         } while (vma);
26060 @@ -1995,6 +1995,8 @@ unsigned long do_brk(unsigned long addr,
26061                 lock_limit >>= PAGE_SHIFT;
26062                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26063                         return -EAGAIN;
26064 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26065 +                       return -ENOMEM;
26066         }
26067  
26068         /*
26069 @@ -2021,7 +2023,8 @@ unsigned long do_brk(unsigned long addr,
26070         if (mm->map_count > sysctl_max_map_count)
26071                 return -ENOMEM;
26072  
26073 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26074 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26075 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26076                 return -ENOMEM;
26077  
26078         /* Can we just expand an old private anonymous mapping? */
26079 @@ -2046,9 +2049,9 @@ unsigned long do_brk(unsigned long addr,
26080         vma->vm_page_prot = vm_get_page_prot(flags);
26081         vma_link(mm, vma, prev, rb_link, rb_parent);
26082  out:
26083 -       mm->total_vm += len >> PAGE_SHIFT;
26084 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26085         if (flags & VM_LOCKED) {
26086 -               mm->locked_vm += len >> PAGE_SHIFT;
26087 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26088                 make_pages_present(addr, addr + len);
26089         }
26090         return addr;
26091 @@ -2078,6 +2081,11 @@ void exit_mmap(struct mm_struct *mm)
26092         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26093         tlb_finish_mmu(tlb, 0, end);
26094  
26095 +       set_mm_counter(mm, file_rss, 0);
26096 +       set_mm_counter(mm, anon_rss, 0);
26097 +       vx_vmpages_sub(mm, mm->total_vm);
26098 +       vx_vmlocked_sub(mm, mm->locked_vm);
26099 +
26100         /*
26101          * Walk the list again, actually closing and freeing it,
26102          * with preemption enabled, without holding any MM locks.
26103 @@ -2117,7 +2125,8 @@ int insert_vm_struct(struct mm_struct * 
26104         if (__vma && __vma->vm_start < vma->vm_end)
26105                 return -ENOMEM;
26106         if ((vma->vm_flags & VM_ACCOUNT) &&
26107 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26108 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26109 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26110                 return -ENOMEM;
26111         vma_link(mm, vma, prev, rb_link, rb_parent);
26112         return 0;
26113 @@ -2193,6 +2202,8 @@ int may_expand_vm(struct mm_struct *mm, 
26114  
26115         if (cur + npages > lim)
26116                 return 0;
26117 +       if (!vx_vmpages_avail(mm, npages))
26118 +               return 0;
26119         return 1;
26120  }
26121  
26122 @@ -2270,8 +2281,7 @@ int install_special_mapping(struct mm_st
26123                 return -ENOMEM;
26124         }
26125  
26126 -       mm->total_vm += len >> PAGE_SHIFT;
26127 -
26128 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26129         return 0;
26130  }
26131  
26132 diff -NurpP --minimal linux-2.6.27.6/mm/mremap.c linux-2.6.27.6-vs2.3.0.36/mm/mremap.c
26133 --- linux-2.6.27.6/mm/mremap.c  2008-10-13 14:52:09.000000000 +0200
26134 +++ linux-2.6.27.6-vs2.3.0.36/mm/mremap.c       2008-10-13 14:54:20.000000000 +0200
26135 @@ -19,6 +19,7 @@
26136  #include <linux/security.h>
26137  #include <linux/syscalls.h>
26138  #include <linux/mmu_notifier.h>
26139 +#include <linux/vs_memory.h>
26140  
26141  #include <asm/uaccess.h>
26142  #include <asm/cacheflush.h>
26143 @@ -218,7 +219,7 @@ static unsigned long move_vma(struct vm_
26144          * If this were a serious issue, we'd add a flag to do_munmap().
26145          */
26146         hiwater_vm = mm->hiwater_vm;
26147 -       mm->total_vm += new_len >> PAGE_SHIFT;
26148 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26149         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26150  
26151         if (do_munmap(mm, old_addr, old_len) < 0) {
26152 @@ -236,7 +237,7 @@ static unsigned long move_vma(struct vm_
26153         }
26154  
26155         if (vm_flags & VM_LOCKED) {
26156 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26157 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26158                 if (new_len > old_len)
26159                         make_pages_present(new_addr + old_len,
26160                                            new_addr + new_len);
26161 @@ -347,6 +348,9 @@ unsigned long do_mremap(unsigned long ad
26162                 ret = -EAGAIN;
26163                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26164                         goto out;
26165 +               if (!vx_vmlocked_avail(current->mm,
26166 +                       (new_len - old_len) >> PAGE_SHIFT))
26167 +                       goto out;
26168         }
26169         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26170                 ret = -ENOMEM;
26171 @@ -375,10 +379,10 @@ unsigned long do_mremap(unsigned long ad
26172                         vma_adjust(vma, vma->vm_start,
26173                                 addr + new_len, vma->vm_pgoff, NULL);
26174  
26175 -                       mm->total_vm += pages;
26176 +                       vx_vmpages_add(mm, pages);
26177                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26178                         if (vma->vm_flags & VM_LOCKED) {
26179 -                               mm->locked_vm += pages;
26180 +                               vx_vmlocked_add(mm, pages);
26181                                 make_pages_present(addr + old_len,
26182                                                    addr + new_len);
26183                         }
26184 diff -NurpP --minimal linux-2.6.27.6/mm/nommu.c linux-2.6.27.6-vs2.3.0.36/mm/nommu.c
26185 --- linux-2.6.27.6/mm/nommu.c   2008-10-13 14:52:09.000000000 +0200
26186 +++ linux-2.6.27.6-vs2.3.0.36/mm/nommu.c        2008-10-13 14:54:20.000000000 +0200
26187 @@ -1028,7 +1028,7 @@ unsigned long do_mmap_pgoff(struct file 
26188         realalloc += kobjsize(vma);
26189         askedalloc += sizeof(*vma);
26190  
26191 -       current->mm->total_vm += len >> PAGE_SHIFT;
26192 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26193  
26194         add_nommu_vma(vma);
26195  
26196 @@ -1160,7 +1160,7 @@ int do_munmap(struct mm_struct *mm, unsi
26197         kfree(vml);
26198  
26199         update_hiwater_vm(mm);
26200 -       mm->total_vm -= len >> PAGE_SHIFT;
26201 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
26202  
26203  #ifdef DEBUG
26204         show_process_blocks();
26205 @@ -1193,7 +1193,7 @@ void exit_mmap(struct mm_struct * mm)
26206                 printk("Exit_mmap:\n");
26207  #endif
26208  
26209 -               mm->total_vm = 0;
26210 +               vx_vmpages_sub(mm, mm->total_vm);
26211  
26212                 while ((tmp = mm->context.vmlist)) {
26213                         mm->context.vmlist = tmp->next;
26214 diff -NurpP --minimal linux-2.6.27.6/mm/oom_kill.c linux-2.6.27.6-vs2.3.0.36/mm/oom_kill.c
26215 --- linux-2.6.27.6/mm/oom_kill.c        2008-10-13 14:52:09.000000000 +0200
26216 +++ linux-2.6.27.6-vs2.3.0.36/mm/oom_kill.c     2008-10-13 14:54:20.000000000 +0200
26217 @@ -27,6 +27,7 @@
26218  #include <linux/notifier.h>
26219  #include <linux/memcontrol.h>
26220  #include <linux/security.h>
26221 +#include <linux/vs_memory.h>
26222  
26223  int sysctl_panic_on_oom;
26224  int sysctl_oom_kill_allocating_task;
26225 @@ -73,6 +74,12 @@ unsigned long badness(struct task_struct
26226         points = mm->total_vm;
26227  
26228         /*
26229 +        * add points for context badness
26230 +        */
26231 +
26232 +       points += vx_badness(p, mm);
26233 +
26234 +       /*
26235          * After this unlock we can no longer dereference local variable `mm'
26236          */
26237         task_unlock(p);
26238 @@ -163,8 +170,8 @@ unsigned long badness(struct task_struct
26239         }
26240  
26241  #ifdef DEBUG
26242 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26243 -       p->pid, p->comm, points);
26244 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26245 +               task_pid_nr(p), p->xid, p->comm, points);
26246  #endif
26247         return points;
26248  }
26249 @@ -325,8 +332,8 @@ static void __oom_kill_task(struct task_
26250         }
26251  
26252         if (verbose)
26253 -               printk(KERN_ERR "Killed process %d (%s)\n",
26254 -                               task_pid_nr(p), p->comm);
26255 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26256 +                               task_pid_nr(p), p->xid, p->comm);
26257  
26258         /*
26259          * We give our sacrificial lamb high priority and access to
26260 @@ -406,8 +413,8 @@ static int oom_kill_process(struct task_
26261                 return 0;
26262         }
26263  
26264 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26265 -                                       message, task_pid_nr(p), p->comm, points);
26266 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26267 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26268  
26269         /* Try to kill a child first */
26270         list_for_each_entry(c, &p->children, sibling) {
26271 diff -NurpP --minimal linux-2.6.27.6/mm/page_alloc.c linux-2.6.27.6-vs2.3.0.36/mm/page_alloc.c
26272 --- linux-2.6.27.6/mm/page_alloc.c      2008-11-17 18:07:34.000000000 +0100
26273 +++ linux-2.6.27.6-vs2.3.0.36/mm/page_alloc.c   2008-11-17 18:20:41.000000000 +0100
26274 @@ -46,6 +46,8 @@
26275  #include <linux/page-isolation.h>
26276  #include <linux/memcontrol.h>
26277  #include <linux/debugobjects.h>
26278 +#include <linux/vs_base.h>
26279 +#include <linux/vs_limit.h>
26280  
26281  #include <asm/tlbflush.h>
26282  #include <asm/div64.h>
26283 @@ -1823,6 +1825,9 @@ void si_meminfo(struct sysinfo *val)
26284         val->totalhigh = totalhigh_pages;
26285         val->freehigh = nr_free_highpages();
26286         val->mem_unit = PAGE_SIZE;
26287 +
26288 +       if (vx_flags(VXF_VIRT_MEM, 0))
26289 +               vx_vsi_meminfo(val);
26290  }
26291  
26292  EXPORT_SYMBOL(si_meminfo);
26293 @@ -1843,6 +1848,9 @@ void si_meminfo_node(struct sysinfo *val
26294         val->freehigh = 0;
26295  #endif
26296         val->mem_unit = PAGE_SIZE;
26297 +
26298 +       if (vx_flags(VXF_VIRT_MEM, 0))
26299 +               vx_vsi_meminfo(val);
26300  }
26301  #endif
26302  
26303 diff -NurpP --minimal linux-2.6.27.6/mm/rmap.c linux-2.6.27.6-vs2.3.0.36/mm/rmap.c
26304 --- linux-2.6.27.6/mm/rmap.c    2008-11-17 18:07:34.000000000 +0100
26305 +++ linux-2.6.27.6-vs2.3.0.36/mm/rmap.c 2008-10-30 01:17:01.000000000 +0100
26306 @@ -50,6 +50,7 @@
26307  #include <linux/kallsyms.h>
26308  #include <linux/memcontrol.h>
26309  #include <linux/mmu_notifier.h>
26310 +#include <linux/vs_memory.h>
26311  
26312  #include <asm/tlbflush.h>
26313  
26314 diff -NurpP --minimal linux-2.6.27.6/mm/shmem.c linux-2.6.27.6-vs2.3.0.36/mm/shmem.c
26315 --- linux-2.6.27.6/mm/shmem.c   2008-10-13 14:52:09.000000000 +0200
26316 +++ linux-2.6.27.6-vs2.3.0.36/mm/shmem.c        2008-10-13 14:54:20.000000000 +0200
26317 @@ -56,7 +56,6 @@
26318  #include <asm/pgtable.h>
26319  
26320  /* This magic number is used in glibc for posix shared memory */
26321 -#define TMPFS_MAGIC    0x01021994
26322  
26323  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
26324  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
26325 @@ -1738,7 +1737,7 @@ static int shmem_statfs(struct dentry *d
26326  {
26327         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26328  
26329 -       buf->f_type = TMPFS_MAGIC;
26330 +       buf->f_type = TMPFS_SUPER_MAGIC;
26331         buf->f_bsize = PAGE_CACHE_SIZE;
26332         buf->f_namelen = NAME_MAX;
26333         spin_lock(&sbinfo->stat_lock);
26334 @@ -2306,7 +2305,7 @@ static int shmem_fill_super(struct super
26335         sb->s_maxbytes = SHMEM_MAX_BYTES;
26336         sb->s_blocksize = PAGE_CACHE_SIZE;
26337         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26338 -       sb->s_magic = TMPFS_MAGIC;
26339 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26340         sb->s_op = &shmem_ops;
26341         sb->s_time_gran = 1;
26342  #ifdef CONFIG_TMPFS_POSIX_ACL
26343 diff -NurpP --minimal linux-2.6.27.6/mm/slab.c linux-2.6.27.6-vs2.3.0.36/mm/slab.c
26344 --- linux-2.6.27.6/mm/slab.c    2008-10-13 14:52:09.000000000 +0200
26345 +++ linux-2.6.27.6-vs2.3.0.36/mm/slab.c 2008-10-13 14:54:20.000000000 +0200
26346 @@ -508,6 +508,8 @@ struct kmem_cache {
26347  #define STATS_INC_FREEMISS(x)  do { } while (0)
26348  #endif
26349  
26350 +#include "slab_vs.h"
26351 +
26352  #if DEBUG
26353  
26354  /*
26355 @@ -3337,6 +3339,7 @@ retry:
26356  
26357         obj = slab_get_obj(cachep, slabp, nodeid);
26358         check_slabp(cachep, slabp);
26359 +       vx_slab_alloc(cachep, flags);
26360         l3->free_objects--;
26361         /* move slabp to correct slabp list: */
26362         list_del(&slabp->list);
26363 @@ -3409,6 +3412,7 @@ __cache_alloc_node(struct kmem_cache *ca
26364         /* ___cache_alloc_node can fall back to other nodes */
26365         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26366    out:
26367 +       vx_slab_alloc(cachep, flags);
26368         local_irq_restore(save_flags);
26369         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26370  
26371 @@ -3580,6 +3584,7 @@ static inline void __cache_free(struct k
26372  
26373         check_irq_off();
26374         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26375 +       vx_slab_free(cachep);
26376  
26377         /*
26378          * Skip calling cache_free_alien() when the platform is not numa.
26379 diff -NurpP --minimal linux-2.6.27.6/mm/slab_vs.h linux-2.6.27.6-vs2.3.0.36/mm/slab_vs.h
26380 --- linux-2.6.27.6/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
26381 +++ linux-2.6.27.6-vs2.3.0.36/mm/slab_vs.h      2008-10-13 14:54:20.000000000 +0200
26382 @@ -0,0 +1,27 @@
26383 +
26384 +#include <linux/vserver/context.h>
26385 +
26386 +#include <linux/vs_context.h>
26387 +
26388 +static inline
26389 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26390 +{
26391 +       int what = gfp_zone(cachep->gfpflags);
26392 +
26393 +       if (!current->vx_info)
26394 +               return;
26395 +
26396 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26397 +}
26398 +
26399 +static inline
26400 +void vx_slab_free(struct kmem_cache *cachep)
26401 +{
26402 +       int what = gfp_zone(cachep->gfpflags);
26403 +
26404 +       if (!current->vx_info)
26405 +               return;
26406 +
26407 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26408 +}
26409 +
26410 diff -NurpP --minimal linux-2.6.27.6/mm/swapfile.c linux-2.6.27.6-vs2.3.0.36/mm/swapfile.c
26411 --- linux-2.6.27.6/mm/swapfile.c        2008-10-13 14:52:09.000000000 +0200
26412 +++ linux-2.6.27.6-vs2.3.0.36/mm/swapfile.c     2008-10-13 14:54:20.000000000 +0200
26413 @@ -32,6 +32,8 @@
26414  #include <asm/pgtable.h>
26415  #include <asm/tlbflush.h>
26416  #include <linux/swapops.h>
26417 +#include <linux/vs_base.h>
26418 +#include <linux/vs_memory.h>
26419  
26420  static DEFINE_SPINLOCK(swap_lock);
26421  static unsigned int nr_swapfiles;
26422 @@ -1748,6 +1750,8 @@ void si_swapinfo(struct sysinfo *val)
26423         val->freeswap = nr_swap_pages + nr_to_be_unused;
26424         val->totalswap = total_swap_pages + nr_to_be_unused;
26425         spin_unlock(&swap_lock);
26426 +       if (vx_flags(VXF_VIRT_MEM, 0))
26427 +               vx_vsi_swapinfo(val);
26428  }
26429  
26430  /*
26431 diff -NurpP --minimal linux-2.6.27.6/net/core/dev.c linux-2.6.27.6-vs2.3.0.36/net/core/dev.c
26432 --- linux-2.6.27.6/net/core/dev.c       2008-10-13 14:52:09.000000000 +0200
26433 +++ linux-2.6.27.6-vs2.3.0.36/net/core/dev.c    2008-11-20 15:25:30.000000000 +0100
26434 @@ -127,6 +127,7 @@
26435  #include <linux/in.h>
26436  #include <linux/jhash.h>
26437  #include <linux/random.h>
26438 +#include <linux/vs_inet.h>
26439  
26440  #include "net-sysfs.h"
26441  
26442 @@ -925,10 +926,15 @@ int dev_change_name(struct net_device *d
26443                 strlcpy(dev->name, newname, IFNAMSIZ);
26444  
26445  rollback:
26446 -       err = device_rename(&dev->dev, dev->name);
26447 -       if (err) {
26448 -               memcpy(dev->name, oldname, IFNAMSIZ);
26449 -               return err;
26450 +       /* For now only devices in the initial network namespace
26451 +        * are in sysfs.
26452 +        */
26453 +       if (net == &init_net) {
26454 +               ret = device_rename(&dev->dev, dev->name);
26455 +               if (ret) {
26456 +                       memcpy(dev->name, oldname, IFNAMSIZ);
26457 +                       return ret;
26458 +               }
26459         }
26460  
26461         write_lock_bh(&dev_base_lock);
26462 @@ -2515,6 +2521,8 @@ static int dev_ifconf(struct net *net, c
26463  
26464         total = 0;
26465         for_each_netdev(net, dev) {
26466 +               if (!nx_dev_visible(current->nx_info, dev))
26467 +                       continue;
26468                 for (i = 0; i < NPROTO; i++) {
26469                         if (gifconf_list[i]) {
26470                                 int done;
26471 @@ -2583,6 +2591,9 @@ static void dev_seq_printf_stats(struct 
26472  {
26473         struct net_device_stats *stats = dev->get_stats(dev);
26474  
26475 +       if (!nx_dev_visible(current->nx_info, dev))
26476 +               return;
26477 +
26478         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26479                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26480                    dev->name, stats->rx_bytes, stats->rx_packets,
26481 @@ -4385,6 +4396,15 @@ int dev_change_net_namespace(struct net_
26482         if (dev->features & NETIF_F_NETNS_LOCAL)
26483                 goto out;
26484  
26485 +#ifdef CONFIG_SYSFS
26486 +       /* Don't allow real devices to be moved when sysfs
26487 +        * is enabled.
26488 +        */
26489 +       err = -EINVAL;
26490 +       if (dev->dev.parent)
26491 +               goto out;
26492 +#endif
26493 +
26494         /* Ensure the device has been registrered */
26495         err = -EINVAL;
26496         if (dev->reg_state != NETREG_REGISTERED)
26497 @@ -4442,6 +4462,8 @@ int dev_change_net_namespace(struct net_
26498          */
26499         dev_addr_discard(dev);
26500  
26501 +       netdev_unregister_kobject(dev);
26502 +
26503         /* Actually switch the network namespace */
26504         dev_net_set(dev, net);
26505  
26506 @@ -4458,7 +4480,6 @@ int dev_change_net_namespace(struct net_
26507         }
26508  
26509         /* Fixup kobjects */
26510 -       netdev_unregister_kobject(dev);
26511         err = netdev_register_kobject(dev);
26512         WARN_ON(err);
26513  
26514 diff -NurpP --minimal linux-2.6.27.6/net/core/net-sysfs.c linux-2.6.27.6-vs2.3.0.36/net/core/net-sysfs.c
26515 --- linux-2.6.27.6/net/core/net-sysfs.c 2008-10-13 14:52:09.000000000 +0200
26516 +++ linux-2.6.27.6-vs2.3.0.36/net/core/net-sysfs.c      2008-11-20 15:21:32.000000000 +0100
26517 @@ -440,6 +440,10 @@ void netdev_unregister_kobject(struct ne
26518         struct device *dev = &(net->dev);
26519  
26520         kobject_get(&dev->kobj);
26521 +
26522 +       if (dev_net(net) != &init_net)
26523 +               return;
26524 +
26525         device_del(dev);
26526  }
26527  
26528 @@ -465,6 +469,9 @@ int netdev_register_kobject(struct net_d
26529  #endif
26530  #endif /* CONFIG_SYSFS */
26531  
26532 +       if (dev_net(net) != &init_net)
26533 +               return 0;
26534 +
26535         return device_add(dev);
26536  }
26537  
26538 diff -NurpP --minimal linux-2.6.27.6/net/core/rtnetlink.c linux-2.6.27.6-vs2.3.0.36/net/core/rtnetlink.c
26539 --- linux-2.6.27.6/net/core/rtnetlink.c 2008-10-13 14:52:09.000000000 +0200
26540 +++ linux-2.6.27.6-vs2.3.0.36/net/core/rtnetlink.c      2008-10-13 14:54:20.000000000 +0200
26541 @@ -686,6 +686,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26542  
26543         idx = 0;
26544         for_each_netdev(net, dev) {
26545 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26546 +                       continue;
26547                 if (idx < s_idx)
26548                         goto cont;
26549                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26550 @@ -1219,6 +1221,9 @@ void rtmsg_ifinfo(int type, struct net_d
26551         struct sk_buff *skb;
26552         int err = -ENOBUFS;
26553  
26554 +       if (!nx_dev_visible(current->nx_info, dev))
26555 +               return;
26556 +
26557         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26558         if (skb == NULL)
26559                 goto errout;
26560 diff -NurpP --minimal linux-2.6.27.6/net/core/sock.c linux-2.6.27.6-vs2.3.0.36/net/core/sock.c
26561 --- linux-2.6.27.6/net/core/sock.c      2008-10-13 14:52:09.000000000 +0200
26562 +++ linux-2.6.27.6-vs2.3.0.36/net/core/sock.c   2008-10-13 14:54:20.000000000 +0200
26563 @@ -124,6 +124,10 @@
26564  #include <linux/ipsec.h>
26565  
26566  #include <linux/filter.h>
26567 +#include <linux/vs_socket.h>
26568 +#include <linux/vs_limit.h>
26569 +#include <linux/vs_context.h>
26570 +#include <linux/vs_network.h>
26571  
26572  #ifdef CONFIG_INET
26573  #include <net/tcp.h>
26574 @@ -897,6 +901,8 @@ static struct sock *sk_prot_alloc(struct
26575                 if (!try_module_get(prot->owner))
26576                         goto out_free_sec;
26577         }
26578 +               sock_vx_init(sk);
26579 +               sock_nx_init(sk);
26580  
26581         return sk;
26582  
26583 @@ -973,6 +979,11 @@ void sk_free(struct sock *sk)
26584                        __func__, atomic_read(&sk->sk_omem_alloc));
26585  
26586         put_net(sock_net(sk));
26587 +       vx_sock_dec(sk);
26588 +       clr_vx_info(&sk->sk_vx_info);
26589 +       sk->sk_xid = -1;
26590 +       clr_nx_info(&sk->sk_nx_info);
26591 +       sk->sk_nid = -1;
26592         sk_prot_free(sk->sk_prot_creator, sk);
26593  }
26594  
26595 @@ -1008,6 +1019,8 @@ struct sock *sk_clone(const struct sock 
26596  
26597                 /* SANITY */
26598                 get_net(sock_net(newsk));
26599 +               sock_vx_init(newsk);
26600 +               sock_nx_init(newsk);
26601                 sk_node_init(&newsk->sk_node);
26602                 sock_lock_init(newsk);
26603                 bh_lock_sock(newsk);
26604 @@ -1054,6 +1067,12 @@ struct sock *sk_clone(const struct sock 
26605                 newsk->sk_priority = 0;
26606                 atomic_set(&newsk->sk_refcnt, 2);
26607  
26608 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26609 +               newsk->sk_xid = sk->sk_xid;
26610 +               vx_sock_inc(newsk);
26611 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26612 +               newsk->sk_nid = sk->sk_nid;
26613 +
26614                 /*
26615                  * Increment the counter in the same struct proto as the master
26616                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26617 @@ -1738,6 +1757,11 @@ void sock_init_data(struct socket *sock,
26618  
26619         sk->sk_stamp = ktime_set(-1L, 0);
26620  
26621 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26622 +       sk->sk_xid = vx_current_xid();
26623 +       vx_sock_inc(sk);
26624 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26625 +       sk->sk_nid = nx_current_nid();
26626         atomic_set(&sk->sk_refcnt, 1);
26627         atomic_set(&sk->sk_drops, 0);
26628  }
26629 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/af_inet.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/af_inet.c
26630 --- linux-2.6.27.6/net/ipv4/af_inet.c   2008-10-13 14:52:09.000000000 +0200
26631 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/af_inet.c        2008-10-13 14:54:20.000000000 +0200
26632 @@ -114,6 +114,7 @@
26633  #ifdef CONFIG_IP_MROUTE
26634  #include <linux/mroute.h>
26635  #endif
26636 +#include <linux/vs_limit.h>
26637  
26638  extern void ip_mc_drop_socket(struct sock *sk);
26639  
26640 @@ -325,9 +326,12 @@ lookup_protocol:
26641         }
26642  
26643         err = -EPERM;
26644 +       if ((protocol == IPPROTO_ICMP) &&
26645 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26646 +               goto override;
26647         if (answer->capability > 0 && !capable(answer->capability))
26648                 goto out_rcu_unlock;
26649 -
26650 +override:
26651         err = -EAFNOSUPPORT;
26652         if (!inet_netns_ok(net, protocol))
26653                 goto out_rcu_unlock;
26654 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26655         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26656         struct sock *sk = sock->sk;
26657         struct inet_sock *inet = inet_sk(sk);
26658 +       struct nx_v4_sock_addr nsa;
26659         unsigned short snum;
26660         int chk_addr_ret;
26661         int err;
26662 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26663         if (addr_len < sizeof(struct sockaddr_in))
26664                 goto out;
26665  
26666 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26667 +       err = v4_map_sock_addr(inet, addr, &nsa);
26668 +       if (err)
26669 +               goto out;
26670 +
26671 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26672  
26673         /* Not specified by any standard per-se, however it breaks too
26674          * many applications when removed.  It is unfortunate since
26675 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26676         err = -EADDRNOTAVAIL;
26677         if (!sysctl_ip_nonlocal_bind &&
26678             !inet->freebind &&
26679 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26680 +           nsa.saddr != htonl(INADDR_ANY) &&
26681             chk_addr_ret != RTN_LOCAL &&
26682             chk_addr_ret != RTN_MULTICAST &&
26683             chk_addr_ret != RTN_BROADCAST)
26684 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26685         if (sk->sk_state != TCP_CLOSE || inet->num)
26686                 goto out_release_sock;
26687  
26688 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26689 +       v4_set_sock_addr(inet, &nsa);
26690         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26691                 inet->saddr = 0;  /* Use device */
26692  
26693 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26694                      peer == 1))
26695                         return -ENOTCONN;
26696                 sin->sin_port = inet->dport;
26697 -               sin->sin_addr.s_addr = inet->daddr;
26698 +               sin->sin_addr.s_addr =
26699 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26700         } else {
26701                 __be32 addr = inet->rcv_saddr;
26702                 if (!addr)
26703                         addr = inet->saddr;
26704 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26705                 sin->sin_port = inet->sport;
26706                 sin->sin_addr.s_addr = addr;
26707         }
26708 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/devinet.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/devinet.c
26709 --- linux-2.6.27.6/net/ipv4/devinet.c   2008-10-13 14:52:09.000000000 +0200
26710 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/devinet.c        2008-10-13 14:54:20.000000000 +0200
26711 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
26712         return in_dev;
26713  }
26714  
26715 +
26716  /* Called only from RTNL semaphored context. No locks. */
26717  
26718  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26719 @@ -662,6 +663,8 @@ int devinet_ioctl(struct net *net, unsig
26720                 *colon = ':';
26721  
26722         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26723 +               struct nx_info *nxi = current->nx_info;
26724 +
26725                 if (tryaddrmatch) {
26726                         /* Matthias Andree */
26727                         /* compare label and address (4.4BSD style) */
26728 @@ -670,6 +673,8 @@ int devinet_ioctl(struct net *net, unsig
26729                            This is checked above. */
26730                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26731                              ifap = &ifa->ifa_next) {
26732 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26733 +                                       continue;
26734                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26735                                     sin_orig.sin_addr.s_addr ==
26736                                                         ifa->ifa_address) {
26737 @@ -682,9 +687,12 @@ int devinet_ioctl(struct net *net, unsig
26738                    comparing just the label */
26739                 if (!ifa) {
26740                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26741 -                            ifap = &ifa->ifa_next)
26742 +                            ifap = &ifa->ifa_next) {
26743 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26744 +                                       continue;
26745                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26746                                         break;
26747 +                       }
26748                 }
26749         }
26750  
26751 @@ -835,6 +843,8 @@ static int inet_gifconf(struct net_devic
26752                 goto out;
26753  
26754         for (; ifa; ifa = ifa->ifa_next) {
26755 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26756 +                       continue;
26757                 if (!buf) {
26758                         done += sizeof(ifr);
26759                         continue;
26760 @@ -1165,6 +1175,7 @@ static int inet_dump_ifaddr(struct sk_bu
26761         struct net_device *dev;
26762         struct in_device *in_dev;
26763         struct in_ifaddr *ifa;
26764 +       struct sock *sk = skb->sk;
26765         int s_ip_idx, s_idx = cb->args[0];
26766  
26767         s_ip_idx = ip_idx = cb->args[1];
26768 @@ -1179,6 +1190,8 @@ static int inet_dump_ifaddr(struct sk_bu
26769  
26770                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26771                      ifa = ifa->ifa_next, ip_idx++) {
26772 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26773 +                               continue;
26774                         if (ip_idx < s_ip_idx)
26775                                 continue;
26776                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26777 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/fib_hash.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/fib_hash.c
26778 --- linux-2.6.27.6/net/ipv4/fib_hash.c  2008-10-13 14:52:09.000000000 +0200
26779 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/fib_hash.c       2008-10-13 14:54:20.000000000 +0200
26780 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26781         prefix  = f->fn_key;
26782         mask    = FZ_MASK(iter->zone);
26783         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26784 -       if (fi)
26785 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26786                 seq_printf(seq,
26787                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26788                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26789 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/inet_connection_sock.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/inet_connection_sock.c
26790 --- linux-2.6.27.6/net/ipv4/inet_connection_sock.c      2008-10-13 14:52:09.000000000 +0200
26791 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/inet_connection_sock.c   2008-10-13 14:54:20.000000000 +0200
26792 @@ -47,10 +47,40 @@ void inet_get_local_port_range(int *low,
26793  }
26794  EXPORT_SYMBOL(inet_get_local_port_range);
26795  
26796 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26797 +{
26798 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26799 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26800 +
26801 +       if (inet_v6_ipv6only(sk2))
26802 +               return 0;
26803 +
26804 +       if (sk1_rcv_saddr &&
26805 +           sk2_rcv_saddr &&
26806 +           sk1_rcv_saddr == sk2_rcv_saddr)
26807 +               return 1;
26808 +
26809 +       if (sk1_rcv_saddr &&
26810 +           !sk2_rcv_saddr &&
26811 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26812 +               return 1;
26813 +
26814 +       if (sk2_rcv_saddr &&
26815 +           !sk1_rcv_saddr &&
26816 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26817 +               return 1;
26818 +
26819 +       if (!sk1_rcv_saddr &&
26820 +           !sk2_rcv_saddr &&
26821 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26822 +               return 1;
26823 +
26824 +       return 0;
26825 +}
26826 +
26827  int inet_csk_bind_conflict(const struct sock *sk,
26828                            const struct inet_bind_bucket *tb)
26829  {
26830 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26831         struct sock *sk2;
26832         struct hlist_node *node;
26833         int reuse = sk->sk_reuse;
26834 @@ -70,9 +100,7 @@ int inet_csk_bind_conflict(const struct 
26835                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26836                         if (!reuse || !sk2->sk_reuse ||
26837                             sk2->sk_state == TCP_LISTEN) {
26838 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26839 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26840 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26841 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26842                                         break;
26843                         }
26844                 }
26845 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/inet_diag.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/inet_diag.c
26846 --- linux-2.6.27.6/net/ipv4/inet_diag.c 2008-10-13 14:52:09.000000000 +0200
26847 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/inet_diag.c      2008-10-13 14:54:20.000000000 +0200
26848 @@ -32,6 +32,8 @@
26849  #include <linux/stddef.h>
26850  
26851  #include <linux/inet_diag.h>
26852 +#include <linux/vs_network.h>
26853 +#include <linux/vs_inet.h>
26854  
26855  static const struct inet_diag_handler **inet_diag_table;
26856  
26857 @@ -120,8 +122,8 @@ static int inet_csk_diag_fill(struct soc
26858  
26859         r->id.idiag_sport = inet->sport;
26860         r->id.idiag_dport = inet->dport;
26861 -       r->id.idiag_src[0] = inet->rcv_saddr;
26862 -       r->id.idiag_dst[0] = inet->daddr;
26863 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26864 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26865  
26866  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26867         if (r->idiag_family == AF_INET6) {
26868 @@ -208,8 +210,8 @@ static int inet_twsk_diag_fill(struct in
26869         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26870         r->id.idiag_sport     = tw->tw_sport;
26871         r->id.idiag_dport     = tw->tw_dport;
26872 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26873 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26874 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26875 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26876         r->idiag_state        = tw->tw_substate;
26877         r->idiag_timer        = 3;
26878         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26879 @@ -266,6 +268,7 @@ static int inet_diag_get_exact(struct sk
26880         err = -EINVAL;
26881  
26882         if (req->idiag_family == AF_INET) {
26883 +               /* TODO: lback */
26884                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26885                                  req->id.idiag_dport, req->id.idiag_src[0],
26886                                  req->id.idiag_sport, req->id.idiag_if);
26887 @@ -508,6 +511,7 @@ static int inet_csk_diag_dump(struct soc
26888                 } else
26889  #endif
26890                 {
26891 +                       /* TODO: lback */
26892                         entry.saddr = &inet->rcv_saddr;
26893                         entry.daddr = &inet->daddr;
26894                 }
26895 @@ -544,6 +548,7 @@ static int inet_twsk_diag_dump(struct in
26896                 } else
26897  #endif
26898                 {
26899 +                       /* TODO: lback */
26900                         entry.saddr = &tw->tw_rcv_saddr;
26901                         entry.daddr = &tw->tw_daddr;
26902                 }
26903 @@ -590,8 +595,8 @@ static int inet_diag_fill_req(struct sk_
26904  
26905         r->id.idiag_sport = inet->sport;
26906         r->id.idiag_dport = ireq->rmt_port;
26907 -       r->id.idiag_src[0] = ireq->loc_addr;
26908 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26909 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26910 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26911         r->idiag_expires = jiffies_to_msecs(tmo);
26912         r->idiag_rqueue = 0;
26913         r->idiag_wqueue = 0;
26914 @@ -661,6 +666,7 @@ static int inet_diag_dump_reqs(struct sk
26915                                 continue;
26916  
26917                         if (bc) {
26918 +                               /* TODO: lback */
26919                                 entry.saddr =
26920  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26921                                         (entry.family == AF_INET6) ?
26922 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26923                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
26924                                 struct inet_sock *inet = inet_sk(sk);
26925  
26926 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26927 +                                       continue;
26928                                 if (num < s_num) {
26929                                         num++;
26930                                         continue;
26931 @@ -790,6 +798,8 @@ skip_listen_ht:
26932                 sk_for_each(sk, node, &head->chain) {
26933                         struct inet_sock *inet = inet_sk(sk);
26934  
26935 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26936 +                               continue;
26937                         if (num < s_num)
26938                                 goto next_normal;
26939                         if (!(r->idiag_states & (1 << sk->sk_state)))
26940 @@ -814,6 +824,8 @@ next_normal:
26941                         inet_twsk_for_each(tw, node,
26942                                     &head->twchain) {
26943  
26944 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26945 +                                       continue;
26946                                 if (num < s_num)
26947                                         goto next_dying;
26948                                 if (r->id.idiag_sport != tw->tw_sport &&
26949 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/inet_hashtables.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/inet_hashtables.c
26950 --- linux-2.6.27.6/net/ipv4/inet_hashtables.c   2008-10-13 14:52:09.000000000 +0200
26951 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/inet_hashtables.c        2008-10-13 14:54:20.000000000 +0200
26952 @@ -21,6 +21,7 @@
26953  
26954  #include <net/inet_connection_sock.h>
26955  #include <net/inet_hashtables.h>
26956 +#include <net/route.h>
26957  #include <net/ip.h>
26958  
26959  /*
26960 @@ -163,11 +164,10 @@ static struct sock *inet_lookup_listener
26961                         const __be32 rcv_saddr = inet->rcv_saddr;
26962                         int score = sk->sk_family == PF_INET ? 1 : 0;
26963  
26964 -                       if (rcv_saddr) {
26965 -                               if (rcv_saddr != daddr)
26966 -                                       continue;
26967 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
26968                                 score += 2;
26969 -                       }
26970 +                       else
26971 +                               continue;
26972                         if (sk->sk_bound_dev_if) {
26973                                 if (sk->sk_bound_dev_if != dif)
26974                                         continue;
26975 @@ -199,7 +199,7 @@ struct sock *__inet_lookup_listener(stru
26976                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
26977  
26978                 if (inet->num == hnum && !sk->sk_node.next &&
26979 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
26980 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
26981                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
26982                     !sk->sk_bound_dev_if && net_eq(sock_net(sk), net))
26983                         goto sherry_cache;
26984 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/netfilter/nf_nat_helper.c
26985 --- linux-2.6.27.6/net/ipv4/netfilter/nf_nat_helper.c   2008-07-13 23:51:29.000000000 +0200
26986 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/netfilter/nf_nat_helper.c        2008-10-13 14:54:20.000000000 +0200
26987 @@ -18,6 +18,7 @@
26988  #include <net/tcp.h>
26989  
26990  #include <linux/netfilter_ipv4.h>
26991 +#include <net/route.h>
26992  #include <net/netfilter/nf_conntrack.h>
26993  #include <net/netfilter/nf_conntrack_helper.h>
26994  #include <net/netfilter/nf_conntrack_ecache.h>
26995 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/netfilter.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/netfilter.c
26996 --- linux-2.6.27.6/net/ipv4/netfilter.c 2008-07-13 23:51:29.000000000 +0200
26997 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/netfilter.c      2008-10-13 14:54:20.000000000 +0200
26998 @@ -4,7 +4,7 @@
26999  #include <linux/netfilter_ipv4.h>
27000  #include <linux/ip.h>
27001  #include <linux/skbuff.h>
27002 -#include <net/route.h>
27003 +// #include <net/route.h>
27004  #include <net/xfrm.h>
27005  #include <net/ip.h>
27006  #include <net/netfilter/nf_queue.h>
27007 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/raw.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/raw.c
27008 --- linux-2.6.27.6/net/ipv4/raw.c       2008-10-13 14:52:09.000000000 +0200
27009 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/raw.c    2008-10-13 14:54:20.000000000 +0200
27010 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27011  
27012                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27013                     !(inet->daddr && inet->daddr != raddr)              &&
27014 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27015 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27016                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27017                         goto found; /* gotcha */
27018         }
27019 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
27020                 icmp_out_count(net, ((struct icmphdr *)
27021                         skb_transport_header(skb))->type);
27022  
27023 +       err = -EPERM;
27024 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27025 +               sk->sk_nx_info &&
27026 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27027 +               goto error_free;
27028 +
27029         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27030                       dst_output);
27031         if (err > 0)
27032 @@ -383,6 +389,7 @@ out:
27033  
27034  error_fault:
27035         err = -EFAULT;
27036 +error_free:
27037         kfree_skb(skb);
27038  error:
27039         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
27040 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
27041                 }
27042  
27043                 security_sk_classify_flow(sk, &fl);
27044 +               if (sk->sk_nx_info) {
27045 +                       err = ip_v4_find_src(sock_net(sk),
27046 +                               sk->sk_nx_info, &rt, &fl);
27047 +
27048 +                       if (err)
27049 +                               goto done;
27050 +               }
27051                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27052         }
27053         if (err)
27054 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
27055  {
27056         struct inet_sock *inet = inet_sk(sk);
27057         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27058 +       struct nx_v4_sock_addr nsa = { 0 };
27059         int ret = -EINVAL;
27060         int chk_addr_ret;
27061  
27062         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27063                 goto out;
27064 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27065 +       v4_map_sock_addr(inet, addr, &nsa);
27066 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27067         ret = -EADDRNOTAVAIL;
27068 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27069 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27070             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27071                 goto out;
27072 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27073 +       v4_set_sock_addr(inet, &nsa);
27074         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27075                 inet->saddr = 0;  /* Use device */
27076         sk_dst_reset(sk);
27077 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
27078         /* Copy the address. */
27079         if (sin) {
27080                 sin->sin_family = AF_INET;
27081 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27082 +               sin->sin_addr.s_addr =
27083 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27084                 sin->sin_port = 0;
27085                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27086         }
27087 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
27088                 struct hlist_node *node;
27089  
27090                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27091 -                       if (sock_net(sk) == seq_file_net(seq))
27092 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27093 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27094                                 goto found;
27095         }
27096         sk = NULL;
27097 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
27098                 sk = sk_next(sk);
27099  try_again:
27100                 ;
27101 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27102 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27103 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27104  
27105         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27106                 sk = sk_head(&state->h->ht[state->bucket]);
27107 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
27108  
27109         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27110                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27111 -               i, src, srcp, dest, destp, sp->sk_state,
27112 +               i,
27113 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27114 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27115 +               sp->sk_state,
27116                 atomic_read(&sp->sk_wmem_alloc),
27117                 atomic_read(&sp->sk_rmem_alloc),
27118                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27119 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/syncookies.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/syncookies.c
27120 --- linux-2.6.27.6/net/ipv4/syncookies.c        2008-10-13 14:52:09.000000000 +0200
27121 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/syncookies.c     2008-10-13 14:54:20.000000000 +0200
27122 @@ -16,6 +16,7 @@
27123  #include <linux/cryptohash.h>
27124  #include <linux/kernel.h>
27125  #include <net/tcp.h>
27126 +#include <net/route.h>
27127  
27128  /* Timestamps: lowest 9 bits store TCP options */
27129  #define TSBITS 9
27130 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/tcp.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/tcp.c
27131 --- linux-2.6.27.6/net/ipv4/tcp.c       2008-10-13 14:52:09.000000000 +0200
27132 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/tcp.c    2008-10-13 14:54:20.000000000 +0200
27133 @@ -264,6 +264,7 @@
27134  #include <linux/cache.h>
27135  #include <linux/err.h>
27136  #include <linux/crypto.h>
27137 +#include <linux/in.h>
27138  
27139  #include <net/icmp.h>
27140  #include <net/tcp.h>
27141 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/tcp_ipv4.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/tcp_ipv4.c
27142 --- linux-2.6.27.6/net/ipv4/tcp_ipv4.c  2008-10-13 14:52:09.000000000 +0200
27143 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/tcp_ipv4.c       2008-10-13 14:54:20.000000000 +0200
27144 @@ -1886,6 +1886,12 @@ static void *listening_get_next(struct s
27145                 req = req->dl_next;
27146                 while (1) {
27147                         while (req) {
27148 +                               vxdprintk(VXD_CBIT(net, 6),
27149 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27150 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27151 +                               if (req->sk &&
27152 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27153 +                                       continue;
27154                                 if (req->rsk_ops->family == st->family) {
27155                                         cur = req;
27156                                         goto out;
27157 @@ -1910,6 +1916,10 @@ get_req:
27158         }
27159  get_sk:
27160         sk_for_each_from(sk, node) {
27161 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27162 +                       sk, sk->sk_nid, nx_current_nid());
27163 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27164 +                       continue;
27165                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27166                         cur = sk;
27167                         goto out;
27168 @@ -1960,6 +1970,11 @@ static void *established_get_first(struc
27169  
27170                 read_lock_bh(lock);
27171                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27172 +                       vxdprintk(VXD_CBIT(net, 6),
27173 +                               "sk,egf: %p [#%d] (from %d)",
27174 +                               sk, sk->sk_nid, nx_current_nid());
27175 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27176 +                               continue;
27177                         if (sk->sk_family != st->family ||
27178                             !net_eq(sock_net(sk), net)) {
27179                                 continue;
27180 @@ -1970,6 +1985,11 @@ static void *established_get_first(struc
27181                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27182                 inet_twsk_for_each(tw, node,
27183                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27184 +                       vxdprintk(VXD_CBIT(net, 6),
27185 +                               "tw: %p [#%d] (from %d)",
27186 +                               tw, tw->tw_nid, nx_current_nid());
27187 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27188 +                               continue;
27189                         if (tw->tw_family != st->family ||
27190                             !net_eq(twsk_net(tw), net)) {
27191                                 continue;
27192 @@ -1998,7 +2018,9 @@ static void *established_get_next(struct
27193                 tw = cur;
27194                 tw = tw_next(tw);
27195  get_tw:
27196 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27197 +               while (tw && (tw->tw_family != st->family ||
27198 +                       !net_eq(twsk_net(tw), net) ||
27199 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27200                         tw = tw_next(tw);
27201                 }
27202                 if (tw) {
27203 @@ -2019,6 +2041,11 @@ get_tw:
27204                 sk = sk_next(sk);
27205  
27206         sk_for_each_from(sk, node) {
27207 +               vxdprintk(VXD_CBIT(net, 6),
27208 +                       "sk,egn: %p [#%d] (from %d)",
27209 +                       sk, sk->sk_nid, nx_current_nid());
27210 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27211 +                       continue;
27212                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27213                         goto found;
27214         }
27215 @@ -2173,9 +2200,9 @@ static void get_openreq4(struct sock *sk
27216         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27217                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27218                 i,
27219 -               ireq->loc_addr,
27220 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27221                 ntohs(inet_sk(sk)->sport),
27222 -               ireq->rmt_addr,
27223 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27224                 ntohs(ireq->rmt_port),
27225                 TCP_SYN_RECV,
27226                 0, 0, /* could print option size, but that is af dependent. */
27227 @@ -2218,7 +2245,10 @@ static void get_tcp4_sock(struct sock *s
27228  
27229         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27230                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27231 -               i, src, srcp, dest, destp, sk->sk_state,
27232 +               i,
27233 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27234 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27235 +               sk->sk_state,
27236                 tp->write_seq - tp->snd_una,
27237                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27238                                              (tp->rcv_nxt - tp->copied_seq),
27239 @@ -2254,7 +2284,10 @@ static void get_timewait4_sock(struct in
27240  
27241         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27242                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27243 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27244 +               i,
27245 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27246 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27247 +               tw->tw_substate, 0, 0,
27248                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27249                 atomic_read(&tw->tw_refcnt), tw, len);
27250  }
27251 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/tcp_minisocks.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/tcp_minisocks.c
27252 --- linux-2.6.27.6/net/ipv4/tcp_minisocks.c     2008-10-13 14:52:09.000000000 +0200
27253 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/tcp_minisocks.c  2008-10-13 14:54:20.000000000 +0200
27254 @@ -26,6 +26,10 @@
27255  #include <net/inet_common.h>
27256  #include <net/xfrm.h>
27257  
27258 +#include <linux/vs_limit.h>
27259 +#include <linux/vs_socket.h>
27260 +#include <linux/vs_context.h>
27261 +
27262  #ifdef CONFIG_SYSCTL
27263  #define SYNC_INIT 0 /* let the user enable it */
27264  #else
27265 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27266                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27267                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27268  
27269 +               tw->tw_xid              = sk->sk_xid;
27270 +               tw->tw_vx_info          = NULL;
27271 +               tw->tw_nid              = sk->sk_nid;
27272 +               tw->tw_nx_info          = NULL;
27273 +
27274  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27275                 if (tw->tw_family == PF_INET6) {
27276                         struct ipv6_pinfo *np = inet6_sk(sk);
27277 diff -NurpP --minimal linux-2.6.27.6/net/ipv4/udp.c linux-2.6.27.6-vs2.3.0.36/net/ipv4/udp.c
27278 --- linux-2.6.27.6/net/ipv4/udp.c       2008-10-13 14:52:09.000000000 +0200
27279 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv4/udp.c    2008-10-13 14:54:20.000000000 +0200
27280 @@ -234,20 +234,14 @@ fail:
27281         return error;
27282  }
27283  
27284 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27285 -{
27286 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27287 -
27288 -       return  ( !ipv6_only_sock(sk2)  &&
27289 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27290 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27291 -}
27292 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27293  
27294  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27295  {
27296         return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal);
27297  }
27298  
27299 +
27300  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27301   * harder than this. -DaveM
27302   */
27303 @@ -267,10 +261,16 @@ static struct sock *__udp4_lib_lookup(st
27304                 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
27305                                 !ipv6_only_sock(sk)) {
27306                         int score = (sk->sk_family == PF_INET ? 1 : 0);
27307 +
27308                         if (inet->rcv_saddr) {
27309                                 if (inet->rcv_saddr != daddr)
27310                                         continue;
27311                                 score+=2;
27312 +                       } else {
27313 +                               /* block non nx_info ips */
27314 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
27315 +                                       daddr, NXA_MASK_BIND))
27316 +                                       continue;
27317                         }
27318                         if (inet->daddr) {
27319                                 if (inet->daddr != saddr)
27320 @@ -296,6 +296,7 @@ static struct sock *__udp4_lib_lookup(st
27321                         }
27322                 }
27323         }
27324 +
27325         if (result)
27326                 sock_hold(result);
27327         read_unlock(&udp_hash_lock);
27328 @@ -317,7 +318,7 @@ static inline struct sock *udp_v4_mcast_
27329                 if (s->sk_hash != hnum                                  ||
27330                     (inet->daddr && inet->daddr != rmt_addr)            ||
27331                     (inet->dport != rmt_port && inet->dport)            ||
27332 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27333 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27334                     ipv6_only_sock(s)                                   ||
27335                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27336                         continue;
27337 @@ -654,8 +655,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27338                                                { .sport = inet->sport,
27339                                                  .dport = dport } } };
27340                 struct net *net = sock_net(sk);
27341 +               struct nx_info *nxi = sk->sk_nx_info;
27342  
27343                 security_sk_classify_flow(sk, &fl);
27344 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27345 +               if (err)
27346 +                       goto out;
27347 +
27348                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27349                 if (err) {
27350                         if (err == -ENETUNREACH)
27351 @@ -900,7 +906,8 @@ try_again:
27352         {
27353                 sin->sin_family = AF_INET;
27354                 sin->sin_port = udp_hdr(skb)->source;
27355 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27356 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27357 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27358                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27359         }
27360         if (inet->cmsg_flags)
27361 @@ -1528,6 +1535,8 @@ static struct sock *udp_get_first(struct
27362                 sk_for_each(sk, node, state->hashtable + state->bucket) {
27363                         if (!net_eq(sock_net(sk), net))
27364                                 continue;
27365 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27366 +                               continue;
27367                         if (sk->sk_family == state->family)
27368                                 goto found;
27369                 }
27370 @@ -1546,7 +1555,9 @@ static struct sock *udp_get_next(struct 
27371                 sk = sk_next(sk);
27372  try_again:
27373                 ;
27374 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27375 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27376 +               sk->sk_family != state->family ||
27377 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27378  
27379         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
27380                 sk = sk_head(state->hashtable + state->bucket);
27381 @@ -1647,7 +1658,10 @@ static void udp4_format_sock(struct sock
27382  
27383         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27384                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27385 -               bucket, src, srcp, dest, destp, sp->sk_state,
27386 +               bucket,
27387 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27388 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27389 +               sp->sk_state,
27390                 atomic_read(&sp->sk_wmem_alloc),
27391                 atomic_read(&sp->sk_rmem_alloc),
27392                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27393 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/addrconf.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/addrconf.c
27394 --- linux-2.6.27.6/net/ipv6/addrconf.c  2008-10-13 14:52:09.000000000 +0200
27395 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/addrconf.c       2008-10-13 14:54:20.000000000 +0200
27396 @@ -85,6 +85,8 @@
27397  
27398  #include <linux/proc_fs.h>
27399  #include <linux/seq_file.h>
27400 +#include <linux/vs_network.h>
27401 +#include <linux/vs_inet6.h>
27402  
27403  /* Set to 3 to get tracing... */
27404  #define ACONF_DEBUG 2
27405 @@ -1108,7 +1110,7 @@ out:
27406  
27407  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27408                        const struct in6_addr *daddr, unsigned int prefs,
27409 -                      struct in6_addr *saddr)
27410 +                      struct in6_addr *saddr, struct nx_info *nxi)
27411  {
27412         struct ipv6_saddr_score scores[2],
27413                                 *score = &scores[0], *hiscore = &scores[1];
27414 @@ -1364,35 +1366,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27415         return ifp;
27416  }
27417  
27418 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27419 +
27420  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27421  {
27422         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27423         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27424 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27425         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27426         int sk_ipv6only = ipv6_only_sock(sk);
27427         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27428         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27429         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27430  
27431 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27432 +       /* FIXME: needs handling for v4 ANY */
27433 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27434                 return 1;
27435  
27436         if (addr_type2 == IPV6_ADDR_ANY &&
27437 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27438 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27439 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27440                 return 1;
27441  
27442         if (addr_type == IPV6_ADDR_ANY &&
27443 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27444 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27445 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27446 +               return 1;
27447 +
27448 +       if (addr_type == IPV6_ADDR_ANY &&
27449 +           addr_type2 == IPV6_ADDR_ANY &&
27450 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27451                 return 1;
27452  
27453         if (sk2_rcv_saddr6 &&
27454 +           addr_type != IPV6_ADDR_ANY &&
27455 +           addr_type != IPV6_ADDR_ANY &&
27456             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27457                 return 1;
27458  
27459         if (addr_type == IPV6_ADDR_MAPPED &&
27460             !sk2_ipv6only &&
27461 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27462 +           ipv4_rcv_saddr_equal(sk, sk2))
27463                 return 1;
27464  
27465         return 0;
27466 @@ -2986,7 +2999,10 @@ static void if6_seq_stop(struct seq_file
27467  static int if6_seq_show(struct seq_file *seq, void *v)
27468  {
27469         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27470 -       seq_printf(seq,
27471 +
27472 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27473 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27474 +               seq_printf(seq,
27475                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
27476                    NIP6(ifp->addr),
27477                    ifp->idev->dev->ifindex,
27478 @@ -3481,6 +3497,12 @@ static int inet6_dump_addr(struct sk_buf
27479         struct ifmcaddr6 *ifmca;
27480         struct ifacaddr6 *ifaca;
27481         struct net *net = sock_net(skb->sk);
27482 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27483 +
27484 +       /* disable ipv6 on non v6 guests */
27485 +       if (nxi && !nx_info_has_v6(nxi))
27486 +               return skb->len;
27487 +
27488  
27489         s_idx = cb->args[0];
27490         s_ip_idx = ip_idx = cb->args[1];
27491 @@ -3502,6 +3524,8 @@ static int inet6_dump_addr(struct sk_buf
27492                              ifa = ifa->if_next, ip_idx++) {
27493                                 if (ip_idx < s_ip_idx)
27494                                         continue;
27495 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27496 +                                       continue;
27497                                 err = inet6_fill_ifaddr(skb, ifa,
27498                                                         NETLINK_CB(cb->skb).pid,
27499                                                         cb->nlh->nlmsg_seq,
27500 @@ -3515,6 +3539,8 @@ static int inet6_dump_addr(struct sk_buf
27501                              ifmca = ifmca->next, ip_idx++) {
27502                                 if (ip_idx < s_ip_idx)
27503                                         continue;
27504 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27505 +                                       continue;
27506                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27507                                                           NETLINK_CB(cb->skb).pid,
27508                                                           cb->nlh->nlmsg_seq,
27509 @@ -3528,6 +3554,8 @@ static int inet6_dump_addr(struct sk_buf
27510                              ifaca = ifaca->aca_next, ip_idx++) {
27511                                 if (ip_idx < s_ip_idx)
27512                                         continue;
27513 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27514 +                                       continue;
27515                                 err = inet6_fill_ifacaddr(skb, ifaca,
27516                                                           NETLINK_CB(cb->skb).pid,
27517                                                           cb->nlh->nlmsg_seq,
27518 @@ -3813,12 +3841,19 @@ static int inet6_dump_ifinfo(struct sk_b
27519         int s_idx = cb->args[0];
27520         struct net_device *dev;
27521         struct inet6_dev *idev;
27522 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27523 +
27524 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27525 +       if (skb->sk && skb->sk->sk_vx_info)
27526 +               return skb->len; */
27527  
27528         read_lock(&dev_base_lock);
27529         idx = 0;
27530         for_each_netdev(net, dev) {
27531                 if (idx < s_idx)
27532                         goto cont;
27533 +               if (!v6_dev_in_nx_info(dev, nxi))
27534 +                       goto cont;
27535                 if ((idev = in6_dev_get(dev)) == NULL)
27536                         goto cont;
27537                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27538 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/af_inet6.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/af_inet6.c
27539 --- linux-2.6.27.6/net/ipv6/af_inet6.c  2008-10-13 14:52:09.000000000 +0200
27540 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/af_inet6.c       2008-10-13 14:54:20.000000000 +0200
27541 @@ -41,6 +41,8 @@
27542  #include <linux/netdevice.h>
27543  #include <linux/icmpv6.h>
27544  #include <linux/netfilter_ipv6.h>
27545 +#include <linux/vs_inet.h>
27546 +#include <linux/vs_inet6.h>
27547  
27548  #include <net/ip.h>
27549  #include <net/ipv6.h>
27550 @@ -49,6 +51,7 @@
27551  #include <net/tcp.h>
27552  #include <net/ipip.h>
27553  #include <net/protocol.h>
27554 +#include <net/route.h>
27555  #include <net/inet_common.h>
27556  #include <net/transp_v6.h>
27557  #include <net/ip6_route.h>
27558 @@ -141,9 +144,12 @@ lookup_protocol:
27559         }
27560  
27561         err = -EPERM;
27562 +       if ((protocol == IPPROTO_ICMPV6) &&
27563 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27564 +               goto override;
27565         if (answer->capability > 0 && !capable(answer->capability))
27566                 goto out_rcu_unlock;
27567 -
27568 +override:
27569         sock->ops = answer->ops;
27570         answer_prot = answer->prot;
27571         answer_no_check = answer->no_check;
27572 @@ -242,6 +248,7 @@ int inet6_bind(struct socket *sock, stru
27573         struct inet_sock *inet = inet_sk(sk);
27574         struct ipv6_pinfo *np = inet6_sk(sk);
27575         struct net *net = sock_net(sk);
27576 +       struct nx_v6_sock_addr nsa;
27577         __be32 v4addr = 0;
27578         unsigned short snum;
27579         int addr_type = 0;
27580 @@ -253,6 +260,11 @@ int inet6_bind(struct socket *sock, stru
27581  
27582         if (addr_len < SIN6_LEN_RFC2133)
27583                 return -EINVAL;
27584 +
27585 +       err = v6_map_sock_addr(inet, addr, &nsa);
27586 +       if (err)
27587 +               return err;
27588 +
27589         addr_type = ipv6_addr_type(&addr->sin6_addr);
27590         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27591                 return -EINVAL;
27592 @@ -276,6 +288,10 @@ int inet6_bind(struct socket *sock, stru
27593                         err = -EADDRNOTAVAIL;
27594                         goto out;
27595                 }
27596 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27597 +                       err = -EADDRNOTAVAIL;
27598 +                       goto out;
27599 +               }
27600         } else {
27601                 if (addr_type != IPV6_ADDR_ANY) {
27602                         struct net_device *dev = NULL;
27603 @@ -301,6 +317,11 @@ int inet6_bind(struct socket *sock, stru
27604                                 }
27605                         }
27606  
27607 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27608 +                               err = -EADDRNOTAVAIL;
27609 +                               goto out;
27610 +                       }
27611 +
27612                         /* ipv4 addr of the socket is invalid.  Only the
27613                          * unspecified and mapped address have a v4 equivalent.
27614                          */
27615 @@ -319,6 +340,8 @@ int inet6_bind(struct socket *sock, stru
27616                 }
27617         }
27618  
27619 +       v6_set_sock_addr(inet, &nsa);
27620 +
27621         inet->rcv_saddr = v4addr;
27622         inet->saddr = v4addr;
27623  
27624 @@ -411,9 +434,11 @@ int inet6_getname(struct socket *sock, s
27625                         return -ENOTCONN;
27626                 sin->sin6_port = inet->dport;
27627                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27628 +               /* FIXME: remap lback? */
27629                 if (np->sndflow)
27630                         sin->sin6_flowinfo = np->flow_label;
27631         } else {
27632 +               /* FIXME: remap lback? */
27633                 if (ipv6_addr_any(&np->rcv_saddr))
27634                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27635                 else
27636 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/fib6_rules.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/fib6_rules.c
27637 --- linux-2.6.27.6/net/ipv6/fib6_rules.c        2008-10-13 14:52:09.000000000 +0200
27638 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/fib6_rules.c     2008-10-13 14:54:20.000000000 +0200
27639 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27640                         if (ipv6_dev_get_saddr(net,
27641                                                ip6_dst_idev(&rt->u.dst)->dev,
27642                                                &flp->fl6_dst, srcprefs,
27643 -                                              &saddr))
27644 +                                              &saddr, NULL))
27645                                 goto again;
27646                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27647                                                r->src.plen))
27648 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/inet6_hashtables.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/inet6_hashtables.c
27649 --- linux-2.6.27.6/net/ipv6/inet6_hashtables.c  2008-10-13 14:52:09.000000000 +0200
27650 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/inet6_hashtables.c       2008-10-13 14:54:20.000000000 +0200
27651 @@ -16,6 +16,7 @@
27652  
27653  #include <linux/module.h>
27654  #include <linux/random.h>
27655 +#include <linux/vs_inet6.h>
27656  
27657  #include <net/inet_connection_sock.h>
27658  #include <net/inet_hashtables.h>
27659 @@ -115,6 +116,9 @@ struct sock *inet6_lookup_listener(struc
27660                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27661                                         continue;
27662                                 score++;
27663 +                       } else {
27664 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27665 +                                       continue;
27666                         }
27667                         if (sk->sk_bound_dev_if) {
27668                                 if (sk->sk_bound_dev_if != dif)
27669 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/ip6_output.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/ip6_output.c
27670 --- linux-2.6.27.6/net/ipv6/ip6_output.c        2008-10-13 14:52:09.000000000 +0200
27671 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/ip6_output.c     2008-10-13 14:54:20.000000000 +0200
27672 @@ -937,7 +937,7 @@ static int ip6_dst_lookup_tail(struct so
27673                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27674                                          &fl->fl6_dst,
27675                                          sk ? inet6_sk(sk)->srcprefs : 0,
27676 -                                        &fl->fl6_src);
27677 +                                        &fl->fl6_src, sk->sk_nx_info);
27678                 if (err)
27679                         goto out_err_release;
27680         }
27681 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/Kconfig linux-2.6.27.6-vs2.3.0.36/net/ipv6/Kconfig
27682 --- linux-2.6.27.6/net/ipv6/Kconfig     2008-10-13 14:52:09.000000000 +0200
27683 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/Kconfig  2008-10-13 14:54:20.000000000 +0200
27684 @@ -4,8 +4,8 @@
27685  
27686  #   IPv6 as module will cause a CRASH if you try to unload it
27687  menuconfig IPV6
27688 -       tristate "The IPv6 protocol"
27689 -       default m
27690 +       bool "The IPv6 protocol"
27691 +       default n
27692         ---help---
27693           This is complemental support for the IP version 6.
27694           You will still be able to do traditional IPv4 networking as well.
27695 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/ndisc.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/ndisc.c
27696 --- linux-2.6.27.6/net/ipv6/ndisc.c     2008-10-13 14:52:09.000000000 +0200
27697 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/ndisc.c  2008-10-13 14:54:20.000000000 +0200
27698 @@ -551,7 +551,7 @@ static void ndisc_send_na(struct net_dev
27699         } else {
27700                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27701                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27702 -                                      &tmpaddr))
27703 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27704                         return;
27705                 src_addr = &tmpaddr;
27706         }
27707 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/route.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/route.c
27708 --- linux-2.6.27.6/net/ipv6/route.c     2008-10-13 14:52:09.000000000 +0200
27709 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/route.c  2008-10-13 14:54:20.000000000 +0200
27710 @@ -2191,7 +2191,8 @@ static int rt6_fill_node(struct net *net
27711                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27712                 struct in6_addr saddr_buf;
27713                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27714 -                                      dst, 0, &saddr_buf) == 0)
27715 +                       dst, 0, &saddr_buf,
27716 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27717                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27718         }
27719  
27720 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/tcp_ipv6.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/tcp_ipv6.c
27721 --- linux-2.6.27.6/net/ipv6/tcp_ipv6.c  2008-11-17 18:07:35.000000000 +0100
27722 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/tcp_ipv6.c       2008-11-17 18:20:41.000000000 +0100
27723 @@ -67,6 +67,7 @@
27724  
27725  #include <linux/crypto.h>
27726  #include <linux/scatterlist.h>
27727 +#include <linux/vs_inet6.h>
27728  
27729  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27730  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27731 @@ -155,8 +156,15 @@ static int tcp_v6_connect(struct sock *s
27732          *      connect() to INADDR_ANY means loopback (BSD'ism).
27733          */
27734  
27735 -       if(ipv6_addr_any(&usin->sin6_addr))
27736 -               usin->sin6_addr.s6_addr[15] = 0x1;
27737 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27738 +               struct nx_info *nxi =  sk->sk_nx_info;
27739 +
27740 +               if (nxi && nx_info_has_v6(nxi))
27741 +                       /* FIXME: remap lback? */
27742 +                       usin->sin6_addr = nxi->v6.ip;
27743 +               else
27744 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27745 +       }
27746  
27747         addr_type = ipv6_addr_type(&usin->sin6_addr);
27748  
27749 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/udp.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/udp.c
27750 --- linux-2.6.27.6/net/ipv6/udp.c       2008-10-13 14:52:09.000000000 +0200
27751 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/udp.c    2008-10-13 14:54:20.000000000 +0200
27752 @@ -47,6 +47,7 @@
27753  
27754  #include <linux/proc_fs.h>
27755  #include <linux/seq_file.h>
27756 +#include <linux/vs_inet6.h>
27757  #include "udp_impl.h"
27758  
27759  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27760 @@ -81,6 +82,10 @@ static struct sock *__udp6_lib_lookup(st
27761                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27762                                         continue;
27763                                 score++;
27764 +                       } else {
27765 +                               /* block non nx_info ips */
27766 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27767 +                                       continue;
27768                         }
27769                         if (!ipv6_addr_any(&np->daddr)) {
27770                                 if (!ipv6_addr_equal(&np->daddr, saddr))
27771 diff -NurpP --minimal linux-2.6.27.6/net/ipv6/xfrm6_policy.c linux-2.6.27.6-vs2.3.0.36/net/ipv6/xfrm6_policy.c
27772 --- linux-2.6.27.6/net/ipv6/xfrm6_policy.c      2008-10-13 14:52:09.000000000 +0200
27773 +++ linux-2.6.27.6-vs2.3.0.36/net/ipv6/xfrm6_policy.c   2008-10-13 14:54:20.000000000 +0200
27774 @@ -61,7 +61,7 @@ static int xfrm6_get_saddr(xfrm_address_
27775         dev = ip6_dst_idev(dst)->dev;
27776         ipv6_dev_get_saddr(dev_net(dev), dev,
27777                            (struct in6_addr *)&daddr->a6, 0,
27778 -                          (struct in6_addr *)&saddr->a6);
27779 +                          (struct in6_addr *)&saddr->a6, NULL);
27780         dst_release(dst);
27781         return 0;
27782  }
27783 diff -NurpP --minimal linux-2.6.27.6/net/Kconfig linux-2.6.27.6-vs2.3.0.36/net/Kconfig
27784 --- linux-2.6.27.6/net/Kconfig  2008-10-13 14:52:09.000000000 +0200
27785 +++ linux-2.6.27.6-vs2.3.0.36/net/Kconfig       2008-11-20 15:21:32.000000000 +0100
27786 @@ -27,7 +27,7 @@ menu "Networking options"
27787  config NET_NS
27788         bool "Network namespace support"
27789         default n
27790 -       depends on EXPERIMENTAL && !SYSFS && NAMESPACES
27791 +       depends on EXPERIMENTAL && NAMESPACES
27792         help
27793           Allow user space to create what appear to be multiple instances
27794           of the network stack.
27795 diff -NurpP --minimal linux-2.6.27.6/net/netlink/af_netlink.c linux-2.6.27.6-vs2.3.0.36/net/netlink/af_netlink.c
27796 --- linux-2.6.27.6/net/netlink/af_netlink.c     2008-10-13 14:52:09.000000000 +0200
27797 +++ linux-2.6.27.6-vs2.3.0.36/net/netlink/af_netlink.c  2008-10-13 14:54:20.000000000 +0200
27798 @@ -55,6 +55,9 @@
27799  #include <linux/types.h>
27800  #include <linux/audit.h>
27801  #include <linux/mutex.h>
27802 +#include <linux/vs_context.h>
27803 +#include <linux/vs_network.h>
27804 +#include <linux/vs_limit.h>
27805  
27806  #include <net/net_namespace.h>
27807  #include <net/sock.h>
27808 @@ -1761,6 +1764,8 @@ static struct sock *netlink_seq_socket_i
27809                         sk_for_each(s, node, &hash->table[j]) {
27810                                 if (sock_net(s) != seq_file_net(seq))
27811                                         continue;
27812 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27813 +                                       continue;
27814                                 if (off == pos) {
27815                                         iter->link = i;
27816                                         iter->hash_idx = j;
27817 @@ -1795,7 +1800,8 @@ static void *netlink_seq_next(struct seq
27818         s = v;
27819         do {
27820                 s = sk_next(s);
27821 -       } while (s && sock_net(s) != seq_file_net(seq));
27822 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27823 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27824         if (s)
27825                 return s;
27826  
27827 @@ -1807,7 +1813,8 @@ static void *netlink_seq_next(struct seq
27828  
27829                 for (; j <= hash->mask; j++) {
27830                         s = sk_head(&hash->table[j]);
27831 -                       while (s && sock_net(s) != seq_file_net(seq))
27832 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27833 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27834                                 s = sk_next(s);
27835                         if (s) {
27836                                 iter->link = i;
27837 diff -NurpP --minimal linux-2.6.27.6/net/sctp/ipv6.c linux-2.6.27.6-vs2.3.0.36/net/sctp/ipv6.c
27838 --- linux-2.6.27.6/net/sctp/ipv6.c      2008-10-13 14:52:09.000000000 +0200
27839 +++ linux-2.6.27.6-vs2.3.0.36/net/sctp/ipv6.c   2008-10-13 14:54:20.000000000 +0200
27840 @@ -323,7 +323,8 @@ static void sctp_v6_get_saddr(struct sct
27841                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27842                                    &daddr->v6.sin6_addr,
27843                                    inet6_sk(&sk->inet.sk)->srcprefs,
27844 -                                  &saddr->v6.sin6_addr);
27845 +                                  &saddr->v6.sin6_addr,
27846 +                                  asoc->base.sk->sk_nx_info);
27847                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
27848                                   NIP6(saddr->v6.sin6_addr));
27849                 return;
27850 diff -NurpP --minimal linux-2.6.27.6/net/socket.c linux-2.6.27.6-vs2.3.0.36/net/socket.c
27851 --- linux-2.6.27.6/net/socket.c 2008-10-13 14:52:09.000000000 +0200
27852 +++ linux-2.6.27.6-vs2.3.0.36/net/socket.c      2008-10-13 14:54:20.000000000 +0200
27853 @@ -96,6 +96,10 @@
27854  
27855  #include <net/sock.h>
27856  #include <linux/netfilter.h>
27857 +#include <linux/vs_base.h>
27858 +#include <linux/vs_socket.h>
27859 +#include <linux/vs_inet.h>
27860 +#include <linux/vs_inet6.h>
27861  
27862  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27863  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27864 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
27865                                  struct msghdr *msg, size_t size)
27866  {
27867         struct sock_iocb *si = kiocb_to_siocb(iocb);
27868 -       int err;
27869 +       int err, len;
27870  
27871         si->sock = sock;
27872         si->scm = NULL;
27873 @@ -561,7 +565,22 @@ static inline int __sock_sendmsg(struct 
27874         if (err)
27875                 return err;
27876  
27877 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27878 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27879 +       if (sock->sk) {
27880 +               if (len == size)
27881 +                       vx_sock_send(sock->sk, size);
27882 +               else
27883 +                       vx_sock_fail(sock->sk, size);
27884 +       }
27885 +       vxdprintk(VXD_CBIT(net, 7),
27886 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27887 +               sock, sock->sk,
27888 +               (sock->sk)?sock->sk->sk_nx_info:0,
27889 +               (sock->sk)?sock->sk->sk_vx_info:0,
27890 +               (sock->sk)?sock->sk->sk_xid:0,
27891 +               (sock->sk)?sock->sk->sk_nid:0,
27892 +               (unsigned int)size, len);
27893 +       return len;
27894  }
27895  
27896  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27897 @@ -630,7 +649,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27898  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27899                                  struct msghdr *msg, size_t size, int flags)
27900  {
27901 -       int err;
27902 +       int err, len;
27903         struct sock_iocb *si = kiocb_to_siocb(iocb);
27904  
27905         si->sock = sock;
27906 @@ -643,7 +662,18 @@ static inline int __sock_recvmsg(struct 
27907         if (err)
27908                 return err;
27909  
27910 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27911 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27912 +       if ((len >= 0) && sock->sk)
27913 +               vx_sock_recv(sock->sk, len);
27914 +       vxdprintk(VXD_CBIT(net, 7),
27915 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27916 +               sock, sock->sk,
27917 +               (sock->sk)?sock->sk->sk_nx_info:0,
27918 +               (sock->sk)?sock->sk->sk_vx_info:0,
27919 +               (sock->sk)?sock->sk->sk_xid:0,
27920 +               (sock->sk)?sock->sk->sk_nid:0,
27921 +               (unsigned int)size, len);
27922 +       return len;
27923  }
27924  
27925  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27926 @@ -1108,6 +1138,13 @@ static int __sock_create(struct net *net
27927         if (type < 0 || type >= SOCK_MAX)
27928                 return -EINVAL;
27929  
27930 +       if (!nx_check(0, VS_ADMIN)) {
27931 +               if (family == PF_INET && !current_nx_info_has_v4())
27932 +                       return -EAFNOSUPPORT;
27933 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27934 +                       return -EAFNOSUPPORT;
27935 +       }
27936 +
27937         /* Compatibility.
27938  
27939            This uglymoron is moved from INET layer to here to avoid
27940 @@ -1240,6 +1277,7 @@ asmlinkage long sys_socket(int family, i
27941         if (retval < 0)
27942                 goto out;
27943  
27944 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27945         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27946         if (retval < 0)
27947                 goto out_release;
27948 @@ -1281,10 +1319,12 @@ asmlinkage long sys_socketpair(int famil
27949         err = sock_create(family, type, protocol, &sock1);
27950         if (err < 0)
27951                 goto out;
27952 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27953  
27954         err = sock_create(family, type, protocol, &sock2);
27955         if (err < 0)
27956                 goto out_release_1;
27957 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27958  
27959         err = sock1->ops->socketpair(sock1, sock2);
27960         if (err < 0)
27961 diff -NurpP --minimal linux-2.6.27.6/net/sunrpc/auth.c linux-2.6.27.6-vs2.3.0.36/net/sunrpc/auth.c
27962 --- linux-2.6.27.6/net/sunrpc/auth.c    2008-07-13 23:51:29.000000000 +0200
27963 +++ linux-2.6.27.6-vs2.3.0.36/net/sunrpc/auth.c 2008-10-13 14:54:20.000000000 +0200
27964 @@ -14,6 +14,7 @@
27965  #include <linux/hash.h>
27966  #include <linux/sunrpc/clnt.h>
27967  #include <linux/spinlock.h>
27968 +#include <linux/vs_tag.h>
27969  
27970  #ifdef RPC_DEBUG
27971  # define RPCDBG_FACILITY       RPCDBG_AUTH
27972 @@ -353,6 +354,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27973         struct auth_cred acred = {
27974                 .uid = current->fsuid,
27975                 .gid = current->fsgid,
27976 +               .tag = dx_current_tag(),
27977                 .group_info = current->group_info,
27978         };
27979         struct rpc_cred *ret;
27980 @@ -398,6 +400,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27981         struct auth_cred acred = {
27982                 .uid = 0,
27983                 .gid = 0,
27984 +               .tag = dx_current_tag(),
27985         };
27986         struct rpc_cred *ret;
27987  
27988 diff -NurpP --minimal linux-2.6.27.6/net/sunrpc/auth_unix.c linux-2.6.27.6-vs2.3.0.36/net/sunrpc/auth_unix.c
27989 --- linux-2.6.27.6/net/sunrpc/auth_unix.c       2008-10-13 14:52:09.000000000 +0200
27990 +++ linux-2.6.27.6-vs2.3.0.36/net/sunrpc/auth_unix.c    2008-10-13 14:54:20.000000000 +0200
27991 @@ -11,12 +11,14 @@
27992  #include <linux/module.h>
27993  #include <linux/sunrpc/clnt.h>
27994  #include <linux/sunrpc/auth.h>
27995 +#include <linux/vs_tag.h>
27996  
27997  #define NFS_NGROUPS    16
27998  
27999  struct unx_cred {
28000         struct rpc_cred         uc_base;
28001         gid_t                   uc_gid;
28002 +       tag_t                   uc_tag;
28003         gid_t                   uc_gids[NFS_NGROUPS];
28004  };
28005  #define uc_uid                 uc_base.cr_uid
28006 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28007                 groups = NFS_NGROUPS;
28008  
28009         cred->uc_gid = acred->gid;
28010 +       cred->uc_tag = acred->tag;
28011         for (i = 0; i < groups; i++)
28012                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28013         if (i < NFS_NGROUPS)
28014 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28015         unsigned int i;
28016  
28017  
28018 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28019 +       if (cred->uc_uid != acred->uid ||
28020 +               cred->uc_gid != acred->gid ||
28021 +               cred->uc_tag != acred->tag)
28022                 return 0;
28023  
28024         if (acred->group_info != NULL)
28025 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28026         struct rpc_clnt *clnt = task->tk_client;
28027         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28028         __be32          *base, *hold;
28029 -       int             i;
28030 +       int             i, tag;
28031  
28032         *p++ = htonl(RPC_AUTH_UNIX);
28033         base = p++;
28034 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28035          * Copy the UTS nodename captured when the client was created.
28036          */
28037         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28038 +       tag = task->tk_client->cl_tag;
28039  
28040 -       *p++ = htonl((u32) cred->uc_uid);
28041 -       *p++ = htonl((u32) cred->uc_gid);
28042 +       *p++ = htonl((u32) TAGINO_UID(tag,
28043 +               cred->uc_uid, cred->uc_tag));
28044 +       *p++ = htonl((u32) TAGINO_GID(tag,
28045 +               cred->uc_gid, cred->uc_tag));
28046         hold = p++;
28047         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28048                 *p++ = htonl((u32) cred->uc_gids[i]);
28049 diff -NurpP --minimal linux-2.6.27.6/net/sunrpc/clnt.c linux-2.6.27.6-vs2.3.0.36/net/sunrpc/clnt.c
28050 --- linux-2.6.27.6/net/sunrpc/clnt.c    2008-10-13 14:52:09.000000000 +0200
28051 +++ linux-2.6.27.6-vs2.3.0.36/net/sunrpc/clnt.c 2008-10-13 14:54:20.000000000 +0200
28052 @@ -32,6 +32,7 @@
28053  #include <linux/utsname.h>
28054  #include <linux/workqueue.h>
28055  #include <linux/in6.h>
28056 +#include <linux/vs_cvirt.h>
28057  
28058  #include <linux/sunrpc/clnt.h>
28059  #include <linux/sunrpc/rpc_pipe_fs.h>
28060 @@ -327,6 +328,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28061         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28062                 clnt->cl_chatty = 1;
28063  
28064 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28065 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28066 +               clnt->cl_tag = 1; */
28067         return clnt;
28068  }
28069  EXPORT_SYMBOL_GPL(rpc_create);
28070 diff -NurpP --minimal linux-2.6.27.6/net/unix/af_unix.c linux-2.6.27.6-vs2.3.0.36/net/unix/af_unix.c
28071 --- linux-2.6.27.6/net/unix/af_unix.c   2008-11-17 18:07:35.000000000 +0100
28072 +++ linux-2.6.27.6-vs2.3.0.36/net/unix/af_unix.c        2008-11-17 18:20:42.000000000 +0100
28073 @@ -114,6 +114,8 @@
28074  #include <linux/mount.h>
28075  #include <net/checksum.h>
28076  #include <linux/security.h>
28077 +#include <linux/vs_context.h>
28078 +#include <linux/vs_limit.h>
28079  
28080  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28081  static DEFINE_SPINLOCK(unix_table_lock);
28082 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28083                 if (!net_eq(sock_net(s), net))
28084                         continue;
28085  
28086 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28087 +                       continue;
28088                 if (u->addr->len == len &&
28089                     !memcmp(u->addr->name, sunname, len))
28090                         goto found;
28091 @@ -2101,6 +2105,8 @@ static struct sock *unix_seq_idx(struct 
28092         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28093                 if (sock_net(s) != seq_file_net(seq))
28094                         continue;
28095 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28096 +                       continue;
28097                 if (off == pos)
28098                         return s;
28099                 ++off;
28100 @@ -2126,7 +2132,8 @@ static void *unix_seq_next(struct seq_fi
28101                 sk = first_unix_socket(&iter->i);
28102         else
28103                 sk = next_unix_socket(&iter->i, sk);
28104 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28105 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28106 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28107                 sk = next_unix_socket(&iter->i, sk);
28108         return sk;
28109  }
28110 diff -NurpP --minimal linux-2.6.27.6/net/x25/af_x25.c linux-2.6.27.6-vs2.3.0.36/net/x25/af_x25.c
28111 --- linux-2.6.27.6/net/x25/af_x25.c     2008-10-13 14:52:10.000000000 +0200
28112 +++ linux-2.6.27.6-vs2.3.0.36/net/x25/af_x25.c  2008-10-13 14:54:20.000000000 +0200
28113 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
28114  
28115         x25 = x25_sk(sk);
28116  
28117 -       sock_init_data(sock, sk);
28118 +       sk->sk_socket = sock;
28119 +       sk->sk_type = sock->type;
28120 +       sk->sk_sleep = &sock->wait;
28121 +       sock->sk = sk;
28122  
28123         x25_init_timers(sk);
28124  
28125 diff -NurpP --minimal linux-2.6.27.6/scripts/checksyscalls.sh linux-2.6.27.6-vs2.3.0.36/scripts/checksyscalls.sh
28126 --- linux-2.6.27.6/scripts/checksyscalls.sh     2008-07-13 23:51:29.000000000 +0200
28127 +++ linux-2.6.27.6-vs2.3.0.36/scripts/checksyscalls.sh  2008-10-13 14:54:20.000000000 +0200
28128 @@ -108,7 +108,6 @@ cat << EOF
28129  #define __IGNORE_afs_syscall
28130  #define __IGNORE_getpmsg
28131  #define __IGNORE_putpmsg
28132 -#define __IGNORE_vserver
28133  EOF
28134  }
28135  
28136 diff -NurpP --minimal linux-2.6.27.6/security/commoncap.c linux-2.6.27.6-vs2.3.0.36/security/commoncap.c
28137 --- linux-2.6.27.6/security/commoncap.c 2008-11-17 18:07:35.000000000 +0100
28138 +++ linux-2.6.27.6-vs2.3.0.36/security/commoncap.c      2008-11-17 18:20:42.000000000 +0100
28139 @@ -26,10 +26,11 @@
28140  #include <linux/sched.h>
28141  #include <linux/prctl.h>
28142  #include <linux/securebits.h>
28143 +#include <linux/vs_context.h>
28144  
28145  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28146  {
28147 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
28148 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
28149         return 0;
28150  }
28151  
28152 @@ -50,9 +51,24 @@ EXPORT_SYMBOL(cap_netlink_recv);
28153   */
28154  int cap_capable (struct task_struct *tsk, int cap)
28155  {
28156 +       struct vx_info *vxi = tsk->vx_info;
28157 +
28158 +#if 0
28159 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28160 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28161 +               cap_raised(tsk->cap_effective, cap),
28162 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28163 +#endif
28164 +
28165 +       /* special case SETUP */
28166 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28167 +               cap_raised(tsk->cap_effective, cap))
28168 +               return 0;
28169 +
28170         /* Derived from include/linux/sched.h:capable. */
28171 -       if (cap_raised(tsk->cap_effective, cap))
28172 +       if (vx_cap_raised(vxi, tsk->cap_effective, cap))
28173                 return 0;
28174 +
28175         return -EPERM;
28176  }
28177  
28178 @@ -696,7 +712,8 @@ void cap_task_reparent_to_init (struct t
28179  
28180  int cap_syslog (int type)
28181  {
28182 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28183 +       if ((type != 3 && type != 10) &&
28184 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28185                 return -EPERM;
28186         return 0;
28187  }
28188 diff -NurpP --minimal linux-2.6.27.6/security/selinux/hooks.c linux-2.6.27.6-vs2.3.0.36/security/selinux/hooks.c
28189 --- linux-2.6.27.6/security/selinux/hooks.c     2008-10-13 14:52:10.000000000 +0200
28190 +++ linux-2.6.27.6-vs2.3.0.36/security/selinux/hooks.c  2008-10-13 14:54:20.000000000 +0200
28191 @@ -64,7 +64,6 @@
28192  #include <linux/dccp.h>
28193  #include <linux/quota.h>
28194  #include <linux/un.h>          /* for Unix socket types */
28195 -#include <net/af_unix.h>       /* for Unix socket types */
28196  #include <linux/parser.h>
28197  #include <linux/nfs_mount.h>
28198  #include <net/ipv6.h>
This page took 3.274367 seconds and 3 git commands to generate.