]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.3.patch
- up to 2.6.17.28
[packages/kernel.git] / linux-2.6-vs2.3.patch
1 diff -NurpP --minimal linux-2.6.27.14/arch/alpha/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/Kconfig
2 --- linux-2.6.27.14/arch/alpha/Kconfig  2008-10-13 14:51:51.000000000 +0200
3 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/alpha/kernel/entry.S linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/entry.S
14 --- linux-2.6.27.14/arch/alpha/kernel/entry.S   2009-02-03 17:59:54.000000000 +0100
15 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/entry.S      2009-02-03 17:59:04.000000000 +0100
16 @@ -872,24 +872,15 @@ sys_getxgid:
17         .globl  sys_getxpid
18         .ent    sys_getxpid
19  sys_getxpid:
20 +       lda     $sp, -16($sp)
21 +       stq     $26, 0($sp)
22         .prologue 0
23 -       ldq     $2, TI_TASK($8)
24  
25 -       /* See linux/kernel/timer.c sys_getppid for discussion
26 -          about this loop.  */
27 -       ldq     $3, TASK_GROUP_LEADER($2)
28 -       ldq     $4, TASK_REAL_PARENT($3)
29 -       ldl     $0, TASK_TGID($2)
30 -1:     ldl     $1, TASK_TGID($4)
31 -#ifdef CONFIG_SMP
32 -       mov     $4, $5
33 -       mb
34 -       ldq     $3, TASK_GROUP_LEADER($2)
35 -       ldq     $4, TASK_REAL_PARENT($3)
36 -       cmpeq   $4, $5, $5
37 -       beq     $5, 1b
38 -#endif
39 -       stq     $1, 80($sp)
40 +       lda     $16, 96($sp)
41 +       jsr     $26, do_getxpid
42 +       ldq     $26, 0($sp)
43 +
44 +       lda     $sp, 16($sp)
45         ret
46  .end sys_getxpid
47  
48 diff -NurpP --minimal linux-2.6.27.14/arch/alpha/kernel/osf_sys.c linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.27.14/arch/alpha/kernel/osf_sys.c 2008-10-13 14:51:51.000000000 +0200
50 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/alpha/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.27.14/arch/alpha/kernel/ptrace.c  2008-07-13 23:51:29.000000000 +0200
62 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/alpha/kernel/systbls.S linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/systbls.S
72 --- linux-2.6.27.14/arch/alpha/kernel/systbls.S 2009-02-03 17:59:54.000000000 +0100
73 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/systbls.S    2009-02-03 17:59:04.000000000 +0100
74 @@ -446,7 +446,7 @@ sys_call_table:
75         .quad sys_stat64                        /* 425 */
76         .quad sys_lstat64
77         .quad sys_fstat64
78 -       .quad sys_ni_syscall                    /* sys_vserver */
79 +       .quad sys_vserver                       /* sys_vserver */
80         .quad sys_ni_syscall                    /* sys_mbind */
81         .quad sys_ni_syscall                    /* sys_get_mempolicy */
82         .quad sys_ni_syscall                    /* sys_set_mempolicy */
83 diff -NurpP --minimal linux-2.6.27.14/arch/alpha/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/kernel/traps.c
84 --- linux-2.6.27.14/arch/alpha/kernel/traps.c   2008-07-13 23:51:29.000000000 +0200
85 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/alpha/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/alpha/mm/fault.c
97 --- linux-2.6.27.14/arch/alpha/mm/fault.c       2008-07-13 23:51:29.000000000 +0200
98 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/arm/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/arm/Kconfig
111 --- linux-2.6.27.14/arch/arm/Kconfig    2008-10-13 14:51:51.000000000 +0200
112 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/arm/kernel/calls.S linux-2.6.27.14-vs2.3.0.36.4/arch/arm/kernel/calls.S
123 --- linux-2.6.27.14/arch/arm/kernel/calls.S     2009-02-03 17:59:54.000000000 +0100
124 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/arm/kernel/calls.S        2009-02-03 17:59:04.000000000 +0100
125 @@ -322,7 +322,7 @@
126  /* 310 */      CALL(sys_request_key)
127                 CALL(sys_keyctl)
128                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
129 -/* vserver */  CALL(sys_ni_syscall)
130 +               CALL(sys_vserver)
131                 CALL(sys_ioprio_set)
132  /* 315 */      CALL(sys_ioprio_get)
133                 CALL(sys_inotify_init)
134 diff -NurpP --minimal linux-2.6.27.14/arch/arm/kernel/process.c linux-2.6.27.14-vs2.3.0.36.4/arch/arm/kernel/process.c
135 --- linux-2.6.27.14/arch/arm/kernel/process.c   2008-10-13 14:51:52.000000000 +0200
136 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/arm/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/arm/kernel/traps.c
148 --- linux-2.6.27.14/arch/arm/kernel/traps.c     2008-10-13 14:51:52.000000000 +0200
149 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/arm/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/arm/mm/fault.c
162 --- linux-2.6.27.14/arch/arm/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
163 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/cris/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/cris/Kconfig
175 --- linux-2.6.27.14/arch/cris/Kconfig   2008-07-13 23:51:29.000000000 +0200
176 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/frv/kernel/kernel_thread.S linux-2.6.27.14-vs2.3.0.36.4/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.27.14/arch/frv/kernel/kernel_thread.S     2008-07-13 23:51:29.000000000 +0200
188 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/h8300/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/h8300/Kconfig
199 --- linux-2.6.27.14/arch/h8300/Kconfig  2008-10-13 14:51:55.000000000 +0200
200 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/ia64/ia32/ia32_entry.S linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.27.14/arch/ia64/ia32/ia32_entry.S 2009-02-03 17:59:54.000000000 +0100
212 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/ia32/ia32_entry.S    2009-02-03 17:59:04.000000000 +0100
213 @@ -446,7 +446,7 @@ ia32_syscall_table:
214         data8 sys_tgkill        /* 270 */
215         data8 compat_sys_utimes
216         data8 sys32_fadvise64_64
217 -       data8 sys_ni_syscall
218 +       data8 sys32_vserver
219         data8 sys_ni_syscall
220         data8 sys_ni_syscall    /* 275 */
221         data8 sys_ni_syscall
222 diff -NurpP --minimal linux-2.6.27.14/arch/ia64/ia32/sys_ia32.c linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/ia32/sys_ia32.c
223 --- linux-2.6.27.14/arch/ia64/ia32/sys_ia32.c   2008-10-13 14:51:55.000000000 +0200
224 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/ia64/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/Kconfig
235 --- linux-2.6.27.14/arch/ia64/Kconfig   2009-02-03 17:59:54.000000000 +0100
236 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/Kconfig      2009-02-03 17:59:04.000000000 +0100
237 @@ -640,6 +640,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.14/arch/ia64/kernel/entry.S linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/kernel/entry.S
247 --- linux-2.6.27.14/arch/ia64/kernel/entry.S    2009-02-03 17:59:54.000000000 +0100
248 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/kernel/entry.S       2009-02-03 17:59:04.000000000 +0100
249 @@ -1647,7 +1647,7 @@ sys_call_table:
250         data8 sys_mq_notify
251         data8 sys_mq_getsetattr
252         data8 sys_kexec_load
253 -       data8 sys_ni_syscall                    // reserved for vserver
254 +       data8 sys_vserver
255         data8 sys_waitid                        // 1270
256         data8 sys_add_key
257         data8 sys_request_key
258 diff -NurpP --minimal linux-2.6.27.14/arch/ia64/kernel/perfmon.c linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/kernel/perfmon.c
259 --- linux-2.6.27.14/arch/ia64/kernel/perfmon.c  2008-10-13 14:51:55.000000000 +0200
260 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/ia64/kernel/process.c linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/kernel/process.c
279 --- linux-2.6.27.14/arch/ia64/kernel/process.c  2008-10-13 14:51:55.000000000 +0200
280 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/ia64/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/kernel/ptrace.c
293 --- linux-2.6.27.14/arch/ia64/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
294 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/ia64/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/kernel/traps.c
304 --- linux-2.6.27.14/arch/ia64/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
305 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/ia64/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/ia64/mm/fault.c
331 --- linux-2.6.27.14/arch/ia64/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
332 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/m32r/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/m32r/kernel/traps.c
342 --- linux-2.6.27.14/arch/m32r/kernel/traps.c    2008-10-13 14:51:55.000000000 +0200
343 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/m68k/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/m68k/Kconfig
357 --- linux-2.6.27.14/arch/m68k/Kconfig   2008-10-13 14:51:55.000000000 +0200
358 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/m68k/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/m68k/kernel/ptrace.c
369 --- linux-2.6.27.14/arch/m68k/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
370 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/m68k/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/m68k/kernel/traps.c
389 --- linux-2.6.27.14/arch/m68k/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
390 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/m68knommu/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/m68knommu/Kconfig
403 --- linux-2.6.27.14/arch/m68knommu/Kconfig      2008-10-13 14:51:55.000000000 +0200
404 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/m68knommu/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/m68knommu/kernel/traps.c
415 --- linux-2.6.27.14/arch/m68knommu/kernel/traps.c       2008-10-13 14:51:55.000000000 +0200
416 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/mips/Kconfig
430 --- linux-2.6.27.14/arch/mips/Kconfig   2008-10-13 14:51:55.000000000 +0200
431 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/kernel/linux32.c linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/linux32.c
442 --- linux-2.6.27.14/arch/mips/kernel/linux32.c  2008-10-13 14:51:56.000000000 +0200
443 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/ptrace.c
454 --- linux-2.6.27.14/arch/mips/kernel/ptrace.c   2008-10-13 14:51:56.000000000 +0200
455 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/kernel/scall32-o32.S linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/scall32-o32.S
475 --- linux-2.6.27.14/arch/mips/kernel/scall32-o32.S      2009-02-03 17:59:54.000000000 +0100
476 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/scall32-o32.S 2009-02-03 17:59:04.000000000 +0100
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.14/arch/mips/kernel/scall64-64.S linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/scall64-64.S
487 --- linux-2.6.27.14/arch/mips/kernel/scall64-64.S       2008-10-13 14:51:56.000000000 +0200
488 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/kernel/scall64-n32.S linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/scall64-n32.S
499 --- linux-2.6.27.14/arch/mips/kernel/scall64-n32.S      2008-10-13 14:51:56.000000000 +0200
500 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/kernel/scall64-o32.S linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/scall64-o32.S
511 --- linux-2.6.27.14/arch/mips/kernel/scall64-o32.S      2008-10-13 14:51:56.000000000 +0200
512 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/mips/kernel/traps.c
523 --- linux-2.6.27.14/arch/mips/kernel/traps.c    2008-10-13 14:51:56.000000000 +0200
524 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/mips/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/mips/mm/fault.c
540 --- linux-2.6.27.14/arch/mips/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
541 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/parisc/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/parisc/Kconfig
553 --- linux-2.6.27.14/arch/parisc/Kconfig 2008-10-13 14:51:56.000000000 +0200
554 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/parisc/kernel/syscall_table.S linux-2.6.27.14-vs2.3.0.36.4/arch/parisc/kernel/syscall_table.S
565 --- linux-2.6.27.14/arch/parisc/kernel/syscall_table.S  2008-07-13 23:51:29.000000000 +0200
566 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/parisc/kernel/sys_parisc32.c linux-2.6.27.14-vs2.3.0.36.4/arch/parisc/kernel/sys_parisc32.c
577 --- linux-2.6.27.14/arch/parisc/kernel/sys_parisc32.c   2008-07-13 23:51:29.000000000 +0200
578 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/parisc/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/parisc/kernel/traps.c
594 --- linux-2.6.27.14/arch/parisc/kernel/traps.c  2009-02-03 17:59:54.000000000 +0100
595 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/parisc/kernel/traps.c     2009-02-03 17:59:04.000000000 +0100
596 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
597                 if (err == 0)
598                         return; /* STFU */
599  
600 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
601 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
602 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
603 +                       current->comm, task_pid_nr(current), current->xid,
604 +                       str, err, regs->iaoq[0]);
605  #ifdef PRINT_USER_FAULTS
606                 /* XXX for debugging only */
607                 show_regs(regs);
608 @@ -269,8 +270,8 @@ KERN_CRIT "                     ||     |
609                 pdc_console_restart();
610         
611         if (err)
612 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
613 -                       current->comm, task_pid_nr(current), str, err);
614 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
615 +                       current->comm, task_pid_nr(current), current->xid, str, err);
616  
617         /* Wot's wrong wif bein' racy? */
618         if (current->thread.flags & PARISC_KERNEL_DEATH) {
619 diff -NurpP --minimal linux-2.6.27.14/arch/parisc/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/parisc/mm/fault.c
620 --- linux-2.6.27.14/arch/parisc/mm/fault.c      2008-07-13 23:51:29.000000000 +0200
621 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/powerpc/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/Kconfig
645 --- linux-2.6.27.14/arch/powerpc/Kconfig        2009-02-03 17:59:54.000000000 +0100
646 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/Kconfig   2009-02-03 17:59:04.000000000 +0100
647 @@ -836,6 +836,8 @@ source "lib/Kconfig"
648  
649  source "arch/powerpc/Kconfig.debug"
650  
651 +source "kernel/vserver/Kconfig"
652 +
653  source "security/Kconfig"
654  
655  config KEYS_COMPAT
656 diff -NurpP --minimal linux-2.6.27.14/arch/powerpc/kernel/irq.c linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/kernel/irq.c
657 --- linux-2.6.27.14/arch/powerpc/kernel/irq.c   2008-10-13 14:51:56.000000000 +0200
658 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/powerpc/kernel/process.c linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/kernel/process.c
668 --- linux-2.6.27.14/arch/powerpc/kernel/process.c       2008-10-13 14:51:56.000000000 +0200
669 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/powerpc/kernel/sys_ppc32.c linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/kernel/sys_ppc32.c
683 --- linux-2.6.27.14/arch/powerpc/kernel/sys_ppc32.c     2008-10-13 14:51:56.000000000 +0200
684 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/powerpc/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/kernel/traps.c
695 --- linux-2.6.27.14/arch/powerpc/kernel/traps.c 2008-10-13 14:51:56.000000000 +0200
696 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/powerpc/kernel/vdso.c linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/kernel/vdso.c
710 --- linux-2.6.27.14/arch/powerpc/kernel/vdso.c  2008-10-13 14:51:56.000000000 +0200
711 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/powerpc/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/powerpc/mm/fault.c
721 --- linux-2.6.27.14/arch/powerpc/mm/fault.c     2008-10-13 14:51:56.000000000 +0200
722 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/s390/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/s390/Kconfig
734 --- linux-2.6.27.14/arch/s390/Kconfig   2009-02-03 17:59:54.000000000 +0100
735 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/s390/Kconfig      2009-02-03 17:59:04.000000000 +0100
736 @@ -588,6 +588,8 @@ source "fs/Kconfig"
737  
738  source "arch/s390/Kconfig.debug"
739  
740 +source "kernel/vserver/Kconfig"
741 +
742  source "security/Kconfig"
743  
744  source "crypto/Kconfig"
745 diff -NurpP --minimal linux-2.6.27.14/arch/s390/kernel/compat_linux.c linux-2.6.27.14-vs2.3.0.36.4/arch/s390/kernel/compat_linux.c
746 --- linux-2.6.27.14/arch/s390/kernel/compat_linux.c     2008-07-13 23:51:29.000000000 +0200
747 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/s390/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/s390/kernel/ptrace.c
758 --- linux-2.6.27.14/arch/s390/kernel/ptrace.c   2008-10-13 14:51:57.000000000 +0200
759 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/s390/kernel/syscalls.S linux-2.6.27.14-vs2.3.0.36.4/arch/s390/kernel/syscalls.S
769 --- linux-2.6.27.14/arch/s390/kernel/syscalls.S 2009-02-03 17:59:54.000000000 +0100
770 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/s390/kernel/syscalls.S    2009-02-03 17:59:04.000000000 +0100
771 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
772  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
773  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
774  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
775 -NI_SYSCALL                                                     /* reserved for vserver */
776 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
777  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
778  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
779  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
780 diff -NurpP --minimal linux-2.6.27.14/arch/s390/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/s390/mm/fault.c
781 --- linux-2.6.27.14/arch/s390/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
782 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sh/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/sh/Kconfig
794 --- linux-2.6.27.14/arch/sh/Kconfig     2008-10-13 14:51:57.000000000 +0200
795 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sh/kernel/irq.c linux-2.6.27.14-vs2.3.0.36.4/arch/sh/kernel/irq.c
806 --- linux-2.6.27.14/arch/sh/kernel/irq.c        2008-10-13 14:51:57.000000000 +0200
807 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.27.14-vs2.3.0.36.4/arch/sh/kernel/vsyscall/vsyscall.c
817 --- linux-2.6.27.14/arch/sh/kernel/vsyscall/vsyscall.c  2008-07-13 23:51:29.000000000 +0200
818 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/sparc/Kconfig
828 --- linux-2.6.27.14/arch/sparc/Kconfig  2008-10-13 14:51:58.000000000 +0200
829 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc/kernel/ptrace.c
840 --- linux-2.6.27.14/arch/sparc/kernel/ptrace.c  2008-10-13 14:51:58.000000000 +0200
841 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc/kernel/systbls.S linux-2.6.27.14-vs2.3.0.36.4/arch/sparc/kernel/systbls.S
851 --- linux-2.6.27.14/arch/sparc/kernel/systbls.S 2009-02-03 17:59:54.000000000 +0100
852 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/sparc/kernel/systbls.S    2009-02-03 17:59:04.000000000 +0100
853 @@ -70,7 +70,7 @@ sys_call_table:
854  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
855  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
856  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
857 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
858 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
859  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
860  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
861  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
862 diff -NurpP --minimal linux-2.6.27.14/arch/sparc/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc/kernel/traps.c
863 --- linux-2.6.27.14/arch/sparc/kernel/traps.c   2008-10-13 14:51:58.000000000 +0200
864 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc/mm/fault.c
876 --- linux-2.6.27.14/arch/sparc/mm/fault.c       2008-10-13 14:51:58.000000000 +0200
877 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc64/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/Kconfig
889 --- linux-2.6.27.14/arch/sparc64/Kconfig        2008-10-13 14:51:58.000000000 +0200
890 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc64/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/kernel/ptrace.c
901 --- linux-2.6.27.14/arch/sparc64/kernel/ptrace.c        2009-02-03 17:59:54.000000000 +0100
902 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/kernel/ptrace.c   2009-02-03 17:59:04.000000000 +0100
903 @@ -26,6 +26,7 @@
904  #include <linux/tracehook.h>
905  #include <linux/compat.h>
906  #include <linux/elf.h>
907 +#include <linux/vs_base.h>
908  
909  #include <asm/asi.h>
910  #include <asm/pgtable.h>
911 diff -NurpP --minimal linux-2.6.27.14/arch/sparc64/kernel/sys_sparc32.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/kernel/sys_sparc32.c
912 --- linux-2.6.27.14/arch/sparc64/kernel/sys_sparc32.c   2008-10-13 14:51:58.000000000 +0200
913 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc64/kernel/systbls.S linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/kernel/systbls.S
924 --- linux-2.6.27.14/arch/sparc64/kernel/systbls.S       2009-02-03 17:59:54.000000000 +0100
925 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/kernel/systbls.S  2009-02-03 17:59:04.000000000 +0100
926 @@ -71,7 +71,7 @@ sys_call_table32:
927  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
928         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
929  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
930 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
931 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
932  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
933         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
934  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
935 @@ -145,7 +145,7 @@ sys_call_table:
936  /*250*/        .word 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.14/arch/sparc64/kernel/traps.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/kernel/traps.c
945 --- linux-2.6.27.14/arch/sparc64/kernel/traps.c 2008-10-13 14:51:58.000000000 +0200
946 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/sparc64/mm/fault.c linux-2.6.27.14-vs2.3.0.36.4/arch/sparc64/mm/fault.c
958 --- linux-2.6.27.14/arch/sparc64/mm/fault.c     2008-10-13 14:51:58.000000000 +0200
959 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/um/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/um/Kconfig
971 --- linux-2.6.27.14/arch/um/Kconfig     2008-07-13 23:51:29.000000000 +0200
972 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/um/kernel/trap.c linux-2.6.27.14-vs2.3.0.36.4/arch/um/kernel/trap.c
983 --- linux-2.6.27.14/arch/um/kernel/trap.c       2008-07-13 23:51:29.000000000 +0200
984 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/x86/ia32/ia32entry.S linux-2.6.27.14-vs2.3.0.36.4/arch/x86/ia32/ia32entry.S
996 --- linux-2.6.27.14/arch/x86/ia32/ia32entry.S   2008-10-13 14:51:58.000000000 +0200
997 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/arch/x86/Kconfig linux-2.6.27.14-vs2.3.0.36.4/arch/x86/Kconfig
1008 --- linux-2.6.27.14/arch/x86/Kconfig    2009-02-03 17:59:54.000000000 +0100
1009 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/x86/Kconfig       2009-02-03 17:59:04.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.14/arch/x86/kernel/syscall_table_32.S linux-2.6.27.14-vs2.3.0.36.4/arch/x86/kernel/syscall_table_32.S
1020 --- linux-2.6.27.14/arch/x86/kernel/syscall_table_32.S  2009-02-03 17:59:54.000000000 +0100
1021 +++ linux-2.6.27.14-vs2.3.0.36.4/arch/x86/kernel/syscall_table_32.S     2009-02-03 17:59:04.000000000 +0100
1022 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1023         .long sys_tgkill        /* 270 */
1024         .long sys_utimes
1025         .long sys_fadvise64_64
1026 -       .long sys_ni_syscall    /* sys_vserver */
1027 +       .long sys_vserver
1028         .long sys_mbind
1029         .long sys_get_mempolicy
1030         .long sys_set_mempolicy
1031 diff -NurpP --minimal linux-2.6.27.14/Documentation/vserver/debug.txt linux-2.6.27.14-vs2.3.0.36.4/Documentation/vserver/debug.txt
1032 --- linux-2.6.27.14/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
1033 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/block/Kconfig linux-2.6.27.14-vs2.3.0.36.4/drivers/block/Kconfig
1190 --- linux-2.6.27.14/drivers/block/Kconfig       2008-10-13 14:51:59.000000000 +0200
1191 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/block/loop.c linux-2.6.27.14-vs2.3.0.36.4/drivers/block/loop.c
1207 --- linux-2.6.27.14/drivers/block/loop.c        2008-07-13 23:51:29.000000000 +0200
1208 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/block/Makefile linux-2.6.27.14-vs2.3.0.36.4/drivers/block/Makefile
1263 --- linux-2.6.27.14/drivers/block/Makefile      2008-10-13 14:51:59.000000000 +0200
1264 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/block/vroot.c linux-2.6.27.14-vs2.3.0.36.4/drivers/block/vroot.c
1273 --- linux-2.6.27.14/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
1274 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/char/sysrq.c linux-2.6.27.14-vs2.3.0.36.4/drivers/char/sysrq.c
1560 --- linux-2.6.27.14/drivers/char/sysrq.c        2008-10-13 14:51:59.000000000 +0200
1561 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/char/tty_io.c linux-2.6.27.14-vs2.3.0.36.4/drivers/char/tty_io.c
1615 --- linux-2.6.27.14/drivers/char/tty_io.c       2009-02-03 17:59:54.000000000 +0100
1616 +++ linux-2.6.27.14-vs2.3.0.36.4/drivers/char/tty_io.c  2009-02-03 17:59:04.000000000 +0100
1617 @@ -106,6 +106,7 @@
1618  
1619  #include <linux/kmod.h>
1620  #include <linux/nsproxy.h>
1621 +#include <linux/vs_pid.h>
1622  
1623  #undef TTY_DEBUG_HANGUP
1624  
1625 @@ -2770,6 +2771,7 @@ static int tiocspgrp(struct tty_struct *
1626                 return -ENOTTY;
1627         if (get_user(pgrp_nr, p))
1628                 return -EFAULT;
1629 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1630         if (pgrp_nr < 0)
1631                 return -EINVAL;
1632         rcu_read_lock();
1633 diff -NurpP --minimal linux-2.6.27.14/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.27.14-vs2.3.0.36.4/drivers/infiniband/hw/ipath/ipath_user_pages.c
1634 --- linux-2.6.27.14/drivers/infiniband/hw/ipath/ipath_user_pages.c      2008-07-13 23:51:29.000000000 +0200
1635 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/md/dm.c linux-2.6.27.14-vs2.3.0.36.4/drivers/md/dm.c
1682 --- linux-2.6.27.14/drivers/md/dm.c     2008-10-13 14:52:01.000000000 +0200
1683 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/md/dm.h linux-2.6.27.14-vs2.3.0.36.4/drivers/md/dm.h
1758 --- linux-2.6.27.14/drivers/md/dm.h     2008-10-13 14:52:01.000000000 +0200
1759 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/md/dm-ioctl.c linux-2.6.27.14-vs2.3.0.36.4/drivers/md/dm-ioctl.c
1770 --- linux-2.6.27.14/drivers/md/dm-ioctl.c       2008-07-13 23:51:29.000000000 +0200
1771 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/drivers/net/tun.c linux-2.6.27.14-vs2.3.0.36.4/drivers/net/tun.c
1854 --- linux-2.6.27.14/drivers/net/tun.c   2008-10-13 14:52:02.000000000 +0200
1855 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/attr.c linux-2.6.27.14-vs2.3.0.36.4/fs/attr.c
1926 --- linux-2.6.27.14/fs/attr.c   2008-10-13 14:52:05.000000000 +0200
1927 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/binfmt_aout.c linux-2.6.27.14-vs2.3.0.36.4/fs/binfmt_aout.c
1969 --- linux-2.6.27.14/fs/binfmt_aout.c    2008-10-13 14:52:05.000000000 +0200
1970 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/binfmt_elf.c linux-2.6.27.14-vs2.3.0.36.4/fs/binfmt_elf.c
1980 --- linux-2.6.27.14/fs/binfmt_elf.c     2008-10-13 14:52:05.000000000 +0200
1981 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/binfmt_flat.c linux-2.6.27.14-vs2.3.0.36.4/fs/binfmt_flat.c
1991 --- linux-2.6.27.14/fs/binfmt_flat.c    2008-10-13 14:52:05.000000000 +0200
1992 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/binfmt_som.c linux-2.6.27.14-vs2.3.0.36.4/fs/binfmt_som.c
2002 --- linux-2.6.27.14/fs/binfmt_som.c     2008-10-13 14:52:05.000000000 +0200
2003 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/block_dev.c linux-2.6.27.14-vs2.3.0.36.4/fs/block_dev.c
2013 --- linux-2.6.27.14/fs/block_dev.c      2008-10-13 14:52:05.000000000 +0200
2014 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/char_dev.c linux-2.6.27.14-vs2.3.0.36.4/fs/char_dev.c
2053 --- linux-2.6.27.14/fs/char_dev.c       2008-10-13 14:52:05.000000000 +0200
2054 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/dcache.c linux-2.6.27.14-vs2.3.0.36.4/fs/dcache.c
2088 --- linux-2.6.27.14/fs/dcache.c 2009-02-03 17:59:55.000000000 +0100
2089 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/dcache.c    2009-02-03 17:59:04.000000000 +0100
2090 @@ -32,6 +32,7 @@
2091  #include <linux/seqlock.h>
2092  #include <linux/swap.h>
2093  #include <linux/bootmem.h>
2094 +#include <linux/vs_limit.h>
2095  #include "internal.h"
2096  
2097  
2098 @@ -226,6 +227,8 @@ repeat:
2099                 return;
2100         }
2101  
2102 +       vx_dentry_dec(dentry);
2103 +
2104         /*
2105          * AV: ->d_delete() is _NOT_ allowed to block now.
2106          */
2107 @@ -317,6 +320,7 @@ static inline struct dentry * __dget_loc
2108  {
2109         atomic_inc(&dentry->d_count);
2110         dentry_lru_del_init(dentry);
2111 +       vx_dentry_inc(dentry);
2112         return dentry;
2113  }
2114  
2115 @@ -914,6 +918,9 @@ struct dentry *d_alloc(struct dentry * p
2116         struct dentry *dentry;
2117         char *dname;
2118  
2119 +       if (!vx_dentry_avail(1))
2120 +               return NULL;
2121 +
2122         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2123         if (!dentry)
2124                 return NULL;
2125 @@ -962,6 +969,7 @@ struct dentry *d_alloc(struct dentry * p
2126         if (parent)
2127                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2128         dentry_stat.nr_dentry++;
2129 +       vx_dentry_inc(dentry);
2130         spin_unlock(&dcache_lock);
2131  
2132         return dentry;
2133 @@ -1415,6 +1423,7 @@ struct dentry * __d_lookup(struct dentry
2134                 }
2135  
2136                 atomic_inc(&dentry->d_count);
2137 +               vx_dentry_inc(dentry);
2138                 found = dentry;
2139                 spin_unlock(&dentry->d_lock);
2140                 break;
2141 diff -NurpP --minimal linux-2.6.27.14/fs/devpts/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/devpts/inode.c
2142 --- linux-2.6.27.14/fs/devpts/inode.c   2008-10-13 14:52:05.000000000 +0200
2143 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/exec.c linux-2.6.27.14-vs2.3.0.36.4/fs/exec.c
2225 --- linux-2.6.27.14/fs/exec.c   2009-02-03 17:59:55.000000000 +0100
2226 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/exec.c      2009-02-03 17:59:04.000000000 +0100
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 @@ -1461,7 +1463,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.14/fs/ext2/balloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/balloc.c
2248 --- linux-2.6.27.14/fs/ext2/balloc.c    2009-02-03 17:59:55.000000000 +0100
2249 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/balloc.c       2009-02-03 17:59:04.000000000 +0100
2250 @@ -16,6 +16,8 @@
2251  #include <linux/sched.h>
2252  #include <linux/buffer_head.h>
2253  #include <linux/capability.h>
2254 +#include <linux/vs_dlimit.h>
2255 +#include <linux/vs_tag.h>
2256  
2257  /*
2258   * balloc.c contains the blocks allocation and deallocation routines
2259 @@ -569,6 +571,7 @@ do_more:
2260         }
2261  error_return:
2262         brelse(bitmap_bh);
2263 +       DLIMIT_FREE_BLOCK(inode, freed);
2264         release_blocks(sb, freed);
2265         DQUOT_FREE_BLOCK(inode, freed);
2266  }
2267 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2268                         start = 0;
2269                 end = EXT2_BLOCKS_PER_GROUP(sb);
2270         }
2271 -
2272         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2273  
2274  repeat:
2275 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2276                 *errp = -EDQUOT;
2277                 return 0;
2278         }
2279 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2280 +               *errp = -ENOSPC;
2281 +               DQUOT_FREE_BLOCK(inode, num);
2282 +               return 0;
2283 +       }
2284  
2285         sbi = EXT2_SB(sb);
2286         es = EXT2_SB(sb)->s_es;
2287 @@ -1409,6 +1416,7 @@ allocated:
2288  
2289         *errp = 0;
2290         brelse(bitmap_bh);
2291 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2292         DQUOT_FREE_BLOCK(inode, *count-num);
2293         *count = num;
2294         return ret_block;
2295 @@ -1419,8 +1427,10 @@ out:
2296         /*
2297          * Undo the block allocation
2298          */
2299 -       if (!performed_allocation)
2300 +       if (!performed_allocation) {
2301 +               DLIMIT_FREE_BLOCK(inode, *count);
2302                 DQUOT_FREE_BLOCK(inode, *count);
2303 +       }
2304         brelse(bitmap_bh);
2305         return 0;
2306  }
2307 diff -NurpP --minimal linux-2.6.27.14/fs/ext2/ext2.h linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/ext2.h
2308 --- linux-2.6.27.14/fs/ext2/ext2.h      2008-07-13 23:51:29.000000000 +0200
2309 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/file.c
2319 --- linux-2.6.27.14/fs/ext2/file.c      2008-07-13 23:51:29.000000000 +0200
2320 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/ialloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/ialloc.c
2328 --- linux-2.6.27.14/fs/ext2/ialloc.c    2008-07-13 23:51:29.000000000 +0200
2329 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/inode.c
2386 --- linux-2.6.27.14/fs/ext2/inode.c     2008-10-13 14:52:05.000000000 +0200
2387 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/ioctl.c
2548 --- linux-2.6.27.14/fs/ext2/ioctl.c     2008-07-13 23:51:29.000000000 +0200
2549 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/namei.c
2582 --- linux-2.6.27.14/fs/ext2/namei.c     2008-07-13 23:51:29.000000000 +0200
2583 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/super.c
2615 --- linux-2.6.27.14/fs/ext2/super.c     2008-10-13 14:52:05.000000000 +0200
2616 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/symlink.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/symlink.c
2682 --- linux-2.6.27.14/fs/ext2/symlink.c   2008-07-13 23:51:29.000000000 +0200
2683 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext2/xattr.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext2/xattr.c
2699 --- linux-2.6.27.14/fs/ext2/xattr.c     2008-07-13 23:51:29.000000000 +0200
2700 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext3/balloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/balloc.c
2739 --- linux-2.6.27.14/fs/ext3/balloc.c    2009-02-03 17:59:55.000000000 +0100
2740 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/balloc.c       2009-02-03 17:59:04.000000000 +0100
2741 @@ -19,6 +19,8 @@
2742  #include <linux/ext3_jbd.h>
2743  #include <linux/quotaops.h>
2744  #include <linux/buffer_head.h>
2745 +#include <linux/vs_dlimit.h>
2746 +#include <linux/vs_tag.h>
2747  
2748  /*
2749   * balloc.c contains the blocks allocation and deallocation routines
2750 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2751                 return;
2752         }
2753         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2754 -       if (dquot_freed_blocks)
2755 +       if (dquot_freed_blocks) {
2756 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2757                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2758 +       }
2759         return;
2760  }
2761  
2762 @@ -1415,18 +1419,33 @@ out:
2763   *
2764   * Check if filesystem has at least 1 free block available for allocation.
2765   */
2766 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2767 +static int ext3_has_free_blocks(struct super_block *sb)
2768  {
2769 -       ext3_fsblk_t free_blocks, root_blocks;
2770 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2771 +       unsigned long long free_blocks, root_blocks;
2772 +       int cond;
2773  
2774         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2775         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2776 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2777 +
2778 +       vxdprintk(VXD_CBIT(dlim, 3),
2779 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2780 +               sb, free_blocks, root_blocks);
2781 +
2782 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2783 +
2784 +       cond = (free_blocks < root_blocks + 1 &&
2785 +               !capable(CAP_SYS_RESOURCE) &&
2786                 sbi->s_resuid != current->fsuid &&
2787 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2788 -               return 0;
2789 -       }
2790 -       return 1;
2791 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2792 +
2793 +       vxdprintk(VXD_CBIT(dlim, 3),
2794 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2795 +               sb, free_blocks, root_blocks,
2796 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2797 +               sbi->s_resuid, current->fsuid, cond?0:1);
2798 +
2799 +       return (cond ? 0 : 1);
2800  }
2801  
2802  /**
2803 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2804   */
2805  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2806  {
2807 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2808 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2809                 return 0;
2810  
2811         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2812 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2813                 *errp = -EDQUOT;
2814                 return 0;
2815         }
2816 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2817 +           goto out_dlimit;
2818  
2819         sbi = EXT3_SB(sb);
2820         es = EXT3_SB(sb)->s_es;
2821 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2822         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2823                 my_rsv = &block_i->rsv_window_node;
2824  
2825 -       if (!ext3_has_free_blocks(sbi)) {
2826 +       if (!ext3_has_free_blocks(sb)) {
2827                 *errp = -ENOSPC;
2828                 goto out;
2829         }
2830 @@ -1715,12 +1736,16 @@ allocated:
2831         *errp = 0;
2832         brelse(bitmap_bh);
2833         DQUOT_FREE_BLOCK(inode, *count-num);
2834 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2835         *count = num;
2836         return ret_block;
2837  
2838  io_error:
2839         *errp = -EIO;
2840  out:
2841 +       if (!performed_allocation)
2842 +               DLIMIT_FREE_BLOCK(inode, *count);
2843 +out_dlimit:
2844         if (fatal) {
2845                 *errp = fatal;
2846                 ext3_std_error(sb, fatal);
2847 diff -NurpP --minimal linux-2.6.27.14/fs/ext3/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/file.c
2848 --- linux-2.6.27.14/fs/ext3/file.c      2008-07-13 23:51:29.000000000 +0200
2849 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext3/ialloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/ialloc.c
2858 --- linux-2.6.27.14/fs/ext3/ialloc.c    2008-10-13 14:52:05.000000000 +0200
2859 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext3/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/inode.c
2918 --- linux-2.6.27.14/fs/ext3/inode.c     2009-02-03 17:59:55.000000000 +0100
2919 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/inode.c        2009-02-03 17:59:04.000000000 +0100
2920 @@ -36,6 +36,7 @@
2921  #include <linux/mpage.h>
2922  #include <linux/uio.h>
2923  #include <linux/bio.h>
2924 +#include <linux/vs_tag.h>
2925  #include "xattr.h"
2926  #include "acl.h"
2927  
2928 @@ -2272,7 +2273,7 @@ static void ext3_free_branches(handle_t 
2929  
2930  int ext3_can_truncate(struct inode *inode)
2931  {
2932 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2933 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2934                 return 0;
2935         if (S_ISREG(inode->i_mode))
2936                 return 1;
2937 @@ -2646,36 +2647,84 @@ void ext3_set_inode_flags(struct inode *
2938  {
2939         unsigned int flags = EXT3_I(inode)->i_flags;
2940  
2941 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2942 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2943 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2944 +
2945 +       if (flags & EXT3_IMMUTABLE_FL)
2946 +               inode->i_flags |= S_IMMUTABLE;
2947 +       if (flags & EXT3_IXUNLINK_FL)
2948 +               inode->i_flags |= S_IXUNLINK;
2949 +
2950         if (flags & EXT3_SYNC_FL)
2951                 inode->i_flags |= S_SYNC;
2952         if (flags & EXT3_APPEND_FL)
2953                 inode->i_flags |= S_APPEND;
2954 -       if (flags & EXT3_IMMUTABLE_FL)
2955 -               inode->i_flags |= S_IMMUTABLE;
2956         if (flags & EXT3_NOATIME_FL)
2957                 inode->i_flags |= S_NOATIME;
2958         if (flags & EXT3_DIRSYNC_FL)
2959                 inode->i_flags |= S_DIRSYNC;
2960 +
2961 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2962 +
2963 +       if (flags & EXT3_BARRIER_FL)
2964 +               inode->i_vflags |= V_BARRIER;
2965 +       if (flags & EXT3_COW_FL)
2966 +               inode->i_vflags |= V_COW;
2967  }
2968  
2969  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2970  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2971  {
2972         unsigned int flags = ei->vfs_inode.i_flags;
2973 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2974 +
2975 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2976 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2977 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2978 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2979 +
2980 +       if (flags & S_IMMUTABLE)
2981 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2982 +       if (flags & S_IXUNLINK)
2983 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2984  
2985 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2986 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2987         if (flags & S_SYNC)
2988                 ei->i_flags |= EXT3_SYNC_FL;
2989         if (flags & S_APPEND)
2990                 ei->i_flags |= EXT3_APPEND_FL;
2991 -       if (flags & S_IMMUTABLE)
2992 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2993         if (flags & S_NOATIME)
2994                 ei->i_flags |= EXT3_NOATIME_FL;
2995         if (flags & S_DIRSYNC)
2996                 ei->i_flags |= EXT3_DIRSYNC_FL;
2997 +
2998 +       if (vflags & V_BARRIER)
2999 +               ei->i_flags |= EXT3_BARRIER_FL;
3000 +       if (vflags & V_COW)
3001 +               ei->i_flags |= EXT3_COW_FL;
3002 +}
3003 +
3004 +int ext3_sync_flags(struct inode *inode)
3005 +{
3006 +       struct ext3_iloc iloc;
3007 +       handle_t *handle;
3008 +       int err;
3009 +
3010 +       handle = ext3_journal_start(inode, 1);
3011 +       if (IS_ERR(handle))
3012 +               return PTR_ERR(handle);
3013 +       if (IS_SYNC(inode))
3014 +               handle->h_sync = 1;
3015 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3016 +       if (err)
3017 +               goto flags_err;
3018 +
3019 +       ext3_get_inode_flags(EXT3_I(inode));
3020 +       inode->i_ctime = CURRENT_TIME;
3021 +
3022 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3023 +flags_err:
3024 +       ext3_journal_stop(handle);
3025 +       return err;
3026  }
3027  
3028  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3029 @@ -2687,6 +2736,8 @@ struct inode *ext3_iget(struct super_blo
3030         struct inode *inode;
3031         long ret;
3032         int block;
3033 +       uid_t uid;
3034 +       gid_t gid;
3035  
3036         inode = iget_locked(sb, ino);
3037         if (!inode)
3038 @@ -2707,12 +2758,17 @@ struct inode *ext3_iget(struct super_blo
3039         bh = iloc.bh;
3040         raw_inode = ext3_raw_inode(&iloc);
3041         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3042 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3043 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3044 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3045 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3046         if(!(test_opt (inode->i_sb, NO_UID32))) {
3047 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3048 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3049 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3050 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3051         }
3052 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3053 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3054 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3055 +               le16_to_cpu(raw_inode->i_raw_tag));
3056 +
3057         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3058         inode->i_size = le32_to_cpu(raw_inode->i_size);
3059         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3060 @@ -2841,6 +2897,8 @@ static int ext3_do_update_inode(handle_t
3061         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3062         struct ext3_inode_info *ei = EXT3_I(inode);
3063         struct buffer_head *bh = iloc->bh;
3064 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3065 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3066         int err = 0, rc, block;
3067  
3068         /* For fields not not tracking in the in-memory inode,
3069 @@ -2851,29 +2909,32 @@ static int ext3_do_update_inode(handle_t
3070         ext3_get_inode_flags(ei);
3071         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3072         if(!(test_opt(inode->i_sb, NO_UID32))) {
3073 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3074 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3075 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3076 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3077  /*
3078   * Fix up interoperability with old kernels. Otherwise, old inodes get
3079   * re-used with the upper 16 bits of the uid/gid intact
3080   */
3081                 if(!ei->i_dtime) {
3082                         raw_inode->i_uid_high =
3083 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3084 +                               cpu_to_le16(high_16_bits(uid));
3085                         raw_inode->i_gid_high =
3086 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3087 +                               cpu_to_le16(high_16_bits(gid));
3088                 } else {
3089                         raw_inode->i_uid_high = 0;
3090                         raw_inode->i_gid_high = 0;
3091                 }
3092         } else {
3093                 raw_inode->i_uid_low =
3094 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3095 +                       cpu_to_le16(fs_high2lowuid(uid));
3096                 raw_inode->i_gid_low =
3097 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3098 +                       cpu_to_le16(fs_high2lowgid(gid));
3099                 raw_inode->i_uid_high = 0;
3100                 raw_inode->i_gid_high = 0;
3101         }
3102 +#ifdef CONFIG_TAGGING_INTERN
3103 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3104 +#endif
3105         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3106         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3107         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3108 @@ -3026,7 +3087,8 @@ int ext3_setattr(struct dentry *dentry, 
3109                 return error;
3110  
3111         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3112 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3113 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3114 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3115                 handle_t *handle;
3116  
3117                 /* (user+group)*(old+new) structure, inode write (sb,
3118 @@ -3048,6 +3110,8 @@ int ext3_setattr(struct dentry *dentry, 
3119                         inode->i_uid = attr->ia_uid;
3120                 if (attr->ia_valid & ATTR_GID)
3121                         inode->i_gid = attr->ia_gid;
3122 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3123 +                       inode->i_tag = attr->ia_tag;
3124                 error = ext3_mark_inode_dirty(handle, inode);
3125                 ext3_journal_stop(handle);
3126         }
3127 diff -NurpP --minimal linux-2.6.27.14/fs/ext3/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/ioctl.c
3128 --- linux-2.6.27.14/fs/ext3/ioctl.c     2008-07-13 23:51:29.000000000 +0200
3129 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext3/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/namei.c
3170 --- linux-2.6.27.14/fs/ext3/namei.c     2009-02-03 17:59:55.000000000 +0100
3171 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/namei.c        2009-02-03 18:03:38.000000000 +0100
3172 @@ -36,6 +36,7 @@
3173  #include <linux/quotaops.h>
3174  #include <linux/buffer_head.h>
3175  #include <linux/bio.h>
3176 +#include <linux/vs_tag.h>
3177  
3178  #include "namei.h"
3179  #include "xattr.h"
3180 @@ -912,6 +913,7 @@ restart:
3181                                 if (bh)
3182                                         ll_rw_block(READ_META, 1, &bh);
3183                         }
3184 +               dx_propagate_tag(nd, inode);
3185                 }
3186                 if ((bh = bh_use[ra_ptr++]) == NULL)
3187                         goto next;
3188 @@ -2433,6 +2435,7 @@ const struct inode_operations ext3_dir_i
3189         .removexattr    = generic_removexattr,
3190  #endif
3191         .permission     = ext3_permission,
3192 +       .sync_flags     = ext3_sync_flags,
3193  };
3194  
3195  const struct inode_operations ext3_special_inode_operations = {
3196 @@ -2444,4 +2447,5 @@ const struct inode_operations ext3_speci
3197         .removexattr    = generic_removexattr,
3198  #endif
3199         .permission     = ext3_permission,
3200 +       .sync_flags     = ext3_sync_flags,
3201  };
3202 diff -NurpP --minimal linux-2.6.27.14/fs/ext3/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/super.c
3203 --- linux-2.6.27.14/fs/ext3/super.c     2009-02-03 17:59:55.000000000 +0100
3204 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/super.c        2009-02-03 17:59:04.000000000 +0100
3205 @@ -757,7 +757,7 @@ enum {
3206         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3207         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3208         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3209 -       Opt_grpquota
3210 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3211  };
3212  
3213  static match_table_t tokens = {
3214 @@ -808,6 +808,9 @@ static match_table_t tokens = {
3215         {Opt_usrquota, "usrquota"},
3216         {Opt_barrier, "barrier=%u"},
3217         {Opt_resize, "resize"},
3218 +       {Opt_tag, "tag"},
3219 +       {Opt_notag, "notag"},
3220 +       {Opt_tagid, "tagid=%u"},
3221         {Opt_err, NULL},
3222  };
3223  
3224 @@ -900,6 +903,20 @@ static int parse_options (char *options,
3225                 case Opt_nouid32:
3226                         set_opt (sbi->s_mount_opt, NO_UID32);
3227                         break;
3228 +#ifndef CONFIG_TAGGING_NONE
3229 +               case Opt_tag:
3230 +                       set_opt (sbi->s_mount_opt, TAGGED);
3231 +                       break;
3232 +               case Opt_notag:
3233 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3234 +                       break;
3235 +#endif
3236 +#ifdef CONFIG_PROPAGATE
3237 +               case Opt_tagid:
3238 +                       /* use args[0] */
3239 +                       set_opt (sbi->s_mount_opt, TAGGED);
3240 +                       break;
3241 +#endif
3242                 case Opt_nocheck:
3243                         clear_opt (sbi->s_mount_opt, CHECK);
3244                         break;
3245 @@ -1609,6 +1626,9 @@ static int ext3_fill_super (struct super
3246                             NULL, 0))
3247                 goto failed_mount;
3248  
3249 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3250 +               sb->s_flags |= MS_TAGGED;
3251 +
3252         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3253                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3254  
3255 @@ -2446,6 +2466,13 @@ static int ext3_remount (struct super_bl
3256         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3257                 ext3_abort(sb, __func__, "Abort forced by user");
3258  
3259 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3260 +               !(sb->s_flags & MS_TAGGED)) {
3261 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3262 +                       sb->s_id);
3263 +               return -EINVAL;
3264 +       }
3265 +
3266         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3267                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3268  
3269 diff -NurpP --minimal linux-2.6.27.14/fs/ext3/symlink.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/symlink.c
3270 --- linux-2.6.27.14/fs/ext3/symlink.c   2008-07-13 23:51:29.000000000 +0200
3271 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext3/xattr.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext3/xattr.c
3287 --- linux-2.6.27.14/fs/ext3/xattr.c     2008-07-13 23:51:29.000000000 +0200
3288 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext4/balloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/balloc.c
3331 --- linux-2.6.27.14/fs/ext4/balloc.c    2008-10-13 14:52:05.000000000 +0200
3332 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext4/ext4.h linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/ext4.h
3381 --- linux-2.6.27.14/fs/ext4/ext4.h      2009-02-03 17:59:55.000000000 +0100
3382 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/ext4.h 2009-02-03 17:59:04.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 @@ -541,6 +545,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 @@ -1055,6 +1060,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.14/fs/ext4/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/file.c
3413 --- linux-2.6.27.14/fs/ext4/file.c      2008-10-13 14:52:05.000000000 +0200
3414 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext4/ialloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/ialloc.c
3423 --- linux-2.6.27.14/fs/ext4/ialloc.c    2009-02-03 17:59:55.000000000 +0100
3424 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/ialloc.c       2009-02-03 17:59:04.000000000 +0100
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 @@ -810,7 +819,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 @@ -866,6 +876,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 @@ -877,6 +889,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.14/fs/ext4/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/inode.c
3483 --- linux-2.6.27.14/fs/ext4/inode.c     2009-02-03 17:59:55.000000000 +0100
3484 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/inode.c        2009-02-03 17:59:04.000000000 +0100
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 @@ -3485,7 +3486,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 @@ -3844,37 +3845,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 @@ -3907,6 +3957,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 @@ -3927,12 +3979,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 @@ -4106,6 +4163,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 @@ -4116,29 +4175,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 @@ -4302,7 +4364,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 @@ -4324,6 +4387,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.14/fs/ext4/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/ioctl.c
3695 --- linux-2.6.27.14/fs/ext4/ioctl.c     2009-02-03 17:59:55.000000000 +0100
3696 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/ioctl.c        2009-02-03 17:59:04.000000000 +0100
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.14/fs/ext4/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/namei.c
3736 --- linux-2.6.27.14/fs/ext4/namei.c     2009-02-03 17:59:55.000000000 +0100
3737 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/namei.c        2009-02-03 17:59:04.000000000 +0100
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 @@ -2460,6 +2462,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 @@ -2471,4 +2474,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.14/fs/ext4/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/super.c
3769 --- linux-2.6.27.14/fs/ext4/super.c     2009-02-03 17:59:55.000000000 +0100
3770 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/super.c        2009-02-03 17:59:04.000000000 +0100
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 @@ -2033,6 +2051,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 @@ -3015,6 +3036,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.14/fs/ext4/symlink.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/symlink.c
3835 --- linux-2.6.27.14/fs/ext4/symlink.c   2008-07-13 23:51:29.000000000 +0200
3836 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ext4/xattr.c linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/xattr.c
3852 --- linux-2.6.27.14/fs/ext4/xattr.c     2009-02-03 17:59:55.000000000 +0100
3853 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ext4/xattr.c        2009-02-03 17:59:04.000000000 +0100
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.14/fs/fcntl.c linux-2.6.27.14-vs2.3.0.36.4/fs/fcntl.c
3896 --- linux-2.6.27.14/fs/fcntl.c  2009-02-03 17:59:55.000000000 +0100
3897 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/fcntl.c     2009-02-03 17:59:04.000000000 +0100
3898 @@ -20,6 +20,7 @@
3899  #include <linux/rcupdate.h>
3900  #include <linux/pid_namespace.h>
3901  #include <linux/smp_lock.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  #include <asm/poll.h>
3905  #include <asm/siginfo.h>
3906 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
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 @@ -342,6 +345,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
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.14/fs/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/file.c
3925 --- linux-2.6.27.14/fs/file.c   2008-10-13 14:52:05.000000000 +0200
3926 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/file_table.c linux-2.6.27.14-vs2.3.0.36.4/fs/file_table.c
3953 --- linux-2.6.27.14/fs/file_table.c     2008-10-13 14:52:05.000000000 +0200
3954 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/hfsplus/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/hfsplus/ioctl.c
3992 --- linux-2.6.27.14/fs/hfsplus/ioctl.c  2008-07-13 23:51:29.000000000 +0200
3993 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/inode.c
4003 --- linux-2.6.27.14/fs/inode.c  2008-10-13 14:52:05.000000000 +0200
4004 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/ioctl.c
4045 --- linux-2.6.27.14/fs/ioctl.c  2009-02-03 17:59:55.000000000 +0100
4046 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ioctl.c     2009-02-03 17:59:04.000000000 +0100
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.14/fs/ioprio.c linux-2.6.27.14-vs2.3.0.36.4/fs/ioprio.c
4058 --- linux-2.6.27.14/fs/ioprio.c 2009-02-03 17:59:55.000000000 +0100
4059 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/ioprio.c    2009-02-03 17:59:04.000000000 +0100
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 @@ SYSCALL_DEFINE3(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 @@ SYSCALL_DEFINE2(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.14/fs/jfs/acl.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/acl.c
4087 --- linux-2.6.27.14/fs/jfs/acl.c        2008-10-13 14:52:05.000000000 +0200
4088 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/file.c
4100 --- linux-2.6.27.14/fs/jfs/file.c       2008-07-13 23:51:29.000000000 +0200
4101 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/inode.c
4111 --- linux-2.6.27.14/fs/jfs/inode.c      2008-07-13 23:51:29.000000000 +0200
4112 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/ioctl.c
4130 --- linux-2.6.27.14/fs/jfs/ioctl.c      2008-07-13 23:51:29.000000000 +0200
4131 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_dinode.h linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_dinode.h
4164 --- linux-2.6.27.14/fs/jfs/jfs_dinode.h 2008-07-13 23:51:29.000000000 +0200
4165 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_dtree.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_dtree.c
4183 --- linux-2.6.27.14/fs/jfs/jfs_dtree.c  2008-07-13 23:51:29.000000000 +0200
4184 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_extent.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_extent.c
4297 --- linux-2.6.27.14/fs/jfs/jfs_extent.c 2008-07-13 23:51:29.000000000 +0200
4298 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_filsys.h linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_filsys.h
4361 --- linux-2.6.27.14/fs/jfs/jfs_filsys.h 2008-07-13 23:51:29.000000000 +0200
4362 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_imap.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_imap.c
4372 --- linux-2.6.27.14/fs/jfs/jfs_imap.c   2008-10-13 14:52:05.000000000 +0200
4373 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_inode.c
4434 --- linux-2.6.27.14/fs/jfs/jfs_inode.c  2008-07-13 23:51:29.000000000 +0200
4435 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_inode.h linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_inode.h
4537 --- linux-2.6.27.14/fs/jfs/jfs_inode.h  2008-07-13 23:51:29.000000000 +0200
4538 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/jfs_xtree.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/jfs_xtree.c
4548 --- linux-2.6.27.14/fs/jfs/jfs_xtree.c  2008-10-13 14:52:05.000000000 +0200
4549 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/namei.c
4634 --- linux-2.6.27.14/fs/jfs/namei.c      2008-10-13 14:52:05.000000000 +0200
4635 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/super.c
4661 --- linux-2.6.27.14/fs/jfs/super.c      2008-10-13 14:52:05.000000000 +0200
4662 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/jfs/xattr.c linux-2.6.27.14-vs2.3.0.36.4/fs/jfs/xattr.c
4730 --- linux-2.6.27.14/fs/jfs/xattr.c      2008-07-13 23:51:29.000000000 +0200
4731 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/libfs.c linux-2.6.27.14-vs2.3.0.36.4/fs/libfs.c
4810 --- linux-2.6.27.14/fs/libfs.c  2009-02-03 17:59:55.000000000 +0100
4811 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/libfs.c     2009-02-03 17:59:04.000000000 +0100
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.14/fs/locks.c linux-2.6.27.14-vs2.3.0.36.4/fs/locks.c
4859 --- linux-2.6.27.14/fs/locks.c  2009-02-03 17:59:55.000000000 +0100
4860 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/locks.c     2009-02-03 17:59:04.000000000 +0100
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.14/fs/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/namei.c
5047 --- linux-2.6.27.14/fs/namei.c  2009-02-03 17:59:55.000000000 +0100
5048 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/namei.c     2009-02-03 17:59:04.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 @@ -2755,6 +2895,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.14/fs/namespace.c linux-2.6.27.14-vs2.3.0.36.4/fs/namespace.c
5517 --- linux-2.6.27.14/fs/namespace.c      2009-02-03 17:59:55.000000000 +0100
5518 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/namespace.c 2009-02-03 17:59:04.000000000 +0100
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 @@ SYSCALL_DEFINE2(umount, char __user *, n
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 @@ SYSCALL_DEFINE1(oldumount, char __user *
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 @@ -1582,7 +1643,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 @@ -1665,7 +1726,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 @@ -1910,6 +1971,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 @@ -1925,6 +1987,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 @@ -1941,6 +2009,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 @@ -1956,9 +2026,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 @@ -2027,6 +2097,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 @@ -2354,5 +2425,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.14/fs/nfs/client.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfs/client.c
5787 --- linux-2.6.27.14/fs/nfs/client.c     2008-10-13 14:52:05.000000000 +0200
5788 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfs/dir.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfs/dir.c
5811 --- linux-2.6.27.14/fs/nfs/dir.c        2008-10-13 14:52:05.000000000 +0200
5812 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfs/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfs/inode.c
5830 --- linux-2.6.27.14/fs/nfs/inode.c      2008-10-13 14:52:05.000000000 +0200
5831 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfs/nfs3xdr.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfs/nfs3xdr.c
5927 --- linux-2.6.27.14/fs/nfs/nfs3xdr.c    2008-07-13 23:51:29.000000000 +0200
5928 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfs/nfsroot.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfs/nfsroot.c
6019 --- linux-2.6.27.14/fs/nfs/nfsroot.c    2008-10-13 14:52:05.000000000 +0200
6020 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfs/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfs/super.c
6068 --- linux-2.6.27.14/fs/nfs/super.c      2008-10-13 14:52:05.000000000 +0200
6069 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfsd/auth.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfsd/auth.c
6087 --- linux-2.6.27.14/fs/nfsd/auth.c      2008-07-13 23:51:29.000000000 +0200
6088 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfsd/nfs3xdr.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfsd/nfs3xdr.c
6125 --- linux-2.6.27.14/fs/nfsd/nfs3xdr.c   2008-07-13 23:51:29.000000000 +0200
6126 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfsd/nfs4xdr.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfsd/nfs4xdr.c
6178 --- linux-2.6.27.14/fs/nfsd/nfs4xdr.c   2008-10-13 14:52:06.000000000 +0200
6179 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/nfsd/nfsxdr.c linux-2.6.27.14-vs2.3.0.36.4/fs/nfsd/nfsxdr.c
6210 --- linux-2.6.27.14/fs/nfsd/nfsxdr.c    2008-07-13 23:51:29.000000000 +0200
6211 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/dlm/dlmfs.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/dlm/dlmfs.c
6261 --- linux-2.6.27.14/fs/ocfs2/dlm/dlmfs.c        2008-10-13 14:52:06.000000000 +0200
6262 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/dlmglue.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/dlmglue.c
6288 --- linux-2.6.27.14/fs/ocfs2/dlmglue.c  2008-10-13 14:52:06.000000000 +0200
6289 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/dlmglue.h linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/dlmglue.h
6307 --- linux-2.6.27.14/fs/ocfs2/dlmglue.h  2008-07-13 23:51:29.000000000 +0200
6308 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/file.c
6320 --- linux-2.6.27.14/fs/ocfs2/file.c     2008-10-13 14:52:06.000000000 +0200
6321 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/inode.c
6348 --- linux-2.6.27.14/fs/ocfs2/inode.c    2008-07-13 23:51:29.000000000 +0200
6349 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/inode.h linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/inode.h
6538 --- linux-2.6.27.14/fs/ocfs2/inode.h    2008-07-13 23:51:29.000000000 +0200
6539 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/ioctl.c
6549 --- linux-2.6.27.14/fs/ocfs2/ioctl.c    2008-07-13 23:51:29.000000000 +0200
6550 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/ioctl.h linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/ioctl.h
6573 --- linux-2.6.27.14/fs/ocfs2/ioctl.h    2008-07-13 23:51:29.000000000 +0200
6574 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/namei.c
6586 --- linux-2.6.27.14/fs/ocfs2/namei.c    2008-07-13 23:51:29.000000000 +0200
6587 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/ocfs2_fs.h linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/ocfs2_fs.h
6637 --- linux-2.6.27.14/fs/ocfs2/ocfs2_fs.h 2008-10-13 14:52:06.000000000 +0200
6638 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/ocfs2.h linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/ocfs2.h
6675 --- linux-2.6.27.14/fs/ocfs2/ocfs2.h    2008-10-13 14:52:06.000000000 +0200
6676 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/ocfs2/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/ocfs2/super.c
6686 --- linux-2.6.27.14/fs/ocfs2/super.c    2008-10-13 14:52:06.000000000 +0200
6687 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/open.c linux-2.6.27.14-vs2.3.0.36.4/fs/open.c
6752 --- linux-2.6.27.14/fs/open.c   2009-02-03 17:59:55.000000000 +0100
6753 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/open.c      2009-02-03 17:59:04.000000000 +0100
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 @@ -643,6 +652,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
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 @@ -676,11 +689,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 @@ -703,7 +716,11 @@ SYSCALL_DEFINE3(chown, const char __user
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 @@ -728,7 +745,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
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 @@ -747,7 +768,11 @@ SYSCALL_DEFINE3(lchown, const char __use
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 @@ -986,6 +1011,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.14/fs/proc/array.c linux-2.6.27.14-vs2.3.0.36.4/fs/proc/array.c
6861 --- linux-2.6.27.14/fs/proc/array.c     2008-10-13 14:52:06.000000000 +0200
6862 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/proc/base.c linux-2.6.27.14-vs2.3.0.36.4/fs/proc/base.c
7002 --- linux-2.6.27.14/fs/proc/base.c      2008-10-13 14:52:06.000000000 +0200
7003 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/proc/generic.c linux-2.6.27.14-vs2.3.0.36.4/fs/proc/generic.c
7118 --- linux-2.6.27.14/fs/proc/generic.c   2008-10-13 14:52:06.000000000 +0200
7119 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/proc/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/proc/inode.c
7182 --- linux-2.6.27.14/fs/proc/inode.c     2008-10-13 14:52:06.000000000 +0200
7183 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/proc/internal.h linux-2.6.27.14-vs2.3.0.36.4/fs/proc/internal.h
7194 --- linux-2.6.27.14/fs/proc/internal.h  2008-10-13 14:52:06.000000000 +0200
7195 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/proc/proc_misc.c linux-2.6.27.14-vs2.3.0.36.4/fs/proc/proc_misc.c
7233 --- linux-2.6.27.14/fs/proc/proc_misc.c 2008-10-13 14:52:06.000000000 +0200
7234 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/proc/root.c linux-2.6.27.14-vs2.3.0.36.4/fs/proc/root.c
7307 --- linux-2.6.27.14/fs/proc/root.c      2008-07-13 23:51:29.000000000 +0200
7308 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/quota.c linux-2.6.27.14-vs2.3.0.36.4/fs/quota.c
7341 --- linux-2.6.27.14/fs/quota.c  2009-02-03 17:59:55.000000000 +0100
7342 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/quota.c     2009-02-03 17:59:04.000000000 +0100
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.14/fs/reiserfs/bitmap.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/bitmap.c
7449 --- linux-2.6.27.14/fs/reiserfs/bitmap.c        2008-07-13 23:51:29.000000000 +0200
7450 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/reiserfs/file.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/file.c
7544 --- linux-2.6.27.14/fs/reiserfs/file.c  2008-07-13 23:51:29.000000000 +0200
7545 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/reiserfs/inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/inode.c
7553 --- linux-2.6.27.14/fs/reiserfs/inode.c 2009-02-03 17:59:55.000000000 +0100
7554 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/inode.c    2009-02-03 17:59:04.000000000 +0100
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.14/fs/reiserfs/ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/ioctl.c
7777 --- linux-2.6.27.14/fs/reiserfs/ioctl.c 2008-07-13 23:51:29.000000000 +0200
7778 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/reiserfs/namei.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/namei.c
7827 --- linux-2.6.27.14/fs/reiserfs/namei.c 2008-07-13 23:51:29.000000000 +0200
7828 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/reiserfs/stree.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/stree.c
7877 --- linux-2.6.27.14/fs/reiserfs/stree.c 2008-07-13 23:51:29.000000000 +0200
7878 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/reiserfs/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/super.c
7955 --- linux-2.6.27.14/fs/reiserfs/super.c 2008-10-13 14:52:06.000000000 +0200
7956 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/reiserfs/xattr.c linux-2.6.27.14-vs2.3.0.36.4/fs/reiserfs/xattr.c
7997 --- linux-2.6.27.14/fs/reiserfs/xattr.c 2008-10-13 14:52:06.000000000 +0200
7998 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/stat.c linux-2.6.27.14-vs2.3.0.36.4/fs/stat.c
8008 --- linux-2.6.27.14/fs/stat.c   2009-02-03 17:59:55.000000000 +0100
8009 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/stat.c      2009-02-03 17:59:04.000000000 +0100
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.14/fs/super.c linux-2.6.27.14-vs2.3.0.36.4/fs/super.c
8019 --- linux-2.6.27.14/fs/super.c  2009-02-03 17:59:55.000000000 +0100
8020 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/super.c     2009-02-03 17:59:04.000000000 +0100
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.14/fs/sysfs/mount.c linux-2.6.27.14-vs2.3.0.36.4/fs/sysfs/mount.c
8067 --- linux-2.6.27.14/fs/sysfs/mount.c    2008-07-13 23:51:29.000000000 +0200
8068 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/utimes.c linux-2.6.27.14-vs2.3.0.36.4/fs/utimes.c
8088 --- linux-2.6.27.14/fs/utimes.c 2009-02-03 17:59:55.000000000 +0100
8089 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/utimes.c    2009-02-03 17:59:04.000000000 +0100
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.14/fs/xattr.c linux-2.6.27.14-vs2.3.0.36.4/fs/xattr.c
8100 --- linux-2.6.27.14/fs/xattr.c  2009-02-03 17:59:55.000000000 +0100
8101 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/xattr.c     2009-02-03 17:59:04.000000000 +0100
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.14/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_ioctl.c
8111 --- linux-2.6.27.14/fs/xfs/linux-2.6/xfs_ioctl.c        2008-10-13 14:52:06.000000000 +0200
8112 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_iops.c
8173 --- linux-2.6.27.14/fs/xfs/linux-2.6/xfs_iops.c 2008-10-13 14:52:06.000000000 +0200
8174 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_linux.h
8256 --- linux-2.6.27.14/fs/xfs/linux-2.6/xfs_linux.h        2008-10-13 14:52:06.000000000 +0200
8257 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/linux-2.6/xfs_super.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_super.c
8267 --- linux-2.6.27.14/fs/xfs/linux-2.6/xfs_super.c        2009-02-03 17:59:55.000000000 +0100
8268 +++ linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_super.c   2009-02-03 17:59:04.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.14/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/quota/xfs_qm_syscalls.c
8352 --- linux-2.6.27.14/fs/xfs/quota/xfs_qm_syscalls.c      2008-10-13 14:52:06.000000000 +0200
8353 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_clnt.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_clnt.h
8364 --- linux-2.6.27.14/fs/xfs/xfs_clnt.h   2008-10-13 14:52:06.000000000 +0200
8365 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_dinode.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_dinode.h
8374 --- linux-2.6.27.14/fs/xfs/xfs_dinode.h 2008-07-13 23:51:29.000000000 +0200
8375 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_fs.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_fs.h
8428 --- linux-2.6.27.14/fs/xfs/xfs_fs.h     2008-10-13 14:52:06.000000000 +0200
8429 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_ialloc.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_ialloc.c
8451 --- linux-2.6.27.14/fs/xfs/xfs_ialloc.c 2008-07-13 23:51:29.000000000 +0200
8452 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_inode.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_inode.c
8463 --- linux-2.6.27.14/fs/xfs/xfs_inode.c  2008-10-13 14:52:06.000000000 +0200
8464 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_inode.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_inode.h
8632 --- linux-2.6.27.14/fs/xfs/xfs_inode.h  2008-10-13 14:52:06.000000000 +0200
8633 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_itable.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_itable.c
8658 --- linux-2.6.27.14/fs/xfs/xfs_itable.c 2008-10-13 14:52:06.000000000 +0200
8659 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_log_recover.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_log_recover.c
8669 --- linux-2.6.27.14/fs/xfs/xfs_log_recover.c    2008-10-13 14:52:06.000000000 +0200
8670 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_mount.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_mount.h
8682 --- linux-2.6.27.14/fs/xfs/xfs_mount.h  2008-10-13 14:52:06.000000000 +0200
8683 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_vnodeops.c linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_vnodeops.c
8693 --- linux-2.6.27.14/fs/xfs/xfs_vnodeops.c       2008-10-13 14:52:06.000000000 +0200
8694 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/fs/xfs/xfs_vnodeops.h linux-2.6.27.14-vs2.3.0.36.4/fs/xfs/xfs_vnodeops.h
8845 --- linux-2.6.27.14/fs/xfs/xfs_vnodeops.h       2008-10-13 14:52:06.000000000 +0200
8846 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/asm-generic/tlb.h linux-2.6.27.14-vs2.3.0.36.4/include/asm-generic/tlb.h
8856 --- linux-2.6.27.14/include/asm-generic/tlb.h   2008-07-13 23:51:29.000000000 +0200
8857 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/asm-x86/unistd_64.h linux-2.6.27.14-vs2.3.0.36.4/include/asm-x86/unistd_64.h
8867 --- linux-2.6.27.14/include/asm-x86/unistd_64.h 2008-10-13 14:52:08.000000000 +0200
8868 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/capability.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/capability.h
8879 --- linux-2.6.27.14/include/linux/capability.h  2008-10-13 14:52:09.000000000 +0200
8880 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/devpts_fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/devpts_fs.h
8905 --- linux-2.6.27.14/include/linux/devpts_fs.h   2008-07-13 23:51:29.000000000 +0200
8906 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/ext2_fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/ext2_fs.h
8914 --- linux-2.6.27.14/include/linux/ext2_fs.h     2008-10-13 14:52:09.000000000 +0200
8915 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/ext3_fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/ext3_fs.h
8955 --- linux-2.6.27.14/include/linux/ext3_fs.h     2008-10-13 14:52:09.000000000 +0200
8956 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/fs.h
9008 --- linux-2.6.27.14/include/linux/fs.h  2009-02-03 17:59:55.000000000 +0100
9009 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/fs.h     2009-02-03 17:59:04.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 @@ -629,7 +661,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 @@ -677,7 +711,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 @@ -764,12 +799,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 @@ -827,6 +862,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 @@ -961,6 +997,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 @@ -1289,6 +1326,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 @@ -1304,6 +1342,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 @@ -1994,6 +2033,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.14/include/linux/if_tun.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/if_tun.h
9189 --- linux-2.6.27.14/include/linux/if_tun.h      2008-10-13 14:52:09.000000000 +0200
9190 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/init_task.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/init_task.h
9200 --- linux-2.6.27.14/include/linux/init_task.h   2008-10-13 14:52:09.000000000 +0200
9201 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/interrupt.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/interrupt.h
9214 --- linux-2.6.27.14/include/linux/interrupt.h   2008-10-13 14:52:09.000000000 +0200
9215 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/ipc.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/ipc.h
9227 --- linux-2.6.27.14/include/linux/ipc.h 2008-07-13 23:51:29.000000000 +0200
9228 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/Kbuild linux-2.6.27.14-vs2.3.0.36.4/include/linux/Kbuild
9238 --- linux-2.6.27.14/include/linux/Kbuild        2009-02-03 17:59:55.000000000 +0100
9239 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/Kbuild   2009-02-03 18:03:38.000000000 +0100
9240 @@ -370,3 +370,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.14/include/linux/loop.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/loop.h
9248 --- linux-2.6.27.14/include/linux/loop.h        2008-07-13 23:51:29.000000000 +0200
9249 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/magic.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/magic.h
9259 --- linux-2.6.27.14/include/linux/magic.h       2008-07-13 23:51:29.000000000 +0200
9260 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/major.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/major.h
9279 --- linux-2.6.27.14/include/linux/major.h       2008-10-13 14:52:09.000000000 +0200
9280 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/mm_types.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/mm_types.h
9290 --- linux-2.6.27.14/include/linux/mm_types.h    2008-10-13 14:52:09.000000000 +0200
9291 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/mount.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/mount.h
9301 --- linux-2.6.27.14/include/linux/mount.h       2008-10-13 14:52:09.000000000 +0200
9302 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/net.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/net.h
9322 --- linux-2.6.27.14/include/linux/net.h 2008-10-13 14:52:09.000000000 +0200
9323 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/nfs_mount.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/nfs_mount.h
9333 --- linux-2.6.27.14/include/linux/nfs_mount.h   2008-07-13 23:51:29.000000000 +0200
9334 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/nsproxy.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/nsproxy.h
9345 --- linux-2.6.27.14/include/linux/nsproxy.h     2008-10-13 14:52:09.000000000 +0200
9346 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/pid.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/pid.h
9396 --- linux-2.6.27.14/include/linux/pid.h 2008-10-13 14:52:09.000000000 +0200
9397 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/proc_fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/proc_fs.h
9417 --- linux-2.6.27.14/include/linux/proc_fs.h     2008-10-13 14:52:09.000000000 +0200
9418 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/reiserfs_fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/reiserfs_fs.h
9455 --- linux-2.6.27.14/include/linux/reiserfs_fs.h 2008-10-13 14:52:09.000000000 +0200
9456 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/reiserfs_fs_sb.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/reiserfs_fs_sb.h
9488 --- linux-2.6.27.14/include/linux/reiserfs_fs_sb.h      2008-10-13 14:52:09.000000000 +0200
9489 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/sched.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/sched.h
9499 --- linux-2.6.27.14/include/linux/sched.h       2009-02-03 17:59:55.000000000 +0100
9500 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/sched.h  2009-02-03 18:03:38.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 @@ -1199,6 +1201,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 @@ -1385,6 +1395,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 @@ -1394,7 +1409,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 @@ -1407,7 +1422,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.14/include/linux/shmem_fs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/shmem_fs.h
9601 --- linux-2.6.27.14/include/linux/shmem_fs.h    2008-10-13 14:52:09.000000000 +0200
9602 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/stat.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/stat.h
9614 --- linux-2.6.27.14/include/linux/stat.h        2008-07-13 23:51:29.000000000 +0200
9615 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/sunrpc/auth.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/sunrpc/auth.h
9625 --- linux-2.6.27.14/include/linux/sunrpc/auth.h 2008-07-13 23:51:29.000000000 +0200
9626 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/sunrpc/clnt.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/sunrpc/clnt.h
9636 --- linux-2.6.27.14/include/linux/sunrpc/clnt.h 2008-10-13 14:52:09.000000000 +0200
9637 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/syscalls.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/syscalls.h
9649 --- linux-2.6.27.14/include/linux/syscalls.h    2009-02-03 17:59:55.000000000 +0100
9650 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/syscalls.h       2009-02-03 17:59:04.000000000 +0100
9651 @@ -364,6 +364,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.14/include/linux/sysctl.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/sysctl.h
9661 --- linux-2.6.27.14/include/linux/sysctl.h      2008-10-13 14:52:09.000000000 +0200
9662 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/sysfs.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/sysfs.h
9680 --- linux-2.6.27.14/include/linux/sysfs.h       2008-10-13 14:52:09.000000000 +0200
9681 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/time.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/time.h
9692 --- linux-2.6.27.14/include/linux/time.h        2009-02-03 17:59:55.000000000 +0100
9693 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/time.h   2009-02-03 17:59:04.000000000 +0100
9694 @@ -180,6 +180,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.14/include/linux/types.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/types.h
9705 --- linux-2.6.27.14/include/linux/types.h       2008-07-13 23:51:29.000000000 +0200
9706 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vroot.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vroot.h
9718 --- linux-2.6.27.14/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
9719 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vs_base.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_base.h
9773 --- linux-2.6.27.14/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
9774 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vs_context.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_context.h
9787 --- linux-2.6.27.14/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
9788 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vs_cowbl.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_cowbl.h
10018 --- linux-2.6.27.14/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
10019 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vs_cvirt.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_cvirt.h
10069 --- linux-2.6.27.14/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
10070 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vs_device.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_device.h
10123 --- linux-2.6.27.14/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
10124 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vs_dlimit.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_dlimit.h
10172 --- linux-2.6.27.14/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
10173 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/base.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/base.h
10387 --- linux-2.6.27.14/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
10388 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cacct_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cacct_cmd.h
10548 --- linux-2.6.27.14/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
10549 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cacct_def.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cacct_def.h
10575 --- linux-2.6.27.14/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
10576 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cacct.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cacct.h
10622 --- linux-2.6.27.14/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
10623 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cacct_int.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cacct_int.h
10641 --- linux-2.6.27.14/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
10642 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/check.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/check.h
10666 --- linux-2.6.27.14/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
10667 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/context_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/context_cmd.h
10759 --- linux-2.6.27.14/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
10760 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/context.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/context.h
10891 --- linux-2.6.27.14/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
10892 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cvirt_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cvirt_cmd.h
11073 --- linux-2.6.27.14/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
11074 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cvirt_def.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cvirt_def.h
11130 --- linux-2.6.27.14/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
11131 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/cvirt.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/cvirt.h
11214 --- linux-2.6.27.14/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
11215 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/debug_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/debug_cmd.h
11238 --- linux-2.6.27.14/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
11239 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/debug.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/debug.h
11300 --- linux-2.6.27.14/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
11301 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/device_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/device_cmd.h
11431 --- linux-2.6.27.14/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
11432 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/device_def.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/device_def.h
11479 --- linux-2.6.27.14/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
11480 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/device.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/device.h
11500 --- linux-2.6.27.14/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
11501 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/dlimit_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/dlimit_cmd.h
11519 --- linux-2.6.27.14/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
11520 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/dlimit.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/dlimit.h
11597 --- linux-2.6.27.14/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
11598 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/global.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/global.h
11655 --- linux-2.6.27.14/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
11656 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/history.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/history.h
11679 --- linux-2.6.27.14/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
11680 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/inode_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/inode_cmd.h
11880 --- linux-2.6.27.14/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
11881 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/inode.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/inode.h
11943 --- linux-2.6.27.14/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
11944 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/Kbuild linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/Kbuild
11985 --- linux-2.6.27.14/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
11986 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/limit_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/limit_cmd.h
11997 --- linux-2.6.27.14/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11998 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/limit_cmd.h      2009-01-04 02:28:31.000000000 +0100
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__ ((packed));
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.14/include/linux/vserver/limit_def.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/limit_def.h
12070 --- linux-2.6.27.14/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
12071 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/limit.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/limit.h
12121 --- linux-2.6.27.14/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
12122 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/limit_int.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/limit_int.h
12195 --- linux-2.6.27.14/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
12196 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/monitor.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/monitor.h
12397 --- linux-2.6.27.14/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
12398 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/network_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/network_cmd.h
12497 --- linux-2.6.27.14/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
12498 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/network.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/network.h
12651 --- linux-2.6.27.14/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
12652 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/percpu.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/percpu.h
12801 --- linux-2.6.27.14/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
12802 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/pid.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/pid.h
12819 --- linux-2.6.27.14/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
12820 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/sched_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/sched_cmd.h
12874 --- linux-2.6.27.14/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
12875 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/sched_def.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/sched_def.h
12986 --- linux-2.6.27.14/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
12987 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/sched.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/sched.h
13058 --- linux-2.6.27.14/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
13059 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/signal_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/signal_cmd.h
13088 --- linux-2.6.27.14/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
13089 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/signal.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/signal.h
13135 --- linux-2.6.27.14/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
13136 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/space_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/space_cmd.h
13153 --- linux-2.6.27.14/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
13154 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/space.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/space.h
13195 --- linux-2.6.27.14/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
13196 +++ linux-2.6.27.14-vs2.3.0.36.4/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.14/include/linux/vserver/switch.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/switch.h
13211 --- linux-2.6.27.14/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
13212 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/switch.h 2008-11-22 20:32:00.000000000 +0100
13213 @@ -0,0 +1,98 @@
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 +#endif /* __KERNEL__ */
13309 +
13310 +#endif /* _VX_SWITCH_H */
13311 +
13312 diff -NurpP --minimal linux-2.6.27.14/include/linux/vserver/tag_cmd.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/tag_cmd.h
13313 --- linux-2.6.27.14/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
13314 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/tag_cmd.h        2008-10-13 14:54:20.000000000 +0200
13315 @@ -0,0 +1,22 @@
13316 +#ifndef _VX_TAG_CMD_H
13317 +#define _VX_TAG_CMD_H
13318 +
13319 +
13320 +/* vinfo commands */
13321 +
13322 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13323 +
13324 +#ifdef __KERNEL__
13325 +extern int vc_task_tag(uint32_t);
13326 +
13327 +#endif /* __KERNEL__ */
13328 +
13329 +/* context commands */
13330 +
13331 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13332 +
13333 +#ifdef __KERNEL__
13334 +extern int vc_tag_migrate(uint32_t);
13335 +
13336 +#endif /* __KERNEL__ */
13337 +#endif /* _VX_TAG_CMD_H */
13338 diff -NurpP --minimal linux-2.6.27.14/include/linux/vserver/tag.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/tag.h
13339 --- linux-2.6.27.14/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
13340 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vserver/tag.h    2008-10-24 03:34:52.000000000 +0200
13341 @@ -0,0 +1,143 @@
13342 +#ifndef _DX_TAG_H
13343 +#define _DX_TAG_H
13344 +
13345 +#include <linux/types.h>
13346 +
13347 +
13348 +#define DX_TAG(in)     (IS_TAGGED(in))
13349 +
13350 +
13351 +#ifdef CONFIG_TAG_NFSD
13352 +#define DX_TAG_NFSD    1
13353 +#else
13354 +#define DX_TAG_NFSD    0
13355 +#endif
13356 +
13357 +
13358 +#ifdef CONFIG_TAGGING_NONE
13359 +
13360 +#define MAX_UID                0xFFFFFFFF
13361 +#define MAX_GID                0xFFFFFFFF
13362 +
13363 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13364 +
13365 +#define TAGINO_UID(cond, uid, tag)     (uid)
13366 +#define TAGINO_GID(cond, gid, tag)     (gid)
13367 +
13368 +#endif
13369 +
13370 +
13371 +#ifdef CONFIG_TAGGING_GID16
13372 +
13373 +#define MAX_UID                0xFFFFFFFF
13374 +#define MAX_GID                0x0000FFFF
13375 +
13376 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13377 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13378 +
13379 +#define TAGINO_UID(cond, uid, tag)     (uid)
13380 +#define TAGINO_GID(cond, gid, tag)     \
13381 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13382 +
13383 +#endif
13384 +
13385 +
13386 +#ifdef CONFIG_TAGGING_ID24
13387 +
13388 +#define MAX_UID                0x00FFFFFF
13389 +#define MAX_GID                0x00FFFFFF
13390 +
13391 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13392 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13393 +
13394 +#define TAGINO_UID(cond, uid, tag)     \
13395 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13396 +#define TAGINO_GID(cond, gid, tag)     \
13397 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13398 +
13399 +#endif
13400 +
13401 +
13402 +#ifdef CONFIG_TAGGING_UID16
13403 +
13404 +#define MAX_UID                0x0000FFFF
13405 +#define MAX_GID                0xFFFFFFFF
13406 +
13407 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13408 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13409 +
13410 +#define TAGINO_UID(cond, uid, tag)     \
13411 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13412 +#define TAGINO_GID(cond, gid, tag)     (gid)
13413 +
13414 +#endif
13415 +
13416 +
13417 +#ifdef CONFIG_TAGGING_INTERN
13418 +
13419 +#define MAX_UID                0xFFFFFFFF
13420 +#define MAX_GID                0xFFFFFFFF
13421 +
13422 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13423 +       ((cond) ? (tag) : 0)
13424 +
13425 +#define TAGINO_UID(cond, uid, tag)     (uid)
13426 +#define TAGINO_GID(cond, gid, tag)     (gid)
13427 +
13428 +#endif
13429 +
13430 +
13431 +#ifndef CONFIG_TAGGING_NONE
13432 +#define dx_current_fstag(sb)   \
13433 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13434 +#else
13435 +#define dx_current_fstag(sb)   (0)
13436 +#endif
13437 +
13438 +#ifndef CONFIG_TAGGING_INTERN
13439 +#define TAGINO_TAG(cond, tag)  (0)
13440 +#else
13441 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13442 +#endif
13443 +
13444 +#define INOTAG_UID(cond, uid, gid)     \
13445 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13446 +#define INOTAG_GID(cond, uid, gid)     \
13447 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13448 +
13449 +
13450 +static inline uid_t dx_map_uid(uid_t uid)
13451 +{
13452 +       if ((uid > MAX_UID) && (uid != -1))
13453 +               uid = -2;
13454 +       return (uid & MAX_UID);
13455 +}
13456 +
13457 +static inline gid_t dx_map_gid(gid_t gid)
13458 +{
13459 +       if ((gid > MAX_GID) && (gid != -1))
13460 +               gid = -2;
13461 +       return (gid & MAX_GID);
13462 +}
13463 +
13464 +struct peer_tag {
13465 +       int32_t xid;
13466 +       int32_t nid;
13467 +};
13468 +
13469 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13470 +
13471 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13472 +                unsigned long *flags);
13473 +
13474 +#ifdef CONFIG_PROPAGATE
13475 +
13476 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13477 +
13478 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13479 +
13480 +#else
13481 +#define dx_propagate_tag(n, i) do { } while (0)
13482 +#endif
13483 +
13484 +#endif /* _DX_TAG_H */
13485 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_inet6.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_inet6.h
13486 --- linux-2.6.27.14/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
13487 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_inet6.h       2008-11-16 17:35:20.000000000 +0100
13488 @@ -0,0 +1,246 @@
13489 +#ifndef _VS_INET6_H
13490 +#define _VS_INET6_H
13491 +
13492 +#include "vserver/base.h"
13493 +#include "vserver/network.h"
13494 +#include "vserver/debug.h"
13495 +
13496 +#include <net/ipv6.h>
13497 +
13498 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
13499 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
13500 +
13501 +
13502 +#ifdef CONFIG_IPV6
13503 +
13504 +static inline
13505 +int v6_addr_match(struct nx_addr_v6 *nxa,
13506 +       const struct in6_addr *addr, uint16_t mask)
13507 +{
13508 +       int ret = 0;
13509 +
13510 +       switch (nxa->type & mask) {
13511 +       case NXA_TYPE_MASK:
13512 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13513 +               break;
13514 +       case NXA_TYPE_ADDR:
13515 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13516 +               break;
13517 +       case NXA_TYPE_ANY:
13518 +               ret = 1;
13519 +               break;
13520 +       }
13521 +       vxdprintk(VXD_CBIT(net, 0),
13522 +               "v6_addr_match(%p" NXAV6_FMT ", " NIP6_FMT ", %04x) = %d",
13523 +               nxa, NXAV6(nxa), NIP6(*addr), mask, ret);
13524 +       return ret;
13525 +}
13526 +
13527 +static inline
13528 +int v6_addr_in_nx_info(struct nx_info *nxi,
13529 +       const struct in6_addr *addr, uint16_t mask)
13530 +{
13531 +       struct nx_addr_v6 *nxa;
13532 +       int ret = 1;
13533 +
13534 +       if (!nxi)
13535 +               goto out;
13536 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13537 +               if (v6_addr_match(nxa, addr, mask))
13538 +                       goto out;
13539 +       ret = 0;
13540 +out:
13541 +       vxdprintk(VXD_CBIT(net, 0),
13542 +               "v6_addr_in_nx_info(%p[#%u]," NIP6_FMT ",%04x) = %d",
13543 +               nxi, nxi ? nxi->nx_id : 0, NIP6(*addr), mask, ret);
13544 +       return ret;
13545 +}
13546 +
13547 +static inline
13548 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13549 +{
13550 +       /* FIXME: needs full range checks */
13551 +       return v6_addr_match(nxa, &addr->ip, mask);
13552 +}
13553 +
13554 +static inline
13555 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13556 +{
13557 +       struct nx_addr_v6 *ptr;
13558 +
13559 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13560 +               if (v6_nx_addr_match(ptr, nxa, mask))
13561 +                       return 1;
13562 +       return 0;
13563 +}
13564 +
13565 +
13566 +/*
13567 + *     Check if a given address matches for a socket
13568 + *
13569 + *     nxi:            the socket's nx_info if any
13570 + *     addr:           to be verified address
13571 + */
13572 +static inline
13573 +int v6_sock_addr_match (
13574 +       struct nx_info *nxi,
13575 +       struct inet_sock *inet,
13576 +       struct in6_addr *addr)
13577 +{
13578 +       struct sock *sk = &inet->sk;
13579 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13580 +
13581 +       if (!ipv6_addr_any(addr) &&
13582 +               ipv6_addr_equal(saddr, addr))
13583 +               return 1;
13584 +       if (ipv6_addr_any(saddr))
13585 +               return v6_addr_in_nx_info(nxi, addr, -1);
13586 +       return 0;
13587 +}
13588 +
13589 +/*
13590 + *     check if address is covered by socket
13591 + *
13592 + *     sk:     the socket to check against
13593 + *     addr:   the address in question (must be != 0)
13594 + */
13595 +
13596 +static inline
13597 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13598 +{
13599 +       struct nx_info *nxi = sk->sk_nx_info;
13600 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13601 +
13602 +       vxdprintk(VXD_CBIT(net, 5),
13603 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
13604 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
13605 +               (sk->sk_socket?sk->sk_socket->flags:0));
13606 +
13607 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13608 +               return v6_addr_match(nxa, saddr, -1);
13609 +       } else if (nxi) {               /* match against nx_info */
13610 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13611 +       } else {                        /* unrestricted any socket */
13612 +               return 1;
13613 +       }
13614 +}
13615 +
13616 +
13617 +/* inet related checks and helpers */
13618 +
13619 +
13620 +struct in_ifaddr;
13621 +struct net_device;
13622 +struct sock;
13623 +
13624 +
13625 +#include <linux/netdevice.h>
13626 +#include <linux/inetdevice.h>
13627 +#include <net/inet_timewait_sock.h>
13628 +
13629 +
13630 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13631 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13632 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13633 +
13634 +
13635 +
13636 +static inline
13637 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13638 +{
13639 +       if (!nxi)
13640 +               return 1;
13641 +       if (!ifa)
13642 +               return 0;
13643 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13644 +}
13645 +
13646 +static inline
13647 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13648 +{
13649 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13650 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13651 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13652 +
13653 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13654 +               return 1;
13655 +       if (v6_ifa_in_nx_info(ifa, nxi))
13656 +               return 1;
13657 +       return 0;
13658 +}
13659 +
13660 +
13661 +struct nx_v6_sock_addr {
13662 +       struct in6_addr saddr;  /* Address used for validation */
13663 +       struct in6_addr baddr;  /* Address used for socket bind */
13664 +};
13665 +
13666 +static inline
13667 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13668 +       struct nx_v6_sock_addr *nsa)
13669 +{
13670 +       // struct sock *sk = &inet->sk;
13671 +       // struct nx_info *nxi = sk->sk_nx_info;
13672 +       struct in6_addr saddr = addr->sin6_addr;
13673 +       struct in6_addr baddr = saddr;
13674 +
13675 +       nsa->saddr = saddr;
13676 +       nsa->baddr = baddr;
13677 +       return 0;
13678 +}
13679 +
13680 +static inline
13681 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13682 +{
13683 +       // struct sock *sk = &inet->sk;
13684 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13685 +
13686 +       // *saddr = nsa->baddr;
13687 +       // inet->saddr = nsa->baddr;
13688 +}
13689 +
13690 +static inline
13691 +int nx_info_has_v6(struct nx_info *nxi)
13692 +{
13693 +       if (!nxi)
13694 +               return 1;
13695 +       if (NX_IPV6(nxi))
13696 +               return 1;
13697 +       return 0;
13698 +}
13699 +
13700 +#else /* CONFIG_IPV6 */
13701 +
13702 +static inline
13703 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13704 +{
13705 +       return 1;
13706 +}
13707 +
13708 +
13709 +static inline
13710 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13711 +{
13712 +       return 1;
13713 +}
13714 +
13715 +static inline
13716 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13717 +{
13718 +       return 1;
13719 +}
13720 +
13721 +static inline
13722 +int nx_info_has_v6(struct nx_info *nxi)
13723 +{
13724 +       return 0;
13725 +}
13726 +
13727 +#endif /* CONFIG_IPV6 */
13728 +
13729 +#define current_nx_info_has_v6() \
13730 +       nx_info_has_v6(current_nx_info())
13731 +
13732 +#else
13733 +#warning duplicate inclusion
13734 +#endif
13735 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_inet.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_inet.h
13736 --- linux-2.6.27.14/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
13737 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_inet.h        2008-10-13 14:54:20.000000000 +0200
13738 @@ -0,0 +1,342 @@
13739 +#ifndef _VS_INET_H
13740 +#define _VS_INET_H
13741 +
13742 +#include "vserver/base.h"
13743 +#include "vserver/network.h"
13744 +#include "vserver/debug.h"
13745 +
13746 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13747 +
13748 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13749 +                       NIPQUAD((a)->mask), (a)->type
13750 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13751 +
13752 +
13753 +static inline
13754 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13755 +{
13756 +       __be32 ip = nxa->ip[0].s_addr;
13757 +       __be32 mask = nxa->mask.s_addr;
13758 +       __be32 bcast = ip | ~mask;
13759 +       int ret = 0;
13760 +
13761 +       switch (nxa->type & tmask) {
13762 +       case NXA_TYPE_MASK:
13763 +               ret = (ip == (addr & mask));
13764 +               break;
13765 +       case NXA_TYPE_ADDR:
13766 +               ret = 3;
13767 +               if (addr == ip)
13768 +                       break;
13769 +               /* fall through to broadcast */
13770 +       case NXA_MOD_BCAST:
13771 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13772 +               break;
13773 +       case NXA_TYPE_RANGE:
13774 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13775 +                       (nxa->ip[1].s_addr > addr));
13776 +               break;
13777 +       case NXA_TYPE_ANY:
13778 +               ret = 2;
13779 +               break;
13780 +       }
13781 +
13782 +       vxdprintk(VXD_CBIT(net, 0),
13783 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13784 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13785 +       return ret;
13786 +}
13787 +
13788 +static inline
13789 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13790 +{
13791 +       struct nx_addr_v4 *nxa;
13792 +       int ret = 1;
13793 +
13794 +       if (!nxi)
13795 +               goto out;
13796 +
13797 +       ret = 2;
13798 +       /* allow 127.0.0.1 when remapping lback */
13799 +       if ((tmask & NXA_LOOPBACK) &&
13800 +               (addr == IPI_LOOPBACK) &&
13801 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13802 +               goto out;
13803 +       ret = 3;
13804 +       /* check for lback address */
13805 +       if ((tmask & NXA_MOD_LBACK) &&
13806 +               (nxi->v4_lback.s_addr == addr))
13807 +               goto out;
13808 +       ret = 4;
13809 +       /* check for broadcast address */
13810 +       if ((tmask & NXA_MOD_BCAST) &&
13811 +               (nxi->v4_bcast.s_addr == addr))
13812 +               goto out;
13813 +       ret = 5;
13814 +       /* check for v4 addresses */
13815 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13816 +               if (v4_addr_match(nxa, addr, tmask))
13817 +                       goto out;
13818 +       ret = 0;
13819 +out:
13820 +       vxdprintk(VXD_CBIT(net, 0),
13821 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13822 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13823 +       return ret;
13824 +}
13825 +
13826 +static inline
13827 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13828 +{
13829 +       /* FIXME: needs full range checks */
13830 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13831 +}
13832 +
13833 +static inline
13834 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13835 +{
13836 +       struct nx_addr_v4 *ptr;
13837 +
13838 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13839 +               if (v4_nx_addr_match(ptr, nxa, mask))
13840 +                       return 1;
13841 +       return 0;
13842 +}
13843 +
13844 +#include <net/inet_sock.h>
13845 +
13846 +/*
13847 + *     Check if a given address matches for a socket
13848 + *
13849 + *     nxi:            the socket's nx_info if any
13850 + *     addr:           to be verified address
13851 + */
13852 +static inline
13853 +int v4_sock_addr_match (
13854 +       struct nx_info *nxi,
13855 +       struct inet_sock *inet,
13856 +       __be32 addr)
13857 +{
13858 +       __be32 saddr = inet->rcv_saddr;
13859 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13860 +
13861 +       if (addr && (saddr == addr || bcast == addr))
13862 +               return 1;
13863 +       if (!saddr)
13864 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13865 +       return 0;
13866 +}
13867 +
13868 +
13869 +/* inet related checks and helpers */
13870 +
13871 +
13872 +struct in_ifaddr;
13873 +struct net_device;
13874 +struct sock;
13875 +
13876 +#ifdef CONFIG_INET
13877 +
13878 +#include <linux/netdevice.h>
13879 +#include <linux/inetdevice.h>
13880 +#include <net/inet_sock.h>
13881 +#include <net/inet_timewait_sock.h>
13882 +
13883 +
13884 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13885 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13886 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13887 +
13888 +
13889 +/*
13890 + *     check if address is covered by socket
13891 + *
13892 + *     sk:     the socket to check against
13893 + *     addr:   the address in question (must be != 0)
13894 + */
13895 +
13896 +static inline
13897 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13898 +{
13899 +       struct nx_info *nxi = sk->sk_nx_info;
13900 +       __be32 saddr = inet_rcv_saddr(sk);
13901 +
13902 +       vxdprintk(VXD_CBIT(net, 5),
13903 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13904 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13905 +               (sk->sk_socket?sk->sk_socket->flags:0));
13906 +
13907 +       if (saddr) {            /* direct address match */
13908 +               return v4_addr_match(nxa, saddr, -1);
13909 +       } else if (nxi) {       /* match against nx_info */
13910 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13911 +       } else {                /* unrestricted any socket */
13912 +               return 1;
13913 +       }
13914 +}
13915 +
13916 +
13917 +
13918 +static inline
13919 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13920 +{
13921 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13922 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13923 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13924 +
13925 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13926 +               return 1;
13927 +       if (dev_in_nx_info(dev, nxi))
13928 +               return 1;
13929 +       return 0;
13930 +}
13931 +
13932 +
13933 +static inline
13934 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13935 +{
13936 +       if (!nxi)
13937 +               return 1;
13938 +       if (!ifa)
13939 +               return 0;
13940 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13941 +}
13942 +
13943 +static inline
13944 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13945 +{
13946 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13947 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13948 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13949 +
13950 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13951 +               return 1;
13952 +       if (v4_ifa_in_nx_info(ifa, nxi))
13953 +               return 1;
13954 +       return 0;
13955 +}
13956 +
13957 +
13958 +struct nx_v4_sock_addr {
13959 +       __be32 saddr;   /* Address used for validation */
13960 +       __be32 baddr;   /* Address used for socket bind */
13961 +};
13962 +
13963 +static inline
13964 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13965 +       struct nx_v4_sock_addr *nsa)
13966 +{
13967 +       struct sock *sk = &inet->sk;
13968 +       struct nx_info *nxi = sk->sk_nx_info;
13969 +       __be32 saddr = addr->sin_addr.s_addr;
13970 +       __be32 baddr = saddr;
13971 +
13972 +       vxdprintk(VXD_CBIT(net, 3),
13973 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13974 +               sk, sk->sk_nx_info, sk->sk_socket,
13975 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13976 +               NIPQUAD(saddr));
13977 +
13978 +       if (nxi) {
13979 +               if (saddr == INADDR_ANY) {
13980 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13981 +                               baddr = nxi->v4.ip[0].s_addr;
13982 +               } else if (saddr == IPI_LOOPBACK) {
13983 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13984 +                               baddr = nxi->v4_lback.s_addr;
13985 +               } else {        /* normal address bind */
13986 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13987 +                               return -EADDRNOTAVAIL;
13988 +               }
13989 +       }
13990 +
13991 +       vxdprintk(VXD_CBIT(net, 3),
13992 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13993 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13994 +
13995 +       nsa->saddr = saddr;
13996 +       nsa->baddr = baddr;
13997 +       return 0;
13998 +}
13999 +
14000 +static inline
14001 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
14002 +{
14003 +       inet->saddr = nsa->baddr;
14004 +       inet->rcv_saddr = nsa->baddr;
14005 +}
14006 +
14007 +
14008 +/*
14009 + *      helper to simplify inet_lookup_listener
14010 + *
14011 + *      nxi:   the socket's nx_info if any
14012 + *      addr:  to be verified address
14013 + *      saddr: socket address
14014 + */
14015 +static inline int v4_inet_addr_match (
14016 +       struct nx_info *nxi,
14017 +       __be32 addr,
14018 +       __be32 saddr)
14019 +{
14020 +       if (addr && (saddr == addr))
14021 +               return 1;
14022 +       if (!saddr)
14023 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
14024 +       return 0;
14025 +}
14026 +
14027 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
14028 +{
14029 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
14030 +               (addr == nxi->v4_lback.s_addr))
14031 +               return IPI_LOOPBACK;
14032 +       return addr;
14033 +}
14034 +
14035 +static inline
14036 +int nx_info_has_v4(struct nx_info *nxi)
14037 +{
14038 +       if (!nxi)
14039 +               return 1;
14040 +       if (NX_IPV4(nxi))
14041 +               return 1;
14042 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14043 +               return 1;
14044 +       return 0;
14045 +}
14046 +
14047 +#else /* CONFIG_INET */
14048 +
14049 +static inline
14050 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
14051 +{
14052 +       return 1;
14053 +}
14054 +
14055 +static inline
14056 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14057 +{
14058 +       return 1;
14059 +}
14060 +
14061 +static inline
14062 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14063 +{
14064 +       return 1;
14065 +}
14066 +
14067 +static inline
14068 +int nx_info_has_v4(struct nx_info *nxi)
14069 +{
14070 +       return 0;
14071 +}
14072 +
14073 +#endif /* CONFIG_INET */
14074 +
14075 +#define current_nx_info_has_v4() \
14076 +       nx_info_has_v4(current_nx_info())
14077 +
14078 +#else
14079 +// #warning duplicate inclusion
14080 +#endif
14081 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_limit.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_limit.h
14082 --- linux-2.6.27.14/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
14083 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_limit.h       2008-10-13 14:54:20.000000000 +0200
14084 @@ -0,0 +1,140 @@
14085 +#ifndef _VS_LIMIT_H
14086 +#define _VS_LIMIT_H
14087 +
14088 +#include "vserver/limit.h"
14089 +#include "vserver/base.h"
14090 +#include "vserver/context.h"
14091 +#include "vserver/debug.h"
14092 +#include "vserver/context.h"
14093 +#include "vserver/limit_int.h"
14094 +
14095 +
14096 +#define vx_acc_cres(v, d, p, r) \
14097 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14098 +
14099 +#define vx_acc_cres_cond(x, d, p, r) \
14100 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14101 +       r, d, p, __FILE__, __LINE__)
14102 +
14103 +
14104 +#define vx_add_cres(v, a, p, r) \
14105 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
14106 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
14107 +
14108 +#define vx_add_cres_cond(x, a, p, r) \
14109 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14110 +       r, a, p, __FILE__, __LINE__)
14111 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
14112 +
14113 +
14114 +/* process and file limits */
14115 +
14116 +#define vx_nproc_inc(p) \
14117 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
14118 +
14119 +#define vx_nproc_dec(p) \
14120 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
14121 +
14122 +#define vx_files_inc(f) \
14123 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
14124 +
14125 +#define vx_files_dec(f) \
14126 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
14127 +
14128 +#define vx_locks_inc(l) \
14129 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
14130 +
14131 +#define vx_locks_dec(l) \
14132 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
14133 +
14134 +#define vx_openfd_inc(f) \
14135 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
14136 +
14137 +#define vx_openfd_dec(f) \
14138 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
14139 +
14140 +
14141 +#define vx_cres_avail(v, n, r) \
14142 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14143 +
14144 +
14145 +#define vx_nproc_avail(n) \
14146 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
14147 +
14148 +#define vx_files_avail(n) \
14149 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
14150 +
14151 +#define vx_locks_avail(n) \
14152 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
14153 +
14154 +#define vx_openfd_avail(n) \
14155 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
14156 +
14157 +
14158 +/* dentry limits */
14159 +
14160 +#define vx_dentry_inc(d) do {                                          \
14161 +       if (atomic_read(&d->d_count) == 1)                              \
14162 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
14163 +       } while (0)
14164 +
14165 +#define vx_dentry_dec(d) do {                                          \
14166 +       if (atomic_read(&d->d_count) == 0)                              \
14167 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
14168 +       } while (0)
14169 +
14170 +#define vx_dentry_avail(n) \
14171 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
14172 +
14173 +
14174 +/* socket limits */
14175 +
14176 +#define vx_sock_inc(s) \
14177 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14178 +
14179 +#define vx_sock_dec(s) \
14180 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14181 +
14182 +#define vx_sock_avail(n) \
14183 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
14184 +
14185 +
14186 +/* ipc resource limits */
14187 +
14188 +#define vx_ipcmsg_add(v, u, a) \
14189 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14190 +
14191 +#define vx_ipcmsg_sub(v, u, a) \
14192 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14193 +
14194 +#define vx_ipcmsg_avail(v, a) \
14195 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14196 +
14197 +
14198 +#define vx_ipcshm_add(v, k, a) \
14199 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14200 +
14201 +#define vx_ipcshm_sub(v, k, a) \
14202 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14203 +
14204 +#define vx_ipcshm_avail(v, a) \
14205 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14206 +
14207 +
14208 +#define vx_semary_inc(a) \
14209 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
14210 +
14211 +#define vx_semary_dec(a) \
14212 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
14213 +
14214 +
14215 +#define vx_nsems_add(a,n) \
14216 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14217 +
14218 +#define vx_nsems_sub(a,n) \
14219 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14220 +
14221 +
14222 +#else
14223 +#warning duplicate inclusion
14224 +#endif
14225 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_memory.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_memory.h
14226 --- linux-2.6.27.14/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
14227 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_memory.h      2008-10-13 14:54:20.000000000 +0200
14228 @@ -0,0 +1,159 @@
14229 +#ifndef _VS_MEMORY_H
14230 +#define _VS_MEMORY_H
14231 +
14232 +#include "vserver/limit.h"
14233 +#include "vserver/base.h"
14234 +#include "vserver/context.h"
14235 +#include "vserver/debug.h"
14236 +#include "vserver/context.h"
14237 +#include "vserver/limit_int.h"
14238 +
14239 +
14240 +#define __acc_add_long(a, v)   (*(v) += (a))
14241 +#define __acc_inc_long(v)      (++*(v))
14242 +#define __acc_dec_long(v)      (--*(v))
14243 +
14244 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14245 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14246 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14247 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14248 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14249 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14250 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14251 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14252 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14253 +
14254 +
14255 +#define vx_acc_page(m, d, v, r) do {                                   \
14256 +       if ((d) > 0)                                                    \
14257 +               __acc_inc_long(&(m)->v);                                \
14258 +       else                                                            \
14259 +               __acc_dec_long(&(m)->v);                                \
14260 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14261 +} while (0)
14262 +
14263 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14264 +       if ((d) > 0)                                                    \
14265 +               __acc_inc_atomic(&(m)->v);                              \
14266 +       else                                                            \
14267 +               __acc_dec_atomic(&(m)->v);                              \
14268 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14269 +} while (0)
14270 +
14271 +
14272 +#define vx_acc_pages(m, p, v, r) do {                                  \
14273 +       unsigned long __p = (p);                                        \
14274 +       __acc_add_long(__p, &(m)->v);                                   \
14275 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14276 +} while (0)
14277 +
14278 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14279 +       unsigned long __p = (p);                                        \
14280 +       __acc_add_atomic(__p, &(m)->v);                                 \
14281 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14282 +} while (0)
14283 +
14284 +
14285 +
14286 +#define vx_acc_vmpage(m, d) \
14287 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14288 +#define vx_acc_vmlpage(m, d) \
14289 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14290 +#define vx_acc_file_rsspage(m, d) \
14291 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14292 +#define vx_acc_anon_rsspage(m, d) \
14293 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14294 +
14295 +#define vx_acc_vmpages(m, p) \
14296 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14297 +#define vx_acc_vmlpages(m, p) \
14298 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14299 +#define vx_acc_file_rsspages(m, p) \
14300 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14301 +#define vx_acc_anon_rsspages(m, p) \
14302 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14303 +
14304 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14305 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14306 +
14307 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14308 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14309 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14310 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14311 +
14312 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14313 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14314 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14315 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14316 +
14317 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14318 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14319 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14320 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14321 +
14322 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14323 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14324 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14325 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14326 +
14327 +
14328 +#define vx_pages_avail(m, p, r) \
14329 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14330 +
14331 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14332 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14333 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14334 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14335 +
14336 +#define vx_rss_avail(m, p) \
14337 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14338 +
14339 +
14340 +enum {
14341 +       VXPT_UNKNOWN = 0,
14342 +       VXPT_ANON,
14343 +       VXPT_NONE,
14344 +       VXPT_FILE,
14345 +       VXPT_SWAP,
14346 +       VXPT_WRITE
14347 +};
14348 +
14349 +#if 0
14350 +#define        vx_page_fault(mm, vma, type, ret)
14351 +#else
14352 +
14353 +static inline
14354 +void __vx_page_fault(struct mm_struct *mm,
14355 +       struct vm_area_struct *vma, int type, int ret)
14356 +{
14357 +       struct vx_info *vxi = mm->mm_vx_info;
14358 +       int what;
14359 +/*
14360 +       static char *page_type[6] =
14361 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14362 +       static char *page_what[4] =
14363 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14364 +*/
14365 +
14366 +       if (!vxi)
14367 +               return;
14368 +
14369 +       what = (ret & 0x3);
14370 +
14371 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14372 +               type, what, ret, page_type[type], page_what[what]);
14373 +*/
14374 +       if (ret & VM_FAULT_WRITE)
14375 +               what |= 0x4;
14376 +       atomic_inc(&vxi->cacct.page[type][what]);
14377 +}
14378 +
14379 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14380 +#endif
14381 +
14382 +
14383 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14384 +
14385 +#else
14386 +#warning duplicate inclusion
14387 +#endif
14388 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_network.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_network.h
14389 --- linux-2.6.27.14/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
14390 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_network.h     2008-10-13 14:54:20.000000000 +0200
14391 @@ -0,0 +1,169 @@
14392 +#ifndef _NX_VS_NETWORK_H
14393 +#define _NX_VS_NETWORK_H
14394 +
14395 +#include "vserver/context.h"
14396 +#include "vserver/network.h"
14397 +#include "vserver/base.h"
14398 +#include "vserver/check.h"
14399 +#include "vserver/debug.h"
14400 +
14401 +#include <linux/sched.h>
14402 +
14403 +
14404 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14405 +
14406 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14407 +       const char *_file, int _line)
14408 +{
14409 +       if (!nxi)
14410 +               return NULL;
14411 +
14412 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14413 +               nxi, nxi ? nxi->nx_id : 0,
14414 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14415 +               _file, _line);
14416 +
14417 +       atomic_inc(&nxi->nx_usecnt);
14418 +       return nxi;
14419 +}
14420 +
14421 +
14422 +extern void free_nx_info(struct nx_info *);
14423 +
14424 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14425 +
14426 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14427 +{
14428 +       if (!nxi)
14429 +               return;
14430 +
14431 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14432 +               nxi, nxi ? nxi->nx_id : 0,
14433 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14434 +               _file, _line);
14435 +
14436 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14437 +               free_nx_info(nxi);
14438 +}
14439 +
14440 +
14441 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14442 +
14443 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14444 +               const char *_file, int _line)
14445 +{
14446 +       if (nxi) {
14447 +               vxlprintk(VXD_CBIT(nid, 3),
14448 +                       "init_nx_info(%p[#%d.%d])",
14449 +                       nxi, nxi ? nxi->nx_id : 0,
14450 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14451 +                       _file, _line);
14452 +
14453 +               atomic_inc(&nxi->nx_usecnt);
14454 +       }
14455 +       *nxp = nxi;
14456 +}
14457 +
14458 +
14459 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14460 +
14461 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14462 +       const char *_file, int _line)
14463 +{
14464 +       struct nx_info *nxo;
14465 +
14466 +       if (!nxi)
14467 +               return;
14468 +
14469 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14470 +               nxi, nxi ? nxi->nx_id : 0,
14471 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14472 +               _file, _line);
14473 +
14474 +       atomic_inc(&nxi->nx_usecnt);
14475 +       nxo = xchg(nxp, nxi);
14476 +       BUG_ON(nxo);
14477 +}
14478 +
14479 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14480 +
14481 +static inline void __clr_nx_info(struct nx_info **nxp,
14482 +       const char *_file, int _line)
14483 +{
14484 +       struct nx_info *nxo;
14485 +
14486 +       nxo = xchg(nxp, NULL);
14487 +       if (!nxo)
14488 +               return;
14489 +
14490 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14491 +               nxo, nxo ? nxo->nx_id : 0,
14492 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14493 +               _file, _line);
14494 +
14495 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14496 +               free_nx_info(nxo);
14497 +}
14498 +
14499 +
14500 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14501 +
14502 +static inline void __claim_nx_info(struct nx_info *nxi,
14503 +       struct task_struct *task, const char *_file, int _line)
14504 +{
14505 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14506 +               nxi, nxi ? nxi->nx_id : 0,
14507 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14508 +               nxi?atomic_read(&nxi->nx_tasks):0,
14509 +               task, _file, _line);
14510 +
14511 +       atomic_inc(&nxi->nx_tasks);
14512 +}
14513 +
14514 +
14515 +extern void unhash_nx_info(struct nx_info *);
14516 +
14517 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14518 +
14519 +static inline void __release_nx_info(struct nx_info *nxi,
14520 +       struct task_struct *task, const char *_file, int _line)
14521 +{
14522 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14523 +               nxi, nxi ? nxi->nx_id : 0,
14524 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14525 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14526 +               task, _file, _line);
14527 +
14528 +       might_sleep();
14529 +
14530 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14531 +               unhash_nx_info(nxi);
14532 +}
14533 +
14534 +
14535 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14536 +
14537 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14538 +       const char *_file, int _line)
14539 +{
14540 +       struct nx_info *nxi;
14541 +
14542 +       task_lock(p);
14543 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14544 +               p, _file, _line);
14545 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14546 +       task_unlock(p);
14547 +       return nxi;
14548 +}
14549 +
14550 +
14551 +static inline void exit_nx_info(struct task_struct *p)
14552 +{
14553 +       if (p->nx_info)
14554 +               release_nx_info(p->nx_info, p);
14555 +}
14556 +
14557 +
14558 +#else
14559 +#warning duplicate inclusion
14560 +#endif
14561 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_pid.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_pid.h
14562 --- linux-2.6.27.14/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
14563 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_pid.h 2008-10-13 14:54:20.000000000 +0200
14564 @@ -0,0 +1,95 @@
14565 +#ifndef _VS_PID_H
14566 +#define _VS_PID_H
14567 +
14568 +#include "vserver/base.h"
14569 +#include "vserver/check.h"
14570 +#include "vserver/context.h"
14571 +#include "vserver/debug.h"
14572 +#include "vserver/pid.h"
14573 +#include <linux/pid_namespace.h>
14574 +
14575 +
14576 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14577 +
14578 +static inline
14579 +int vx_proc_task_visible(struct task_struct *task)
14580 +{
14581 +       if ((task->pid == 1) &&
14582 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14583 +               /* show a blend through init */
14584 +               goto visible;
14585 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14586 +               goto visible;
14587 +       return 0;
14588 +visible:
14589 +       return 1;
14590 +}
14591 +
14592 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14593 +
14594 +#if 0
14595 +
14596 +static inline
14597 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14598 +{
14599 +       struct task_struct *task = find_task_by_real_pid(pid);
14600 +
14601 +       if (task && !vx_proc_task_visible(task)) {
14602 +               vxdprintk(VXD_CBIT(misc, 6),
14603 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14604 +                       task, task->xid, task->pid,
14605 +                       current, current->xid, current->pid);
14606 +               task = NULL;
14607 +       }
14608 +       return task;
14609 +}
14610 +
14611 +#endif
14612 +
14613 +static inline
14614 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14615 +{
14616 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14617 +
14618 +       if (task && !vx_proc_task_visible(task)) {
14619 +               vxdprintk(VXD_CBIT(misc, 6),
14620 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14621 +                       task, task->xid, task->pid,
14622 +                       current, current->xid, current->pid);
14623 +               put_task_struct(task);
14624 +               task = NULL;
14625 +       }
14626 +       return task;
14627 +}
14628 +
14629 +#if 0
14630 +
14631 +static inline
14632 +struct task_struct *vx_child_reaper(struct task_struct *p)
14633 +{
14634 +       struct vx_info *vxi = p->vx_info;
14635 +       struct task_struct *reaper = child_reaper(p);
14636 +
14637 +       if (!vxi)
14638 +               goto out;
14639 +
14640 +       BUG_ON(!p->vx_info->vx_reaper);
14641 +
14642 +       /* child reaper for the guest reaper */
14643 +       if (vxi->vx_reaper == p)
14644 +               goto out;
14645 +
14646 +       reaper = vxi->vx_reaper;
14647 +out:
14648 +       vxdprintk(VXD_CBIT(xid, 7),
14649 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14650 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14651 +       return reaper;
14652 +}
14653 +
14654 +#endif
14655 +
14656 +
14657 +#else
14658 +#warning duplicate inclusion
14659 +#endif
14660 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_sched.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_sched.h
14661 --- linux-2.6.27.14/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
14662 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_sched.h       2008-10-13 14:54:20.000000000 +0200
14663 @@ -0,0 +1,110 @@
14664 +#ifndef _VS_SCHED_H
14665 +#define _VS_SCHED_H
14666 +
14667 +#include "vserver/base.h"
14668 +#include "vserver/context.h"
14669 +#include "vserver/sched.h"
14670 +
14671 +
14672 +#define VAVAVOOM_RATIO          50
14673 +
14674 +#define MAX_PRIO_BIAS           20
14675 +#define MIN_PRIO_BIAS          -20
14676 +
14677 +
14678 +#ifdef CONFIG_VSERVER_HARDCPU
14679 +
14680 +/*
14681 + * effective_prio - return the priority that is based on the static
14682 + * priority but is modified by bonuses/penalties.
14683 + *
14684 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14685 + * into a -4 ... 0 ... +4 bonus/penalty range.
14686 + *
14687 + * Additionally, we scale another amount based on the number of
14688 + * CPU tokens currently held by the context, if the process is
14689 + * part of a context (and the appropriate SCHED flag is set).
14690 + * This ranges from -5 ... 0 ... +15, quadratically.
14691 + *
14692 + * So, the total bonus is -9 .. 0 .. +19
14693 + * We use ~50% of the full 0...39 priority range so that:
14694 + *
14695 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14696 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14697 + *    unless that context is far exceeding its CPU allocation.
14698 + *
14699 + * Both properties are important to certain workloads.
14700 + */
14701 +static inline
14702 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14703 +{
14704 +       int vavavoom, max;
14705 +
14706 +       /* lots of tokens = lots of vavavoom
14707 +        *      no tokens = no vavavoom      */
14708 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14709 +               max = sched_pc->tokens_max;
14710 +               vavavoom = max - vavavoom;
14711 +               max = max * max;
14712 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14713 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14714 +               return vavavoom;
14715 +       }
14716 +       return 0;
14717 +}
14718 +
14719 +
14720 +static inline
14721 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14722 +{
14723 +       struct vx_info *vxi = p->vx_info;
14724 +       struct _vx_sched_pc *sched_pc;
14725 +
14726 +       if (!vxi)
14727 +               return prio;
14728 +
14729 +       sched_pc = &vx_cpu(vxi, sched_pc);
14730 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14731 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14732 +
14733 +               sched_pc->vavavoom = vavavoom;
14734 +               prio += vavavoom;
14735 +       }
14736 +       prio += sched_pc->prio_bias;
14737 +       return prio;
14738 +}
14739 +
14740 +#else /* !CONFIG_VSERVER_HARDCPU */
14741 +
14742 +static inline
14743 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14744 +{
14745 +       struct vx_info *vxi = p->vx_info;
14746 +
14747 +       if (vxi)
14748 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14749 +       return prio;
14750 +}
14751 +
14752 +#endif /* CONFIG_VSERVER_HARDCPU */
14753 +
14754 +
14755 +static inline void vx_account_user(struct vx_info *vxi,
14756 +       cputime_t cputime, int nice)
14757 +{
14758 +       if (!vxi)
14759 +               return;
14760 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14761 +}
14762 +
14763 +static inline void vx_account_system(struct vx_info *vxi,
14764 +       cputime_t cputime, int idle)
14765 +{
14766 +       if (!vxi)
14767 +               return;
14768 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14769 +}
14770 +
14771 +#else
14772 +#warning duplicate inclusion
14773 +#endif
14774 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_socket.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_socket.h
14775 --- linux-2.6.27.14/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
14776 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_socket.h      2008-10-13 14:54:20.000000000 +0200
14777 @@ -0,0 +1,67 @@
14778 +#ifndef _VS_SOCKET_H
14779 +#define _VS_SOCKET_H
14780 +
14781 +#include "vserver/debug.h"
14782 +#include "vserver/base.h"
14783 +#include "vserver/cacct.h"
14784 +#include "vserver/context.h"
14785 +#include "vserver/tag.h"
14786 +
14787 +
14788 +/* socket accounting */
14789 +
14790 +#include <linux/socket.h>
14791 +
14792 +static inline int vx_sock_type(int family)
14793 +{
14794 +       switch (family) {
14795 +       case PF_UNSPEC:
14796 +               return VXA_SOCK_UNSPEC;
14797 +       case PF_UNIX:
14798 +               return VXA_SOCK_UNIX;
14799 +       case PF_INET:
14800 +               return VXA_SOCK_INET;
14801 +       case PF_INET6:
14802 +               return VXA_SOCK_INET6;
14803 +       case PF_PACKET:
14804 +               return VXA_SOCK_PACKET;
14805 +       default:
14806 +               return VXA_SOCK_OTHER;
14807 +       }
14808 +}
14809 +
14810 +#define vx_acc_sock(v, f, p, s) \
14811 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14812 +
14813 +static inline void __vx_acc_sock(struct vx_info *vxi,
14814 +       int family, int pos, int size, char *file, int line)
14815 +{
14816 +       if (vxi) {
14817 +               int type = vx_sock_type(family);
14818 +
14819 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14820 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14821 +       }
14822 +}
14823 +
14824 +#define vx_sock_recv(sk, s) \
14825 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14826 +#define vx_sock_send(sk, s) \
14827 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14828 +#define vx_sock_fail(sk, s) \
14829 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14830 +
14831 +
14832 +#define sock_vx_init(s) do {           \
14833 +       (s)->sk_xid = 0;                \
14834 +       (s)->sk_vx_info = NULL;         \
14835 +       } while (0)
14836 +
14837 +#define sock_nx_init(s) do {           \
14838 +       (s)->sk_nid = 0;                \
14839 +       (s)->sk_nx_info = NULL;         \
14840 +       } while (0)
14841 +
14842 +#else
14843 +#warning duplicate inclusion
14844 +#endif
14845 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_tag.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_tag.h
14846 --- linux-2.6.27.14/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
14847 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_tag.h 2008-10-24 03:34:52.000000000 +0200
14848 @@ -0,0 +1,47 @@
14849 +#ifndef _VS_TAG_H
14850 +#define _VS_TAG_H
14851 +
14852 +#include <linux/vserver/tag.h>
14853 +
14854 +/* check conditions */
14855 +
14856 +#define DX_ADMIN       0x0001
14857 +#define DX_WATCH       0x0002
14858 +#define DX_HOSTID      0x0008
14859 +
14860 +#define DX_IDENT       0x0010
14861 +
14862 +#define DX_ARG_MASK    0x0010
14863 +
14864 +
14865 +#define dx_task_tag(t) ((t)->tag)
14866 +
14867 +#define dx_current_tag() dx_task_tag(current)
14868 +
14869 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14870 +
14871 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14872 +
14873 +
14874 +/*
14875 + * check current context for ADMIN/WATCH and
14876 + * optionally against supplied argument
14877 + */
14878 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14879 +{
14880 +       if (mode & DX_ARG_MASK) {
14881 +               if ((mode & DX_IDENT) && (id == cid))
14882 +                       return 1;
14883 +       }
14884 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14885 +               ((mode & DX_WATCH) && (cid == 1)) ||
14886 +               ((mode & DX_HOSTID) && (id == 0)));
14887 +}
14888 +
14889 +struct inode;
14890 +int dx_permission(struct inode *inode, int mask);
14891 +
14892 +
14893 +#else
14894 +#warning duplicate inclusion
14895 +#endif
14896 diff -NurpP --minimal linux-2.6.27.14/include/linux/vs_time.h linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_time.h
14897 --- linux-2.6.27.14/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
14898 +++ linux-2.6.27.14-vs2.3.0.36.4/include/linux/vs_time.h        2008-10-13 14:54:20.000000000 +0200
14899 @@ -0,0 +1,19 @@
14900 +#ifndef _VS_TIME_H
14901 +#define _VS_TIME_H
14902 +
14903 +
14904 +/* time faking stuff */
14905 +
14906 +#ifdef CONFIG_VSERVER_VTIME
14907 +
14908 +extern void vx_gettimeofday(struct timeval *tv);
14909 +extern int vx_settimeofday(struct timespec *ts);
14910 +
14911 +#else
14912 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14913 +#define        vx_settimeofday(t)      do_settimeofday(t)
14914 +#endif
14915 +
14916 +#else
14917 +#warning duplicate inclusion
14918 +#endif
14919 diff -NurpP --minimal linux-2.6.27.14/include/net/addrconf.h linux-2.6.27.14-vs2.3.0.36.4/include/net/addrconf.h
14920 --- linux-2.6.27.14/include/net/addrconf.h      2008-10-13 14:52:09.000000000 +0200
14921 +++ linux-2.6.27.14-vs2.3.0.36.4/include/net/addrconf.h 2008-10-13 14:54:20.000000000 +0200
14922 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14923                                                struct net_device *dev,
14924                                                const struct in6_addr *daddr,
14925                                                unsigned int srcprefs,
14926 -                                              struct in6_addr *saddr);
14927 +                                              struct in6_addr *saddr,
14928 +                                              struct nx_info *nxi);
14929  extern int                     ipv6_get_lladdr(struct net_device *dev,
14930                                                 struct in6_addr *addr,
14931                                                 unsigned char banned_flags);
14932 diff -NurpP --minimal linux-2.6.27.14/include/net/af_unix.h linux-2.6.27.14-vs2.3.0.36.4/include/net/af_unix.h
14933 --- linux-2.6.27.14/include/net/af_unix.h       2009-02-03 17:59:55.000000000 +0100
14934 +++ linux-2.6.27.14-vs2.3.0.36.4/include/net/af_unix.h  2009-02-03 17:59:04.000000000 +0100
14935 @@ -4,6 +4,7 @@
14936  #include <linux/socket.h>
14937  #include <linux/un.h>
14938  #include <linux/mutex.h>
14939 +#include <linux/vs_base.h>
14940  #include <net/sock.h>
14941  
14942  extern void unix_inflight(struct file *fp);
14943 diff -NurpP --minimal linux-2.6.27.14/include/net/inet_sock.h linux-2.6.27.14-vs2.3.0.36.4/include/net/inet_sock.h
14944 --- linux-2.6.27.14/include/net/inet_sock.h     2008-10-13 14:52:09.000000000 +0200
14945 +++ linux-2.6.27.14-vs2.3.0.36.4/include/net/inet_sock.h        2008-10-13 14:54:20.000000000 +0200
14946 @@ -24,7 +24,7 @@
14947  #include <net/flow.h>
14948  #include <net/sock.h>
14949  #include <net/request_sock.h>
14950 -#include <net/route.h>
14951 +// #include <net/route.h>
14952  #include <net/netns/hash.h>
14953  
14954  /** struct ip_options - IP Options
14955 @@ -195,11 +195,6 @@ static inline int inet_sk_ehashfn(const 
14956  }
14957  
14958  
14959 -static inline int inet_iif(const struct sk_buff *skb)
14960 -{
14961 -       return skb->rtable->rt_iif;
14962 -}
14963 -
14964  static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
14965  {
14966         struct request_sock *req = reqsk_alloc(ops);
14967 diff -NurpP --minimal linux-2.6.27.14/include/net/inet_timewait_sock.h linux-2.6.27.14-vs2.3.0.36.4/include/net/inet_timewait_sock.h
14968 --- linux-2.6.27.14/include/net/inet_timewait_sock.h    2008-10-13 14:52:09.000000000 +0200
14969 +++ linux-2.6.27.14-vs2.3.0.36.4/include/net/inet_timewait_sock.h       2008-10-13 14:54:20.000000000 +0200
14970 @@ -15,15 +15,14 @@
14971  #ifndef _INET_TIMEWAIT_SOCK_
14972  #define _INET_TIMEWAIT_SOCK_
14973  
14974 +// #include <net/inet_sock.h>
14975 +#include <net/sock.h>
14976  
14977  #include <linux/list.h>
14978  #include <linux/module.h>
14979  #include <linux/timer.h>
14980  #include <linux/types.h>
14981  #include <linux/workqueue.h>
14982 -
14983 -#include <net/inet_sock.h>
14984 -#include <net/sock.h>
14985  #include <net/tcp_states.h>
14986  #include <net/timewait_sock.h>
14987  
14988 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14989  #define tw_hash                        __tw_common.skc_hash
14990  #define tw_prot                        __tw_common.skc_prot
14991  #define tw_net                 __tw_common.skc_net
14992 +#define tw_xid                 __tw_common.skc_xid
14993 +#define tw_vx_info             __tw_common.skc_vx_info
14994 +#define tw_nid                 __tw_common.skc_nid
14995 +#define tw_nx_info             __tw_common.skc_nx_info
14996         int                     tw_timeout;
14997         volatile unsigned char  tw_substate;
14998         /* 3 bits hole, try to pack */
14999 diff -NurpP --minimal linux-2.6.27.14/include/net/route.h linux-2.6.27.14-vs2.3.0.36.4/include/net/route.h
15000 --- linux-2.6.27.14/include/net/route.h 2008-10-13 14:52:09.000000000 +0200
15001 +++ linux-2.6.27.14-vs2.3.0.36.4/include/net/route.h    2008-10-13 14:54:20.000000000 +0200
15002 @@ -28,6 +28,7 @@
15003  #include <net/inetpeer.h>
15004  #include <net/flow.h>
15005  #include <net/sock.h>
15006 +// #include <linux/in.h>
15007  #include <linux/in_route.h>
15008  #include <linux/rtnetlink.h>
15009  #include <linux/route.h>
15010 @@ -85,6 +86,11 @@ struct ip_rt_acct
15011         __u32   i_packets;
15012  };
15013  
15014 +static inline int inet_iif(const struct sk_buff *skb)
15015 +{
15016 +       return skb->rtable->rt_iif;
15017 +}
15018 +
15019  struct rt_cache_stat 
15020  {
15021          unsigned int in_hit;
15022 @@ -135,6 +141,9 @@ static inline void ip_rt_put(struct rtab
15023                 dst_release(&rt->u.dst);
15024  }
15025  
15026 +#include <linux/vs_base.h>
15027 +#include <linux/vs_inet.h>
15028 +
15029  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15030  
15031  extern const __u8 ip_tos2prio[16];
15032 @@ -144,6 +153,9 @@ static inline char rt_tos2priority(u8 to
15033         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15034  }
15035  
15036 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
15037 +       struct rtable **, struct flowi *);
15038 +
15039  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15040                                    __be32 src, u32 tos, int oif, u8 protocol,
15041                                    __be16 sport, __be16 dport, struct sock *sk,
15042 @@ -161,7 +173,21 @@ static inline int ip_route_connect(struc
15043  
15044         int err;
15045         struct net *net = sock_net(sk);
15046 -       if (!dst || !src) {
15047 +       struct nx_info *nx_info = current->nx_info;
15048 +
15049 +       if (sk)
15050 +               nx_info = sk->sk_nx_info;
15051 +
15052 +       vxdprintk(VXD_CBIT(net, 4),
15053 +               "ip_route_connect(%p) %p,%p;%lx",
15054 +               sk, nx_info, sk->sk_socket,
15055 +               (sk->sk_socket?sk->sk_socket->flags:0));
15056 +
15057 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
15058 +       if (err)
15059 +               return err;
15060 +
15061 +       if (!fl.fl4_dst || !fl.fl4_src) {
15062                 err = __ip_route_output_key(net, rp, &fl);
15063                 if (err)
15064                         return err;
15065 diff -NurpP --minimal linux-2.6.27.14/include/net/sock.h linux-2.6.27.14-vs2.3.0.36.4/include/net/sock.h
15066 --- linux-2.6.27.14/include/net/sock.h  2008-10-13 14:52:09.000000000 +0200
15067 +++ linux-2.6.27.14-vs2.3.0.36.4/include/net/sock.h     2008-10-13 14:54:20.000000000 +0200
15068 @@ -128,6 +128,10 @@ struct sock_common {
15069  #ifdef CONFIG_NET_NS
15070         struct net              *skc_net;
15071  #endif
15072 +       xid_t                   skc_xid;
15073 +       struct vx_info          *skc_vx_info;
15074 +       nid_t                   skc_nid;
15075 +       struct nx_info          *skc_nx_info;
15076  };
15077  
15078  /**
15079 @@ -211,6 +215,10 @@ struct sock {
15080  #define sk_hash                        __sk_common.skc_hash
15081  #define sk_prot                        __sk_common.skc_prot
15082  #define sk_net                 __sk_common.skc_net
15083 +#define sk_xid                 __sk_common.skc_xid
15084 +#define sk_vx_info             __sk_common.skc_vx_info
15085 +#define sk_nid                 __sk_common.skc_nid
15086 +#define sk_nx_info             __sk_common.skc_nx_info
15087         unsigned char           sk_shutdown : 2,
15088                                 sk_no_check : 2,
15089                                 sk_userlocks : 4;
15090 diff -NurpP --minimal linux-2.6.27.14/init/main.c linux-2.6.27.14-vs2.3.0.36.4/init/main.c
15091 --- linux-2.6.27.14/init/main.c 2008-10-13 14:52:09.000000000 +0200
15092 +++ linux-2.6.27.14-vs2.3.0.36.4/init/main.c    2008-10-13 14:54:20.000000000 +0200
15093 @@ -60,6 +60,7 @@
15094  #include <linux/sched.h>
15095  #include <linux/signal.h>
15096  #include <linux/idr.h>
15097 +#include <linux/vserver/percpu.h>
15098  
15099  #include <asm/io.h>
15100  #include <asm/bugs.h>
15101 @@ -391,12 +392,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15102  
15103  static void __init setup_per_cpu_areas(void)
15104  {
15105 -       unsigned long size, i;
15106 +       unsigned long size, vspc, i;
15107         char *ptr;
15108         unsigned long nr_possible_cpus = num_possible_cpus();
15109  
15110 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15111 +
15112         /* Copy section for each CPU (we discard the original) */
15113 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15114 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15115         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15116  
15117         for_each_possible_cpu(i) {
15118 diff -NurpP --minimal linux-2.6.27.14/ipc/mqueue.c linux-2.6.27.14-vs2.3.0.36.4/ipc/mqueue.c
15119 --- linux-2.6.27.14/ipc/mqueue.c        2009-02-03 17:59:55.000000000 +0100
15120 +++ linux-2.6.27.14-vs2.3.0.36.4/ipc/mqueue.c   2009-02-03 17:59:04.000000000 +0100
15121 @@ -31,6 +31,8 @@
15122  #include <linux/mutex.h>
15123  #include <linux/nsproxy.h>
15124  #include <linux/pid.h>
15125 +#include <linux/vs_context.h>
15126 +#include <linux/vs_limit.h>
15127  
15128  #include <net/sock.h>
15129  #include "util.h"
15130 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
15131         struct sigevent notify;
15132         struct pid* notify_owner;
15133         struct user_struct *user;       /* user who created, for accounting */
15134 +       struct vx_info *vxi;
15135         struct sock *notify_sock;
15136         struct sk_buff *notify_cookie;
15137  
15138 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
15139                         struct mqueue_inode_info *info;
15140                         struct task_struct *p = current;
15141                         struct user_struct *u = p->user;
15142 +                       struct vx_info *vxi = p->vx_info;
15143                         unsigned long mq_bytes, mq_msg_tblsz;
15144  
15145                         inode->i_fop = &mqueue_file_operations;
15146 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
15147                         info->notify_owner = NULL;
15148                         info->qsize = 0;
15149                         info->user = NULL;      /* set when all is ok */
15150 +                       info->vxi = NULL;
15151                         memset(&info->attr, 0, sizeof(info->attr));
15152                         info->attr.mq_maxmsg = DFLT_MSGMAX;
15153                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
15154 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
15155                         spin_lock(&mq_lock);
15156                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15157                             u->mq_bytes + mq_bytes >
15158 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15159 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15160 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15161                                 spin_unlock(&mq_lock);
15162                                 goto out_inode;
15163                         }
15164                         u->mq_bytes += mq_bytes;
15165 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15166                         spin_unlock(&mq_lock);
15167  
15168                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15169                         if (!info->messages) {
15170                                 spin_lock(&mq_lock);
15171                                 u->mq_bytes -= mq_bytes;
15172 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15173                                 spin_unlock(&mq_lock);
15174                                 goto out_inode;
15175                         }
15176                         /* all is ok */
15177                         info->user = get_uid(u);
15178 +                       info->vxi = get_vx_info(vxi);
15179                 } else if (S_ISDIR(mode)) {
15180                         inc_nlink(inode);
15181                         /* Some things misbehave if size == 0 on a directory */
15182 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
15183                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15184         user = info->user;
15185         if (user) {
15186 +               struct vx_info *vxi = info->vxi;
15187 +
15188                 spin_lock(&mq_lock);
15189                 user->mq_bytes -= mq_bytes;
15190 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15191                 queues_count--;
15192                 spin_unlock(&mq_lock);
15193 +               put_vx_info(vxi);
15194                 free_uid(user);
15195         }
15196  }
15197 diff -NurpP --minimal linux-2.6.27.14/ipc/msg.c linux-2.6.27.14-vs2.3.0.36.4/ipc/msg.c
15198 --- linux-2.6.27.14/ipc/msg.c   2009-02-03 17:59:55.000000000 +0100
15199 +++ linux-2.6.27.14-vs2.3.0.36.4/ipc/msg.c      2009-02-03 17:59:04.000000000 +0100
15200 @@ -38,6 +38,7 @@
15201  #include <linux/rwsem.h>
15202  #include <linux/nsproxy.h>
15203  #include <linux/ipc_namespace.h>
15204 +#include <linux/vs_base.h>
15205  
15206  #include <asm/current.h>
15207  #include <asm/uaccess.h>
15208 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
15209  
15210         msq->q_perm.mode = msgflg & S_IRWXUGO;
15211         msq->q_perm.key = key;
15212 +       msq->q_perm.xid = vx_current_xid();
15213  
15214         msq->q_perm.security = NULL;
15215         retval = security_msg_queue_alloc(msq);
15216 diff -NurpP --minimal linux-2.6.27.14/ipc/namespace.c linux-2.6.27.14-vs2.3.0.36.4/ipc/namespace.c
15217 --- linux-2.6.27.14/ipc/namespace.c     2008-07-13 23:51:29.000000000 +0200
15218 +++ linux-2.6.27.14-vs2.3.0.36.4/ipc/namespace.c        2008-10-13 14:54:20.000000000 +0200
15219 @@ -9,6 +9,8 @@
15220  #include <linux/rcupdate.h>
15221  #include <linux/nsproxy.h>
15222  #include <linux/slab.h>
15223 +#include <linux/vs_base.h>
15224 +#include <linux/vserver/global.h>
15225  
15226  #include "util.h"
15227  
15228 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
15229         register_ipcns_notifier(ns);
15230  
15231         kref_init(&ns->kref);
15232 +       atomic_inc(&vs_global_ipc_ns);
15233         return ns;
15234  }
15235  
15236 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
15237         sem_exit_ns(ns);
15238         msg_exit_ns(ns);
15239         shm_exit_ns(ns);
15240 +       atomic_dec(&vs_global_ipc_ns);
15241         kfree(ns);
15242         atomic_dec(&nr_ipc_ns);
15243  
15244 diff -NurpP --minimal linux-2.6.27.14/ipc/sem.c linux-2.6.27.14-vs2.3.0.36.4/ipc/sem.c
15245 --- linux-2.6.27.14/ipc/sem.c   2009-02-03 17:59:55.000000000 +0100
15246 +++ linux-2.6.27.14-vs2.3.0.36.4/ipc/sem.c      2009-02-03 17:59:04.000000000 +0100
15247 @@ -83,6 +83,8 @@
15248  #include <linux/rwsem.h>
15249  #include <linux/nsproxy.h>
15250  #include <linux/ipc_namespace.h>
15251 +#include <linux/vs_base.h>
15252 +#include <linux/vs_limit.h>
15253  
15254  #include <asm/uaccess.h>
15255  #include "util.h"
15256 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
15257  
15258         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15259         sma->sem_perm.key = key;
15260 +       sma->sem_perm.xid = vx_current_xid();
15261  
15262         sma->sem_perm.security = NULL;
15263         retval = security_sem_alloc(sma);
15264 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
15265                 return id;
15266         }
15267         ns->used_sems += nsems;
15268 +       /* FIXME: obsoleted? */
15269 +       vx_semary_inc(sma);
15270 +       vx_nsems_add(sma, nsems);
15271  
15272         sma->sem_base = (struct sem *) &sma[1];
15273         INIT_LIST_HEAD(&sma->sem_pending);
15274 diff -NurpP --minimal linux-2.6.27.14/ipc/shm.c linux-2.6.27.14-vs2.3.0.36.4/ipc/shm.c
15275 --- linux-2.6.27.14/ipc/shm.c   2009-02-03 17:59:55.000000000 +0100
15276 +++ linux-2.6.27.14-vs2.3.0.36.4/ipc/shm.c      2009-02-03 17:59:04.000000000 +0100
15277 @@ -39,6 +39,8 @@
15278  #include <linux/nsproxy.h>
15279  #include <linux/mount.h>
15280  #include <linux/ipc_namespace.h>
15281 +#include <linux/vs_context.h>
15282 +#include <linux/vs_limit.h>
15283  
15284  #include <asm/uaccess.h>
15285  
15286 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
15287   */
15288  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15289  {
15290 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15291 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15292 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15293 +
15294 +       vx_ipcshm_sub(vxi, shp, numpages);
15295 +       ns->shm_tot -= numpages;
15296 +
15297         shm_rmid(ns, shp);
15298         shm_unlock(shp);
15299         if (!is_file_hugepages(shp->shm_file))
15300 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
15301                                                 shp->mlock_user);
15302         fput (shp->shm_file);
15303         security_shm_free(shp);
15304 +       put_vx_info(vxi);
15305         ipc_rcu_putref(shp);
15306  }
15307  
15308 @@ -347,11 +355,15 @@ static int newseg(struct ipc_namespace *
15309         if (ns->shm_tot + numpages > ns->shm_ctlall)
15310                 return -ENOSPC;
15311  
15312 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15313 +               return -ENOSPC;
15314 +
15315         shp = ipc_rcu_alloc(sizeof(*shp));
15316         if (!shp)
15317                 return -ENOMEM;
15318  
15319         shp->shm_perm.key = key;
15320 +       shp->shm_perm.xid = vx_current_xid();
15321         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15322         shp->mlock_user = NULL;
15323  
15324 @@ -404,6 +416,7 @@ static int newseg(struct ipc_namespace *
15325         ns->shm_tot += numpages;
15326         error = shp->shm_perm.id;
15327         shm_unlock(shp);
15328 +       vx_ipcshm_add(current->vx_info, key, numpages);
15329         return error;
15330  
15331  no_id:
15332 diff -NurpP --minimal linux-2.6.27.14/kernel/capability.c linux-2.6.27.14-vs2.3.0.36.4/kernel/capability.c
15333 --- linux-2.6.27.14/kernel/capability.c 2009-02-03 17:59:55.000000000 +0100
15334 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/capability.c    2009-02-03 17:59:04.000000000 +0100
15335 @@ -13,6 +13,7 @@
15336  #include <linux/security.h>
15337  #include <linux/syscalls.h>
15338  #include <linux/pid_namespace.h>
15339 +#include <linux/vs_context.h>
15340  #include <asm/uaccess.h>
15341  
15342  /*
15343 @@ -166,6 +167,8 @@ static inline int cap_set_pg(int pgrp_nr
15344  
15345         pgrp = find_vpid(pgrp_nr);
15346         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
15347 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
15348 +                       continue;
15349                 target = g;
15350                 while_each_thread(g, target) {
15351                         if (!security_capset_check(target, effective,
15352 @@ -486,6 +489,8 @@ SYSCALL_DEFINE2(capset, cap_user_header_
15353         return ret;
15354  }
15355  
15356 +#include <linux/vserver/base.h>
15357 +
15358  /**
15359   * capable - Determine if the current task has a superior capability in effect
15360   * @cap: The capability to be tested for
15361 @@ -498,6 +503,9 @@ SYSCALL_DEFINE2(capset, cap_user_header_
15362   */
15363  int capable(int cap)
15364  {
15365 +       /* here for now so we don't require task locking */
15366 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15367 +               return 0;
15368         if (has_capability(current, cap)) {
15369                 current->flags |= PF_SUPERPRIV;
15370                 return 1;
15371 diff -NurpP --minimal linux-2.6.27.14/kernel/compat.c linux-2.6.27.14-vs2.3.0.36.4/kernel/compat.c
15372 --- linux-2.6.27.14/kernel/compat.c     2008-07-13 23:51:29.000000000 +0200
15373 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/compat.c        2008-10-13 14:54:20.000000000 +0200
15374 @@ -845,7 +845,7 @@ asmlinkage long compat_sys_time(compat_t
15375         compat_time_t i;
15376         struct timeval tv;
15377  
15378 -       do_gettimeofday(&tv);
15379 +       vx_gettimeofday(&tv);
15380         i = tv.tv_sec;
15381  
15382         if (tloc) {
15383 @@ -869,7 +869,7 @@ asmlinkage long compat_sys_stime(compat_
15384         if (err)
15385                 return err;
15386  
15387 -       do_settimeofday(&tv);
15388 +       vx_settimeofday(&tv);
15389         return 0;
15390  }
15391  
15392 diff -NurpP --minimal linux-2.6.27.14/kernel/exit.c linux-2.6.27.14-vs2.3.0.36.4/kernel/exit.c
15393 --- linux-2.6.27.14/kernel/exit.c       2009-02-03 17:59:55.000000000 +0100
15394 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/exit.c  2009-02-03 17:59:04.000000000 +0100
15395 @@ -47,6 +47,11 @@
15396  #include <linux/blkdev.h>
15397  #include <linux/task_io_accounting_ops.h>
15398  #include <linux/tracehook.h>
15399 +#include <linux/vs_limit.h>
15400 +#include <linux/vs_context.h>
15401 +#include <linux/vs_network.h>
15402 +#include <linux/vs_pid.h>
15403 +#include <linux/vserver/global.h>
15404  
15405  #include <asm/uaccess.h>
15406  #include <asm/unistd.h>
15407 @@ -485,9 +490,11 @@ static void close_files(struct files_str
15408                                         filp_close(file, files);
15409                                         cond_resched();
15410                                 }
15411 +                               vx_openfd_dec(i);
15412                         }
15413                         i++;
15414                         set >>= 1;
15415 +                       cond_resched();
15416                 }
15417         }
15418  }
15419 @@ -554,6 +561,7 @@ void put_fs_struct(struct fs_struct *fs)
15420         if (atomic_dec_and_test(&fs->count)) {
15421                 path_put(&fs->root);
15422                 path_put(&fs->pwd);
15423 +               atomic_dec(&vs_global_fs);
15424                 kmem_cache_free(fs_cachep, fs);
15425         }
15426  }
15427 @@ -1122,6 +1130,10 @@ NORET_TYPE void do_exit(long code)
15428         if (tsk->splice_pipe)
15429                 __free_pipe_info(tsk->splice_pipe);
15430  
15431 +       /* needs to stay after exit_notify() */
15432 +       exit_vx_info(tsk, code);
15433 +       exit_nx_info(tsk);
15434 +
15435         preempt_disable();
15436         /* causes final put_task_struct in finish_task_switch(). */
15437         tsk->state = TASK_DEAD;
15438 diff -NurpP --minimal linux-2.6.27.14/kernel/fork.c linux-2.6.27.14-vs2.3.0.36.4/kernel/fork.c
15439 --- linux-2.6.27.14/kernel/fork.c       2009-02-03 17:59:55.000000000 +0100
15440 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/fork.c  2009-02-03 17:59:04.000000000 +0100
15441 @@ -58,6 +58,11 @@
15442  #include <linux/tty.h>
15443  #include <linux/proc_fs.h>
15444  #include <linux/blkdev.h>
15445 +#include <linux/vs_context.h>
15446 +#include <linux/vs_network.h>
15447 +#include <linux/vs_limit.h>
15448 +#include <linux/vs_memory.h>
15449 +#include <linux/vserver/global.h>
15450  
15451  #include <asm/pgtable.h>
15452  #include <asm/pgalloc.h>
15453 @@ -135,6 +140,8 @@ void free_task(struct task_struct *tsk)
15454         prop_local_destroy_single(&tsk->dirties);
15455         free_thread_info(tsk->stack);
15456         rt_mutex_debug_task_free(tsk);
15457 +       clr_vx_info(&tsk->vx_info);
15458 +       clr_nx_info(&tsk->nx_info);
15459         free_task_struct(tsk);
15460  }
15461  EXPORT_SYMBOL(free_task);
15462 @@ -274,6 +281,8 @@ static int dup_mmap(struct mm_struct *mm
15463         mm->free_area_cache = oldmm->mmap_base;
15464         mm->cached_hole_size = ~0UL;
15465         mm->map_count = 0;
15466 +       __set_mm_counter(mm, file_rss, 0);
15467 +       __set_mm_counter(mm, anon_rss, 0);
15468         cpus_clear(mm->cpu_vm_mask);
15469         mm->mm_rb = RB_ROOT;
15470         rb_link = &mm->mm_rb.rb_node;
15471 @@ -285,7 +294,7 @@ static int dup_mmap(struct mm_struct *mm
15472  
15473                 if (mpnt->vm_flags & VM_DONTCOPY) {
15474                         long pages = vma_pages(mpnt);
15475 -                       mm->total_vm -= pages;
15476 +                       vx_vmpages_sub(mm, pages);
15477                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15478                                                                 -pages);
15479                         continue;
15480 @@ -407,8 +416,8 @@ static struct mm_struct * mm_init(struct
15481                                   : MMF_DUMP_FILTER_DEFAULT;
15482         mm->core_state = NULL;
15483         mm->nr_ptes = 0;
15484 -       set_mm_counter(mm, file_rss, 0);
15485 -       set_mm_counter(mm, anon_rss, 0);
15486 +       __set_mm_counter(mm, file_rss, 0);
15487 +       __set_mm_counter(mm, anon_rss, 0);
15488         spin_lock_init(&mm->page_table_lock);
15489         rwlock_init(&mm->ioctx_list_lock);
15490         mm->ioctx_list = NULL;
15491 @@ -419,6 +428,7 @@ static struct mm_struct * mm_init(struct
15492         if (likely(!mm_alloc_pgd(mm))) {
15493                 mm->def_flags = 0;
15494                 mmu_notifier_mm_init(mm);
15495 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15496                 return mm;
15497         }
15498  
15499 @@ -452,6 +462,7 @@ void __mmdrop(struct mm_struct *mm)
15500         mm_free_pgd(mm);
15501         destroy_context(mm);
15502         mmu_notifier_mm_destroy(mm);
15503 +       clr_vx_info(&mm->mm_vx_info);
15504         free_mm(mm);
15505  }
15506  EXPORT_SYMBOL_GPL(__mmdrop);
15507 @@ -568,6 +579,7 @@ struct mm_struct *dup_mm(struct task_str
15508                 goto fail_nomem;
15509  
15510         memcpy(mm, oldmm, sizeof(*mm));
15511 +       mm->mm_vx_info = NULL;
15512  
15513         /* Initializing for Swap token stuff */
15514         mm->token_priority = 0;
15515 @@ -601,6 +613,7 @@ fail_nocontext:
15516          * If init_new_context() failed, we cannot use mmput() to free the mm
15517          * because it calls destroy_context()
15518          */
15519 +       clr_vx_info(&mm->mm_vx_info);
15520         mm_free_pgd(mm);
15521         free_mm(mm);
15522         return NULL;
15523 @@ -664,6 +677,7 @@ static struct fs_struct *__copy_fs_struc
15524                 fs->pwd = old->pwd;
15525                 path_get(&old->pwd);
15526                 read_unlock(&old->lock);
15527 +               atomic_inc(&vs_global_fs);
15528         }
15529         return fs;
15530  }
15531 @@ -907,6 +921,8 @@ static struct task_struct *copy_process(
15532         int retval;
15533         struct task_struct *p;
15534         int cgroup_callbacks_done = 0;
15535 +       struct vx_info *vxi;
15536 +       struct nx_info *nxi;
15537  
15538         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15539                 return ERR_PTR(-EINVAL);
15540 @@ -941,12 +957,28 @@ static struct task_struct *copy_process(
15541         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15542         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15543  #endif
15544 +       init_vx_info(&p->vx_info, current->vx_info);
15545 +       init_nx_info(&p->nx_info, current->nx_info);
15546 +
15547 +       /* check vserver memory */
15548 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15549 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15550 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15551 +               else
15552 +                       goto bad_fork_free;
15553 +       }
15554 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15555 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15556 +                       goto bad_fork_cleanup_vm;
15557 +       }
15558         retval = -EAGAIN;
15559 +       if (!vx_nproc_avail(1))
15560 +               goto bad_fork_cleanup_vm;
15561         if (atomic_read(&p->user->processes) >=
15562                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15563                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15564                     p->user != current->nsproxy->user_ns->root_user)
15565 -                       goto bad_fork_free;
15566 +                       goto bad_fork_cleanup_vm;
15567         }
15568  
15569         atomic_inc(&p->user->__count);
15570 @@ -1244,6 +1276,18 @@ static struct task_struct *copy_process(
15571  
15572         total_forks++;
15573         spin_unlock(&current->sighand->siglock);
15574 +
15575 +       /* p is copy of current */
15576 +       vxi = p->vx_info;
15577 +       if (vxi) {
15578 +               claim_vx_info(vxi, p);
15579 +               atomic_inc(&vxi->cvirt.nr_threads);
15580 +               atomic_inc(&vxi->cvirt.total_forks);
15581 +               vx_nproc_inc(p);
15582 +       }
15583 +       nxi = p->nx_info;
15584 +       if (nxi)
15585 +               claim_nx_info(nxi, p);
15586         write_unlock_irq(&tasklist_lock);
15587         proc_fork_connector(p);
15588         cgroup_post_fork(p);
15589 @@ -1290,6 +1334,9 @@ bad_fork_cleanup_count:
15590         put_group_info(p->group_info);
15591         atomic_dec(&p->user->processes);
15592         free_uid(p->user);
15593 +bad_fork_cleanup_vm:
15594 +       if (p->mm && !(clone_flags & CLONE_VM))
15595 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15596  bad_fork_free:
15597         free_task(p);
15598  fork_out:
15599 diff -NurpP --minimal linux-2.6.27.14/kernel/kthread.c linux-2.6.27.14-vs2.3.0.36.4/kernel/kthread.c
15600 --- linux-2.6.27.14/kernel/kthread.c    2008-10-13 14:52:09.000000000 +0200
15601 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/kthread.c       2008-10-13 14:54:20.000000000 +0200
15602 @@ -13,6 +13,7 @@
15603  #include <linux/file.h>
15604  #include <linux/module.h>
15605  #include <linux/mutex.h>
15606 +#include <linux/vs_pid.h>
15607  
15608  #define KTHREAD_NICE_LEVEL (-5)
15609  
15610 @@ -98,7 +99,7 @@ static void create_kthread(struct kthrea
15611                 struct sched_param param = { .sched_priority = 0 };
15612                 wait_for_completion(&create->started);
15613                 read_lock(&tasklist_lock);
15614 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15615 +               create->result = find_task_by_real_pid(pid);
15616                 read_unlock(&tasklist_lock);
15617                 /*
15618                  * root may have changed our (kthreadd's) priority or CPU mask.
15619 diff -NurpP --minimal linux-2.6.27.14/kernel/Makefile linux-2.6.27.14-vs2.3.0.36.4/kernel/Makefile
15620 --- linux-2.6.27.14/kernel/Makefile     2009-02-03 17:59:55.000000000 +0100
15621 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/Makefile        2009-02-03 17:59:04.000000000 +0100
15622 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15623  CFLAGS_REMOVE_sched.o = -pg
15624  endif
15625  
15626 +obj-y += vserver/
15627  obj-$(CONFIG_PROFILING) += profile.o
15628  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15629  obj-$(CONFIG_STACKTRACE) += stacktrace.o
15630 diff -NurpP --minimal linux-2.6.27.14/kernel/nsproxy.c linux-2.6.27.14-vs2.3.0.36.4/kernel/nsproxy.c
15631 --- linux-2.6.27.14/kernel/nsproxy.c    2008-10-13 14:52:09.000000000 +0200
15632 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/nsproxy.c       2008-10-13 14:54:20.000000000 +0200
15633 @@ -19,6 +19,8 @@
15634  #include <linux/mnt_namespace.h>
15635  #include <linux/utsname.h>
15636  #include <linux/pid_namespace.h>
15637 +#include <linux/vserver/global.h>
15638 +#include <linux/vserver/debug.h>
15639  #include <net/net_namespace.h>
15640  #include <linux/ipc_namespace.h>
15641  
15642 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15643         if (ns) {
15644                 memcpy(ns, orig, sizeof(struct nsproxy));
15645                 atomic_set(&ns->count, 1);
15646 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15647 +                       orig, atomic_read(&orig->count), ns);
15648 +               atomic_inc(&vs_global_nsproxy);
15649         }
15650         return ns;
15651  }
15652 @@ -46,47 +51,51 @@ static inline struct nsproxy *clone_nspr
15653   * Return the newly created nsproxy.  Do not attach this to the task,
15654   * leave it to the caller to do proper locking and attach it to task.
15655   */
15656 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15657 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15658 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15659 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15660  {
15661         struct nsproxy *new_nsp;
15662         int err;
15663  
15664 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15665 +       vxdprintk(VXD_CBIT(space, 4),
15666 +               "unshare_namespaces(0x%08lx,%p,%p)",
15667 +               flags, orig, new_fs);
15668 +
15669 +       new_nsp = clone_nsproxy(orig);
15670         if (!new_nsp)
15671                 return ERR_PTR(-ENOMEM);
15672  
15673 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15674 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15675         if (IS_ERR(new_nsp->mnt_ns)) {
15676                 err = PTR_ERR(new_nsp->mnt_ns);
15677                 goto out_ns;
15678         }
15679  
15680 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15681 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15682         if (IS_ERR(new_nsp->uts_ns)) {
15683                 err = PTR_ERR(new_nsp->uts_ns);
15684                 goto out_uts;
15685         }
15686  
15687 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15688 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15689         if (IS_ERR(new_nsp->ipc_ns)) {
15690                 err = PTR_ERR(new_nsp->ipc_ns);
15691                 goto out_ipc;
15692         }
15693  
15694 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15695 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15696         if (IS_ERR(new_nsp->pid_ns)) {
15697                 err = PTR_ERR(new_nsp->pid_ns);
15698                 goto out_pid;
15699         }
15700  
15701 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
15702 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15703         if (IS_ERR(new_nsp->user_ns)) {
15704                 err = PTR_ERR(new_nsp->user_ns);
15705                 goto out_user;
15706         }
15707  
15708 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15709 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15710         if (IS_ERR(new_nsp->net_ns)) {
15711                 err = PTR_ERR(new_nsp->net_ns);
15712                 goto out_net;
15713 @@ -114,6 +123,37 @@ out_ns:
15714         return ERR_PTR(err);
15715  }
15716  
15717 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15718 +                       struct fs_struct *new_fs)
15719 +{
15720 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15721 +}
15722 +
15723 +/*
15724 + * copies the nsproxy, setting refcount to 1, and grabbing a
15725 + * reference to all contained namespaces.
15726 + */
15727 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15728 +{
15729 +       struct nsproxy *ns = clone_nsproxy(orig);
15730 +
15731 +       if (ns) {
15732 +               if (ns->mnt_ns)
15733 +                       get_mnt_ns(ns->mnt_ns);
15734 +               if (ns->uts_ns)
15735 +                       get_uts_ns(ns->uts_ns);
15736 +               if (ns->ipc_ns)
15737 +                       get_ipc_ns(ns->ipc_ns);
15738 +               if (ns->pid_ns)
15739 +                       get_pid_ns(ns->pid_ns);
15740 +               if (ns->user_ns)
15741 +                       get_user_ns(ns->user_ns);
15742 +               if (ns->net_ns)
15743 +                       get_net(ns->net_ns);
15744 +       }
15745 +       return ns;
15746 +}
15747 +
15748  /*
15749   * called from clone.  This now handles copy for nsproxy and all
15750   * namespaces therein.
15751 @@ -121,9 +161,12 @@ out_ns:
15752  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15753  {
15754         struct nsproxy *old_ns = tsk->nsproxy;
15755 -       struct nsproxy *new_ns;
15756 +       struct nsproxy *new_ns = NULL;
15757         int err = 0;
15758  
15759 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15760 +               flags, tsk, old_ns);
15761 +
15762         if (!old_ns)
15763                 return 0;
15764  
15765 @@ -160,6 +203,9 @@ int copy_namespaces(unsigned long flags,
15766  
15767  out:
15768         put_nsproxy(old_ns);
15769 +       vxdprintk(VXD_CBIT(space, 3),
15770 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15771 +               flags, tsk, old_ns, err, new_ns);
15772         return err;
15773  }
15774  
15775 @@ -175,7 +221,9 @@ void free_nsproxy(struct nsproxy *ns)
15776                 put_pid_ns(ns->pid_ns);
15777         if (ns->user_ns)
15778                 put_user_ns(ns->user_ns);
15779 -       put_net(ns->net_ns);
15780 +       if (ns->net_ns)
15781 +               put_net(ns->net_ns);
15782 +       atomic_dec(&vs_global_nsproxy);
15783         kmem_cache_free(nsproxy_cachep, ns);
15784  }
15785  
15786 @@ -188,6 +236,10 @@ int unshare_nsproxy_namespaces(unsigned 
15787  {
15788         int err = 0;
15789  
15790 +       vxdprintk(VXD_CBIT(space, 4),
15791 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15792 +               unshare_flags, current->nsproxy);
15793 +
15794         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15795                                CLONE_NEWUSER | CLONE_NEWNET)))
15796                 return 0;
15797 diff -NurpP --minimal linux-2.6.27.14/kernel/pid.c linux-2.6.27.14-vs2.3.0.36.4/kernel/pid.c
15798 --- linux-2.6.27.14/kernel/pid.c        2008-10-13 14:52:09.000000000 +0200
15799 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/pid.c   2008-10-13 14:54:20.000000000 +0200
15800 @@ -36,6 +36,8 @@
15801  #include <linux/pid_namespace.h>
15802  #include <linux/init_task.h>
15803  #include <linux/syscalls.h>
15804 +#include <linux/vs_pid.h>
15805 +#include <linux/vserver/global.h>
15806  
15807  #define pid_hashfn(nr, ns)     \
15808         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15809 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15810  
15811  struct pid *find_vpid(int nr)
15812  {
15813 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15814 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15815  }
15816  EXPORT_SYMBOL_GPL(find_vpid);
15817  
15818 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15819  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15820  {
15821         struct task_struct *result = NULL;
15822 +
15823 +       if (type == PIDTYPE_REALPID)
15824 +               type = PIDTYPE_PID;
15825         if (pid) {
15826                 struct hlist_node *first;
15827                 first = rcu_dereference(pid->tasks[type].first);
15828 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15829  
15830  struct task_struct *find_task_by_vpid(pid_t vnr)
15831  {
15832 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15833 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15834                         current->nsproxy->pid_ns);
15835  }
15836  EXPORT_SYMBOL(find_task_by_vpid);
15837  
15838  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15839  {
15840 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15841 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15842  }
15843  EXPORT_SYMBOL(find_task_by_pid_ns);
15844  
15845 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15846  }
15847  EXPORT_SYMBOL_GPL(find_get_pid);
15848  
15849 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15850 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15851  {
15852         struct upid *upid;
15853         pid_t nr = 0;
15854 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15855         return nr;
15856  }
15857  
15858 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15859 +{
15860 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15861 +}
15862 +
15863  pid_t pid_vnr(struct pid *pid)
15864  {
15865         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15866 diff -NurpP --minimal linux-2.6.27.14/kernel/pid_namespace.c linux-2.6.27.14-vs2.3.0.36.4/kernel/pid_namespace.c
15867 --- linux-2.6.27.14/kernel/pid_namespace.c      2008-10-13 14:52:09.000000000 +0200
15868 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/pid_namespace.c 2008-10-13 14:54:20.000000000 +0200
15869 @@ -13,6 +13,7 @@
15870  #include <linux/syscalls.h>
15871  #include <linux/err.h>
15872  #include <linux/acct.h>
15873 +#include <linux/vserver/global.h>
15874  
15875  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15876  
15877 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15878                 goto out_free_map;
15879  
15880         kref_init(&ns->kref);
15881 +       atomic_inc(&vs_global_pid_ns);
15882         ns->level = level;
15883  
15884         set_bit(0, ns->pidmap[0].page);
15885 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15886  
15887         for (i = 0; i < PIDMAP_ENTRIES; i++)
15888                 kfree(ns->pidmap[i].page);
15889 +       atomic_dec(&vs_global_pid_ns);
15890         kmem_cache_free(pid_ns_cachep, ns);
15891  }
15892  
15893 diff -NurpP --minimal linux-2.6.27.14/kernel/posix-timers.c linux-2.6.27.14-vs2.3.0.36.4/kernel/posix-timers.c
15894 --- linux-2.6.27.14/kernel/posix-timers.c       2009-02-03 17:59:55.000000000 +0100
15895 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/posix-timers.c  2009-02-03 17:59:04.000000000 +0100
15896 @@ -46,6 +46,7 @@
15897  #include <linux/wait.h>
15898  #include <linux/workqueue.h>
15899  #include <linux/module.h>
15900 +#include <linux/vs_context.h>
15901  
15902  /*
15903   * Management arrays for POSIX timers.  Timers are kept in slab memory
15904 @@ -298,6 +299,12 @@ void do_schedule_next_timer(struct sigin
15905  
15906  int posix_timer_event(struct k_itimer *timr, int si_private)
15907  {
15908 +       struct vx_info_save vxis;
15909 +       struct vx_info *vxi;
15910 +       int ret;
15911 +
15912 +       vxi = task_get_vx_info(timr->it_process);
15913 +       enter_vx_info(vxi, &vxis);
15914         /*
15915          * FIXME: if ->sigq is queued we can race with
15916          * dequeue_signal()->do_schedule_next_timer().
15917 @@ -318,10 +325,11 @@ int posix_timer_event(struct k_itimer *t
15918  
15919         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
15920                 struct task_struct *leader;
15921 -               int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15922 +
15923 +               ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15924  
15925                 if (likely(ret >= 0))
15926 -                       return ret;
15927 +                       goto out;
15928  
15929                 timr->it_sigev_notify = SIGEV_SIGNAL;
15930                 leader = timr->it_process->group_leader;
15931 @@ -329,7 +337,11 @@ int posix_timer_event(struct k_itimer *t
15932                 timr->it_process = leader;
15933         }
15934  
15935 -       return send_sigqueue(timr->sigq, timr->it_process, 1);
15936 +       ret = send_sigqueue(timr->sigq, timr->it_process, 1);
15937 +out:
15938 +       leave_vx_info(&vxis);
15939 +       put_vx_info(vxi);
15940 +       return ret;
15941  }
15942  EXPORT_SYMBOL_GPL(posix_timer_event);
15943  
15944 diff -NurpP --minimal linux-2.6.27.14/kernel/printk.c linux-2.6.27.14-vs2.3.0.36.4/kernel/printk.c
15945 --- linux-2.6.27.14/kernel/printk.c     2009-02-03 17:59:55.000000000 +0100
15946 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/printk.c        2009-02-03 17:59:04.000000000 +0100
15947 @@ -32,6 +32,7 @@
15948  #include <linux/security.h>
15949  #include <linux/bootmem.h>
15950  #include <linux/syscalls.h>
15951 +#include <linux/vs_cvirt.h>
15952  
15953  #include <asm/uaccess.h>
15954  
15955 @@ -291,18 +292,13 @@ int do_syslog(int type, char __user *buf
15956         unsigned i, j, limit, count;
15957         int do_clear = 0;
15958         char c;
15959 -       int error = 0;
15960 +       int error;
15961  
15962         error = security_syslog(type);
15963         if (error)
15964                 return error;
15965  
15966 -       switch (type) {
15967 -       case 0:         /* Close log */
15968 -               break;
15969 -       case 1:         /* Open log */
15970 -               break;
15971 -       case 2:         /* Read from log */
15972 +       if ((type >= 2) && (type <= 4)) {
15973                 error = -EINVAL;
15974                 if (!buf || len < 0)
15975                         goto out;
15976 @@ -313,6 +309,16 @@ int do_syslog(int type, char __user *buf
15977                         error = -EFAULT;
15978                         goto out;
15979                 }
15980 +       }
15981 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15982 +               return vx_do_syslog(type, buf, len);
15983 +
15984 +       switch (type) {
15985 +       case 0:         /* Close log */
15986 +               break;
15987 +       case 1:         /* Open log */
15988 +               break;
15989 +       case 2:         /* Read from log */
15990                 error = wait_event_interruptible(log_wait,
15991                                                         (log_start - log_end));
15992                 if (error)
15993 @@ -337,16 +343,6 @@ int do_syslog(int type, char __user *buf
15994                 do_clear = 1;
15995                 /* FALL THRU */
15996         case 3:         /* Read last kernel messages */
15997 -               error = -EINVAL;
15998 -               if (!buf || len < 0)
15999 -                       goto out;
16000 -               error = 0;
16001 -               if (!len)
16002 -                       goto out;
16003 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16004 -                       error = -EFAULT;
16005 -                       goto out;
16006 -               }
16007                 count = len;
16008                 if (count > log_buf_len)
16009                         count = log_buf_len;
16010 diff -NurpP --minimal linux-2.6.27.14/kernel/ptrace.c linux-2.6.27.14-vs2.3.0.36.4/kernel/ptrace.c
16011 --- linux-2.6.27.14/kernel/ptrace.c     2009-02-03 17:59:55.000000000 +0100
16012 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/ptrace.c        2009-02-03 17:59:04.000000000 +0100
16013 @@ -21,6 +21,7 @@
16014  #include <linux/audit.h>
16015  #include <linux/pid_namespace.h>
16016  #include <linux/syscalls.h>
16017 +#include <linux/vs_context.h>
16018  
16019  #include <asm/pgtable.h>
16020  #include <asm/uaccess.h>
16021 @@ -139,6 +140,11 @@ int __ptrace_may_access(struct task_stru
16022                 dumpable = get_dumpable(task->mm);
16023         if (!dumpable && !capable(CAP_SYS_PTRACE))
16024                 return -EPERM;
16025 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16026 +               return -EPERM;
16027 +       if (!vx_check(task->xid, VS_IDENT) &&
16028 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16029 +               return -EACCES;
16030  
16031         return security_ptrace_may_access(task, mode);
16032  }
16033 @@ -567,6 +573,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
16034                 goto out;
16035         }
16036  
16037 +       ret = -EPERM;
16038 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16039 +               goto out_put_task_struct;
16040 +
16041         if (request == PTRACE_ATTACH) {
16042                 ret = ptrace_attach(child);
16043                 /*
16044 diff -NurpP --minimal linux-2.6.27.14/kernel/sched.c linux-2.6.27.14-vs2.3.0.36.4/kernel/sched.c
16045 --- linux-2.6.27.14/kernel/sched.c      2009-02-03 17:59:55.000000000 +0100
16046 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sched.c 2009-02-03 17:59:04.000000000 +0100
16047 @@ -71,6 +71,8 @@
16048  #include <linux/debugfs.h>
16049  #include <linux/ctype.h>
16050  #include <linux/ftrace.h>
16051 +#include <linux/vs_sched.h>
16052 +#include <linux/vs_cvirt.h>
16053  
16054  #include <asm/tlb.h>
16055  #include <asm/irq_regs.h>
16056 @@ -497,6 +499,16 @@ struct root_domain {
16057  static struct root_domain def_root_domain;
16058  
16059  #endif
16060 +       unsigned long norm_time;
16061 +       unsigned long idle_time;
16062 +#ifdef CONFIG_VSERVER_IDLETIME
16063 +       int idle_skip;
16064 +#endif
16065 +#ifdef CONFIG_VSERVER_HARDCPU
16066 +       struct list_head hold_queue;
16067 +       unsigned long nr_onhold;
16068 +       int idle_tokens;
16069 +#endif
16070  
16071  /*
16072   * This is the main, per-CPU runqueue data structure.
16073 @@ -1640,6 +1652,7 @@ static void update_avg(u64 *avg, u64 sam
16074  
16075  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
16076  {
16077 +       // BUG_ON(p->state & TASK_ONHOLD);
16078         sched_info_queued(p);
16079         p->sched_class->enqueue_task(rq, p, wakeup);
16080         p->se.on_rq = 1;
16081 @@ -1837,6 +1850,9 @@ struct migration_req {
16082         struct completion done;
16083  };
16084  
16085 +#include "sched_mon.h"
16086 +
16087 +
16088  /*
16089   * The task's runqueue lock must be held.
16090   * Returns true if you have to wait for migration thread.
16091 @@ -1846,6 +1862,7 @@ migrate_task(struct task_struct *p, int 
16092  {
16093         struct rq *rq = task_rq(p);
16094  
16095 +       vxm_migrate_task(p, rq, dest_cpu);
16096         /*
16097          * If the task is not on a runqueue (and not running), then
16098          * it is sufficient to simply update the task's cpu field.
16099 @@ -2242,6 +2259,12 @@ static int try_to_wake_up(struct task_st
16100                 /* might preempt at this point */
16101                 rq = task_rq_lock(p, &flags);
16102                 old_state = p->state;
16103 +
16104 +       /* we need to unhold suspended tasks
16105 +       if (old_state & TASK_ONHOLD) {
16106 +               vx_unhold_task(p, rq);
16107 +               old_state = p->state;
16108 +       } */
16109                 if (!(old_state & state))
16110                         goto out;
16111                 if (p->se.on_rq)
16112 @@ -4067,13 +4090,16 @@ unsigned long long task_sched_runtime(st
16113  void account_user_time(struct task_struct *p, cputime_t cputime)
16114  {
16115         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16116 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16117         cputime64_t tmp;
16118 +       int nice = (TASK_NICE(p) > 0);
16119  
16120         p->utime = cputime_add(p->utime, cputime);
16121 +       vx_account_user(vxi, cputime, nice);
16122  
16123         /* Add user time to cpustat. */
16124         tmp = cputime_to_cputime64(cputime);
16125 -       if (TASK_NICE(p) > 0)
16126 +       if (nice)
16127                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16128         else
16129                 cpustat->user = cputime64_add(cpustat->user, tmp);
16130 @@ -4120,6 +4146,7 @@ void account_system_time(struct task_str
16131                          cputime_t cputime)
16132  {
16133         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16134 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16135         struct rq *rq = this_rq();
16136         cputime64_t tmp;
16137  
16138 @@ -4129,6 +4156,7 @@ void account_system_time(struct task_str
16139         }
16140  
16141         p->stime = cputime_add(p->stime, cputime);
16142 +       vx_account_system(vxi, cputime, (p == rq->idle));
16143  
16144         /* Add system time to cpustat. */
16145         tmp = cputime_to_cputime64(cputime);
16146 @@ -4963,7 +4991,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16147                 nice = 19;
16148  
16149         if (increment < 0 && !can_nice(current, nice))
16150 -               return -EPERM;
16151 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16152  
16153         retval = security_task_setnice(current, nice);
16154         if (retval)
16155 diff -NurpP --minimal linux-2.6.27.14/kernel/sched_fair.c linux-2.6.27.14-vs2.3.0.36.4/kernel/sched_fair.c
16156 --- linux-2.6.27.14/kernel/sched_fair.c 2008-10-13 14:52:09.000000000 +0200
16157 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sched_fair.c    2008-10-13 14:54:20.000000000 +0200
16158 @@ -724,6 +724,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16159         check_spread(cfs_rq, se);
16160         if (se != cfs_rq->curr)
16161                 __enqueue_entity(cfs_rq, se);
16162 +
16163 +       if (entity_is_task(se))
16164 +               vx_activate_task(task_of(se));
16165  }
16166  
16167  static void
16168 @@ -750,6 +753,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16169  
16170         if (se != cfs_rq->curr)
16171                 __dequeue_entity(cfs_rq, se);
16172 +       if (entity_is_task(se))
16173 +               vx_deactivate_task(task_of(se));
16174         account_entity_dequeue(cfs_rq, se);
16175  }
16176  
16177 diff -NurpP --minimal linux-2.6.27.14/kernel/sched_hard.h linux-2.6.27.14-vs2.3.0.36.4/kernel/sched_hard.h
16178 --- linux-2.6.27.14/kernel/sched_hard.h 1970-01-01 01:00:00.000000000 +0100
16179 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sched_hard.h    2008-10-13 14:54:20.000000000 +0200
16180 @@ -0,0 +1,324 @@
16181 +
16182 +#ifdef CONFIG_VSERVER_IDLELIMIT
16183 +
16184 +/*
16185 + * vx_idle_resched - reschedule after maxidle
16186 + */
16187 +static inline
16188 +void vx_idle_resched(struct rq *rq)
16189 +{
16190 +       /* maybe have a better criterion for paused */
16191 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16192 +               set_need_resched();
16193 +}
16194 +
16195 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16196 +
16197 +#define vx_idle_resched(rq)
16198 +
16199 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16200 +
16201 +
16202 +
16203 +#ifdef CONFIG_VSERVER_IDLETIME
16204 +
16205 +#define vx_set_rq_min_skip(rq, min)            \
16206 +       (rq)->idle_skip = (min)
16207 +
16208 +#define vx_save_min_skip(ret, min, val)                \
16209 +       __vx_save_min_skip(ret, min, val)
16210 +
16211 +static inline
16212 +void __vx_save_min_skip(int ret, int *min, int val)
16213 +{
16214 +       if (ret > -2)
16215 +               return;
16216 +       if ((*min > val) || !*min)
16217 +               *min = val;
16218 +}
16219 +
16220 +static inline
16221 +int vx_try_skip(struct rq *rq, int cpu)
16222 +{
16223 +       /* artificially advance time */
16224 +       if (rq->idle_skip > 0) {
16225 +               vxdprintk(list_empty(&rq->hold_queue),
16226 +                       "hold queue empty on cpu %d", cpu);
16227 +               rq->idle_time += rq->idle_skip;
16228 +               vxm_idle_skip(rq, cpu);
16229 +               return 1;
16230 +       }
16231 +       return 0;
16232 +}
16233 +
16234 +#else /* !CONFIG_VSERVER_IDLETIME */
16235 +
16236 +#define vx_set_rq_min_skip(rq, min)            \
16237 +       ({ int dummy = (min); dummy; })
16238 +
16239 +#define vx_save_min_skip(ret, min, val)
16240 +
16241 +static inline
16242 +int vx_try_skip(struct rq *rq, int cpu)
16243 +{
16244 +       return 0;
16245 +}
16246 +
16247 +#endif /* CONFIG_VSERVER_IDLETIME */
16248 +
16249 +
16250 +
16251 +#ifdef CONFIG_VSERVER_HARDCPU
16252 +
16253 +#define vx_set_rq_max_idle(rq, max)            \
16254 +       (rq)->idle_tokens = (max)
16255 +
16256 +#define vx_save_max_idle(ret, min, val)                \
16257 +       __vx_save_max_idle(ret, min, val)
16258 +
16259 +static inline
16260 +void __vx_save_max_idle(int ret, int *min, int val)
16261 +{
16262 +       if (*min > val)
16263 +               *min = val;
16264 +}
16265 +
16266 +
16267 +/*
16268 + * vx_hold_task - put a task on the hold queue
16269 + */
16270 +static inline
16271 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16272 +{
16273 +       __deactivate_task(p, rq);
16274 +       p->state |= TASK_ONHOLD;
16275 +       /* a new one on hold */
16276 +       rq->nr_onhold++;
16277 +       vxm_hold_task(p, rq);
16278 +       list_add_tail(&p->run_list, &rq->hold_queue);
16279 +}
16280 +
16281 +/*
16282 + * vx_unhold_task - put a task back to the runqueue
16283 + */
16284 +static inline
16285 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16286 +{
16287 +       list_del(&p->run_list);
16288 +       /* one less waiting */
16289 +       rq->nr_onhold--;
16290 +       p->state &= ~TASK_ONHOLD;
16291 +       enqueue_task(p, rq->expired);
16292 +       inc_nr_running(p, rq);
16293 +       vxm_unhold_task(p, rq);
16294 +
16295 +       if (p->static_prio < rq->best_expired_prio)
16296 +               rq->best_expired_prio = p->static_prio;
16297 +}
16298 +
16299 +unsigned long nr_onhold(void)
16300 +{
16301 +       unsigned long i, sum = 0;
16302 +
16303 +       for_each_online_cpu(i)
16304 +               sum += cpu_rq(i)->nr_onhold;
16305 +
16306 +       return sum;
16307 +}
16308 +
16309 +
16310 +
16311 +static inline
16312 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16313 +{
16314 +       return sched_pc->tokens;
16315 +}
16316 +
16317 +static inline
16318 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16319 +{
16320 +       sched_pc->tokens--;
16321 +}
16322 +
16323 +static inline
16324 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16325 +{
16326 +       struct vx_info *vxi = p->vx_info;
16327 +
16328 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16329 +               struct _vx_sched_pc *sched_pc =
16330 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16331 +               int tokens;
16332 +
16333 +               /* maybe we can simplify that to decrement
16334 +                  the token counter unconditional? */
16335 +
16336 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16337 +                       __vx_consume_token(sched_pc);
16338 +
16339 +               /* for tokens > 0, one token was consumed */
16340 +               if (tokens < 2)
16341 +                       slice = 0;
16342 +       }
16343 +       vxm_need_resched(p, slice, cpu);
16344 +       return (slice == 0);
16345 +}
16346 +
16347 +
16348 +#define vx_set_rq_time(rq, time) do {  \
16349 +       rq->norm_time = time;           \
16350 +} while (0)
16351 +
16352 +
16353 +static inline
16354 +void vx_try_unhold(struct rq *rq, int cpu)
16355 +{
16356 +       struct vx_info *vxi = NULL;
16357 +       struct list_head *l, *n;
16358 +       int maxidle = HZ;
16359 +       int minskip = 0;
16360 +
16361 +       /* nothing to do? what about pause? */
16362 +       if (list_empty(&rq->hold_queue))
16363 +               return;
16364 +
16365 +       list_for_each_safe(l, n, &rq->hold_queue) {
16366 +               int ret, delta_min[2];
16367 +               struct _vx_sched_pc *sched_pc;
16368 +               struct task_struct *p;
16369 +
16370 +               p = list_entry(l, struct task_struct, run_list);
16371 +               /* don't bother with same context */
16372 +               if (vxi == p->vx_info)
16373 +                       continue;
16374 +
16375 +               vxi = p->vx_info;
16376 +               /* ignore paused contexts */
16377 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16378 +                       continue;
16379 +
16380 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16381 +
16382 +               /* recalc tokens */
16383 +               vxm_sched_info(sched_pc, vxi, cpu);
16384 +               ret = vx_tokens_recalc(sched_pc,
16385 +                       &rq->norm_time, &rq->idle_time, delta_min);
16386 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16387 +
16388 +               if (ret > 0) {
16389 +                       /* we found a runable context */
16390 +                       vx_unhold_task(p, rq);
16391 +                       break;
16392 +               }
16393 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16394 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16395 +       }
16396 +       vx_set_rq_max_idle(rq, maxidle);
16397 +       vx_set_rq_min_skip(rq, minskip);
16398 +       vxm_rq_max_min(rq, cpu);
16399 +}
16400 +
16401 +
16402 +static inline
16403 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16404 +{
16405 +       struct vx_info *vxi = next->vx_info;
16406 +       struct _vx_sched_pc *sched_pc;
16407 +       int delta_min[2];
16408 +       int flags, ret;
16409 +
16410 +       if (!vxi)
16411 +               return 1;
16412 +
16413 +       flags = vxi->vx_flags;
16414 +
16415 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16416 +               goto put_on_hold;
16417 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16418 +               return 1;
16419 +
16420 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16421 +#ifdef CONFIG_SMP
16422 +       /* update scheduler params */
16423 +       if (cpu_isset(cpu, vxi->sched.update)) {
16424 +               vx_update_sched_param(&vxi->sched, sched_pc);
16425 +               vxm_update_sched(sched_pc, vxi, cpu);
16426 +               cpu_clear(cpu, vxi->sched.update);
16427 +       }
16428 +#endif
16429 +       vxm_sched_info(sched_pc, vxi, cpu);
16430 +       ret  = vx_tokens_recalc(sched_pc,
16431 +               &rq->norm_time, &rq->idle_time, delta_min);
16432 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16433 +
16434 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16435 +               return 1;
16436 +
16437 +       if (unlikely(ret < 0)) {
16438 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16439 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16440 +               vxm_rq_max_min(rq, cpu);
16441 +       put_on_hold:
16442 +               vx_hold_task(next, rq);
16443 +               return 0;
16444 +       }
16445 +       return 1;
16446 +}
16447 +
16448 +
16449 +#else /* CONFIG_VSERVER_HARDCPU */
16450 +
16451 +static inline
16452 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16453 +{
16454 +       return;
16455 +}
16456 +
16457 +static inline
16458 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16459 +{
16460 +       return;
16461 +}
16462 +
16463 +unsigned long nr_onhold(void)
16464 +{
16465 +       return 0;
16466 +}
16467 +
16468 +
16469 +static inline
16470 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16471 +{
16472 +       return (slice == 0);
16473 +}
16474 +
16475 +
16476 +#define vx_set_rq_time(rq, time)
16477 +
16478 +static inline
16479 +void vx_try_unhold(struct rq *rq, int cpu)
16480 +{
16481 +       return;
16482 +}
16483 +
16484 +static inline
16485 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16486 +{
16487 +       struct vx_info *vxi = next->vx_info;
16488 +       struct _vx_sched_pc *sched_pc;
16489 +       int delta_min[2];
16490 +       int ret;
16491 +
16492 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16493 +               return 1;
16494 +
16495 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16496 +       vxm_sched_info(sched_pc, vxi, cpu);
16497 +       ret  = vx_tokens_recalc(sched_pc,
16498 +               &rq->norm_time, &rq->idle_time, delta_min);
16499 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16500 +       return 1;
16501 +}
16502 +
16503 +#endif /* CONFIG_VSERVER_HARDCPU */
16504 +
16505 diff -NurpP --minimal linux-2.6.27.14/kernel/sched_mon.h linux-2.6.27.14-vs2.3.0.36.4/kernel/sched_mon.h
16506 --- linux-2.6.27.14/kernel/sched_mon.h  1970-01-01 01:00:00.000000000 +0100
16507 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sched_mon.h     2008-10-13 14:54:20.000000000 +0200
16508 @@ -0,0 +1,200 @@
16509 +
16510 +#include <linux/vserver/monitor.h>
16511 +
16512 +#ifdef  CONFIG_VSERVER_MONITOR
16513 +
16514 +#ifdef CONFIG_VSERVER_HARDCPU
16515 +#define HARDCPU(x) (x)
16516 +#else
16517 +#define HARDCPU(x) (0)
16518 +#endif
16519 +
16520 +#ifdef CONFIG_VSERVER_IDLETIME
16521 +#define IDLETIME(x) (x)
16522 +#else
16523 +#define IDLETIME(x) (0)
16524 +#endif
16525 +
16526 +struct _vx_mon_entry *vxm_advance(int cpu);
16527 +
16528 +
16529 +static inline
16530 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16531 +{
16532 +       entry->type = type;
16533 +       entry->xid = xid;
16534 +}
16535 +
16536 +static inline
16537 +void   __vxm_sync(int cpu)
16538 +{
16539 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16540 +
16541 +       __vxm_basic(entry, 0, VXM_SYNC);
16542 +       entry->ev.sec = xtime.tv_sec;
16543 +       entry->ev.nsec = xtime.tv_nsec;
16544 +}
16545 +
16546 +static inline
16547 +void   __vxm_task(struct task_struct *p, int type)
16548 +{
16549 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16550 +
16551 +       __vxm_basic(entry, p->xid, type);
16552 +       entry->ev.tsk.pid = p->pid;
16553 +       entry->ev.tsk.state = p->state;
16554 +}
16555 +
16556 +static inline
16557 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16558 +{
16559 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16560 +
16561 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16562 +       entry->sd.tokens = s->tokens;
16563 +       entry->sd.norm_time = s->norm_time;
16564 +       entry->sd.idle_time = s->idle_time;
16565 +}
16566 +
16567 +static inline
16568 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16569 +{
16570 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16571 +
16572 +       entry->type = VXM_RQINFO_1;
16573 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16574 +       entry->q1.running = q->nr_running;
16575 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16576 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16577 +       entry->q1.uintr = q->nr_uninterruptible;
16578 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16579 +}
16580 +
16581 +static inline
16582 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16583 +{
16584 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16585 +
16586 +       entry->type = VXM_RQINFO_2;
16587 +       entry->xid = (unsigned long)q & 0xffff;
16588 +       entry->q2.norm_time = q->norm_time;
16589 +       entry->q2.idle_time = q->idle_time;
16590 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16591 +}
16592 +
16593 +static inline
16594 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16595 +{
16596 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16597 +
16598 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16599 +       entry->ev.tokens = s->tokens;
16600 +}
16601 +
16602 +static inline
16603 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16604 +{
16605 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16606 +
16607 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16608 +       entry->u1.tokens_max = s->tokens_max;
16609 +       entry->u1.fill_rate = s->fill_rate[0];
16610 +       entry->u1.interval = s->interval[0];
16611 +}
16612 +
16613 +static inline
16614 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16615 +{
16616 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16617 +
16618 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16619 +       entry->u2.tokens_min = s->tokens_min;
16620 +       entry->u2.fill_rate = s->fill_rate[1];
16621 +       entry->u2.interval = s->interval[1];
16622 +}
16623 +
16624 +
16625 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16626 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16627 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16628 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16629 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16630 +
16631 +static inline
16632 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16633 +{
16634 +       __vxm_task(p, VXM_MIGRATE);
16635 +       __vxm_rqinfo1(rq, task_cpu(p));
16636 +       __vxm_rqinfo2(rq, task_cpu(p));
16637 +}
16638 +
16639 +static inline
16640 +void   vxm_idle_skip(struct rq *rq, int cpu)
16641 +{
16642 +       __vxm_rqinfo1(rq, cpu);
16643 +       __vxm_rqinfo2(rq, cpu);
16644 +}
16645 +
16646 +static inline
16647 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16648 +{
16649 +       if (slice)
16650 +               return;
16651 +
16652 +       __vxm_task(p, VXM_RESCHED);
16653 +}
16654 +
16655 +static inline
16656 +void   vxm_sync(unsigned long now, int cpu)
16657 +{
16658 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16659 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16660 +               return;
16661 +
16662 +       __vxm_sync(cpu);
16663 +}
16664 +
16665 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16666 +
16667 +static inline
16668 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16669 +       struct vx_info *vxi, int cpu)
16670 +{
16671 +       __vxm_sched(s, vxi, cpu);
16672 +       __vxm_rqinfo2(rq, cpu);
16673 +}
16674 +
16675 +static inline
16676 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16677 +{
16678 +       __vxm_sched(s, vxi, cpu);
16679 +       __vxm_update(s, vxi, cpu);
16680 +       __vxm_update1(s, vxi, cpu);
16681 +       __vxm_update2(s, vxi, cpu);
16682 +}
16683 +
16684 +static inline
16685 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16686 +{
16687 +       __vxm_rqinfo1(rq, cpu);
16688 +       __vxm_rqinfo2(rq, cpu);
16689 +}
16690 +
16691 +#else  /* CONFIG_VSERVER_MONITOR */
16692 +
16693 +#define        vxm_activate_task(t,q)          do { } while (0)
16694 +#define        vxm_activate_idle(t,q)          do { } while (0)
16695 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16696 +#define        vxm_hold_task(t,q)              do { } while (0)
16697 +#define        vxm_unhold_task(t,q)            do { } while (0)
16698 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16699 +#define        vxm_idle_skip(q,c)              do { } while (0)
16700 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16701 +#define        vxm_sync(s,c)                   do { } while (0)
16702 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16703 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16704 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16705 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16706 +
16707 +#endif /* CONFIG_VSERVER_MONITOR */
16708 +
16709 diff -NurpP --minimal linux-2.6.27.14/kernel/signal.c linux-2.6.27.14-vs2.3.0.36.4/kernel/signal.c
16710 --- linux-2.6.27.14/kernel/signal.c     2009-02-03 17:59:55.000000000 +0100
16711 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/signal.c        2009-02-03 17:59:04.000000000 +0100
16712 @@ -27,6 +27,8 @@
16713  #include <linux/freezer.h>
16714  #include <linux/pid_namespace.h>
16715  #include <linux/nsproxy.h>
16716 +#include <linux/vs_context.h>
16717 +#include <linux/vs_pid.h>
16718  
16719  #include <asm/param.h>
16720  #include <asm/uaccess.h>
16721 @@ -571,6 +573,14 @@ static int check_kill_permission(int sig
16722         if (!valid_signal(sig))
16723                 return -EINVAL;
16724  
16725 +       if ((info != SEND_SIG_NOINFO) &&
16726 +               (is_si_special(info) || !SI_FROMUSER(info)))
16727 +               goto skip;
16728 +
16729 +       vxdprintk(VXD_CBIT(misc, 7),
16730 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16731 +               sig, info, t, vx_task_xid(t), t->pid);
16732 +
16733         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16734                 return 0;
16735  
16736 @@ -595,6 +605,18 @@ static int check_kill_permission(int sig
16737                 }
16738         }
16739  
16740 +       error = -EPERM;
16741 +       if (t->pid == 1 && current->xid)
16742 +               return error;
16743 +
16744 +       error = -ESRCH;
16745 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16746 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16747 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16748 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16749 +               return error;
16750 +       }
16751 +skip:
16752         return security_task_kill(t, info, sig, 0);
16753  }
16754  
16755 @@ -1051,7 +1073,7 @@ int kill_pid_info(int sig, struct siginf
16756         rcu_read_lock();
16757  retry:
16758         p = pid_task(pid, PIDTYPE_PID);
16759 -       if (p) {
16760 +       if (p && vx_check(vx_task_xid(p), VS_ADMIN | VS_IDENT)) {
16761                 error = group_send_sig_info(sig, info, p);
16762                 if (unlikely(error == -ESRCH))
16763                         /*
16764 @@ -1089,7 +1111,7 @@ int kill_pid_info_as_uid(int sig, struct
16765  
16766         read_lock(&tasklist_lock);
16767         p = pid_task(pid, PIDTYPE_PID);
16768 -       if (!p) {
16769 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16770                 ret = -ESRCH;
16771                 goto out_unlock;
16772         }
16773 @@ -1141,8 +1163,10 @@ static int kill_something_info(int sig, 
16774                 struct task_struct * p;
16775  
16776                 for_each_process(p) {
16777 -                       if (task_pid_vnr(p) > 1 &&
16778 -                                       !same_thread_group(p, current)) {
16779 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16780 +                               task_pid_vnr(p) > 1 &&
16781 +                               !same_thread_group(p, current) &&
16782 +                               !vx_current_initpid(p->pid)) {
16783                                 int err = group_send_sig_info(sig, info, p);
16784                                 ++count;
16785                                 if (err != -EPERM)
16786 @@ -1815,6 +1839,11 @@ relock:
16787                     !signal_group_exit(signal))
16788                         continue;
16789  
16790 +               /* virtual init is protected against user signals */
16791 +               if ((info->si_code == SI_USER) &&
16792 +                       vx_current_initpid(current->pid))
16793 +                       continue;
16794 +
16795                 if (sig_kernel_stop(signr)) {
16796                         /*
16797                          * The default action is to stop all threads in
16798 diff -NurpP --minimal linux-2.6.27.14/kernel/softirq.c linux-2.6.27.14-vs2.3.0.36.4/kernel/softirq.c
16799 --- linux-2.6.27.14/kernel/softirq.c    2008-10-13 14:52:09.000000000 +0200
16800 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/softirq.c       2008-10-13 14:54:20.000000000 +0200
16801 @@ -21,6 +21,7 @@
16802  #include <linux/rcupdate.h>
16803  #include <linux/smp.h>
16804  #include <linux/tick.h>
16805 +#include <linux/vs_context.h>
16806  
16807  #include <asm/irq.h>
16808  /*
16809 diff -NurpP --minimal linux-2.6.27.14/kernel/sys.c linux-2.6.27.14-vs2.3.0.36.4/kernel/sys.c
16810 --- linux-2.6.27.14/kernel/sys.c        2009-02-03 17:59:55.000000000 +0100
16811 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sys.c   2009-02-03 17:59:04.000000000 +0100
16812 @@ -38,6 +38,7 @@
16813  #include <linux/syscalls.h>
16814  #include <linux/kprobes.h>
16815  #include <linux/user_namespace.h>
16816 +#include <linux/vs_pid.h>
16817  
16818  #include <asm/uaccess.h>
16819  #include <asm/io.h>
16820 @@ -122,7 +123,10 @@ static int set_one_prio(struct task_stru
16821                 goto out;
16822         }
16823         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16824 -               error = -EACCES;
16825 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16826 +                       error = 0;
16827 +               else
16828 +                       error = -EACCES;
16829                 goto out;
16830         }
16831         no_nice = security_task_setnice(p, niceval);
16832 @@ -170,6 +174,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16833                         else
16834                                 pgrp = task_pgrp(current);
16835                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16836 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16837 +                                       continue;
16838                                 error = set_one_prio(p, niceval, error);
16839                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16840                         break;
16841 @@ -230,6 +236,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16842                         else
16843                                 pgrp = task_pgrp(current);
16844                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16845 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16846 +                                       continue;
16847                                 niceval = 20 - task_nice(p);
16848                                 if (niceval > retval)
16849                                         retval = niceval;
16850 @@ -339,6 +347,9 @@ void kernel_power_off(void)
16851         machine_power_off();
16852  }
16853  EXPORT_SYMBOL_GPL(kernel_power_off);
16854 +
16855 +long vs_reboot(unsigned int, void __user *);
16856 +
16857  /*
16858   * Reboot system call: for obvious reasons only root may call it,
16859   * and even root needs to set up some magic numbers in the registers
16860 @@ -370,6 +381,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16861         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16862                 cmd = LINUX_REBOOT_CMD_HALT;
16863  
16864 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16865 +               return vs_reboot(cmd, arg);
16866 +
16867         lock_kernel();
16868         switch (cmd) {
16869         case LINUX_REBOOT_CMD_RESTART:
16870 @@ -1345,7 +1359,7 @@ SYSCALL_DEFINE2(sethostname, char __user
16871         int errno;
16872         char tmp[__NEW_UTS_LEN];
16873  
16874 -       if (!capable(CAP_SYS_ADMIN))
16875 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16876                 return -EPERM;
16877         if (len < 0 || len > __NEW_UTS_LEN)
16878                 return -EINVAL;
16879 @@ -1390,7 +1404,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
16880         int errno;
16881         char tmp[__NEW_UTS_LEN];
16882  
16883 -       if (!capable(CAP_SYS_ADMIN))
16884 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16885                 return -EPERM;
16886         if (len < 0 || len > __NEW_UTS_LEN)
16887                 return -EINVAL;
16888 @@ -1458,7 +1472,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
16889                 return -EINVAL;
16890         old_rlim = current->signal->rlim + resource;
16891         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16892 -           !capable(CAP_SYS_RESOURCE))
16893 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16894                 return -EPERM;
16895         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16896                 return -EPERM;
16897 diff -NurpP --minimal linux-2.6.27.14/kernel/sysctl.c linux-2.6.27.14-vs2.3.0.36.4/kernel/sysctl.c
16898 --- linux-2.6.27.14/kernel/sysctl.c     2009-02-03 17:59:55.000000000 +0100
16899 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sysctl.c        2009-02-03 17:59:04.000000000 +0100
16900 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16901  #ifdef CONFIG_MODULES
16902  extern char modprobe_path[];
16903  #endif
16904 +extern char vshelper_path[];
16905  #ifdef CONFIG_CHR_DEV_SG
16906  extern int sg_big_buff;
16907  #endif
16908 @@ -503,6 +504,15 @@ static struct ctl_table kern_table[] = {
16909                 .strategy       = &sysctl_string,
16910         },
16911  #endif
16912 +       {
16913 +               .ctl_name       = KERN_VSHELPER,
16914 +               .procname       = "vshelper",
16915 +               .data           = &vshelper_path,
16916 +               .maxlen         = 256,
16917 +               .mode           = 0644,
16918 +               .proc_handler   = &proc_dostring,
16919 +               .strategy       = &sysctl_string,
16920 +       },
16921  #ifdef CONFIG_CHR_DEV_SG
16922         {
16923                 .ctl_name       = KERN_SG_BIG_BUFF,
16924 diff -NurpP --minimal linux-2.6.27.14/kernel/sysctl_check.c linux-2.6.27.14-vs2.3.0.36.4/kernel/sysctl_check.c
16925 --- linux-2.6.27.14/kernel/sysctl_check.c       2008-10-13 14:52:09.000000000 +0200
16926 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/sysctl_check.c  2008-10-13 14:54:20.000000000 +0200
16927 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16928  
16929         { KERN_PANIC,                   "panic" },
16930         { KERN_REALROOTDEV,             "real-root-dev" },
16931 +       { KERN_VSHELPER,                "vshelper", },
16932  
16933         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16934         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16935 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
16936         {}
16937  };
16938  
16939 +static struct trans_ctl_table trans_vserver_table[] = {
16940 +       { 1,    "debug_switch" },
16941 +       { 2,    "debug_xid" },
16942 +       { 3,    "debug_nid" },
16943 +       { 4,    "debug_tag" },
16944 +       { 5,    "debug_net" },
16945 +       { 6,    "debug_limit" },
16946 +       { 7,    "debug_cres" },
16947 +       { 8,    "debug_dlim" },
16948 +       { 9,    "debug_quota" },
16949 +       { 10,   "debug_cvirt" },
16950 +       { 11,   "debug_space" },
16951 +       { 12,   "debug_misc" },
16952 +       {}
16953 +};
16954 +
16955  static const struct trans_ctl_table trans_root_table[] = {
16956         { CTL_KERN,     "kernel",       trans_kern_table },
16957         { CTL_VM,       "vm",           trans_vm_table },
16958 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
16959         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16960         { CTL_PM,       "pm",           trans_pm_table },
16961         { CTL_FRV,      "frv",          trans_frv_table },
16962 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16963         {}
16964  };
16965  
16966 diff -NurpP --minimal linux-2.6.27.14/kernel/time.c linux-2.6.27.14-vs2.3.0.36.4/kernel/time.c
16967 --- linux-2.6.27.14/kernel/time.c       2009-02-03 17:59:55.000000000 +0100
16968 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/time.c  2009-02-03 17:59:04.000000000 +0100
16969 @@ -62,6 +62,7 @@ EXPORT_SYMBOL(sys_tz);
16970  SYSCALL_DEFINE1(time, time_t __user *, tloc)
16971  {
16972         time_t i = get_seconds();
16973 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16974  
16975         if (tloc) {
16976                 if (put_user(i,tloc))
16977 @@ -91,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
16978         if (err)
16979                 return err;
16980  
16981 -       do_settimeofday(&tv);
16982 +       vx_settimeofday(&tv);
16983         return 0;
16984  }
16985  
16986 @@ -102,7 +103,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
16987  {
16988         if (likely(tv != NULL)) {
16989                 struct timeval ktv;
16990 -               do_gettimeofday(&ktv);
16991 +               vx_gettimeofday(&ktv);
16992                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16993                         return -EFAULT;
16994         }
16995 @@ -177,7 +178,7 @@ int do_sys_settimeofday(struct timespec 
16996                 /* SMP safe, again the code in arch/foo/time.c should
16997                  * globally block out interrupts when it runs.
16998                  */
16999 -               return do_settimeofday(tv);
17000 +               return vx_settimeofday(tv);
17001         }
17002         return 0;
17003  }
17004 @@ -309,7 +310,7 @@ void getnstimeofday(struct timespec *tv)
17005  {
17006         struct timeval x;
17007  
17008 -       do_gettimeofday(&x);
17009 +       vx_gettimeofday(&x);
17010         tv->tv_sec = x.tv_sec;
17011         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17012  }
17013 diff -NurpP --minimal linux-2.6.27.14/kernel/timer.c linux-2.6.27.14-vs2.3.0.36.4/kernel/timer.c
17014 --- linux-2.6.27.14/kernel/timer.c      2009-02-03 17:59:55.000000000 +0100
17015 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/timer.c 2009-02-03 17:59:04.000000000 +0100
17016 @@ -37,6 +37,10 @@
17017  #include <linux/delay.h>
17018  #include <linux/tick.h>
17019  #include <linux/kallsyms.h>
17020 +#include <linux/vs_base.h>
17021 +#include <linux/vs_cvirt.h>
17022 +#include <linux/vs_pid.h>
17023 +#include <linux/vserver/sched.h>
17024  
17025  #include <asm/uaccess.h>
17026  #include <asm/unistd.h>
17027 @@ -1081,12 +1085,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17028  
17029  #endif
17030  
17031 -#ifndef __alpha__
17032 -
17033 -/*
17034 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17035 - * should be moved into arch/i386 instead?
17036 - */
17037  
17038  /**
17039   * sys_getpid - return the thread group id of the current process
17040 @@ -1115,10 +1113,23 @@ SYSCALL_DEFINE0(getppid)
17041         rcu_read_lock();
17042         pid = task_tgid_vnr(current->real_parent);
17043         rcu_read_unlock();
17044 +       return vx_map_pid(pid);
17045 +}
17046  
17047 -       return pid;
17048 +#ifdef __alpha__
17049 +
17050 +/*
17051 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17052 + */
17053 +
17054 +asmlinkage long do_getxpid(long *ppid)
17055 +{
17056 +       *ppid = sys_getppid();
17057 +       return sys_getpid();
17058  }
17059  
17060 +#else /* _alpha_ */
17061 +
17062  SYSCALL_DEFINE0(getuid)
17063  {
17064         /* Only we change this so SMP safe */
17065 @@ -1289,6 +1300,8 @@ int do_sysinfo(struct sysinfo *info)
17066                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17067                         tp.tv_sec++;
17068                 }
17069 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17070 +                       vx_vsi_uptime(&tp, NULL);
17071                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17072  
17073                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17074 diff -NurpP --minimal linux-2.6.27.14/kernel/user.c linux-2.6.27.14-vs2.3.0.36.4/kernel/user.c
17075 --- linux-2.6.27.14/kernel/user.c       2008-07-13 23:51:29.000000000 +0200
17076 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/user.c  2008-10-13 14:54:20.000000000 +0200
17077 @@ -243,12 +243,15 @@ static struct kobj_type uids_ktype = {
17078  };
17079  
17080  /* create /sys/kernel/uids/<uid>/cpu_share file for this user */
17081 -static int uids_user_create(struct user_struct *up)
17082 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17083  {
17084         struct kobject *kobj = &up->kobj;
17085 -       int error;
17086 +       int error = 0;
17087  
17088         memset(kobj, 0, sizeof(struct kobject));
17089 +       if (ns != &init_user_ns)
17090 +               goto done;
17091 +
17092         kobj->kset = uids_kset;
17093         error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
17094         if (error) {
17095 @@ -272,7 +275,7 @@ int __init uids_sysfs_init(void)
17096         if (!uids_kset)
17097                 return -ENOMEM;
17098  
17099 -       return uids_user_create(&root_user);
17100 +       return uids_user_create(NULL, &root_user);
17101  }
17102  
17103  /* work function to remove sysfs directory for a user and free up
17104 @@ -302,9 +305,11 @@ static void remove_user_sysfs_dir(struct
17105         if (!remove_user)
17106                 goto done;
17107  
17108 -       kobject_uevent(&up->kobj, KOBJ_REMOVE);
17109 -       kobject_del(&up->kobj);
17110 -       kobject_put(&up->kobj);
17111 +       if (up->kobj.name) {
17112 +               kobject_uevent(&up->kobj, KOBJ_REMOVE);
17113 +               kobject_del(&up->kobj);
17114 +               kobject_put(&up->kobj);
17115 +       }
17116  
17117         sched_destroy_user(up);
17118         key_put(up->uid_keyring);
17119 @@ -332,7 +337,8 @@ static inline void free_user(struct user
17120  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
17121  
17122  int uids_sysfs_init(void) { return 0; }
17123 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17124 +static inline int uids_user_create(struct user_namespace *ns,
17125 +       struct user_struct *up) { return 0; }
17126  static inline void uids_mutex_lock(void) { }
17127  static inline void uids_mutex_unlock(void) { }
17128  
17129 @@ -409,7 +415,7 @@ struct user_struct *alloc_uid(struct use
17130                 if (sched_create_user(new) < 0)
17131                         goto out_free_user;
17132  
17133 -               if (uids_user_create(new))
17134 +               if (uids_user_create(ns, new))
17135                         goto out_destoy_sched;
17136  
17137                 /*
17138 diff -NurpP --minimal linux-2.6.27.14/kernel/user_namespace.c linux-2.6.27.14-vs2.3.0.36.4/kernel/user_namespace.c
17139 --- linux-2.6.27.14/kernel/user_namespace.c     2008-10-13 14:52:09.000000000 +0200
17140 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/user_namespace.c        2008-10-13 14:54:20.000000000 +0200
17141 @@ -9,6 +9,7 @@
17142  #include <linux/nsproxy.h>
17143  #include <linux/slab.h>
17144  #include <linux/user_namespace.h>
17145 +#include <linux/vserver/global.h>
17146  
17147  /*
17148   * Clone a new ns copying an original user ns, setting refcount to 1
17149 @@ -26,6 +27,7 @@ static struct user_namespace *clone_user
17150                 return ERR_PTR(-ENOMEM);
17151  
17152         kref_init(&ns->kref);
17153 +       atomic_inc(&vs_global_user_ns);
17154  
17155         for (n = 0; n < UIDHASH_SZ; ++n)
17156                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17157 @@ -71,6 +73,7 @@ void free_user_ns(struct kref *kref)
17158  
17159         ns = container_of(kref, struct user_namespace, kref);
17160         release_uids(ns);
17161 +       atomic_dec(&vs_global_user_ns);
17162         kfree(ns);
17163  }
17164  EXPORT_SYMBOL(free_user_ns);
17165 diff -NurpP --minimal linux-2.6.27.14/kernel/utsname.c linux-2.6.27.14-vs2.3.0.36.4/kernel/utsname.c
17166 --- linux-2.6.27.14/kernel/utsname.c    2008-10-13 14:52:09.000000000 +0200
17167 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/utsname.c       2008-10-13 14:54:20.000000000 +0200
17168 @@ -14,6 +14,7 @@
17169  #include <linux/utsname.h>
17170  #include <linux/err.h>
17171  #include <linux/slab.h>
17172 +#include <linux/vserver/global.h>
17173  
17174  /*
17175   * Clone a new ns copying an original utsname, setting refcount to 1
17176 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17177         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17178         up_read(&uts_sem);
17179         kref_init(&ns->kref);
17180 +       atomic_inc(&vs_global_uts_ns);
17181         return ns;
17182  }
17183  
17184 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17185         struct uts_namespace *ns;
17186  
17187         ns = container_of(kref, struct uts_namespace, kref);
17188 +       atomic_dec(&vs_global_uts_ns);
17189         kfree(ns);
17190  }
17191 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/cacct.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cacct.c
17192 --- linux-2.6.27.14/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
17193 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cacct.c 2008-10-13 14:54:20.000000000 +0200
17194 @@ -0,0 +1,42 @@
17195 +/*
17196 + *  linux/kernel/vserver/cacct.c
17197 + *
17198 + *  Virtual Server: Context Accounting
17199 + *
17200 + *  Copyright (C) 2006-2007 Herbert Pötzl
17201 + *
17202 + *  V0.01  added accounting stats
17203 + *
17204 + */
17205 +
17206 +#include <linux/types.h>
17207 +#include <linux/vs_context.h>
17208 +#include <linux/vserver/cacct_cmd.h>
17209 +#include <linux/vserver/cacct_int.h>
17210 +
17211 +#include <asm/errno.h>
17212 +#include <asm/uaccess.h>
17213 +
17214 +
17215 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17216 +{
17217 +       struct vcmd_sock_stat_v0 vc_data;
17218 +       int j, field;
17219 +
17220 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17221 +               return -EFAULT;
17222 +
17223 +       field = vc_data.field;
17224 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17225 +               return -EINVAL;
17226 +
17227 +       for (j = 0; j < 3; j++) {
17228 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17229 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17230 +       }
17231 +
17232 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17233 +               return -EFAULT;
17234 +       return 0;
17235 +}
17236 +
17237 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/cacct_init.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cacct_init.h
17238 --- linux-2.6.27.14/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
17239 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cacct_init.h    2008-10-13 14:54:20.000000000 +0200
17240 @@ -0,0 +1,25 @@
17241 +
17242 +
17243 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17244 +{
17245 +       int i, j;
17246 +
17247 +
17248 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17249 +               for (j = 0; j < 3; j++) {
17250 +                       atomic_set(&cacct->sock[i][j].count, 0);
17251 +                       atomic_set(&cacct->sock[i][j].total, 0);
17252 +               }
17253 +       }
17254 +       for (i = 0; i < 8; i++)
17255 +               atomic_set(&cacct->slab[i], 0);
17256 +       for (i = 0; i < 5; i++)
17257 +               for (j = 0; j < 4; j++)
17258 +                       atomic_set(&cacct->page[i][j], 0);
17259 +}
17260 +
17261 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17262 +{
17263 +       return;
17264 +}
17265 +
17266 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/cacct_proc.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cacct_proc.h
17267 --- linux-2.6.27.14/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
17268 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cacct_proc.h    2008-10-13 14:54:20.000000000 +0200
17269 @@ -0,0 +1,53 @@
17270 +#ifndef _VX_CACCT_PROC_H
17271 +#define _VX_CACCT_PROC_H
17272 +
17273 +#include <linux/vserver/cacct_int.h>
17274 +
17275 +
17276 +#define VX_SOCKA_TOP   \
17277 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17278 +
17279 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17280 +{
17281 +       int i, j, length = 0;
17282 +       static char *type[VXA_SOCK_SIZE] = {
17283 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17284 +       };
17285 +
17286 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17287 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17288 +               length += sprintf(buffer + length, "%s:", type[i]);
17289 +               for (j = 0; j < 3; j++) {
17290 +                       length += sprintf(buffer + length,
17291 +                               "\t%10lu/%-10lu",
17292 +                               vx_sock_count(cacct, i, j),
17293 +                               vx_sock_total(cacct, i, j));
17294 +               }
17295 +               buffer[length++] = '\n';
17296 +       }
17297 +
17298 +       length += sprintf(buffer + length, "\n");
17299 +       length += sprintf(buffer + length,
17300 +               "slab:\t %8u %8u %8u %8u\n",
17301 +               atomic_read(&cacct->slab[1]),
17302 +               atomic_read(&cacct->slab[4]),
17303 +               atomic_read(&cacct->slab[0]),
17304 +               atomic_read(&cacct->slab[2]));
17305 +
17306 +       length += sprintf(buffer + length, "\n");
17307 +       for (i = 0; i < 5; i++) {
17308 +               length += sprintf(buffer + length,
17309 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17310 +                       atomic_read(&cacct->page[i][0]),
17311 +                       atomic_read(&cacct->page[i][1]),
17312 +                       atomic_read(&cacct->page[i][2]),
17313 +                       atomic_read(&cacct->page[i][3]),
17314 +                       atomic_read(&cacct->page[i][4]),
17315 +                       atomic_read(&cacct->page[i][5]),
17316 +                       atomic_read(&cacct->page[i][6]),
17317 +                       atomic_read(&cacct->page[i][7]));
17318 +       }
17319 +       return length;
17320 +}
17321 +
17322 +#endif /* _VX_CACCT_PROC_H */
17323 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/context.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/context.c
17324 --- linux-2.6.27.14/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
17325 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/context.c       2008-10-31 03:56:55.000000000 +0100
17326 @@ -0,0 +1,1018 @@
17327 +/*
17328 + *  linux/kernel/vserver/context.c
17329 + *
17330 + *  Virtual Server: Context Support
17331 + *
17332 + *  Copyright (C) 2003-2007  Herbert Pötzl
17333 + *
17334 + *  V0.01  context helper
17335 + *  V0.02  vx_ctx_kill syscall command
17336 + *  V0.03  replaced context_info calls
17337 + *  V0.04  redesign of struct (de)alloc
17338 + *  V0.05  rlimit basic implementation
17339 + *  V0.06  task_xid and info commands
17340 + *  V0.07  context flags and caps
17341 + *  V0.08  switch to RCU based hash
17342 + *  V0.09  revert to non RCU for now
17343 + *  V0.10  and back to working RCU hash
17344 + *  V0.11  and back to locking again
17345 + *  V0.12  referenced context store
17346 + *  V0.13  separate per cpu data
17347 + *  V0.14  changed vcmds to vxi arg
17348 + *  V0.15  added context stat
17349 + *  V0.16  have __create claim() the vxi
17350 + *  V0.17  removed older and legacy stuff
17351 + *
17352 + */
17353 +
17354 +#include <linux/slab.h>
17355 +#include <linux/types.h>
17356 +#include <linux/security.h>
17357 +#include <linux/pid_namespace.h>
17358 +
17359 +#include <linux/vserver/context.h>
17360 +#include <linux/vserver/network.h>
17361 +#include <linux/vserver/debug.h>
17362 +#include <linux/vserver/limit.h>
17363 +#include <linux/vserver/limit_int.h>
17364 +#include <linux/vserver/space.h>
17365 +
17366 +#include <linux/vs_context.h>
17367 +#include <linux/vs_limit.h>
17368 +#include <linux/vs_pid.h>
17369 +#include <linux/vserver/context_cmd.h>
17370 +
17371 +#include "cvirt_init.h"
17372 +#include "cacct_init.h"
17373 +#include "limit_init.h"
17374 +#include "sched_init.h"
17375 +
17376 +
17377 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17378 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17379 +
17380 +
17381 +/*     now inactive context structures */
17382 +
17383 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17384 +
17385 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17386 +
17387 +
17388 +/*     __alloc_vx_info()
17389 +
17390 +       * allocate an initialized vx_info struct
17391 +       * doesn't make it visible (hash)                        */
17392 +
17393 +static struct vx_info *__alloc_vx_info(xid_t xid)
17394 +{
17395 +       struct vx_info *new = NULL;
17396 +       int cpu;
17397 +
17398 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17399 +
17400 +       /* would this benefit from a slab cache? */
17401 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17402 +       if (!new)
17403 +               return 0;
17404 +
17405 +       memset(new, 0, sizeof(struct vx_info));
17406 +#ifdef CONFIG_SMP
17407 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17408 +       if (!new->ptr_pc)
17409 +               goto error;
17410 +#endif
17411 +       new->vx_id = xid;
17412 +       INIT_HLIST_NODE(&new->vx_hlist);
17413 +       atomic_set(&new->vx_usecnt, 0);
17414 +       atomic_set(&new->vx_tasks, 0);
17415 +       new->vx_parent = NULL;
17416 +       new->vx_state = 0;
17417 +       init_waitqueue_head(&new->vx_wait);
17418 +
17419 +       /* prepare reaper */
17420 +       get_task_struct(init_pid_ns.child_reaper);
17421 +       new->vx_reaper = init_pid_ns.child_reaper;
17422 +       new->vx_badness_bias = 0;
17423 +
17424 +       /* rest of init goes here */
17425 +       vx_info_init_limit(&new->limit);
17426 +       vx_info_init_sched(&new->sched);
17427 +       vx_info_init_cvirt(&new->cvirt);
17428 +       vx_info_init_cacct(&new->cacct);
17429 +
17430 +       /* per cpu data structures */
17431 +       for_each_possible_cpu(cpu) {
17432 +               vx_info_init_sched_pc(
17433 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17434 +               vx_info_init_cvirt_pc(
17435 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17436 +       }
17437 +
17438 +       new->vx_flags = VXF_INIT_SET;
17439 +       cap_set_init_eff(new->vx_bcaps);
17440 +       new->vx_ccaps = 0;
17441 +       // new->vx_cap_bset = current->cap_bset;
17442 +
17443 +       new->reboot_cmd = 0;
17444 +       new->exit_code = 0;
17445 +
17446 +       vxdprintk(VXD_CBIT(xid, 0),
17447 +               "alloc_vx_info(%d) = %p", xid, new);
17448 +       vxh_alloc_vx_info(new);
17449 +       atomic_inc(&vx_global_ctotal);
17450 +       return new;
17451 +#ifdef CONFIG_SMP
17452 +error:
17453 +       kfree(new);
17454 +       return 0;
17455 +#endif
17456 +}
17457 +
17458 +/*     __dealloc_vx_info()
17459 +
17460 +       * final disposal of vx_info                             */
17461 +
17462 +static void __dealloc_vx_info(struct vx_info *vxi)
17463 +{
17464 +       struct vx_info_save vxis;
17465 +       int cpu;
17466 +
17467 +       vxdprintk(VXD_CBIT(xid, 0),
17468 +               "dealloc_vx_info(%p)", vxi);
17469 +       vxh_dealloc_vx_info(vxi);
17470 +
17471 +#ifdef CONFIG_VSERVER_WARN
17472 +       enter_vx_info(vxi, &vxis);
17473 +       vx_info_exit_limit(&vxi->limit);
17474 +       vx_info_exit_sched(&vxi->sched);
17475 +       vx_info_exit_cvirt(&vxi->cvirt);
17476 +       vx_info_exit_cacct(&vxi->cacct);
17477 +
17478 +       for_each_possible_cpu(cpu) {
17479 +               vx_info_exit_sched_pc(
17480 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17481 +               vx_info_exit_cvirt_pc(
17482 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17483 +       }
17484 +       leave_vx_info(&vxis);
17485 +#endif
17486 +
17487 +       vxi->vx_id = -1;
17488 +       vxi->vx_state |= VXS_RELEASED;
17489 +
17490 +#ifdef CONFIG_SMP
17491 +       free_percpu(vxi->ptr_pc);
17492 +#endif
17493 +       kfree(vxi);
17494 +       atomic_dec(&vx_global_ctotal);
17495 +}
17496 +
17497 +static void __shutdown_vx_info(struct vx_info *vxi)
17498 +{
17499 +       struct nsproxy *nsproxy;
17500 +       struct fs_struct *fs;
17501 +       int index;
17502 +
17503 +       might_sleep();
17504 +
17505 +       vxi->vx_state |= VXS_SHUTDOWN;
17506 +       vs_state_change(vxi, VSC_SHUTDOWN);
17507 +
17508 +       for (index = 0; index < VX_SPACES; index++) {
17509 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17510 +               if (nsproxy)
17511 +                       put_nsproxy(nsproxy);
17512 +
17513 +               fs = xchg(&vxi->vx_fs[index], NULL);
17514 +               if (fs)
17515 +                       put_fs_struct(fs);
17516 +       }
17517 +}
17518 +
17519 +/* exported stuff */
17520 +
17521 +void free_vx_info(struct vx_info *vxi)
17522 +{
17523 +       unsigned long flags;
17524 +       unsigned index;
17525 +
17526 +       /* check for reference counts first */
17527 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17528 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17529 +
17530 +       /* context must not be hashed */
17531 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17532 +
17533 +       /* context shutdown is mandatory */
17534 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17535 +
17536 +       /* nsproxy and fs check */
17537 +       for (index = 0; index < VX_SPACES; index++) {
17538 +               BUG_ON(vxi->vx_nsproxy[index]);
17539 +               BUG_ON(vxi->vx_fs[index]);
17540 +       }
17541 +
17542 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17543 +       hlist_del(&vxi->vx_hlist);
17544 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17545 +
17546 +       __dealloc_vx_info(vxi);
17547 +}
17548 +
17549 +
17550 +/*     hash table for vx_info hash */
17551 +
17552 +#define VX_HASH_SIZE   13
17553 +
17554 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17555 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17556 +
17557 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17558 +
17559 +
17560 +static inline unsigned int __hashval(xid_t xid)
17561 +{
17562 +       return (xid % VX_HASH_SIZE);
17563 +}
17564 +
17565 +
17566 +
17567 +/*     __hash_vx_info()
17568 +
17569 +       * add the vxi to the global hash table
17570 +       * requires the hash_lock to be held                     */
17571 +
17572 +static inline void __hash_vx_info(struct vx_info *vxi)
17573 +{
17574 +       struct hlist_head *head;
17575 +
17576 +       vxd_assert_lock(&vx_info_hash_lock);
17577 +       vxdprintk(VXD_CBIT(xid, 4),
17578 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17579 +       vxh_hash_vx_info(vxi);
17580 +
17581 +       /* context must not be hashed */
17582 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17583 +
17584 +       vxi->vx_state |= VXS_HASHED;
17585 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17586 +       hlist_add_head(&vxi->vx_hlist, head);
17587 +       atomic_inc(&vx_global_cactive);
17588 +}
17589 +
17590 +/*     __unhash_vx_info()
17591 +
17592 +       * remove the vxi from the global hash table
17593 +       * requires the hash_lock to be held                     */
17594 +
17595 +static inline void __unhash_vx_info(struct vx_info *vxi)
17596 +{
17597 +       unsigned long flags;
17598 +
17599 +       vxd_assert_lock(&vx_info_hash_lock);
17600 +       vxdprintk(VXD_CBIT(xid, 4),
17601 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17602 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17603 +       vxh_unhash_vx_info(vxi);
17604 +
17605 +       /* context must be hashed */
17606 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17607 +       /* but without tasks */
17608 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17609 +
17610 +       vxi->vx_state &= ~VXS_HASHED;
17611 +       hlist_del_init(&vxi->vx_hlist);
17612 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17613 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17614 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17615 +       atomic_dec(&vx_global_cactive);
17616 +}
17617 +
17618 +
17619 +/*     __lookup_vx_info()
17620 +
17621 +       * requires the hash_lock to be held
17622 +       * doesn't increment the vx_refcnt                       */
17623 +
17624 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17625 +{
17626 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17627 +       struct hlist_node *pos;
17628 +       struct vx_info *vxi;
17629 +
17630 +       vxd_assert_lock(&vx_info_hash_lock);
17631 +       hlist_for_each(pos, head) {
17632 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17633 +
17634 +               if (vxi->vx_id == xid)
17635 +                       goto found;
17636 +       }
17637 +       vxi = NULL;
17638 +found:
17639 +       vxdprintk(VXD_CBIT(xid, 0),
17640 +               "__lookup_vx_info(#%u): %p[#%u]",
17641 +               xid, vxi, vxi ? vxi->vx_id : 0);
17642 +       vxh_lookup_vx_info(vxi, xid);
17643 +       return vxi;
17644 +}
17645 +
17646 +
17647 +/*     __create_vx_info()
17648 +
17649 +       * create the requested context
17650 +       * get(), claim() and hash it                            */
17651 +
17652 +static struct vx_info *__create_vx_info(int id)
17653 +{
17654 +       struct vx_info *new, *vxi = NULL;
17655 +
17656 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17657 +
17658 +       if (!(new = __alloc_vx_info(id)))
17659 +               return ERR_PTR(-ENOMEM);
17660 +
17661 +       /* required to make dynamic xids unique */
17662 +       spin_lock(&vx_info_hash_lock);
17663 +
17664 +       /* static context requested */
17665 +       if ((vxi = __lookup_vx_info(id))) {
17666 +               vxdprintk(VXD_CBIT(xid, 0),
17667 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17668 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17669 +                       vxi = ERR_PTR(-EBUSY);
17670 +               else
17671 +                       vxi = ERR_PTR(-EEXIST);
17672 +               goto out_unlock;
17673 +       }
17674 +       /* new context */
17675 +       vxdprintk(VXD_CBIT(xid, 0),
17676 +               "create_vx_info(%d) = %p (new)", id, new);
17677 +       claim_vx_info(new, NULL);
17678 +       __hash_vx_info(get_vx_info(new));
17679 +       vxi = new, new = NULL;
17680 +
17681 +out_unlock:
17682 +       spin_unlock(&vx_info_hash_lock);
17683 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17684 +       if (new)
17685 +               __dealloc_vx_info(new);
17686 +       return vxi;
17687 +}
17688 +
17689 +
17690 +/*     exported stuff                                          */
17691 +
17692 +
17693 +void unhash_vx_info(struct vx_info *vxi)
17694 +{
17695 +       __shutdown_vx_info(vxi);
17696 +       spin_lock(&vx_info_hash_lock);
17697 +       __unhash_vx_info(vxi);
17698 +       spin_unlock(&vx_info_hash_lock);
17699 +       __wakeup_vx_info(vxi);
17700 +}
17701 +
17702 +
17703 +/*     lookup_vx_info()
17704 +
17705 +       * search for a vx_info and get() it
17706 +       * negative id means current                             */
17707 +
17708 +struct vx_info *lookup_vx_info(int id)
17709 +{
17710 +       struct vx_info *vxi = NULL;
17711 +
17712 +       if (id < 0) {
17713 +               vxi = get_vx_info(current->vx_info);
17714 +       } else if (id > 1) {
17715 +               spin_lock(&vx_info_hash_lock);
17716 +               vxi = get_vx_info(__lookup_vx_info(id));
17717 +               spin_unlock(&vx_info_hash_lock);
17718 +       }
17719 +       return vxi;
17720 +}
17721 +
17722 +/*     xid_is_hashed()
17723 +
17724 +       * verify that xid is still hashed                       */
17725 +
17726 +int xid_is_hashed(xid_t xid)
17727 +{
17728 +       int hashed;
17729 +
17730 +       spin_lock(&vx_info_hash_lock);
17731 +       hashed = (__lookup_vx_info(xid) != NULL);
17732 +       spin_unlock(&vx_info_hash_lock);
17733 +       return hashed;
17734 +}
17735 +
17736 +#ifdef CONFIG_PROC_FS
17737 +
17738 +/*     get_xid_list()
17739 +
17740 +       * get a subset of hashed xids for proc
17741 +       * assumes size is at least one                          */
17742 +
17743 +int get_xid_list(int index, unsigned int *xids, int size)
17744 +{
17745 +       int hindex, nr_xids = 0;
17746 +
17747 +       /* only show current and children */
17748 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17749 +               if (index > 0)
17750 +                       return 0;
17751 +               xids[nr_xids] = vx_current_xid();
17752 +               return 1;
17753 +       }
17754 +
17755 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17756 +               struct hlist_head *head = &vx_info_hash[hindex];
17757 +               struct hlist_node *pos;
17758 +
17759 +               spin_lock(&vx_info_hash_lock);
17760 +               hlist_for_each(pos, head) {
17761 +                       struct vx_info *vxi;
17762 +
17763 +                       if (--index > 0)
17764 +                               continue;
17765 +
17766 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17767 +                       xids[nr_xids] = vxi->vx_id;
17768 +                       if (++nr_xids >= size) {
17769 +                               spin_unlock(&vx_info_hash_lock);
17770 +                               goto out;
17771 +                       }
17772 +               }
17773 +               /* keep the lock time short */
17774 +               spin_unlock(&vx_info_hash_lock);
17775 +       }
17776 +out:
17777 +       return nr_xids;
17778 +}
17779 +#endif
17780 +
17781 +#ifdef CONFIG_VSERVER_DEBUG
17782 +
17783 +void   dump_vx_info_inactive(int level)
17784 +{
17785 +       struct hlist_node *entry, *next;
17786 +
17787 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17788 +               struct vx_info *vxi =
17789 +                       list_entry(entry, struct vx_info, vx_hlist);
17790 +
17791 +               dump_vx_info(vxi, level);
17792 +       }
17793 +}
17794 +
17795 +#endif
17796 +
17797 +#if 0
17798 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17799 +{
17800 +       struct user_struct *new_user, *old_user;
17801 +
17802 +       if (!p || !vxi)
17803 +               BUG();
17804 +
17805 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17806 +               return -EACCES;
17807 +
17808 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17809 +       if (!new_user)
17810 +               return -ENOMEM;
17811 +
17812 +       old_user = p->user;
17813 +       if (new_user != old_user) {
17814 +               atomic_inc(&new_user->processes);
17815 +               atomic_dec(&old_user->processes);
17816 +               p->user = new_user;
17817 +       }
17818 +       free_uid(old_user);
17819 +       return 0;
17820 +}
17821 +#endif
17822 +
17823 +#if 0
17824 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17825 +{
17826 +       // p->cap_effective &= vxi->vx_cap_bset;
17827 +       p->cap_effective =
17828 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17829 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17830 +       p->cap_inheritable =
17831 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17832 +       // p->cap_permitted &= vxi->vx_cap_bset;
17833 +       p->cap_permitted =
17834 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17835 +}
17836 +#endif
17837 +
17838 +
17839 +#include <linux/file.h>
17840 +#include <linux/fdtable.h>
17841 +
17842 +static int vx_openfd_task(struct task_struct *tsk)
17843 +{
17844 +       struct files_struct *files = tsk->files;
17845 +       struct fdtable *fdt;
17846 +       const unsigned long *bptr;
17847 +       int count, total;
17848 +
17849 +       /* no rcu_read_lock() because of spin_lock() */
17850 +       spin_lock(&files->file_lock);
17851 +       fdt = files_fdtable(files);
17852 +       bptr = fdt->open_fds->fds_bits;
17853 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17854 +       for (total = 0; count > 0; count--) {
17855 +               if (*bptr)
17856 +                       total += hweight_long(*bptr);
17857 +               bptr++;
17858 +       }
17859 +       spin_unlock(&files->file_lock);
17860 +       return total;
17861 +}
17862 +
17863 +
17864 +/*     for *space compatibility */
17865 +
17866 +asmlinkage long sys_unshare(unsigned long);
17867 +
17868 +/*
17869 + *     migrate task to new context
17870 + *     gets vxi, puts old_vxi on change
17871 + *     optionally unshares namespaces (hack)
17872 + */
17873 +
17874 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17875 +{
17876 +       struct vx_info *old_vxi;
17877 +       int ret = 0;
17878 +
17879 +       if (!p || !vxi)
17880 +               BUG();
17881 +
17882 +       vxdprintk(VXD_CBIT(xid, 5),
17883 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17884 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17885 +
17886 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17887 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17888 +               return -EACCES;
17889 +
17890 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17891 +               return -EFAULT;
17892 +
17893 +       old_vxi = task_get_vx_info(p);
17894 +       if (old_vxi == vxi)
17895 +               goto out;
17896 +
17897 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17898 +       {
17899 +               int openfd;
17900 +
17901 +               task_lock(p);
17902 +               openfd = vx_openfd_task(p);
17903 +
17904 +               if (old_vxi) {
17905 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17906 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17907 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17908 +                       /* FIXME: what about the struct files here? */
17909 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17910 +                       /* account for the executable */
17911 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17912 +               }
17913 +               atomic_inc(&vxi->cvirt.nr_threads);
17914 +               atomic_inc(&vxi->cvirt.nr_running);
17915 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17916 +               /* FIXME: what about the struct files here? */
17917 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17918 +               /* account for the executable */
17919 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17920 +
17921 +               if (old_vxi) {
17922 +                       release_vx_info(old_vxi, p);
17923 +                       clr_vx_info(&p->vx_info);
17924 +               }
17925 +               claim_vx_info(vxi, p);
17926 +               set_vx_info(&p->vx_info, vxi);
17927 +               p->xid = vxi->vx_id;
17928 +
17929 +               vxdprintk(VXD_CBIT(xid, 5),
17930 +                       "moved task %p into vxi:%p[#%d]",
17931 +                       p, vxi, vxi->vx_id);
17932 +
17933 +               // vx_mask_cap_bset(vxi, p);
17934 +               task_unlock(p);
17935 +
17936 +               /* hack for *spaces to provide compatibility */
17937 +               if (unshare) {
17938 +                       struct nsproxy *old_nsp, *new_nsp;
17939 +
17940 +                       ret = unshare_nsproxy_namespaces(
17941 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17942 +                               &new_nsp, NULL);
17943 +                       if (ret)
17944 +                               goto out;
17945 +
17946 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17947 +                       vx_set_space(vxi,
17948 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17949 +                       put_nsproxy(old_nsp);
17950 +               }
17951 +       }
17952 +out:
17953 +       put_vx_info(old_vxi);
17954 +       return ret;
17955 +}
17956 +
17957 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17958 +{
17959 +       struct task_struct *old_reaper;
17960 +
17961 +       if (!vxi)
17962 +               return -EINVAL;
17963 +
17964 +       vxdprintk(VXD_CBIT(xid, 6),
17965 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17966 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17967 +
17968 +       old_reaper = vxi->vx_reaper;
17969 +       if (old_reaper == p)
17970 +               return 0;
17971 +
17972 +       /* set new child reaper */
17973 +       get_task_struct(p);
17974 +       vxi->vx_reaper = p;
17975 +       put_task_struct(old_reaper);
17976 +       return 0;
17977 +}
17978 +
17979 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17980 +{
17981 +       if (!vxi)
17982 +               return -EINVAL;
17983 +
17984 +       vxdprintk(VXD_CBIT(xid, 6),
17985 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17986 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17987 +
17988 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17989 +       vxi->vx_initpid = p->tgid;
17990 +       return 0;
17991 +}
17992 +
17993 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17994 +{
17995 +       vxdprintk(VXD_CBIT(xid, 6),
17996 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17997 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17998 +
17999 +       vxi->exit_code = code;
18000 +       vxi->vx_initpid = 0;
18001 +}
18002 +
18003 +
18004 +void vx_set_persistent(struct vx_info *vxi)
18005 +{
18006 +       vxdprintk(VXD_CBIT(xid, 6),
18007 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18008 +
18009 +       get_vx_info(vxi);
18010 +       claim_vx_info(vxi, NULL);
18011 +}
18012 +
18013 +void vx_clear_persistent(struct vx_info *vxi)
18014 +{
18015 +       vxdprintk(VXD_CBIT(xid, 6),
18016 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18017 +
18018 +       release_vx_info(vxi, NULL);
18019 +       put_vx_info(vxi);
18020 +}
18021 +
18022 +void vx_update_persistent(struct vx_info *vxi)
18023 +{
18024 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18025 +               vx_set_persistent(vxi);
18026 +       else
18027 +               vx_clear_persistent(vxi);
18028 +}
18029 +
18030 +
18031 +/*     task must be current or locked          */
18032 +
18033 +void   exit_vx_info(struct task_struct *p, int code)
18034 +{
18035 +       struct vx_info *vxi = p->vx_info;
18036 +
18037 +       if (vxi) {
18038 +               atomic_dec(&vxi->cvirt.nr_threads);
18039 +               vx_nproc_dec(p);
18040 +
18041 +               vxi->exit_code = code;
18042 +               release_vx_info(vxi, p);
18043 +       }
18044 +}
18045 +
18046 +void   exit_vx_info_early(struct task_struct *p, int code)
18047 +{
18048 +       struct vx_info *vxi = p->vx_info;
18049 +
18050 +       if (vxi) {
18051 +               if (vxi->vx_initpid == p->tgid)
18052 +                       vx_exit_init(vxi, p, code);
18053 +               if (vxi->vx_reaper == p)
18054 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18055 +       }
18056 +}
18057 +
18058 +
18059 +/* vserver syscall commands below here */
18060 +
18061 +/* taks xid and vx_info functions */
18062 +
18063 +#include <asm/uaccess.h>
18064 +
18065 +
18066 +int vc_task_xid(uint32_t id)
18067 +{
18068 +       xid_t xid;
18069 +
18070 +       if (id) {
18071 +               struct task_struct *tsk;
18072 +
18073 +               read_lock(&tasklist_lock);
18074 +               tsk = find_task_by_real_pid(id);
18075 +               xid = (tsk) ? tsk->xid : -ESRCH;
18076 +               read_unlock(&tasklist_lock);
18077 +       } else
18078 +               xid = vx_current_xid();
18079 +       return xid;
18080 +}
18081 +
18082 +
18083 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18084 +{
18085 +       struct vcmd_vx_info_v0 vc_data;
18086 +
18087 +       vc_data.xid = vxi->vx_id;
18088 +       vc_data.initpid = vxi->vx_initpid;
18089 +
18090 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18091 +               return -EFAULT;
18092 +       return 0;
18093 +}
18094 +
18095 +
18096 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18097 +{
18098 +       struct vcmd_ctx_stat_v0 vc_data;
18099 +
18100 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18101 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18102 +
18103 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18104 +               return -EFAULT;
18105 +       return 0;
18106 +}
18107 +
18108 +
18109 +/* context functions */
18110 +
18111 +int vc_ctx_create(uint32_t xid, void __user *data)
18112 +{
18113 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18114 +       struct vx_info *new_vxi;
18115 +       int ret;
18116 +
18117 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18118 +               return -EFAULT;
18119 +
18120 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18121 +               return -EINVAL;
18122 +
18123 +       new_vxi = __create_vx_info(xid);
18124 +       if (IS_ERR(new_vxi))
18125 +               return PTR_ERR(new_vxi);
18126 +
18127 +       /* initial flags */
18128 +       new_vxi->vx_flags = vc_data.flagword;
18129 +
18130 +       ret = -ENOEXEC;
18131 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18132 +               goto out;
18133 +
18134 +       ret = vx_migrate_task(current, new_vxi, (!data));
18135 +       if (ret)
18136 +               goto out;
18137 +
18138 +       /* return context id on success */
18139 +       ret = new_vxi->vx_id;
18140 +
18141 +       /* get a reference for persistent contexts */
18142 +       if ((vc_data.flagword & VXF_PERSISTENT))
18143 +               vx_set_persistent(new_vxi);
18144 +out:
18145 +       release_vx_info(new_vxi, NULL);
18146 +       put_vx_info(new_vxi);
18147 +       return ret;
18148 +}
18149 +
18150 +
18151 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18152 +{
18153 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18154 +       int ret;
18155 +
18156 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18157 +               return -EFAULT;
18158 +
18159 +       ret = vx_migrate_task(current, vxi, 0);
18160 +       if (ret)
18161 +               return ret;
18162 +       if (vc_data.flagword & VXM_SET_INIT)
18163 +               ret = vx_set_init(vxi, current);
18164 +       if (ret)
18165 +               return ret;
18166 +       if (vc_data.flagword & VXM_SET_REAPER)
18167 +               ret = vx_set_reaper(vxi, current);
18168 +       return ret;
18169 +}
18170 +
18171 +
18172 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18173 +{
18174 +       struct vcmd_ctx_flags_v0 vc_data;
18175 +
18176 +       vc_data.flagword = vxi->vx_flags;
18177 +
18178 +       /* special STATE flag handling */
18179 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18180 +
18181 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18182 +               return -EFAULT;
18183 +       return 0;
18184 +}
18185 +
18186 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18187 +{
18188 +       struct vcmd_ctx_flags_v0 vc_data;
18189 +       uint64_t mask, trigger;
18190 +
18191 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18192 +               return -EFAULT;
18193 +
18194 +       /* special STATE flag handling */
18195 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18196 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18197 +
18198 +       if (vxi == current->vx_info) {
18199 +               /* if (trigger & VXF_STATE_SETUP)
18200 +                       vx_mask_cap_bset(vxi, current); */
18201 +               if (trigger & VXF_STATE_INIT) {
18202 +                       int ret;
18203 +
18204 +                       ret = vx_set_init(vxi, current);
18205 +                       if (ret)
18206 +                               return ret;
18207 +                       ret = vx_set_reaper(vxi, current);
18208 +                       if (ret)
18209 +                               return ret;
18210 +               }
18211 +       }
18212 +
18213 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18214 +               vc_data.flagword, mask);
18215 +       if (trigger & VXF_PERSISTENT)
18216 +               vx_update_persistent(vxi);
18217 +
18218 +       return 0;
18219 +}
18220 +
18221 +
18222 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18223 +{
18224 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18225 +
18226 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18227 +       return v;
18228 +}
18229 +
18230 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18231 +{
18232 +       kernel_cap_t c = __cap_empty_set;
18233 +
18234 +       c.cap[0] = v & 0xFFFFFFFF;
18235 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18236 +
18237 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18238 +       return c;
18239 +}
18240 +
18241 +
18242 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18243 +{
18244 +       if (bcaps)
18245 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18246 +       if (ccaps)
18247 +               *ccaps = vxi->vx_ccaps;
18248 +
18249 +       return 0;
18250 +}
18251 +
18252 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18253 +{
18254 +       struct vcmd_ctx_caps_v1 vc_data;
18255 +       int ret;
18256 +
18257 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18258 +       if (ret)
18259 +               return ret;
18260 +       vc_data.cmask = ~0ULL;
18261 +
18262 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18263 +               return -EFAULT;
18264 +       return 0;
18265 +}
18266 +
18267 +static int do_set_caps(struct vx_info *vxi,
18268 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18269 +{
18270 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18271 +
18272 +#if 0
18273 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18274 +               bcaps, bmask, ccaps, cmask);
18275 +#endif
18276 +       vxi->vx_bcaps = cap_t_from_caps(
18277 +               vs_mask_flags(bcold, bcaps, bmask));
18278 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18279 +
18280 +       return 0;
18281 +}
18282 +
18283 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18284 +{
18285 +       struct vcmd_ctx_caps_v1 vc_data;
18286 +
18287 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18288 +               return -EFAULT;
18289 +
18290 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18291 +}
18292 +
18293 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18294 +{
18295 +       struct vcmd_bcaps vc_data;
18296 +       int ret;
18297 +
18298 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18299 +       if (ret)
18300 +               return ret;
18301 +       vc_data.bmask = ~0ULL;
18302 +
18303 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18304 +               return -EFAULT;
18305 +       return 0;
18306 +}
18307 +
18308 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18309 +{
18310 +       struct vcmd_bcaps vc_data;
18311 +
18312 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18313 +               return -EFAULT;
18314 +
18315 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18316 +}
18317 +
18318 +
18319 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18320 +{
18321 +       struct vcmd_badness_v0 vc_data;
18322 +
18323 +       vc_data.bias = vxi->vx_badness_bias;
18324 +
18325 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18326 +               return -EFAULT;
18327 +       return 0;
18328 +}
18329 +
18330 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18331 +{
18332 +       struct vcmd_badness_v0 vc_data;
18333 +
18334 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18335 +               return -EFAULT;
18336 +
18337 +       vxi->vx_badness_bias = vc_data.bias;
18338 +       return 0;
18339 +}
18340 +
18341 +#include <linux/module.h>
18342 +
18343 +EXPORT_SYMBOL_GPL(free_vx_info);
18344 +
18345 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/cvirt.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cvirt.c
18346 --- linux-2.6.27.14/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
18347 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cvirt.c 2008-10-31 03:49:36.000000000 +0100
18348 @@ -0,0 +1,300 @@
18349 +/*
18350 + *  linux/kernel/vserver/cvirt.c
18351 + *
18352 + *  Virtual Server: Context Virtualization
18353 + *
18354 + *  Copyright (C) 2004-2007  Herbert Pötzl
18355 + *
18356 + *  V0.01  broken out from limit.c
18357 + *  V0.02  added utsname stuff
18358 + *  V0.03  changed vcmds to vxi arg
18359 + *
18360 + */
18361 +
18362 +#include <linux/types.h>
18363 +#include <linux/utsname.h>
18364 +#include <linux/vs_cvirt.h>
18365 +#include <linux/vserver/switch.h>
18366 +#include <linux/vserver/cvirt_cmd.h>
18367 +
18368 +#include <asm/uaccess.h>
18369 +
18370 +
18371 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18372 +{
18373 +       struct vx_info *vxi = current->vx_info;
18374 +
18375 +       set_normalized_timespec(uptime,
18376 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18377 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18378 +       if (!idle)
18379 +               return;
18380 +       set_normalized_timespec(idle,
18381 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18382 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18383 +       return;
18384 +}
18385 +
18386 +uint64_t vx_idle_jiffies(void)
18387 +{
18388 +       return init_task.utime + init_task.stime;
18389 +}
18390 +
18391 +
18392 +
18393 +static inline uint32_t __update_loadavg(uint32_t load,
18394 +       int wsize, int delta, int n)
18395 +{
18396 +       unsigned long long calc, prev;
18397 +
18398 +       /* just set it to n */
18399 +       if (unlikely(delta >= wsize))
18400 +               return (n << FSHIFT);
18401 +
18402 +       calc = delta * n;
18403 +       calc <<= FSHIFT;
18404 +       prev = (wsize - delta);
18405 +       prev *= load;
18406 +       calc += prev;
18407 +       do_div(calc, wsize);
18408 +       return calc;
18409 +}
18410 +
18411 +
18412 +void vx_update_load(struct vx_info *vxi)
18413 +{
18414 +       uint32_t now, last, delta;
18415 +       unsigned int nr_running, nr_uninterruptible;
18416 +       unsigned int total;
18417 +       unsigned long flags;
18418 +
18419 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18420 +
18421 +       now = jiffies;
18422 +       last = vxi->cvirt.load_last;
18423 +       delta = now - last;
18424 +
18425 +       if (delta < 5*HZ)
18426 +               goto out;
18427 +
18428 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18429 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18430 +       total = nr_running + nr_uninterruptible;
18431 +
18432 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18433 +               60*HZ, delta, total);
18434 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18435 +               5*60*HZ, delta, total);
18436 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18437 +               15*60*HZ, delta, total);
18438 +
18439 +       vxi->cvirt.load_last = now;
18440 +out:
18441 +       atomic_inc(&vxi->cvirt.load_updates);
18442 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18443 +}
18444 +
18445 +
18446 +/*
18447 + * Commands to do_syslog:
18448 + *
18449 + *      0 -- Close the log.  Currently a NOP.
18450 + *      1 -- Open the log. Currently a NOP.
18451 + *      2 -- Read from the log.
18452 + *      3 -- Read all messages remaining in the ring buffer.
18453 + *      4 -- Read and clear all messages remaining in the ring buffer
18454 + *      5 -- Clear ring buffer.
18455 + *      6 -- Disable printk's to console
18456 + *      7 -- Enable printk's to console
18457 + *      8 -- Set level of messages printed to console
18458 + *      9 -- Return number of unread characters in the log buffer
18459 + *     10 -- Return size of the log buffer
18460 + */
18461 +int vx_do_syslog(int type, char __user *buf, int len)
18462 +{
18463 +       int error = 0;
18464 +       int do_clear = 0;
18465 +       struct vx_info *vxi = current->vx_info;
18466 +       struct _vx_syslog *log;
18467 +
18468 +       if (!vxi)
18469 +               return -EINVAL;
18470 +       log = &vxi->cvirt.syslog;
18471 +
18472 +       switch (type) {
18473 +       case 0:         /* Close log */
18474 +       case 1:         /* Open log */
18475 +               break;
18476 +       case 2:         /* Read from log */
18477 +               error = wait_event_interruptible(log->log_wait,
18478 +                       (log->log_start - log->log_end));
18479 +               if (error)
18480 +                       break;
18481 +               spin_lock_irq(&log->logbuf_lock);
18482 +               spin_unlock_irq(&log->logbuf_lock);
18483 +               break;
18484 +       case 4:         /* Read/clear last kernel messages */
18485 +               do_clear = 1;
18486 +               /* fall through */
18487 +       case 3:         /* Read last kernel messages */
18488 +               return 0;
18489 +
18490 +       case 5:         /* Clear ring buffer */
18491 +               return 0;
18492 +
18493 +       case 6:         /* Disable logging to console */
18494 +       case 7:         /* Enable logging to console */
18495 +       case 8:         /* Set level of messages printed to console */
18496 +               break;
18497 +
18498 +       case 9:         /* Number of chars in the log buffer */
18499 +               return 0;
18500 +       case 10:        /* Size of the log buffer */
18501 +               return 0;
18502 +       default:
18503 +               error = -EINVAL;
18504 +               break;
18505 +       }
18506 +       return error;
18507 +}
18508 +
18509 +
18510 +/* virtual host info names */
18511 +
18512 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18513 +{
18514 +       struct nsproxy *nsproxy;
18515 +       struct uts_namespace *uts;
18516 +
18517 +       if (id == VHIN_CONTEXT)
18518 +               return vxi->vx_name;
18519 +
18520 +       nsproxy = vxi->vx_nsproxy[0];
18521 +       if (!nsproxy)
18522 +               return NULL;
18523 +
18524 +       uts = nsproxy->uts_ns;
18525 +       if (!uts)
18526 +               return NULL;
18527 +
18528 +       switch (id) {
18529 +       case VHIN_SYSNAME:
18530 +               return uts->name.sysname;
18531 +       case VHIN_NODENAME:
18532 +               return uts->name.nodename;
18533 +       case VHIN_RELEASE:
18534 +               return uts->name.release;
18535 +       case VHIN_VERSION:
18536 +               return uts->name.version;
18537 +       case VHIN_MACHINE:
18538 +               return uts->name.machine;
18539 +       case VHIN_DOMAINNAME:
18540 +               return uts->name.domainname;
18541 +       default:
18542 +               return NULL;
18543 +       }
18544 +       return NULL;
18545 +}
18546 +
18547 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18548 +{
18549 +       struct vcmd_vhi_name_v0 vc_data;
18550 +       char *name;
18551 +
18552 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18553 +               return -EFAULT;
18554 +
18555 +       name = vx_vhi_name(vxi, vc_data.field);
18556 +       if (!name)
18557 +               return -EINVAL;
18558 +
18559 +       memcpy(name, vc_data.name, 65);
18560 +       return 0;
18561 +}
18562 +
18563 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18564 +{
18565 +       struct vcmd_vhi_name_v0 vc_data;
18566 +       char *name;
18567 +
18568 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18569 +               return -EFAULT;
18570 +
18571 +       name = vx_vhi_name(vxi, vc_data.field);
18572 +       if (!name)
18573 +               return -EINVAL;
18574 +
18575 +       memcpy(vc_data.name, name, 65);
18576 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18577 +               return -EFAULT;
18578 +       return 0;
18579 +}
18580 +
18581 +
18582 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18583 +{
18584 +       struct vcmd_virt_stat_v0 vc_data;
18585 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18586 +       struct timespec uptime;
18587 +
18588 +       do_posix_clock_monotonic_gettime(&uptime);
18589 +       set_normalized_timespec(&uptime,
18590 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18591 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18592 +
18593 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18594 +       vc_data.uptime = timespec_to_ns(&uptime);
18595 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18596 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18597 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18598 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18599 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18600 +       vc_data.load[0] = cvirt->load[0];
18601 +       vc_data.load[1] = cvirt->load[1];
18602 +       vc_data.load[2] = cvirt->load[2];
18603 +
18604 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18605 +               return -EFAULT;
18606 +       return 0;
18607 +}
18608 +
18609 +
18610 +#ifdef CONFIG_VSERVER_VTIME
18611 +
18612 +/* virtualized time base */
18613 +
18614 +void vx_gettimeofday(struct timeval *tv)
18615 +{
18616 +       do_gettimeofday(tv);
18617 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18618 +               return;
18619 +
18620 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18621 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18622 +
18623 +       if (tv->tv_usec >= USEC_PER_SEC) {
18624 +               tv->tv_sec++;
18625 +               tv->tv_usec -= USEC_PER_SEC;
18626 +       } else if (tv->tv_usec < 0) {
18627 +               tv->tv_sec--;
18628 +               tv->tv_usec += USEC_PER_SEC;
18629 +       }
18630 +}
18631 +
18632 +int vx_settimeofday(struct timespec *ts)
18633 +{
18634 +       struct timeval tv;
18635 +
18636 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18637 +               return do_settimeofday(ts);
18638 +
18639 +       do_gettimeofday(&tv);
18640 +       current->vx_info->cvirt.bias_tv.tv_sec =
18641 +               ts->tv_sec - tv.tv_sec;
18642 +       current->vx_info->cvirt.bias_tv.tv_usec =
18643 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18644 +       return 0;
18645 +}
18646 +
18647 +#endif
18648 +
18649 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/cvirt_init.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cvirt_init.h
18650 --- linux-2.6.27.14/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
18651 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cvirt_init.h    2008-10-13 14:54:20.000000000 +0200
18652 @@ -0,0 +1,69 @@
18653 +
18654 +
18655 +extern uint64_t vx_idle_jiffies(void);
18656 +
18657 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18658 +{
18659 +       uint64_t idle_jiffies = vx_idle_jiffies();
18660 +       uint64_t nsuptime;
18661 +
18662 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18663 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18664 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18665 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18666 +       cvirt->bias_tv.tv_sec = 0;
18667 +       cvirt->bias_tv.tv_usec = 0;
18668 +
18669 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18670 +       atomic_set(&cvirt->nr_threads, 0);
18671 +       atomic_set(&cvirt->nr_running, 0);
18672 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18673 +       atomic_set(&cvirt->nr_onhold, 0);
18674 +
18675 +       spin_lock_init(&cvirt->load_lock);
18676 +       cvirt->load_last = jiffies;
18677 +       atomic_set(&cvirt->load_updates, 0);
18678 +       cvirt->load[0] = 0;
18679 +       cvirt->load[1] = 0;
18680 +       cvirt->load[2] = 0;
18681 +       atomic_set(&cvirt->total_forks, 0);
18682 +
18683 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18684 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18685 +       cvirt->syslog.log_start = 0;
18686 +       cvirt->syslog.log_end = 0;
18687 +       cvirt->syslog.con_start = 0;
18688 +       cvirt->syslog.logged_chars = 0;
18689 +}
18690 +
18691 +static inline
18692 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18693 +{
18694 +       // cvirt_pc->cpustat = { 0 };
18695 +}
18696 +
18697 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18698 +{
18699 +       int value;
18700 +
18701 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18702 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18703 +               cvirt, value);
18704 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18705 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18706 +               cvirt, value);
18707 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18708 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18709 +               cvirt, value);
18710 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18711 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18712 +               cvirt, value);
18713 +       return;
18714 +}
18715 +
18716 +static inline
18717 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18718 +{
18719 +       return;
18720 +}
18721 +
18722 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/cvirt_proc.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cvirt_proc.h
18723 --- linux-2.6.27.14/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
18724 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/cvirt_proc.h    2008-10-13 14:54:20.000000000 +0200
18725 @@ -0,0 +1,135 @@
18726 +#ifndef _VX_CVIRT_PROC_H
18727 +#define _VX_CVIRT_PROC_H
18728 +
18729 +#include <linux/nsproxy.h>
18730 +#include <linux/mnt_namespace.h>
18731 +#include <linux/ipc_namespace.h>
18732 +#include <linux/utsname.h>
18733 +#include <linux/ipc.h>
18734 +
18735 +
18736 +static inline
18737 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18738 +{
18739 +       struct mnt_namespace *ns;
18740 +       struct uts_namespace *uts;
18741 +       struct ipc_namespace *ipc;
18742 +       struct path path;
18743 +       char *pstr, *root;
18744 +       int length = 0;
18745 +
18746 +       if (!nsproxy)
18747 +               goto out;
18748 +
18749 +       length += sprintf(buffer + length,
18750 +               "NSProxy:\t%p [%p,%p,%p]\n",
18751 +               nsproxy, nsproxy->mnt_ns,
18752 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18753 +
18754 +       ns = nsproxy->mnt_ns;
18755 +       if (!ns)
18756 +               goto skip_ns;
18757 +
18758 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18759 +       if (!pstr)
18760 +               goto skip_ns;
18761 +
18762 +       path.mnt = ns->root;
18763 +       path.dentry = ns->root->mnt_root;
18764 +       root = d_path(&path, pstr, PATH_MAX - 2);
18765 +       length += sprintf(buffer + length,
18766 +               "Namespace:\t%p [#%u]\n"
18767 +               "RootPath:\t%s\n",
18768 +               ns, atomic_read(&ns->count),
18769 +               root);
18770 +       kfree(pstr);
18771 +skip_ns:
18772 +
18773 +       uts = nsproxy->uts_ns;
18774 +       if (!uts)
18775 +               goto skip_uts;
18776 +
18777 +       length += sprintf(buffer + length,
18778 +               "SysName:\t%.*s\n"
18779 +               "NodeName:\t%.*s\n"
18780 +               "Release:\t%.*s\n"
18781 +               "Version:\t%.*s\n"
18782 +               "Machine:\t%.*s\n"
18783 +               "DomainName:\t%.*s\n",
18784 +               __NEW_UTS_LEN, uts->name.sysname,
18785 +               __NEW_UTS_LEN, uts->name.nodename,
18786 +               __NEW_UTS_LEN, uts->name.release,
18787 +               __NEW_UTS_LEN, uts->name.version,
18788 +               __NEW_UTS_LEN, uts->name.machine,
18789 +               __NEW_UTS_LEN, uts->name.domainname);
18790 +skip_uts:
18791 +
18792 +       ipc = nsproxy->ipc_ns;
18793 +       if (!ipc)
18794 +               goto skip_ipc;
18795 +
18796 +       length += sprintf(buffer + length,
18797 +               "SEMS:\t\t%d %d %d %d  %d\n"
18798 +               "MSG:\t\t%d %d %d\n"
18799 +               "SHM:\t\t%lu %lu  %d %d\n",
18800 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18801 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18802 +               ipc->used_sems,
18803 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18804 +               (unsigned long)ipc->shm_ctlmax,
18805 +               (unsigned long)ipc->shm_ctlall,
18806 +               ipc->shm_ctlmni, ipc->shm_tot);
18807 +skip_ipc:
18808 +out:
18809 +       return length;
18810 +}
18811 +
18812 +
18813 +#include <linux/sched.h>
18814 +
18815 +#define LOAD_INT(x) ((x) >> FSHIFT)
18816 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18817 +
18818 +static inline
18819 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18820 +{
18821 +       int length = 0;
18822 +       int a, b, c;
18823 +
18824 +       length += sprintf(buffer + length,
18825 +               "BiasUptime:\t%lu.%02lu\n",
18826 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18827 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18828 +
18829 +       a = cvirt->load[0] + (FIXED_1 / 200);
18830 +       b = cvirt->load[1] + (FIXED_1 / 200);
18831 +       c = cvirt->load[2] + (FIXED_1 / 200);
18832 +       length += sprintf(buffer + length,
18833 +               "nr_threads:\t%d\n"
18834 +               "nr_running:\t%d\n"
18835 +               "nr_unintr:\t%d\n"
18836 +               "nr_onhold:\t%d\n"
18837 +               "load_updates:\t%d\n"
18838 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18839 +               "total_forks:\t%d\n",
18840 +               atomic_read(&cvirt->nr_threads),
18841 +               atomic_read(&cvirt->nr_running),
18842 +               atomic_read(&cvirt->nr_uninterruptible),
18843 +               atomic_read(&cvirt->nr_onhold),
18844 +               atomic_read(&cvirt->load_updates),
18845 +               LOAD_INT(a), LOAD_FRAC(a),
18846 +               LOAD_INT(b), LOAD_FRAC(b),
18847 +               LOAD_INT(c), LOAD_FRAC(c),
18848 +               atomic_read(&cvirt->total_forks));
18849 +       return length;
18850 +}
18851 +
18852 +static inline
18853 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18854 +       char *buffer, int cpu)
18855 +{
18856 +       int length = 0;
18857 +       return length;
18858 +}
18859 +
18860 +#endif /* _VX_CVIRT_PROC_H */
18861 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/debug.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/debug.c
18862 --- linux-2.6.27.14/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
18863 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/debug.c 2008-10-13 14:54:20.000000000 +0200
18864 @@ -0,0 +1,32 @@
18865 +/*
18866 + *  kernel/vserver/debug.c
18867 + *
18868 + *  Copyright (C) 2005-2007 Herbert Pötzl
18869 + *
18870 + *  V0.01  vx_info dump support
18871 + *
18872 + */
18873 +
18874 +#include <linux/module.h>
18875 +
18876 +#include <linux/vserver/context.h>
18877 +
18878 +
18879 +void   dump_vx_info(struct vx_info *vxi, int level)
18880 +{
18881 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18882 +               atomic_read(&vxi->vx_usecnt),
18883 +               atomic_read(&vxi->vx_tasks),
18884 +               vxi->vx_state);
18885 +       if (level > 0) {
18886 +               __dump_vx_limit(&vxi->limit);
18887 +               __dump_vx_sched(&vxi->sched);
18888 +               __dump_vx_cvirt(&vxi->cvirt);
18889 +               __dump_vx_cacct(&vxi->cacct);
18890 +       }
18891 +       printk("---\n");
18892 +}
18893 +
18894 +
18895 +EXPORT_SYMBOL_GPL(dump_vx_info);
18896 +
18897 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/device.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/device.c
18898 --- linux-2.6.27.14/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
18899 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/device.c        2008-10-13 14:54:20.000000000 +0200
18900 @@ -0,0 +1,443 @@
18901 +/*
18902 + *  linux/kernel/vserver/device.c
18903 + *
18904 + *  Linux-VServer: Device Support
18905 + *
18906 + *  Copyright (C) 2006  Herbert Pötzl
18907 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18908 + *
18909 + *  V0.01  device mapping basics
18910 + *  V0.02  added defaults
18911 + *
18912 + */
18913 +
18914 +#include <linux/slab.h>
18915 +#include <linux/rcupdate.h>
18916 +#include <linux/fs.h>
18917 +#include <linux/namei.h>
18918 +#include <linux/hash.h>
18919 +
18920 +#include <asm/errno.h>
18921 +#include <asm/uaccess.h>
18922 +#include <linux/vserver/base.h>
18923 +#include <linux/vserver/debug.h>
18924 +#include <linux/vserver/context.h>
18925 +#include <linux/vserver/device.h>
18926 +#include <linux/vserver/device_cmd.h>
18927 +
18928 +
18929 +#define DMAP_HASH_BITS 4
18930 +
18931 +
18932 +struct vs_mapping {
18933 +       union {
18934 +               struct hlist_node hlist;
18935 +               struct list_head list;
18936 +       } u;
18937 +#define dm_hlist       u.hlist
18938 +#define dm_list                u.list
18939 +       xid_t xid;
18940 +       dev_t device;
18941 +       struct vx_dmap_target target;
18942 +};
18943 +
18944 +
18945 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18946 +
18947 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18948 +
18949 +static struct vx_dmap_target dmap_defaults[2] = {
18950 +       { .flags = DATTR_OPEN },
18951 +       { .flags = DATTR_OPEN },
18952 +};
18953 +
18954 +
18955 +struct kmem_cache *dmap_cachep __read_mostly;
18956 +
18957 +int __init dmap_cache_init(void)
18958 +{
18959 +       dmap_cachep = kmem_cache_create("dmap_cache",
18960 +               sizeof(struct vs_mapping), 0,
18961 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18962 +       return 0;
18963 +}
18964 +
18965 +__initcall(dmap_cache_init);
18966 +
18967 +
18968 +static inline unsigned int __hashval(dev_t dev, int bits)
18969 +{
18970 +       return hash_long((unsigned long)dev, bits);
18971 +}
18972 +
18973 +
18974 +/*     __hash_mapping()
18975 + *     add the mapping to the hash table
18976 + */
18977 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18978 +{
18979 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18980 +       struct hlist_head *head, *hash = dmap_main_hash;
18981 +       int device = vdm->device;
18982 +
18983 +       spin_lock(hash_lock);
18984 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18985 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18986 +
18987 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18988 +       hlist_add_head(&vdm->dm_hlist, head);
18989 +       spin_unlock(hash_lock);
18990 +}
18991 +
18992 +
18993 +static inline int __mode_to_default(umode_t mode)
18994 +{
18995 +       switch (mode) {
18996 +       case S_IFBLK:
18997 +               return 0;
18998 +       case S_IFCHR:
18999 +               return 1;
19000 +       default:
19001 +               BUG();
19002 +       }
19003 +}
19004 +
19005 +
19006 +/*     __set_default()
19007 + *     set a default
19008 + */
19009 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19010 +       struct vx_dmap_target *vdmt)
19011 +{
19012 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19013 +       spin_lock(hash_lock);
19014 +
19015 +       if (vxi)
19016 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19017 +       else
19018 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19019 +
19020 +
19021 +       spin_unlock(hash_lock);
19022 +
19023 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19024 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19025 +}
19026 +
19027 +
19028 +/*     __remove_default()
19029 + *     remove a default
19030 + */
19031 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19032 +{
19033 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19034 +       spin_lock(hash_lock);
19035 +
19036 +       if (vxi)
19037 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19038 +       else    /* remove == reset */
19039 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19040 +
19041 +       spin_unlock(hash_lock);
19042 +       return 0;
19043 +}
19044 +
19045 +
19046 +/*     __find_mapping()
19047 + *     find a mapping in the hash table
19048 + *
19049 + *     caller must hold hash_lock
19050 + */
19051 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19052 +       struct vs_mapping **local, struct vs_mapping **global)
19053 +{
19054 +       struct hlist_head *hash = dmap_main_hash;
19055 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19056 +       struct hlist_node *pos;
19057 +       struct vs_mapping *vdm;
19058 +
19059 +       *local = NULL;
19060 +       if (global)
19061 +               *global = NULL;
19062 +
19063 +       hlist_for_each(pos, head) {
19064 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19065 +
19066 +               if ((vdm->device == device) &&
19067 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19068 +                       if (vdm->xid == xid) {
19069 +                               *local = vdm;
19070 +                               return 1;
19071 +                       } else if (global && vdm->xid == 0)
19072 +                               *global = vdm;
19073 +               }
19074 +       }
19075 +
19076 +       if (global && *global)
19077 +               return 0;
19078 +       else
19079 +               return -ENOENT;
19080 +}
19081 +
19082 +
19083 +/*     __lookup_mapping()
19084 + *     find a mapping and store the result in target and flags
19085 + */
19086 +static inline int __lookup_mapping(struct vx_info *vxi,
19087 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19088 +{
19089 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19090 +       struct vs_mapping *vdm, *global;
19091 +       struct vx_dmap_target *vdmt;
19092 +       int ret = 0;
19093 +       xid_t xid = vxi->vx_id;
19094 +       int index;
19095 +
19096 +       spin_lock(hash_lock);
19097 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19098 +               ret = 1;
19099 +               vdmt = &vdm->target;
19100 +               goto found;
19101 +       }
19102 +
19103 +       index = __mode_to_default(mode);
19104 +       if (vxi && vxi->dmap.targets[index].flags) {
19105 +               ret = 2;
19106 +               vdmt = &vxi->dmap.targets[index];
19107 +       } else if (global) {
19108 +               ret = 3;
19109 +               vdmt = &global->target;
19110 +               goto found;
19111 +       } else {
19112 +               ret = 4;
19113 +               vdmt = &dmap_defaults[index];
19114 +       }
19115 +
19116 +found:
19117 +       if (target && (vdmt->flags & DATTR_REMAP))
19118 +               *target = vdmt->target;
19119 +       else if (target)
19120 +               *target = device;
19121 +       if (flags)
19122 +               *flags = vdmt->flags;
19123 +
19124 +       spin_unlock(hash_lock);
19125 +
19126 +       return ret;
19127 +}
19128 +
19129 +
19130 +/*     __remove_mapping()
19131 + *     remove a mapping from the hash table
19132 + */
19133 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19134 +       umode_t mode)
19135 +{
19136 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19137 +       struct vs_mapping *vdm = NULL;
19138 +       int ret = 0;
19139 +
19140 +       spin_lock(hash_lock);
19141 +
19142 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19143 +               NULL);
19144 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19145 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19146 +       if (ret < 0)
19147 +               goto out;
19148 +       hlist_del(&vdm->dm_hlist);
19149 +
19150 +out:
19151 +       spin_unlock(hash_lock);
19152 +       if (vdm)
19153 +               kmem_cache_free(dmap_cachep, vdm);
19154 +       return ret;
19155 +}
19156 +
19157 +
19158 +
19159 +int vs_map_device(struct vx_info *vxi,
19160 +       dev_t device, dev_t *target, umode_t mode)
19161 +{
19162 +       int ret, flags = DATTR_MASK;
19163 +
19164 +       if (!vxi) {
19165 +               if (target)
19166 +                       *target = device;
19167 +               goto out;
19168 +       }
19169 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19170 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19171 +               device, target ? *target : 0, flags, mode, ret);
19172 +out:
19173 +       return (flags & DATTR_MASK);
19174 +}
19175 +
19176 +
19177 +
19178 +static int do_set_mapping(struct vx_info *vxi,
19179 +       dev_t device, dev_t target, int flags, umode_t mode)
19180 +{
19181 +       if (device) {
19182 +               struct vs_mapping *new;
19183 +
19184 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19185 +               if (!new)
19186 +                       return -ENOMEM;
19187 +
19188 +               INIT_HLIST_NODE(&new->dm_hlist);
19189 +               new->device = device;
19190 +               new->target.target = target;
19191 +               new->target.flags = flags | mode;
19192 +               new->xid = (vxi ? vxi->vx_id : 0);
19193 +
19194 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19195 +               __hash_mapping(vxi, new);
19196 +       } else {
19197 +               struct vx_dmap_target new = {
19198 +                       .target = target,
19199 +                       .flags = flags | mode,
19200 +               };
19201 +               __set_default(vxi, mode, &new);
19202 +       }
19203 +       return 0;
19204 +}
19205 +
19206 +
19207 +static int do_unset_mapping(struct vx_info *vxi,
19208 +       dev_t device, dev_t target, int flags, umode_t mode)
19209 +{
19210 +       int ret = -EINVAL;
19211 +
19212 +       if (device) {
19213 +               ret = __remove_mapping(vxi, device, mode);
19214 +               if (ret < 0)
19215 +                       goto out;
19216 +       } else {
19217 +               ret = __remove_default(vxi, mode);
19218 +               if (ret < 0)
19219 +                       goto out;
19220 +       }
19221 +
19222 +out:
19223 +       return ret;
19224 +}
19225 +
19226 +
19227 +static inline int __user_device(const char __user *name, dev_t *dev,
19228 +       umode_t *mode)
19229 +{
19230 +       struct nameidata nd;
19231 +       int ret;
19232 +
19233 +       if (!name) {
19234 +               *dev = 0;
19235 +               return 0;
19236 +       }
19237 +       ret = user_lpath(name, &nd.path);
19238 +       if (ret)
19239 +               return ret;
19240 +       if (nd.path.dentry->d_inode) {
19241 +               *dev = nd.path.dentry->d_inode->i_rdev;
19242 +               *mode = nd.path.dentry->d_inode->i_mode;
19243 +       }
19244 +       path_put(&nd.path);
19245 +       return 0;
19246 +}
19247 +
19248 +static inline int __mapping_mode(dev_t device, dev_t target,
19249 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19250 +{
19251 +       if (device)
19252 +               *mode = device_mode & S_IFMT;
19253 +       else if (target)
19254 +               *mode = target_mode & S_IFMT;
19255 +       else
19256 +               return -EINVAL;
19257 +
19258 +       /* if both given, device and target mode have to match */
19259 +       if (device && target &&
19260 +               ((device_mode ^ target_mode) & S_IFMT))
19261 +               return -EINVAL;
19262 +       return 0;
19263 +}
19264 +
19265 +
19266 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19267 +       const char __user *target_path, int flags, int set)
19268 +{
19269 +       dev_t device = ~0, target = ~0;
19270 +       umode_t device_mode = 0, target_mode = 0, mode;
19271 +       int ret;
19272 +
19273 +       ret = __user_device(device_path, &device, &device_mode);
19274 +       if (ret)
19275 +               return ret;
19276 +       ret = __user_device(target_path, &target, &target_mode);
19277 +       if (ret)
19278 +               return ret;
19279 +
19280 +       ret = __mapping_mode(device, target,
19281 +               device_mode, target_mode, &mode);
19282 +       if (ret)
19283 +               return ret;
19284 +
19285 +       if (set)
19286 +               return do_set_mapping(vxi, device, target,
19287 +                       flags, mode);
19288 +       else
19289 +               return do_unset_mapping(vxi, device, target,
19290 +                       flags, mode);
19291 +}
19292 +
19293 +
19294 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19295 +{
19296 +       struct vcmd_set_mapping_v0 vc_data;
19297 +
19298 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19299 +               return -EFAULT;
19300 +
19301 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19302 +               vc_data.flags, 1);
19303 +}
19304 +
19305 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19306 +{
19307 +       struct vcmd_set_mapping_v0 vc_data;
19308 +
19309 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19310 +               return -EFAULT;
19311 +
19312 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19313 +               vc_data.flags, 0);
19314 +}
19315 +
19316 +
19317 +#ifdef CONFIG_COMPAT
19318 +
19319 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19320 +{
19321 +       struct vcmd_set_mapping_v0_x32 vc_data;
19322 +
19323 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19324 +               return -EFAULT;
19325 +
19326 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19327 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19328 +}
19329 +
19330 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19331 +{
19332 +       struct vcmd_set_mapping_v0_x32 vc_data;
19333 +
19334 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19335 +               return -EFAULT;
19336 +
19337 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19338 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19339 +}
19340 +
19341 +#endif /* CONFIG_COMPAT */
19342 +
19343 +
19344 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/dlimit.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/dlimit.c
19345 --- linux-2.6.27.14/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
19346 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/dlimit.c        2008-10-13 14:54:20.000000000 +0200
19347 @@ -0,0 +1,522 @@
19348 +/*
19349 + *  linux/kernel/vserver/dlimit.c
19350 + *
19351 + *  Virtual Server: Context Disk Limits
19352 + *
19353 + *  Copyright (C) 2004-2007  Herbert Pötzl
19354 + *
19355 + *  V0.01  initial version
19356 + *  V0.02  compat32 splitup
19357 + *
19358 + */
19359 +
19360 +#include <linux/statfs.h>
19361 +#include <linux/sched.h>
19362 +#include <linux/namei.h>
19363 +#include <linux/vs_tag.h>
19364 +#include <linux/vs_dlimit.h>
19365 +#include <linux/vserver/dlimit_cmd.h>
19366 +
19367 +#include <asm/uaccess.h>
19368 +
19369 +/*     __alloc_dl_info()
19370 +
19371 +       * allocate an initialized dl_info struct
19372 +       * doesn't make it visible (hash)                        */
19373 +
19374 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19375 +{
19376 +       struct dl_info *new = NULL;
19377 +
19378 +       vxdprintk(VXD_CBIT(dlim, 5),
19379 +               "alloc_dl_info(%p,%d)*", sb, tag);
19380 +
19381 +       /* would this benefit from a slab cache? */
19382 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19383 +       if (!new)
19384 +               return 0;
19385 +
19386 +       memset(new, 0, sizeof(struct dl_info));
19387 +       new->dl_tag = tag;
19388 +       new->dl_sb = sb;
19389 +       INIT_RCU_HEAD(&new->dl_rcu);
19390 +       INIT_HLIST_NODE(&new->dl_hlist);
19391 +       spin_lock_init(&new->dl_lock);
19392 +       atomic_set(&new->dl_refcnt, 0);
19393 +       atomic_set(&new->dl_usecnt, 0);
19394 +
19395 +       /* rest of init goes here */
19396 +
19397 +       vxdprintk(VXD_CBIT(dlim, 4),
19398 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19399 +       return new;
19400 +}
19401 +
19402 +/*     __dealloc_dl_info()
19403 +
19404 +       * final disposal of dl_info                             */
19405 +
19406 +static void __dealloc_dl_info(struct dl_info *dli)
19407 +{
19408 +       vxdprintk(VXD_CBIT(dlim, 4),
19409 +               "dealloc_dl_info(%p)", dli);
19410 +
19411 +       dli->dl_hlist.next = LIST_POISON1;
19412 +       dli->dl_tag = -1;
19413 +       dli->dl_sb = 0;
19414 +
19415 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19416 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19417 +
19418 +       kfree(dli);
19419 +}
19420 +
19421 +
19422 +/*     hash table for dl_info hash */
19423 +
19424 +#define DL_HASH_SIZE   13
19425 +
19426 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19427 +
19428 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19429 +
19430 +
19431 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19432 +{
19433 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19434 +}
19435 +
19436 +
19437 +
19438 +/*     __hash_dl_info()
19439 +
19440 +       * add the dli to the global hash table
19441 +       * requires the hash_lock to be held                     */
19442 +
19443 +static inline void __hash_dl_info(struct dl_info *dli)
19444 +{
19445 +       struct hlist_head *head;
19446 +
19447 +       vxdprintk(VXD_CBIT(dlim, 6),
19448 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19449 +       get_dl_info(dli);
19450 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19451 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19452 +}
19453 +
19454 +/*     __unhash_dl_info()
19455 +
19456 +       * remove the dli from the global hash table
19457 +       * requires the hash_lock to be held                     */
19458 +
19459 +static inline void __unhash_dl_info(struct dl_info *dli)
19460 +{
19461 +       vxdprintk(VXD_CBIT(dlim, 6),
19462 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19463 +       hlist_del_rcu(&dli->dl_hlist);
19464 +       put_dl_info(dli);
19465 +}
19466 +
19467 +
19468 +/*     __lookup_dl_info()
19469 +
19470 +       * requires the rcu_read_lock()
19471 +       * doesn't increment the dl_refcnt                       */
19472 +
19473 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19474 +{
19475 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19476 +       struct hlist_node *pos;
19477 +       struct dl_info *dli;
19478 +
19479 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19480 +
19481 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19482 +                       return dli;
19483 +               }
19484 +       }
19485 +       return NULL;
19486 +}
19487 +
19488 +
19489 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19490 +{
19491 +       struct dl_info *dli;
19492 +
19493 +       rcu_read_lock();
19494 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19495 +       vxdprintk(VXD_CBIT(dlim, 7),
19496 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19497 +       rcu_read_unlock();
19498 +       return dli;
19499 +}
19500 +
19501 +void rcu_free_dl_info(struct rcu_head *head)
19502 +{
19503 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19504 +       int usecnt, refcnt;
19505 +
19506 +       BUG_ON(!dli || !head);
19507 +
19508 +       usecnt = atomic_read(&dli->dl_usecnt);
19509 +       BUG_ON(usecnt < 0);
19510 +
19511 +       refcnt = atomic_read(&dli->dl_refcnt);
19512 +       BUG_ON(refcnt < 0);
19513 +
19514 +       vxdprintk(VXD_CBIT(dlim, 3),
19515 +               "rcu_free_dl_info(%p)", dli);
19516 +       if (!usecnt)
19517 +               __dealloc_dl_info(dli);
19518 +       else
19519 +               printk("!!! rcu didn't free\n");
19520 +}
19521 +
19522 +
19523 +
19524 +
19525 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19526 +       uint32_t flags, int add)
19527 +{
19528 +       struct path path;
19529 +       int ret;
19530 +
19531 +       ret = user_lpath(name, &path);
19532 +       if (!ret) {
19533 +               struct super_block *sb;
19534 +               struct dl_info *dli;
19535 +
19536 +               ret = -EINVAL;
19537 +               if (!path.dentry->d_inode)
19538 +                       goto out_release;
19539 +               if (!(sb = path.dentry->d_inode->i_sb))
19540 +                       goto out_release;
19541 +
19542 +               if (add) {
19543 +                       dli = __alloc_dl_info(sb, id);
19544 +                       spin_lock(&dl_info_hash_lock);
19545 +
19546 +                       ret = -EEXIST;
19547 +                       if (__lookup_dl_info(sb, id))
19548 +                               goto out_unlock;
19549 +                       __hash_dl_info(dli);
19550 +                       dli = NULL;
19551 +               } else {
19552 +                       spin_lock(&dl_info_hash_lock);
19553 +                       dli = __lookup_dl_info(sb, id);
19554 +
19555 +                       ret = -ESRCH;
19556 +                       if (!dli)
19557 +                               goto out_unlock;
19558 +                       __unhash_dl_info(dli);
19559 +               }
19560 +               ret = 0;
19561 +       out_unlock:
19562 +               spin_unlock(&dl_info_hash_lock);
19563 +               if (add && dli)
19564 +                       __dealloc_dl_info(dli);
19565 +       out_release:
19566 +               path_put(&path);
19567 +       }
19568 +       return ret;
19569 +}
19570 +
19571 +int vc_add_dlimit(uint32_t id, void __user *data)
19572 +{
19573 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19574 +
19575 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19576 +               return -EFAULT;
19577 +
19578 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19579 +}
19580 +
19581 +int vc_rem_dlimit(uint32_t id, void __user *data)
19582 +{
19583 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19584 +
19585 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19586 +               return -EFAULT;
19587 +
19588 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19589 +}
19590 +
19591 +#ifdef CONFIG_COMPAT
19592 +
19593 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19594 +{
19595 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19596 +
19597 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19598 +               return -EFAULT;
19599 +
19600 +       return do_addrem_dlimit(id,
19601 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19602 +}
19603 +
19604 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19605 +{
19606 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19607 +
19608 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19609 +               return -EFAULT;
19610 +
19611 +       return do_addrem_dlimit(id,
19612 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19613 +}
19614 +
19615 +#endif /* CONFIG_COMPAT */
19616 +
19617 +
19618 +static inline
19619 +int do_set_dlimit(uint32_t id, const char __user *name,
19620 +       uint32_t space_used, uint32_t space_total,
19621 +       uint32_t inodes_used, uint32_t inodes_total,
19622 +       uint32_t reserved, uint32_t flags)
19623 +{
19624 +       struct path path;
19625 +       int ret;
19626 +
19627 +       ret = user_lpath(name, &path);
19628 +       if (!ret) {
19629 +               struct super_block *sb;
19630 +               struct dl_info *dli;
19631 +
19632 +               ret = -EINVAL;
19633 +               if (!path.dentry->d_inode)
19634 +                       goto out_release;
19635 +               if (!(sb = path.dentry->d_inode->i_sb))
19636 +                       goto out_release;
19637 +               if ((reserved != CDLIM_KEEP &&
19638 +                       reserved > 100) ||
19639 +                       (inodes_used != CDLIM_KEEP &&
19640 +                       inodes_used > inodes_total) ||
19641 +                       (space_used != CDLIM_KEEP &&
19642 +                       space_used > space_total))
19643 +                       goto out_release;
19644 +
19645 +               ret = -ESRCH;
19646 +               dli = locate_dl_info(sb, id);
19647 +               if (!dli)
19648 +                       goto out_release;
19649 +
19650 +               spin_lock(&dli->dl_lock);
19651 +
19652 +               if (inodes_used != CDLIM_KEEP)
19653 +                       dli->dl_inodes_used = inodes_used;
19654 +               if (inodes_total != CDLIM_KEEP)
19655 +                       dli->dl_inodes_total = inodes_total;
19656 +               if (space_used != CDLIM_KEEP) {
19657 +                       dli->dl_space_used = space_used;
19658 +                       dli->dl_space_used <<= 10;
19659 +               }
19660 +               if (space_total == CDLIM_INFINITY)
19661 +                       dli->dl_space_total = DLIM_INFINITY;
19662 +               else if (space_total != CDLIM_KEEP) {
19663 +                       dli->dl_space_total = space_total;
19664 +                       dli->dl_space_total <<= 10;
19665 +               }
19666 +               if (reserved != CDLIM_KEEP)
19667 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19668 +
19669 +               spin_unlock(&dli->dl_lock);
19670 +
19671 +               put_dl_info(dli);
19672 +               ret = 0;
19673 +
19674 +       out_release:
19675 +               path_put(&path);
19676 +       }
19677 +       return ret;
19678 +}
19679 +
19680 +int vc_set_dlimit(uint32_t id, void __user *data)
19681 +{
19682 +       struct vcmd_ctx_dlimit_v0 vc_data;
19683 +
19684 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19685 +               return -EFAULT;
19686 +
19687 +       return do_set_dlimit(id, vc_data.name,
19688 +               vc_data.space_used, vc_data.space_total,
19689 +               vc_data.inodes_used, vc_data.inodes_total,
19690 +               vc_data.reserved, vc_data.flags);
19691 +}
19692 +
19693 +#ifdef CONFIG_COMPAT
19694 +
19695 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19696 +{
19697 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19698 +
19699 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19700 +               return -EFAULT;
19701 +
19702 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19703 +               vc_data.space_used, vc_data.space_total,
19704 +               vc_data.inodes_used, vc_data.inodes_total,
19705 +               vc_data.reserved, vc_data.flags);
19706 +}
19707 +
19708 +#endif /* CONFIG_COMPAT */
19709 +
19710 +
19711 +static inline
19712 +int do_get_dlimit(uint32_t id, const char __user *name,
19713 +       uint32_t *space_used, uint32_t *space_total,
19714 +       uint32_t *inodes_used, uint32_t *inodes_total,
19715 +       uint32_t *reserved, uint32_t *flags)
19716 +{
19717 +       struct path path;
19718 +       int ret;
19719 +
19720 +       ret = user_lpath(name, &path);
19721 +       if (!ret) {
19722 +               struct super_block *sb;
19723 +               struct dl_info *dli;
19724 +
19725 +               ret = -EINVAL;
19726 +               if (!path.dentry->d_inode)
19727 +                       goto out_release;
19728 +               if (!(sb = path.dentry->d_inode->i_sb))
19729 +                       goto out_release;
19730 +
19731 +               ret = -ESRCH;
19732 +               dli = locate_dl_info(sb, id);
19733 +               if (!dli)
19734 +                       goto out_release;
19735 +
19736 +               spin_lock(&dli->dl_lock);
19737 +               *inodes_used = dli->dl_inodes_used;
19738 +               *inodes_total = dli->dl_inodes_total;
19739 +               *space_used = dli->dl_space_used >> 10;
19740 +               if (dli->dl_space_total == DLIM_INFINITY)
19741 +                       *space_total = CDLIM_INFINITY;
19742 +               else
19743 +                       *space_total = dli->dl_space_total >> 10;
19744 +
19745 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19746 +               spin_unlock(&dli->dl_lock);
19747 +
19748 +               put_dl_info(dli);
19749 +               ret = -EFAULT;
19750 +
19751 +               ret = 0;
19752 +       out_release:
19753 +               path_put(&path);
19754 +       }
19755 +       return ret;
19756 +}
19757 +
19758 +
19759 +int vc_get_dlimit(uint32_t id, void __user *data)
19760 +{
19761 +       struct vcmd_ctx_dlimit_v0 vc_data;
19762 +       int ret;
19763 +
19764 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19765 +               return -EFAULT;
19766 +
19767 +       ret = do_get_dlimit(id, vc_data.name,
19768 +               &vc_data.space_used, &vc_data.space_total,
19769 +               &vc_data.inodes_used, &vc_data.inodes_total,
19770 +               &vc_data.reserved, &vc_data.flags);
19771 +       if (ret)
19772 +               return ret;
19773 +
19774 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19775 +               return -EFAULT;
19776 +       return 0;
19777 +}
19778 +
19779 +#ifdef CONFIG_COMPAT
19780 +
19781 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19782 +{
19783 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19784 +       int ret;
19785 +
19786 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19787 +               return -EFAULT;
19788 +
19789 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19790 +               &vc_data.space_used, &vc_data.space_total,
19791 +               &vc_data.inodes_used, &vc_data.inodes_total,
19792 +               &vc_data.reserved, &vc_data.flags);
19793 +       if (ret)
19794 +               return ret;
19795 +
19796 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19797 +               return -EFAULT;
19798 +       return 0;
19799 +}
19800 +
19801 +#endif /* CONFIG_COMPAT */
19802 +
19803 +
19804 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19805 +{
19806 +       struct dl_info *dli;
19807 +       __u64 blimit, bfree, bavail;
19808 +       __u32 ifree;
19809 +
19810 +       dli = locate_dl_info(sb, dx_current_tag());
19811 +       if (!dli)
19812 +               return;
19813 +
19814 +       spin_lock(&dli->dl_lock);
19815 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19816 +               goto no_ilim;
19817 +
19818 +       /* reduce max inodes available to limit */
19819 +       if (buf->f_files > dli->dl_inodes_total)
19820 +               buf->f_files = dli->dl_inodes_total;
19821 +
19822 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19823 +       /* reduce free inodes to min */
19824 +       if (ifree < buf->f_ffree)
19825 +               buf->f_ffree = ifree;
19826 +
19827 +no_ilim:
19828 +       if (dli->dl_space_total == DLIM_INFINITY)
19829 +               goto no_blim;
19830 +
19831 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19832 +
19833 +       if (dli->dl_space_total < dli->dl_space_used)
19834 +               bfree = 0;
19835 +       else
19836 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19837 +                       >> sb->s_blocksize_bits;
19838 +
19839 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19840 +       if (bavail < dli->dl_space_used)
19841 +               bavail = 0;
19842 +       else
19843 +               bavail = (bavail - dli->dl_space_used)
19844 +                       >> sb->s_blocksize_bits;
19845 +
19846 +       /* reduce max space available to limit */
19847 +       if (buf->f_blocks > blimit)
19848 +               buf->f_blocks = blimit;
19849 +
19850 +       /* reduce free space to min */
19851 +       if (bfree < buf->f_bfree)
19852 +               buf->f_bfree = bfree;
19853 +
19854 +       /* reduce avail space to min */
19855 +       if (bavail < buf->f_bavail)
19856 +               buf->f_bavail = bavail;
19857 +
19858 +no_blim:
19859 +       spin_unlock(&dli->dl_lock);
19860 +       put_dl_info(dli);
19861 +
19862 +       return;
19863 +}
19864 +
19865 +#include <linux/module.h>
19866 +
19867 +EXPORT_SYMBOL_GPL(locate_dl_info);
19868 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19869 +
19870 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/helper.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/helper.c
19871 --- linux-2.6.27.14/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
19872 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/helper.c        2008-10-13 14:54:20.000000000 +0200
19873 @@ -0,0 +1,199 @@
19874 +/*
19875 + *  linux/kernel/vserver/helper.c
19876 + *
19877 + *  Virtual Context Support
19878 + *
19879 + *  Copyright (C) 2004-2007  Herbert Pötzl
19880 + *
19881 + *  V0.01  basic helper
19882 + *
19883 + */
19884 +
19885 +#include <linux/kmod.h>
19886 +#include <linux/reboot.h>
19887 +#include <linux/vs_context.h>
19888 +#include <linux/vs_network.h>
19889 +#include <linux/vserver/signal.h>
19890 +
19891 +
19892 +char vshelper_path[255] = "/sbin/vshelper";
19893 +
19894 +
19895 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19896 +{
19897 +       int ret;
19898 +
19899 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19900 +               printk( KERN_WARNING
19901 +                       "%s: (%s %s) returned %s with %d\n",
19902 +                       name, argv[1], argv[2],
19903 +                       sync ? "sync" : "async", ret);
19904 +       }
19905 +       vxdprintk(VXD_CBIT(switch, 4),
19906 +               "%s: (%s %s) returned %s with %d",
19907 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19908 +       return ret;
19909 +}
19910 +
19911 +/*
19912 + *      vshelper path is set via /proc/sys
19913 + *      invoked by vserver sys_reboot(), with
19914 + *      the following arguments
19915 + *
19916 + *      argv [0] = vshelper_path;
19917 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19918 + *      argv [2] = context identifier
19919 + *
19920 + *      envp [*] = type-specific parameters
19921 + */
19922 +
19923 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19924 +{
19925 +       char id_buf[8], cmd_buf[16];
19926 +       char uid_buf[16], pid_buf[16];
19927 +       int ret;
19928 +
19929 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19930 +       char *envp[] = {"HOME=/", "TERM=linux",
19931 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19932 +                       uid_buf, pid_buf, cmd_buf, 0};
19933 +
19934 +       if (vx_info_state(vxi, VXS_HELPER))
19935 +               return -EAGAIN;
19936 +       vxi->vx_state |= VXS_HELPER;
19937 +
19938 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19939 +
19940 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19941 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
19942 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19943 +
19944 +       switch (cmd) {
19945 +       case LINUX_REBOOT_CMD_RESTART:
19946 +               argv[1] = "restart";
19947 +               break;
19948 +
19949 +       case LINUX_REBOOT_CMD_HALT:
19950 +               argv[1] = "halt";
19951 +               break;
19952 +
19953 +       case LINUX_REBOOT_CMD_POWER_OFF:
19954 +               argv[1] = "poweroff";
19955 +               break;
19956 +
19957 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19958 +               argv[1] = "swsusp";
19959 +               break;
19960 +
19961 +       default:
19962 +               vxi->vx_state &= ~VXS_HELPER;
19963 +               return 0;
19964 +       }
19965 +
19966 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19967 +       vxi->vx_state &= ~VXS_HELPER;
19968 +       __wakeup_vx_info(vxi);
19969 +       return (ret) ? -EPERM : 0;
19970 +}
19971 +
19972 +
19973 +long vs_reboot(unsigned int cmd, void __user *arg)
19974 +{
19975 +       struct vx_info *vxi = current->vx_info;
19976 +       long ret = 0;
19977 +
19978 +       vxdprintk(VXD_CBIT(misc, 5),
19979 +               "vs_reboot(%p[#%d],%d)",
19980 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19981 +
19982 +       ret = vs_reboot_helper(vxi, cmd, arg);
19983 +       if (ret)
19984 +               return ret;
19985 +
19986 +       vxi->reboot_cmd = cmd;
19987 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19988 +               switch (cmd) {
19989 +               case LINUX_REBOOT_CMD_RESTART:
19990 +               case LINUX_REBOOT_CMD_HALT:
19991 +               case LINUX_REBOOT_CMD_POWER_OFF:
19992 +                       vx_info_kill(vxi, 0, SIGKILL);
19993 +                       vx_info_kill(vxi, 1, SIGKILL);
19994 +               default:
19995 +                       break;
19996 +               }
19997 +       }
19998 +       return 0;
19999 +}
20000 +
20001 +
20002 +/*
20003 + *      argv [0] = vshelper_path;
20004 + *      argv [1] = action: "startup", "shutdown"
20005 + *      argv [2] = context identifier
20006 + *
20007 + *      envp [*] = type-specific parameters
20008 + */
20009 +
20010 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20011 +{
20012 +       char id_buf[8], cmd_buf[16];
20013 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20014 +       char *envp[] = {"HOME=/", "TERM=linux",
20015 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20016 +
20017 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20018 +               return 0;
20019 +
20020 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20021 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20022 +
20023 +       switch (cmd) {
20024 +       case VSC_STARTUP:
20025 +               argv[1] = "startup";
20026 +               break;
20027 +       case VSC_SHUTDOWN:
20028 +               argv[1] = "shutdown";
20029 +               break;
20030 +       default:
20031 +               return 0;
20032 +       }
20033 +
20034 +       return do_vshelper(vshelper_path, argv, envp, 1);
20035 +}
20036 +
20037 +
20038 +/*
20039 + *      argv [0] = vshelper_path;
20040 + *      argv [1] = action: "netup", "netdown"
20041 + *      argv [2] = context identifier
20042 + *
20043 + *      envp [*] = type-specific parameters
20044 + */
20045 +
20046 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20047 +{
20048 +       char id_buf[8], cmd_buf[16];
20049 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20050 +       char *envp[] = {"HOME=/", "TERM=linux",
20051 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20052 +
20053 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20054 +               return 0;
20055 +
20056 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20057 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20058 +
20059 +       switch (cmd) {
20060 +       case VSC_NETUP:
20061 +               argv[1] = "netup";
20062 +               break;
20063 +       case VSC_NETDOWN:
20064 +               argv[1] = "netdown";
20065 +               break;
20066 +       default:
20067 +               return 0;
20068 +       }
20069 +
20070 +       return do_vshelper(vshelper_path, argv, envp, 1);
20071 +}
20072 +
20073 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/history.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/history.c
20074 --- linux-2.6.27.14/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
20075 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/history.c       2008-10-13 14:54:20.000000000 +0200
20076 @@ -0,0 +1,258 @@
20077 +/*
20078 + *  kernel/vserver/history.c
20079 + *
20080 + *  Virtual Context History Backtrace
20081 + *
20082 + *  Copyright (C) 2004-2007  Herbert Pötzl
20083 + *
20084 + *  V0.01  basic structure
20085 + *  V0.02  hash/unhash and trace
20086 + *  V0.03  preemption fixes
20087 + *
20088 + */
20089 +
20090 +#include <linux/module.h>
20091 +#include <asm/uaccess.h>
20092 +
20093 +#include <linux/vserver/context.h>
20094 +#include <linux/vserver/debug.h>
20095 +#include <linux/vserver/debug_cmd.h>
20096 +#include <linux/vserver/history.h>
20097 +
20098 +
20099 +#ifdef CONFIG_VSERVER_HISTORY
20100 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20101 +#else
20102 +#define VXH_SIZE       64
20103 +#endif
20104 +
20105 +struct _vx_history {
20106 +       unsigned int counter;
20107 +
20108 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20109 +};
20110 +
20111 +
20112 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20113 +
20114 +unsigned volatile int vxh_active = 1;
20115 +
20116 +static atomic_t sequence = ATOMIC_INIT(0);
20117 +
20118 +
20119 +/*     vxh_advance()
20120 +
20121 +       * requires disabled preemption                          */
20122 +
20123 +struct _vx_hist_entry *vxh_advance(void *loc)
20124 +{
20125 +       unsigned int cpu = smp_processor_id();
20126 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20127 +       struct _vx_hist_entry *entry;
20128 +       unsigned int index;
20129 +
20130 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20131 +       entry = &hist->entry[index];
20132 +
20133 +       entry->seq = atomic_inc_return(&sequence);
20134 +       entry->loc = loc;
20135 +       return entry;
20136 +}
20137 +
20138 +EXPORT_SYMBOL_GPL(vxh_advance);
20139 +
20140 +
20141 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20142 +
20143 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20144 +
20145 +
20146 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20147 +
20148 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20149 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20150 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20151 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20152 +
20153 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20154 +{
20155 +       switch (e->type) {
20156 +       case VXH_THROW_OOPS:
20157 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20158 +               break;
20159 +
20160 +       case VXH_GET_VX_INFO:
20161 +       case VXH_PUT_VX_INFO:
20162 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20163 +                       VXH_LOC_ARGS(e),
20164 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20165 +                       VXH_VXI_ARGS(e));
20166 +               break;
20167 +
20168 +       case VXH_INIT_VX_INFO:
20169 +       case VXH_SET_VX_INFO:
20170 +       case VXH_CLR_VX_INFO:
20171 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20172 +                       VXH_LOC_ARGS(e),
20173 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20174 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20175 +                       VXH_VXI_ARGS(e), e->sc.data);
20176 +               break;
20177 +
20178 +       case VXH_CLAIM_VX_INFO:
20179 +       case VXH_RELEASE_VX_INFO:
20180 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20181 +                       VXH_LOC_ARGS(e),
20182 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20183 +                       VXH_VXI_ARGS(e), e->sc.data);
20184 +               break;
20185 +
20186 +       case VXH_ALLOC_VX_INFO:
20187 +       case VXH_DEALLOC_VX_INFO:
20188 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20189 +                       VXH_LOC_ARGS(e),
20190 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20191 +                       VXH_VXI_ARGS(e));
20192 +               break;
20193 +
20194 +       case VXH_HASH_VX_INFO:
20195 +       case VXH_UNHASH_VX_INFO:
20196 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20197 +                       VXH_LOC_ARGS(e),
20198 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20199 +                       VXH_VXI_ARGS(e));
20200 +               break;
20201 +
20202 +       case VXH_LOC_VX_INFO:
20203 +       case VXH_LOOKUP_VX_INFO:
20204 +       case VXH_CREATE_VX_INFO:
20205 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20206 +                       VXH_LOC_ARGS(e),
20207 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20208 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20209 +                       e->ll.arg, VXH_VXI_ARGS(e));
20210 +               break;
20211 +       }
20212 +}
20213 +
20214 +static void __vxh_dump_history(void)
20215 +{
20216 +       unsigned int i, cpu;
20217 +
20218 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20219 +               atomic_read(&sequence), NR_CPUS);
20220 +
20221 +       for (i = 0; i < VXH_SIZE; i++) {
20222 +               for_each_online_cpu(cpu) {
20223 +                       struct _vx_history *hist =
20224 +                               &per_cpu(vx_history_buffer, cpu);
20225 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20226 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20227 +
20228 +                       vxh_dump_entry(entry, cpu);
20229 +               }
20230 +       }
20231 +}
20232 +
20233 +void   vxh_dump_history(void)
20234 +{
20235 +       vxh_active = 0;
20236 +#ifdef CONFIG_SMP
20237 +       local_irq_enable();
20238 +       smp_send_stop();
20239 +       local_irq_disable();
20240 +#endif
20241 +       __vxh_dump_history();
20242 +}
20243 +
20244 +
20245 +/* vserver syscall commands below here */
20246 +
20247 +
20248 +int vc_dump_history(uint32_t id)
20249 +{
20250 +       vxh_active = 0;
20251 +       __vxh_dump_history();
20252 +       vxh_active = 1;
20253 +
20254 +       return 0;
20255 +}
20256 +
20257 +
20258 +int do_read_history(struct __user _vx_hist_entry *data,
20259 +       int cpu, uint32_t *index, uint32_t *count)
20260 +{
20261 +       int pos, ret = 0;
20262 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20263 +       int end = hist->counter;
20264 +       int start = end - VXH_SIZE + 2;
20265 +       int idx = *index;
20266 +
20267 +       /* special case: get current pos */
20268 +       if (!*count) {
20269 +               *index = end;
20270 +               return 0;
20271 +       }
20272 +
20273 +       /* have we lost some data? */
20274 +       if (idx < start)
20275 +               idx = start;
20276 +
20277 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20278 +               struct _vx_hist_entry *entry =
20279 +                       &hist->entry[idx % VXH_SIZE];
20280 +
20281 +               /* send entry to userspace */
20282 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20283 +               if (ret)
20284 +                       break;
20285 +       }
20286 +       /* save new index and count */
20287 +       *index = idx;
20288 +       *count = pos;
20289 +       return ret ? ret : (*index < end);
20290 +}
20291 +
20292 +int vc_read_history(uint32_t id, void __user *data)
20293 +{
20294 +       struct vcmd_read_history_v0 vc_data;
20295 +       int ret;
20296 +
20297 +       if (id >= NR_CPUS)
20298 +               return -EINVAL;
20299 +
20300 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20301 +               return -EFAULT;
20302 +
20303 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20304 +               id, &vc_data.index, &vc_data.count);
20305 +
20306 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20307 +               return -EFAULT;
20308 +       return ret;
20309 +}
20310 +
20311 +#ifdef CONFIG_COMPAT
20312 +
20313 +int vc_read_history_x32(uint32_t id, void __user *data)
20314 +{
20315 +       struct vcmd_read_history_v0_x32 vc_data;
20316 +       int ret;
20317 +
20318 +       if (id >= NR_CPUS)
20319 +               return -EINVAL;
20320 +
20321 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20322 +               return -EFAULT;
20323 +
20324 +       ret = do_read_history((struct __user _vx_hist_entry *)
20325 +               compat_ptr(vc_data.data_ptr),
20326 +               id, &vc_data.index, &vc_data.count);
20327 +
20328 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20329 +               return -EFAULT;
20330 +       return ret;
20331 +}
20332 +
20333 +#endif /* CONFIG_COMPAT */
20334 +
20335 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/inet.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/inet.c
20336 --- linux-2.6.27.14/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
20337 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/inet.c  2008-10-13 14:54:20.000000000 +0200
20338 @@ -0,0 +1,225 @@
20339 +
20340 +#include <linux/in.h>
20341 +#include <linux/inetdevice.h>
20342 +#include <linux/vs_inet.h>
20343 +#include <linux/vs_inet6.h>
20344 +#include <linux/vserver/debug.h>
20345 +#include <net/route.h>
20346 +#include <net/addrconf.h>
20347 +
20348 +
20349 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20350 +{
20351 +       int ret = 0;
20352 +
20353 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20354 +               ret = 1;
20355 +       else {
20356 +               struct nx_addr_v4 *ptr;
20357 +
20358 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20359 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20360 +                               ret = 1;
20361 +                               break;
20362 +                       }
20363 +               }
20364 +       }
20365 +
20366 +       vxdprintk(VXD_CBIT(net, 2),
20367 +               "nx_v4_addr_conflict(%p,%p): %d",
20368 +               nxi1, nxi2, ret);
20369 +
20370 +       return ret;
20371 +}
20372 +
20373 +
20374 +#ifdef CONFIG_IPV6
20375 +
20376 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20377 +{
20378 +       int ret = 0;
20379 +
20380 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20381 +               ret = 1;
20382 +       else {
20383 +               struct nx_addr_v6 *ptr;
20384 +
20385 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20386 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20387 +                               ret = 1;
20388 +                               break;
20389 +                       }
20390 +               }
20391 +       }
20392 +
20393 +       vxdprintk(VXD_CBIT(net, 2),
20394 +               "nx_v6_addr_conflict(%p,%p): %d",
20395 +               nxi1, nxi2, ret);
20396 +
20397 +       return ret;
20398 +}
20399 +
20400 +#endif
20401 +
20402 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20403 +{
20404 +       struct in_device *in_dev;
20405 +       struct in_ifaddr **ifap;
20406 +       struct in_ifaddr *ifa;
20407 +       int ret = 0;
20408 +
20409 +       if (!dev)
20410 +               goto out;
20411 +       in_dev = in_dev_get(dev);
20412 +       if (!in_dev)
20413 +               goto out;
20414 +
20415 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20416 +               ifap = &ifa->ifa_next) {
20417 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20418 +                       ret = 1;
20419 +                       break;
20420 +               }
20421 +       }
20422 +       in_dev_put(in_dev);
20423 +out:
20424 +       return ret;
20425 +}
20426 +
20427 +
20428 +#ifdef CONFIG_IPV6
20429 +
20430 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20431 +{
20432 +       struct inet6_dev *in_dev;
20433 +       struct inet6_ifaddr **ifap;
20434 +       struct inet6_ifaddr *ifa;
20435 +       int ret = 0;
20436 +
20437 +       if (!dev)
20438 +               goto out;
20439 +       in_dev = in6_dev_get(dev);
20440 +       if (!in_dev)
20441 +               goto out;
20442 +
20443 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20444 +               ifap = &ifa->if_next) {
20445 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20446 +                       ret = 1;
20447 +                       break;
20448 +               }
20449 +       }
20450 +       in6_dev_put(in_dev);
20451 +out:
20452 +       return ret;
20453 +}
20454 +
20455 +#endif
20456 +
20457 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20458 +{
20459 +       int ret = 1;
20460 +
20461 +       if (!nxi)
20462 +               goto out;
20463 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20464 +               goto out;
20465 +#ifdef CONFIG_IPV6
20466 +       ret = 2;
20467 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20468 +               goto out;
20469 +#endif
20470 +       ret = 0;
20471 +out:
20472 +       vxdprintk(VXD_CBIT(net, 3),
20473 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20474 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20475 +       return ret;
20476 +}
20477 +
20478 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20479 +       struct rtable **rp, struct flowi *fl)
20480 +{
20481 +       if (!nxi)
20482 +               return 0;
20483 +
20484 +       /* FIXME: handle lback only case */
20485 +       if (!NX_IPV4(nxi))
20486 +               return -EPERM;
20487 +
20488 +       vxdprintk(VXD_CBIT(net, 4),
20489 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20490 +               nxi, nxi ? nxi->nx_id : 0,
20491 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20492 +
20493 +       /* single IP is unconditional */
20494 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20495 +               (fl->fl4_src == INADDR_ANY))
20496 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20497 +
20498 +       if (fl->fl4_src == INADDR_ANY) {
20499 +               struct nx_addr_v4 *ptr;
20500 +               __be32 found = 0;
20501 +               int err;
20502 +
20503 +               err = __ip_route_output_key(net, rp, fl);
20504 +               if (!err) {
20505 +                       found = (*rp)->rt_src;
20506 +                       ip_rt_put(*rp);
20507 +                       vxdprintk(VXD_CBIT(net, 4),
20508 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20509 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20510 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20511 +                               goto found;
20512 +               }
20513 +
20514 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20515 +                       __be32 primary = ptr->ip[0].s_addr;
20516 +                       __be32 mask = ptr->mask.s_addr;
20517 +                       __be32 neta = primary & mask;
20518 +
20519 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20520 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20521 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20522 +                               NIPQUAD(mask), NIPQUAD(neta));
20523 +                       if ((found & mask) != neta)
20524 +                               continue;
20525 +
20526 +                       fl->fl4_src = primary;
20527 +                       err = __ip_route_output_key(net, rp, fl);
20528 +                       vxdprintk(VXD_CBIT(net, 4),
20529 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20530 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20531 +                       if (!err) {
20532 +                               found = (*rp)->rt_src;
20533 +                               ip_rt_put(*rp);
20534 +                               if (found == primary)
20535 +                                       goto found;
20536 +                       }
20537 +               }
20538 +               /* still no source ip? */
20539 +               found = ipv4_is_loopback(fl->fl4_dst)
20540 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20541 +       found:
20542 +               /* assign src ip to flow */
20543 +               fl->fl4_src = found;
20544 +
20545 +       } else {
20546 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20547 +                       return -EPERM;
20548 +       }
20549 +
20550 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20551 +               if (ipv4_is_loopback(fl->fl4_dst))
20552 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20553 +               if (ipv4_is_loopback(fl->fl4_src))
20554 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20555 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20556 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20557 +               return -EPERM;
20558 +
20559 +       return 0;
20560 +}
20561 +
20562 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20563 +
20564 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/init.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/init.c
20565 --- linux-2.6.27.14/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
20566 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/init.c  2008-10-13 14:54:20.000000000 +0200
20567 @@ -0,0 +1,45 @@
20568 +/*
20569 + *  linux/kernel/init.c
20570 + *
20571 + *  Virtual Server Init
20572 + *
20573 + *  Copyright (C) 2004-2007  Herbert Pötzl
20574 + *
20575 + *  V0.01  basic structure
20576 + *
20577 + */
20578 +
20579 +#include <linux/init.h>
20580 +
20581 +int    vserver_register_sysctl(void);
20582 +void   vserver_unregister_sysctl(void);
20583 +
20584 +
20585 +static int __init init_vserver(void)
20586 +{
20587 +       int ret = 0;
20588 +
20589 +#ifdef CONFIG_VSERVER_DEBUG
20590 +       vserver_register_sysctl();
20591 +#endif
20592 +       return ret;
20593 +}
20594 +
20595 +
20596 +static void __exit exit_vserver(void)
20597 +{
20598 +
20599 +#ifdef CONFIG_VSERVER_DEBUG
20600 +       vserver_unregister_sysctl();
20601 +#endif
20602 +       return;
20603 +}
20604 +
20605 +/* FIXME: GFP_ZONETYPES gone
20606 +long vx_slab[GFP_ZONETYPES]; */
20607 +long vx_area;
20608 +
20609 +
20610 +module_init(init_vserver);
20611 +module_exit(exit_vserver);
20612 +
20613 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/inode.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/inode.c
20614 --- linux-2.6.27.14/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
20615 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/inode.c 2008-10-24 03:34:52.000000000 +0200
20616 @@ -0,0 +1,422 @@
20617 +/*
20618 + *  linux/kernel/vserver/inode.c
20619 + *
20620 + *  Virtual Server: File System Support
20621 + *
20622 + *  Copyright (C) 2004-2007  Herbert Pötzl
20623 + *
20624 + *  V0.01  separated from vcontext V0.05
20625 + *  V0.02  moved to tag (instead of xid)
20626 + *
20627 + */
20628 +
20629 +#include <linux/tty.h>
20630 +#include <linux/proc_fs.h>
20631 +#include <linux/devpts_fs.h>
20632 +#include <linux/fs.h>
20633 +#include <linux/file.h>
20634 +#include <linux/mount.h>
20635 +#include <linux/parser.h>
20636 +#include <linux/namei.h>
20637 +#include <linux/vserver/inode.h>
20638 +#include <linux/vserver/inode_cmd.h>
20639 +#include <linux/vs_base.h>
20640 +#include <linux/vs_tag.h>
20641 +
20642 +#include <asm/uaccess.h>
20643 +
20644 +
20645 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20646 +{
20647 +       struct proc_dir_entry *entry;
20648 +
20649 +       if (!in || !in->i_sb)
20650 +               return -ESRCH;
20651 +
20652 +       *flags = IATTR_TAG
20653 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20654 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20655 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20656 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20657 +
20658 +       if (S_ISDIR(in->i_mode))
20659 +               *mask |= IATTR_BARRIER;
20660 +
20661 +       if (IS_TAGGED(in)) {
20662 +               *tag = in->i_tag;
20663 +               *mask |= IATTR_TAG;
20664 +       }
20665 +
20666 +       switch (in->i_sb->s_magic) {
20667 +       case PROC_SUPER_MAGIC:
20668 +               entry = PROC_I(in)->pde;
20669 +
20670 +               /* check for specific inodes? */
20671 +               if (entry)
20672 +                       *mask |= IATTR_FLAGS;
20673 +               if (entry)
20674 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20675 +               else
20676 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20677 +               break;
20678 +
20679 +       case DEVPTS_SUPER_MAGIC:
20680 +               *tag = in->i_tag;
20681 +               *mask |= IATTR_TAG;
20682 +               break;
20683 +
20684 +       default:
20685 +               break;
20686 +       }
20687 +       return 0;
20688 +}
20689 +
20690 +int vc_get_iattr(void __user *data)
20691 +{
20692 +       struct path path;
20693 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20694 +       int ret;
20695 +
20696 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20697 +               return -EFAULT;
20698 +
20699 +       ret = user_lpath(vc_data.name, &path);
20700 +       if (!ret) {
20701 +               ret = __vc_get_iattr(path.dentry->d_inode,
20702 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20703 +               path_put(&path);
20704 +       }
20705 +       if (ret)
20706 +               return ret;
20707 +
20708 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20709 +               ret = -EFAULT;
20710 +       return ret;
20711 +}
20712 +
20713 +#ifdef CONFIG_COMPAT
20714 +
20715 +int vc_get_iattr_x32(void __user *data)
20716 +{
20717 +       struct path path;
20718 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20719 +       int ret;
20720 +
20721 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20722 +               return -EFAULT;
20723 +
20724 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20725 +       if (!ret) {
20726 +               ret = __vc_get_iattr(path.dentry->d_inode,
20727 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20728 +               path_put(&path);
20729 +       }
20730 +       if (ret)
20731 +               return ret;
20732 +
20733 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20734 +               ret = -EFAULT;
20735 +       return ret;
20736 +}
20737 +
20738 +#endif /* CONFIG_COMPAT */
20739 +
20740 +
20741 +int vc_fget_iattr(uint32_t fd, void __user *data)
20742 +{
20743 +       struct file *filp;
20744 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20745 +       int ret;
20746 +
20747 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20748 +               return -EFAULT;
20749 +
20750 +       filp = fget(fd);
20751 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20752 +               return -EBADF;
20753 +
20754 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20755 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20756 +
20757 +       fput(filp);
20758 +
20759 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20760 +               ret = -EFAULT;
20761 +       return ret;
20762 +}
20763 +
20764 +
20765 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20766 +{
20767 +       struct inode *in = de->d_inode;
20768 +       int error = 0, is_proc = 0, has_tag = 0;
20769 +       struct iattr attr = { 0 };
20770 +
20771 +       if (!in || !in->i_sb)
20772 +               return -ESRCH;
20773 +
20774 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20775 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20776 +               return -EINVAL;
20777 +
20778 +       has_tag = IS_TAGGED(in) ||
20779 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20780 +       if ((*mask & IATTR_TAG) && !has_tag)
20781 +               return -EINVAL;
20782 +
20783 +       mutex_lock(&in->i_mutex);
20784 +       if (*mask & IATTR_TAG) {
20785 +               attr.ia_tag = *tag;
20786 +               attr.ia_valid |= ATTR_TAG;
20787 +       }
20788 +
20789 +       if (*mask & IATTR_FLAGS) {
20790 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20791 +               unsigned int iflags = PROC_I(in)->vx_flags;
20792 +
20793 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20794 +                       | (*flags & IATTR_FLAGS);
20795 +               PROC_I(in)->vx_flags = iflags;
20796 +               if (entry)
20797 +                       entry->vx_flags = iflags;
20798 +       }
20799 +
20800 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20801 +               if (*mask & IATTR_IMMUTABLE) {
20802 +                       if (*flags & IATTR_IMMUTABLE)
20803 +                               in->i_flags |= S_IMMUTABLE;
20804 +                       else
20805 +                               in->i_flags &= ~S_IMMUTABLE;
20806 +               }
20807 +               if (*mask & IATTR_IXUNLINK) {
20808 +                       if (*flags & IATTR_IXUNLINK)
20809 +                               in->i_flags |= S_IXUNLINK;
20810 +                       else
20811 +                               in->i_flags &= ~S_IXUNLINK;
20812 +               }
20813 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20814 +                       if (*flags & IATTR_BARRIER)
20815 +                               in->i_vflags |= V_BARRIER;
20816 +                       else
20817 +                               in->i_vflags &= ~V_BARRIER;
20818 +               }
20819 +               if (in->i_op && in->i_op->sync_flags) {
20820 +                       error = in->i_op->sync_flags(in);
20821 +                       if (error)
20822 +                               goto out;
20823 +               }
20824 +       }
20825 +
20826 +       if (attr.ia_valid) {
20827 +               if (in->i_op && in->i_op->setattr)
20828 +                       error = in->i_op->setattr(de, &attr);
20829 +               else {
20830 +                       error = inode_change_ok(in, &attr);
20831 +                       if (!error)
20832 +                               error = inode_setattr(in, &attr);
20833 +               }
20834 +       }
20835 +
20836 +out:
20837 +       mutex_unlock(&in->i_mutex);
20838 +       return error;
20839 +}
20840 +
20841 +int vc_set_iattr(void __user *data)
20842 +{
20843 +       struct path path;
20844 +       struct vcmd_ctx_iattr_v1 vc_data;
20845 +       int ret;
20846 +
20847 +       if (!capable(CAP_LINUX_IMMUTABLE))
20848 +               return -EPERM;
20849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20850 +               return -EFAULT;
20851 +
20852 +       ret = user_lpath(vc_data.name, &path);
20853 +       if (!ret) {
20854 +               ret = __vc_set_iattr(path.dentry,
20855 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20856 +               path_put(&path);
20857 +       }
20858 +
20859 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20860 +               ret = -EFAULT;
20861 +       return ret;
20862 +}
20863 +
20864 +#ifdef CONFIG_COMPAT
20865 +
20866 +int vc_set_iattr_x32(void __user *data)
20867 +{
20868 +       struct path path;
20869 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20870 +       int ret;
20871 +
20872 +       if (!capable(CAP_LINUX_IMMUTABLE))
20873 +               return -EPERM;
20874 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20875 +               return -EFAULT;
20876 +
20877 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20878 +       if (!ret) {
20879 +               ret = __vc_set_iattr(path.dentry,
20880 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20881 +               path_put(&path);
20882 +       }
20883 +
20884 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20885 +               ret = -EFAULT;
20886 +       return ret;
20887 +}
20888 +
20889 +#endif /* CONFIG_COMPAT */
20890 +
20891 +int vc_fset_iattr(uint32_t fd, void __user *data)
20892 +{
20893 +       struct file *filp;
20894 +       struct vcmd_ctx_fiattr_v0 vc_data;
20895 +       int ret;
20896 +
20897 +       if (!capable(CAP_LINUX_IMMUTABLE))
20898 +               return -EPERM;
20899 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20900 +               return -EFAULT;
20901 +
20902 +       filp = fget(fd);
20903 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20904 +               return -EBADF;
20905 +
20906 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20907 +               &vc_data.flags, &vc_data.mask);
20908 +
20909 +       fput(filp);
20910 +
20911 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20912 +               return -EFAULT;
20913 +       return ret;
20914 +}
20915 +
20916 +
20917 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20918 +
20919 +static match_table_t tokens = {
20920 +       {Opt_notagcheck, "notagcheck"},
20921 +#ifdef CONFIG_PROPAGATE
20922 +       {Opt_notag, "notag"},
20923 +       {Opt_tag, "tag"},
20924 +       {Opt_tagid, "tagid=%u"},
20925 +#endif
20926 +       {Opt_err, NULL}
20927 +};
20928 +
20929 +
20930 +static void __dx_parse_remove(char *string, char *opt)
20931 +{
20932 +       char *p = strstr(string, opt);
20933 +       char *q = p;
20934 +
20935 +       if (p) {
20936 +               while (*q != '\0' && *q != ',')
20937 +                       q++;
20938 +               while (*q)
20939 +                       *p++ = *q++;
20940 +               while (*p)
20941 +                       *p++ = '\0';
20942 +       }
20943 +}
20944 +
20945 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20946 +                unsigned long *flags)
20947 +{
20948 +       int set = 0;
20949 +       substring_t args[MAX_OPT_ARGS];
20950 +       int token, option = 0;
20951 +       char *s, *p, *opts;
20952 +
20953 +       if (!string)
20954 +               return 0;
20955 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20956 +       if (!s)
20957 +               return 0;
20958 +
20959 +       opts = s;
20960 +       while ((p = strsep(&opts, ",")) != NULL) {
20961 +               token = match_token(p, tokens, args);
20962 +
20963 +               vxdprintk(VXD_CBIT(tag, 7),
20964 +                       "dx_parse_tag(»%s«): %d:#%d",
20965 +                       p, token, option);
20966 +
20967 +               switch (token) {
20968 +#ifdef CONFIG_PROPAGATE
20969 +               case Opt_tag:
20970 +                       if (tag)
20971 +                               *tag = 0;
20972 +                       if (remove)
20973 +                               __dx_parse_remove(s, "tag");
20974 +                       *mnt_flags |= MNT_TAGID;
20975 +                       set |= MNT_TAGID;
20976 +                       break;
20977 +               case Opt_notag:
20978 +                       if (remove)
20979 +                               __dx_parse_remove(s, "notag");
20980 +                       *mnt_flags |= MNT_NOTAG;
20981 +                       set |= MNT_NOTAG;
20982 +                       break;
20983 +               case Opt_tagid:
20984 +                       if (tag && !match_int(args, &option))
20985 +                               *tag = option;
20986 +                       if (remove)
20987 +                               __dx_parse_remove(s, "tagid");
20988 +                       *mnt_flags |= MNT_TAGID;
20989 +                       set |= MNT_TAGID;
20990 +                       break;
20991 +#endif
20992 +               case Opt_notagcheck:
20993 +                       if (remove)
20994 +                               __dx_parse_remove(s, "notagcheck");
20995 +                       *flags |= MS_NOTAGCHECK;
20996 +                       set |= MS_NOTAGCHECK;
20997 +                       break;
20998 +               }
20999 +       }
21000 +       if (set)
21001 +               strcpy(string, s);
21002 +       kfree(s);
21003 +       return set;
21004 +}
21005 +
21006 +#ifdef CONFIG_PROPAGATE
21007 +
21008 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21009 +{
21010 +       tag_t new_tag = 0;
21011 +       struct vfsmount *mnt;
21012 +       int propagate;
21013 +
21014 +       if (!nd)
21015 +               return;
21016 +       mnt = nd->path.mnt;
21017 +       if (!mnt)
21018 +               return;
21019 +
21020 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21021 +       if (propagate)
21022 +               new_tag = mnt->mnt_tag;
21023 +
21024 +       vxdprintk(VXD_CBIT(tag, 7),
21025 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21026 +               inode, inode->i_ino, inode->i_tag,
21027 +               new_tag, (propagate) ? 1 : 0);
21028 +
21029 +       if (propagate)
21030 +               inode->i_tag = new_tag;
21031 +}
21032 +
21033 +#include <linux/module.h>
21034 +
21035 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21036 +
21037 +#endif /* CONFIG_PROPAGATE */
21038 +
21039 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/Kconfig linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/Kconfig
21040 --- linux-2.6.27.14/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
21041 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/Kconfig 2008-10-13 14:54:20.000000000 +0200
21042 @@ -0,0 +1,251 @@
21043 +#
21044 +# Linux VServer configuration
21045 +#
21046 +
21047 +menu "Linux VServer"
21048 +
21049 +config VSERVER_AUTO_LBACK
21050 +       bool    "Automatically Assign Loopback IP"
21051 +       default y
21052 +       help
21053 +         Automatically assign a guest specific loopback
21054 +         IP and add it to the kernel network stack on
21055 +         startup.
21056 +
21057 +config VSERVER_AUTO_SINGLE
21058 +       bool    "Automatic Single IP Special Casing"
21059 +       depends on EXPERIMENTAL
21060 +       default y
21061 +       help
21062 +         This allows network contexts with a single IP to
21063 +         automatically remap 0.0.0.0 bindings to that IP,
21064 +         avoiding further network checks and improving
21065 +         performance.
21066 +
21067 +         (note: such guests do not allow to change the ip
21068 +          on the fly and do not show loopback addresses)
21069 +
21070 +config VSERVER_COWBL
21071 +       bool    "Enable COW Immutable Link Breaking"
21072 +       default y
21073 +       help
21074 +         This enables the COW (Copy-On-Write) link break code.
21075 +         It allows you to treat unified files like normal files
21076 +         when writing to them (which will implicitely break the
21077 +         link and create a copy of the unified file)
21078 +
21079 +config VSERVER_VTIME
21080 +       bool    "Enable Virtualized Guest Time"
21081 +       depends on EXPERIMENTAL
21082 +       default n
21083 +       help
21084 +         This enables per guest time offsets to allow for
21085 +         adjusting the system clock individually per guest.
21086 +         this adds some overhead to the time functions and
21087 +         therefore should not be enabled without good reason.
21088 +
21089 +config VSERVER_DEVICE
21090 +       bool    "Enable Guest Device Mapping"
21091 +       depends on EXPERIMENTAL
21092 +       default n
21093 +       help
21094 +         This enables generic device remapping.
21095 +
21096 +config VSERVER_PROC_SECURE
21097 +       bool    "Enable Proc Security"
21098 +       depends on PROC_FS
21099 +       default y
21100 +       help
21101 +         This configures ProcFS security to initially hide
21102 +         non-process entries for all contexts except the main and
21103 +         spectator context (i.e. for all guests), which is a secure
21104 +         default.
21105 +
21106 +         (note: on 1.2x the entries were visible by default)
21107 +
21108 +config VSERVER_HARDCPU
21109 +       bool    "Enable Hard CPU Limits"
21110 +       default y
21111 +       help
21112 +         Activate the Hard CPU Limits
21113 +
21114 +         This will compile in code that allows the Token Bucket
21115 +         Scheduler to put processes on hold when a context's
21116 +         tokens are depleted (provided that its per-context
21117 +         sched_hard flag is set).
21118 +
21119 +         Processes belonging to that context will not be able
21120 +         to consume CPU resources again until a per-context
21121 +         configured minimum of tokens has been reached.
21122 +
21123 +config VSERVER_IDLETIME
21124 +       bool    "Avoid idle CPUs by skipping Time"
21125 +       depends on VSERVER_HARDCPU
21126 +       default y
21127 +       help
21128 +         This option allows the scheduler to artificially
21129 +         advance time (per cpu) when otherwise the idle
21130 +         task would be scheduled, thus keeping the cpu
21131 +         busy and sharing the available resources among
21132 +         certain contexts.
21133 +
21134 +config VSERVER_IDLELIMIT
21135 +       bool    "Limit the IDLE task"
21136 +       depends on VSERVER_HARDCPU
21137 +       default n
21138 +       help
21139 +         Limit the idle slices, so the the next context
21140 +         will be scheduled as soon as possible.
21141 +
21142 +         This might improve interactivity and latency, but
21143 +         will also marginally increase scheduling overhead.
21144 +
21145 +choice
21146 +       prompt  "Persistent Inode Tagging"
21147 +       default TAGGING_ID24
21148 +       help
21149 +         This adds persistent context information to filesystems
21150 +         mounted with the tagxid option. Tagging is a requirement
21151 +         for per-context disk limits and per-context quota.
21152 +
21153 +
21154 +config TAGGING_NONE
21155 +       bool    "Disabled"
21156 +       help
21157 +         do not store per-context information in inodes.
21158 +
21159 +config TAGGING_UID16
21160 +       bool    "UID16/GID32"
21161 +       help
21162 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21163 +
21164 +config TAGGING_GID16
21165 +       bool    "UID32/GID16"
21166 +       help
21167 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21168 +
21169 +config TAGGING_ID24
21170 +       bool    "UID24/GID24"
21171 +       help
21172 +         uses the upper 8bit from UID and GID for XID tagging
21173 +         which leaves 24bit for UID/GID each, which should be
21174 +         more than sufficient for normal use.
21175 +
21176 +config TAGGING_INTERN
21177 +       bool    "UID32/GID32"
21178 +       help
21179 +         this uses otherwise reserved inode fields in the on
21180 +         disk representation, which limits the use to a few
21181 +         filesystems (currently ext2 and ext3)
21182 +
21183 +endchoice
21184 +
21185 +config TAG_NFSD
21186 +       bool    "Tag NFSD User Auth and Files"
21187 +       default n
21188 +       help
21189 +         Enable this if you do want the in-kernel NFS
21190 +         Server to use the tagging specified above.
21191 +         (will require patched clients too)
21192 +
21193 +config VSERVER_PRIVACY
21194 +       bool    "Honor Privacy Aspects of Guests"
21195 +       default n
21196 +       help
21197 +         When enabled, most context checks will disallow
21198 +         access to structures assigned to a specific context,
21199 +         like ptys or loop devices.
21200 +
21201 +config VSERVER_CONTEXTS
21202 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21203 +       range 1 65533
21204 +       default "768"   if 64BIT
21205 +       default "256"
21206 +       help
21207 +         This setting will optimize certain data structures
21208 +         and memory allocations according to the expected
21209 +         maximum.
21210 +
21211 +         note: this is not a strict upper limit.
21212 +
21213 +config VSERVER_WARN
21214 +       bool    "VServer Warnings"
21215 +       default y
21216 +       help
21217 +         This enables various runtime warnings, which will
21218 +         notify about potential manipulation attempts or
21219 +         resource shortage. It is generally considered to
21220 +         be a good idea to have that enabled.
21221 +
21222 +config VSERVER_DEBUG
21223 +       bool    "VServer Debugging Code"
21224 +       default n
21225 +       help
21226 +         Set this to yes if you want to be able to activate
21227 +         debugging output at runtime. It adds a very small
21228 +         overhead to all vserver related functions and
21229 +         increases the kernel size by about 20k.
21230 +
21231 +config VSERVER_HISTORY
21232 +       bool    "VServer History Tracing"
21233 +       depends on VSERVER_DEBUG
21234 +       default n
21235 +       help
21236 +         Set this to yes if you want to record the history of
21237 +         linux-vserver activities, so they can be replayed in
21238 +         the event of a kernel panic or oops.
21239 +
21240 +config VSERVER_HISTORY_SIZE
21241 +       int     "Per-CPU History Size (32-65536)"
21242 +       depends on VSERVER_HISTORY
21243 +       range 32 65536
21244 +       default 64
21245 +       help
21246 +         This allows you to specify the number of entries in
21247 +         the per-CPU history buffer.
21248 +
21249 +config VSERVER_MONITOR
21250 +       bool    "VServer Scheduling Monitor"
21251 +       depends on VSERVER_DISABLED
21252 +       default n
21253 +       help
21254 +         Set this to yes if you want to record the scheduling
21255 +         decisions, so that they can be relayed to userspace
21256 +         for detailed analysis.
21257 +
21258 +config VSERVER_MONITOR_SIZE
21259 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21260 +       depends on VSERVER_MONITOR
21261 +       range 32 65536
21262 +       default 1024
21263 +       help
21264 +         This allows you to specify the number of entries in
21265 +         the per-CPU scheduling monitor buffer.
21266 +
21267 +config VSERVER_MONITOR_SYNC
21268 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21269 +       depends on VSERVER_MONITOR
21270 +       range 0 65536
21271 +       default 256
21272 +       help
21273 +         This allows you to specify the interval in ticks
21274 +         when a time sync entry is inserted.
21275 +
21276 +endmenu
21277 +
21278 +
21279 +config VSERVER
21280 +       bool
21281 +       default y
21282 +       select NAMESPACES
21283 +       select UTS_NS
21284 +       select IPC_NS
21285 +       select USER_NS
21286 +       select SYSVIPC
21287 +
21288 +config VSERVER_SECURITY
21289 +       bool
21290 +       depends on SECURITY
21291 +       default y
21292 +       select SECURITY_CAPABILITIES
21293 +
21294 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/limit.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/limit.c
21295 --- linux-2.6.27.14/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
21296 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/limit.c 2008-10-13 14:54:20.000000000 +0200
21297 @@ -0,0 +1,319 @@
21298 +/*
21299 + *  linux/kernel/vserver/limit.c
21300 + *
21301 + *  Virtual Server: Context Limits
21302 + *
21303 + *  Copyright (C) 2004-2007  Herbert Pötzl
21304 + *
21305 + *  V0.01  broken out from vcontext V0.05
21306 + *  V0.02  changed vcmds to vxi arg
21307 + *
21308 + */
21309 +
21310 +#include <linux/sched.h>
21311 +#include <linux/module.h>
21312 +#include <linux/vs_limit.h>
21313 +#include <linux/vserver/limit.h>
21314 +#include <linux/vserver/limit_cmd.h>
21315 +
21316 +#include <asm/uaccess.h>
21317 +
21318 +
21319 +const char *vlimit_name[NUM_LIMITS] = {
21320 +       [RLIMIT_CPU]            = "CPU",
21321 +       [RLIMIT_RSS]            = "RSS",
21322 +       [RLIMIT_NPROC]          = "NPROC",
21323 +       [RLIMIT_NOFILE]         = "NOFILE",
21324 +       [RLIMIT_MEMLOCK]        = "VML",
21325 +       [RLIMIT_AS]             = "VM",
21326 +       [RLIMIT_LOCKS]          = "LOCKS",
21327 +       [RLIMIT_SIGPENDING]     = "SIGP",
21328 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21329 +
21330 +       [VLIMIT_NSOCK]          = "NSOCK",
21331 +       [VLIMIT_OPENFD]         = "OPENFD",
21332 +       [VLIMIT_ANON]           = "ANON",
21333 +       [VLIMIT_SHMEM]          = "SHMEM",
21334 +       [VLIMIT_DENTRY]         = "DENTRY",
21335 +};
21336 +
21337 +EXPORT_SYMBOL_GPL(vlimit_name);
21338 +
21339 +#define MASK_ENTRY(x)  (1 << (x))
21340 +
21341 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21342 +               /* minimum */
21343 +       0
21344 +       ,       /* softlimit */
21345 +       MASK_ENTRY( RLIMIT_RSS          ) |
21346 +       MASK_ENTRY( VLIMIT_ANON         ) |
21347 +       0
21348 +       ,       /* maximum */
21349 +       MASK_ENTRY( RLIMIT_RSS          ) |
21350 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21351 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21352 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21353 +       MASK_ENTRY( RLIMIT_AS           ) |
21354 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21355 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21356 +
21357 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21358 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21359 +       MASK_ENTRY( VLIMIT_ANON         ) |
21360 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21361 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21362 +       0
21363 +};
21364 +               /* accounting only */
21365 +uint32_t account_mask =
21366 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21367 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21368 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21369 +       0;
21370 +
21371 +
21372 +static int is_valid_vlimit(int id)
21373 +{
21374 +       uint32_t mask = vlimit_mask.minimum |
21375 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21376 +       return mask & (1 << id);
21377 +}
21378 +
21379 +static int is_accounted_vlimit(int id)
21380 +{
21381 +       if (is_valid_vlimit(id))
21382 +               return 1;
21383 +       return account_mask & (1 << id);
21384 +}
21385 +
21386 +
21387 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21388 +{
21389 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21390 +       return VX_VLIM(limit);
21391 +}
21392 +
21393 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21394 +{
21395 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21396 +       return VX_VLIM(limit);
21397 +}
21398 +
21399 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21400 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21401 +{
21402 +       if (!is_valid_vlimit(id))
21403 +               return -EINVAL;
21404 +
21405 +       if (minimum)
21406 +               *minimum = CRLIM_UNSET;
21407 +       if (softlimit)
21408 +               *softlimit = vc_get_soft(vxi, id);
21409 +       if (maximum)
21410 +               *maximum = vc_get_hard(vxi, id);
21411 +       return 0;
21412 +}
21413 +
21414 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21415 +{
21416 +       struct vcmd_ctx_rlimit_v0 vc_data;
21417 +       int ret;
21418 +
21419 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21420 +               return -EFAULT;
21421 +
21422 +       ret = do_get_rlimit(vxi, vc_data.id,
21423 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21424 +       if (ret)
21425 +               return ret;
21426 +
21427 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21428 +               return -EFAULT;
21429 +       return 0;
21430 +}
21431 +
21432 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21433 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21434 +{
21435 +       if (!is_valid_vlimit(id))
21436 +               return -EINVAL;
21437 +
21438 +       if (maximum != CRLIM_KEEP)
21439 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21440 +       if (softlimit != CRLIM_KEEP)
21441 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21442 +
21443 +       /* clamp soft limit */
21444 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21445 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21446 +
21447 +       return 0;
21448 +}
21449 +
21450 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21451 +{
21452 +       struct vcmd_ctx_rlimit_v0 vc_data;
21453 +
21454 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21455 +               return -EFAULT;
21456 +
21457 +       return do_set_rlimit(vxi, vc_data.id,
21458 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21459 +}
21460 +
21461 +#ifdef CONFIG_IA32_EMULATION
21462 +
21463 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21464 +{
21465 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21466 +
21467 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21468 +               return -EFAULT;
21469 +
21470 +       return do_set_rlimit(vxi, vc_data.id,
21471 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21472 +}
21473 +
21474 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21475 +{
21476 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21477 +       int ret;
21478 +
21479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21480 +               return -EFAULT;
21481 +
21482 +       ret = do_get_rlimit(vxi, vc_data.id,
21483 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21484 +       if (ret)
21485 +               return ret;
21486 +
21487 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21488 +               return -EFAULT;
21489 +       return 0;
21490 +}
21491 +
21492 +#endif /* CONFIG_IA32_EMULATION */
21493 +
21494 +
21495 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21496 +{
21497 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21498 +               return -EFAULT;
21499 +       return 0;
21500 +}
21501 +
21502 +
21503 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21504 +{
21505 +       rlim_t value;
21506 +       int lim;
21507 +
21508 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21509 +               value = __rlim_get(limit, lim);
21510 +               __rlim_rmax(limit, lim) = value;
21511 +               __rlim_rmin(limit, lim) = value;
21512 +       }
21513 +}
21514 +
21515 +
21516 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21517 +{
21518 +       vx_reset_minmax(&vxi->limit);
21519 +       return 0;
21520 +}
21521 +
21522 +
21523 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21524 +{
21525 +       struct vcmd_rlimit_stat_v0 vc_data;
21526 +       struct _vx_limit *limit = &vxi->limit;
21527 +       int id;
21528 +
21529 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21530 +               return -EFAULT;
21531 +
21532 +       id = vc_data.id;
21533 +       if (!is_accounted_vlimit(id))
21534 +               return -EINVAL;
21535 +
21536 +       vx_limit_fixup(limit, id);
21537 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21538 +       vc_data.value = __rlim_get(limit, id);
21539 +       vc_data.minimum = __rlim_rmin(limit, id);
21540 +       vc_data.maximum = __rlim_rmax(limit, id);
21541 +
21542 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21543 +               return -EFAULT;
21544 +       return 0;
21545 +}
21546 +
21547 +
21548 +void vx_vsi_meminfo(struct sysinfo *val)
21549 +{
21550 +       struct vx_info *vxi = current->vx_info;
21551 +       unsigned long totalram, freeram;
21552 +       rlim_t v;
21553 +
21554 +       /* we blindly accept the max */
21555 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21556 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21557 +
21558 +       /* total minus used equals free */
21559 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21560 +       freeram = (v < totalram) ? totalram - v : 0;
21561 +
21562 +       val->totalram = totalram;
21563 +       val->freeram = freeram;
21564 +       val->bufferram = 0;
21565 +       val->totalhigh = 0;
21566 +       val->freehigh = 0;
21567 +       return;
21568 +}
21569 +
21570 +void vx_vsi_swapinfo(struct sysinfo *val)
21571 +{
21572 +       struct vx_info *vxi = current->vx_info;
21573 +       unsigned long totalswap, freeswap;
21574 +       rlim_t v, w;
21575 +
21576 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21577 +       if (v == RLIM_INFINITY) {
21578 +               val->freeswap = val->totalswap;
21579 +               return;
21580 +       }
21581 +
21582 +       /* we blindly accept the max */
21583 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21584 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21585 +
21586 +       /* currently 'used' swap */
21587 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21588 +       w -= (w > v) ? v : w;
21589 +
21590 +       /* total minus used equals free */
21591 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21592 +
21593 +       val->totalswap = totalswap;
21594 +       val->freeswap = freeswap;
21595 +       return;
21596 +}
21597 +
21598 +
21599 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21600 +{
21601 +       struct vx_info *vxi = mm->mm_vx_info;
21602 +       unsigned long points;
21603 +       rlim_t v, w;
21604 +
21605 +       if (!vxi)
21606 +               return 0;
21607 +
21608 +       points = vxi->vx_badness_bias;
21609 +
21610 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21611 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21612 +       points += (v > w) ? (v - w) : 0;
21613 +
21614 +       return points;
21615 +}
21616 +
21617 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/limit_init.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/limit_init.h
21618 --- linux-2.6.27.14/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
21619 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/limit_init.h    2008-10-13 14:54:20.000000000 +0200
21620 @@ -0,0 +1,31 @@
21621 +
21622 +
21623 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21624 +{
21625 +       int lim;
21626 +
21627 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21628 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21629 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21630 +               __rlim_set(limit, lim, 0);
21631 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21632 +               __rlim_rmin(limit, lim) = 0;
21633 +               __rlim_rmax(limit, lim) = 0;
21634 +       }
21635 +}
21636 +
21637 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21638 +{
21639 +       rlim_t value;
21640 +       int lim;
21641 +
21642 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21643 +               if ((1 << lim) & VLIM_NOCHECK)
21644 +                       continue;
21645 +               value = __rlim_get(limit, lim);
21646 +               vxwprintk_xid(value,
21647 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21648 +                       limit, vlimit_name[lim], lim, (long)value);
21649 +       }
21650 +}
21651 +
21652 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/limit_proc.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/limit_proc.h
21653 --- linux-2.6.27.14/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
21654 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/limit_proc.h    2008-10-13 14:54:20.000000000 +0200
21655 @@ -0,0 +1,57 @@
21656 +#ifndef _VX_LIMIT_PROC_H
21657 +#define _VX_LIMIT_PROC_H
21658 +
21659 +#include <linux/vserver/limit_int.h>
21660 +
21661 +
21662 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21663 +#define VX_LIMIT_TOP   \
21664 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21665 +
21666 +#define VX_LIMIT_ARG(r)                                \
21667 +       (unsigned long)__rlim_get(limit, r),    \
21668 +       (unsigned long)__rlim_rmin(limit, r),   \
21669 +       (unsigned long)__rlim_rmax(limit, r),   \
21670 +       VX_VLIM(__rlim_soft(limit, r)),         \
21671 +       VX_VLIM(__rlim_hard(limit, r)),         \
21672 +       atomic_read(&__rlim_lhit(limit, r))
21673 +
21674 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21675 +{
21676 +       vx_limit_fixup(limit, -1);
21677 +       return sprintf(buffer, VX_LIMIT_TOP
21678 +               "PROC"  VX_LIMIT_FMT
21679 +               "VM"    VX_LIMIT_FMT
21680 +               "VML"   VX_LIMIT_FMT
21681 +               "RSS"   VX_LIMIT_FMT
21682 +               "ANON"  VX_LIMIT_FMT
21683 +               "RMAP"  VX_LIMIT_FMT
21684 +               "FILES" VX_LIMIT_FMT
21685 +               "OFD"   VX_LIMIT_FMT
21686 +               "LOCKS" VX_LIMIT_FMT
21687 +               "SOCK"  VX_LIMIT_FMT
21688 +               "MSGQ"  VX_LIMIT_FMT
21689 +               "SHM"   VX_LIMIT_FMT
21690 +               "SEMA"  VX_LIMIT_FMT
21691 +               "SEMS"  VX_LIMIT_FMT
21692 +               "DENT"  VX_LIMIT_FMT,
21693 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21694 +               VX_LIMIT_ARG(RLIMIT_AS),
21695 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21696 +               VX_LIMIT_ARG(RLIMIT_RSS),
21697 +               VX_LIMIT_ARG(VLIMIT_ANON),
21698 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21699 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21700 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21701 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21702 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21703 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21704 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21705 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21706 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21707 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21708 +}
21709 +
21710 +#endif /* _VX_LIMIT_PROC_H */
21711 +
21712 +
21713 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/Makefile linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/Makefile
21714 --- linux-2.6.27.14/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
21715 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/Makefile        2008-10-13 14:54:20.000000000 +0200
21716 @@ -0,0 +1,18 @@
21717 +#
21718 +# Makefile for the Linux vserver routines.
21719 +#
21720 +
21721 +
21722 +obj-y          += vserver.o
21723 +
21724 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21725 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21726 +                  dlimit.o tag.o
21727 +
21728 +vserver-$(CONFIG_INET) += inet.o
21729 +vserver-$(CONFIG_PROC_FS) += proc.o
21730 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21731 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21732 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21733 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21734 +
21735 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/monitor.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/monitor.c
21736 --- linux-2.6.27.14/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
21737 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/monitor.c       2008-10-13 14:54:20.000000000 +0200
21738 @@ -0,0 +1,138 @@
21739 +/*
21740 + *  kernel/vserver/monitor.c
21741 + *
21742 + *  Virtual Context Scheduler Monitor
21743 + *
21744 + *  Copyright (C) 2006-2007 Herbert Pötzl
21745 + *
21746 + *  V0.01  basic design
21747 + *
21748 + */
21749 +
21750 +#include <linux/module.h>
21751 +#include <linux/jiffies.h>
21752 +#include <asm/uaccess.h>
21753 +#include <asm/atomic.h>
21754 +
21755 +#include <linux/vserver/monitor.h>
21756 +#include <linux/vserver/debug_cmd.h>
21757 +
21758 +
21759 +#ifdef CONFIG_VSERVER_MONITOR
21760 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21761 +#else
21762 +#define VXM_SIZE       64
21763 +#endif
21764 +
21765 +struct _vx_monitor {
21766 +       unsigned int counter;
21767 +
21768 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21769 +};
21770 +
21771 +
21772 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21773 +
21774 +unsigned volatile int vxm_active = 1;
21775 +
21776 +static atomic_t sequence = ATOMIC_INIT(0);
21777 +
21778 +
21779 +/*     vxm_advance()
21780 +
21781 +       * requires disabled preemption                          */
21782 +
21783 +struct _vx_mon_entry *vxm_advance(int cpu)
21784 +{
21785 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21786 +       struct _vx_mon_entry *entry;
21787 +       unsigned int index;
21788 +
21789 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21790 +       entry = &mon->entry[index];
21791 +
21792 +       entry->ev.seq = atomic_inc_return(&sequence);
21793 +       entry->ev.jif = jiffies;
21794 +       return entry;
21795 +}
21796 +
21797 +EXPORT_SYMBOL_GPL(vxm_advance);
21798 +
21799 +
21800 +int do_read_monitor(struct __user _vx_mon_entry *data,
21801 +       int cpu, uint32_t *index, uint32_t *count)
21802 +{
21803 +       int pos, ret = 0;
21804 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21805 +       int end = mon->counter;
21806 +       int start = end - VXM_SIZE + 2;
21807 +       int idx = *index;
21808 +
21809 +       /* special case: get current pos */
21810 +       if (!*count) {
21811 +               *index = end;
21812 +               return 0;
21813 +       }
21814 +
21815 +       /* have we lost some data? */
21816 +       if (idx < start)
21817 +               idx = start;
21818 +
21819 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21820 +               struct _vx_mon_entry *entry =
21821 +                       &mon->entry[idx % VXM_SIZE];
21822 +
21823 +               /* send entry to userspace */
21824 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21825 +               if (ret)
21826 +                       break;
21827 +       }
21828 +       /* save new index and count */
21829 +       *index = idx;
21830 +       *count = pos;
21831 +       return ret ? ret : (*index < end);
21832 +}
21833 +
21834 +int vc_read_monitor(uint32_t id, void __user *data)
21835 +{
21836 +       struct vcmd_read_monitor_v0 vc_data;
21837 +       int ret;
21838 +
21839 +       if (id >= NR_CPUS)
21840 +               return -EINVAL;
21841 +
21842 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21843 +               return -EFAULT;
21844 +
21845 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21846 +               id, &vc_data.index, &vc_data.count);
21847 +
21848 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21849 +               return -EFAULT;
21850 +       return ret;
21851 +}
21852 +
21853 +#ifdef CONFIG_COMPAT
21854 +
21855 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21856 +{
21857 +       struct vcmd_read_monitor_v0_x32 vc_data;
21858 +       int ret;
21859 +
21860 +       if (id >= NR_CPUS)
21861 +               return -EINVAL;
21862 +
21863 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21864 +               return -EFAULT;
21865 +
21866 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21867 +               compat_ptr(vc_data.data_ptr),
21868 +               id, &vc_data.index, &vc_data.count);
21869 +
21870 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21871 +               return -EFAULT;
21872 +       return ret;
21873 +}
21874 +
21875 +#endif /* CONFIG_COMPAT */
21876 +
21877 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/network.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/network.c
21878 --- linux-2.6.27.14/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
21879 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/network.c       2008-10-13 14:54:20.000000000 +0200
21880 @@ -0,0 +1,864 @@
21881 +/*
21882 + *  linux/kernel/vserver/network.c
21883 + *
21884 + *  Virtual Server: Network Support
21885 + *
21886 + *  Copyright (C) 2003-2007  Herbert Pötzl
21887 + *
21888 + *  V0.01  broken out from vcontext V0.05
21889 + *  V0.02  cleaned up implementation
21890 + *  V0.03  added equiv nx commands
21891 + *  V0.04  switch to RCU based hash
21892 + *  V0.05  and back to locking again
21893 + *  V0.06  changed vcmds to nxi arg
21894 + *  V0.07  have __create claim() the nxi
21895 + *
21896 + */
21897 +
21898 +#include <linux/err.h>
21899 +#include <linux/slab.h>
21900 +#include <linux/rcupdate.h>
21901 +
21902 +#include <linux/vs_network.h>
21903 +#include <linux/vs_pid.h>
21904 +#include <linux/vserver/network_cmd.h>
21905 +
21906 +
21907 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21908 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21909 +
21910 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21911 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21912 +
21913 +
21914 +static int __init init_network(void)
21915 +{
21916 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21917 +               sizeof(struct nx_addr_v4), 0,
21918 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21919 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21920 +               sizeof(struct nx_addr_v6), 0,
21921 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21922 +       return 0;
21923 +}
21924 +
21925 +
21926 +/*     __alloc_nx_addr_v4()                                    */
21927 +
21928 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21929 +{
21930 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21931 +               nx_addr_v4_cachep, GFP_KERNEL);
21932 +
21933 +       if (!IS_ERR(nxa))
21934 +               memset(nxa, 0, sizeof(*nxa));
21935 +       return nxa;
21936 +}
21937 +
21938 +/*     __dealloc_nx_addr_v4()                                  */
21939 +
21940 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21941 +{
21942 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21943 +}
21944 +
21945 +/*     __dealloc_nx_addr_v4_all()                              */
21946 +
21947 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21948 +{
21949 +       while (nxa) {
21950 +               struct nx_addr_v4 *next = nxa->next;
21951 +
21952 +               __dealloc_nx_addr_v4(nxa);
21953 +               nxa = next;
21954 +       }
21955 +}
21956 +
21957 +
21958 +#ifdef CONFIG_IPV6
21959 +
21960 +/*     __alloc_nx_addr_v6()                                    */
21961 +
21962 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21963 +{
21964 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21965 +               nx_addr_v6_cachep, GFP_KERNEL);
21966 +
21967 +       if (!IS_ERR(nxa))
21968 +               memset(nxa, 0, sizeof(*nxa));
21969 +       return nxa;
21970 +}
21971 +
21972 +/*     __dealloc_nx_addr_v6()                                  */
21973 +
21974 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21975 +{
21976 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21977 +}
21978 +
21979 +/*     __dealloc_nx_addr_v6_all()                              */
21980 +
21981 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21982 +{
21983 +       while (nxa) {
21984 +               struct nx_addr_v6 *next = nxa->next;
21985 +
21986 +               __dealloc_nx_addr_v6(nxa);
21987 +               nxa = next;
21988 +       }
21989 +}
21990 +
21991 +#endif /* CONFIG_IPV6 */
21992 +
21993 +/*     __alloc_nx_info()
21994 +
21995 +       * allocate an initialized nx_info struct
21996 +       * doesn't make it visible (hash)                        */
21997 +
21998 +static struct nx_info *__alloc_nx_info(nid_t nid)
21999 +{
22000 +       struct nx_info *new = NULL;
22001 +
22002 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22003 +
22004 +       /* would this benefit from a slab cache? */
22005 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22006 +       if (!new)
22007 +               return 0;
22008 +
22009 +       memset(new, 0, sizeof(struct nx_info));
22010 +       new->nx_id = nid;
22011 +       INIT_HLIST_NODE(&new->nx_hlist);
22012 +       atomic_set(&new->nx_usecnt, 0);
22013 +       atomic_set(&new->nx_tasks, 0);
22014 +       new->nx_state = 0;
22015 +
22016 +       new->nx_flags = NXF_INIT_SET;
22017 +
22018 +       /* rest of init goes here */
22019 +
22020 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22021 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22022 +
22023 +       vxdprintk(VXD_CBIT(nid, 0),
22024 +               "alloc_nx_info(%d) = %p", nid, new);
22025 +       atomic_inc(&nx_global_ctotal);
22026 +       return new;
22027 +}
22028 +
22029 +/*     __dealloc_nx_info()
22030 +
22031 +       * final disposal of nx_info                             */
22032 +
22033 +static void __dealloc_nx_info(struct nx_info *nxi)
22034 +{
22035 +       vxdprintk(VXD_CBIT(nid, 0),
22036 +               "dealloc_nx_info(%p)", nxi);
22037 +
22038 +       nxi->nx_hlist.next = LIST_POISON1;
22039 +       nxi->nx_id = -1;
22040 +
22041 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22042 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22043 +
22044 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22045 +
22046 +       nxi->nx_state |= NXS_RELEASED;
22047 +       kfree(nxi);
22048 +       atomic_dec(&nx_global_ctotal);
22049 +}
22050 +
22051 +static void __shutdown_nx_info(struct nx_info *nxi)
22052 +{
22053 +       nxi->nx_state |= NXS_SHUTDOWN;
22054 +       vs_net_change(nxi, VSC_NETDOWN);
22055 +}
22056 +
22057 +/*     exported stuff                                          */
22058 +
22059 +void free_nx_info(struct nx_info *nxi)
22060 +{
22061 +       /* context shutdown is mandatory */
22062 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22063 +
22064 +       /* context must not be hashed */
22065 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22066 +
22067 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22068 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22069 +
22070 +       __dealloc_nx_info(nxi);
22071 +}
22072 +
22073 +
22074 +void __nx_set_lback(struct nx_info *nxi)
22075 +{
22076 +       int nid = nxi->nx_id;
22077 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22078 +
22079 +       nxi->v4_lback.s_addr = lback;
22080 +}
22081 +
22082 +extern int __nx_inet_add_lback(__be32 addr);
22083 +extern int __nx_inet_del_lback(__be32 addr);
22084 +
22085 +
22086 +/*     hash table for nx_info hash */
22087 +
22088 +#define NX_HASH_SIZE   13
22089 +
22090 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22091 +
22092 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22093 +
22094 +
22095 +static inline unsigned int __hashval(nid_t nid)
22096 +{
22097 +       return (nid % NX_HASH_SIZE);
22098 +}
22099 +
22100 +
22101 +
22102 +/*     __hash_nx_info()
22103 +
22104 +       * add the nxi to the global hash table
22105 +       * requires the hash_lock to be held                     */
22106 +
22107 +static inline void __hash_nx_info(struct nx_info *nxi)
22108 +{
22109 +       struct hlist_head *head;
22110 +
22111 +       vxd_assert_lock(&nx_info_hash_lock);
22112 +       vxdprintk(VXD_CBIT(nid, 4),
22113 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22114 +
22115 +       /* context must not be hashed */
22116 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22117 +
22118 +       nxi->nx_state |= NXS_HASHED;
22119 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22120 +       hlist_add_head(&nxi->nx_hlist, head);
22121 +       atomic_inc(&nx_global_cactive);
22122 +}
22123 +
22124 +/*     __unhash_nx_info()
22125 +
22126 +       * remove the nxi from the global hash table
22127 +       * requires the hash_lock to be held                     */
22128 +
22129 +static inline void __unhash_nx_info(struct nx_info *nxi)
22130 +{
22131 +       vxd_assert_lock(&nx_info_hash_lock);
22132 +       vxdprintk(VXD_CBIT(nid, 4),
22133 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22134 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22135 +
22136 +       /* context must be hashed */
22137 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22138 +       /* but without tasks */
22139 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22140 +
22141 +       nxi->nx_state &= ~NXS_HASHED;
22142 +       hlist_del(&nxi->nx_hlist);
22143 +       atomic_dec(&nx_global_cactive);
22144 +}
22145 +
22146 +
22147 +/*     __lookup_nx_info()
22148 +
22149 +       * requires the hash_lock to be held
22150 +       * doesn't increment the nx_refcnt                       */
22151 +
22152 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22153 +{
22154 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22155 +       struct hlist_node *pos;
22156 +       struct nx_info *nxi;
22157 +
22158 +       vxd_assert_lock(&nx_info_hash_lock);
22159 +       hlist_for_each(pos, head) {
22160 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22161 +
22162 +               if (nxi->nx_id == nid)
22163 +                       goto found;
22164 +       }
22165 +       nxi = NULL;
22166 +found:
22167 +       vxdprintk(VXD_CBIT(nid, 0),
22168 +               "__lookup_nx_info(#%u): %p[#%u]",
22169 +               nid, nxi, nxi ? nxi->nx_id : 0);
22170 +       return nxi;
22171 +}
22172 +
22173 +
22174 +/*     __create_nx_info()
22175 +
22176 +       * create the requested context
22177 +       * get(), claim() and hash it                            */
22178 +
22179 +static struct nx_info *__create_nx_info(int id)
22180 +{
22181 +       struct nx_info *new, *nxi = NULL;
22182 +
22183 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22184 +
22185 +       if (!(new = __alloc_nx_info(id)))
22186 +               return ERR_PTR(-ENOMEM);
22187 +
22188 +       /* required to make dynamic xids unique */
22189 +       spin_lock(&nx_info_hash_lock);
22190 +
22191 +       /* static context requested */
22192 +       if ((nxi = __lookup_nx_info(id))) {
22193 +               vxdprintk(VXD_CBIT(nid, 0),
22194 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22195 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22196 +                       nxi = ERR_PTR(-EBUSY);
22197 +               else
22198 +                       nxi = ERR_PTR(-EEXIST);
22199 +               goto out_unlock;
22200 +       }
22201 +       /* new context */
22202 +       vxdprintk(VXD_CBIT(nid, 0),
22203 +               "create_nx_info(%d) = %p (new)", id, new);
22204 +       claim_nx_info(new, NULL);
22205 +       __nx_set_lback(new);
22206 +       __hash_nx_info(get_nx_info(new));
22207 +       nxi = new, new = NULL;
22208 +
22209 +out_unlock:
22210 +       spin_unlock(&nx_info_hash_lock);
22211 +       if (new)
22212 +               __dealloc_nx_info(new);
22213 +       return nxi;
22214 +}
22215 +
22216 +
22217 +
22218 +/*     exported stuff                                          */
22219 +
22220 +
22221 +void unhash_nx_info(struct nx_info *nxi)
22222 +{
22223 +       __shutdown_nx_info(nxi);
22224 +       spin_lock(&nx_info_hash_lock);
22225 +       __unhash_nx_info(nxi);
22226 +       spin_unlock(&nx_info_hash_lock);
22227 +}
22228 +
22229 +/*     lookup_nx_info()
22230 +
22231 +       * search for a nx_info and get() it
22232 +       * negative id means current                             */
22233 +
22234 +struct nx_info *lookup_nx_info(int id)
22235 +{
22236 +       struct nx_info *nxi = NULL;
22237 +
22238 +       if (id < 0) {
22239 +               nxi = get_nx_info(current->nx_info);
22240 +       } else if (id > 1) {
22241 +               spin_lock(&nx_info_hash_lock);
22242 +               nxi = get_nx_info(__lookup_nx_info(id));
22243 +               spin_unlock(&nx_info_hash_lock);
22244 +       }
22245 +       return nxi;
22246 +}
22247 +
22248 +/*     nid_is_hashed()
22249 +
22250 +       * verify that nid is still hashed                       */
22251 +
22252 +int nid_is_hashed(nid_t nid)
22253 +{
22254 +       int hashed;
22255 +
22256 +       spin_lock(&nx_info_hash_lock);
22257 +       hashed = (__lookup_nx_info(nid) != NULL);
22258 +       spin_unlock(&nx_info_hash_lock);
22259 +       return hashed;
22260 +}
22261 +
22262 +
22263 +#ifdef CONFIG_PROC_FS
22264 +
22265 +/*     get_nid_list()
22266 +
22267 +       * get a subset of hashed nids for proc
22268 +       * assumes size is at least one                          */
22269 +
22270 +int get_nid_list(int index, unsigned int *nids, int size)
22271 +{
22272 +       int hindex, nr_nids = 0;
22273 +
22274 +       /* only show current and children */
22275 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22276 +               if (index > 0)
22277 +                       return 0;
22278 +               nids[nr_nids] = nx_current_nid();
22279 +               return 1;
22280 +       }
22281 +
22282 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22283 +               struct hlist_head *head = &nx_info_hash[hindex];
22284 +               struct hlist_node *pos;
22285 +
22286 +               spin_lock(&nx_info_hash_lock);
22287 +               hlist_for_each(pos, head) {
22288 +                       struct nx_info *nxi;
22289 +
22290 +                       if (--index > 0)
22291 +                               continue;
22292 +
22293 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22294 +                       nids[nr_nids] = nxi->nx_id;
22295 +                       if (++nr_nids >= size) {
22296 +                               spin_unlock(&nx_info_hash_lock);
22297 +                               goto out;
22298 +                       }
22299 +               }
22300 +               /* keep the lock time short */
22301 +               spin_unlock(&nx_info_hash_lock);
22302 +       }
22303 +out:
22304 +       return nr_nids;
22305 +}
22306 +#endif
22307 +
22308 +
22309 +/*
22310 + *     migrate task to new network
22311 + *     gets nxi, puts old_nxi on change
22312 + */
22313 +
22314 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22315 +{
22316 +       struct nx_info *old_nxi;
22317 +       int ret = 0;
22318 +
22319 +       if (!p || !nxi)
22320 +               BUG();
22321 +
22322 +       vxdprintk(VXD_CBIT(nid, 5),
22323 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22324 +               p, nxi, nxi->nx_id,
22325 +               atomic_read(&nxi->nx_usecnt),
22326 +               atomic_read(&nxi->nx_tasks));
22327 +
22328 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22329 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22330 +               return -EACCES;
22331 +
22332 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22333 +               return -EFAULT;
22334 +
22335 +       /* maybe disallow this completely? */
22336 +       old_nxi = task_get_nx_info(p);
22337 +       if (old_nxi == nxi)
22338 +               goto out;
22339 +
22340 +       task_lock(p);
22341 +       if (old_nxi)
22342 +               clr_nx_info(&p->nx_info);
22343 +       claim_nx_info(nxi, p);
22344 +       set_nx_info(&p->nx_info, nxi);
22345 +       p->nid = nxi->nx_id;
22346 +       task_unlock(p);
22347 +
22348 +       vxdprintk(VXD_CBIT(nid, 5),
22349 +               "moved task %p into nxi:%p[#%d]",
22350 +               p, nxi, nxi->nx_id);
22351 +
22352 +       if (old_nxi)
22353 +               release_nx_info(old_nxi, p);
22354 +       ret = 0;
22355 +out:
22356 +       put_nx_info(old_nxi);
22357 +       return ret;
22358 +}
22359 +
22360 +
22361 +void nx_set_persistent(struct nx_info *nxi)
22362 +{
22363 +       vxdprintk(VXD_CBIT(nid, 6),
22364 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22365 +
22366 +       get_nx_info(nxi);
22367 +       claim_nx_info(nxi, NULL);
22368 +}
22369 +
22370 +void nx_clear_persistent(struct nx_info *nxi)
22371 +{
22372 +       vxdprintk(VXD_CBIT(nid, 6),
22373 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22374 +
22375 +       release_nx_info(nxi, NULL);
22376 +       put_nx_info(nxi);
22377 +}
22378 +
22379 +void nx_update_persistent(struct nx_info *nxi)
22380 +{
22381 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22382 +               nx_set_persistent(nxi);
22383 +       else
22384 +               nx_clear_persistent(nxi);
22385 +}
22386 +
22387 +/* vserver syscall commands below here */
22388 +
22389 +/* taks nid and nx_info functions */
22390 +
22391 +#include <asm/uaccess.h>
22392 +
22393 +
22394 +int vc_task_nid(uint32_t id)
22395 +{
22396 +       nid_t nid;
22397 +
22398 +       if (id) {
22399 +               struct task_struct *tsk;
22400 +
22401 +               read_lock(&tasklist_lock);
22402 +               tsk = find_task_by_real_pid(id);
22403 +               nid = (tsk) ? tsk->nid : -ESRCH;
22404 +               read_unlock(&tasklist_lock);
22405 +       } else
22406 +               nid = nx_current_nid();
22407 +       return nid;
22408 +}
22409 +
22410 +
22411 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22412 +{
22413 +       struct vcmd_nx_info_v0 vc_data;
22414 +
22415 +       vc_data.nid = nxi->nx_id;
22416 +
22417 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22418 +               return -EFAULT;
22419 +       return 0;
22420 +}
22421 +
22422 +
22423 +/* network functions */
22424 +
22425 +int vc_net_create(uint32_t nid, void __user *data)
22426 +{
22427 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22428 +       struct nx_info *new_nxi;
22429 +       int ret;
22430 +
22431 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22432 +               return -EFAULT;
22433 +
22434 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22435 +               return -EINVAL;
22436 +
22437 +       new_nxi = __create_nx_info(nid);
22438 +       if (IS_ERR(new_nxi))
22439 +               return PTR_ERR(new_nxi);
22440 +
22441 +       /* initial flags */
22442 +       new_nxi->nx_flags = vc_data.flagword;
22443 +
22444 +       ret = -ENOEXEC;
22445 +       if (vs_net_change(new_nxi, VSC_NETUP))
22446 +               goto out;
22447 +
22448 +       ret = nx_migrate_task(current, new_nxi);
22449 +       if (ret)
22450 +               goto out;
22451 +
22452 +       /* return context id on success */
22453 +       ret = new_nxi->nx_id;
22454 +
22455 +       /* get a reference for persistent contexts */
22456 +       if ((vc_data.flagword & NXF_PERSISTENT))
22457 +               nx_set_persistent(new_nxi);
22458 +out:
22459 +       release_nx_info(new_nxi, NULL);
22460 +       put_nx_info(new_nxi);
22461 +       return ret;
22462 +}
22463 +
22464 +
22465 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22466 +{
22467 +       return nx_migrate_task(current, nxi);
22468 +}
22469 +
22470 +
22471 +
22472 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22473 +       uint16_t type, uint16_t flags)
22474 +{
22475 +       struct nx_addr_v4 *nxa = &nxi->v4;
22476 +
22477 +       if (NX_IPV4(nxi)) {
22478 +               /* locate last entry */
22479 +               for (; nxa->next; nxa = nxa->next);
22480 +               nxa->next = __alloc_nx_addr_v4();
22481 +               nxa = nxa->next;
22482 +
22483 +               if (IS_ERR(nxa))
22484 +                       return PTR_ERR(nxa);
22485 +       }
22486 +
22487 +       if (nxi->v4.next)
22488 +               /* remove single ip for ip list */
22489 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22490 +
22491 +       nxa->ip[0].s_addr = ip;
22492 +       nxa->ip[1].s_addr = ip2;
22493 +       nxa->mask.s_addr = mask;
22494 +       nxa->type = type;
22495 +       nxa->flags = flags;
22496 +       return 0;
22497 +}
22498 +
22499 +
22500 +int vc_net_add(struct nx_info *nxi, void __user *data)
22501 +{
22502 +       struct vcmd_net_addr_v0 vc_data;
22503 +       int index, ret = 0;
22504 +
22505 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22506 +               return -EFAULT;
22507 +
22508 +       switch (vc_data.type) {
22509 +       case NXA_TYPE_IPV4:
22510 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22511 +                       return -EINVAL;
22512 +
22513 +               index = 0;
22514 +               while (index < vc_data.count) {
22515 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22516 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22517 +                       if (ret)
22518 +                               return ret;
22519 +                       index++;
22520 +               }
22521 +               ret = index;
22522 +               break;
22523 +
22524 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22525 +               nxi->v4_bcast = vc_data.ip[0];
22526 +               ret = 1;
22527 +               break;
22528 +
22529 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22530 +               nxi->v4_lback = vc_data.ip[0];
22531 +               ret = 1;
22532 +               break;
22533 +
22534 +       default:
22535 +               ret = -EINVAL;
22536 +               break;
22537 +       }
22538 +       return ret;
22539 +}
22540 +
22541 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22542 +{
22543 +       struct vcmd_net_addr_v0 vc_data;
22544 +
22545 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22546 +               return -EFAULT;
22547 +
22548 +       switch (vc_data.type) {
22549 +       case NXA_TYPE_ANY:
22550 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22551 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22552 +               break;
22553 +
22554 +       default:
22555 +               return -EINVAL;
22556 +       }
22557 +       return 0;
22558 +}
22559 +
22560 +
22561 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22562 +{
22563 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22564 +
22565 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22566 +               return -EFAULT;
22567 +
22568 +       switch (vc_data.type) {
22569 +       case NXA_TYPE_ADDR:
22570 +       case NXA_TYPE_RANGE:
22571 +       case NXA_TYPE_MASK:
22572 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22573 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22574 +
22575 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22576 +               nxi->v4_bcast = vc_data.ip;
22577 +               break;
22578 +
22579 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22580 +               nxi->v4_lback = vc_data.ip;
22581 +               break;
22582 +
22583 +       default:
22584 +               return -EINVAL;
22585 +       }
22586 +       return 0;
22587 +}
22588 +
22589 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22590 +{
22591 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22592 +
22593 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22594 +               return -EFAULT;
22595 +
22596 +       switch (vc_data.type) {
22597 +/*     case NXA_TYPE_ADDR:
22598 +               break;          */
22599 +
22600 +       case NXA_TYPE_ANY:
22601 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22602 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22603 +               break;
22604 +
22605 +       default:
22606 +               return -EINVAL;
22607 +       }
22608 +       return 0;
22609 +}
22610 +
22611 +
22612 +#ifdef CONFIG_IPV6
22613 +
22614 +int do_add_v6_addr(struct nx_info *nxi,
22615 +       struct in6_addr *ip, struct in6_addr *mask,
22616 +       uint32_t prefix, uint16_t type, uint16_t flags)
22617 +{
22618 +       struct nx_addr_v6 *nxa = &nxi->v6;
22619 +
22620 +       if (NX_IPV6(nxi)) {
22621 +               /* locate last entry */
22622 +               for (; nxa->next; nxa = nxa->next);
22623 +               nxa->next = __alloc_nx_addr_v6();
22624 +               nxa = nxa->next;
22625 +
22626 +               if (IS_ERR(nxa))
22627 +                       return PTR_ERR(nxa);
22628 +       }
22629 +
22630 +       nxa->ip = *ip;
22631 +       nxa->mask = *mask;
22632 +       nxa->prefix = prefix;
22633 +       nxa->type = type;
22634 +       nxa->flags = flags;
22635 +       return 0;
22636 +}
22637 +
22638 +
22639 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22640 +{
22641 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22642 +
22643 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22644 +               return -EFAULT;
22645 +
22646 +       switch (vc_data.type) {
22647 +       case NXA_TYPE_ADDR:
22648 +       case NXA_TYPE_MASK:
22649 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22650 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22651 +       default:
22652 +               return -EINVAL;
22653 +       }
22654 +       return 0;
22655 +}
22656 +
22657 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22658 +{
22659 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22660 +
22661 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22662 +               return -EFAULT;
22663 +
22664 +       switch (vc_data.type) {
22665 +       case NXA_TYPE_ANY:
22666 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22667 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22668 +               break;
22669 +
22670 +       default:
22671 +               return -EINVAL;
22672 +       }
22673 +       return 0;
22674 +}
22675 +
22676 +#endif /* CONFIG_IPV6 */
22677 +
22678 +
22679 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22680 +{
22681 +       struct vcmd_net_flags_v0 vc_data;
22682 +
22683 +       vc_data.flagword = nxi->nx_flags;
22684 +
22685 +       /* special STATE flag handling */
22686 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22687 +
22688 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22689 +               return -EFAULT;
22690 +       return 0;
22691 +}
22692 +
22693 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22694 +{
22695 +       struct vcmd_net_flags_v0 vc_data;
22696 +       uint64_t mask, trigger;
22697 +
22698 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22699 +               return -EFAULT;
22700 +
22701 +       /* special STATE flag handling */
22702 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22703 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22704 +
22705 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22706 +               vc_data.flagword, mask);
22707 +       if (trigger & NXF_PERSISTENT)
22708 +               nx_update_persistent(nxi);
22709 +
22710 +       return 0;
22711 +}
22712 +
22713 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22714 +{
22715 +       struct vcmd_net_caps_v0 vc_data;
22716 +
22717 +       vc_data.ncaps = nxi->nx_ncaps;
22718 +       vc_data.cmask = ~0ULL;
22719 +
22720 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22721 +               return -EFAULT;
22722 +       return 0;
22723 +}
22724 +
22725 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22726 +{
22727 +       struct vcmd_net_caps_v0 vc_data;
22728 +
22729 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22730 +               return -EFAULT;
22731 +
22732 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22733 +               vc_data.ncaps, vc_data.cmask);
22734 +       return 0;
22735 +}
22736 +
22737 +
22738 +#include <linux/module.h>
22739 +
22740 +module_init(init_network);
22741 +
22742 +EXPORT_SYMBOL_GPL(free_nx_info);
22743 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22744 +
22745 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/proc.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/proc.c
22746 --- linux-2.6.27.14/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
22747 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/proc.c  2008-10-31 18:15:28.000000000 +0100
22748 @@ -0,0 +1,1092 @@
22749 +/*
22750 + *  linux/kernel/vserver/proc.c
22751 + *
22752 + *  Virtual Context Support
22753 + *
22754 + *  Copyright (C) 2003-2007  Herbert Pötzl
22755 + *
22756 + *  V0.01  basic structure
22757 + *  V0.02  adaptation vs1.3.0
22758 + *  V0.03  proc permissions
22759 + *  V0.04  locking/generic
22760 + *  V0.05  next generation procfs
22761 + *  V0.06  inode validation
22762 + *  V0.07  generic rewrite vid
22763 + *  V0.08  remove inode type
22764 + *
22765 + */
22766 +
22767 +#include <linux/proc_fs.h>
22768 +#include <asm/unistd.h>
22769 +
22770 +#include <linux/vs_context.h>
22771 +#include <linux/vs_network.h>
22772 +#include <linux/vs_cvirt.h>
22773 +
22774 +#include <linux/in.h>
22775 +#include <linux/inetdevice.h>
22776 +#include <linux/vs_inet.h>
22777 +#include <linux/vs_inet6.h>
22778 +
22779 +#include <linux/vserver/global.h>
22780 +
22781 +#include "cvirt_proc.h"
22782 +#include "cacct_proc.h"
22783 +#include "limit_proc.h"
22784 +#include "sched_proc.h"
22785 +#include "vci_config.h"
22786 +
22787 +
22788 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22789 +{
22790 +       unsigned __capi;
22791 +
22792 +       CAP_FOR_EACH_U32(__capi) {
22793 +               buffer += sprintf(buffer, "%08x",
22794 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22795 +       }
22796 +       return buffer;
22797 +}
22798 +
22799 +
22800 +static struct proc_dir_entry *proc_virtual;
22801 +
22802 +static struct proc_dir_entry *proc_virtnet;
22803 +
22804 +
22805 +/* first the actual feeds */
22806 +
22807 +
22808 +static int proc_vci(char *buffer)
22809 +{
22810 +       return sprintf(buffer,
22811 +               "VCIVersion:\t%04x:%04x\n"
22812 +               "VCISyscall:\t%d\n"
22813 +               "VCIKernel:\t%08x\n",
22814 +               VCI_VERSION >> 16,
22815 +               VCI_VERSION & 0xFFFF,
22816 +               __NR_vserver,
22817 +               vci_kernel_config());
22818 +}
22819 +
22820 +static int proc_virtual_info(char *buffer)
22821 +{
22822 +       return proc_vci(buffer);
22823 +}
22824 +
22825 +static int proc_virtual_status(char *buffer)
22826 +{
22827 +       return sprintf(buffer,
22828 +               "#CTotal:\t%d\n"
22829 +               "#CActive:\t%d\n"
22830 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22831 +               atomic_read(&vx_global_ctotal),
22832 +               atomic_read(&vx_global_cactive),
22833 +               atomic_read(&vs_global_nsproxy),
22834 +               atomic_read(&vs_global_fs),
22835 +               atomic_read(&vs_global_mnt_ns),
22836 +               atomic_read(&vs_global_uts_ns),
22837 +               atomic_read(&vs_global_ipc_ns),
22838 +               atomic_read(&vs_global_user_ns),
22839 +               atomic_read(&vs_global_pid_ns));
22840 +}
22841 +
22842 +
22843 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22844 +{
22845 +       int length;
22846 +
22847 +       length = sprintf(buffer,
22848 +               "ID:\t%d\n"
22849 +               "Info:\t%p\n"
22850 +               "Init:\t%d\n"
22851 +               "OOM:\t%lld\n",
22852 +               vxi->vx_id,
22853 +               vxi,
22854 +               vxi->vx_initpid,
22855 +               vxi->vx_badness_bias);
22856 +       return length;
22857 +}
22858 +
22859 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22860 +{
22861 +       char *orig = buffer;
22862 +
22863 +       buffer += sprintf(buffer,
22864 +               "UseCnt:\t%d\n"
22865 +               "Tasks:\t%d\n"
22866 +               "Flags:\t%016llx\n",
22867 +               atomic_read(&vxi->vx_usecnt),
22868 +               atomic_read(&vxi->vx_tasks),
22869 +               (unsigned long long)vxi->vx_flags);
22870 +
22871 +       buffer += sprintf(buffer, "BCaps:\t");
22872 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22873 +       buffer += sprintf(buffer, "\n");
22874 +
22875 +       buffer += sprintf(buffer,
22876 +               "CCaps:\t%016llx\n"
22877 +               "Spaces:\t%08lx %08lx\n",
22878 +               (unsigned long long)vxi->vx_ccaps,
22879 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22880 +       return buffer - orig;
22881 +}
22882 +
22883 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22884 +{
22885 +       return vx_info_proc_limit(&vxi->limit, buffer);
22886 +}
22887 +
22888 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22889 +{
22890 +       int cpu, length;
22891 +
22892 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22893 +       for_each_online_cpu(cpu) {
22894 +               length += vx_info_proc_sched_pc(
22895 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22896 +                       buffer + length, cpu);
22897 +       }
22898 +       return length;
22899 +}
22900 +
22901 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22902 +{
22903 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22904 +}
22905 +
22906 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22907 +{
22908 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22909 +}
22910 +
22911 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22912 +{
22913 +       int cpu, length;
22914 +
22915 +       vx_update_load(vxi);
22916 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22917 +       for_each_online_cpu(cpu) {
22918 +               length += vx_info_proc_cvirt_pc(
22919 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22920 +                       buffer + length, cpu);
22921 +       }
22922 +       return length;
22923 +}
22924 +
22925 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22926 +{
22927 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22928 +}
22929 +
22930 +
22931 +static int proc_virtnet_info(char *buffer)
22932 +{
22933 +       return proc_vci(buffer);
22934 +}
22935 +
22936 +static int proc_virtnet_status(char *buffer)
22937 +{
22938 +       return sprintf(buffer,
22939 +               "#CTotal:\t%d\n"
22940 +               "#CActive:\t%d\n",
22941 +               atomic_read(&nx_global_ctotal),
22942 +               atomic_read(&nx_global_cactive));
22943 +}
22944 +
22945 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22946 +{
22947 +       struct nx_addr_v4 *v4a;
22948 +#ifdef CONFIG_IPV6
22949 +       struct nx_addr_v6 *v6a;
22950 +#endif
22951 +       int length, i;
22952 +
22953 +       length = sprintf(buffer,
22954 +               "ID:\t%d\n"
22955 +               "Info:\t%p\n"
22956 +               "Bcast:\t" NIPQUAD_FMT "\n"
22957 +               "Lback:\t" NIPQUAD_FMT "\n",
22958 +               nxi->nx_id,
22959 +               nxi,
22960 +               NIPQUAD(nxi->v4_bcast.s_addr),
22961 +               NIPQUAD(nxi->v4_lback.s_addr));
22962 +
22963 +       if (!NX_IPV4(nxi))
22964 +               goto skip_v4;
22965 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22966 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22967 +                       i, NXAV4(v4a));
22968 +skip_v4:
22969 +#ifdef CONFIG_IPV6
22970 +       if (!NX_IPV6(nxi))
22971 +               goto skip_v6;
22972 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22973 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22974 +                       i, NXAV6(v6a));
22975 +skip_v6:
22976 +#endif
22977 +       return length;
22978 +}
22979 +
22980 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22981 +{
22982 +       int length;
22983 +
22984 +       length = sprintf(buffer,
22985 +               "UseCnt:\t%d\n"
22986 +               "Tasks:\t%d\n"
22987 +               "Flags:\t%016llx\n"
22988 +               "NCaps:\t%016llx\n",
22989 +               atomic_read(&nxi->nx_usecnt),
22990 +               atomic_read(&nxi->nx_tasks),
22991 +               (unsigned long long)nxi->nx_flags,
22992 +               (unsigned long long)nxi->nx_ncaps);
22993 +       return length;
22994 +}
22995 +
22996 +
22997 +
22998 +/* here the inode helpers */
22999 +
23000 +struct vs_entry {
23001 +       int len;
23002 +       char *name;
23003 +       mode_t mode;
23004 +       struct inode_operations *iop;
23005 +       struct file_operations *fop;
23006 +       union proc_op op;
23007 +};
23008 +
23009 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23010 +{
23011 +       struct inode *inode = new_inode(sb);
23012 +
23013 +       if (!inode)
23014 +               goto out;
23015 +
23016 +       inode->i_mode = p->mode;
23017 +       if (p->iop)
23018 +               inode->i_op = p->iop;
23019 +       if (p->fop)
23020 +               inode->i_fop = p->fop;
23021 +
23022 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23023 +       inode->i_flags |= S_IMMUTABLE;
23024 +
23025 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23026 +
23027 +       inode->i_uid = 0;
23028 +       inode->i_gid = 0;
23029 +       inode->i_tag = 0;
23030 +out:
23031 +       return inode;
23032 +}
23033 +
23034 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23035 +       struct dentry *dentry, int id, void *ptr)
23036 +{
23037 +       struct vs_entry *p = ptr;
23038 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23039 +       struct dentry *error = ERR_PTR(-EINVAL);
23040 +
23041 +       if (!inode)
23042 +               goto out;
23043 +
23044 +       PROC_I(inode)->op = p->op;
23045 +       PROC_I(inode)->fd = id;
23046 +       d_add(dentry, inode);
23047 +       error = NULL;
23048 +out:
23049 +       return error;
23050 +}
23051 +
23052 +/* Lookups */
23053 +
23054 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23055 +
23056 +/*
23057 + * Fill a directory entry.
23058 + *
23059 + * If possible create the dcache entry and derive our inode number and
23060 + * file type from dcache entry.
23061 + *
23062 + * Since all of the proc inode numbers are dynamically generated, the inode
23063 + * numbers do not exist until the inode is cache.  This means creating the
23064 + * the dcache entry in readdir is necessary to keep the inode numbers
23065 + * reported by readdir in sync with the inode numbers reported
23066 + * by stat.
23067 + */
23068 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23069 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23070 +{
23071 +       struct dentry *child, *dir = filp->f_dentry;
23072 +       struct inode *inode;
23073 +       struct qstr qname;
23074 +       ino_t ino = 0;
23075 +       unsigned type = DT_UNKNOWN;
23076 +
23077 +       qname.name = name;
23078 +       qname.len  = len;
23079 +       qname.hash = full_name_hash(name, len);
23080 +
23081 +       child = d_lookup(dir, &qname);
23082 +       if (!child) {
23083 +               struct dentry *new;
23084 +               new = d_alloc(dir, &qname);
23085 +               if (new) {
23086 +                       child = instantiate(dir->d_inode, new, id, ptr);
23087 +                       if (child)
23088 +                               dput(new);
23089 +                       else
23090 +                               child = new;
23091 +               }
23092 +       }
23093 +       if (!child || IS_ERR(child) || !child->d_inode)
23094 +               goto end_instantiate;
23095 +       inode = child->d_inode;
23096 +       if (inode) {
23097 +               ino = inode->i_ino;
23098 +               type = inode->i_mode >> 12;
23099 +       }
23100 +       dput(child);
23101 +end_instantiate:
23102 +       if (!ino)
23103 +               ino = find_inode_number(dir, &qname);
23104 +       if (!ino)
23105 +               ino = 1;
23106 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23107 +}
23108 +
23109 +
23110 +
23111 +/* get and revalidate vx_info/xid */
23112 +
23113 +static inline
23114 +struct vx_info *get_proc_vx_info(struct inode *inode)
23115 +{
23116 +       return lookup_vx_info(PROC_I(inode)->fd);
23117 +}
23118 +
23119 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23120 +{
23121 +       struct inode *inode = dentry->d_inode;
23122 +       xid_t xid = PROC_I(inode)->fd;
23123 +
23124 +       if (!xid || xid_is_hashed(xid))
23125 +               return 1;
23126 +       d_drop(dentry);
23127 +       return 0;
23128 +}
23129 +
23130 +
23131 +/* get and revalidate nx_info/nid */
23132 +
23133 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23134 +{
23135 +       struct inode *inode = dentry->d_inode;
23136 +       nid_t nid = PROC_I(inode)->fd;
23137 +
23138 +       if (!nid || nid_is_hashed(nid))
23139 +               return 1;
23140 +       d_drop(dentry);
23141 +       return 0;
23142 +}
23143 +
23144 +
23145 +
23146 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23147 +
23148 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23149 +                         size_t count, loff_t *ppos)
23150 +{
23151 +       struct inode *inode = file->f_dentry->d_inode;
23152 +       unsigned long page;
23153 +       ssize_t length = 0;
23154 +
23155 +       if (count > PROC_BLOCK_SIZE)
23156 +               count = PROC_BLOCK_SIZE;
23157 +
23158 +       /* fade that out as soon as stable */
23159 +       WARN_ON(PROC_I(inode)->fd);
23160 +
23161 +       if (!(page = __get_free_page(GFP_KERNEL)))
23162 +               return -ENOMEM;
23163 +
23164 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23165 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23166 +
23167 +       if (length >= 0)
23168 +               length = simple_read_from_buffer(buf, count, ppos,
23169 +                       (char *)page, length);
23170 +
23171 +       free_page(page);
23172 +       return length;
23173 +}
23174 +
23175 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23176 +                         size_t count, loff_t *ppos)
23177 +{
23178 +       struct inode *inode = file->f_dentry->d_inode;
23179 +       struct vx_info *vxi = NULL;
23180 +       xid_t xid = PROC_I(inode)->fd;
23181 +       unsigned long page;
23182 +       ssize_t length = 0;
23183 +
23184 +       if (count > PROC_BLOCK_SIZE)
23185 +               count = PROC_BLOCK_SIZE;
23186 +
23187 +       /* fade that out as soon as stable */
23188 +       WARN_ON(!xid);
23189 +       vxi = lookup_vx_info(xid);
23190 +       if (!vxi)
23191 +               goto out;
23192 +
23193 +       length = -ENOMEM;
23194 +       if (!(page = __get_free_page(GFP_KERNEL)))
23195 +               goto out_put;
23196 +
23197 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23198 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23199 +
23200 +       if (length >= 0)
23201 +               length = simple_read_from_buffer(buf, count, ppos,
23202 +                       (char *)page, length);
23203 +
23204 +       free_page(page);
23205 +out_put:
23206 +       put_vx_info(vxi);
23207 +out:
23208 +       return length;
23209 +}
23210 +
23211 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23212 +                         size_t count, loff_t *ppos)
23213 +{
23214 +       struct inode *inode = file->f_dentry->d_inode;
23215 +       struct nx_info *nxi = NULL;
23216 +       nid_t nid = PROC_I(inode)->fd;
23217 +       unsigned long page;
23218 +       ssize_t length = 0;
23219 +
23220 +       if (count > PROC_BLOCK_SIZE)
23221 +               count = PROC_BLOCK_SIZE;
23222 +
23223 +       /* fade that out as soon as stable */
23224 +       WARN_ON(!nid);
23225 +       nxi = lookup_nx_info(nid);
23226 +       if (!nxi)
23227 +               goto out;
23228 +
23229 +       length = -ENOMEM;
23230 +       if (!(page = __get_free_page(GFP_KERNEL)))
23231 +               goto out_put;
23232 +
23233 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23234 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23235 +
23236 +       if (length >= 0)
23237 +               length = simple_read_from_buffer(buf, count, ppos,
23238 +                       (char *)page, length);
23239 +
23240 +       free_page(page);
23241 +out_put:
23242 +       put_nx_info(nxi);
23243 +out:
23244 +       return length;
23245 +}
23246 +
23247 +
23248 +
23249 +/* here comes the lower level */
23250 +
23251 +
23252 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23253 +       .len  = sizeof(NAME) - 1,       \
23254 +       .name = (NAME),                 \
23255 +       .mode = MODE,                   \
23256 +       .iop  = IOP,                    \
23257 +       .fop  = FOP,                    \
23258 +       .op   = OP,                     \
23259 +}
23260 +
23261 +
23262 +#define DIR(NAME, MODE, OTYPE)                         \
23263 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23264 +               &proc_ ## OTYPE ## _inode_operations,   \
23265 +               &proc_ ## OTYPE ## _file_operations, { } )
23266 +
23267 +#define INF(NAME, MODE, OTYPE)                         \
23268 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23269 +               &proc_vs_info_file_operations,          \
23270 +               { .proc_vs_read = &proc_##OTYPE } )
23271 +
23272 +#define VINF(NAME, MODE, OTYPE)                                \
23273 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23274 +               &proc_vx_info_file_operations,          \
23275 +               { .proc_vxi_read = &proc_##OTYPE } )
23276 +
23277 +#define NINF(NAME, MODE, OTYPE)                                \
23278 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23279 +               &proc_nx_info_file_operations,          \
23280 +               { .proc_nxi_read = &proc_##OTYPE } )
23281 +
23282 +
23283 +static struct file_operations proc_vs_info_file_operations = {
23284 +       .read =         proc_vs_info_read,
23285 +};
23286 +
23287 +static struct file_operations proc_vx_info_file_operations = {
23288 +       .read =         proc_vx_info_read,
23289 +};
23290 +
23291 +static struct dentry_operations proc_xid_dentry_operations = {
23292 +       .d_revalidate = proc_xid_revalidate,
23293 +};
23294 +
23295 +static struct vs_entry vx_base_stuff[] = {
23296 +       VINF("info",    S_IRUGO, vxi_info),
23297 +       VINF("status",  S_IRUGO, vxi_status),
23298 +       VINF("limit",   S_IRUGO, vxi_limit),
23299 +       VINF("sched",   S_IRUGO, vxi_sched),
23300 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23301 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23302 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23303 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23304 +       {}
23305 +};
23306 +
23307 +
23308 +
23309 +
23310 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23311 +       struct dentry *dentry, int id, void *ptr)
23312 +{
23313 +       dentry->d_op = &proc_xid_dentry_operations;
23314 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23315 +}
23316 +
23317 +static struct dentry *proc_xid_lookup(struct inode *dir,
23318 +       struct dentry *dentry, struct nameidata *nd)
23319 +{
23320 +       struct vs_entry *p = vx_base_stuff;
23321 +       struct dentry *error = ERR_PTR(-ENOENT);
23322 +
23323 +       for (; p->name; p++) {
23324 +               if (p->len != dentry->d_name.len)
23325 +                       continue;
23326 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23327 +                       break;
23328 +       }
23329 +       if (!p->name)
23330 +               goto out;
23331 +
23332 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23333 +out:
23334 +       return error;
23335 +}
23336 +
23337 +static int proc_xid_readdir(struct file *filp,
23338 +       void *dirent, filldir_t filldir)
23339 +{
23340 +       struct dentry *dentry = filp->f_dentry;
23341 +       struct inode *inode = dentry->d_inode;
23342 +       struct vs_entry *p = vx_base_stuff;
23343 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23344 +       int pos, index;
23345 +       u64 ino;
23346 +
23347 +       pos = filp->f_pos;
23348 +       switch (pos) {
23349 +       case 0:
23350 +               ino = inode->i_ino;
23351 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23352 +                       goto out;
23353 +               pos++;
23354 +               /* fall through */
23355 +       case 1:
23356 +               ino = parent_ino(dentry);
23357 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23358 +                       goto out;
23359 +               pos++;
23360 +               /* fall through */
23361 +       default:
23362 +               index = pos - 2;
23363 +               if (index >= size)
23364 +                       goto out;
23365 +               for (p += index; p->name; p++) {
23366 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23367 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23368 +                               goto out;
23369 +                       pos++;
23370 +               }
23371 +       }
23372 +out:
23373 +       filp->f_pos = pos;
23374 +       return 1;
23375 +}
23376 +
23377 +
23378 +
23379 +static struct file_operations proc_nx_info_file_operations = {
23380 +       .read =         proc_nx_info_read,
23381 +};
23382 +
23383 +static struct dentry_operations proc_nid_dentry_operations = {
23384 +       .d_revalidate = proc_nid_revalidate,
23385 +};
23386 +
23387 +static struct vs_entry nx_base_stuff[] = {
23388 +       NINF("info",    S_IRUGO, nxi_info),
23389 +       NINF("status",  S_IRUGO, nxi_status),
23390 +       {}
23391 +};
23392 +
23393 +
23394 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23395 +       struct dentry *dentry, int id, void *ptr)
23396 +{
23397 +       dentry->d_op = &proc_nid_dentry_operations;
23398 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23399 +}
23400 +
23401 +static struct dentry *proc_nid_lookup(struct inode *dir,
23402 +       struct dentry *dentry, struct nameidata *nd)
23403 +{
23404 +       struct vs_entry *p = nx_base_stuff;
23405 +       struct dentry *error = ERR_PTR(-ENOENT);
23406 +
23407 +       for (; p->name; p++) {
23408 +               if (p->len != dentry->d_name.len)
23409 +                       continue;
23410 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23411 +                       break;
23412 +       }
23413 +       if (!p->name)
23414 +               goto out;
23415 +
23416 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23417 +out:
23418 +       return error;
23419 +}
23420 +
23421 +static int proc_nid_readdir(struct file *filp,
23422 +       void *dirent, filldir_t filldir)
23423 +{
23424 +       struct dentry *dentry = filp->f_dentry;
23425 +       struct inode *inode = dentry->d_inode;
23426 +       struct vs_entry *p = nx_base_stuff;
23427 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23428 +       int pos, index;
23429 +       u64 ino;
23430 +
23431 +       pos = filp->f_pos;
23432 +       switch (pos) {
23433 +       case 0:
23434 +               ino = inode->i_ino;
23435 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23436 +                       goto out;
23437 +               pos++;
23438 +               /* fall through */
23439 +       case 1:
23440 +               ino = parent_ino(dentry);
23441 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23442 +                       goto out;
23443 +               pos++;
23444 +               /* fall through */
23445 +       default:
23446 +               index = pos - 2;
23447 +               if (index >= size)
23448 +                       goto out;
23449 +               for (p += index; p->name; p++) {
23450 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23451 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23452 +                               goto out;
23453 +                       pos++;
23454 +               }
23455 +       }
23456 +out:
23457 +       filp->f_pos = pos;
23458 +       return 1;
23459 +}
23460 +
23461 +
23462 +#define MAX_MULBY10    ((~0U - 9) / 10)
23463 +
23464 +static inline int atovid(const char *str, int len)
23465 +{
23466 +       int vid, c;
23467 +
23468 +       vid = 0;
23469 +       while (len-- > 0) {
23470 +               c = *str - '0';
23471 +               str++;
23472 +               if (c > 9)
23473 +                       return -1;
23474 +               if (vid >= MAX_MULBY10)
23475 +                       return -1;
23476 +               vid *= 10;
23477 +               vid += c;
23478 +               if (!vid)
23479 +                       return -1;
23480 +       }
23481 +       return vid;
23482 +}
23483 +
23484 +/* now the upper level (virtual) */
23485 +
23486 +
23487 +static struct file_operations proc_xid_file_operations = {
23488 +       .read =         generic_read_dir,
23489 +       .readdir =      proc_xid_readdir,
23490 +};
23491 +
23492 +static struct inode_operations proc_xid_inode_operations = {
23493 +       .lookup =       proc_xid_lookup,
23494 +};
23495 +
23496 +static struct vs_entry vx_virtual_stuff[] = {
23497 +       INF("info",     S_IRUGO, virtual_info),
23498 +       INF("status",   S_IRUGO, virtual_status),
23499 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23500 +};
23501 +
23502 +
23503 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23504 +       struct dentry *dentry, struct nameidata *nd)
23505 +{
23506 +       struct vs_entry *p = vx_virtual_stuff;
23507 +       struct dentry *error = ERR_PTR(-ENOENT);
23508 +       int id = 0;
23509 +
23510 +       for (; p->name; p++) {
23511 +               if (p->len != dentry->d_name.len)
23512 +                       continue;
23513 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23514 +                       break;
23515 +       }
23516 +       if (p->name)
23517 +               goto instantiate;
23518 +
23519 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23520 +       if ((id < 0) || !xid_is_hashed(id))
23521 +               goto out;
23522 +
23523 +instantiate:
23524 +       error = proc_xid_instantiate(dir, dentry, id, p);
23525 +out:
23526 +       return error;
23527 +}
23528 +
23529 +static struct file_operations proc_nid_file_operations = {
23530 +       .read =         generic_read_dir,
23531 +       .readdir =      proc_nid_readdir,
23532 +};
23533 +
23534 +static struct inode_operations proc_nid_inode_operations = {
23535 +       .lookup =       proc_nid_lookup,
23536 +};
23537 +
23538 +static struct vs_entry nx_virtnet_stuff[] = {
23539 +       INF("info",     S_IRUGO, virtnet_info),
23540 +       INF("status",   S_IRUGO, virtnet_status),
23541 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23542 +};
23543 +
23544 +
23545 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23546 +       struct dentry *dentry, struct nameidata *nd)
23547 +{
23548 +       struct vs_entry *p = nx_virtnet_stuff;
23549 +       struct dentry *error = ERR_PTR(-ENOENT);
23550 +       int id = 0;
23551 +
23552 +       for (; p->name; p++) {
23553 +               if (p->len != dentry->d_name.len)
23554 +                       continue;
23555 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23556 +                       break;
23557 +       }
23558 +       if (p->name)
23559 +               goto instantiate;
23560 +
23561 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23562 +       if ((id < 0) || !nid_is_hashed(id))
23563 +               goto out;
23564 +
23565 +instantiate:
23566 +       error = proc_nid_instantiate(dir, dentry, id, p);
23567 +out:
23568 +       return error;
23569 +}
23570 +
23571 +
23572 +#define PROC_MAXVIDS 32
23573 +
23574 +int proc_virtual_readdir(struct file *filp,
23575 +       void *dirent, filldir_t filldir)
23576 +{
23577 +       struct dentry *dentry = filp->f_dentry;
23578 +       struct inode *inode = dentry->d_inode;
23579 +       struct vs_entry *p = vx_virtual_stuff;
23580 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23581 +       int pos, index;
23582 +       unsigned int xid_array[PROC_MAXVIDS];
23583 +       char buf[PROC_NUMBUF];
23584 +       unsigned int nr_xids, i;
23585 +       u64 ino;
23586 +
23587 +       pos = filp->f_pos;
23588 +       switch (pos) {
23589 +       case 0:
23590 +               ino = inode->i_ino;
23591 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23592 +                       goto out;
23593 +               pos++;
23594 +               /* fall through */
23595 +       case 1:
23596 +               ino = parent_ino(dentry);
23597 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23598 +                       goto out;
23599 +               pos++;
23600 +               /* fall through */
23601 +       default:
23602 +               index = pos - 2;
23603 +               if (index >= size)
23604 +                       goto entries;
23605 +               for (p += index; p->name; p++) {
23606 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23607 +                               vs_proc_instantiate, 0, p))
23608 +                               goto out;
23609 +                       pos++;
23610 +               }
23611 +       entries:
23612 +               index = pos - size;
23613 +               p = &vx_virtual_stuff[size - 1];
23614 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23615 +               for (i = 0; i < nr_xids; i++) {
23616 +                       int n, xid = xid_array[i];
23617 +                       unsigned int j = PROC_NUMBUF;
23618 +
23619 +                       n = xid;
23620 +                       do
23621 +                               buf[--j] = '0' + (n % 10);
23622 +                       while (n /= 10);
23623 +
23624 +                       if (proc_fill_cache(filp, dirent, filldir,
23625 +                               buf + j, PROC_NUMBUF - j,
23626 +                               vs_proc_instantiate, xid, p))
23627 +                               goto out;
23628 +                       pos++;
23629 +               }
23630 +       }
23631 +out:
23632 +       filp->f_pos = pos;
23633 +       return 0;
23634 +}
23635 +
23636 +static int proc_virtual_getattr(struct vfsmount *mnt,
23637 +       struct dentry *dentry, struct kstat *stat)
23638 +{
23639 +       struct inode *inode = dentry->d_inode;
23640 +
23641 +       generic_fillattr(inode, stat);
23642 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23643 +       return 0;
23644 +}
23645 +
23646 +static struct file_operations proc_virtual_dir_operations = {
23647 +       .read =         generic_read_dir,
23648 +       .readdir =      proc_virtual_readdir,
23649 +};
23650 +
23651 +static struct inode_operations proc_virtual_dir_inode_operations = {
23652 +       .getattr =      proc_virtual_getattr,
23653 +       .lookup =       proc_virtual_lookup,
23654 +};
23655 +
23656 +
23657 +
23658 +
23659 +
23660 +int proc_virtnet_readdir(struct file *filp,
23661 +       void *dirent, filldir_t filldir)
23662 +{
23663 +       struct dentry *dentry = filp->f_dentry;
23664 +       struct inode *inode = dentry->d_inode;
23665 +       struct vs_entry *p = nx_virtnet_stuff;
23666 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23667 +       int pos, index;
23668 +       unsigned int nid_array[PROC_MAXVIDS];
23669 +       char buf[PROC_NUMBUF];
23670 +       unsigned int nr_nids, i;
23671 +       u64 ino;
23672 +
23673 +       pos = filp->f_pos;
23674 +       switch (pos) {
23675 +       case 0:
23676 +               ino = inode->i_ino;
23677 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23678 +                       goto out;
23679 +               pos++;
23680 +               /* fall through */
23681 +       case 1:
23682 +               ino = parent_ino(dentry);
23683 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23684 +                       goto out;
23685 +               pos++;
23686 +               /* fall through */
23687 +       default:
23688 +               index = pos - 2;
23689 +               if (index >= size)
23690 +                       goto entries;
23691 +               for (p += index; p->name; p++) {
23692 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23693 +                               vs_proc_instantiate, 0, p))
23694 +                               goto out;
23695 +                       pos++;
23696 +               }
23697 +       entries:
23698 +               index = pos - size;
23699 +               p = &nx_virtnet_stuff[size - 1];
23700 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23701 +               for (i = 0; i < nr_nids; i++) {
23702 +                       int n, nid = nid_array[i];
23703 +                       unsigned int j = PROC_NUMBUF;
23704 +
23705 +                       n = nid;
23706 +                       do
23707 +                               buf[--j] = '0' + (n % 10);
23708 +                       while (n /= 10);
23709 +
23710 +                       if (proc_fill_cache(filp, dirent, filldir,
23711 +                               buf + j, PROC_NUMBUF - j,
23712 +                               vs_proc_instantiate, nid, p))
23713 +                               goto out;
23714 +                       pos++;
23715 +               }
23716 +       }
23717 +out:
23718 +       filp->f_pos = pos;
23719 +       return 0;
23720 +}
23721 +
23722 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23723 +       struct dentry *dentry, struct kstat *stat)
23724 +{
23725 +       struct inode *inode = dentry->d_inode;
23726 +
23727 +       generic_fillattr(inode, stat);
23728 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23729 +       return 0;
23730 +}
23731 +
23732 +static struct file_operations proc_virtnet_dir_operations = {
23733 +       .read =         generic_read_dir,
23734 +       .readdir =      proc_virtnet_readdir,
23735 +};
23736 +
23737 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23738 +       .getattr =      proc_virtnet_getattr,
23739 +       .lookup =       proc_virtnet_lookup,
23740 +};
23741 +
23742 +
23743 +
23744 +void proc_vx_init(void)
23745 +{
23746 +       struct proc_dir_entry *ent;
23747 +
23748 +       ent = proc_mkdir("virtual", 0);
23749 +       if (ent) {
23750 +               ent->proc_fops = &proc_virtual_dir_operations;
23751 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23752 +       }
23753 +       proc_virtual = ent;
23754 +
23755 +       ent = proc_mkdir("virtnet", 0);
23756 +       if (ent) {
23757 +               ent->proc_fops = &proc_virtnet_dir_operations;
23758 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23759 +       }
23760 +       proc_virtnet = ent;
23761 +}
23762 +
23763 +
23764 +
23765 +
23766 +/* per pid info */
23767 +
23768 +
23769 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23770 +{
23771 +       struct vx_info *vxi;
23772 +       char *orig = buffer;
23773 +
23774 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23775 +
23776 +       vxi = task_get_vx_info(p);
23777 +       if (!vxi)
23778 +               goto out;
23779 +
23780 +       buffer += sprintf(buffer, "BCaps:\t");
23781 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23782 +       buffer += sprintf(buffer, "\n");
23783 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23784 +               (unsigned long long)vxi->vx_ccaps);
23785 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23786 +               (unsigned long long)vxi->vx_flags);
23787 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23788 +
23789 +       put_vx_info(vxi);
23790 +out:
23791 +       return buffer - orig;
23792 +}
23793 +
23794 +
23795 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23796 +{
23797 +       struct nx_info *nxi;
23798 +       struct nx_addr_v4 *v4a;
23799 +#ifdef CONFIG_IPV6
23800 +       struct nx_addr_v6 *v6a;
23801 +#endif
23802 +       char *orig = buffer;
23803 +       int i;
23804 +
23805 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23806 +
23807 +       nxi = task_get_nx_info(p);
23808 +       if (!nxi)
23809 +               goto out;
23810 +
23811 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23812 +               (unsigned long long)nxi->nx_ncaps);
23813 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23814 +               (unsigned long long)nxi->nx_flags);
23815 +
23816 +       buffer += sprintf(buffer,
23817 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23818 +               NIPQUAD(nxi->v4_bcast.s_addr));
23819 +       buffer += sprintf (buffer,
23820 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23821 +               NIPQUAD(nxi->v4_lback.s_addr));
23822 +       if (!NX_IPV4(nxi))
23823 +               goto skip_v4;
23824 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23825 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23826 +                       i, NXAV4(v4a));
23827 +skip_v4:
23828 +#ifdef CONFIG_IPV6
23829 +       if (!NX_IPV6(nxi))
23830 +               goto skip_v6;
23831 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23832 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23833 +                       i, NXAV6(v6a));
23834 +skip_v6:
23835 +#endif
23836 +       put_nx_info(nxi);
23837 +out:
23838 +       return buffer - orig;
23839 +}
23840 +
23841 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/sched.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sched.c
23842 --- linux-2.6.27.14/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
23843 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sched.c 2008-10-13 14:54:20.000000000 +0200
23844 @@ -0,0 +1,413 @@
23845 +/*
23846 + *  linux/kernel/vserver/sched.c
23847 + *
23848 + *  Virtual Server: Scheduler Support
23849 + *
23850 + *  Copyright (C) 2004-2007  Herbert Pötzl
23851 + *
23852 + *  V0.01  adapted Sam Vilains version to 2.6.3
23853 + *  V0.02  removed legacy interface
23854 + *  V0.03  changed vcmds to vxi arg
23855 + *  V0.04  removed older and legacy interfaces
23856 + *
23857 + */
23858 +
23859 +#include <linux/vs_context.h>
23860 +#include <linux/vs_sched.h>
23861 +#include <linux/vserver/sched_cmd.h>
23862 +
23863 +#include <asm/uaccess.h>
23864 +
23865 +
23866 +#define vxd_check_range(val, min, max) do {            \
23867 +       vxlprintk((val < min) || (val > max),           \
23868 +               "check_range(%ld,%ld,%ld)",             \
23869 +               (long)val, (long)min, (long)max,        \
23870 +               __FILE__, __LINE__);                    \
23871 +       } while (0)
23872 +
23873 +
23874 +void vx_update_sched_param(struct _vx_sched *sched,
23875 +       struct _vx_sched_pc *sched_pc)
23876 +{
23877 +       unsigned int set_mask = sched->update_mask;
23878 +
23879 +       if (set_mask & VXSM_FILL_RATE)
23880 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23881 +       if (set_mask & VXSM_INTERVAL)
23882 +               sched_pc->interval[0] = sched->interval[0];
23883 +       if (set_mask & VXSM_FILL_RATE2)
23884 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23885 +       if (set_mask & VXSM_INTERVAL2)
23886 +               sched_pc->interval[1] = sched->interval[1];
23887 +       if (set_mask & VXSM_TOKENS)
23888 +               sched_pc->tokens = sched->tokens;
23889 +       if (set_mask & VXSM_TOKENS_MIN)
23890 +               sched_pc->tokens_min = sched->tokens_min;
23891 +       if (set_mask & VXSM_TOKENS_MAX)
23892 +               sched_pc->tokens_max = sched->tokens_max;
23893 +       if (set_mask & VXSM_PRIO_BIAS)
23894 +               sched_pc->prio_bias = sched->prio_bias;
23895 +
23896 +       if (set_mask & VXSM_IDLE_TIME)
23897 +               sched_pc->flags |= VXSF_IDLE_TIME;
23898 +       else
23899 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23900 +
23901 +       /* reset time */
23902 +       sched_pc->norm_time = jiffies;
23903 +}
23904 +
23905 +
23906 +/*
23907 + * recalculate the context's scheduling tokens
23908 + *
23909 + * ret > 0 : number of tokens available
23910 + * ret < 0 : on hold, check delta_min[]
23911 + *          -1 only jiffies
23912 + *          -2 also idle time
23913 + *
23914 + */
23915 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23916 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23917 +{
23918 +       long delta;
23919 +       long tokens = 0;
23920 +       int flags = sched_pc->flags;
23921 +
23922 +       /* how much time did pass? */
23923 +       delta = *norm_time - sched_pc->norm_time;
23924 +       vxd_check_range(delta, 0, INT_MAX);
23925 +
23926 +       if (delta >= sched_pc->interval[0]) {
23927 +               long tokens, integral;
23928 +
23929 +               /* calc integral token part */
23930 +               tokens = delta / sched_pc->interval[0];
23931 +               integral = tokens * sched_pc->interval[0];
23932 +               tokens *= sched_pc->fill_rate[0];
23933 +#ifdef CONFIG_VSERVER_HARDCPU
23934 +               delta_min[0] = delta - integral;
23935 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23936 +#endif
23937 +               /* advance time */
23938 +               sched_pc->norm_time += delta;
23939 +
23940 +               /* add tokens */
23941 +               sched_pc->tokens += tokens;
23942 +               sched_pc->token_time += tokens;
23943 +       } else
23944 +               delta_min[0] = delta;
23945 +
23946 +#ifdef CONFIG_VSERVER_IDLETIME
23947 +       if (!(flags & VXSF_IDLE_TIME))
23948 +               goto skip_idle;
23949 +
23950 +       /* how much was the idle skip? */
23951 +       delta = *idle_time - sched_pc->idle_time;
23952 +       vxd_check_range(delta, 0, INT_MAX);
23953 +
23954 +       if (delta >= sched_pc->interval[1]) {
23955 +               long tokens, integral;
23956 +
23957 +               /* calc fair share token part */
23958 +               tokens = delta / sched_pc->interval[1];
23959 +               integral = tokens * sched_pc->interval[1];
23960 +               tokens *= sched_pc->fill_rate[1];
23961 +               delta_min[1] = delta - integral;
23962 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23963 +
23964 +               /* advance idle time */
23965 +               sched_pc->idle_time += integral;
23966 +
23967 +               /* add tokens */
23968 +               sched_pc->tokens += tokens;
23969 +               sched_pc->token_time += tokens;
23970 +       } else
23971 +               delta_min[1] = delta;
23972 +skip_idle:
23973 +#endif
23974 +
23975 +       /* clip at maximum */
23976 +       if (sched_pc->tokens > sched_pc->tokens_max)
23977 +               sched_pc->tokens = sched_pc->tokens_max;
23978 +       tokens = sched_pc->tokens;
23979 +
23980 +       if ((flags & VXSF_ONHOLD)) {
23981 +               /* can we unhold? */
23982 +               if (tokens >= sched_pc->tokens_min) {
23983 +                       flags &= ~VXSF_ONHOLD;
23984 +                       sched_pc->hold_ticks +=
23985 +                               *norm_time - sched_pc->onhold;
23986 +               } else
23987 +                       goto on_hold;
23988 +       } else {
23989 +               /* put on hold? */
23990 +               if (tokens <= 0) {
23991 +                       flags |= VXSF_ONHOLD;
23992 +                       sched_pc->onhold = *norm_time;
23993 +                       goto on_hold;
23994 +               }
23995 +       }
23996 +       sched_pc->flags = flags;
23997 +       return tokens;
23998 +
23999 +on_hold:
24000 +       tokens = sched_pc->tokens_min - tokens;
24001 +       sched_pc->flags = flags;
24002 +       BUG_ON(tokens < 0);
24003 +
24004 +#ifdef CONFIG_VSERVER_HARDCPU
24005 +       /* next interval? */
24006 +       if (!sched_pc->fill_rate[0])
24007 +               delta_min[0] = HZ;
24008 +       else if (tokens > sched_pc->fill_rate[0])
24009 +               delta_min[0] += sched_pc->interval[0] *
24010 +                       tokens / sched_pc->fill_rate[0];
24011 +       else
24012 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24013 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24014 +
24015 +#ifdef CONFIG_VSERVER_IDLETIME
24016 +       if (!(flags & VXSF_IDLE_TIME))
24017 +               return -1;
24018 +
24019 +       /* next interval? */
24020 +       if (!sched_pc->fill_rate[1])
24021 +               delta_min[1] = HZ;
24022 +       else if (tokens > sched_pc->fill_rate[1])
24023 +               delta_min[1] += sched_pc->interval[1] *
24024 +                       tokens / sched_pc->fill_rate[1];
24025 +       else
24026 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24027 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24028 +
24029 +       return -2;
24030 +#else
24031 +       return -1;
24032 +#endif /* CONFIG_VSERVER_IDLETIME */
24033 +#else
24034 +       return 0;
24035 +#endif /* CONFIG_VSERVER_HARDCPU */
24036 +}
24037 +
24038 +static inline unsigned long msec_to_ticks(unsigned long msec)
24039 +{
24040 +       return msecs_to_jiffies(msec);
24041 +}
24042 +
24043 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24044 +{
24045 +       return jiffies_to_msecs(ticks);
24046 +}
24047 +
24048 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24049 +{
24050 +       return jiffies_to_usecs(ticks);
24051 +}
24052 +
24053 +
24054 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24055 +{
24056 +       unsigned int set_mask = data->mask;
24057 +       unsigned int update_mask;
24058 +       int i, cpu;
24059 +
24060 +       /* Sanity check data values */
24061 +       if (data->tokens_max <= 0)
24062 +               data->tokens_max = HZ;
24063 +       if (data->tokens_min < 0)
24064 +               data->tokens_min = HZ / 3;
24065 +       if (data->tokens_min >= data->tokens_max)
24066 +               data->tokens_min = data->tokens_max;
24067 +
24068 +       if (data->prio_bias > MAX_PRIO_BIAS)
24069 +               data->prio_bias = MAX_PRIO_BIAS;
24070 +       if (data->prio_bias < MIN_PRIO_BIAS)
24071 +               data->prio_bias = MIN_PRIO_BIAS;
24072 +
24073 +       spin_lock(&vxi->sched.tokens_lock);
24074 +
24075 +       /* sync up on delayed updates */
24076 +       for_each_cpu_mask(cpu, vxi->sched.update)
24077 +               vx_update_sched_param(&vxi->sched,
24078 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24079 +
24080 +       if (set_mask & VXSM_FILL_RATE)
24081 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24082 +       if (set_mask & VXSM_FILL_RATE2)
24083 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24084 +       if (set_mask & VXSM_INTERVAL)
24085 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24086 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24087 +       if (set_mask & VXSM_INTERVAL2)
24088 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24089 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24090 +       if (set_mask & VXSM_TOKENS)
24091 +               vxi->sched.tokens = data->tokens;
24092 +       if (set_mask & VXSM_TOKENS_MIN)
24093 +               vxi->sched.tokens_min = data->tokens_min;
24094 +       if (set_mask & VXSM_TOKENS_MAX)
24095 +               vxi->sched.tokens_max = data->tokens_max;
24096 +       if (set_mask & VXSM_PRIO_BIAS)
24097 +               vxi->sched.prio_bias = data->prio_bias;
24098 +
24099 +       /* Sanity check rate/interval */
24100 +       for (i = 0; i < 2; i++) {
24101 +               if (data->fill_rate[i] < 0)
24102 +                       data->fill_rate[i] = 0;
24103 +               if (data->interval[i] <= 0)
24104 +                       data->interval[i] = HZ;
24105 +       }
24106 +
24107 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24108 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24109 +       vxi->sched.update_mask = update_mask;
24110 +
24111 +#ifdef CONFIG_SMP
24112 +       rmb();
24113 +       if (set_mask & VXSM_CPU_ID) {
24114 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24115 +               cpus_and(vxi->sched.update, cpu_online_map,
24116 +                       vxi->sched.update);
24117 +       } else
24118 +               vxi->sched.update = cpu_online_map;
24119 +
24120 +       /* forced reload? */
24121 +       if (set_mask & VXSM_FORCE) {
24122 +               for_each_cpu_mask(cpu, vxi->sched.update)
24123 +                       vx_update_sched_param(&vxi->sched,
24124 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24125 +               vxi->sched.update = CPU_MASK_NONE;
24126 +       }
24127 +#else
24128 +       /* on UP we update immediately */
24129 +       vx_update_sched_param(&vxi->sched,
24130 +               &vx_per_cpu(vxi, sched_pc, 0));
24131 +#endif
24132 +
24133 +       spin_unlock(&vxi->sched.tokens_lock);
24134 +       return 0;
24135 +}
24136 +
24137 +
24138 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24139 +#define COPY_PRI(C) C(prio_bias)
24140 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24141 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24142 +                   C(fill_rate[1]); C(interval[1]);
24143 +
24144 +#define COPY_VALUE(name) vc_data.name = data->name
24145 +
24146 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24147 +{
24148 +       struct vcmd_sched_v5 vc_data;
24149 +
24150 +       vc_data.mask = data->set_mask;
24151 +       COPY_IDS(COPY_VALUE);
24152 +       COPY_PRI(COPY_VALUE);
24153 +       COPY_TOK(COPY_VALUE);
24154 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24155 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24156 +       return do_set_sched(vxi, &vc_data);
24157 +}
24158 +
24159 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24160 +{
24161 +       struct vcmd_set_sched_v4 vc_data;
24162 +
24163 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24164 +               return -EFAULT;
24165 +
24166 +       return do_set_sched_v4(vxi, &vc_data);
24167 +}
24168 +
24169 +       /* latest interface is v5 */
24170 +
24171 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24172 +{
24173 +       struct vcmd_sched_v5 vc_data;
24174 +
24175 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24176 +               return -EFAULT;
24177 +
24178 +       return do_set_sched(vxi, &vc_data);
24179 +}
24180 +
24181 +
24182 +#define COPY_PRI(C) C(prio_bias)
24183 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24184 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24185 +                   C(fill_rate[1]); C(interval[1]);
24186 +
24187 +#define COPY_VALUE(name) vc_data.name = data->name
24188 +
24189 +
24190 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24191 +{
24192 +       struct vcmd_sched_v5 vc_data;
24193 +
24194 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24195 +               return -EFAULT;
24196 +
24197 +       if (vc_data.mask & VXSM_CPU_ID) {
24198 +               int cpu = vc_data.cpu_id;
24199 +               struct _vx_sched_pc *data;
24200 +
24201 +               if (!cpu_possible(cpu))
24202 +                       return -EINVAL;
24203 +
24204 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24205 +               COPY_TOK(COPY_VALUE);
24206 +               COPY_PRI(COPY_VALUE);
24207 +               COPY_FRI(COPY_VALUE);
24208 +
24209 +               if (data->flags & VXSF_IDLE_TIME)
24210 +                       vc_data.mask |= VXSM_IDLE_TIME;
24211 +       } else {
24212 +               struct _vx_sched *data = &vxi->sched;
24213 +
24214 +               COPY_TOK(COPY_VALUE);
24215 +               COPY_PRI(COPY_VALUE);
24216 +               COPY_FRI(COPY_VALUE);
24217 +       }
24218 +
24219 +       if (vc_data.mask & VXSM_MSEC) {
24220 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24221 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24222 +       }
24223 +
24224 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24225 +               return -EFAULT;
24226 +       return 0;
24227 +}
24228 +
24229 +
24230 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24231 +{
24232 +       struct vcmd_sched_info vc_data;
24233 +       int cpu;
24234 +
24235 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24236 +               return -EFAULT;
24237 +
24238 +       cpu = vc_data.cpu_id;
24239 +       if (!cpu_possible(cpu))
24240 +               return -EINVAL;
24241 +
24242 +       if (vxi) {
24243 +               struct _vx_sched_pc *sched_pc =
24244 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24245 +
24246 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24247 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24248 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24249 +               vc_data.vavavoom = sched_pc->vavavoom;
24250 +       }
24251 +       vc_data.token_usec = ticks_to_usec(1);
24252 +
24253 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24254 +               return -EFAULT;
24255 +       return 0;
24256 +}
24257 +
24258 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/sched_init.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sched_init.h
24259 --- linux-2.6.27.14/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
24260 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sched_init.h    2008-10-13 14:54:20.000000000 +0200
24261 @@ -0,0 +1,50 @@
24262 +
24263 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24264 +{
24265 +       static struct lock_class_key tokens_lock_key;
24266 +
24267 +       /* scheduling; hard code starting values as constants */
24268 +       sched->fill_rate[0]     = 1;
24269 +       sched->interval[0]      = 4;
24270 +       sched->fill_rate[1]     = 1;
24271 +       sched->interval[1]      = 8;
24272 +       sched->tokens           = HZ >> 2;
24273 +       sched->tokens_min       = HZ >> 4;
24274 +       sched->tokens_max       = HZ >> 1;
24275 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24276 +       sched->prio_bias        = 0;
24277 +
24278 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24279 +}
24280 +
24281 +static inline
24282 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24283 +{
24284 +       sched_pc->fill_rate[0]  = 1;
24285 +       sched_pc->interval[0]   = 4;
24286 +       sched_pc->fill_rate[1]  = 1;
24287 +       sched_pc->interval[1]   = 8;
24288 +       sched_pc->tokens        = HZ >> 2;
24289 +       sched_pc->tokens_min    = HZ >> 4;
24290 +       sched_pc->tokens_max    = HZ >> 1;
24291 +       sched_pc->prio_bias     = 0;
24292 +       sched_pc->vavavoom      = 0;
24293 +       sched_pc->token_time    = 0;
24294 +       sched_pc->idle_time     = 0;
24295 +       sched_pc->norm_time     = jiffies;
24296 +
24297 +       sched_pc->user_ticks = 0;
24298 +       sched_pc->sys_ticks = 0;
24299 +       sched_pc->hold_ticks = 0;
24300 +}
24301 +
24302 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24303 +{
24304 +       return;
24305 +}
24306 +
24307 +static inline
24308 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24309 +{
24310 +       return;
24311 +}
24312 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/sched_proc.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sched_proc.h
24313 --- linux-2.6.27.14/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
24314 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sched_proc.h    2008-10-13 14:54:20.000000000 +0200
24315 @@ -0,0 +1,57 @@
24316 +#ifndef _VX_SCHED_PROC_H
24317 +#define _VX_SCHED_PROC_H
24318 +
24319 +
24320 +static inline
24321 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24322 +{
24323 +       int length = 0;
24324 +
24325 +       length += sprintf(buffer,
24326 +               "FillRate:\t%8d,%d\n"
24327 +               "Interval:\t%8d,%d\n"
24328 +               "TokensMin:\t%8d\n"
24329 +               "TokensMax:\t%8d\n"
24330 +               "PrioBias:\t%8d\n",
24331 +               sched->fill_rate[0],
24332 +               sched->fill_rate[1],
24333 +               sched->interval[0],
24334 +               sched->interval[1],
24335 +               sched->tokens_min,
24336 +               sched->tokens_max,
24337 +               sched->prio_bias);
24338 +       return length;
24339 +}
24340 +
24341 +static inline
24342 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24343 +       char *buffer, int cpu)
24344 +{
24345 +       int length = 0;
24346 +
24347 +       length += sprintf(buffer + length,
24348 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24349 +               (unsigned long long)sched_pc->user_ticks,
24350 +               (unsigned long long)sched_pc->sys_ticks,
24351 +               (unsigned long long)sched_pc->hold_ticks,
24352 +               sched_pc->token_time,
24353 +               sched_pc->idle_time);
24354 +       length += sprintf(buffer + length,
24355 +               " %c%c %d %d %d %d/%d %d/%d",
24356 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24357 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24358 +               sched_pc->tokens,
24359 +               sched_pc->tokens_min,
24360 +               sched_pc->tokens_max,
24361 +               sched_pc->fill_rate[0],
24362 +               sched_pc->interval[0],
24363 +               sched_pc->fill_rate[1],
24364 +               sched_pc->interval[1]);
24365 +       length += sprintf(buffer + length,
24366 +               " %d %d\n",
24367 +               sched_pc->prio_bias,
24368 +               sched_pc->vavavoom);
24369 +       return length;
24370 +}
24371 +
24372 +#endif /* _VX_SCHED_PROC_H */
24373 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/signal.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/signal.c
24374 --- linux-2.6.27.14/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
24375 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/signal.c        2008-10-13 14:54:20.000000000 +0200
24376 @@ -0,0 +1,132 @@
24377 +/*
24378 + *  linux/kernel/vserver/signal.c
24379 + *
24380 + *  Virtual Server: Signal Support
24381 + *
24382 + *  Copyright (C) 2003-2007  Herbert Pötzl
24383 + *
24384 + *  V0.01  broken out from vcontext V0.05
24385 + *  V0.02  changed vcmds to vxi arg
24386 + *  V0.03  adjusted siginfo for kill
24387 + *
24388 + */
24389 +
24390 +#include <asm/uaccess.h>
24391 +
24392 +#include <linux/vs_context.h>
24393 +#include <linux/vs_pid.h>
24394 +#include <linux/vserver/signal_cmd.h>
24395 +
24396 +
24397 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24398 +{
24399 +       int retval, count = 0;
24400 +       struct task_struct *p;
24401 +       struct siginfo *sip = SEND_SIG_PRIV;
24402 +
24403 +       retval = -ESRCH;
24404 +       vxdprintk(VXD_CBIT(misc, 4),
24405 +               "vx_info_kill(%p[#%d],%d,%d)*",
24406 +               vxi, vxi->vx_id, pid, sig);
24407 +       read_lock(&tasklist_lock);
24408 +       switch (pid) {
24409 +       case  0:
24410 +       case -1:
24411 +               for_each_process(p) {
24412 +                       int err = 0;
24413 +
24414 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24415 +                               (pid && vxi->vx_initpid == p->pid))
24416 +                               continue;
24417 +
24418 +                       err = group_send_sig_info(sig, sip, p);
24419 +                       ++count;
24420 +                       if (err != -EPERM)
24421 +                               retval = err;
24422 +               }
24423 +               break;
24424 +
24425 +       case 1:
24426 +               if (vxi->vx_initpid) {
24427 +                       pid = vxi->vx_initpid;
24428 +                       /* for now, only SIGINT to private init ... */
24429 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24430 +                               /* ... as long as there are tasks left */
24431 +                               (atomic_read(&vxi->vx_tasks) > 1))
24432 +                               sig = SIGINT;
24433 +               }
24434 +               /* fallthrough */
24435 +       default:
24436 +               p = find_task_by_real_pid(pid);
24437 +               if (p) {
24438 +                       if (vx_task_xid(p) == vxi->vx_id)
24439 +                               retval = group_send_sig_info(sig, sip, p);
24440 +               }
24441 +               break;
24442 +       }
24443 +       read_unlock(&tasklist_lock);
24444 +       vxdprintk(VXD_CBIT(misc, 4),
24445 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24446 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24447 +       return retval;
24448 +}
24449 +
24450 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24451 +{
24452 +       struct vcmd_ctx_kill_v0 vc_data;
24453 +
24454 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24455 +               return -EFAULT;
24456 +
24457 +       /* special check to allow guest shutdown */
24458 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24459 +               /* forbid killall pid=0 when init is present */
24460 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24461 +               (vc_data.pid > 1)))
24462 +               return -EACCES;
24463 +
24464 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24465 +}
24466 +
24467 +
24468 +static int __wait_exit(struct vx_info *vxi)
24469 +{
24470 +       DECLARE_WAITQUEUE(wait, current);
24471 +       int ret = 0;
24472 +
24473 +       add_wait_queue(&vxi->vx_wait, &wait);
24474 +       set_current_state(TASK_INTERRUPTIBLE);
24475 +
24476 +wait:
24477 +       if (vx_info_state(vxi,
24478 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24479 +               goto out;
24480 +       if (signal_pending(current)) {
24481 +               ret = -ERESTARTSYS;
24482 +               goto out;
24483 +       }
24484 +       schedule();
24485 +       goto wait;
24486 +
24487 +out:
24488 +       set_current_state(TASK_RUNNING);
24489 +       remove_wait_queue(&vxi->vx_wait, &wait);
24490 +       return ret;
24491 +}
24492 +
24493 +
24494 +
24495 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24496 +{
24497 +       struct vcmd_wait_exit_v0 vc_data;
24498 +       int ret;
24499 +
24500 +       ret = __wait_exit(vxi);
24501 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24502 +       vc_data.exit_code = vxi->exit_code;
24503 +
24504 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24505 +               ret = -EFAULT;
24506 +       return ret;
24507 +}
24508 +
24509 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/space.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/space.c
24510 --- linux-2.6.27.14/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
24511 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/space.c 2008-10-31 18:15:28.000000000 +0100
24512 @@ -0,0 +1,398 @@
24513 +/*
24514 + *  linux/kernel/vserver/space.c
24515 + *
24516 + *  Virtual Server: Context Space Support
24517 + *
24518 + *  Copyright (C) 2003-2007  Herbert Pötzl
24519 + *
24520 + *  V0.01  broken out from context.c 0.07
24521 + *  V0.02  added task locking for namespace
24522 + *  V0.03  broken out vx_enter_namespace
24523 + *  V0.04  added *space support and commands
24524 + *
24525 + */
24526 +
24527 +#include <linux/utsname.h>
24528 +#include <linux/nsproxy.h>
24529 +#include <linux/err.h>
24530 +#include <asm/uaccess.h>
24531 +
24532 +#include <linux/vs_context.h>
24533 +#include <linux/vserver/space.h>
24534 +#include <linux/vserver/space_cmd.h>
24535 +
24536 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24537 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24538 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24539 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24540 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24541 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24542 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24543 +
24544 +
24545 +/* namespace functions */
24546 +
24547 +#include <linux/mnt_namespace.h>
24548 +#include <linux/user_namespace.h>
24549 +#include <linux/pid_namespace.h>
24550 +#include <linux/ipc_namespace.h>
24551 +#include <net/net_namespace.h>
24552 +
24553 +
24554 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24555 +       .mask = CLONE_FS |
24556 +               CLONE_NEWNS |
24557 +               CLONE_NEWUTS |
24558 +               CLONE_NEWIPC |
24559 +               CLONE_NEWUSER |
24560 +               0
24561 +};
24562 +
24563 +static const struct vcmd_space_mask_v1 space_mask = {
24564 +       .mask = CLONE_FS |
24565 +               CLONE_NEWNS |
24566 +               CLONE_NEWUTS |
24567 +               CLONE_NEWIPC |
24568 +               CLONE_NEWUSER |
24569 +#ifdef CONFIG_PID_NS
24570 +               CLONE_NEWPID |
24571 +#endif
24572 +#ifdef CONFIG_NET_NS
24573 +               CLONE_NEWNET |
24574 +#endif
24575 +               0
24576 +};
24577 +
24578 +static const struct vcmd_space_mask_v1 default_space_mask = {
24579 +       .mask = CLONE_FS |
24580 +               CLONE_NEWNS |
24581 +               CLONE_NEWUTS |
24582 +               CLONE_NEWIPC |
24583 +               CLONE_NEWUSER |
24584 +#ifdef CONFIG_PID_NS
24585 +//             CLONE_NEWPID |
24586 +#endif
24587 +               0
24588 +};
24589 +
24590 +/*
24591 + *     build a new nsproxy mix
24592 + *      assumes that both proxies are 'const'
24593 + *     does not touch nsproxy refcounts
24594 + *     will hold a reference on the result.
24595 + */
24596 +
24597 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24598 +       struct nsproxy *new_nsproxy, unsigned long mask)
24599 +{
24600 +       struct mnt_namespace *old_ns;
24601 +       struct uts_namespace *old_uts;
24602 +       struct ipc_namespace *old_ipc;
24603 +       struct user_namespace *old_user;
24604 +#ifdef CONFIG_PID_NS
24605 +       struct pid_namespace *old_pid;
24606 +#endif
24607 +#ifdef CONFIG_NET_NS
24608 +       struct net *old_net;
24609 +#endif
24610 +       struct nsproxy *nsproxy;
24611 +
24612 +       nsproxy = copy_nsproxy(old_nsproxy);
24613 +       if (!nsproxy)
24614 +               goto out;
24615 +
24616 +       if (mask & CLONE_NEWNS) {
24617 +               old_ns = nsproxy->mnt_ns;
24618 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24619 +               if (nsproxy->mnt_ns)
24620 +                       get_mnt_ns(nsproxy->mnt_ns);
24621 +       } else
24622 +               old_ns = NULL;
24623 +
24624 +       if (mask & CLONE_NEWUTS) {
24625 +               old_uts = nsproxy->uts_ns;
24626 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24627 +               if (nsproxy->uts_ns)
24628 +                       get_uts_ns(nsproxy->uts_ns);
24629 +       } else
24630 +               old_uts = NULL;
24631 +
24632 +       if (mask & CLONE_NEWIPC) {
24633 +               old_ipc = nsproxy->ipc_ns;
24634 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24635 +               if (nsproxy->ipc_ns)
24636 +                       get_ipc_ns(nsproxy->ipc_ns);
24637 +       } else
24638 +               old_ipc = NULL;
24639 +
24640 +       if (mask & CLONE_NEWUSER) {
24641 +               old_user = nsproxy->user_ns;
24642 +               nsproxy->user_ns = new_nsproxy->user_ns;
24643 +               if (nsproxy->user_ns)
24644 +                       get_user_ns(nsproxy->user_ns);
24645 +       } else
24646 +               old_user = NULL;
24647 +
24648 +#ifdef CONFIG_PID_NS
24649 +       if (mask & CLONE_NEWPID) {
24650 +               old_pid = nsproxy->pid_ns;
24651 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24652 +               if (nsproxy->pid_ns)
24653 +                       get_pid_ns(nsproxy->pid_ns);
24654 +       } else
24655 +               old_pid = NULL;
24656 +#endif
24657 +#ifdef CONFIG_NET_NS
24658 +       if (mask & CLONE_NEWNET) {
24659 +               old_net = nsproxy->net_ns;
24660 +               nsproxy->net_ns = new_nsproxy->net_ns;
24661 +               if (nsproxy->net_ns)
24662 +                       get_net(nsproxy->net_ns);
24663 +       } else
24664 +               old_net = NULL;
24665 +#endif
24666 +       if (old_ns)
24667 +               put_mnt_ns(old_ns);
24668 +       if (old_uts)
24669 +               put_uts_ns(old_uts);
24670 +       if (old_ipc)
24671 +               put_ipc_ns(old_ipc);
24672 +       if (old_user)
24673 +               put_user_ns(old_user);
24674 +#ifdef CONFIG_PID_NS
24675 +       if (old_pid)
24676 +               put_pid_ns(old_pid);
24677 +#endif
24678 +#ifdef CONFIG_NET_NS
24679 +       if (old_net)
24680 +               put_net(old_net);
24681 +#endif
24682 +out:
24683 +       return nsproxy;
24684 +}
24685 +
24686 +
24687 +/*
24688 + *     merge two nsproxy structs into a new one.
24689 + *     will hold a reference on the result.
24690 + */
24691 +
24692 +static inline
24693 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24694 +       struct nsproxy *proxy, unsigned long mask)
24695 +{
24696 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24697 +
24698 +       if (!proxy)
24699 +               return NULL;
24700 +
24701 +       if (mask) {
24702 +               /* vs_mix_nsproxy returns with reference */
24703 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24704 +                       proxy, mask);
24705 +       }
24706 +       get_nsproxy(proxy);
24707 +       return proxy;
24708 +}
24709 +
24710 +/*
24711 + *     merge two fs structs into a new one.
24712 + *     will take a reference on the result.
24713 + */
24714 +
24715 +static inline
24716 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24717 +       struct fs_struct *fs, unsigned long mask)
24718 +{
24719 +       if (!(mask & CLONE_FS)) {
24720 +               if (old)
24721 +                       atomic_inc(&old->count);
24722 +               return old;
24723 +       }
24724 +
24725 +       if (!fs)
24726 +               return NULL;
24727 +
24728 +       return copy_fs_struct(fs);
24729 +}
24730 +
24731 +
24732 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24733 +{
24734 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24735 +       struct fs_struct *fs, *fs_cur, *fs_new;
24736 +       int ret;
24737 +
24738 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24739 +               vxi, vxi->vx_id, mask, index);
24740 +
24741 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24742 +               return -EACCES;
24743 +
24744 +       if (!mask)
24745 +               mask = vxi->vx_nsmask[index];
24746 +
24747 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24748 +               return -EINVAL;
24749 +
24750 +       proxy = vxi->vx_nsproxy[index];
24751 +       fs = vxi->vx_fs[index];
24752 +
24753 +       task_lock(current);
24754 +       fs_cur = current->fs;
24755 +       atomic_inc(&fs_cur->count);
24756 +       proxy_cur = current->nsproxy;
24757 +       get_nsproxy(proxy_cur);
24758 +       task_unlock(current);
24759 +
24760 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24761 +       if (IS_ERR(fs_new)) {
24762 +               ret = PTR_ERR(fs_new);
24763 +               goto out_put;
24764 +       }
24765 +
24766 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24767 +       if (IS_ERR(proxy_new)) {
24768 +               ret = PTR_ERR(proxy_new);
24769 +               goto out_put_fs;
24770 +       }
24771 +
24772 +       fs_new = xchg(&current->fs, fs_new);
24773 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24774 +       ret = 0;
24775 +
24776 +       if (proxy_new)
24777 +               put_nsproxy(proxy_new);
24778 +out_put_fs:
24779 +       if (fs_new)
24780 +               put_fs_struct(fs_new);
24781 +out_put:
24782 +       if (proxy_cur)
24783 +               put_nsproxy(proxy_cur);
24784 +       if (fs_cur)
24785 +               put_fs_struct(fs_cur);
24786 +       return ret;
24787 +}
24788 +
24789 +
24790 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24791 +{
24792 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24793 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24794 +       int ret;
24795 +
24796 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24797 +               vxi, vxi->vx_id, mask, index);
24798 +#if 0
24799 +       if (!mask)
24800 +               mask = default_space_mask.mask;
24801 +#endif
24802 +       if ((mask & space_mask.mask) != mask)
24803 +               return -EINVAL;
24804 +
24805 +       proxy_vxi = vxi->vx_nsproxy[index];
24806 +       fs_vxi = vxi->vx_fs[index];
24807 +
24808 +       task_lock(current);
24809 +       fs_cur = current->fs;
24810 +       atomic_inc(&fs_cur->count);
24811 +       proxy_cur = current->nsproxy;
24812 +       get_nsproxy(proxy_cur);
24813 +       task_unlock(current);
24814 +
24815 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24816 +       if (IS_ERR(fs_new)) {
24817 +               ret = PTR_ERR(fs_new);
24818 +               goto out_put;
24819 +       }
24820 +
24821 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24822 +       if (IS_ERR(proxy_new)) {
24823 +               ret = PTR_ERR(proxy_new);
24824 +               goto out_put_fs;
24825 +       }
24826 +
24827 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24828 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24829 +       vxi->vx_nsmask[index] |= mask;
24830 +       ret = 0;
24831 +
24832 +       if (proxy_new)
24833 +               put_nsproxy(proxy_new);
24834 +out_put_fs:
24835 +       if (fs_new)
24836 +               put_fs_struct(fs_new);
24837 +out_put:
24838 +       if (proxy_cur)
24839 +               put_nsproxy(proxy_cur);
24840 +       if (fs_cur)
24841 +               put_fs_struct(fs_cur);
24842 +       return ret;
24843 +}
24844 +
24845 +
24846 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24847 +{
24848 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24849 +
24850 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24851 +               return -EFAULT;
24852 +
24853 +       return vx_enter_space(vxi, vc_data.mask, 0);
24854 +}
24855 +
24856 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24857 +{
24858 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24859 +
24860 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24861 +               return -EFAULT;
24862 +
24863 +       if (vc_data.index >= VX_SPACES)
24864 +               return -EINVAL;
24865 +
24866 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24867 +}
24868 +
24869 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24870 +{
24871 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24872 +
24873 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24874 +               return -EFAULT;
24875 +
24876 +       return vx_set_space(vxi, vc_data.mask, 0);
24877 +}
24878 +
24879 +int vc_set_space(struct vx_info *vxi, void __user *data)
24880 +{
24881 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24882 +
24883 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24884 +               return -EFAULT;
24885 +
24886 +       if (vc_data.index >= VX_SPACES)
24887 +               return -EINVAL;
24888 +
24889 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24890 +}
24891 +
24892 +int vc_get_space_mask(void __user *data, int type)
24893 +{
24894 +       const struct vcmd_space_mask_v1 *mask;
24895 +
24896 +       if (type == 0)
24897 +               mask = &space_mask_v0;
24898 +       else if (type == 1)
24899 +               mask = &space_mask;
24900 +       else
24901 +               mask = &default_space_mask;
24902 +
24903 +       vxdprintk(VXD_CBIT(space, 10),
24904 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24905 +
24906 +       if (copy_to_user(data, mask, sizeof(*mask)))
24907 +               return -EFAULT;
24908 +       return 0;
24909 +}
24910 +
24911 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/switch.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/switch.c
24912 --- linux-2.6.27.14/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
24913 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/switch.c        2008-10-31 04:42:36.000000000 +0100
24914 @@ -0,0 +1,543 @@
24915 +/*
24916 + *  linux/kernel/vserver/switch.c
24917 + *
24918 + *  Virtual Server: Syscall Switch
24919 + *
24920 + *  Copyright (C) 2003-2007  Herbert Pötzl
24921 + *
24922 + *  V0.01  syscall switch
24923 + *  V0.02  added signal to context
24924 + *  V0.03  added rlimit functions
24925 + *  V0.04  added iattr, task/xid functions
24926 + *  V0.05  added debug/history stuff
24927 + *  V0.06  added compat32 layer
24928 + *  V0.07  vcmd args and perms
24929 + *  V0.08  added status commands
24930 + *  V0.09  added tag commands
24931 + *  V0.10  added oom bias
24932 + *  V0.11  added device commands
24933 + *
24934 + */
24935 +
24936 +#include <linux/vs_context.h>
24937 +#include <linux/vs_network.h>
24938 +#include <linux/vserver/switch.h>
24939 +
24940 +#include "vci_config.h"
24941 +
24942 +
24943 +static inline
24944 +int vc_get_version(uint32_t id)
24945 +{
24946 +       return VCI_VERSION;
24947 +}
24948 +
24949 +static inline
24950 +int vc_get_vci(uint32_t id)
24951 +{
24952 +       return vci_kernel_config();
24953 +}
24954 +
24955 +#include <linux/vserver/context_cmd.h>
24956 +#include <linux/vserver/cvirt_cmd.h>
24957 +#include <linux/vserver/cacct_cmd.h>
24958 +#include <linux/vserver/limit_cmd.h>
24959 +#include <linux/vserver/network_cmd.h>
24960 +#include <linux/vserver/sched_cmd.h>
24961 +#include <linux/vserver/debug_cmd.h>
24962 +#include <linux/vserver/inode_cmd.h>
24963 +#include <linux/vserver/dlimit_cmd.h>
24964 +#include <linux/vserver/signal_cmd.h>
24965 +#include <linux/vserver/space_cmd.h>
24966 +#include <linux/vserver/tag_cmd.h>
24967 +#include <linux/vserver/device_cmd.h>
24968 +
24969 +#include <linux/vserver/inode.h>
24970 +#include <linux/vserver/dlimit.h>
24971 +
24972 +
24973 +#ifdef CONFIG_COMPAT
24974 +#define __COMPAT(name, id, data, compat)       \
24975 +       (compat) ? name ## _x32(id, data) : name(id, data)
24976 +#define __COMPAT_NO_ID(name, data, compat)     \
24977 +       (compat) ? name ## _x32(data) : name(data)
24978 +#else
24979 +#define __COMPAT(name, id, data, compat)       \
24980 +       name(id, data)
24981 +#define __COMPAT_NO_ID(name, data, compat)     \
24982 +       name(data)
24983 +#endif
24984 +
24985 +
24986 +static inline
24987 +long do_vcmd(uint32_t cmd, uint32_t id,
24988 +       struct vx_info *vxi, struct nx_info *nxi,
24989 +       void __user *data, int compat)
24990 +{
24991 +       switch (cmd) {
24992 +
24993 +       case VCMD_get_version:
24994 +               return vc_get_version(id);
24995 +       case VCMD_get_vci:
24996 +               return vc_get_vci(id);
24997 +
24998 +       case VCMD_task_xid:
24999 +               return vc_task_xid(id);
25000 +       case VCMD_vx_info:
25001 +               return vc_vx_info(vxi, data);
25002 +
25003 +       case VCMD_task_nid:
25004 +               return vc_task_nid(id);
25005 +       case VCMD_nx_info:
25006 +               return vc_nx_info(nxi, data);
25007 +
25008 +       case VCMD_task_tag:
25009 +               return vc_task_tag(id);
25010 +
25011 +       case VCMD_set_space_v1:
25012 +               return vc_set_space_v1(vxi, data);
25013 +       /* this is version 2 */
25014 +       case VCMD_set_space:
25015 +               return vc_set_space(vxi, data);
25016 +
25017 +       case VCMD_get_space_mask_v0:
25018 +               return vc_get_space_mask(data, 0);
25019 +       /* this is version 1 */
25020 +       case VCMD_get_space_mask:
25021 +               return vc_get_space_mask(data, 1);
25022 +
25023 +       case VCMD_get_space_default:
25024 +               return vc_get_space_mask(data, -1);
25025 +
25026 +#ifdef CONFIG_IA32_EMULATION
25027 +       case VCMD_get_rlimit:
25028 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25029 +       case VCMD_set_rlimit:
25030 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25031 +#else
25032 +       case VCMD_get_rlimit:
25033 +               return vc_get_rlimit(vxi, data);
25034 +       case VCMD_set_rlimit:
25035 +               return vc_set_rlimit(vxi, data);
25036 +#endif
25037 +       case VCMD_get_rlimit_mask:
25038 +               return vc_get_rlimit_mask(id, data);
25039 +       case VCMD_reset_minmax:
25040 +               return vc_reset_minmax(vxi, data);
25041 +
25042 +       case VCMD_get_vhi_name:
25043 +               return vc_get_vhi_name(vxi, data);
25044 +       case VCMD_set_vhi_name:
25045 +               return vc_set_vhi_name(vxi, data);
25046 +
25047 +       case VCMD_ctx_stat:
25048 +               return vc_ctx_stat(vxi, data);
25049 +       case VCMD_virt_stat:
25050 +               return vc_virt_stat(vxi, data);
25051 +       case VCMD_sock_stat:
25052 +               return vc_sock_stat(vxi, data);
25053 +       case VCMD_rlimit_stat:
25054 +               return vc_rlimit_stat(vxi, data);
25055 +
25056 +       case VCMD_set_cflags:
25057 +               return vc_set_cflags(vxi, data);
25058 +       case VCMD_get_cflags:
25059 +               return vc_get_cflags(vxi, data);
25060 +
25061 +       /* this is version 1 */
25062 +       case VCMD_set_ccaps:
25063 +               return vc_set_ccaps(vxi, data);
25064 +       /* this is version 1 */
25065 +       case VCMD_get_ccaps:
25066 +               return vc_get_ccaps(vxi, data);
25067 +       case VCMD_set_bcaps:
25068 +               return vc_set_bcaps(vxi, data);
25069 +       case VCMD_get_bcaps:
25070 +               return vc_get_bcaps(vxi, data);
25071 +
25072 +       case VCMD_set_badness:
25073 +               return vc_set_badness(vxi, data);
25074 +       case VCMD_get_badness:
25075 +               return vc_get_badness(vxi, data);
25076 +
25077 +       case VCMD_set_nflags:
25078 +               return vc_set_nflags(nxi, data);
25079 +       case VCMD_get_nflags:
25080 +               return vc_get_nflags(nxi, data);
25081 +
25082 +       case VCMD_set_ncaps:
25083 +               return vc_set_ncaps(nxi, data);
25084 +       case VCMD_get_ncaps:
25085 +               return vc_get_ncaps(nxi, data);
25086 +
25087 +       case VCMD_set_sched_v4:
25088 +               return vc_set_sched_v4(vxi, data);
25089 +       /* this is version 5 */
25090 +       case VCMD_set_sched:
25091 +               return vc_set_sched(vxi, data);
25092 +       case VCMD_get_sched:
25093 +               return vc_get_sched(vxi, data);
25094 +       case VCMD_sched_info:
25095 +               return vc_sched_info(vxi, data);
25096 +
25097 +       case VCMD_add_dlimit:
25098 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25099 +       case VCMD_rem_dlimit:
25100 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25101 +       case VCMD_set_dlimit:
25102 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25103 +       case VCMD_get_dlimit:
25104 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25105 +
25106 +       case VCMD_ctx_kill:
25107 +               return vc_ctx_kill(vxi, data);
25108 +
25109 +       case VCMD_wait_exit:
25110 +               return vc_wait_exit(vxi, data);
25111 +
25112 +       case VCMD_get_iattr:
25113 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25114 +       case VCMD_set_iattr:
25115 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25116 +
25117 +       case VCMD_fget_iattr:
25118 +               return vc_fget_iattr(id, data);
25119 +       case VCMD_fset_iattr:
25120 +               return vc_fset_iattr(id, data);
25121 +
25122 +       case VCMD_enter_space_v0:
25123 +               return vc_enter_space_v1(vxi, NULL);
25124 +       case VCMD_enter_space_v1:
25125 +               return vc_enter_space_v1(vxi, data);
25126 +       /* this is version 2 */
25127 +       case VCMD_enter_space:
25128 +               return vc_enter_space(vxi, data);
25129 +
25130 +       case VCMD_ctx_create_v0:
25131 +               return vc_ctx_create(id, NULL);
25132 +       case VCMD_ctx_create:
25133 +               return vc_ctx_create(id, data);
25134 +       case VCMD_ctx_migrate_v0:
25135 +               return vc_ctx_migrate(vxi, NULL);
25136 +       case VCMD_ctx_migrate:
25137 +               return vc_ctx_migrate(vxi, data);
25138 +
25139 +       case VCMD_net_create_v0:
25140 +               return vc_net_create(id, NULL);
25141 +       case VCMD_net_create:
25142 +               return vc_net_create(id, data);
25143 +       case VCMD_net_migrate:
25144 +               return vc_net_migrate(nxi, data);
25145 +
25146 +       case VCMD_tag_migrate:
25147 +               return vc_tag_migrate(id);
25148 +
25149 +       case VCMD_net_add:
25150 +               return vc_net_add(nxi, data);
25151 +       case VCMD_net_remove:
25152 +               return vc_net_remove(nxi, data);
25153 +
25154 +       case VCMD_net_add_ipv4:
25155 +               return vc_net_add_ipv4(nxi, data);
25156 +       case VCMD_net_remove_ipv4:
25157 +               return vc_net_remove_ipv4(nxi, data);
25158 +#ifdef CONFIG_IPV6
25159 +       case VCMD_net_add_ipv6:
25160 +               return vc_net_add_ipv6(nxi, data);
25161 +       case VCMD_net_remove_ipv6:
25162 +               return vc_net_remove_ipv6(nxi, data);
25163 +#endif
25164 +/*     case VCMD_add_match_ipv4:
25165 +               return vc_add_match_ipv4(nxi, data);
25166 +       case VCMD_get_match_ipv4:
25167 +               return vc_get_match_ipv4(nxi, data);
25168 +#ifdef CONFIG_IPV6
25169 +       case VCMD_add_match_ipv6:
25170 +               return vc_add_match_ipv6(nxi, data);
25171 +       case VCMD_get_match_ipv6:
25172 +               return vc_get_match_ipv6(nxi, data);
25173 +#endif */
25174 +
25175 +#ifdef CONFIG_VSERVER_DEVICE
25176 +       case VCMD_set_mapping:
25177 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25178 +       case VCMD_unset_mapping:
25179 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25180 +#endif
25181 +#ifdef CONFIG_VSERVER_HISTORY
25182 +       case VCMD_dump_history:
25183 +               return vc_dump_history(id);
25184 +       case VCMD_read_history:
25185 +               return __COMPAT(vc_read_history, id, data, compat);
25186 +#endif
25187 +#ifdef CONFIG_VSERVER_MONITOR
25188 +       case VCMD_read_monitor:
25189 +               return __COMPAT(vc_read_monitor, id, data, compat);
25190 +#endif
25191 +       default:
25192 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25193 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25194 +       }
25195 +       return -ENOSYS;
25196 +}
25197 +
25198 +
25199 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25200 +       case VCMD_ ## vcmd: perm = _perm;               \
25201 +               args = _args; flags = _flags; break
25202 +
25203 +
25204 +#define VCA_NONE       0x00
25205 +#define VCA_VXI                0x01
25206 +#define VCA_NXI                0x02
25207 +
25208 +#define VCF_NONE       0x00
25209 +#define VCF_INFO       0x01
25210 +#define VCF_ADMIN      0x02
25211 +#define VCF_ARES       0x06    /* includes admin */
25212 +#define VCF_SETUP      0x08
25213 +
25214 +#define VCF_ZIDOK      0x10    /* zero id okay */
25215 +
25216 +
25217 +static inline
25218 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25219 +{
25220 +       long ret;
25221 +       int permit = -1, state = 0;
25222 +       int perm = -1, args = 0, flags = 0;
25223 +       struct vx_info *vxi = NULL;
25224 +       struct nx_info *nxi = NULL;
25225 +
25226 +       switch (cmd) {
25227 +       /* unpriviledged commands */
25228 +       __VCMD(get_version,      0, VCA_NONE,   0);
25229 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25230 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25231 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25232 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25233 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25234 +
25235 +       /* info commands */
25236 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25237 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25238 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25239 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25240 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25241 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25242 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25243 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25244 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25245 +
25246 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25247 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25248 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25249 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25250 +
25251 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25252 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25253 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25254 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25255 +
25256 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25257 +
25258 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25259 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25260 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25261 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25262 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25263 +
25264 +       /* lower admin commands */
25265 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25266 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25267 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25268 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25269 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25270 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25271 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25272 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25273 +
25274 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25275 +       __VCMD(net_create,       5, VCA_NONE,   0);
25276 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25277 +
25278 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25279 +
25280 +       /* higher admin commands */
25281 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25282 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25283 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25284 +
25285 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25286 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25287 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25288 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25289 +
25290 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25291 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25292 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25293 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25294 +
25295 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25296 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25297 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25298 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25299 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25300 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25301 +#ifdef CONFIG_IPV6
25302 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25303 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25304 +#endif
25305 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25306 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25307 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25308 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25309 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25310 +
25311 +#ifdef CONFIG_VSERVER_DEVICE
25312 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25313 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25314 +#endif
25315 +       /* debug level admin commands */
25316 +#ifdef CONFIG_VSERVER_HISTORY
25317 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25318 +       __VCMD(read_history,     9, VCA_NONE,   0);
25319 +#endif
25320 +#ifdef CONFIG_VSERVER_MONITOR
25321 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25322 +#endif
25323 +
25324 +       default:
25325 +               perm = -1;
25326 +       }
25327 +
25328 +       vxdprintk(VXD_CBIT(switch, 0),
25329 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25330 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25331 +               VC_VERSION(cmd), id, data, compat,
25332 +               perm, args, flags);
25333 +
25334 +       ret = -ENOSYS;
25335 +       if (perm < 0)
25336 +               goto out;
25337 +
25338 +       state = 1;
25339 +       if (!capable(CAP_CONTEXT))
25340 +               goto out;
25341 +
25342 +       state = 2;
25343 +       /* moved here from the individual commands */
25344 +       ret = -EPERM;
25345 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25346 +               goto out;
25347 +
25348 +       state = 3;
25349 +       /* vcmd involves resource management  */
25350 +       ret = -EPERM;
25351 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25352 +               goto out;
25353 +
25354 +       state = 4;
25355 +       /* various legacy exceptions */
25356 +       switch (cmd) {
25357 +       /* will go away when spectator is a cap */
25358 +       case VCMD_ctx_migrate_v0:
25359 +       case VCMD_ctx_migrate:
25360 +               if (id == 1) {
25361 +                       current->xid = 1;
25362 +                       ret = 1;
25363 +                       goto out;
25364 +               }
25365 +               break;
25366 +
25367 +       /* will go away when spectator is a cap */
25368 +       case VCMD_net_migrate:
25369 +               if (id == 1) {
25370 +                       current->nid = 1;
25371 +                       ret = 1;
25372 +                       goto out;
25373 +               }
25374 +               break;
25375 +       }
25376 +
25377 +       /* vcmds are fine by default */
25378 +       permit = 1;
25379 +
25380 +       /* admin type vcmds require admin ... */
25381 +       if (flags & VCF_ADMIN)
25382 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25383 +
25384 +       /* ... but setup type vcmds override that */
25385 +       if (!permit && (flags & VCF_SETUP))
25386 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25387 +
25388 +       state = 5;
25389 +       ret = -EPERM;
25390 +       if (!permit)
25391 +               goto out;
25392 +
25393 +       state = 6;
25394 +       if (!id && (flags & VCF_ZIDOK))
25395 +               goto skip_id;
25396 +
25397 +       ret = -ESRCH;
25398 +       if (args & VCA_VXI) {
25399 +               vxi = lookup_vx_info(id);
25400 +               if (!vxi)
25401 +                       goto out;
25402 +
25403 +               if ((flags & VCF_ADMIN) &&
25404 +                       /* special case kill for shutdown */
25405 +                       (cmd != VCMD_ctx_kill) &&
25406 +                       /* can context be administrated? */
25407 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25408 +                       ret = -EACCES;
25409 +                       goto out_vxi;
25410 +               }
25411 +       }
25412 +       state = 7;
25413 +       if (args & VCA_NXI) {
25414 +               nxi = lookup_nx_info(id);
25415 +               if (!nxi)
25416 +                       goto out_vxi;
25417 +
25418 +               if ((flags & VCF_ADMIN) &&
25419 +                       /* can context be administrated? */
25420 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25421 +                       ret = -EACCES;
25422 +                       goto out_nxi;
25423 +               }
25424 +       }
25425 +skip_id:
25426 +       state = 8;
25427 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25428 +
25429 +out_nxi:
25430 +       if ((args & VCA_NXI) && nxi)
25431 +               put_nx_info(nxi);
25432 +out_vxi:
25433 +       if ((args & VCA_VXI) && vxi)
25434 +               put_vx_info(vxi);
25435 +out:
25436 +       vxdprintk(VXD_CBIT(switch, 1),
25437 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25438 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25439 +               VC_VERSION(cmd), ret, ret, state, permit);
25440 +       return ret;
25441 +}
25442 +
25443 +asmlinkage long
25444 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25445 +{
25446 +       return do_vserver(cmd, id, data, 0);
25447 +}
25448 +
25449 +#ifdef CONFIG_COMPAT
25450 +
25451 +asmlinkage long
25452 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25453 +{
25454 +       return do_vserver(cmd, id, data, 1);
25455 +}
25456 +
25457 +#endif /* CONFIG_COMPAT */
25458 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/sysctl.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sysctl.c
25459 --- linux-2.6.27.14/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
25460 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/sysctl.c        2008-10-13 14:54:20.000000000 +0200
25461 @@ -0,0 +1,244 @@
25462 +/*
25463 + *  kernel/vserver/sysctl.c
25464 + *
25465 + *  Virtual Context Support
25466 + *
25467 + *  Copyright (C) 2004-2007  Herbert Pötzl
25468 + *
25469 + *  V0.01  basic structure
25470 + *
25471 + */
25472 +
25473 +#include <linux/module.h>
25474 +#include <linux/ctype.h>
25475 +#include <linux/sysctl.h>
25476 +#include <linux/parser.h>
25477 +#include <asm/uaccess.h>
25478 +
25479 +
25480 +enum {
25481 +       CTL_DEBUG_ERROR         = 0,
25482 +       CTL_DEBUG_SWITCH        = 1,
25483 +       CTL_DEBUG_XID,
25484 +       CTL_DEBUG_NID,
25485 +       CTL_DEBUG_TAG,
25486 +       CTL_DEBUG_NET,
25487 +       CTL_DEBUG_LIMIT,
25488 +       CTL_DEBUG_CRES,
25489 +       CTL_DEBUG_DLIM,
25490 +       CTL_DEBUG_QUOTA,
25491 +       CTL_DEBUG_CVIRT,
25492 +       CTL_DEBUG_SPACE,
25493 +       CTL_DEBUG_MISC,
25494 +};
25495 +
25496 +
25497 +unsigned int vx_debug_switch   = 0;
25498 +unsigned int vx_debug_xid      = 0;
25499 +unsigned int vx_debug_nid      = 0;
25500 +unsigned int vx_debug_tag      = 0;
25501 +unsigned int vx_debug_net      = 0;
25502 +unsigned int vx_debug_limit    = 0;
25503 +unsigned int vx_debug_cres     = 0;
25504 +unsigned int vx_debug_dlim     = 0;
25505 +unsigned int vx_debug_quota    = 0;
25506 +unsigned int vx_debug_cvirt    = 0;
25507 +unsigned int vx_debug_space    = 0;
25508 +unsigned int vx_debug_misc     = 0;
25509 +
25510 +
25511 +static struct ctl_table_header *vserver_table_header;
25512 +static ctl_table vserver_root_table[];
25513 +
25514 +
25515 +void vserver_register_sysctl(void)
25516 +{
25517 +       if (!vserver_table_header) {
25518 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25519 +       }
25520 +
25521 +}
25522 +
25523 +void vserver_unregister_sysctl(void)
25524 +{
25525 +       if (vserver_table_header) {
25526 +               unregister_sysctl_table(vserver_table_header);
25527 +               vserver_table_header = NULL;
25528 +       }
25529 +}
25530 +
25531 +
25532 +static int proc_dodebug(ctl_table *table, int write,
25533 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25534 +{
25535 +       char            tmpbuf[20], *p, c;
25536 +       unsigned int    value;
25537 +       size_t          left, len;
25538 +
25539 +       if ((*ppos && !write) || !*lenp) {
25540 +               *lenp = 0;
25541 +               return 0;
25542 +       }
25543 +
25544 +       left = *lenp;
25545 +
25546 +       if (write) {
25547 +               if (!access_ok(VERIFY_READ, buffer, left))
25548 +                       return -EFAULT;
25549 +               p = (char *)buffer;
25550 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25551 +                       left--, p++;
25552 +               if (!left)
25553 +                       goto done;
25554 +
25555 +               if (left > sizeof(tmpbuf) - 1)
25556 +                       return -EINVAL;
25557 +               if (copy_from_user(tmpbuf, p, left))
25558 +                       return -EFAULT;
25559 +               tmpbuf[left] = '\0';
25560 +
25561 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25562 +                       value = 10 * value + (*p - '0');
25563 +               if (*p && !isspace(*p))
25564 +                       return -EINVAL;
25565 +               while (left && isspace(*p))
25566 +                       left--, p++;
25567 +               *(unsigned int *)table->data = value;
25568 +       } else {
25569 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25570 +                       return -EFAULT;
25571 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25572 +               if (len > left)
25573 +                       len = left;
25574 +               if (__copy_to_user(buffer, tmpbuf, len))
25575 +                       return -EFAULT;
25576 +               if ((left -= len) > 0) {
25577 +                       if (put_user('\n', (char *)buffer + len))
25578 +                               return -EFAULT;
25579 +                       left--;
25580 +               }
25581 +       }
25582 +
25583 +done:
25584 +       *lenp -= left;
25585 +       *ppos += *lenp;
25586 +       return 0;
25587 +}
25588 +
25589 +static int zero;
25590 +
25591 +#define        CTL_ENTRY(ctl, name)                            \
25592 +       {                                               \
25593 +               .ctl_name       = ctl,                  \
25594 +               .procname       = #name,                \
25595 +               .data           = &vx_ ## name,         \
25596 +               .maxlen         = sizeof(int),          \
25597 +               .mode           = 0644,                 \
25598 +               .proc_handler   = &proc_dodebug,        \
25599 +               .strategy       = &sysctl_intvec,       \
25600 +               .extra1         = &zero,                \
25601 +       }
25602 +
25603 +static ctl_table vserver_debug_table[] = {
25604 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25605 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25606 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25607 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25608 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25609 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25610 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25611 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25612 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25613 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25614 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25615 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25616 +       { .ctl_name = 0 }
25617 +};
25618 +
25619 +static ctl_table vserver_root_table[] = {
25620 +       {
25621 +               .ctl_name       = CTL_VSERVER,
25622 +               .procname       = "vserver",
25623 +               .mode           = 0555,
25624 +               .child          = vserver_debug_table
25625 +       },
25626 +       { .ctl_name = 0 }
25627 +};
25628 +
25629 +
25630 +static match_table_t tokens = {
25631 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25632 +       { CTL_DEBUG_XID,        "xid=%x"        },
25633 +       { CTL_DEBUG_NID,        "nid=%x"        },
25634 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25635 +       { CTL_DEBUG_NET,        "net=%x"        },
25636 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25637 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25638 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25639 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25640 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25641 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25642 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25643 +       { CTL_DEBUG_ERROR,      NULL            }
25644 +};
25645 +
25646 +#define        HANDLE_CASE(id, name, val)                              \
25647 +       case CTL_DEBUG_ ## id:                                  \
25648 +               vx_debug_ ## name = val;                        \
25649 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25650 +               break
25651 +
25652 +
25653 +static int __init vs_debug_setup(char *str)
25654 +{
25655 +       char *p;
25656 +       int token;
25657 +
25658 +       printk("vs_debug_setup(%s)\n", str);
25659 +       while ((p = strsep(&str, ",")) != NULL) {
25660 +               substring_t args[MAX_OPT_ARGS];
25661 +               unsigned int value;
25662 +
25663 +               if (!*p)
25664 +                       continue;
25665 +
25666 +               token = match_token(p, tokens, args);
25667 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25668 +
25669 +               switch (token) {
25670 +               HANDLE_CASE(SWITCH, switch, value);
25671 +               HANDLE_CASE(XID,    xid,    value);
25672 +               HANDLE_CASE(NID,    nid,    value);
25673 +               HANDLE_CASE(TAG,    tag,    value);
25674 +               HANDLE_CASE(NET,    net,    value);
25675 +               HANDLE_CASE(LIMIT,  limit,  value);
25676 +               HANDLE_CASE(CRES,   cres,   value);
25677 +               HANDLE_CASE(DLIM,   dlim,   value);
25678 +               HANDLE_CASE(QUOTA,  quota,  value);
25679 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25680 +               HANDLE_CASE(SPACE,  space,  value);
25681 +               HANDLE_CASE(MISC,   misc,   value);
25682 +               default:
25683 +                       return -EINVAL;
25684 +                       break;
25685 +               }
25686 +       }
25687 +       return 1;
25688 +}
25689 +
25690 +__setup("vsdebug=", vs_debug_setup);
25691 +
25692 +
25693 +
25694 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25695 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25696 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25697 +EXPORT_SYMBOL_GPL(vx_debug_net);
25698 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25699 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25700 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25701 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25702 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25703 +EXPORT_SYMBOL_GPL(vx_debug_space);
25704 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25705 +
25706 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/tag.c linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/tag.c
25707 --- linux-2.6.27.14/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
25708 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/tag.c   2008-10-13 14:54:20.000000000 +0200
25709 @@ -0,0 +1,63 @@
25710 +/*
25711 + *  linux/kernel/vserver/tag.c
25712 + *
25713 + *  Virtual Server: Shallow Tag Space
25714 + *
25715 + *  Copyright (C) 2007  Herbert Pötzl
25716 + *
25717 + *  V0.01  basic implementation
25718 + *
25719 + */
25720 +
25721 +#include <linux/sched.h>
25722 +#include <linux/vserver/debug.h>
25723 +#include <linux/vs_pid.h>
25724 +#include <linux/vs_tag.h>
25725 +
25726 +#include <linux/vserver/tag_cmd.h>
25727 +
25728 +
25729 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25730 +{
25731 +       if (!p)
25732 +               BUG();
25733 +
25734 +       vxdprintk(VXD_CBIT(tag, 5),
25735 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25736 +
25737 +       task_lock(p);
25738 +       p->tag = tag;
25739 +       task_unlock(p);
25740 +
25741 +       vxdprintk(VXD_CBIT(tag, 5),
25742 +               "moved task %p into [#%d]", p, tag);
25743 +       return 0;
25744 +}
25745 +
25746 +/* vserver syscall commands below here */
25747 +
25748 +/* taks xid and vx_info functions */
25749 +
25750 +
25751 +int vc_task_tag(uint32_t id)
25752 +{
25753 +       tag_t tag;
25754 +
25755 +       if (id) {
25756 +               struct task_struct *tsk;
25757 +               read_lock(&tasklist_lock);
25758 +               tsk = find_task_by_real_pid(id);
25759 +               tag = (tsk) ? tsk->tag : -ESRCH;
25760 +               read_unlock(&tasklist_lock);
25761 +       } else
25762 +               tag = dx_current_tag();
25763 +       return tag;
25764 +}
25765 +
25766 +
25767 +int vc_tag_migrate(uint32_t tag)
25768 +{
25769 +       return dx_migrate_task(current, tag & 0xFFFF);
25770 +}
25771 +
25772 +
25773 diff -NurpP --minimal linux-2.6.27.14/kernel/vserver/vci_config.h linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/vci_config.h
25774 --- linux-2.6.27.14/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
25775 +++ linux-2.6.27.14-vs2.3.0.36.4/kernel/vserver/vci_config.h    2008-10-31 18:16:04.000000000 +0100
25776 @@ -0,0 +1,81 @@
25777 +
25778 +/*  interface version */
25779 +
25780 +#define VCI_VERSION            0x00020304
25781 +
25782 +
25783 +enum {
25784 +       VCI_KCBIT_NO_DYNAMIC = 0,
25785 +
25786 +       VCI_KCBIT_PROC_SECURE = 4,
25787 +       VCI_KCBIT_HARDCPU = 5,
25788 +       VCI_KCBIT_IDLELIMIT = 6,
25789 +       VCI_KCBIT_IDLETIME = 7,
25790 +
25791 +       VCI_KCBIT_COWBL = 8,
25792 +       VCI_KCBIT_FULLCOWBL = 9,
25793 +       VCI_KCBIT_SPACES = 10,
25794 +       VCI_KCBIT_NETV2 = 11,
25795 +
25796 +       VCI_KCBIT_DEBUG = 16,
25797 +       VCI_KCBIT_HISTORY = 20,
25798 +       VCI_KCBIT_TAGGED = 24,
25799 +       VCI_KCBIT_PPTAG = 28,
25800 +
25801 +       VCI_KCBIT_MORE = 31,
25802 +};
25803 +
25804 +
25805 +static inline uint32_t vci_kernel_config(void)
25806 +{
25807 +       return
25808 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25809 +
25810 +       /* configured features */
25811 +#ifdef CONFIG_VSERVER_PROC_SECURE
25812 +       (1 << VCI_KCBIT_PROC_SECURE) |
25813 +#endif
25814 +#ifdef CONFIG_VSERVER_HARDCPU
25815 +       (1 << VCI_KCBIT_HARDCPU) |
25816 +#endif
25817 +#ifdef CONFIG_VSERVER_IDLELIMIT
25818 +       (1 << VCI_KCBIT_IDLELIMIT) |
25819 +#endif
25820 +#ifdef CONFIG_VSERVER_IDLETIME
25821 +       (1 << VCI_KCBIT_IDLETIME) |
25822 +#endif
25823 +#ifdef CONFIG_VSERVER_COWBL
25824 +       (1 << VCI_KCBIT_COWBL) |
25825 +       (1 << VCI_KCBIT_FULLCOWBL) |
25826 +#endif
25827 +       (1 << VCI_KCBIT_SPACES) |
25828 +       (1 << VCI_KCBIT_NETV2) |
25829 +
25830 +       /* debug options */
25831 +#ifdef CONFIG_VSERVER_DEBUG
25832 +       (1 << VCI_KCBIT_DEBUG) |
25833 +#endif
25834 +#ifdef CONFIG_VSERVER_HISTORY
25835 +       (1 << VCI_KCBIT_HISTORY) |
25836 +#endif
25837 +
25838 +       /* inode context tagging */
25839 +#if    defined(CONFIG_TAGGING_NONE)
25840 +       (0 << VCI_KCBIT_TAGGED) |
25841 +#elif  defined(CONFIG_TAGGING_UID16)
25842 +       (1 << VCI_KCBIT_TAGGED) |
25843 +#elif  defined(CONFIG_TAGGING_GID16)
25844 +       (2 << VCI_KCBIT_TAGGED) |
25845 +#elif  defined(CONFIG_TAGGING_ID24)
25846 +       (3 << VCI_KCBIT_TAGGED) |
25847 +#elif  defined(CONFIG_TAGGING_INTERN)
25848 +       (4 << VCI_KCBIT_TAGGED) |
25849 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25850 +       (5 << VCI_KCBIT_TAGGED) |
25851 +#else
25852 +       (7 << VCI_KCBIT_TAGGED) |
25853 +#endif
25854 +       (1 << VCI_KCBIT_PPTAG) |
25855 +       0;
25856 +}
25857 +
25858 diff -NurpP --minimal linux-2.6.27.14/mm/filemap_xip.c linux-2.6.27.14-vs2.3.0.36.4/mm/filemap_xip.c
25859 --- linux-2.6.27.14/mm/filemap_xip.c    2008-10-13 14:52:09.000000000 +0200
25860 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/filemap_xip.c       2008-10-13 14:54:20.000000000 +0200
25861 @@ -17,6 +17,7 @@
25862  #include <linux/sched.h>
25863  #include <linux/seqlock.h>
25864  #include <linux/mutex.h>
25865 +#include <linux/vs_memory.h>
25866  #include <asm/tlbflush.h>
25867  #include <asm/io.h>
25868  
25869 diff -NurpP --minimal linux-2.6.27.14/mm/fremap.c linux-2.6.27.14-vs2.3.0.36.4/mm/fremap.c
25870 --- linux-2.6.27.14/mm/fremap.c 2009-02-03 17:59:55.000000000 +0100
25871 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/fremap.c    2009-02-03 17:59:04.000000000 +0100
25872 @@ -16,6 +16,7 @@
25873  #include <linux/module.h>
25874  #include <linux/syscalls.h>
25875  #include <linux/mmu_notifier.h>
25876 +#include <linux/vs_memory.h>
25877  
25878  #include <asm/mmu_context.h>
25879  #include <asm/cacheflush.h>
25880 diff -NurpP --minimal linux-2.6.27.14/mm/hugetlb.c linux-2.6.27.14-vs2.3.0.36.4/mm/hugetlb.c
25881 --- linux-2.6.27.14/mm/hugetlb.c        2009-02-03 17:59:55.000000000 +0100
25882 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/hugetlb.c   2009-02-03 17:59:04.000000000 +0100
25883 @@ -23,6 +23,7 @@
25884  #include <asm/io.h>
25885  
25886  #include <linux/hugetlb.h>
25887 +#include <linux/vs_memory.h>
25888  #include "internal.h"
25889  
25890  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25891 diff -NurpP --minimal linux-2.6.27.14/mm/memory.c linux-2.6.27.14-vs2.3.0.36.4/mm/memory.c
25892 --- linux-2.6.27.14/mm/memory.c 2008-10-13 14:52:09.000000000 +0200
25893 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/memory.c    2008-10-13 14:54:20.000000000 +0200
25894 @@ -562,6 +562,9 @@ static int copy_pte_range(struct mm_stru
25895         int progress = 0;
25896         int rss[2];
25897  
25898 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25899 +               return -ENOMEM;
25900 +
25901  again:
25902         rss[1] = rss[0] = 0;
25903         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25904 @@ -2294,6 +2297,11 @@ static int do_swap_page(struct mm_struct
25905                 goto out;
25906         }
25907  
25908 +       if (!vx_rss_avail(mm, 1)) {
25909 +               ret = VM_FAULT_OOM;
25910 +               goto out;
25911 +       }
25912 +
25913         mark_page_accessed(page);
25914         lock_page(page);
25915         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
25916 @@ -2365,6 +2373,8 @@ static int do_anonymous_page(struct mm_s
25917         /* Allocate our own private page. */
25918         pte_unmap(page_table);
25919  
25920 +       if (!vx_rss_avail(mm, 1))
25921 +               goto oom;
25922         if (unlikely(anon_vma_prepare(vma)))
25923                 goto oom;
25924         page = alloc_zeroed_user_highpage_movable(vma, address);
25925 @@ -2626,6 +2636,7 @@ static inline int handle_pte_fault(struc
25926  {
25927         pte_t entry;
25928         spinlock_t *ptl;
25929 +       int ret = 0, type = VXPT_UNKNOWN;
25930  
25931         entry = *pte;
25932         if (!pte_present(entry)) {
25933 @@ -2650,9 +2661,12 @@ static inline int handle_pte_fault(struc
25934         if (unlikely(!pte_same(*pte, entry)))
25935                 goto unlock;
25936         if (write_access) {
25937 -               if (!pte_write(entry))
25938 -                       return do_wp_page(mm, vma, address,
25939 +               if (!pte_write(entry)) {
25940 +                       ret = do_wp_page(mm, vma, address,
25941                                         pte, pmd, ptl, entry);
25942 +                       type = VXPT_WRITE;
25943 +                       goto out;
25944 +               }
25945                 entry = pte_mkdirty(entry);
25946         }
25947         entry = pte_mkyoung(entry);
25948 @@ -2670,7 +2684,10 @@ static inline int handle_pte_fault(struc
25949         }
25950  unlock:
25951         pte_unmap_unlock(pte, ptl);
25952 -       return 0;
25953 +       ret = 0;
25954 +out:
25955 +       vx_page_fault(mm, vma, type, ret);
25956 +       return ret;
25957  }
25958  
25959  /*
25960 diff -NurpP --minimal linux-2.6.27.14/mm/mlock.c linux-2.6.27.14-vs2.3.0.36.4/mm/mlock.c
25961 --- linux-2.6.27.14/mm/mlock.c  2009-02-03 17:59:55.000000000 +0100
25962 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/mlock.c     2009-02-03 17:59:04.000000000 +0100
25963 @@ -12,6 +12,7 @@
25964  #include <linux/syscalls.h>
25965  #include <linux/sched.h>
25966  #include <linux/module.h>
25967 +#include <linux/vs_memory.h>
25968  
25969  int can_do_mlock(void)
25970  {
25971 @@ -76,7 +77,7 @@ success:
25972                         ret = make_pages_present(start, end);
25973         }
25974  
25975 -       mm->locked_vm -= pages;
25976 +       vx_vmlocked_sub(mm, pages);
25977  out:
25978         return ret;
25979  }
25980 @@ -132,7 +133,7 @@ static int do_mlock(unsigned long start,
25981  
25982  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25983  {
25984 -       unsigned long locked;
25985 +       unsigned long locked, grow;
25986         unsigned long lock_limit;
25987         int error = -ENOMEM;
25988  
25989 @@ -143,8 +144,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25990         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25991         start &= PAGE_MASK;
25992  
25993 -       locked = len >> PAGE_SHIFT;
25994 -       locked += current->mm->locked_vm;
25995 +       grow = len >> PAGE_SHIFT;
25996 +       if (!vx_vmlocked_avail(current->mm, grow))
25997 +               goto out;
25998 +       locked = current->mm->locked_vm + grow;
25999  
26000         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26001         lock_limit >>= PAGE_SHIFT;
26002 @@ -152,6 +155,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26003         /* check against resource limits */
26004         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26005                 error = do_mlock(start, len, 1);
26006 +out:
26007         up_write(&current->mm->mmap_sem);
26008         return error;
26009  }
26010 @@ -211,6 +215,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26011         lock_limit >>= PAGE_SHIFT;
26012  
26013         ret = -ENOMEM;
26014 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26015 +               goto out;
26016         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26017             capable(CAP_IPC_LOCK))
26018                 ret = do_mlockall(flags);
26019 diff -NurpP --minimal linux-2.6.27.14/mm/mmap.c linux-2.6.27.14-vs2.3.0.36.4/mm/mmap.c
26020 --- linux-2.6.27.14/mm/mmap.c   2009-02-03 17:59:55.000000000 +0100
26021 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/mmap.c      2009-02-03 17:59:04.000000000 +0100
26022 @@ -1221,10 +1221,10 @@ munmap_back:
26023         if (correct_wcount)
26024                 atomic_inc(&inode->i_writecount);
26025  out:
26026 -       mm->total_vm += len >> PAGE_SHIFT;
26027 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26028         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26029         if (vm_flags & VM_LOCKED) {
26030 -               mm->locked_vm += len >> PAGE_SHIFT;
26031 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26032                 make_pages_present(addr, addr + len);
26033         }
26034         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26035 @@ -1573,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
26036                 return -ENOMEM;
26037  
26038         /* Ok, everything looks good - let it rip */
26039 -       mm->total_vm += grow;
26040 +       vx_vmpages_add(mm, grow);
26041         if (vma->vm_flags & VM_LOCKED)
26042 -               mm->locked_vm += grow;
26043 +               vx_vmlocked_add(mm, grow);
26044         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26045         return 0;
26046  }
26047 @@ -1746,9 +1746,9 @@ static void remove_vma_list(struct mm_st
26048         do {
26049                 long nrpages = vma_pages(vma);
26050  
26051 -               mm->total_vm -= nrpages;
26052 +               vx_vmpages_sub(mm, nrpages);
26053                 if (vma->vm_flags & VM_LOCKED)
26054 -                       mm->locked_vm -= nrpages;
26055 +                       vx_vmlocked_sub(mm, nrpages);
26056                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26057                 vma = remove_vma(vma);
26058         } while (vma);
26059 @@ -1995,6 +1995,8 @@ unsigned long do_brk(unsigned long addr,
26060                 lock_limit >>= PAGE_SHIFT;
26061                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26062                         return -EAGAIN;
26063 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26064 +                       return -ENOMEM;
26065         }
26066  
26067         /*
26068 @@ -2021,7 +2023,8 @@ unsigned long do_brk(unsigned long addr,
26069         if (mm->map_count > sysctl_max_map_count)
26070                 return -ENOMEM;
26071  
26072 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26073 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26074 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26075                 return -ENOMEM;
26076  
26077         /* Can we just expand an old private anonymous mapping? */
26078 @@ -2046,9 +2049,9 @@ unsigned long do_brk(unsigned long addr,
26079         vma->vm_page_prot = vm_get_page_prot(flags);
26080         vma_link(mm, vma, prev, rb_link, rb_parent);
26081  out:
26082 -       mm->total_vm += len >> PAGE_SHIFT;
26083 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26084         if (flags & VM_LOCKED) {
26085 -               mm->locked_vm += len >> PAGE_SHIFT;
26086 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26087                 make_pages_present(addr, addr + len);
26088         }
26089         return addr;
26090 @@ -2078,6 +2081,11 @@ void exit_mmap(struct mm_struct *mm)
26091         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26092         tlb_finish_mmu(tlb, 0, end);
26093  
26094 +       set_mm_counter(mm, file_rss, 0);
26095 +       set_mm_counter(mm, anon_rss, 0);
26096 +       vx_vmpages_sub(mm, mm->total_vm);
26097 +       vx_vmlocked_sub(mm, mm->locked_vm);
26098 +
26099         /*
26100          * Walk the list again, actually closing and freeing it,
26101          * with preemption enabled, without holding any MM locks.
26102 @@ -2117,7 +2125,8 @@ int insert_vm_struct(struct mm_struct * 
26103         if (__vma && __vma->vm_start < vma->vm_end)
26104                 return -ENOMEM;
26105         if ((vma->vm_flags & VM_ACCOUNT) &&
26106 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26107 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26108 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26109                 return -ENOMEM;
26110         vma_link(mm, vma, prev, rb_link, rb_parent);
26111         return 0;
26112 @@ -2193,6 +2202,8 @@ int may_expand_vm(struct mm_struct *mm, 
26113  
26114         if (cur + npages > lim)
26115                 return 0;
26116 +       if (!vx_vmpages_avail(mm, npages))
26117 +               return 0;
26118         return 1;
26119  }
26120  
26121 @@ -2270,8 +2281,7 @@ int install_special_mapping(struct mm_st
26122                 return -ENOMEM;
26123         }
26124  
26125 -       mm->total_vm += len >> PAGE_SHIFT;
26126 -
26127 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26128         return 0;
26129  }
26130  
26131 diff -NurpP --minimal linux-2.6.27.14/mm/mremap.c linux-2.6.27.14-vs2.3.0.36.4/mm/mremap.c
26132 --- linux-2.6.27.14/mm/mremap.c 2009-02-03 17:59:55.000000000 +0100
26133 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/mremap.c    2009-02-03 17:59:04.000000000 +0100
26134 @@ -19,6 +19,7 @@
26135  #include <linux/security.h>
26136  #include <linux/syscalls.h>
26137  #include <linux/mmu_notifier.h>
26138 +#include <linux/vs_memory.h>
26139  
26140  #include <asm/uaccess.h>
26141  #include <asm/cacheflush.h>
26142 @@ -218,7 +219,7 @@ static unsigned long move_vma(struct vm_
26143          * If this were a serious issue, we'd add a flag to do_munmap().
26144          */
26145         hiwater_vm = mm->hiwater_vm;
26146 -       mm->total_vm += new_len >> PAGE_SHIFT;
26147 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26148         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26149  
26150         if (do_munmap(mm, old_addr, old_len) < 0) {
26151 @@ -236,7 +237,7 @@ static unsigned long move_vma(struct vm_
26152         }
26153  
26154         if (vm_flags & VM_LOCKED) {
26155 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26156 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26157                 if (new_len > old_len)
26158                         make_pages_present(new_addr + old_len,
26159                                            new_addr + new_len);
26160 @@ -347,6 +348,9 @@ unsigned long do_mremap(unsigned long ad
26161                 ret = -EAGAIN;
26162                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26163                         goto out;
26164 +               if (!vx_vmlocked_avail(current->mm,
26165 +                       (new_len - old_len) >> PAGE_SHIFT))
26166 +                       goto out;
26167         }
26168         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26169                 ret = -ENOMEM;
26170 @@ -375,10 +379,10 @@ unsigned long do_mremap(unsigned long ad
26171                         vma_adjust(vma, vma->vm_start,
26172                                 addr + new_len, vma->vm_pgoff, NULL);
26173  
26174 -                       mm->total_vm += pages;
26175 +                       vx_vmpages_add(mm, pages);
26176                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26177                         if (vma->vm_flags & VM_LOCKED) {
26178 -                               mm->locked_vm += pages;
26179 +                               vx_vmlocked_add(mm, pages);
26180                                 make_pages_present(addr + old_len,
26181                                                    addr + new_len);
26182                         }
26183 diff -NurpP --minimal linux-2.6.27.14/mm/nommu.c linux-2.6.27.14-vs2.3.0.36.4/mm/nommu.c
26184 --- linux-2.6.27.14/mm/nommu.c  2009-02-03 17:59:55.000000000 +0100
26185 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/nommu.c     2009-02-03 17:59:04.000000000 +0100
26186 @@ -1028,7 +1028,7 @@ unsigned long do_mmap_pgoff(struct file 
26187         realalloc += kobjsize(vma);
26188         askedalloc += sizeof(*vma);
26189  
26190 -       current->mm->total_vm += len >> PAGE_SHIFT;
26191 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26192  
26193         add_nommu_vma(vma);
26194  
26195 @@ -1160,7 +1160,7 @@ int do_munmap(struct mm_struct *mm, unsi
26196         kfree(vml);
26197  
26198         update_hiwater_vm(mm);
26199 -       mm->total_vm -= len >> PAGE_SHIFT;
26200 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
26201  
26202  #ifdef DEBUG
26203         show_process_blocks();
26204 @@ -1193,7 +1193,7 @@ void exit_mmap(struct mm_struct * mm)
26205                 printk("Exit_mmap:\n");
26206  #endif
26207  
26208 -               mm->total_vm = 0;
26209 +               vx_vmpages_sub(mm, mm->total_vm);
26210  
26211                 while ((tmp = mm->context.vmlist)) {
26212                         mm->context.vmlist = tmp->next;
26213 diff -NurpP --minimal linux-2.6.27.14/mm/oom_kill.c linux-2.6.27.14-vs2.3.0.36.4/mm/oom_kill.c
26214 --- linux-2.6.27.14/mm/oom_kill.c       2008-10-13 14:52:09.000000000 +0200
26215 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/oom_kill.c  2008-10-13 14:54:20.000000000 +0200
26216 @@ -27,6 +27,7 @@
26217  #include <linux/notifier.h>
26218  #include <linux/memcontrol.h>
26219  #include <linux/security.h>
26220 +#include <linux/vs_memory.h>
26221  
26222  int sysctl_panic_on_oom;
26223  int sysctl_oom_kill_allocating_task;
26224 @@ -73,6 +74,12 @@ unsigned long badness(struct task_struct
26225         points = mm->total_vm;
26226  
26227         /*
26228 +        * add points for context badness
26229 +        */
26230 +
26231 +       points += vx_badness(p, mm);
26232 +
26233 +       /*
26234          * After this unlock we can no longer dereference local variable `mm'
26235          */
26236         task_unlock(p);
26237 @@ -163,8 +170,8 @@ unsigned long badness(struct task_struct
26238         }
26239  
26240  #ifdef DEBUG
26241 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26242 -       p->pid, p->comm, points);
26243 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26244 +               task_pid_nr(p), p->xid, p->comm, points);
26245  #endif
26246         return points;
26247  }
26248 @@ -325,8 +332,8 @@ static void __oom_kill_task(struct task_
26249         }
26250  
26251         if (verbose)
26252 -               printk(KERN_ERR "Killed process %d (%s)\n",
26253 -                               task_pid_nr(p), p->comm);
26254 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26255 +                               task_pid_nr(p), p->xid, p->comm);
26256  
26257         /*
26258          * We give our sacrificial lamb high priority and access to
26259 @@ -406,8 +413,8 @@ static int oom_kill_process(struct task_
26260                 return 0;
26261         }
26262  
26263 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26264 -                                       message, task_pid_nr(p), p->comm, points);
26265 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26266 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26267  
26268         /* Try to kill a child first */
26269         list_for_each_entry(c, &p->children, sibling) {
26270 diff -NurpP --minimal linux-2.6.27.14/mm/page_alloc.c linux-2.6.27.14-vs2.3.0.36.4/mm/page_alloc.c
26271 --- linux-2.6.27.14/mm/page_alloc.c     2009-02-03 17:59:55.000000000 +0100
26272 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/page_alloc.c        2009-02-03 17:59:04.000000000 +0100
26273 @@ -46,6 +46,8 @@
26274  #include <linux/page-isolation.h>
26275  #include <linux/memcontrol.h>
26276  #include <linux/debugobjects.h>
26277 +#include <linux/vs_base.h>
26278 +#include <linux/vs_limit.h>
26279  
26280  #include <asm/tlbflush.h>
26281  #include <asm/div64.h>
26282 @@ -1823,6 +1825,9 @@ void si_meminfo(struct sysinfo *val)
26283         val->totalhigh = totalhigh_pages;
26284         val->freehigh = nr_free_highpages();
26285         val->mem_unit = PAGE_SIZE;
26286 +
26287 +       if (vx_flags(VXF_VIRT_MEM, 0))
26288 +               vx_vsi_meminfo(val);
26289  }
26290  
26291  EXPORT_SYMBOL(si_meminfo);
26292 @@ -1843,6 +1848,9 @@ void si_meminfo_node(struct sysinfo *val
26293         val->freehigh = 0;
26294  #endif
26295         val->mem_unit = PAGE_SIZE;
26296 +
26297 +       if (vx_flags(VXF_VIRT_MEM, 0))
26298 +               vx_vsi_meminfo(val);
26299  }
26300  #endif
26301  
26302 diff -NurpP --minimal linux-2.6.27.14/mm/rmap.c linux-2.6.27.14-vs2.3.0.36.4/mm/rmap.c
26303 --- linux-2.6.27.14/mm/rmap.c   2009-02-03 17:59:55.000000000 +0100
26304 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/rmap.c      2009-02-03 17:59:04.000000000 +0100
26305 @@ -50,6 +50,7 @@
26306  #include <linux/kallsyms.h>
26307  #include <linux/memcontrol.h>
26308  #include <linux/mmu_notifier.h>
26309 +#include <linux/vs_memory.h>
26310  
26311  #include <asm/tlbflush.h>
26312  
26313 diff -NurpP --minimal linux-2.6.27.14/mm/shmem.c linux-2.6.27.14-vs2.3.0.36.4/mm/shmem.c
26314 --- linux-2.6.27.14/mm/shmem.c  2008-10-13 14:52:09.000000000 +0200
26315 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/shmem.c     2008-10-13 14:54:20.000000000 +0200
26316 @@ -56,7 +56,6 @@
26317  #include <asm/pgtable.h>
26318  
26319  /* This magic number is used in glibc for posix shared memory */
26320 -#define TMPFS_MAGIC    0x01021994
26321  
26322  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
26323  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
26324 @@ -1738,7 +1737,7 @@ static int shmem_statfs(struct dentry *d
26325  {
26326         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26327  
26328 -       buf->f_type = TMPFS_MAGIC;
26329 +       buf->f_type = TMPFS_SUPER_MAGIC;
26330         buf->f_bsize = PAGE_CACHE_SIZE;
26331         buf->f_namelen = NAME_MAX;
26332         spin_lock(&sbinfo->stat_lock);
26333 @@ -2306,7 +2305,7 @@ static int shmem_fill_super(struct super
26334         sb->s_maxbytes = SHMEM_MAX_BYTES;
26335         sb->s_blocksize = PAGE_CACHE_SIZE;
26336         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26337 -       sb->s_magic = TMPFS_MAGIC;
26338 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26339         sb->s_op = &shmem_ops;
26340         sb->s_time_gran = 1;
26341  #ifdef CONFIG_TMPFS_POSIX_ACL
26342 diff -NurpP --minimal linux-2.6.27.14/mm/slab.c linux-2.6.27.14-vs2.3.0.36.4/mm/slab.c
26343 --- linux-2.6.27.14/mm/slab.c   2008-10-13 14:52:09.000000000 +0200
26344 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/slab.c      2008-10-13 14:54:20.000000000 +0200
26345 @@ -508,6 +508,8 @@ struct kmem_cache {
26346  #define STATS_INC_FREEMISS(x)  do { } while (0)
26347  #endif
26348  
26349 +#include "slab_vs.h"
26350 +
26351  #if DEBUG
26352  
26353  /*
26354 @@ -3337,6 +3339,7 @@ retry:
26355  
26356         obj = slab_get_obj(cachep, slabp, nodeid);
26357         check_slabp(cachep, slabp);
26358 +       vx_slab_alloc(cachep, flags);
26359         l3->free_objects--;
26360         /* move slabp to correct slabp list: */
26361         list_del(&slabp->list);
26362 @@ -3409,6 +3412,7 @@ __cache_alloc_node(struct kmem_cache *ca
26363         /* ___cache_alloc_node can fall back to other nodes */
26364         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26365    out:
26366 +       vx_slab_alloc(cachep, flags);
26367         local_irq_restore(save_flags);
26368         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26369  
26370 @@ -3580,6 +3584,7 @@ static inline void __cache_free(struct k
26371  
26372         check_irq_off();
26373         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26374 +       vx_slab_free(cachep);
26375  
26376         /*
26377          * Skip calling cache_free_alien() when the platform is not numa.
26378 diff -NurpP --minimal linux-2.6.27.14/mm/slab_vs.h linux-2.6.27.14-vs2.3.0.36.4/mm/slab_vs.h
26379 --- linux-2.6.27.14/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
26380 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/slab_vs.h   2008-10-13 14:54:20.000000000 +0200
26381 @@ -0,0 +1,27 @@
26382 +
26383 +#include <linux/vserver/context.h>
26384 +
26385 +#include <linux/vs_context.h>
26386 +
26387 +static inline
26388 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26389 +{
26390 +       int what = gfp_zone(cachep->gfpflags);
26391 +
26392 +       if (!current->vx_info)
26393 +               return;
26394 +
26395 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26396 +}
26397 +
26398 +static inline
26399 +void vx_slab_free(struct kmem_cache *cachep)
26400 +{
26401 +       int what = gfp_zone(cachep->gfpflags);
26402 +
26403 +       if (!current->vx_info)
26404 +               return;
26405 +
26406 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26407 +}
26408 +
26409 diff -NurpP --minimal linux-2.6.27.14/mm/swapfile.c linux-2.6.27.14-vs2.3.0.36.4/mm/swapfile.c
26410 --- linux-2.6.27.14/mm/swapfile.c       2009-02-03 17:59:55.000000000 +0100
26411 +++ linux-2.6.27.14-vs2.3.0.36.4/mm/swapfile.c  2009-02-03 17:59:04.000000000 +0100
26412 @@ -32,6 +32,8 @@
26413  #include <asm/pgtable.h>
26414  #include <asm/tlbflush.h>
26415  #include <linux/swapops.h>
26416 +#include <linux/vs_base.h>
26417 +#include <linux/vs_memory.h>
26418  
26419  static DEFINE_SPINLOCK(swap_lock);
26420  static unsigned int nr_swapfiles;
26421 @@ -1748,6 +1750,8 @@ void si_swapinfo(struct sysinfo *val)
26422         val->freeswap = nr_swap_pages + nr_to_be_unused;
26423         val->totalswap = total_swap_pages + nr_to_be_unused;
26424         spin_unlock(&swap_lock);
26425 +       if (vx_flags(VXF_VIRT_MEM, 0))
26426 +               vx_vsi_swapinfo(val);
26427  }
26428  
26429  /*
26430 diff -NurpP --minimal linux-2.6.27.14/net/core/dev.c linux-2.6.27.14-vs2.3.0.36.4/net/core/dev.c
26431 --- linux-2.6.27.14/net/core/dev.c      2009-02-03 17:59:55.000000000 +0100
26432 +++ linux-2.6.27.14-vs2.3.0.36.4/net/core/dev.c 2009-02-03 17:59:04.000000000 +0100
26433 @@ -127,6 +127,7 @@
26434  #include <linux/in.h>
26435  #include <linux/jhash.h>
26436  #include <linux/random.h>
26437 +#include <linux/vs_inet.h>
26438  
26439  #include "net-sysfs.h"
26440  
26441 @@ -925,10 +926,15 @@ int dev_change_name(struct net_device *d
26442                 strlcpy(dev->name, newname, IFNAMSIZ);
26443  
26444  rollback:
26445 -       err = device_rename(&dev->dev, dev->name);
26446 -       if (err) {
26447 -               memcpy(dev->name, oldname, IFNAMSIZ);
26448 -               return err;
26449 +       /* For now only devices in the initial network namespace
26450 +        * are in sysfs.
26451 +        */
26452 +       if (net == &init_net) {
26453 +               ret = device_rename(&dev->dev, dev->name);
26454 +               if (ret) {
26455 +                       memcpy(dev->name, oldname, IFNAMSIZ);
26456 +                       return ret;
26457 +               }
26458         }
26459  
26460         write_lock_bh(&dev_base_lock);
26461 @@ -2515,6 +2521,8 @@ static int dev_ifconf(struct net *net, c
26462  
26463         total = 0;
26464         for_each_netdev(net, dev) {
26465 +               if (!nx_dev_visible(current->nx_info, dev))
26466 +                       continue;
26467                 for (i = 0; i < NPROTO; i++) {
26468                         if (gifconf_list[i]) {
26469                                 int done;
26470 @@ -2583,6 +2591,9 @@ static void dev_seq_printf_stats(struct 
26471  {
26472         struct net_device_stats *stats = dev->get_stats(dev);
26473  
26474 +       if (!nx_dev_visible(current->nx_info, dev))
26475 +               return;
26476 +
26477         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26478                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26479                    dev->name, stats->rx_bytes, stats->rx_packets,
26480 @@ -4385,6 +4396,15 @@ int dev_change_net_namespace(struct net_
26481         if (dev->features & NETIF_F_NETNS_LOCAL)
26482                 goto out;
26483  
26484 +#ifdef CONFIG_SYSFS
26485 +       /* Don't allow real devices to be moved when sysfs
26486 +        * is enabled.
26487 +        */
26488 +       err = -EINVAL;
26489 +       if (dev->dev.parent)
26490 +               goto out;
26491 +#endif
26492 +
26493         /* Ensure the device has been registrered */
26494         err = -EINVAL;
26495         if (dev->reg_state != NETREG_REGISTERED)
26496 @@ -4442,6 +4462,8 @@ int dev_change_net_namespace(struct net_
26497          */
26498         dev_addr_discard(dev);
26499  
26500 +       netdev_unregister_kobject(dev);
26501 +
26502         /* Actually switch the network namespace */
26503         dev_net_set(dev, net);
26504  
26505 @@ -4458,7 +4480,6 @@ int dev_change_net_namespace(struct net_
26506         }
26507  
26508         /* Fixup kobjects */
26509 -       netdev_unregister_kobject(dev);
26510         err = netdev_register_kobject(dev);
26511         WARN_ON(err);
26512  
26513 diff -NurpP --minimal linux-2.6.27.14/net/core/net-sysfs.c linux-2.6.27.14-vs2.3.0.36.4/net/core/net-sysfs.c
26514 --- linux-2.6.27.14/net/core/net-sysfs.c        2008-10-13 14:52:09.000000000 +0200
26515 +++ linux-2.6.27.14-vs2.3.0.36.4/net/core/net-sysfs.c   2008-11-20 15:21:32.000000000 +0100
26516 @@ -440,6 +440,10 @@ void netdev_unregister_kobject(struct ne
26517         struct device *dev = &(net->dev);
26518  
26519         kobject_get(&dev->kobj);
26520 +
26521 +       if (dev_net(net) != &init_net)
26522 +               return;
26523 +
26524         device_del(dev);
26525  }
26526  
26527 @@ -465,6 +469,9 @@ int netdev_register_kobject(struct net_d
26528  #endif
26529  #endif /* CONFIG_SYSFS */
26530  
26531 +       if (dev_net(net) != &init_net)
26532 +               return 0;
26533 +
26534         return device_add(dev);
26535  }
26536  
26537 diff -NurpP --minimal linux-2.6.27.14/net/core/rtnetlink.c linux-2.6.27.14-vs2.3.0.36.4/net/core/rtnetlink.c
26538 --- linux-2.6.27.14/net/core/rtnetlink.c        2008-10-13 14:52:09.000000000 +0200
26539 +++ linux-2.6.27.14-vs2.3.0.36.4/net/core/rtnetlink.c   2008-10-13 14:54:20.000000000 +0200
26540 @@ -686,6 +686,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26541  
26542         idx = 0;
26543         for_each_netdev(net, dev) {
26544 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26545 +                       continue;
26546                 if (idx < s_idx)
26547                         goto cont;
26548                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26549 @@ -1219,6 +1221,9 @@ void rtmsg_ifinfo(int type, struct net_d
26550         struct sk_buff *skb;
26551         int err = -ENOBUFS;
26552  
26553 +       if (!nx_dev_visible(current->nx_info, dev))
26554 +               return;
26555 +
26556         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26557         if (skb == NULL)
26558                 goto errout;
26559 diff -NurpP --minimal linux-2.6.27.14/net/core/sock.c linux-2.6.27.14-vs2.3.0.36.4/net/core/sock.c
26560 --- linux-2.6.27.14/net/core/sock.c     2008-10-13 14:52:09.000000000 +0200
26561 +++ linux-2.6.27.14-vs2.3.0.36.4/net/core/sock.c        2008-10-13 14:54:20.000000000 +0200
26562 @@ -124,6 +124,10 @@
26563  #include <linux/ipsec.h>
26564  
26565  #include <linux/filter.h>
26566 +#include <linux/vs_socket.h>
26567 +#include <linux/vs_limit.h>
26568 +#include <linux/vs_context.h>
26569 +#include <linux/vs_network.h>
26570  
26571  #ifdef CONFIG_INET
26572  #include <net/tcp.h>
26573 @@ -897,6 +901,8 @@ static struct sock *sk_prot_alloc(struct
26574                 if (!try_module_get(prot->owner))
26575                         goto out_free_sec;
26576         }
26577 +               sock_vx_init(sk);
26578 +               sock_nx_init(sk);
26579  
26580         return sk;
26581  
26582 @@ -973,6 +979,11 @@ void sk_free(struct sock *sk)
26583                        __func__, atomic_read(&sk->sk_omem_alloc));
26584  
26585         put_net(sock_net(sk));
26586 +       vx_sock_dec(sk);
26587 +       clr_vx_info(&sk->sk_vx_info);
26588 +       sk->sk_xid = -1;
26589 +       clr_nx_info(&sk->sk_nx_info);
26590 +       sk->sk_nid = -1;
26591         sk_prot_free(sk->sk_prot_creator, sk);
26592  }
26593  
26594 @@ -1008,6 +1019,8 @@ struct sock *sk_clone(const struct sock 
26595  
26596                 /* SANITY */
26597                 get_net(sock_net(newsk));
26598 +               sock_vx_init(newsk);
26599 +               sock_nx_init(newsk);
26600                 sk_node_init(&newsk->sk_node);
26601                 sock_lock_init(newsk);
26602                 bh_lock_sock(newsk);
26603 @@ -1054,6 +1067,12 @@ struct sock *sk_clone(const struct sock 
26604                 newsk->sk_priority = 0;
26605                 atomic_set(&newsk->sk_refcnt, 2);
26606  
26607 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26608 +               newsk->sk_xid = sk->sk_xid;
26609 +               vx_sock_inc(newsk);
26610 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26611 +               newsk->sk_nid = sk->sk_nid;
26612 +
26613                 /*
26614                  * Increment the counter in the same struct proto as the master
26615                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26616 @@ -1738,6 +1757,11 @@ void sock_init_data(struct socket *sock,
26617  
26618         sk->sk_stamp = ktime_set(-1L, 0);
26619  
26620 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26621 +       sk->sk_xid = vx_current_xid();
26622 +       vx_sock_inc(sk);
26623 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26624 +       sk->sk_nid = nx_current_nid();
26625         atomic_set(&sk->sk_refcnt, 1);
26626         atomic_set(&sk->sk_drops, 0);
26627  }
26628 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/af_inet.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/af_inet.c
26629 --- linux-2.6.27.14/net/ipv4/af_inet.c  2008-10-13 14:52:09.000000000 +0200
26630 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/af_inet.c     2008-10-13 14:54:20.000000000 +0200
26631 @@ -114,6 +114,7 @@
26632  #ifdef CONFIG_IP_MROUTE
26633  #include <linux/mroute.h>
26634  #endif
26635 +#include <linux/vs_limit.h>
26636  
26637  extern void ip_mc_drop_socket(struct sock *sk);
26638  
26639 @@ -325,9 +326,12 @@ lookup_protocol:
26640         }
26641  
26642         err = -EPERM;
26643 +       if ((protocol == IPPROTO_ICMP) &&
26644 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26645 +               goto override;
26646         if (answer->capability > 0 && !capable(answer->capability))
26647                 goto out_rcu_unlock;
26648 -
26649 +override:
26650         err = -EAFNOSUPPORT;
26651         if (!inet_netns_ok(net, protocol))
26652                 goto out_rcu_unlock;
26653 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26654         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26655         struct sock *sk = sock->sk;
26656         struct inet_sock *inet = inet_sk(sk);
26657 +       struct nx_v4_sock_addr nsa;
26658         unsigned short snum;
26659         int chk_addr_ret;
26660         int err;
26661 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26662         if (addr_len < sizeof(struct sockaddr_in))
26663                 goto out;
26664  
26665 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26666 +       err = v4_map_sock_addr(inet, addr, &nsa);
26667 +       if (err)
26668 +               goto out;
26669 +
26670 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26671  
26672         /* Not specified by any standard per-se, however it breaks too
26673          * many applications when removed.  It is unfortunate since
26674 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26675         err = -EADDRNOTAVAIL;
26676         if (!sysctl_ip_nonlocal_bind &&
26677             !inet->freebind &&
26678 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26679 +           nsa.saddr != htonl(INADDR_ANY) &&
26680             chk_addr_ret != RTN_LOCAL &&
26681             chk_addr_ret != RTN_MULTICAST &&
26682             chk_addr_ret != RTN_BROADCAST)
26683 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26684         if (sk->sk_state != TCP_CLOSE || inet->num)
26685                 goto out_release_sock;
26686  
26687 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26688 +       v4_set_sock_addr(inet, &nsa);
26689         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26690                 inet->saddr = 0;  /* Use device */
26691  
26692 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26693                      peer == 1))
26694                         return -ENOTCONN;
26695                 sin->sin_port = inet->dport;
26696 -               sin->sin_addr.s_addr = inet->daddr;
26697 +               sin->sin_addr.s_addr =
26698 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26699         } else {
26700                 __be32 addr = inet->rcv_saddr;
26701                 if (!addr)
26702                         addr = inet->saddr;
26703 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26704                 sin->sin_port = inet->sport;
26705                 sin->sin_addr.s_addr = addr;
26706         }
26707 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/devinet.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/devinet.c
26708 --- linux-2.6.27.14/net/ipv4/devinet.c  2008-10-13 14:52:09.000000000 +0200
26709 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/devinet.c     2008-10-13 14:54:20.000000000 +0200
26710 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
26711         return in_dev;
26712  }
26713  
26714 +
26715  /* Called only from RTNL semaphored context. No locks. */
26716  
26717  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26718 @@ -662,6 +663,8 @@ int devinet_ioctl(struct net *net, unsig
26719                 *colon = ':';
26720  
26721         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26722 +               struct nx_info *nxi = current->nx_info;
26723 +
26724                 if (tryaddrmatch) {
26725                         /* Matthias Andree */
26726                         /* compare label and address (4.4BSD style) */
26727 @@ -670,6 +673,8 @@ int devinet_ioctl(struct net *net, unsig
26728                            This is checked above. */
26729                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26730                              ifap = &ifa->ifa_next) {
26731 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26732 +                                       continue;
26733                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26734                                     sin_orig.sin_addr.s_addr ==
26735                                                         ifa->ifa_address) {
26736 @@ -682,9 +687,12 @@ int devinet_ioctl(struct net *net, unsig
26737                    comparing just the label */
26738                 if (!ifa) {
26739                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26740 -                            ifap = &ifa->ifa_next)
26741 +                            ifap = &ifa->ifa_next) {
26742 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26743 +                                       continue;
26744                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26745                                         break;
26746 +                       }
26747                 }
26748         }
26749  
26750 @@ -835,6 +843,8 @@ static int inet_gifconf(struct net_devic
26751                 goto out;
26752  
26753         for (; ifa; ifa = ifa->ifa_next) {
26754 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26755 +                       continue;
26756                 if (!buf) {
26757                         done += sizeof(ifr);
26758                         continue;
26759 @@ -1165,6 +1175,7 @@ static int inet_dump_ifaddr(struct sk_bu
26760         struct net_device *dev;
26761         struct in_device *in_dev;
26762         struct in_ifaddr *ifa;
26763 +       struct sock *sk = skb->sk;
26764         int s_ip_idx, s_idx = cb->args[0];
26765  
26766         s_ip_idx = ip_idx = cb->args[1];
26767 @@ -1179,6 +1190,8 @@ static int inet_dump_ifaddr(struct sk_bu
26768  
26769                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26770                      ifa = ifa->ifa_next, ip_idx++) {
26771 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26772 +                               continue;
26773                         if (ip_idx < s_ip_idx)
26774                                 continue;
26775                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26776 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/fib_hash.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/fib_hash.c
26777 --- linux-2.6.27.14/net/ipv4/fib_hash.c 2008-10-13 14:52:09.000000000 +0200
26778 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/fib_hash.c    2008-10-13 14:54:20.000000000 +0200
26779 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26780         prefix  = f->fn_key;
26781         mask    = FZ_MASK(iter->zone);
26782         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26783 -       if (fi)
26784 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26785                 seq_printf(seq,
26786                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26787                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26788 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/inet_connection_sock.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/inet_connection_sock.c
26789 --- linux-2.6.27.14/net/ipv4/inet_connection_sock.c     2008-10-13 14:52:09.000000000 +0200
26790 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/inet_connection_sock.c        2008-10-13 14:54:20.000000000 +0200
26791 @@ -47,10 +47,40 @@ void inet_get_local_port_range(int *low,
26792  }
26793  EXPORT_SYMBOL(inet_get_local_port_range);
26794  
26795 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26796 +{
26797 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26798 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26799 +
26800 +       if (inet_v6_ipv6only(sk2))
26801 +               return 0;
26802 +
26803 +       if (sk1_rcv_saddr &&
26804 +           sk2_rcv_saddr &&
26805 +           sk1_rcv_saddr == sk2_rcv_saddr)
26806 +               return 1;
26807 +
26808 +       if (sk1_rcv_saddr &&
26809 +           !sk2_rcv_saddr &&
26810 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26811 +               return 1;
26812 +
26813 +       if (sk2_rcv_saddr &&
26814 +           !sk1_rcv_saddr &&
26815 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26816 +               return 1;
26817 +
26818 +       if (!sk1_rcv_saddr &&
26819 +           !sk2_rcv_saddr &&
26820 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26821 +               return 1;
26822 +
26823 +       return 0;
26824 +}
26825 +
26826  int inet_csk_bind_conflict(const struct sock *sk,
26827                            const struct inet_bind_bucket *tb)
26828  {
26829 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26830         struct sock *sk2;
26831         struct hlist_node *node;
26832         int reuse = sk->sk_reuse;
26833 @@ -70,9 +100,7 @@ int inet_csk_bind_conflict(const struct 
26834                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26835                         if (!reuse || !sk2->sk_reuse ||
26836                             sk2->sk_state == TCP_LISTEN) {
26837 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26838 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26839 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26840 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26841                                         break;
26842                         }
26843                 }
26844 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/inet_diag.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/inet_diag.c
26845 --- linux-2.6.27.14/net/ipv4/inet_diag.c        2008-10-13 14:52:09.000000000 +0200
26846 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/inet_diag.c   2008-10-13 14:54:20.000000000 +0200
26847 @@ -32,6 +32,8 @@
26848  #include <linux/stddef.h>
26849  
26850  #include <linux/inet_diag.h>
26851 +#include <linux/vs_network.h>
26852 +#include <linux/vs_inet.h>
26853  
26854  static const struct inet_diag_handler **inet_diag_table;
26855  
26856 @@ -120,8 +122,8 @@ static int inet_csk_diag_fill(struct soc
26857  
26858         r->id.idiag_sport = inet->sport;
26859         r->id.idiag_dport = inet->dport;
26860 -       r->id.idiag_src[0] = inet->rcv_saddr;
26861 -       r->id.idiag_dst[0] = inet->daddr;
26862 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26863 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26864  
26865  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26866         if (r->idiag_family == AF_INET6) {
26867 @@ -208,8 +210,8 @@ static int inet_twsk_diag_fill(struct in
26868         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26869         r->id.idiag_sport     = tw->tw_sport;
26870         r->id.idiag_dport     = tw->tw_dport;
26871 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26872 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26873 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26874 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26875         r->idiag_state        = tw->tw_substate;
26876         r->idiag_timer        = 3;
26877         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26878 @@ -266,6 +268,7 @@ static int inet_diag_get_exact(struct sk
26879         err = -EINVAL;
26880  
26881         if (req->idiag_family == AF_INET) {
26882 +               /* TODO: lback */
26883                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26884                                  req->id.idiag_dport, req->id.idiag_src[0],
26885                                  req->id.idiag_sport, req->id.idiag_if);
26886 @@ -508,6 +511,7 @@ static int inet_csk_diag_dump(struct soc
26887                 } else
26888  #endif
26889                 {
26890 +                       /* TODO: lback */
26891                         entry.saddr = &inet->rcv_saddr;
26892                         entry.daddr = &inet->daddr;
26893                 }
26894 @@ -544,6 +548,7 @@ static int inet_twsk_diag_dump(struct in
26895                 } else
26896  #endif
26897                 {
26898 +                       /* TODO: lback */
26899                         entry.saddr = &tw->tw_rcv_saddr;
26900                         entry.daddr = &tw->tw_daddr;
26901                 }
26902 @@ -590,8 +595,8 @@ static int inet_diag_fill_req(struct sk_
26903  
26904         r->id.idiag_sport = inet->sport;
26905         r->id.idiag_dport = ireq->rmt_port;
26906 -       r->id.idiag_src[0] = ireq->loc_addr;
26907 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26908 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26909 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26910         r->idiag_expires = jiffies_to_msecs(tmo);
26911         r->idiag_rqueue = 0;
26912         r->idiag_wqueue = 0;
26913 @@ -661,6 +666,7 @@ static int inet_diag_dump_reqs(struct sk
26914                                 continue;
26915  
26916                         if (bc) {
26917 +                               /* TODO: lback */
26918                                 entry.saddr =
26919  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26920                                         (entry.family == AF_INET6) ?
26921 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26922                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
26923                                 struct inet_sock *inet = inet_sk(sk);
26924  
26925 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26926 +                                       continue;
26927                                 if (num < s_num) {
26928                                         num++;
26929                                         continue;
26930 @@ -790,6 +798,8 @@ skip_listen_ht:
26931                 sk_for_each(sk, node, &head->chain) {
26932                         struct inet_sock *inet = inet_sk(sk);
26933  
26934 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26935 +                               continue;
26936                         if (num < s_num)
26937                                 goto next_normal;
26938                         if (!(r->idiag_states & (1 << sk->sk_state)))
26939 @@ -814,6 +824,8 @@ next_normal:
26940                         inet_twsk_for_each(tw, node,
26941                                     &head->twchain) {
26942  
26943 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26944 +                                       continue;
26945                                 if (num < s_num)
26946                                         goto next_dying;
26947                                 if (r->id.idiag_sport != tw->tw_sport &&
26948 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/inet_hashtables.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/inet_hashtables.c
26949 --- linux-2.6.27.14/net/ipv4/inet_hashtables.c  2008-10-13 14:52:09.000000000 +0200
26950 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/inet_hashtables.c     2008-10-13 14:54:20.000000000 +0200
26951 @@ -21,6 +21,7 @@
26952  
26953  #include <net/inet_connection_sock.h>
26954  #include <net/inet_hashtables.h>
26955 +#include <net/route.h>
26956  #include <net/ip.h>
26957  
26958  /*
26959 @@ -163,11 +164,10 @@ static struct sock *inet_lookup_listener
26960                         const __be32 rcv_saddr = inet->rcv_saddr;
26961                         int score = sk->sk_family == PF_INET ? 1 : 0;
26962  
26963 -                       if (rcv_saddr) {
26964 -                               if (rcv_saddr != daddr)
26965 -                                       continue;
26966 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
26967                                 score += 2;
26968 -                       }
26969 +                       else
26970 +                               continue;
26971                         if (sk->sk_bound_dev_if) {
26972                                 if (sk->sk_bound_dev_if != dif)
26973                                         continue;
26974 @@ -199,7 +199,7 @@ struct sock *__inet_lookup_listener(stru
26975                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
26976  
26977                 if (inet->num == hnum && !sk->sk_node.next &&
26978 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
26979 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
26980                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
26981                     !sk->sk_bound_dev_if && net_eq(sock_net(sk), net))
26982                         goto sherry_cache;
26983 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/netfilter/nf_nat_helper.c
26984 --- linux-2.6.27.14/net/ipv4/netfilter/nf_nat_helper.c  2008-07-13 23:51:29.000000000 +0200
26985 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/netfilter/nf_nat_helper.c     2008-10-13 14:54:20.000000000 +0200
26986 @@ -18,6 +18,7 @@
26987  #include <net/tcp.h>
26988  
26989  #include <linux/netfilter_ipv4.h>
26990 +#include <net/route.h>
26991  #include <net/netfilter/nf_conntrack.h>
26992  #include <net/netfilter/nf_conntrack_helper.h>
26993  #include <net/netfilter/nf_conntrack_ecache.h>
26994 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/netfilter.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/netfilter.c
26995 --- linux-2.6.27.14/net/ipv4/netfilter.c        2008-07-13 23:51:29.000000000 +0200
26996 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/netfilter.c   2008-10-13 14:54:20.000000000 +0200
26997 @@ -4,7 +4,7 @@
26998  #include <linux/netfilter_ipv4.h>
26999  #include <linux/ip.h>
27000  #include <linux/skbuff.h>
27001 -#include <net/route.h>
27002 +// #include <net/route.h>
27003  #include <net/xfrm.h>
27004  #include <net/ip.h>
27005  #include <net/netfilter/nf_queue.h>
27006 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/raw.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/raw.c
27007 --- linux-2.6.27.14/net/ipv4/raw.c      2008-10-13 14:52:09.000000000 +0200
27008 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/raw.c 2008-10-13 14:54:20.000000000 +0200
27009 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27010  
27011                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27012                     !(inet->daddr && inet->daddr != raddr)              &&
27013 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27014 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27015                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27016                         goto found; /* gotcha */
27017         }
27018 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
27019                 icmp_out_count(net, ((struct icmphdr *)
27020                         skb_transport_header(skb))->type);
27021  
27022 +       err = -EPERM;
27023 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27024 +               sk->sk_nx_info &&
27025 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27026 +               goto error_free;
27027 +
27028         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27029                       dst_output);
27030         if (err > 0)
27031 @@ -383,6 +389,7 @@ out:
27032  
27033  error_fault:
27034         err = -EFAULT;
27035 +error_free:
27036         kfree_skb(skb);
27037  error:
27038         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
27039 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
27040                 }
27041  
27042                 security_sk_classify_flow(sk, &fl);
27043 +               if (sk->sk_nx_info) {
27044 +                       err = ip_v4_find_src(sock_net(sk),
27045 +                               sk->sk_nx_info, &rt, &fl);
27046 +
27047 +                       if (err)
27048 +                               goto done;
27049 +               }
27050                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27051         }
27052         if (err)
27053 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
27054  {
27055         struct inet_sock *inet = inet_sk(sk);
27056         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27057 +       struct nx_v4_sock_addr nsa = { 0 };
27058         int ret = -EINVAL;
27059         int chk_addr_ret;
27060  
27061         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27062                 goto out;
27063 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27064 +       v4_map_sock_addr(inet, addr, &nsa);
27065 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27066         ret = -EADDRNOTAVAIL;
27067 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27068 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27069             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27070                 goto out;
27071 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27072 +       v4_set_sock_addr(inet, &nsa);
27073         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27074                 inet->saddr = 0;  /* Use device */
27075         sk_dst_reset(sk);
27076 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
27077         /* Copy the address. */
27078         if (sin) {
27079                 sin->sin_family = AF_INET;
27080 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27081 +               sin->sin_addr.s_addr =
27082 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27083                 sin->sin_port = 0;
27084                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27085         }
27086 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
27087                 struct hlist_node *node;
27088  
27089                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27090 -                       if (sock_net(sk) == seq_file_net(seq))
27091 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27092 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27093                                 goto found;
27094         }
27095         sk = NULL;
27096 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
27097                 sk = sk_next(sk);
27098  try_again:
27099                 ;
27100 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27101 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27102 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27103  
27104         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27105                 sk = sk_head(&state->h->ht[state->bucket]);
27106 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
27107  
27108         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27109                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27110 -               i, src, srcp, dest, destp, sp->sk_state,
27111 +               i,
27112 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27113 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27114 +               sp->sk_state,
27115                 atomic_read(&sp->sk_wmem_alloc),
27116                 atomic_read(&sp->sk_rmem_alloc),
27117                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27118 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/syncookies.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/syncookies.c
27119 --- linux-2.6.27.14/net/ipv4/syncookies.c       2008-10-13 14:52:09.000000000 +0200
27120 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/syncookies.c  2008-10-13 14:54:20.000000000 +0200
27121 @@ -16,6 +16,7 @@
27122  #include <linux/cryptohash.h>
27123  #include <linux/kernel.h>
27124  #include <net/tcp.h>
27125 +#include <net/route.h>
27126  
27127  /* Timestamps: lowest 9 bits store TCP options */
27128  #define TSBITS 9
27129 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/tcp.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/tcp.c
27130 --- linux-2.6.27.14/net/ipv4/tcp.c      2009-02-03 17:59:55.000000000 +0100
27131 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/tcp.c 2009-02-03 17:59:04.000000000 +0100
27132 @@ -264,6 +264,7 @@
27133  #include <linux/cache.h>
27134  #include <linux/err.h>
27135  #include <linux/crypto.h>
27136 +#include <linux/in.h>
27137  
27138  #include <net/icmp.h>
27139  #include <net/tcp.h>
27140 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/tcp_ipv4.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/tcp_ipv4.c
27141 --- linux-2.6.27.14/net/ipv4/tcp_ipv4.c 2008-10-13 14:52:09.000000000 +0200
27142 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/tcp_ipv4.c    2008-10-13 14:54:20.000000000 +0200
27143 @@ -1886,6 +1886,12 @@ static void *listening_get_next(struct s
27144                 req = req->dl_next;
27145                 while (1) {
27146                         while (req) {
27147 +                               vxdprintk(VXD_CBIT(net, 6),
27148 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27149 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27150 +                               if (req->sk &&
27151 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27152 +                                       continue;
27153                                 if (req->rsk_ops->family == st->family) {
27154                                         cur = req;
27155                                         goto out;
27156 @@ -1910,6 +1916,10 @@ get_req:
27157         }
27158  get_sk:
27159         sk_for_each_from(sk, node) {
27160 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27161 +                       sk, sk->sk_nid, nx_current_nid());
27162 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27163 +                       continue;
27164                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27165                         cur = sk;
27166                         goto out;
27167 @@ -1960,6 +1970,11 @@ static void *established_get_first(struc
27168  
27169                 read_lock_bh(lock);
27170                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27171 +                       vxdprintk(VXD_CBIT(net, 6),
27172 +                               "sk,egf: %p [#%d] (from %d)",
27173 +                               sk, sk->sk_nid, nx_current_nid());
27174 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27175 +                               continue;
27176                         if (sk->sk_family != st->family ||
27177                             !net_eq(sock_net(sk), net)) {
27178                                 continue;
27179 @@ -1970,6 +1985,11 @@ static void *established_get_first(struc
27180                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27181                 inet_twsk_for_each(tw, node,
27182                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27183 +                       vxdprintk(VXD_CBIT(net, 6),
27184 +                               "tw: %p [#%d] (from %d)",
27185 +                               tw, tw->tw_nid, nx_current_nid());
27186 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27187 +                               continue;
27188                         if (tw->tw_family != st->family ||
27189                             !net_eq(twsk_net(tw), net)) {
27190                                 continue;
27191 @@ -1998,7 +2018,9 @@ static void *established_get_next(struct
27192                 tw = cur;
27193                 tw = tw_next(tw);
27194  get_tw:
27195 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27196 +               while (tw && (tw->tw_family != st->family ||
27197 +                       !net_eq(twsk_net(tw), net) ||
27198 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27199                         tw = tw_next(tw);
27200                 }
27201                 if (tw) {
27202 @@ -2019,6 +2041,11 @@ get_tw:
27203                 sk = sk_next(sk);
27204  
27205         sk_for_each_from(sk, node) {
27206 +               vxdprintk(VXD_CBIT(net, 6),
27207 +                       "sk,egn: %p [#%d] (from %d)",
27208 +                       sk, sk->sk_nid, nx_current_nid());
27209 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27210 +                       continue;
27211                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27212                         goto found;
27213         }
27214 @@ -2173,9 +2200,9 @@ static void get_openreq4(struct sock *sk
27215         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27216                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27217                 i,
27218 -               ireq->loc_addr,
27219 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27220                 ntohs(inet_sk(sk)->sport),
27221 -               ireq->rmt_addr,
27222 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27223                 ntohs(ireq->rmt_port),
27224                 TCP_SYN_RECV,
27225                 0, 0, /* could print option size, but that is af dependent. */
27226 @@ -2218,7 +2245,10 @@ static void get_tcp4_sock(struct sock *s
27227  
27228         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27229                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27230 -               i, src, srcp, dest, destp, sk->sk_state,
27231 +               i,
27232 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27233 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27234 +               sk->sk_state,
27235                 tp->write_seq - tp->snd_una,
27236                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27237                                              (tp->rcv_nxt - tp->copied_seq),
27238 @@ -2254,7 +2284,10 @@ static void get_timewait4_sock(struct in
27239  
27240         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27241                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27242 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27243 +               i,
27244 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27245 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27246 +               tw->tw_substate, 0, 0,
27247                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27248                 atomic_read(&tw->tw_refcnt), tw, len);
27249  }
27250 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/tcp_minisocks.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/tcp_minisocks.c
27251 --- linux-2.6.27.14/net/ipv4/tcp_minisocks.c    2008-10-13 14:52:09.000000000 +0200
27252 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/tcp_minisocks.c       2008-10-13 14:54:20.000000000 +0200
27253 @@ -26,6 +26,10 @@
27254  #include <net/inet_common.h>
27255  #include <net/xfrm.h>
27256  
27257 +#include <linux/vs_limit.h>
27258 +#include <linux/vs_socket.h>
27259 +#include <linux/vs_context.h>
27260 +
27261  #ifdef CONFIG_SYSCTL
27262  #define SYNC_INIT 0 /* let the user enable it */
27263  #else
27264 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27265                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27266                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27267  
27268 +               tw->tw_xid              = sk->sk_xid;
27269 +               tw->tw_vx_info          = NULL;
27270 +               tw->tw_nid              = sk->sk_nid;
27271 +               tw->tw_nx_info          = NULL;
27272 +
27273  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27274                 if (tw->tw_family == PF_INET6) {
27275                         struct ipv6_pinfo *np = inet6_sk(sk);
27276 diff -NurpP --minimal linux-2.6.27.14/net/ipv4/udp.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/udp.c
27277 --- linux-2.6.27.14/net/ipv4/udp.c      2009-02-03 17:59:55.000000000 +0100
27278 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv4/udp.c 2009-02-03 17:59:04.000000000 +0100
27279 @@ -234,20 +234,14 @@ fail:
27280         return error;
27281  }
27282  
27283 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27284 -{
27285 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27286 -
27287 -       return  ( !ipv6_only_sock(sk2)  &&
27288 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27289 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27290 -}
27291 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27292  
27293  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27294  {
27295         return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal);
27296  }
27297  
27298 +
27299  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27300   * harder than this. -DaveM
27301   */
27302 @@ -267,10 +261,16 @@ static struct sock *__udp4_lib_lookup(st
27303                 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
27304                                 !ipv6_only_sock(sk)) {
27305                         int score = (sk->sk_family == PF_INET ? 1 : 0);
27306 +
27307                         if (inet->rcv_saddr) {
27308                                 if (inet->rcv_saddr != daddr)
27309                                         continue;
27310                                 score+=2;
27311 +                       } else {
27312 +                               /* block non nx_info ips */
27313 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
27314 +                                       daddr, NXA_MASK_BIND))
27315 +                                       continue;
27316                         }
27317                         if (inet->daddr) {
27318                                 if (inet->daddr != saddr)
27319 @@ -296,6 +296,7 @@ static struct sock *__udp4_lib_lookup(st
27320                         }
27321                 }
27322         }
27323 +
27324         if (result)
27325                 sock_hold(result);
27326         read_unlock(&udp_hash_lock);
27327 @@ -318,7 +319,7 @@ static inline struct sock *udp_v4_mcast_
27328                     s->sk_hash != hnum                                  ||
27329                     (inet->daddr && inet->daddr != rmt_addr)            ||
27330                     (inet->dport != rmt_port && inet->dport)            ||
27331 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27332 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27333                     ipv6_only_sock(s)                                   ||
27334                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27335                         continue;
27336 @@ -655,8 +656,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27337                                                { .sport = inet->sport,
27338                                                  .dport = dport } } };
27339                 struct net *net = sock_net(sk);
27340 +               struct nx_info *nxi = sk->sk_nx_info;
27341  
27342                 security_sk_classify_flow(sk, &fl);
27343 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27344 +               if (err)
27345 +                       goto out;
27346 +
27347                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27348                 if (err) {
27349                         if (err == -ENETUNREACH)
27350 @@ -901,7 +907,8 @@ try_again:
27351         {
27352                 sin->sin_family = AF_INET;
27353                 sin->sin_port = udp_hdr(skb)->source;
27354 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27355 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27356 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27357                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27358         }
27359         if (inet->cmsg_flags)
27360 @@ -1530,6 +1537,8 @@ static struct sock *udp_get_first(struct
27361                 sk_for_each(sk, node, state->hashtable + state->bucket) {
27362                         if (!net_eq(sock_net(sk), net))
27363                                 continue;
27364 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27365 +                               continue;
27366                         if (sk->sk_family == state->family)
27367                                 goto found;
27368                 }
27369 @@ -1548,7 +1557,9 @@ static struct sock *udp_get_next(struct 
27370                 sk = sk_next(sk);
27371  try_again:
27372                 ;
27373 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27374 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27375 +               sk->sk_family != state->family ||
27376 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27377  
27378         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
27379                 sk = sk_head(state->hashtable + state->bucket);
27380 @@ -1649,7 +1660,10 @@ static void udp4_format_sock(struct sock
27381  
27382         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27383                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27384 -               bucket, src, srcp, dest, destp, sp->sk_state,
27385 +               bucket,
27386 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27387 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27388 +               sp->sk_state,
27389                 atomic_read(&sp->sk_wmem_alloc),
27390                 atomic_read(&sp->sk_rmem_alloc),
27391                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27392 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/addrconf.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/addrconf.c
27393 --- linux-2.6.27.14/net/ipv6/addrconf.c 2008-10-13 14:52:09.000000000 +0200
27394 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/addrconf.c    2008-11-21 13:32:00.000000000 +0100
27395 @@ -85,6 +85,8 @@
27396  
27397  #include <linux/proc_fs.h>
27398  #include <linux/seq_file.h>
27399 +#include <linux/vs_network.h>
27400 +#include <linux/vs_inet6.h>
27401  
27402  /* Set to 3 to get tracing... */
27403  #define ACONF_DEBUG 2
27404 @@ -1108,7 +1110,7 @@ out:
27405  
27406  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27407                        const struct in6_addr *daddr, unsigned int prefs,
27408 -                      struct in6_addr *saddr)
27409 +                      struct in6_addr *saddr, struct nx_info *nxi)
27410  {
27411         struct ipv6_saddr_score scores[2],
27412                                 *score = &scores[0], *hiscore = &scores[1];
27413 @@ -1181,6 +1183,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27414                                                dev->name);
27415                                 continue;
27416                         }
27417 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27418 +                               continue;
27419  
27420                         score->rule = -1;
27421                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27422 @@ -1364,35 +1368,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27423         return ifp;
27424  }
27425  
27426 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27427 +
27428  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27429  {
27430         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27431         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27432 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27433         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27434         int sk_ipv6only = ipv6_only_sock(sk);
27435         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27436         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27437         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27438  
27439 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27440 +       /* FIXME: needs handling for v4 ANY */
27441 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27442                 return 1;
27443  
27444         if (addr_type2 == IPV6_ADDR_ANY &&
27445 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27446 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27447 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27448                 return 1;
27449  
27450         if (addr_type == IPV6_ADDR_ANY &&
27451 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27452 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27453 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27454 +               return 1;
27455 +
27456 +       if (addr_type == IPV6_ADDR_ANY &&
27457 +           addr_type2 == IPV6_ADDR_ANY &&
27458 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27459                 return 1;
27460  
27461         if (sk2_rcv_saddr6 &&
27462 +           addr_type != IPV6_ADDR_ANY &&
27463 +           addr_type != IPV6_ADDR_ANY &&
27464             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27465                 return 1;
27466  
27467         if (addr_type == IPV6_ADDR_MAPPED &&
27468             !sk2_ipv6only &&
27469 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27470 +           ipv4_rcv_saddr_equal(sk, sk2))
27471                 return 1;
27472  
27473         return 0;
27474 @@ -2986,7 +3001,10 @@ static void if6_seq_stop(struct seq_file
27475  static int if6_seq_show(struct seq_file *seq, void *v)
27476  {
27477         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27478 -       seq_printf(seq,
27479 +
27480 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27481 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27482 +               seq_printf(seq,
27483                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
27484                    NIP6(ifp->addr),
27485                    ifp->idev->dev->ifindex,
27486 @@ -3481,6 +3499,12 @@ static int inet6_dump_addr(struct sk_buf
27487         struct ifmcaddr6 *ifmca;
27488         struct ifacaddr6 *ifaca;
27489         struct net *net = sock_net(skb->sk);
27490 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27491 +
27492 +       /* disable ipv6 on non v6 guests */
27493 +       if (nxi && !nx_info_has_v6(nxi))
27494 +               return skb->len;
27495 +
27496  
27497         s_idx = cb->args[0];
27498         s_ip_idx = ip_idx = cb->args[1];
27499 @@ -3502,6 +3526,8 @@ static int inet6_dump_addr(struct sk_buf
27500                              ifa = ifa->if_next, ip_idx++) {
27501                                 if (ip_idx < s_ip_idx)
27502                                         continue;
27503 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27504 +                                       continue;
27505                                 err = inet6_fill_ifaddr(skb, ifa,
27506                                                         NETLINK_CB(cb->skb).pid,
27507                                                         cb->nlh->nlmsg_seq,
27508 @@ -3515,6 +3541,8 @@ static int inet6_dump_addr(struct sk_buf
27509                              ifmca = ifmca->next, ip_idx++) {
27510                                 if (ip_idx < s_ip_idx)
27511                                         continue;
27512 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27513 +                                       continue;
27514                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27515                                                           NETLINK_CB(cb->skb).pid,
27516                                                           cb->nlh->nlmsg_seq,
27517 @@ -3528,6 +3556,8 @@ static int inet6_dump_addr(struct sk_buf
27518                              ifaca = ifaca->aca_next, ip_idx++) {
27519                                 if (ip_idx < s_ip_idx)
27520                                         continue;
27521 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27522 +                                       continue;
27523                                 err = inet6_fill_ifacaddr(skb, ifaca,
27524                                                           NETLINK_CB(cb->skb).pid,
27525                                                           cb->nlh->nlmsg_seq,
27526 @@ -3813,12 +3843,19 @@ static int inet6_dump_ifinfo(struct sk_b
27527         int s_idx = cb->args[0];
27528         struct net_device *dev;
27529         struct inet6_dev *idev;
27530 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27531 +
27532 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27533 +       if (skb->sk && skb->sk->sk_vx_info)
27534 +               return skb->len; */
27535  
27536         read_lock(&dev_base_lock);
27537         idx = 0;
27538         for_each_netdev(net, dev) {
27539                 if (idx < s_idx)
27540                         goto cont;
27541 +               if (!v6_dev_in_nx_info(dev, nxi))
27542 +                       goto cont;
27543                 if ((idev = in6_dev_get(dev)) == NULL)
27544                         goto cont;
27545                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27546 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/af_inet6.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/af_inet6.c
27547 --- linux-2.6.27.14/net/ipv6/af_inet6.c 2008-10-13 14:52:09.000000000 +0200
27548 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/af_inet6.c    2008-10-13 14:54:20.000000000 +0200
27549 @@ -41,6 +41,8 @@
27550  #include <linux/netdevice.h>
27551  #include <linux/icmpv6.h>
27552  #include <linux/netfilter_ipv6.h>
27553 +#include <linux/vs_inet.h>
27554 +#include <linux/vs_inet6.h>
27555  
27556  #include <net/ip.h>
27557  #include <net/ipv6.h>
27558 @@ -49,6 +51,7 @@
27559  #include <net/tcp.h>
27560  #include <net/ipip.h>
27561  #include <net/protocol.h>
27562 +#include <net/route.h>
27563  #include <net/inet_common.h>
27564  #include <net/transp_v6.h>
27565  #include <net/ip6_route.h>
27566 @@ -141,9 +144,12 @@ lookup_protocol:
27567         }
27568  
27569         err = -EPERM;
27570 +       if ((protocol == IPPROTO_ICMPV6) &&
27571 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27572 +               goto override;
27573         if (answer->capability > 0 && !capable(answer->capability))
27574                 goto out_rcu_unlock;
27575 -
27576 +override:
27577         sock->ops = answer->ops;
27578         answer_prot = answer->prot;
27579         answer_no_check = answer->no_check;
27580 @@ -242,6 +248,7 @@ int inet6_bind(struct socket *sock, stru
27581         struct inet_sock *inet = inet_sk(sk);
27582         struct ipv6_pinfo *np = inet6_sk(sk);
27583         struct net *net = sock_net(sk);
27584 +       struct nx_v6_sock_addr nsa;
27585         __be32 v4addr = 0;
27586         unsigned short snum;
27587         int addr_type = 0;
27588 @@ -253,6 +260,11 @@ int inet6_bind(struct socket *sock, stru
27589  
27590         if (addr_len < SIN6_LEN_RFC2133)
27591                 return -EINVAL;
27592 +
27593 +       err = v6_map_sock_addr(inet, addr, &nsa);
27594 +       if (err)
27595 +               return err;
27596 +
27597         addr_type = ipv6_addr_type(&addr->sin6_addr);
27598         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27599                 return -EINVAL;
27600 @@ -276,6 +288,10 @@ int inet6_bind(struct socket *sock, stru
27601                         err = -EADDRNOTAVAIL;
27602                         goto out;
27603                 }
27604 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27605 +                       err = -EADDRNOTAVAIL;
27606 +                       goto out;
27607 +               }
27608         } else {
27609                 if (addr_type != IPV6_ADDR_ANY) {
27610                         struct net_device *dev = NULL;
27611 @@ -301,6 +317,11 @@ int inet6_bind(struct socket *sock, stru
27612                                 }
27613                         }
27614  
27615 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27616 +                               err = -EADDRNOTAVAIL;
27617 +                               goto out;
27618 +                       }
27619 +
27620                         /* ipv4 addr of the socket is invalid.  Only the
27621                          * unspecified and mapped address have a v4 equivalent.
27622                          */
27623 @@ -319,6 +340,8 @@ int inet6_bind(struct socket *sock, stru
27624                 }
27625         }
27626  
27627 +       v6_set_sock_addr(inet, &nsa);
27628 +
27629         inet->rcv_saddr = v4addr;
27630         inet->saddr = v4addr;
27631  
27632 @@ -411,9 +434,11 @@ int inet6_getname(struct socket *sock, s
27633                         return -ENOTCONN;
27634                 sin->sin6_port = inet->dport;
27635                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27636 +               /* FIXME: remap lback? */
27637                 if (np->sndflow)
27638                         sin->sin6_flowinfo = np->flow_label;
27639         } else {
27640 +               /* FIXME: remap lback? */
27641                 if (ipv6_addr_any(&np->rcv_saddr))
27642                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27643                 else
27644 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/fib6_rules.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/fib6_rules.c
27645 --- linux-2.6.27.14/net/ipv6/fib6_rules.c       2008-10-13 14:52:09.000000000 +0200
27646 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/fib6_rules.c  2008-10-13 14:54:20.000000000 +0200
27647 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27648                         if (ipv6_dev_get_saddr(net,
27649                                                ip6_dst_idev(&rt->u.dst)->dev,
27650                                                &flp->fl6_dst, srcprefs,
27651 -                                              &saddr))
27652 +                                              &saddr, NULL))
27653                                 goto again;
27654                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27655                                                r->src.plen))
27656 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/inet6_hashtables.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/inet6_hashtables.c
27657 --- linux-2.6.27.14/net/ipv6/inet6_hashtables.c 2008-10-13 14:52:09.000000000 +0200
27658 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/inet6_hashtables.c    2008-10-13 14:54:20.000000000 +0200
27659 @@ -16,6 +16,7 @@
27660  
27661  #include <linux/module.h>
27662  #include <linux/random.h>
27663 +#include <linux/vs_inet6.h>
27664  
27665  #include <net/inet_connection_sock.h>
27666  #include <net/inet_hashtables.h>
27667 @@ -115,6 +116,9 @@ struct sock *inet6_lookup_listener(struc
27668                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27669                                         continue;
27670                                 score++;
27671 +                       } else {
27672 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27673 +                                       continue;
27674                         }
27675                         if (sk->sk_bound_dev_if) {
27676                                 if (sk->sk_bound_dev_if != dif)
27677 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/ip6_output.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/ip6_output.c
27678 --- linux-2.6.27.14/net/ipv6/ip6_output.c       2008-10-13 14:52:09.000000000 +0200
27679 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/ip6_output.c  2008-10-13 14:54:20.000000000 +0200
27680 @@ -937,7 +937,7 @@ static int ip6_dst_lookup_tail(struct so
27681                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27682                                          &fl->fl6_dst,
27683                                          sk ? inet6_sk(sk)->srcprefs : 0,
27684 -                                        &fl->fl6_src);
27685 +                                        &fl->fl6_src, sk->sk_nx_info);
27686                 if (err)
27687                         goto out_err_release;
27688         }
27689 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/Kconfig linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/Kconfig
27690 --- linux-2.6.27.14/net/ipv6/Kconfig    2008-10-13 14:52:09.000000000 +0200
27691 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/Kconfig       2008-10-13 14:54:20.000000000 +0200
27692 @@ -4,8 +4,8 @@
27693  
27694  #   IPv6 as module will cause a CRASH if you try to unload it
27695  menuconfig IPV6
27696 -       tristate "The IPv6 protocol"
27697 -       default m
27698 +       bool "The IPv6 protocol"
27699 +       default n
27700         ---help---
27701           This is complemental support for the IP version 6.
27702           You will still be able to do traditional IPv4 networking as well.
27703 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/ndisc.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/ndisc.c
27704 --- linux-2.6.27.14/net/ipv6/ndisc.c    2008-10-13 14:52:09.000000000 +0200
27705 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/ndisc.c       2008-10-13 14:54:20.000000000 +0200
27706 @@ -551,7 +551,7 @@ static void ndisc_send_na(struct net_dev
27707         } else {
27708                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27709                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27710 -                                      &tmpaddr))
27711 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27712                         return;
27713                 src_addr = &tmpaddr;
27714         }
27715 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/raw.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/raw.c
27716 --- linux-2.6.27.14/net/ipv6/raw.c      2008-10-13 14:52:09.000000000 +0200
27717 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/raw.c 2008-11-21 13:32:00.000000000 +0100
27718 @@ -29,6 +29,7 @@
27719  #include <linux/icmpv6.h>
27720  #include <linux/netfilter.h>
27721  #include <linux/netfilter_ipv6.h>
27722 +#include <linux/vs_inet6.h>
27723  #include <linux/skbuff.h>
27724  #include <asm/uaccess.h>
27725  #include <asm/ioctls.h>
27726 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27727                         }
27728                 }
27729  
27730 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27731 +                       err = -EADDRNOTAVAIL;
27732 +                       if (dev)
27733 +                               dev_put(dev);
27734 +                       goto out;
27735 +               }
27736 +
27737                 /* ipv4 addr of the socket is invalid.  Only the
27738                  * unspecified and mapped address have a v4 equivalent.
27739                  */
27740 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/route.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/route.c
27741 --- linux-2.6.27.14/net/ipv6/route.c    2008-10-13 14:52:09.000000000 +0200
27742 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/route.c       2008-10-13 14:54:20.000000000 +0200
27743 @@ -2191,7 +2191,8 @@ static int rt6_fill_node(struct net *net
27744                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27745                 struct in6_addr saddr_buf;
27746                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27747 -                                      dst, 0, &saddr_buf) == 0)
27748 +                       dst, 0, &saddr_buf,
27749 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27750                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27751         }
27752  
27753 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/tcp_ipv6.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/tcp_ipv6.c
27754 --- linux-2.6.27.14/net/ipv6/tcp_ipv6.c 2009-02-03 17:59:55.000000000 +0100
27755 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/tcp_ipv6.c    2009-02-03 17:59:04.000000000 +0100
27756 @@ -67,6 +67,7 @@
27757  
27758  #include <linux/crypto.h>
27759  #include <linux/scatterlist.h>
27760 +#include <linux/vs_inet6.h>
27761  
27762  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27763  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27764 @@ -155,8 +156,15 @@ static int tcp_v6_connect(struct sock *s
27765          *      connect() to INADDR_ANY means loopback (BSD'ism).
27766          */
27767  
27768 -       if(ipv6_addr_any(&usin->sin6_addr))
27769 -               usin->sin6_addr.s6_addr[15] = 0x1;
27770 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27771 +               struct nx_info *nxi =  sk->sk_nx_info;
27772 +
27773 +               if (nxi && nx_info_has_v6(nxi))
27774 +                       /* FIXME: remap lback? */
27775 +                       usin->sin6_addr = nxi->v6.ip;
27776 +               else
27777 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27778 +       }
27779  
27780         addr_type = ipv6_addr_type(&usin->sin6_addr);
27781  
27782 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/udp.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/udp.c
27783 --- linux-2.6.27.14/net/ipv6/udp.c      2009-02-03 17:59:55.000000000 +0100
27784 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/udp.c 2009-02-03 17:59:04.000000000 +0100
27785 @@ -47,6 +47,7 @@
27786  
27787  #include <linux/proc_fs.h>
27788  #include <linux/seq_file.h>
27789 +#include <linux/vs_inet6.h>
27790  #include "udp_impl.h"
27791  
27792  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27793 @@ -81,6 +82,10 @@ static struct sock *__udp6_lib_lookup(st
27794                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27795                                         continue;
27796                                 score++;
27797 +                       } else {
27798 +                               /* block non nx_info ips */
27799 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27800 +                                       continue;
27801                         }
27802                         if (!ipv6_addr_any(&np->daddr)) {
27803                                 if (!ipv6_addr_equal(&np->daddr, saddr))
27804 diff -NurpP --minimal linux-2.6.27.14/net/ipv6/xfrm6_policy.c linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/xfrm6_policy.c
27805 --- linux-2.6.27.14/net/ipv6/xfrm6_policy.c     2008-10-13 14:52:09.000000000 +0200
27806 +++ linux-2.6.27.14-vs2.3.0.36.4/net/ipv6/xfrm6_policy.c        2008-10-13 14:54:20.000000000 +0200
27807 @@ -61,7 +61,7 @@ static int xfrm6_get_saddr(xfrm_address_
27808         dev = ip6_dst_idev(dst)->dev;
27809         ipv6_dev_get_saddr(dev_net(dev), dev,
27810                            (struct in6_addr *)&daddr->a6, 0,
27811 -                          (struct in6_addr *)&saddr->a6);
27812 +                          (struct in6_addr *)&saddr->a6, NULL);
27813         dst_release(dst);
27814         return 0;
27815  }
27816 diff -NurpP --minimal linux-2.6.27.14/net/Kconfig linux-2.6.27.14-vs2.3.0.36.4/net/Kconfig
27817 --- linux-2.6.27.14/net/Kconfig 2008-10-13 14:52:09.000000000 +0200
27818 +++ linux-2.6.27.14-vs2.3.0.36.4/net/Kconfig    2008-11-20 15:21:32.000000000 +0100
27819 @@ -27,7 +27,7 @@ menu "Networking options"
27820  config NET_NS
27821         bool "Network namespace support"
27822         default n
27823 -       depends on EXPERIMENTAL && !SYSFS && NAMESPACES
27824 +       depends on EXPERIMENTAL && NAMESPACES
27825         help
27826           Allow user space to create what appear to be multiple instances
27827           of the network stack.
27828 diff -NurpP --minimal linux-2.6.27.14/net/netlink/af_netlink.c linux-2.6.27.14-vs2.3.0.36.4/net/netlink/af_netlink.c
27829 --- linux-2.6.27.14/net/netlink/af_netlink.c    2008-10-13 14:52:09.000000000 +0200
27830 +++ linux-2.6.27.14-vs2.3.0.36.4/net/netlink/af_netlink.c       2008-10-13 14:54:20.000000000 +0200
27831 @@ -55,6 +55,9 @@
27832  #include <linux/types.h>
27833  #include <linux/audit.h>
27834  #include <linux/mutex.h>
27835 +#include <linux/vs_context.h>
27836 +#include <linux/vs_network.h>
27837 +#include <linux/vs_limit.h>
27838  
27839  #include <net/net_namespace.h>
27840  #include <net/sock.h>
27841 @@ -1761,6 +1764,8 @@ static struct sock *netlink_seq_socket_i
27842                         sk_for_each(s, node, &hash->table[j]) {
27843                                 if (sock_net(s) != seq_file_net(seq))
27844                                         continue;
27845 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27846 +                                       continue;
27847                                 if (off == pos) {
27848                                         iter->link = i;
27849                                         iter->hash_idx = j;
27850 @@ -1795,7 +1800,8 @@ static void *netlink_seq_next(struct seq
27851         s = v;
27852         do {
27853                 s = sk_next(s);
27854 -       } while (s && sock_net(s) != seq_file_net(seq));
27855 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27856 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27857         if (s)
27858                 return s;
27859  
27860 @@ -1807,7 +1813,8 @@ static void *netlink_seq_next(struct seq
27861  
27862                 for (; j <= hash->mask; j++) {
27863                         s = sk_head(&hash->table[j]);
27864 -                       while (s && sock_net(s) != seq_file_net(seq))
27865 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27866 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27867                                 s = sk_next(s);
27868                         if (s) {
27869                                 iter->link = i;
27870 diff -NurpP --minimal linux-2.6.27.14/net/sctp/ipv6.c linux-2.6.27.14-vs2.3.0.36.4/net/sctp/ipv6.c
27871 --- linux-2.6.27.14/net/sctp/ipv6.c     2008-10-13 14:52:09.000000000 +0200
27872 +++ linux-2.6.27.14-vs2.3.0.36.4/net/sctp/ipv6.c        2008-10-13 14:54:20.000000000 +0200
27873 @@ -323,7 +323,8 @@ static void sctp_v6_get_saddr(struct sct
27874                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27875                                    &daddr->v6.sin6_addr,
27876                                    inet6_sk(&sk->inet.sk)->srcprefs,
27877 -                                  &saddr->v6.sin6_addr);
27878 +                                  &saddr->v6.sin6_addr,
27879 +                                  asoc->base.sk->sk_nx_info);
27880                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
27881                                   NIP6(saddr->v6.sin6_addr));
27882                 return;
27883 diff -NurpP --minimal linux-2.6.27.14/net/socket.c linux-2.6.27.14-vs2.3.0.36.4/net/socket.c
27884 --- linux-2.6.27.14/net/socket.c        2009-02-03 17:59:55.000000000 +0100
27885 +++ linux-2.6.27.14-vs2.3.0.36.4/net/socket.c   2009-02-03 17:59:04.000000000 +0100
27886 @@ -96,6 +96,10 @@
27887  
27888  #include <net/sock.h>
27889  #include <linux/netfilter.h>
27890 +#include <linux/vs_base.h>
27891 +#include <linux/vs_socket.h>
27892 +#include <linux/vs_inet.h>
27893 +#include <linux/vs_inet6.h>
27894  
27895  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27896  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27897 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
27898                                  struct msghdr *msg, size_t size)
27899  {
27900         struct sock_iocb *si = kiocb_to_siocb(iocb);
27901 -       int err;
27902 +       int err, len;
27903  
27904         si->sock = sock;
27905         si->scm = NULL;
27906 @@ -561,7 +565,22 @@ static inline int __sock_sendmsg(struct 
27907         if (err)
27908                 return err;
27909  
27910 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27911 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27912 +       if (sock->sk) {
27913 +               if (len == size)
27914 +                       vx_sock_send(sock->sk, size);
27915 +               else
27916 +                       vx_sock_fail(sock->sk, size);
27917 +       }
27918 +       vxdprintk(VXD_CBIT(net, 7),
27919 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27920 +               sock, sock->sk,
27921 +               (sock->sk)?sock->sk->sk_nx_info:0,
27922 +               (sock->sk)?sock->sk->sk_vx_info:0,
27923 +               (sock->sk)?sock->sk->sk_xid:0,
27924 +               (sock->sk)?sock->sk->sk_nid:0,
27925 +               (unsigned int)size, len);
27926 +       return len;
27927  }
27928  
27929  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27930 @@ -630,7 +649,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27931  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27932                                  struct msghdr *msg, size_t size, int flags)
27933  {
27934 -       int err;
27935 +       int err, len;
27936         struct sock_iocb *si = kiocb_to_siocb(iocb);
27937  
27938         si->sock = sock;
27939 @@ -643,7 +662,18 @@ static inline int __sock_recvmsg(struct 
27940         if (err)
27941                 return err;
27942  
27943 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27944 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27945 +       if ((len >= 0) && sock->sk)
27946 +               vx_sock_recv(sock->sk, len);
27947 +       vxdprintk(VXD_CBIT(net, 7),
27948 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27949 +               sock, sock->sk,
27950 +               (sock->sk)?sock->sk->sk_nx_info:0,
27951 +               (sock->sk)?sock->sk->sk_vx_info:0,
27952 +               (sock->sk)?sock->sk->sk_xid:0,
27953 +               (sock->sk)?sock->sk->sk_nid:0,
27954 +               (unsigned int)size, len);
27955 +       return len;
27956  }
27957  
27958  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27959 @@ -1108,6 +1138,13 @@ static int __sock_create(struct net *net
27960         if (type < 0 || type >= SOCK_MAX)
27961                 return -EINVAL;
27962  
27963 +       if (!nx_check(0, VS_ADMIN)) {
27964 +               if (family == PF_INET && !current_nx_info_has_v4())
27965 +                       return -EAFNOSUPPORT;
27966 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27967 +                       return -EAFNOSUPPORT;
27968 +       }
27969 +
27970         /* Compatibility.
27971  
27972            This uglymoron is moved from INET layer to here to avoid
27973 @@ -1240,6 +1277,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27974         if (retval < 0)
27975                 goto out;
27976  
27977 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27978         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27979         if (retval < 0)
27980                 goto out_release;
27981 @@ -1281,10 +1319,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27982         err = sock_create(family, type, protocol, &sock1);
27983         if (err < 0)
27984                 goto out;
27985 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27986  
27987         err = sock_create(family, type, protocol, &sock2);
27988         if (err < 0)
27989                 goto out_release_1;
27990 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27991  
27992         err = sock1->ops->socketpair(sock1, sock2);
27993         if (err < 0)
27994 diff -NurpP --minimal linux-2.6.27.14/net/sunrpc/auth.c linux-2.6.27.14-vs2.3.0.36.4/net/sunrpc/auth.c
27995 --- linux-2.6.27.14/net/sunrpc/auth.c   2008-07-13 23:51:29.000000000 +0200
27996 +++ linux-2.6.27.14-vs2.3.0.36.4/net/sunrpc/auth.c      2008-10-13 14:54:20.000000000 +0200
27997 @@ -14,6 +14,7 @@
27998  #include <linux/hash.h>
27999  #include <linux/sunrpc/clnt.h>
28000  #include <linux/spinlock.h>
28001 +#include <linux/vs_tag.h>
28002  
28003  #ifdef RPC_DEBUG
28004  # define RPCDBG_FACILITY       RPCDBG_AUTH
28005 @@ -353,6 +354,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28006         struct auth_cred acred = {
28007                 .uid = current->fsuid,
28008                 .gid = current->fsgid,
28009 +               .tag = dx_current_tag(),
28010                 .group_info = current->group_info,
28011         };
28012         struct rpc_cred *ret;
28013 @@ -398,6 +400,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28014         struct auth_cred acred = {
28015                 .uid = 0,
28016                 .gid = 0,
28017 +               .tag = dx_current_tag(),
28018         };
28019         struct rpc_cred *ret;
28020  
28021 diff -NurpP --minimal linux-2.6.27.14/net/sunrpc/auth_unix.c linux-2.6.27.14-vs2.3.0.36.4/net/sunrpc/auth_unix.c
28022 --- linux-2.6.27.14/net/sunrpc/auth_unix.c      2008-10-13 14:52:09.000000000 +0200
28023 +++ linux-2.6.27.14-vs2.3.0.36.4/net/sunrpc/auth_unix.c 2008-10-13 14:54:20.000000000 +0200
28024 @@ -11,12 +11,14 @@
28025  #include <linux/module.h>
28026  #include <linux/sunrpc/clnt.h>
28027  #include <linux/sunrpc/auth.h>
28028 +#include <linux/vs_tag.h>
28029  
28030  #define NFS_NGROUPS    16
28031  
28032  struct unx_cred {
28033         struct rpc_cred         uc_base;
28034         gid_t                   uc_gid;
28035 +       tag_t                   uc_tag;
28036         gid_t                   uc_gids[NFS_NGROUPS];
28037  };
28038  #define uc_uid                 uc_base.cr_uid
28039 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28040                 groups = NFS_NGROUPS;
28041  
28042         cred->uc_gid = acred->gid;
28043 +       cred->uc_tag = acred->tag;
28044         for (i = 0; i < groups; i++)
28045                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28046         if (i < NFS_NGROUPS)
28047 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28048         unsigned int i;
28049  
28050  
28051 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28052 +       if (cred->uc_uid != acred->uid ||
28053 +               cred->uc_gid != acred->gid ||
28054 +               cred->uc_tag != acred->tag)
28055                 return 0;
28056  
28057         if (acred->group_info != NULL)
28058 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28059         struct rpc_clnt *clnt = task->tk_client;
28060         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28061         __be32          *base, *hold;
28062 -       int             i;
28063 +       int             i, tag;
28064  
28065         *p++ = htonl(RPC_AUTH_UNIX);
28066         base = p++;
28067 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28068          * Copy the UTS nodename captured when the client was created.
28069          */
28070         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28071 +       tag = task->tk_client->cl_tag;
28072  
28073 -       *p++ = htonl((u32) cred->uc_uid);
28074 -       *p++ = htonl((u32) cred->uc_gid);
28075 +       *p++ = htonl((u32) TAGINO_UID(tag,
28076 +               cred->uc_uid, cred->uc_tag));
28077 +       *p++ = htonl((u32) TAGINO_GID(tag,
28078 +               cred->uc_gid, cred->uc_tag));
28079         hold = p++;
28080         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28081                 *p++ = htonl((u32) cred->uc_gids[i]);
28082 diff -NurpP --minimal linux-2.6.27.14/net/sunrpc/clnt.c linux-2.6.27.14-vs2.3.0.36.4/net/sunrpc/clnt.c
28083 --- linux-2.6.27.14/net/sunrpc/clnt.c   2008-10-13 14:52:09.000000000 +0200
28084 +++ linux-2.6.27.14-vs2.3.0.36.4/net/sunrpc/clnt.c      2008-10-13 14:54:20.000000000 +0200
28085 @@ -32,6 +32,7 @@
28086  #include <linux/utsname.h>
28087  #include <linux/workqueue.h>
28088  #include <linux/in6.h>
28089 +#include <linux/vs_cvirt.h>
28090  
28091  #include <linux/sunrpc/clnt.h>
28092  #include <linux/sunrpc/rpc_pipe_fs.h>
28093 @@ -327,6 +328,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28094         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28095                 clnt->cl_chatty = 1;
28096  
28097 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28098 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28099 +               clnt->cl_tag = 1; */
28100         return clnt;
28101  }
28102  EXPORT_SYMBOL_GPL(rpc_create);
28103 diff -NurpP --minimal linux-2.6.27.14/net/unix/af_unix.c linux-2.6.27.14-vs2.3.0.36.4/net/unix/af_unix.c
28104 --- linux-2.6.27.14/net/unix/af_unix.c  2009-02-03 17:59:55.000000000 +0100
28105 +++ linux-2.6.27.14-vs2.3.0.36.4/net/unix/af_unix.c     2009-02-03 17:59:04.000000000 +0100
28106 @@ -114,6 +114,8 @@
28107  #include <linux/mount.h>
28108  #include <net/checksum.h>
28109  #include <linux/security.h>
28110 +#include <linux/vs_context.h>
28111 +#include <linux/vs_limit.h>
28112  
28113  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28114  static DEFINE_SPINLOCK(unix_table_lock);
28115 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28116                 if (!net_eq(sock_net(s), net))
28117                         continue;
28118  
28119 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28120 +                       continue;
28121                 if (u->addr->len == len &&
28122                     !memcmp(u->addr->name, sunname, len))
28123                         goto found;
28124 @@ -2103,6 +2107,8 @@ static struct sock *unix_seq_idx(struct 
28125         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28126                 if (sock_net(s) != seq_file_net(seq))
28127                         continue;
28128 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28129 +                       continue;
28130                 if (off == pos)
28131                         return s;
28132                 ++off;
28133 @@ -2128,7 +2134,8 @@ static void *unix_seq_next(struct seq_fi
28134                 sk = first_unix_socket(&iter->i);
28135         else
28136                 sk = next_unix_socket(&iter->i, sk);
28137 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28138 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28139 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28140                 sk = next_unix_socket(&iter->i, sk);
28141         return sk;
28142  }
28143 diff -NurpP --minimal linux-2.6.27.14/net/x25/af_x25.c linux-2.6.27.14-vs2.3.0.36.4/net/x25/af_x25.c
28144 --- linux-2.6.27.14/net/x25/af_x25.c    2008-10-13 14:52:10.000000000 +0200
28145 +++ linux-2.6.27.14-vs2.3.0.36.4/net/x25/af_x25.c       2008-10-13 14:54:20.000000000 +0200
28146 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
28147  
28148         x25 = x25_sk(sk);
28149  
28150 -       sock_init_data(sock, sk);
28151 +       sk->sk_socket = sock;
28152 +       sk->sk_type = sock->type;
28153 +       sk->sk_sleep = &sock->wait;
28154 +       sock->sk = sk;
28155  
28156         x25_init_timers(sk);
28157  
28158 diff -NurpP --minimal linux-2.6.27.14/scripts/checksyscalls.sh linux-2.6.27.14-vs2.3.0.36.4/scripts/checksyscalls.sh
28159 --- linux-2.6.27.14/scripts/checksyscalls.sh    2008-07-13 23:51:29.000000000 +0200
28160 +++ linux-2.6.27.14-vs2.3.0.36.4/scripts/checksyscalls.sh       2008-10-13 14:54:20.000000000 +0200
28161 @@ -108,7 +108,6 @@ cat << EOF
28162  #define __IGNORE_afs_syscall
28163  #define __IGNORE_getpmsg
28164  #define __IGNORE_putpmsg
28165 -#define __IGNORE_vserver
28166  EOF
28167  }
28168  
28169 diff -NurpP --minimal linux-2.6.27.14/security/commoncap.c linux-2.6.27.14-vs2.3.0.36.4/security/commoncap.c
28170 --- linux-2.6.27.14/security/commoncap.c        2009-02-03 17:59:55.000000000 +0100
28171 +++ linux-2.6.27.14-vs2.3.0.36.4/security/commoncap.c   2009-02-03 17:59:04.000000000 +0100
28172 @@ -26,10 +26,11 @@
28173  #include <linux/sched.h>
28174  #include <linux/prctl.h>
28175  #include <linux/securebits.h>
28176 +#include <linux/vs_context.h>
28177  
28178  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28179  {
28180 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
28181 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
28182         return 0;
28183  }
28184  
28185 @@ -50,9 +51,24 @@ EXPORT_SYMBOL(cap_netlink_recv);
28186   */
28187  int cap_capable (struct task_struct *tsk, int cap)
28188  {
28189 +       struct vx_info *vxi = tsk->vx_info;
28190 +
28191 +#if 0
28192 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28193 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28194 +               cap_raised(tsk->cap_effective, cap),
28195 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28196 +#endif
28197 +
28198 +       /* special case SETUP */
28199 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28200 +               cap_raised(tsk->cap_effective, cap))
28201 +               return 0;
28202 +
28203         /* Derived from include/linux/sched.h:capable. */
28204 -       if (cap_raised(tsk->cap_effective, cap))
28205 +       if (vx_cap_raised(vxi, tsk->cap_effective, cap))
28206                 return 0;
28207 +
28208         return -EPERM;
28209  }
28210  
28211 @@ -696,7 +712,8 @@ void cap_task_reparent_to_init (struct t
28212  
28213  int cap_syslog (int type)
28214  {
28215 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28216 +       if ((type != 3 && type != 10) &&
28217 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28218                 return -EPERM;
28219         return 0;
28220  }
28221 diff -NurpP --minimal linux-2.6.27.14/security/selinux/hooks.c linux-2.6.27.14-vs2.3.0.36.4/security/selinux/hooks.c
28222 --- linux-2.6.27.14/security/selinux/hooks.c    2008-10-13 14:52:10.000000000 +0200
28223 +++ linux-2.6.27.14-vs2.3.0.36.4/security/selinux/hooks.c       2008-10-13 14:54:20.000000000 +0200
28224 @@ -64,7 +64,6 @@
28225  #include <linux/dccp.h>
28226  #include <linux/quota.h>
28227  #include <linux/un.h>          /* for Unix socket types */
28228 -#include <net/af_unix.h>       /* for Unix socket types */
28229  #include <linux/parser.h>
28230  #include <linux/nfs_mount.h>
28231  #include <net/ipv6.h>
This page took 2.382555 seconds and 3 git commands to generate.