]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- try to fix ppc builds for external modules (untested yet)
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.27.3/arch/alpha/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/Kconfig
2 --- linux-2.6.27.3/arch/alpha/Kconfig   2008-10-13 14:51:51.000000000 +0200
3 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/alpha/kernel/entry.S linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/entry.S
14 --- linux-2.6.27.3/arch/alpha/kernel/entry.S    2008-07-13 23:51:29.000000000 +0200
15 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/entry.S       2008-10-13 14:54:20.000000000 +0200
16 @@ -872,24 +872,15 @@ sys_getxgid:
17         .globl  sys_getxpid
18         .ent    sys_getxpid
19  sys_getxpid:
20 +       lda     $sp, -16($sp)
21 +       stq     $26, 0($sp)
22         .prologue 0
23 -       ldq     $2, TI_TASK($8)
24  
25 -       /* See linux/kernel/timer.c sys_getppid for discussion
26 -          about this loop.  */
27 -       ldq     $3, TASK_GROUP_LEADER($2)
28 -       ldq     $4, TASK_REAL_PARENT($3)
29 -       ldl     $0, TASK_TGID($2)
30 -1:     ldl     $1, TASK_TGID($4)
31 -#ifdef CONFIG_SMP
32 -       mov     $4, $5
33 -       mb
34 -       ldq     $3, TASK_GROUP_LEADER($2)
35 -       ldq     $4, TASK_REAL_PARENT($3)
36 -       cmpeq   $4, $5, $5
37 -       beq     $5, 1b
38 -#endif
39 -       stq     $1, 80($sp)
40 +       lda     $16, 96($sp)
41 +       jsr     $26, do_getxpid
42 +       ldq     $26, 0($sp)
43 +
44 +       lda     $sp, 16($sp)
45         ret
46  .end sys_getxpid
47  
48 diff -NurpP --minimal linux-2.6.27.3/arch/alpha/kernel/osf_sys.c linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.27.3/arch/alpha/kernel/osf_sys.c  2008-10-13 14:51:51.000000000 +0200
50 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/alpha/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.27.3/arch/alpha/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
62 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/alpha/kernel/systbls.S linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/systbls.S
72 --- linux-2.6.27.3/arch/alpha/kernel/systbls.S  2008-07-13 23:51:29.000000000 +0200
73 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/systbls.S     2008-10-13 14:54:20.000000000 +0200
74 @@ -446,7 +446,7 @@ sys_call_table:
75         .quad sys_stat64                        /* 425 */
76         .quad sys_lstat64
77         .quad sys_fstat64
78 -       .quad sys_ni_syscall                    /* sys_vserver */
79 +       .quad sys_vserver                       /* sys_vserver */
80         .quad sys_ni_syscall                    /* sys_mbind */
81         .quad sys_ni_syscall                    /* sys_get_mempolicy */
82         .quad sys_ni_syscall                    /* sys_set_mempolicy */
83 diff -NurpP --minimal linux-2.6.27.3/arch/alpha/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/kernel/traps.c
84 --- linux-2.6.27.3/arch/alpha/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
85 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/alpha/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/alpha/mm/fault.c
97 --- linux-2.6.27.3/arch/alpha/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
98 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/arm/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/arm/Kconfig
111 --- linux-2.6.27.3/arch/arm/Kconfig     2008-10-13 14:51:51.000000000 +0200
112 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/arm/kernel/calls.S linux-2.6.27.3-vs2.3.0.35.7/arch/arm/kernel/calls.S
123 --- linux-2.6.27.3/arch/arm/kernel/calls.S      2008-10-13 14:51:52.000000000 +0200
124 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/arm/kernel/calls.S 2008-10-13 14:54:20.000000000 +0200
125 @@ -322,7 +322,7 @@
126  /* 310 */      CALL(sys_request_key)
127                 CALL(sys_keyctl)
128                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
129 -/* vserver */  CALL(sys_ni_syscall)
130 +               CALL(sys_vserver)
131                 CALL(sys_ioprio_set)
132  /* 315 */      CALL(sys_ioprio_get)
133                 CALL(sys_inotify_init)
134 diff -NurpP --minimal linux-2.6.27.3/arch/arm/kernel/process.c linux-2.6.27.3-vs2.3.0.35.7/arch/arm/kernel/process.c
135 --- linux-2.6.27.3/arch/arm/kernel/process.c    2008-10-13 14:51:52.000000000 +0200
136 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/arm/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/arm/kernel/traps.c
148 --- linux-2.6.27.3/arch/arm/kernel/traps.c      2008-10-13 14:51:52.000000000 +0200
149 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/arm/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/arm/mm/fault.c
162 --- linux-2.6.27.3/arch/arm/mm/fault.c  2008-07-13 23:51:29.000000000 +0200
163 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/cris/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/cris/Kconfig
175 --- linux-2.6.27.3/arch/cris/Kconfig    2008-07-13 23:51:29.000000000 +0200
176 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/frv/kernel/kernel_thread.S linux-2.6.27.3-vs2.3.0.35.7/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.27.3/arch/frv/kernel/kernel_thread.S      2008-07-13 23:51:29.000000000 +0200
188 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/h8300/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/h8300/Kconfig
199 --- linux-2.6.27.3/arch/h8300/Kconfig   2008-10-13 14:51:55.000000000 +0200
200 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/ia64/ia32/ia32_entry.S linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.27.3/arch/ia64/ia32/ia32_entry.S  2008-10-13 14:51:55.000000000 +0200
212 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/ia32/ia32_entry.S     2008-10-13 14:54:20.000000000 +0200
213 @@ -446,7 +446,7 @@ ia32_syscall_table:
214         data8 sys_tgkill        /* 270 */
215         data8 compat_sys_utimes
216         data8 sys32_fadvise64_64
217 -       data8 sys_ni_syscall
218 +       data8 sys32_vserver
219         data8 sys_ni_syscall
220         data8 sys_ni_syscall    /* 275 */
221         data8 sys_ni_syscall
222 diff -NurpP --minimal linux-2.6.27.3/arch/ia64/ia32/sys_ia32.c linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/ia32/sys_ia32.c
223 --- linux-2.6.27.3/arch/ia64/ia32/sys_ia32.c    2008-10-13 14:51:55.000000000 +0200
224 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/ia64/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/Kconfig
235 --- linux-2.6.27.3/arch/ia64/Kconfig    2008-10-13 14:51:55.000000000 +0200
236 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/Kconfig       2008-10-13 14:54:20.000000000 +0200
237 @@ -639,6 +639,8 @@ source "arch/ia64/hp/sim/Kconfig"
238  
239  source "arch/ia64/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-2.6.27.3/arch/ia64/kernel/entry.S linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/kernel/entry.S
247 --- linux-2.6.27.3/arch/ia64/kernel/entry.S     2008-10-13 14:51:55.000000000 +0200
248 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/kernel/entry.S        2008-10-13 14:54:20.000000000 +0200
249 @@ -1647,7 +1647,7 @@ sys_call_table:
250         data8 sys_mq_notify
251         data8 sys_mq_getsetattr
252         data8 sys_kexec_load
253 -       data8 sys_ni_syscall                    // reserved for vserver
254 +       data8 sys_vserver
255         data8 sys_waitid                        // 1270
256         data8 sys_add_key
257         data8 sys_request_key
258 diff -NurpP --minimal linux-2.6.27.3/arch/ia64/kernel/perfmon.c linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/kernel/perfmon.c
259 --- linux-2.6.27.3/arch/ia64/kernel/perfmon.c   2008-10-13 14:51:55.000000000 +0200
260 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/ia64/kernel/process.c linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/kernel/process.c
279 --- linux-2.6.27.3/arch/ia64/kernel/process.c   2008-10-13 14:51:55.000000000 +0200
280 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/ia64/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/kernel/ptrace.c
293 --- linux-2.6.27.3/arch/ia64/kernel/ptrace.c    2008-07-13 23:51:29.000000000 +0200
294 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/ia64/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/kernel/traps.c
304 --- linux-2.6.27.3/arch/ia64/kernel/traps.c     2008-07-13 23:51:29.000000000 +0200
305 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/ia64/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/ia64/mm/fault.c
331 --- linux-2.6.27.3/arch/ia64/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
332 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/m32r/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/m32r/kernel/traps.c
342 --- linux-2.6.27.3/arch/m32r/kernel/traps.c     2008-10-13 14:51:55.000000000 +0200
343 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/m68k/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/m68k/Kconfig
357 --- linux-2.6.27.3/arch/m68k/Kconfig    2008-10-13 14:51:55.000000000 +0200
358 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/m68k/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/m68k/kernel/ptrace.c
369 --- linux-2.6.27.3/arch/m68k/kernel/ptrace.c    2008-07-13 23:51:29.000000000 +0200
370 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/m68k/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/m68k/kernel/traps.c
389 --- linux-2.6.27.3/arch/m68k/kernel/traps.c     2008-07-13 23:51:29.000000000 +0200
390 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/m68knommu/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/m68knommu/Kconfig
403 --- linux-2.6.27.3/arch/m68knommu/Kconfig       2008-10-13 14:51:55.000000000 +0200
404 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/m68knommu/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/m68knommu/kernel/traps.c
415 --- linux-2.6.27.3/arch/m68knommu/kernel/traps.c        2008-10-13 14:51:55.000000000 +0200
416 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/mips/Kconfig
430 --- linux-2.6.27.3/arch/mips/Kconfig    2008-10-13 14:51:55.000000000 +0200
431 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/kernel/linux32.c linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/linux32.c
442 --- linux-2.6.27.3/arch/mips/kernel/linux32.c   2008-10-13 14:51:56.000000000 +0200
443 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/ptrace.c
454 --- linux-2.6.27.3/arch/mips/kernel/ptrace.c    2008-10-13 14:51:56.000000000 +0200
455 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/kernel/scall32-o32.S linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/scall32-o32.S
475 --- linux-2.6.27.3/arch/mips/kernel/scall32-o32.S       2008-10-13 14:51:56.000000000 +0200
476 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/scall32-o32.S  2008-10-13 14:54:20.000000000 +0200
477 @@ -600,7 +600,7 @@ einval:     li      v0, -EINVAL
478         sys     sys_mq_timedreceive     5
479         sys     sys_mq_notify           2       /* 4275 */
480         sys     sys_mq_getsetattr       3
481 -       sys     sys_ni_syscall          0       /* sys_vserver */
482 +       sys     sys_vserver             3
483         sys     sys_waitid              5
484         sys     sys_ni_syscall          0       /* available, was setaltroot */
485         sys     sys_add_key             5       /* 4280 */
486 diff -NurpP --minimal linux-2.6.27.3/arch/mips/kernel/scall64-64.S linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/scall64-64.S
487 --- linux-2.6.27.3/arch/mips/kernel/scall64-64.S        2008-10-13 14:51:56.000000000 +0200
488 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/kernel/scall64-n32.S linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/scall64-n32.S
499 --- linux-2.6.27.3/arch/mips/kernel/scall64-n32.S       2008-10-13 14:51:56.000000000 +0200
500 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/kernel/scall64-o32.S linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/scall64-o32.S
511 --- linux-2.6.27.3/arch/mips/kernel/scall64-o32.S       2008-10-13 14:51:56.000000000 +0200
512 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/mips/kernel/traps.c
523 --- linux-2.6.27.3/arch/mips/kernel/traps.c     2008-10-13 14:51:56.000000000 +0200
524 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/mips/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/mips/mm/fault.c
540 --- linux-2.6.27.3/arch/mips/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
541 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/parisc/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/parisc/Kconfig
553 --- linux-2.6.27.3/arch/parisc/Kconfig  2008-10-13 14:51:56.000000000 +0200
554 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/parisc/kernel/syscall_table.S linux-2.6.27.3-vs2.3.0.35.7/arch/parisc/kernel/syscall_table.S
565 --- linux-2.6.27.3/arch/parisc/kernel/syscall_table.S   2008-07-13 23:51:29.000000000 +0200
566 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/parisc/kernel/sys_parisc32.c linux-2.6.27.3-vs2.3.0.35.7/arch/parisc/kernel/sys_parisc32.c
577 --- linux-2.6.27.3/arch/parisc/kernel/sys_parisc32.c    2008-07-13 23:51:29.000000000 +0200
578 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/parisc/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/parisc/kernel/traps.c
594 --- linux-2.6.27.3/arch/parisc/kernel/traps.c   2008-07-13 23:51:29.000000000 +0200
595 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/parisc/kernel/traps.c      2008-10-13 14:54:20.000000000 +0200
596 @@ -237,8 +237,9 @@ void die_if_kernel(char *str, struct pt_
597                 if (err == 0)
598                         return; /* STFU */
599  
600 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
601 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
602 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
603 +                       current->comm, task_pid_nr(current), current->xid,
604 +                       str, err, regs->iaoq[0]);
605  #ifdef PRINT_USER_FAULTS
606                 /* XXX for debugging only */
607                 show_regs(regs);
608 @@ -270,8 +271,8 @@ KERN_CRIT "                     ||     |
609                 pdc_console_restart();
610         
611         if (err)
612 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
613 -                       current->comm, task_pid_nr(current), str, err);
614 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
615 +                       current->comm, task_pid_nr(current), current->xid, str, err);
616  
617         /* Wot's wrong wif bein' racy? */
618         if (current->thread.flags & PARISC_KERNEL_DEATH) {
619 diff -NurpP --minimal linux-2.6.27.3/arch/parisc/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/parisc/mm/fault.c
620 --- linux-2.6.27.3/arch/parisc/mm/fault.c       2008-07-13 23:51:29.000000000 +0200
621 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/powerpc/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/Kconfig
645 --- linux-2.6.27.3/arch/powerpc/Kconfig 2008-10-13 14:51:56.000000000 +0200
646 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/Kconfig    2008-10-13 14:54:20.000000000 +0200
647 @@ -835,6 +835,8 @@ source "lib/Kconfig"
648  
649  source "arch/powerpc/Kconfig.debug"
650  
651 +source "kernel/vserver/Kconfig"
652 +
653  source "security/Kconfig"
654  
655  config KEYS_COMPAT
656 diff -NurpP --minimal linux-2.6.27.3/arch/powerpc/kernel/irq.c linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/kernel/irq.c
657 --- linux-2.6.27.3/arch/powerpc/kernel/irq.c    2008-10-13 14:51:56.000000000 +0200
658 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/powerpc/kernel/process.c linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/kernel/process.c
668 --- linux-2.6.27.3/arch/powerpc/kernel/process.c        2008-10-13 14:51:56.000000000 +0200
669 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/powerpc/kernel/sys_ppc32.c linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/kernel/sys_ppc32.c
683 --- linux-2.6.27.3/arch/powerpc/kernel/sys_ppc32.c      2008-10-13 14:51:56.000000000 +0200
684 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/powerpc/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/kernel/traps.c
695 --- linux-2.6.27.3/arch/powerpc/kernel/traps.c  2008-10-13 14:51:56.000000000 +0200
696 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/powerpc/kernel/vdso.c linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/kernel/vdso.c
710 --- linux-2.6.27.3/arch/powerpc/kernel/vdso.c   2008-10-13 14:51:56.000000000 +0200
711 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/powerpc/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/powerpc/mm/fault.c
721 --- linux-2.6.27.3/arch/powerpc/mm/fault.c      2008-10-13 14:51:56.000000000 +0200
722 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/s390/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/s390/Kconfig
734 --- linux-2.6.27.3/arch/s390/Kconfig    2008-10-13 14:51:57.000000000 +0200
735 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/s390/Kconfig       2008-10-13 14:54:20.000000000 +0200
736 @@ -587,6 +587,8 @@ source "fs/Kconfig"
737  
738  source "arch/s390/Kconfig.debug"
739  
740 +source "kernel/vserver/Kconfig"
741 +
742  source "security/Kconfig"
743  
744  source "crypto/Kconfig"
745 diff -NurpP --minimal linux-2.6.27.3/arch/s390/kernel/compat_linux.c linux-2.6.27.3-vs2.3.0.35.7/arch/s390/kernel/compat_linux.c
746 --- linux-2.6.27.3/arch/s390/kernel/compat_linux.c      2008-07-13 23:51:29.000000000 +0200
747 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/s390/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/s390/kernel/ptrace.c
758 --- linux-2.6.27.3/arch/s390/kernel/ptrace.c    2008-10-13 14:51:57.000000000 +0200
759 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/s390/kernel/syscalls.S linux-2.6.27.3-vs2.3.0.35.7/arch/s390/kernel/syscalls.S
769 --- linux-2.6.27.3/arch/s390/kernel/syscalls.S  2008-10-13 14:51:57.000000000 +0200
770 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/s390/kernel/syscalls.S     2008-10-13 14:54:20.000000000 +0200
771 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
772  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
773  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
774  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
775 -NI_SYSCALL                                                     /* reserved for vserver */
776 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
777  SYSCALL(s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
778  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
779  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
780 diff -NurpP --minimal linux-2.6.27.3/arch/s390/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/s390/mm/fault.c
781 --- linux-2.6.27.3/arch/s390/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
782 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sh/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/sh/Kconfig
794 --- linux-2.6.27.3/arch/sh/Kconfig      2008-10-13 14:51:57.000000000 +0200
795 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sh/kernel/irq.c linux-2.6.27.3-vs2.3.0.35.7/arch/sh/kernel/irq.c
806 --- linux-2.6.27.3/arch/sh/kernel/irq.c 2008-10-13 14:51:57.000000000 +0200
807 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.27.3-vs2.3.0.35.7/arch/sh/kernel/vsyscall/vsyscall.c
817 --- linux-2.6.27.3/arch/sh/kernel/vsyscall/vsyscall.c   2008-07-13 23:51:29.000000000 +0200
818 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/sparc/Kconfig
828 --- linux-2.6.27.3/arch/sparc/Kconfig   2008-10-13 14:51:58.000000000 +0200
829 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc/kernel/ptrace.c
840 --- linux-2.6.27.3/arch/sparc/kernel/ptrace.c   2008-10-13 14:51:58.000000000 +0200
841 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc/kernel/systbls.S linux-2.6.27.3-vs2.3.0.35.7/arch/sparc/kernel/systbls.S
851 --- linux-2.6.27.3/arch/sparc/kernel/systbls.S  2008-10-13 14:51:58.000000000 +0200
852 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/sparc/kernel/systbls.S     2008-10-13 14:54:20.000000000 +0200
853 @@ -70,7 +70,7 @@ sys_call_table:
854  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
855  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
856  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
857 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
858 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
859  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
860  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
861  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
862 diff -NurpP --minimal linux-2.6.27.3/arch/sparc/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc/kernel/traps.c
863 --- linux-2.6.27.3/arch/sparc/kernel/traps.c    2008-10-13 14:51:58.000000000 +0200
864 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc/mm/fault.c
876 --- linux-2.6.27.3/arch/sparc/mm/fault.c        2008-10-13 14:51:58.000000000 +0200
877 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc64/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/Kconfig
889 --- linux-2.6.27.3/arch/sparc64/Kconfig 2008-10-13 14:51:58.000000000 +0200
890 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc64/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/kernel/ptrace.c
901 --- linux-2.6.27.3/arch/sparc64/kernel/ptrace.c 2008-10-13 14:51:58.000000000 +0200
902 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/kernel/ptrace.c    2008-10-13 14:54:20.000000000 +0200
903 @@ -26,6 +26,7 @@
904  #include <linux/tracehook.h>
905  #include <linux/compat.h>
906  #include <linux/elf.h>
907 +#include <linux/vs_base.h>
908  
909  #include <asm/asi.h>
910  #include <asm/pgtable.h>
911 diff -NurpP --minimal linux-2.6.27.3/arch/sparc64/kernel/sys_sparc32.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/kernel/sys_sparc32.c
912 --- linux-2.6.27.3/arch/sparc64/kernel/sys_sparc32.c    2008-10-13 14:51:58.000000000 +0200
913 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc64/kernel/systbls.S linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/kernel/systbls.S
924 --- linux-2.6.27.3/arch/sparc64/kernel/systbls.S        2008-10-13 14:51:58.000000000 +0200
925 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/kernel/systbls.S   2008-10-13 14:54:20.000000000 +0200
926 @@ -71,7 +71,7 @@ sys_call_table32:
927  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
928         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
929  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
930 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
931 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
932  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
933         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
934  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
935 @@ -145,7 +145,7 @@ sys_call_table:
936  /*250*/        .word sys64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
937         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
938  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
939 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
940 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
941  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
942         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
943  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
944 diff -NurpP --minimal linux-2.6.27.3/arch/sparc64/kernel/traps.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/kernel/traps.c
945 --- linux-2.6.27.3/arch/sparc64/kernel/traps.c  2008-10-13 14:51:58.000000000 +0200
946 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/sparc64/mm/fault.c linux-2.6.27.3-vs2.3.0.35.7/arch/sparc64/mm/fault.c
958 --- linux-2.6.27.3/arch/sparc64/mm/fault.c      2008-10-13 14:51:58.000000000 +0200
959 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/um/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/um/Kconfig
971 --- linux-2.6.27.3/arch/um/Kconfig      2008-07-13 23:51:29.000000000 +0200
972 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/um/kernel/trap.c linux-2.6.27.3-vs2.3.0.35.7/arch/um/kernel/trap.c
983 --- linux-2.6.27.3/arch/um/kernel/trap.c        2008-07-13 23:51:29.000000000 +0200
984 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/x86/ia32/ia32entry.S linux-2.6.27.3-vs2.3.0.35.7/arch/x86/ia32/ia32entry.S
996 --- linux-2.6.27.3/arch/x86/ia32/ia32entry.S    2008-10-13 14:51:58.000000000 +0200
997 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/arch/x86/Kconfig linux-2.6.27.3-vs2.3.0.35.7/arch/x86/Kconfig
1008 --- linux-2.6.27.3/arch/x86/Kconfig     2008-10-13 14:51:58.000000000 +0200
1009 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/x86/Kconfig        2008-10-13 14:54:20.000000000 +0200
1010 @@ -1788,6 +1788,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.3/arch/x86/kernel/syscall_table_32.S linux-2.6.27.3-vs2.3.0.35.7/arch/x86/kernel/syscall_table_32.S
1020 --- linux-2.6.27.3/arch/x86/kernel/syscall_table_32.S   2008-10-13 14:51:58.000000000 +0200
1021 +++ linux-2.6.27.3-vs2.3.0.35.7/arch/x86/kernel/syscall_table_32.S      2008-10-13 14:54:20.000000000 +0200
1022 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1023         .long sys_tgkill        /* 270 */
1024         .long sys_utimes
1025         .long sys_fadvise64_64
1026 -       .long sys_ni_syscall    /* sys_vserver */
1027 +       .long sys_vserver
1028         .long sys_mbind
1029         .long sys_get_mempolicy
1030         .long sys_set_mempolicy
1031 diff -NurpP --minimal linux-2.6.27.3/Documentation/vserver/debug.txt linux-2.6.27.3-vs2.3.0.35.7/Documentation/vserver/debug.txt
1032 --- linux-2.6.27.3/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
1033 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/block/Kconfig linux-2.6.27.3-vs2.3.0.35.7/drivers/block/Kconfig
1190 --- linux-2.6.27.3/drivers/block/Kconfig        2008-10-13 14:51:59.000000000 +0200
1191 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/block/loop.c linux-2.6.27.3-vs2.3.0.35.7/drivers/block/loop.c
1207 --- linux-2.6.27.3/drivers/block/loop.c 2008-07-13 23:51:29.000000000 +0200
1208 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/block/Makefile linux-2.6.27.3-vs2.3.0.35.7/drivers/block/Makefile
1263 --- linux-2.6.27.3/drivers/block/Makefile       2008-10-13 14:51:59.000000000 +0200
1264 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/block/vroot.c linux-2.6.27.3-vs2.3.0.35.7/drivers/block/vroot.c
1273 --- linux-2.6.27.3/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1274 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/char/sysrq.c linux-2.6.27.3-vs2.3.0.35.7/drivers/char/sysrq.c
1560 --- linux-2.6.27.3/drivers/char/sysrq.c 2008-10-13 14:51:59.000000000 +0200
1561 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/char/tty_io.c linux-2.6.27.3-vs2.3.0.35.7/drivers/char/tty_io.c
1615 --- linux-2.6.27.3/drivers/char/tty_io.c        2008-10-24 02:21:28.000000000 +0200
1616 +++ linux-2.6.27.3-vs2.3.0.35.7/drivers/char/tty_io.c   2008-10-24 02:21:46.000000000 +0200
1617 @@ -106,6 +106,7 @@
1618  
1619  #include <linux/kmod.h>
1620  #include <linux/nsproxy.h>
1621 +#include <linux/vs_pid.h>
1622  
1623  #undef TTY_DEBUG_HANGUP
1624  
1625 @@ -2770,6 +2771,7 @@ static int tiocspgrp(struct tty_struct *
1626                 return -ENOTTY;
1627         if (get_user(pgrp_nr, p))
1628                 return -EFAULT;
1629 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1630         if (pgrp_nr < 0)
1631                 return -EINVAL;
1632         rcu_read_lock();
1633 diff -NurpP --minimal linux-2.6.27.3/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.27.3-vs2.3.0.35.7/drivers/infiniband/hw/ipath/ipath_user_pages.c
1634 --- linux-2.6.27.3/drivers/infiniband/hw/ipath/ipath_user_pages.c       2008-07-13 23:51:29.000000000 +0200
1635 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/md/dm.c linux-2.6.27.3-vs2.3.0.35.7/drivers/md/dm.c
1682 --- linux-2.6.27.3/drivers/md/dm.c      2008-10-13 14:52:01.000000000 +0200
1683 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/md/dm.h linux-2.6.27.3-vs2.3.0.35.7/drivers/md/dm.h
1758 --- linux-2.6.27.3/drivers/md/dm.h      2008-10-13 14:52:01.000000000 +0200
1759 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/md/dm-ioctl.c linux-2.6.27.3-vs2.3.0.35.7/drivers/md/dm-ioctl.c
1770 --- linux-2.6.27.3/drivers/md/dm-ioctl.c        2008-07-13 23:51:29.000000000 +0200
1771 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/drivers/net/tun.c linux-2.6.27.3-vs2.3.0.35.7/drivers/net/tun.c
1854 --- linux-2.6.27.3/drivers/net/tun.c    2008-10-13 14:52:02.000000000 +0200
1855 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/attr.c linux-2.6.27.3-vs2.3.0.35.7/fs/attr.c
1926 --- linux-2.6.27.3/fs/attr.c    2008-10-13 14:52:05.000000000 +0200
1927 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/binfmt_aout.c linux-2.6.27.3-vs2.3.0.35.7/fs/binfmt_aout.c
1969 --- linux-2.6.27.3/fs/binfmt_aout.c     2008-10-13 14:52:05.000000000 +0200
1970 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/binfmt_elf.c linux-2.6.27.3-vs2.3.0.35.7/fs/binfmt_elf.c
1980 --- linux-2.6.27.3/fs/binfmt_elf.c      2008-10-13 14:52:05.000000000 +0200
1981 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/binfmt_flat.c linux-2.6.27.3-vs2.3.0.35.7/fs/binfmt_flat.c
1991 --- linux-2.6.27.3/fs/binfmt_flat.c     2008-10-13 14:52:05.000000000 +0200
1992 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/binfmt_som.c linux-2.6.27.3-vs2.3.0.35.7/fs/binfmt_som.c
2002 --- linux-2.6.27.3/fs/binfmt_som.c      2008-10-13 14:52:05.000000000 +0200
2003 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/block_dev.c linux-2.6.27.3-vs2.3.0.35.7/fs/block_dev.c
2013 --- linux-2.6.27.3/fs/block_dev.c       2008-10-13 14:52:05.000000000 +0200
2014 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/char_dev.c linux-2.6.27.3-vs2.3.0.35.7/fs/char_dev.c
2053 --- linux-2.6.27.3/fs/char_dev.c        2008-10-13 14:52:05.000000000 +0200
2054 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/dcache.c linux-2.6.27.3-vs2.3.0.35.7/fs/dcache.c
2088 --- linux-2.6.27.3/fs/dcache.c  2008-10-13 14:52:05.000000000 +0200
2089 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/dcache.c     2008-10-24 03:34:52.000000000 +0200
2090 @@ -32,6 +32,7 @@
2091  #include <linux/seqlock.h>
2092  #include <linux/swap.h>
2093  #include <linux/bootmem.h>
2094 +#include <linux/vs_limit.h>
2095  #include "internal.h"
2096  
2097  
2098 @@ -226,6 +227,8 @@ repeat:
2099                 return;
2100         }
2101  
2102 +       vx_dentry_dec(dentry);
2103 +
2104         /*
2105          * AV: ->d_delete() is _NOT_ allowed to block now.
2106          */
2107 @@ -317,6 +320,7 @@ static inline struct dentry * __dget_loc
2108  {
2109         atomic_inc(&dentry->d_count);
2110         dentry_lru_del_init(dentry);
2111 +       vx_dentry_inc(dentry);
2112         return dentry;
2113  }
2114  
2115 @@ -914,6 +918,9 @@ struct dentry *d_alloc(struct dentry * p
2116         struct dentry *dentry;
2117         char *dname;
2118  
2119 +       if (!vx_dentry_avail(1))
2120 +               return NULL;
2121 +
2122         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2123         if (!dentry)
2124                 return NULL;
2125 @@ -962,6 +969,7 @@ struct dentry *d_alloc(struct dentry * p
2126         if (parent)
2127                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2128         dentry_stat.nr_dentry++;
2129 +       vx_dentry_inc(dentry);
2130         spin_unlock(&dcache_lock);
2131  
2132         return dentry;
2133 @@ -1415,6 +1423,7 @@ struct dentry * __d_lookup(struct dentry
2134                 }
2135  
2136                 atomic_inc(&dentry->d_count);
2137 +               vx_dentry_inc(dentry);
2138                 found = dentry;
2139                 spin_unlock(&dentry->d_lock);
2140                 break;
2141 diff -NurpP --minimal linux-2.6.27.3/fs/devpts/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/devpts/inode.c
2142 --- linux-2.6.27.3/fs/devpts/inode.c    2008-10-13 14:52:05.000000000 +0200
2143 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/exec.c linux-2.6.27.3-vs2.3.0.35.7/fs/exec.c
2225 --- linux-2.6.27.3/fs/exec.c    2008-10-13 14:52:05.000000000 +0200
2226 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/exec.c       2008-10-13 14:54:20.000000000 +0200
2227 @@ -263,7 +263,9 @@ static int __bprm_mm_init(struct linux_b
2228                 goto err;
2229         }
2230  
2231 -       mm->stack_vm = mm->total_vm = 1;
2232 +       mm->total_vm = 0;
2233 +       vx_vmpages_inc(mm);
2234 +       mm->stack_vm = 1;
2235         up_write(&mm->mmap_sem);
2236  
2237         bprm->p = vma->vm_end - sizeof(void *);
2238 @@ -1453,7 +1455,7 @@ static int format_corename(char *corenam
2239                         /* UNIX time of coredump */
2240                         case 't': {
2241                                 struct timeval tv;
2242 -                               do_gettimeofday(&tv);
2243 +                               vx_gettimeofday(&tv);
2244                                 rc = snprintf(out_ptr, out_end - out_ptr,
2245                                               "%lu", tv.tv_sec);
2246                                 if (rc > out_end - out_ptr)
2247 diff -NurpP --minimal linux-2.6.27.3/fs/ext2/balloc.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/balloc.c
2248 --- linux-2.6.27.3/fs/ext2/balloc.c     2008-07-13 23:51:29.000000000 +0200
2249 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/balloc.c        2008-10-13 14:54:20.000000000 +0200
2250 @@ -16,6 +16,8 @@
2251  #include <linux/sched.h>
2252  #include <linux/buffer_head.h>
2253  #include <linux/capability.h>
2254 +#include <linux/vs_dlimit.h>
2255 +#include <linux/vs_tag.h>
2256  
2257  /*
2258   * balloc.c contains the blocks allocation and deallocation routines
2259 @@ -569,6 +571,7 @@ do_more:
2260         }
2261  error_return:
2262         brelse(bitmap_bh);
2263 +       DLIMIT_FREE_BLOCK(inode, freed);
2264         release_blocks(sb, freed);
2265         DQUOT_FREE_BLOCK(inode, freed);
2266  }
2267 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2268                         start = 0;
2269                 end = EXT2_BLOCKS_PER_GROUP(sb);
2270         }
2271 -
2272         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2273  
2274  repeat:
2275 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2276                 *errp = -EDQUOT;
2277                 return 0;
2278         }
2279 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2280 +               *errp = -ENOSPC;
2281 +               DQUOT_FREE_BLOCK(inode, num);
2282 +               return 0;
2283 +       }
2284  
2285         sbi = EXT2_SB(sb);
2286         es = EXT2_SB(sb)->s_es;
2287 @@ -1408,6 +1415,7 @@ allocated:
2288  
2289         *errp = 0;
2290         brelse(bitmap_bh);
2291 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2292         DQUOT_FREE_BLOCK(inode, *count-num);
2293         *count = num;
2294         return ret_block;
2295 @@ -1418,8 +1426,10 @@ out:
2296         /*
2297          * Undo the block allocation
2298          */
2299 -       if (!performed_allocation)
2300 +       if (!performed_allocation) {
2301 +               DLIMIT_FREE_BLOCK(inode, *count);
2302                 DQUOT_FREE_BLOCK(inode, *count);
2303 +       }
2304         brelse(bitmap_bh);
2305         return 0;
2306  }
2307 diff -NurpP --minimal linux-2.6.27.3/fs/ext2/ext2.h linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/ext2.h
2308 --- linux-2.6.27.3/fs/ext2/ext2.h       2008-07-13 23:51:29.000000000 +0200
2309 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/file.c
2319 --- linux-2.6.27.3/fs/ext2/file.c       2008-07-13 23:51:29.000000000 +0200
2320 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/ialloc.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/ialloc.c
2328 --- linux-2.6.27.3/fs/ext2/ialloc.c     2008-07-13 23:51:29.000000000 +0200
2329 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/inode.c
2386 --- linux-2.6.27.3/fs/ext2/inode.c      2008-10-13 14:52:05.000000000 +0200
2387 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/ioctl.c
2548 --- linux-2.6.27.3/fs/ext2/ioctl.c      2008-07-13 23:51:29.000000000 +0200
2549 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/namei.c
2582 --- linux-2.6.27.3/fs/ext2/namei.c      2008-07-13 23:51:29.000000000 +0200
2583 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/super.c
2615 --- linux-2.6.27.3/fs/ext2/super.c      2008-10-13 14:52:05.000000000 +0200
2616 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/symlink.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/symlink.c
2682 --- linux-2.6.27.3/fs/ext2/symlink.c    2008-07-13 23:51:29.000000000 +0200
2683 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext2/xattr.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext2/xattr.c
2699 --- linux-2.6.27.3/fs/ext2/xattr.c      2008-07-13 23:51:29.000000000 +0200
2700 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext3/balloc.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/balloc.c
2739 --- linux-2.6.27.3/fs/ext3/balloc.c     2008-07-13 23:51:29.000000000 +0200
2740 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/balloc.c        2008-10-13 14:54:20.000000000 +0200
2741 @@ -19,6 +19,8 @@
2742  #include <linux/ext3_jbd.h>
2743  #include <linux/quotaops.h>
2744  #include <linux/buffer_head.h>
2745 +#include <linux/vs_dlimit.h>
2746 +#include <linux/vs_tag.h>
2747  
2748  /*
2749   * balloc.c contains the blocks allocation and deallocation routines
2750 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2751                 return;
2752         }
2753         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2754 -       if (dquot_freed_blocks)
2755 +       if (dquot_freed_blocks) {
2756 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2757                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2758 +       }
2759         return;
2760  }
2761  
2762 @@ -1415,18 +1419,33 @@ out:
2763   *
2764   * Check if filesystem has at least 1 free block available for allocation.
2765   */
2766 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2767 +static int ext3_has_free_blocks(struct super_block *sb)
2768  {
2769 -       ext3_fsblk_t free_blocks, root_blocks;
2770 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2771 +       unsigned long long free_blocks, root_blocks;
2772 +       int cond;
2773  
2774         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2775         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2776 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2777 +
2778 +       vxdprintk(VXD_CBIT(dlim, 3),
2779 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2780 +               sb, free_blocks, root_blocks);
2781 +
2782 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2783 +
2784 +       cond = (free_blocks < root_blocks + 1 &&
2785 +               !capable(CAP_SYS_RESOURCE) &&
2786                 sbi->s_resuid != current->fsuid &&
2787 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2788 -               return 0;
2789 -       }
2790 -       return 1;
2791 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2792 +
2793 +       vxdprintk(VXD_CBIT(dlim, 3),
2794 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2795 +               sb, free_blocks, root_blocks,
2796 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2797 +               sbi->s_resuid, current->fsuid, cond?0:1);
2798 +
2799 +       return (cond ? 0 : 1);
2800  }
2801  
2802  /**
2803 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2804   */
2805  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2806  {
2807 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2808 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2809                 return 0;
2810  
2811         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2812 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2813                 *errp = -EDQUOT;
2814                 return 0;
2815         }
2816 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2817 +           goto out_dlimit;
2818  
2819         sbi = EXT3_SB(sb);
2820         es = EXT3_SB(sb)->s_es;
2821 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2822         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2823                 my_rsv = &block_i->rsv_window_node;
2824  
2825 -       if (!ext3_has_free_blocks(sbi)) {
2826 +       if (!ext3_has_free_blocks(sb)) {
2827                 *errp = -ENOSPC;
2828                 goto out;
2829         }
2830 @@ -1714,12 +1735,16 @@ allocated:
2831         *errp = 0;
2832         brelse(bitmap_bh);
2833         DQUOT_FREE_BLOCK(inode, *count-num);
2834 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2835         *count = num;
2836         return ret_block;
2837  
2838  io_error:
2839         *errp = -EIO;
2840  out:
2841 +       if (!performed_allocation)
2842 +               DLIMIT_FREE_BLOCK(inode, *count);
2843 +out_dlimit:
2844         if (fatal) {
2845                 *errp = fatal;
2846                 ext3_std_error(sb, fatal);
2847 diff -NurpP --minimal linux-2.6.27.3/fs/ext3/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/file.c
2848 --- linux-2.6.27.3/fs/ext3/file.c       2008-07-13 23:51:29.000000000 +0200
2849 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext3/ialloc.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/ialloc.c
2858 --- linux-2.6.27.3/fs/ext3/ialloc.c     2008-10-13 14:52:05.000000000 +0200
2859 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext3/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/inode.c
2918 --- linux-2.6.27.3/fs/ext3/inode.c      2008-10-13 14:52:05.000000000 +0200
2919 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/inode.c 2008-10-13 14:54:20.000000000 +0200
2920 @@ -36,6 +36,7 @@
2921  #include <linux/mpage.h>
2922  #include <linux/uio.h>
2923  #include <linux/bio.h>
2924 +#include <linux/vs_tag.h>
2925  #include "xattr.h"
2926  #include "acl.h"
2927  
2928 @@ -2272,7 +2273,7 @@ static void ext3_free_branches(handle_t 
2929  
2930  int ext3_can_truncate(struct inode *inode)
2931  {
2932 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2933 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2934                 return 0;
2935         if (S_ISREG(inode->i_mode))
2936                 return 1;
2937 @@ -2646,36 +2647,84 @@ void ext3_set_inode_flags(struct inode *
2938  {
2939         unsigned int flags = EXT3_I(inode)->i_flags;
2940  
2941 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2942 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2943 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2944 +
2945 +       if (flags & EXT3_IMMUTABLE_FL)
2946 +               inode->i_flags |= S_IMMUTABLE;
2947 +       if (flags & EXT3_IXUNLINK_FL)
2948 +               inode->i_flags |= S_IXUNLINK;
2949 +
2950         if (flags & EXT3_SYNC_FL)
2951                 inode->i_flags |= S_SYNC;
2952         if (flags & EXT3_APPEND_FL)
2953                 inode->i_flags |= S_APPEND;
2954 -       if (flags & EXT3_IMMUTABLE_FL)
2955 -               inode->i_flags |= S_IMMUTABLE;
2956         if (flags & EXT3_NOATIME_FL)
2957                 inode->i_flags |= S_NOATIME;
2958         if (flags & EXT3_DIRSYNC_FL)
2959                 inode->i_flags |= S_DIRSYNC;
2960 +
2961 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2962 +
2963 +       if (flags & EXT3_BARRIER_FL)
2964 +               inode->i_vflags |= V_BARRIER;
2965 +       if (flags & EXT3_COW_FL)
2966 +               inode->i_vflags |= V_COW;
2967  }
2968  
2969  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2970  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2971  {
2972         unsigned int flags = ei->vfs_inode.i_flags;
2973 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2974 +
2975 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2976 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2977 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2978 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2979 +
2980 +       if (flags & S_IMMUTABLE)
2981 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2982 +       if (flags & S_IXUNLINK)
2983 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2984  
2985 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2986 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2987         if (flags & S_SYNC)
2988                 ei->i_flags |= EXT3_SYNC_FL;
2989         if (flags & S_APPEND)
2990                 ei->i_flags |= EXT3_APPEND_FL;
2991 -       if (flags & S_IMMUTABLE)
2992 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2993         if (flags & S_NOATIME)
2994                 ei->i_flags |= EXT3_NOATIME_FL;
2995         if (flags & S_DIRSYNC)
2996                 ei->i_flags |= EXT3_DIRSYNC_FL;
2997 +
2998 +       if (vflags & V_BARRIER)
2999 +               ei->i_flags |= EXT3_BARRIER_FL;
3000 +       if (vflags & V_COW)
3001 +               ei->i_flags |= EXT3_COW_FL;
3002 +}
3003 +
3004 +int ext3_sync_flags(struct inode *inode)
3005 +{
3006 +       struct ext3_iloc iloc;
3007 +       handle_t *handle;
3008 +       int err;
3009 +
3010 +       handle = ext3_journal_start(inode, 1);
3011 +       if (IS_ERR(handle))
3012 +               return PTR_ERR(handle);
3013 +       if (IS_SYNC(inode))
3014 +               handle->h_sync = 1;
3015 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3016 +       if (err)
3017 +               goto flags_err;
3018 +
3019 +       ext3_get_inode_flags(EXT3_I(inode));
3020 +       inode->i_ctime = CURRENT_TIME;
3021 +
3022 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3023 +flags_err:
3024 +       ext3_journal_stop(handle);
3025 +       return err;
3026  }
3027  
3028  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3029 @@ -2687,6 +2736,8 @@ struct inode *ext3_iget(struct super_blo
3030         struct inode *inode;
3031         long ret;
3032         int block;
3033 +       uid_t uid;
3034 +       gid_t gid;
3035  
3036         inode = iget_locked(sb, ino);
3037         if (!inode)
3038 @@ -2707,12 +2758,17 @@ struct inode *ext3_iget(struct super_blo
3039         bh = iloc.bh;
3040         raw_inode = ext3_raw_inode(&iloc);
3041         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3042 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3043 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3044 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3045 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3046         if(!(test_opt (inode->i_sb, NO_UID32))) {
3047 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3048 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3049 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3050 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3051         }
3052 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3053 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3054 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3055 +               le16_to_cpu(raw_inode->i_raw_tag));
3056 +
3057         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3058         inode->i_size = le32_to_cpu(raw_inode->i_size);
3059         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3060 @@ -2841,6 +2897,8 @@ static int ext3_do_update_inode(handle_t
3061         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3062         struct ext3_inode_info *ei = EXT3_I(inode);
3063         struct buffer_head *bh = iloc->bh;
3064 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3065 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3066         int err = 0, rc, block;
3067  
3068         /* For fields not not tracking in the in-memory inode,
3069 @@ -2851,29 +2909,32 @@ static int ext3_do_update_inode(handle_t
3070         ext3_get_inode_flags(ei);
3071         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3072         if(!(test_opt(inode->i_sb, NO_UID32))) {
3073 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3074 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3075 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3076 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3077  /*
3078   * Fix up interoperability with old kernels. Otherwise, old inodes get
3079   * re-used with the upper 16 bits of the uid/gid intact
3080   */
3081                 if(!ei->i_dtime) {
3082                         raw_inode->i_uid_high =
3083 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3084 +                               cpu_to_le16(high_16_bits(uid));
3085                         raw_inode->i_gid_high =
3086 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3087 +                               cpu_to_le16(high_16_bits(gid));
3088                 } else {
3089                         raw_inode->i_uid_high = 0;
3090                         raw_inode->i_gid_high = 0;
3091                 }
3092         } else {
3093                 raw_inode->i_uid_low =
3094 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3095 +                       cpu_to_le16(fs_high2lowuid(uid));
3096                 raw_inode->i_gid_low =
3097 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3098 +                       cpu_to_le16(fs_high2lowgid(gid));
3099                 raw_inode->i_uid_high = 0;
3100                 raw_inode->i_gid_high = 0;
3101         }
3102 +#ifdef CONFIG_TAGGING_INTERN
3103 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3104 +#endif
3105         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3106         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3107         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3108 @@ -3026,7 +3087,8 @@ int ext3_setattr(struct dentry *dentry, 
3109                 return error;
3110  
3111         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3112 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3113 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3114 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3115                 handle_t *handle;
3116  
3117                 /* (user+group)*(old+new) structure, inode write (sb,
3118 @@ -3048,6 +3110,8 @@ int ext3_setattr(struct dentry *dentry, 
3119                         inode->i_uid = attr->ia_uid;
3120                 if (attr->ia_valid & ATTR_GID)
3121                         inode->i_gid = attr->ia_gid;
3122 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3123 +                       inode->i_tag = attr->ia_tag;
3124                 error = ext3_mark_inode_dirty(handle, inode);
3125                 ext3_journal_stop(handle);
3126         }
3127 diff -NurpP --minimal linux-2.6.27.3/fs/ext3/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/ioctl.c
3128 --- linux-2.6.27.3/fs/ext3/ioctl.c      2008-07-13 23:51:29.000000000 +0200
3129 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext3/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/namei.c
3170 --- linux-2.6.27.3/fs/ext3/namei.c      2008-10-13 14:52:05.000000000 +0200
3171 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/namei.c 2008-10-13 14:54:20.000000000 +0200
3172 @@ -36,6 +36,7 @@
3173  #include <linux/quotaops.h>
3174  #include <linux/buffer_head.h>
3175  #include <linux/bio.h>
3176 +#include <linux/vs_tag.h>
3177  
3178  #include "namei.h"
3179  #include "xattr.h"
3180 @@ -912,6 +913,7 @@ restart:
3181                                 if (bh)
3182                                         ll_rw_block(READ_META, 1, &bh);
3183                         }
3184 +               dx_propagate_tag(nd, inode);
3185                 }
3186                 if ((bh = bh_use[ra_ptr++]) == NULL)
3187                         goto next;
3188 @@ -2426,6 +2428,7 @@ const struct inode_operations ext3_dir_i
3189         .removexattr    = generic_removexattr,
3190  #endif
3191         .permission     = ext3_permission,
3192 +       .sync_flags     = ext3_sync_flags,
3193  };
3194  
3195  const struct inode_operations ext3_special_inode_operations = {
3196 @@ -2437,4 +2440,5 @@ const struct inode_operations ext3_speci
3197         .removexattr    = generic_removexattr,
3198  #endif
3199         .permission     = ext3_permission,
3200 +       .sync_flags     = ext3_sync_flags,
3201  };
3202 diff -NurpP --minimal linux-2.6.27.3/fs/ext3/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/super.c
3203 --- linux-2.6.27.3/fs/ext3/super.c      2008-10-13 14:52:05.000000000 +0200
3204 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/super.c 2008-10-13 14:54:20.000000000 +0200
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 @@ -2447,6 +2467,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.3/fs/ext3/symlink.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/symlink.c
3270 --- linux-2.6.27.3/fs/ext3/symlink.c    2008-07-13 23:51:29.000000000 +0200
3271 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext3/xattr.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext3/xattr.c
3287 --- linux-2.6.27.3/fs/ext3/xattr.c      2008-07-13 23:51:29.000000000 +0200
3288 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext4/balloc.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/balloc.c
3331 --- linux-2.6.27.3/fs/ext4/balloc.c     2008-10-13 14:52:05.000000000 +0200
3332 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext4/ext4.h linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/ext4.h
3381 --- linux-2.6.27.3/fs/ext4/ext4.h       2008-10-13 14:52:05.000000000 +0200
3382 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/ext4.h  2008-10-24 03:34:52.000000000 +0200
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                        0x10000000 /* Barrier for chroot() */
3391 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3392 +
3393  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3394  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
3395  
3396 @@ -540,6 +544,7 @@ do {                                                                               \
3397  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3398  #define EXT4_MOUNT_MBALLOC             0x4000000 /* Buddy allocation support */
3399  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3400 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
3401  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
3402  #ifndef _LINUX_EXT2_FS_H
3403  #define clear_opt(o, opt)              o &= ~EXT4_MOUNT_##opt
3404 @@ -1054,6 +1059,7 @@ int ext4_get_blocks_handle(handle_t *han
3405                                 ext4_lblk_t iblock, unsigned long maxblocks,
3406                                 struct buffer_head *bh_result,
3407                                 int create, int extend_disksize);
3408 +extern int ext4_sync_flags(struct inode *inode);
3409  
3410  extern struct inode *ext4_iget(struct super_block *, unsigned long);
3411  extern int  ext4_write_inode (struct inode *, int);
3412 diff -NurpP --minimal linux-2.6.27.3/fs/ext4/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/file.c
3413 --- linux-2.6.27.3/fs/ext4/file.c       2008-10-13 14:52:05.000000000 +0200
3414 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext4/ialloc.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/ialloc.c
3423 --- linux-2.6.27.3/fs/ext4/ialloc.c     2008-10-13 14:52:05.000000000 +0200
3424 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/ialloc.c        2008-10-13 14:54:20.000000000 +0200
3425 @@ -22,6 +22,8 @@
3426  #include <linux/random.h>
3427  #include <linux/bitops.h>
3428  #include <linux/blkdev.h>
3429 +#include <linux/vs_dlimit.h>
3430 +#include <linux/vs_tag.h>
3431  #include <asm/byteorder.h>
3432  #include "ext4.h"
3433  #include "ext4_jbd2.h"
3434 @@ -196,6 +198,7 @@ void ext4_free_inode (handle_t *handle, 
3435         ext4_xattr_delete_inode(handle, inode);
3436         DQUOT_FREE_INODE(inode);
3437         DQUOT_DROP(inode);
3438 +       DLIMIT_FREE_INODE(inode);
3439  
3440         is_directory = S_ISDIR(inode->i_mode);
3441  
3442 @@ -602,6 +605,12 @@ struct inode *ext4_new_inode(handle_t *h
3443         inode = new_inode(sb);
3444         if (!inode)
3445                 return ERR_PTR(-ENOMEM);
3446 +
3447 +       inode->i_tag = dx_current_fstag(sb);
3448 +       if (DLIMIT_ALLOC_INODE(inode)) {
3449 +               err = -ENOSPC;
3450 +               goto out_dlimit;
3451 +       }
3452         ei = EXT4_I(inode);
3453  
3454         sbi = EXT4_SB(sb);
3455 @@ -808,7 +817,8 @@ got:
3456          * newly created directory and file only if -o extent mount option is
3457          * specified
3458          */
3459 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3460 +       ei->i_flags = EXT4_I(dir)->i_flags &
3461 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3462         if (S_ISLNK(mode))
3463                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3464         /* dirsync only applies to directories */
3465 @@ -864,6 +874,8 @@ got:
3466  fail:
3467         ext4_std_error(sb, err);
3468  out:
3469 +       DLIMIT_FREE_INODE(inode);
3470 +out_dlimit:
3471         iput(inode);
3472         ret = ERR_PTR(err);
3473  really_out:
3474 @@ -875,6 +887,7 @@ fail_free_drop:
3475  
3476  fail_drop:
3477         DQUOT_DROP(inode);
3478 +       DLIMIT_FREE_INODE(inode);
3479         inode->i_flags |= S_NOQUOTA;
3480         inode->i_nlink = 0;
3481         iput(inode);
3482 diff -NurpP --minimal linux-2.6.27.3/fs/ext4/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/inode.c
3483 --- linux-2.6.27.3/fs/ext4/inode.c      2008-10-13 14:52:05.000000000 +0200
3484 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/inode.c 2008-10-13 14:54:20.000000000 +0200
3485 @@ -36,6 +36,7 @@
3486  #include <linux/mpage.h>
3487  #include <linux/uio.h>
3488  #include <linux/bio.h>
3489 +#include <linux/vs_tag.h>
3490  #include "ext4_jbd2.h"
3491  #include "xattr.h"
3492  #include "acl.h"
3493 @@ -3483,7 +3484,7 @@ static void ext4_free_branches(handle_t 
3494  
3495  int ext4_can_truncate(struct inode *inode)
3496  {
3497 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3498 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3499                 return 0;
3500         if (S_ISREG(inode->i_mode))
3501                 return 1;
3502 @@ -3842,37 +3843,86 @@ void ext4_set_inode_flags(struct inode *
3503  {
3504         unsigned int flags = EXT4_I(inode)->i_flags;
3505  
3506 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3507 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3508 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3509 +
3510 +       if (flags & EXT4_IMMUTABLE_FL)
3511 +               inode->i_flags |= S_IMMUTABLE;
3512 +       if (flags & EXT4_IXUNLINK_FL)
3513 +               inode->i_flags |= S_IXUNLINK;
3514 +
3515         if (flags & EXT4_SYNC_FL)
3516                 inode->i_flags |= S_SYNC;
3517         if (flags & EXT4_APPEND_FL)
3518                 inode->i_flags |= S_APPEND;
3519 -       if (flags & EXT4_IMMUTABLE_FL)
3520 -               inode->i_flags |= S_IMMUTABLE;
3521         if (flags & EXT4_NOATIME_FL)
3522                 inode->i_flags |= S_NOATIME;
3523         if (flags & EXT4_DIRSYNC_FL)
3524                 inode->i_flags |= S_DIRSYNC;
3525 +
3526 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3527 +
3528 +       if (flags & EXT4_BARRIER_FL)
3529 +               inode->i_vflags |= V_BARRIER;
3530 +       if (flags & EXT4_COW_FL)
3531 +               inode->i_vflags |= V_COW;
3532  }
3533  
3534  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3535  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3536  {
3537         unsigned int flags = ei->vfs_inode.i_flags;
3538 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3539 +
3540 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3541 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3542 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3543 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3544 +
3545 +       if (flags & S_IMMUTABLE)
3546 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3547 +       if (flags & S_IXUNLINK)
3548 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3549  
3550 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3551 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3552         if (flags & S_SYNC)
3553                 ei->i_flags |= EXT4_SYNC_FL;
3554         if (flags & S_APPEND)
3555                 ei->i_flags |= EXT4_APPEND_FL;
3556 -       if (flags & S_IMMUTABLE)
3557 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3558         if (flags & S_NOATIME)
3559                 ei->i_flags |= EXT4_NOATIME_FL;
3560         if (flags & S_DIRSYNC)
3561                 ei->i_flags |= EXT4_DIRSYNC_FL;
3562 +
3563 +       if (vflags & V_BARRIER)
3564 +               ei->i_flags |= EXT4_BARRIER_FL;
3565 +       if (vflags & V_COW)
3566 +               ei->i_flags |= EXT4_COW_FL;
3567  }
3568 +
3569 +int ext4_sync_flags(struct inode *inode)
3570 +{
3571 +       struct ext4_iloc iloc;
3572 +       handle_t *handle;
3573 +       int err;
3574 +
3575 +       handle = ext4_journal_start(inode, 1);
3576 +       if (IS_ERR(handle))
3577 +               return PTR_ERR(handle);
3578 +       if (IS_SYNC(inode))
3579 +               handle->h_sync = 1;
3580 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3581 +       if (err)
3582 +               goto flags_err;
3583 +
3584 +       ext4_get_inode_flags(EXT4_I(inode));
3585 +       inode->i_ctime = CURRENT_TIME;
3586 +
3587 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3588 +flags_err:
3589 +       ext4_journal_stop(handle);
3590 +       return err;
3591 +}
3592 +
3593  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3594                                         struct ext4_inode_info *ei)
3595  {
3596 @@ -3905,6 +3955,8 @@ struct inode *ext4_iget(struct super_blo
3597         struct inode *inode;
3598         long ret;
3599         int block;
3600 +       uid_t uid;
3601 +       gid_t gid;
3602  
3603         inode = iget_locked(sb, ino);
3604         if (!inode)
3605 @@ -3925,12 +3977,17 @@ struct inode *ext4_iget(struct super_blo
3606         bh = iloc.bh;
3607         raw_inode = ext4_raw_inode(&iloc);
3608         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3609 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3610 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3611 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3612 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3613         if(!(test_opt (inode->i_sb, NO_UID32))) {
3614 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3615 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3616 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3617 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3618         }
3619 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3620 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3621 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3622 +               le16_to_cpu(raw_inode->i_raw_tag));
3623 +
3624         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3625  
3626         ei->i_state = 0;
3627 @@ -4104,6 +4161,8 @@ static int ext4_do_update_inode(handle_t
3628         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3629         struct ext4_inode_info *ei = EXT4_I(inode);
3630         struct buffer_head *bh = iloc->bh;
3631 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3632 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3633         int err = 0, rc, block;
3634  
3635         /* For fields not not tracking in the in-memory inode,
3636 @@ -4114,29 +4173,32 @@ static int ext4_do_update_inode(handle_t
3637         ext4_get_inode_flags(ei);
3638         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3639         if(!(test_opt(inode->i_sb, NO_UID32))) {
3640 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3641 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3642 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3643 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3644  /*
3645   * Fix up interoperability with old kernels. Otherwise, old inodes get
3646   * re-used with the upper 16 bits of the uid/gid intact
3647   */
3648                 if(!ei->i_dtime) {
3649                         raw_inode->i_uid_high =
3650 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3651 +                               cpu_to_le16(high_16_bits(uid));
3652                         raw_inode->i_gid_high =
3653 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3654 +                               cpu_to_le16(high_16_bits(gid));
3655                 } else {
3656                         raw_inode->i_uid_high = 0;
3657                         raw_inode->i_gid_high = 0;
3658                 }
3659         } else {
3660                 raw_inode->i_uid_low =
3661 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3662 +                       cpu_to_le16(fs_high2lowuid(uid));
3663                 raw_inode->i_gid_low =
3664 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3665 +                       cpu_to_le16(fs_high2lowgid(gid));
3666                 raw_inode->i_uid_high = 0;
3667                 raw_inode->i_gid_high = 0;
3668         }
3669 +#ifdef CONFIG_TAGGING_INTERN
3670 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3671 +#endif
3672         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3673  
3674         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3675 @@ -4300,7 +4362,8 @@ int ext4_setattr(struct dentry *dentry, 
3676                 return error;
3677  
3678         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3679 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3680 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3681 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3682                 handle_t *handle;
3683  
3684                 /* (user+group)*(old+new) structure, inode write (sb,
3685 @@ -4322,6 +4385,8 @@ int ext4_setattr(struct dentry *dentry, 
3686                         inode->i_uid = attr->ia_uid;
3687                 if (attr->ia_valid & ATTR_GID)
3688                         inode->i_gid = attr->ia_gid;
3689 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3690 +                       inode->i_tag = attr->ia_tag;
3691                 error = ext4_mark_inode_dirty(handle, inode);
3692                 ext4_journal_stop(handle);
3693         }
3694 diff -NurpP --minimal linux-2.6.27.3/fs/ext4/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/ioctl.c
3695 --- linux-2.6.27.3/fs/ext4/ioctl.c      2008-07-13 23:51:29.000000000 +0200
3696 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/ioctl.c 2008-10-13 14:54:20.000000000 +0200
3697 @@ -8,12 +8,14 @@
3698   */
3699  
3700  #include <linux/fs.h>
3701 +#include <linux/mount.h>
3702  #include <linux/jbd2.h>
3703  #include <linux/capability.h>
3704  #include <linux/time.h>
3705  #include <linux/compat.h>
3706  #include <linux/smp_lock.h>
3707  #include <linux/mount.h>
3708 +#include <linux/vs_tag.h>
3709  #include <asm/uaccess.h>
3710  #include "ext4_jbd2.h"
3711  #include "ext4.h"
3712 @@ -52,6 +54,11 @@ long ext4_ioctl(struct file *filp, unsig
3713                 if (!S_ISDIR(inode->i_mode))
3714                         flags &= ~EXT4_DIRSYNC_FL;
3715  
3716 +               if (IS_BARRIER(inode)) {
3717 +                       vxwprintk_task(1, "messing with the barrier.");
3718 +                       return -EACCES;
3719 +               }
3720 +
3721                 err = -EPERM;
3722                 mutex_lock(&inode->i_mutex);
3723                 /* Is it quota file? Do not allow user to mess with it */
3724 @@ -69,7 +76,9 @@ long ext4_ioctl(struct file *filp, unsig
3725                  *
3726                  * This test looks nicer. Thanks to Pauline Middelink
3727                  */
3728 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3729 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3730 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3731 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3732                         if (!capable(CAP_LINUX_IMMUTABLE))
3733                                 goto flags_out;
3734                 }
3735 diff -NurpP --minimal linux-2.6.27.3/fs/ext4/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/namei.c
3736 --- linux-2.6.27.3/fs/ext4/namei.c      2008-10-13 14:52:05.000000000 +0200
3737 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/namei.c 2008-10-13 14:54:20.000000000 +0200
3738 @@ -34,6 +34,7 @@
3739  #include <linux/quotaops.h>
3740  #include <linux/buffer_head.h>
3741  #include <linux/bio.h>
3742 +#include <linux/vs_tag.h>
3743  #include "ext4.h"
3744  #include "ext4_jbd2.h"
3745  
3746 @@ -914,6 +915,7 @@ restart:
3747                                 if (bh)
3748                                         ll_rw_block(READ_META, 1, &bh);
3749                         }
3750 +               dx_propagate_tag(nd, inode);
3751                 }
3752                 if ((bh = bh_use[ra_ptr++]) == NULL)
3753                         goto next;
3754 @@ -2461,6 +2463,7 @@ const struct inode_operations ext4_dir_i
3755         .removexattr    = generic_removexattr,
3756  #endif
3757         .permission     = ext4_permission,
3758 +       .sync_flags     = ext4_sync_flags,
3759  };
3760  
3761  const struct inode_operations ext4_special_inode_operations = {
3762 @@ -2472,4 +2475,5 @@ const struct inode_operations ext4_speci
3763         .removexattr    = generic_removexattr,
3764  #endif
3765         .permission     = ext4_permission,
3766 +       .sync_flags     = ext4_sync_flags,
3767  };
3768 diff -NurpP --minimal linux-2.6.27.3/fs/ext4/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/super.c
3769 --- linux-2.6.27.3/fs/ext4/super.c      2008-10-13 14:52:05.000000000 +0200
3770 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/super.c 2008-10-13 14:54:20.000000000 +0200
3771 @@ -907,6 +907,7 @@ enum {
3772         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3773         Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
3774         Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3775 +       Opt_tag, Opt_notag, Opt_tagid
3776  };
3777  
3778  static match_table_t tokens = {
3779 @@ -967,6 +968,9 @@ static match_table_t tokens = {
3780         {Opt_resize, "resize"},
3781         {Opt_delalloc, "delalloc"},
3782         {Opt_nodelalloc, "nodelalloc"},
3783 +       {Opt_tag, "tag"},
3784 +       {Opt_notag, "notag"},
3785 +       {Opt_tagid, "tagid=%u"},
3786         {Opt_err, NULL},
3787  };
3788  
3789 @@ -1060,6 +1064,20 @@ static int parse_options(char *options, 
3790                 case Opt_nouid32:
3791                         set_opt(sbi->s_mount_opt, NO_UID32);
3792                         break;
3793 +#ifndef CONFIG_TAGGING_NONE
3794 +               case Opt_tag:
3795 +                       set_opt (sbi->s_mount_opt, TAGGED);
3796 +                       break;
3797 +               case Opt_notag:
3798 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3799 +                       break;
3800 +#endif
3801 +#ifdef CONFIG_PROPAGATE
3802 +               case Opt_tagid:
3803 +                       /* use args[0] */
3804 +                       set_opt (sbi->s_mount_opt, TAGGED);
3805 +                       break;
3806 +#endif
3807                 case Opt_nocheck:
3808                         clear_opt(sbi->s_mount_opt, CHECK);
3809                         break;
3810 @@ -2029,6 +2047,9 @@ static int ext4_fill_super(struct super_
3811                            NULL, 0))
3812                 goto failed_mount;
3813  
3814 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3815 +               sb->s_flags |= MS_TAGGED;
3816 +
3817         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3818                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3819  
3820 @@ -2988,6 +3009,13 @@ static int ext4_remount(struct super_blo
3821         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3822                 ext4_abort(sb, __func__, "Abort forced by user");
3823  
3824 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3825 +               !(sb->s_flags & MS_TAGGED)) {
3826 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3827 +                       sb->s_id);
3828 +               return -EINVAL;
3829 +       }
3830 +
3831         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3832                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3833  
3834 diff -NurpP --minimal linux-2.6.27.3/fs/ext4/symlink.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/symlink.c
3835 --- linux-2.6.27.3/fs/ext4/symlink.c    2008-07-13 23:51:29.000000000 +0200
3836 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ext4/xattr.c linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/xattr.c
3852 --- linux-2.6.27.3/fs/ext4/xattr.c      2008-10-13 14:52:05.000000000 +0200
3853 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ext4/xattr.c 2008-10-13 14:54:20.000000000 +0200
3854 @@ -56,6 +56,7 @@
3855  #include <linux/mbcache.h>
3856  #include <linux/quotaops.h>
3857  #include <linux/rwsem.h>
3858 +#include <linux/vs_dlimit.h>
3859  #include "ext4_jbd2.h"
3860  #include "ext4.h"
3861  #include "xattr.h"
3862 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3863                 error = ext4_journal_dirty_metadata(handle, bh);
3864                 if (IS_SYNC(inode))
3865                         handle->h_sync = 1;
3866 +                       DLIMIT_FREE_BLOCK(inode, 1);
3867                 DQUOT_FREE_BLOCK(inode, 1);
3868                 ea_bdebug(bh, "refcount now=%d; releasing",
3869                           le32_to_cpu(BHDR(bh)->h_refcount));
3870 @@ -780,11 +782,14 @@ inserted:
3871                         if (new_bh == bs->bh)
3872                                 ea_bdebug(new_bh, "keeping");
3873                         else {
3874 +                               error = -ENOSPC;
3875 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3876 +                                       goto cleanup;
3877                                 /* The old block is released after updating
3878                                    the inode. */
3879                                 error = -EDQUOT;
3880                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3881 -                                       goto cleanup;
3882 +                                       goto cleanup_dlimit;
3883                                 error = ext4_journal_get_write_access(handle,
3884                                                                       new_bh);
3885                                 if (error)
3886 @@ -858,6 +863,8 @@ cleanup:
3887  
3888  cleanup_dquot:
3889         DQUOT_FREE_BLOCK(inode, 1);
3890 +cleanup_dlimit:
3891 +       DLIMIT_FREE_BLOCK(inode, 1);
3892         goto cleanup;
3893  
3894  bad_block:
3895 diff -NurpP --minimal linux-2.6.27.3/fs/fcntl.c linux-2.6.27.3-vs2.3.0.35.7/fs/fcntl.c
3896 --- linux-2.6.27.3/fs/fcntl.c   2008-10-13 14:52:05.000000000 +0200
3897 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/fcntl.c      2008-10-24 04:44:48.000000000 +0200
3898 @@ -19,6 +19,7 @@
3899  #include <linux/signal.h>
3900  #include <linux/rcupdate.h>
3901  #include <linux/pid_namespace.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  #include <asm/poll.h>
3905  #include <asm/siginfo.h>
3906 @@ -102,6 +103,8 @@ asmlinkage long sys_dup3(unsigned int ol
3907  
3908         if (tofree)
3909                 filp_close(tofree, files);
3910 +       else
3911 +               vx_openfd_inc(newfd);   /* fd was unused */
3912  
3913         return newfd;
3914  
3915 @@ -335,6 +338,8 @@ asmlinkage long sys_fcntl(unsigned int f
3916         filp = fget(fd);
3917         if (!filp)
3918                 goto out;
3919 +       if (!vx_files_avail(1))
3920 +               goto out;
3921  
3922         err = security_file_fcntl(filp, cmd, arg);
3923         if (err) {
3924 diff -NurpP --minimal linux-2.6.27.3/fs/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/file.c
3925 --- linux-2.6.27.3/fs/file.c    2008-10-13 14:52:05.000000000 +0200
3926 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/file_table.c linux-2.6.27.3-vs2.3.0.35.7/fs/file_table.c
3953 --- linux-2.6.27.3/fs/file_table.c      2008-10-13 14:52:05.000000000 +0200
3954 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/hfsplus/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/hfsplus/ioctl.c
3992 --- linux-2.6.27.3/fs/hfsplus/ioctl.c   2008-07-13 23:51:29.000000000 +0200
3993 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/inode.c
4003 --- linux-2.6.27.3/fs/inode.c   2008-10-13 14:52:05.000000000 +0200
4004 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/ioctl.c
4045 --- linux-2.6.27.3/fs/ioctl.c   2008-07-13 23:51:29.000000000 +0200
4046 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ioctl.c      2008-10-13 14:54:20.000000000 +0200
4047 @@ -13,6 +13,9 @@
4048  #include <linux/security.h>
4049  #include <linux/module.h>
4050  #include <linux/uaccess.h>
4051 +#include <linux/proc_fs.h>
4052 +#include <linux/vserver/inode.h>
4053 +#include <linux/vs_tag.h>
4054  
4055  #include <asm/ioctls.h>
4056  
4057 diff -NurpP --minimal linux-2.6.27.3/fs/ioprio.c linux-2.6.27.3-vs2.3.0.35.7/fs/ioprio.c
4058 --- linux-2.6.27.3/fs/ioprio.c  2008-10-13 14:52:05.000000000 +0200
4059 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ioprio.c     2008-10-13 14:54:20.000000000 +0200
4060 @@ -26,6 +26,7 @@
4061  #include <linux/syscalls.h>
4062  #include <linux/security.h>
4063  #include <linux/pid_namespace.h>
4064 +#include <linux/vs_base.h>
4065  
4066  static int set_task_ioprio(struct task_struct *task, int ioprio)
4067  {
4068 @@ -116,6 +117,8 @@ asmlinkage long sys_ioprio_set(int which
4069                         else
4070                                 pgrp = find_vpid(who);
4071                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4072 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4073 +                                       continue;
4074                                 ret = set_task_ioprio(p, ioprio);
4075                                 if (ret)
4076                                         break;
4077 @@ -205,6 +208,8 @@ asmlinkage long sys_ioprio_get(int which
4078                         else
4079                                 pgrp = find_vpid(who);
4080                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4081 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4082 +                                       continue;
4083                                 tmpio = get_task_ioprio(p);
4084                                 if (tmpio < 0)
4085                                         continue;
4086 diff -NurpP --minimal linux-2.6.27.3/fs/jfs/acl.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/acl.c
4087 --- linux-2.6.27.3/fs/jfs/acl.c 2008-10-13 14:52:05.000000000 +0200
4088 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/file.c
4100 --- linux-2.6.27.3/fs/jfs/file.c        2008-07-13 23:51:29.000000000 +0200
4101 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/inode.c
4111 --- linux-2.6.27.3/fs/jfs/inode.c       2008-07-13 23:51:29.000000000 +0200
4112 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/ioctl.c
4130 --- linux-2.6.27.3/fs/jfs/ioctl.c       2008-07-13 23:51:29.000000000 +0200
4131 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_dinode.h linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_dinode.h
4164 --- linux-2.6.27.3/fs/jfs/jfs_dinode.h  2008-07-13 23:51:29.000000000 +0200
4165 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_dinode.h     2008-10-24 03:34:52.000000000 +0200
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         0x10000000 /* 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.3/fs/jfs/jfs_dtree.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_dtree.c
4183 --- linux-2.6.27.3/fs/jfs/jfs_dtree.c   2008-07-13 23:51:29.000000000 +0200
4184 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_extent.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_extent.c
4297 --- linux-2.6.27.3/fs/jfs/jfs_extent.c  2008-07-13 23:51:29.000000000 +0200
4298 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_filsys.h linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_filsys.h
4361 --- linux-2.6.27.3/fs/jfs/jfs_filsys.h  2008-07-13 23:51:29.000000000 +0200
4362 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_imap.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_imap.c
4372 --- linux-2.6.27.3/fs/jfs/jfs_imap.c    2008-10-13 14:52:05.000000000 +0200
4373 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_inode.c
4434 --- linux-2.6.27.3/fs/jfs/jfs_inode.c   2008-07-13 23:51:29.000000000 +0200
4435 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_inode.h linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_inode.h
4537 --- linux-2.6.27.3/fs/jfs/jfs_inode.h   2008-07-13 23:51:29.000000000 +0200
4538 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/jfs_xtree.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/jfs_xtree.c
4548 --- linux-2.6.27.3/fs/jfs/jfs_xtree.c   2008-10-13 14:52:05.000000000 +0200
4549 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/namei.c
4634 --- linux-2.6.27.3/fs/jfs/namei.c       2008-10-13 14:52:05.000000000 +0200
4635 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/super.c
4661 --- linux-2.6.27.3/fs/jfs/super.c       2008-10-13 14:52:05.000000000 +0200
4662 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/jfs/xattr.c linux-2.6.27.3-vs2.3.0.35.7/fs/jfs/xattr.c
4730 --- linux-2.6.27.3/fs/jfs/xattr.c       2008-07-13 23:51:29.000000000 +0200
4731 +++ linux-2.6.27.3-vs2.3.0.35.7/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.3/fs/libfs.c linux-2.6.27.3-vs2.3.0.35.7/fs/libfs.c
4810 --- linux-2.6.27.3/fs/libfs.c   2008-10-13 14:52:05.000000000 +0200
4811 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/libfs.c      2008-10-13 14:54:20.000000000 +0200
4812 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
4813   * both impossible due to the lock on directory.
4814   */
4815  
4816 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4817 +static inline int do_dcache_readdir_filter(struct file *filp,
4818 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4819  {
4820         struct dentry *dentry = filp->f_path.dentry;
4821         struct dentry *cursor = filp->private_data;
4822 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
4823                                 next = list_entry(p, struct dentry, d_u.d_child);
4824                                 if (d_unhashed(next) || !next->d_inode)
4825                                         continue;
4826 +                               if (filter && !filter(next))
4827 +                                       continue;
4828  
4829                                 spin_unlock(&dcache_lock);
4830                                 if (filldir(dirent, next->d_name.name, 
4831 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
4832         return 0;
4833  }
4834  
4835 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4836 +{
4837 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4838 +}
4839 +
4840 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4841 +       int (*filter)(struct dentry *))
4842 +{
4843 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4844 +}
4845 +
4846 +
4847  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4848  {
4849         return -EISDIR;
4850 @@ -823,6 +838,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4851  EXPORT_SYMBOL(dcache_dir_lseek);
4852  EXPORT_SYMBOL(dcache_dir_open);
4853  EXPORT_SYMBOL(dcache_readdir);
4854 +EXPORT_SYMBOL(dcache_readdir_filter);
4855  EXPORT_SYMBOL(generic_read_dir);
4856  EXPORT_SYMBOL(get_sb_pseudo);
4857  EXPORT_SYMBOL(simple_write_begin);
4858 diff -NurpP --minimal linux-2.6.27.3/fs/locks.c linux-2.6.27.3-vs2.3.0.35.7/fs/locks.c
4859 --- linux-2.6.27.3/fs/locks.c   2008-10-13 14:52:05.000000000 +0200
4860 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/locks.c      2008-10-13 14:54:20.000000000 +0200
4861 @@ -127,6 +127,8 @@
4862  #include <linux/time.h>
4863  #include <linux/rcupdate.h>
4864  #include <linux/pid_namespace.h>
4865 +#include <linux/vs_base.h>
4866 +#include <linux/vs_limit.h>
4867  
4868  #include <asm/uaccess.h>
4869  
4870 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4871  /* Allocate an empty lock structure. */
4872  static struct file_lock *locks_alloc_lock(void)
4873  {
4874 +       if (!vx_locks_avail(1))
4875 +               return NULL;
4876         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4877  }
4878  
4879 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
4880         BUG_ON(!list_empty(&fl->fl_block));
4881         BUG_ON(!list_empty(&fl->fl_link));
4882  
4883 +       vx_locks_dec(fl);
4884         locks_release_private(fl);
4885         kmem_cache_free(filelock_cache, fl);
4886  }
4887 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
4888         fl->fl_start = fl->fl_end = 0;
4889         fl->fl_ops = NULL;
4890         fl->fl_lmops = NULL;
4891 +       fl->fl_xid = -1;
4892  }
4893  
4894  EXPORT_SYMBOL(locks_init_lock);
4895 @@ -247,6 +253,7 @@ void locks_copy_lock(struct file_lock *n
4896         new->fl_file = fl->fl_file;
4897         new->fl_ops = fl->fl_ops;
4898         new->fl_lmops = fl->fl_lmops;
4899 +       new->fl_xid = fl->fl_xid;
4900  
4901         locks_copy_private(new, fl);
4902  }
4903 @@ -285,6 +292,11 @@ static int flock_make_lock(struct file *
4904         fl->fl_flags = FL_FLOCK;
4905         fl->fl_type = type;
4906         fl->fl_end = OFFSET_MAX;
4907 +
4908 +       vxd_assert(filp->f_xid == vx_current_xid(),
4909 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4910 +       fl->fl_xid = filp->f_xid;
4911 +       vx_locks_inc(fl);
4912         
4913         *lock = fl;
4914         return 0;
4915 @@ -450,6 +462,7 @@ static int lease_init(struct file *filp,
4916  
4917         fl->fl_owner = current->files;
4918         fl->fl_pid = current->tgid;
4919 +       fl->fl_xid = vx_current_xid();
4920  
4921         fl->fl_file = filp;
4922         fl->fl_flags = FL_LEASE;
4923 @@ -469,6 +482,11 @@ static struct file_lock *lease_alloc(str
4924         if (fl == NULL)
4925                 return ERR_PTR(error);
4926  
4927 +       fl->fl_xid = vx_current_xid();
4928 +       if (filp)
4929 +               vxd_assert(filp->f_xid == fl->fl_xid,
4930 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4931 +       vx_locks_inc(fl);
4932         error = lease_init(filp, type, fl);
4933         if (error) {
4934                 locks_free_lock(fl);
4935 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4936         if (found)
4937                 cond_resched_bkl();
4938  
4939 +       new_fl->fl_xid = -1;
4940  find_conflict:
4941         for_each_lock(inode, before) {
4942                 struct file_lock *fl = *before;
4943 @@ -789,6 +808,7 @@ find_conflict:
4944                 goto out;
4945         locks_copy_lock(new_fl, request);
4946         locks_insert_lock(before, new_fl);
4947 +       vx_locks_inc(new_fl);
4948         new_fl = NULL;
4949         error = 0;
4950  
4951 @@ -799,7 +819,8 @@ out:
4952         return error;
4953  }
4954  
4955 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4956 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4957 +       struct file_lock *conflock, xid_t xid)
4958  {
4959         struct file_lock *fl;
4960         struct file_lock *new_fl = NULL;
4961 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4962         struct file_lock **before;
4963         int error, added = 0;
4964  
4965 +       vxd_assert(xid == vx_current_xid(),
4966 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4967         /*
4968          * We may need two file_lock structures for this operation,
4969          * so we get them in advance to avoid races.
4970 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4971             (request->fl_type != F_UNLCK ||
4972              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4973                 new_fl = locks_alloc_lock();
4974 +               new_fl->fl_xid = xid;
4975 +               vx_locks_inc(new_fl);
4976                 new_fl2 = locks_alloc_lock();
4977 +               new_fl2->fl_xid = xid;
4978 +               vx_locks_inc(new_fl2);
4979         }
4980  
4981         lock_kernel();
4982 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4983  int posix_lock_file(struct file *filp, struct file_lock *fl,
4984                         struct file_lock *conflock)
4985  {
4986 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4987 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4988 +               fl, conflock, filp->f_xid);
4989  }
4990  EXPORT_SYMBOL(posix_lock_file);
4991  
4992 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
4993         fl.fl_end = offset + count - 1;
4994  
4995         for (;;) {
4996 -               error = __posix_lock_file(inode, &fl, NULL);
4997 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4998                 if (error != FILE_LOCK_DEFERRED)
4999                         break;
5000                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
5001 @@ -1423,6 +1451,7 @@ int generic_setlease(struct file *filp, 
5002  
5003         locks_copy_lock(new_fl, lease);
5004         locks_insert_lock(before, new_fl);
5005 +       vx_locks_inc(new_fl);
5006  
5007         *flp = new_fl;
5008         return 0;
5009 @@ -1777,6 +1806,11 @@ int fcntl_setlk(unsigned int fd, struct 
5010         if (file_lock == NULL)
5011                 return -ENOLCK;
5012  
5013 +       vxd_assert(filp->f_xid == vx_current_xid(),
5014 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5015 +       file_lock->fl_xid = filp->f_xid;
5016 +       vx_locks_inc(file_lock);
5017 +
5018         /*
5019          * This might block, so we do it before checking the inode.
5020          */
5021 @@ -1895,6 +1929,11 @@ int fcntl_setlk64(unsigned int fd, struc
5022         if (file_lock == NULL)
5023                 return -ENOLCK;
5024  
5025 +       vxd_assert(filp->f_xid == vx_current_xid(),
5026 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5027 +       file_lock->fl_xid = filp->f_xid;
5028 +       vx_locks_inc(file_lock);
5029 +
5030         /*
5031          * This might block, so we do it before checking the inode.
5032          */
5033 @@ -2159,8 +2198,11 @@ static int locks_show(struct seq_file *f
5034  
5035         lock_get_status(f, fl, (long)f->private, "");
5036  
5037 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
5038 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
5039 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
5040 +                       continue;
5041                 lock_get_status(f, bfl, (long)f->private, " ->");
5042 +       }
5043  
5044         f->private++;
5045         return 0;
5046 diff -NurpP --minimal linux-2.6.27.3/fs/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/namei.c
5047 --- linux-2.6.27.3/fs/namei.c   2008-10-13 14:52:05.000000000 +0200
5048 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/namei.c      2008-10-24 03:52:44.000000000 +0200
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,59 @@ 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 +int dx_permission(struct inode *inode, int mask)
5078 +{
5079 +       if (vx_check(0, VS_ADMIN | VS_WATCH))
5080 +               return 0;
5081 +
5082 +       if (dx_barrier(inode))
5083 +               return -EACCES;
5084 +
5085 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5086 +               /* devpts is xid tagged */
5087 +               if (S_ISDIR(inode->i_mode) ||
5088 +                   vx_check((xid_t)inode->i_tag, VS_IDENT))
5089 +                       return 0;
5090 +       }
5091 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5092 +               struct pid *pid = PROC_I(inode)->pid;
5093 +               struct task_struct *tsk;
5094 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
5095 +                       if (!pid)
5096 +                               goto out;
5097 +
5098 +                       tsk = pid_task(pid, PIDTYPE_PID);
5099 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
5100 +                                      tsk, (tsk ? vx_task_xid(tsk) : 0));
5101 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT))
5102 +                               return 0;
5103 +               }
5104 +               else {
5105 +                       /* FIXME: Should we block some entries here? */
5106 +                       return 0;
5107 +               }
5108 +       }
5109 +       else {
5110 +               if (dx_notagcheck(inode->i_sb) ||
5111 +                   dx_check(inode->i_tag, DX_HOSTID|DX_ADMIN|DX_WATCH|DX_IDENT))
5112 +                       return 0;
5113 +       }
5114 +
5115 +out:
5116 +       vxwprintk_task(1, "denied access to %s:%p[#%d,%lu].",
5117 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino);
5118 +       return -EACCES;
5119 +}
5120 +
5121  
5122  /**
5123   * generic_permission  -  check for access rights on a Posix-like filesystem
5124 @@ -244,10 +305,14 @@ int inode_permission(struct inode *inode
5125                 /*
5126                  * Nobody gets write access to an immutable file.
5127                  */
5128 -               if (IS_IMMUTABLE(inode))
5129 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5130                         return -EACCES;
5131         }
5132  
5133 +       retval = dx_permission(inode, mask);
5134 +       if (retval)
5135 +               return retval;
5136 +
5137         /* Ordinary permission routines do not understand MAY_APPEND. */
5138         if (inode->i_op && inode->i_op->permission) {
5139                 retval = inode->i_op->permission(inode, mask);
5140 @@ -451,6 +516,8 @@ static int exec_permission_lite(struct i
5141  {
5142         umode_t mode = inode->i_mode;
5143  
5144 +       if (dx_barrier(inode))
5145 +               return -EACCES;
5146         if (inode->i_op && inode->i_op->permission)
5147                 return -EAGAIN;
5148  
5149 @@ -773,7 +840,8 @@ static __always_inline void follow_dotdo
5150                 if (nd->path.dentry == fs->root.dentry &&
5151                     nd->path.mnt == fs->root.mnt) {
5152                          read_unlock(&fs->lock);
5153 -                       break;
5154 +                       /* for sane '/' avoid follow_mount() */
5155 +                       return;
5156                 }
5157                  read_unlock(&fs->lock);
5158                 spin_lock(&dcache_lock);
5159 @@ -810,16 +878,39 @@ static int do_lookup(struct nameidata *n
5160  {
5161         struct vfsmount *mnt = nd->path.mnt;
5162         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5163 +       struct inode *inode;
5164  
5165         if (!dentry)
5166                 goto need_lookup;
5167         if (dentry->d_op && dentry->d_op->d_revalidate)
5168                 goto need_revalidate;
5169 +       inode = dentry->d_inode;
5170 +       if (!inode)
5171 +               goto done;
5172 +
5173 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5174 +               struct proc_dir_entry *de = PDE(inode);
5175 +
5176 +               if (de && !vx_hide_check(0, de->vx_flags))
5177 +                       goto hidden;
5178 +       } else if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5179 +               if (!vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
5180 +                       goto hidden;
5181 +       } else {
5182 +               if (!dx_notagcheck(inode->i_sb) && !dx_check(inode->i_tag,
5183 +                       DX_WATCH | DX_ADMIN | DX_HOSTID | DX_IDENT))
5184 +                       goto hidden;
5185 +       }
5186  done:
5187         path->mnt = mnt;
5188         path->dentry = dentry;
5189         __follow_mount(path);
5190         return 0;
5191 +hidden:
5192 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] Â»%s«.",
5193 +               inode, inode->i_tag, inode->i_ino, vxd_path(&nd->path));
5194 +       dput(dentry);
5195 +       return -ENOENT;
5196  
5197  need_lookup:
5198         dentry = real_lookup(nd->path.dentry, name, nd);
5199 @@ -1407,7 +1498,7 @@ static int may_delete(struct inode *dir,
5200         if (IS_APPEND(dir))
5201                 return -EPERM;
5202         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5203 -           IS_IMMUTABLE(victim->d_inode))
5204 +               IS_IXORUNLINK(victim->d_inode))
5205                 return -EPERM;
5206         if (isdir) {
5207                 if (!S_ISDIR(victim->d_inode->i_mode))
5208 @@ -1551,6 +1642,14 @@ int may_open(struct nameidata *nd, int a
5209                 flag &= ~O_TRUNC;
5210         }
5211  
5212 +#ifdef CONFIG_VSERVER_COWBL
5213 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5214 +               if (IS_COW_LINK(inode))
5215 +                       return -EMLINK;
5216 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5217 +               mark_inode_dirty(inode);
5218 +       }
5219 +#endif
5220         error = vfs_permission(nd, acc_mode);
5221         if (error)
5222                 return error;
5223 @@ -1677,6 +1776,11 @@ struct file *do_filp_open(int dfd, const
5224         int will_write;
5225         int flag = open_to_namei_flags(open_flag);
5226  
5227 +#ifdef CONFIG_VSERVER_COWBL
5228 +       int rflag = flag;
5229 +       int rmode = mode;
5230 +restart:
5231 +#endif
5232         acc_mode = MAY_OPEN | ACC_MODE(flag);
5233  
5234         /* O_TRUNC implies we need access checks for write permissions */
5235 @@ -1800,6 +1904,25 @@ ok:
5236                         goto exit;
5237         }
5238         error = may_open(&nd, acc_mode, flag);
5239 +#ifdef CONFIG_VSERVER_COWBL
5240 +       if (error == -EMLINK) {
5241 +               struct dentry *dentry;
5242 +               dentry = cow_break_link(pathname);
5243 +               if (IS_ERR(dentry)) {
5244 +                       error = PTR_ERR(dentry);
5245 +                       goto exit_cow;
5246 +               }
5247 +               dput(dentry);
5248 +               if (will_write)
5249 +                       mnt_drop_write(nd.path.mnt);
5250 +               release_open_intent(&nd);
5251 +               path_put(&nd.path);
5252 +               flag = rflag;
5253 +               mode = rmode;
5254 +               goto restart;
5255 +       }
5256 +exit_cow:
5257 +#endif
5258         if (error) {
5259                 if (will_write)
5260                         mnt_drop_write(nd.path.mnt);
5261 @@ -1952,9 +2075,17 @@ int vfs_mknod(struct inode *dir, struct 
5262         if (error)
5263                 return error;
5264  
5265 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5266 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5267 +               goto okay;
5268 +
5269 +       if (!capable(CAP_MKNOD))
5270                 return -EPERM;
5271  
5272 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5273 +               return -EPERM;
5274 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5275 +               return -EPERM;
5276 +okay:
5277         if (!dir->i_op || !dir->i_op->mknod)
5278                 return -EPERM;
5279  
5280 @@ -2395,7 +2526,7 @@ int vfs_link(struct dentry *old_dentry, 
5281         /*
5282          * A link to an append-only or immutable file cannot be created.
5283          */
5284 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5285 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5286                 return -EPERM;
5287         if (!dir->i_op || !dir->i_op->link)
5288                 return -EPERM;
5289 @@ -2756,6 +2887,214 @@ int vfs_follow_link(struct nameidata *nd
5290         return __vfs_follow_link(nd, link);
5291  }
5292  
5293 +
5294 +#ifdef CONFIG_VSERVER_COWBL
5295 +
5296 +#include <linux/file.h>
5297 +
5298 +static inline
5299 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5300 +{
5301 +       loff_t ppos = 0;
5302 +
5303 +       return do_splice_direct(in, &ppos, out, len, 0);
5304 +}
5305 +
5306 +struct dentry *cow_break_link(const char *pathname)
5307 +{
5308 +       int ret, mode, pathlen, redo = 0;
5309 +       struct nameidata old_nd, dir_nd;
5310 +       struct path old_path, new_path;
5311 +       struct dentry *dir, *res = NULL;
5312 +       struct file *old_file;
5313 +       struct file *new_file;
5314 +       char *to, *path, pad='\251';
5315 +       loff_t size;
5316 +
5317 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5318 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5319 +       ret = -ENOMEM;
5320 +       if (!path)
5321 +               goto out;
5322 +
5323 +       /* old_nd will have refs to dentry and mnt */
5324 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5325 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5326 +       if (ret < 0)
5327 +               goto out_free_path;
5328 +
5329 +       old_path = old_nd.path;
5330 +       mode = old_path.dentry->d_inode->i_mode;
5331 +
5332 +       to = d_path(&old_path, path, PATH_MAX-2);
5333 +       pathlen = strlen(to);
5334 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5335 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5336 +               old_path.dentry->d_name.len);
5337 +
5338 +       to[pathlen + 1] = 0;
5339 +retry:
5340 +       to[pathlen] = pad--;
5341 +       ret = -EMLINK;
5342 +       if (pad <= '\240')
5343 +               goto out_rel_old;
5344 +
5345 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5346 +       /* dir_nd will have refs to dentry and mnt */
5347 +       ret = path_lookup(to,
5348 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5349 +       vxdprintk(VXD_CBIT(misc, 2),
5350 +               "path_lookup(new): %d", ret);
5351 +       if (ret < 0)
5352 +               goto retry;
5353 +
5354 +       /* this puppy downs the inode mutex */
5355 +       new_path.dentry = lookup_create(&dir_nd, 0);
5356 +       vxdprintk(VXD_CBIT(misc, 2),
5357 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5358 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5359 +               new_path.dentry->d_name.len);
5360 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5361 +               path_put(&dir_nd.path);
5362 +               goto retry;
5363 +       }
5364 +       dir = dir_nd.path.dentry;
5365 +
5366 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5367 +       vxdprintk(VXD_CBIT(misc, 2),
5368 +               "vfs_create(new): %d", ret);
5369 +       if (ret == -EEXIST) {
5370 +               mutex_unlock(&dir->d_inode->i_mutex);
5371 +               dput(new_path.dentry);
5372 +               path_put(&dir_nd.path);
5373 +               goto retry;
5374 +       }
5375 +       else if (ret < 0)
5376 +               goto out_unlock_new;
5377 +
5378 +       /* drop out early, ret passes ENOENT */
5379 +       ret = -ENOENT;
5380 +       if ((redo = d_unhashed(old_path.dentry)))
5381 +               goto out_unlock_new;
5382 +
5383 +       new_path.mnt = dir_nd.path.mnt;
5384 +       dget(old_path.dentry);
5385 +       mntget(old_path.mnt);
5386 +       /* this one cleans up the dentry/mnt in case of failure */
5387 +       old_file = dentry_open(old_path.dentry, old_path.mnt, O_RDONLY);
5388 +       vxdprintk(VXD_CBIT(misc, 2),
5389 +               "dentry_open(old): %p", old_file);
5390 +       if (!old_file || IS_ERR(old_file)) {
5391 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5392 +               goto out_unlock_new;
5393 +       }
5394 +
5395 +       dget(new_path.dentry);
5396 +       mntget(new_path.mnt);
5397 +       /* this one cleans up the dentry/mnt in case of failure */
5398 +       new_file = dentry_open(new_path.dentry, new_path.mnt, O_WRONLY);
5399 +       vxdprintk(VXD_CBIT(misc, 2),
5400 +               "dentry_open(new): %p", new_file);
5401 +
5402 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5403 +       if (!new_file || IS_ERR(new_file))
5404 +               goto out_fput_old;
5405 +
5406 +       size = i_size_read(old_file->f_dentry->d_inode);
5407 +       ret = do_cow_splice(old_file, new_file, size);
5408 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5409 +       if (ret < 0) {
5410 +               goto out_fput_both;
5411 +       } else if (ret < size) {
5412 +               ret = -ENOSPC;
5413 +               goto out_fput_both;
5414 +       } else {
5415 +               struct inode *old_inode = old_path.dentry->d_inode;
5416 +               struct inode *new_inode = new_path.dentry->d_inode;
5417 +               struct iattr attr = {
5418 +                       .ia_uid = old_inode->i_uid,
5419 +                       .ia_gid = old_inode->i_gid,
5420 +                       .ia_valid = ATTR_UID | ATTR_GID
5421 +                       };
5422 +
5423 +               ret = inode_setattr(new_inode, &attr);
5424 +               if (ret)
5425 +                       goto out_fput_both;
5426 +       }
5427 +
5428 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5429 +
5430 +       /* drop out late */
5431 +       ret = -ENOENT;
5432 +       if ((redo = d_unhashed(old_path.dentry)))
5433 +               goto out_unlock;
5434 +
5435 +       vxdprintk(VXD_CBIT(misc, 2),
5436 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5437 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5438 +               new_path.dentry->d_name.len,
5439 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5440 +               old_path.dentry->d_name.len);
5441 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5442 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5443 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5444 +       res = new_path.dentry;
5445 +
5446 +out_unlock:
5447 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5448 +
5449 +out_fput_both:
5450 +       vxdprintk(VXD_CBIT(misc, 3),
5451 +               "fput(new_file=%p[#%ld])", new_file,
5452 +               atomic_read(&new_file->f_count));
5453 +       fput(new_file);
5454 +
5455 +out_fput_old:
5456 +       vxdprintk(VXD_CBIT(misc, 3),
5457 +               "fput(old_file=%p[#%ld])", old_file,
5458 +               atomic_read(&old_file->f_count));
5459 +       fput(old_file);
5460 +
5461 +out_unlock_new:
5462 +       mutex_unlock(&dir->d_inode->i_mutex);
5463 +       if (!ret)
5464 +               goto out_redo;
5465 +
5466 +       /* error path cleanup */
5467 +       vfs_unlink(dir->d_inode, new_path.dentry);
5468 +       dput(new_path.dentry);
5469 +
5470 +out_redo:
5471 +       if (!redo)
5472 +               goto out_rel_both;
5473 +       /* lookup dentry once again */
5474 +       path_put(&old_nd.path);
5475 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5476 +       if (ret)
5477 +               goto out_rel_both;
5478 +
5479 +       new_path.dentry = old_nd.path.dentry;
5480 +       vxdprintk(VXD_CBIT(misc, 2),
5481 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5482 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5483 +               new_path.dentry->d_name.len);
5484 +       dget(new_path.dentry);
5485 +       res = new_path.dentry;
5486 +
5487 +out_rel_both:
5488 +       path_put(&dir_nd.path);
5489 +out_rel_old:
5490 +       path_put(&old_nd.path);
5491 +out_free_path:
5492 +       kfree(path);
5493 +out:
5494 +       if (ret)
5495 +               res = ERR_PTR(ret);
5496 +       return res;
5497 +}
5498 +
5499 +#endif
5500 +
5501  /* get the link contents into pagecache */
5502  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5503  {
5504 diff -NurpP --minimal linux-2.6.27.3/fs/namespace.c linux-2.6.27.3-vs2.3.0.35.7/fs/namespace.c
5505 --- linux-2.6.27.3/fs/namespace.c       2008-10-13 14:52:05.000000000 +0200
5506 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/namespace.c  2008-10-24 03:34:52.000000000 +0200
5507 @@ -27,6 +27,11 @@
5508  #include <linux/ramfs.h>
5509  #include <linux/log2.h>
5510  #include <linux/idr.h>
5511 +#include <linux/vs_base.h>
5512 +#include <linux/vs_context.h>
5513 +#include <linux/vs_tag.h>
5514 +#include <linux/vserver/space.h>
5515 +#include <linux/vserver/global.h>
5516  #include <asm/uaccess.h>
5517  #include <asm/unistd.h>
5518  #include "pnode.h"
5519 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5520                 mnt->mnt_root = dget(root);
5521                 mnt->mnt_mountpoint = mnt->mnt_root;
5522                 mnt->mnt_parent = mnt;
5523 +               mnt->mnt_tag = old->mnt_tag;
5524  
5525                 if (flag & CL_SLAVE) {
5526                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5527 @@ -685,6 +691,31 @@ static inline void mangle(struct seq_fil
5528         seq_escape(m, s, " \t\n\\");
5529  }
5530  
5531 +static int mnt_is_reachable(struct vfsmount *mnt)
5532 +{
5533 +       struct path root;
5534 +       struct dentry *point;
5535 +       int ret;
5536 +
5537 +       if (mnt == mnt->mnt_ns->root)
5538 +               return 1;
5539 +
5540 +       spin_lock(&vfsmount_lock);
5541 +       root = current->fs->root;
5542 +       point = root.dentry;
5543 +
5544 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5545 +               point = mnt->mnt_mountpoint;
5546 +               mnt = mnt->mnt_parent;
5547 +       }
5548 +
5549 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5550 +
5551 +       spin_unlock(&vfsmount_lock);
5552 +
5553 +       return ret;
5554 +}
5555 +
5556  /*
5557   * Simple .show_options callback for filesystems which don't want to
5558   * implement more complex mount option showing.
5559 @@ -757,6 +788,8 @@ static int show_sb_opts(struct seq_file 
5560                 { MS_SYNCHRONOUS, ",sync" },
5561                 { MS_DIRSYNC, ",dirsync" },
5562                 { MS_MANDLOCK, ",mand" },
5563 +               { MS_TAGGED, ",tag" },
5564 +               { MS_NOTAGCHECK, ",notagcheck" },
5565                 { 0, NULL }
5566         };
5567         const struct proc_fs_info *fs_infop;
5568 @@ -803,10 +836,20 @@ static int show_vfsmnt(struct seq_file *
5569         int err = 0;
5570         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5571  
5572 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5573 -       seq_putc(m, ' ');
5574 -       seq_path(m, &mnt_path, " \t\n\\");
5575 -       seq_putc(m, ' ');
5576 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5577 +               return SEQ_SKIP;
5578 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5579 +               return SEQ_SKIP;
5580 +
5581 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5582 +               mnt == current->fs->root.mnt) {
5583 +               seq_puts(m, "/dev/root / ");
5584 +       } else {
5585 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5586 +               seq_putc(m, ' ');
5587 +               seq_path(m, &mnt_path, " \t\n\\");
5588 +               seq_putc(m, ' ');
5589 +       }
5590         show_type(m, mnt->mnt_sb);
5591         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5592         err = show_sb_opts(m, mnt->mnt_sb);
5593 @@ -836,6 +879,11 @@ static int show_mountinfo(struct seq_fil
5594         struct path root = p->root;
5595         int err = 0;
5596  
5597 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5598 +               return SEQ_SKIP;
5599 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5600 +               return SEQ_SKIP;
5601 +
5602         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5603                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5604         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5605 @@ -894,17 +942,27 @@ static int show_vfsstat(struct seq_file 
5606         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5607         int err = 0;
5608  
5609 -       /* device */
5610 -       if (mnt->mnt_devname) {
5611 -               seq_puts(m, "device ");
5612 -               mangle(m, mnt->mnt_devname);
5613 -       } else
5614 -               seq_puts(m, "no device");
5615 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5616 +               return SEQ_SKIP;
5617 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5618 +               return SEQ_SKIP;
5619  
5620 -       /* mount point */
5621 -       seq_puts(m, " mounted on ");
5622 -       seq_path(m, &mnt_path, " \t\n\\");
5623 -       seq_putc(m, ' ');
5624 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5625 +               mnt == current->fs->root.mnt) {
5626 +               seq_puts(m, "device /dev/root mounted on / ");
5627 +       } else {
5628 +               /* device */
5629 +               if (mnt->mnt_devname) {
5630 +                       seq_puts(m, "device ");
5631 +                       mangle(m, mnt->mnt_devname);
5632 +               } else
5633 +                       seq_puts(m, "no device");
5634 +
5635 +               /* mount point */
5636 +               seq_puts(m, " mounted on ");
5637 +               seq_path(m, &mnt_path, " \t\n\\");
5638 +               seq_putc(m, ' ');
5639 +       }
5640  
5641         /* file system type */
5642         seq_puts(m, "with fstype ");
5643 @@ -1143,7 +1201,7 @@ asmlinkage long sys_umount(char __user *
5644                 goto dput_and_out;
5645  
5646         retval = -EPERM;
5647 -       if (!capable(CAP_SYS_ADMIN))
5648 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5649                 goto dput_and_out;
5650  
5651         retval = do_umount(path.mnt, flags);
5652 @@ -1169,7 +1227,7 @@ asmlinkage long sys_oldumount(char __use
5653  
5654  static int mount_is_safe(struct nameidata *nd)
5655  {
5656 -       if (capable(CAP_SYS_ADMIN))
5657 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5658                 return 0;
5659         return -EPERM;
5660  #ifdef notyet
5661 @@ -1462,11 +1520,13 @@ static noinline int do_change_type(struc
5662   * noinline this do_mount helper to save do_mount stack space.
5663   */
5664  static noinline int do_loopback(struct nameidata *nd, char *old_name,
5665 -                               int recurse)
5666 +       tag_t tag, unsigned long flags, int mnt_flags)
5667  {
5668         struct nameidata old_nd;
5669         struct vfsmount *mnt = NULL;
5670         int err = mount_is_safe(nd);
5671 +       int recurse = flags & MS_REC;
5672 +
5673         if (err)
5674                 return err;
5675         if (!old_name || !*old_name)
5676 @@ -1500,6 +1560,7 @@ static noinline int do_loopback(struct n
5677                 spin_unlock(&vfsmount_lock);
5678                 release_mounts(&umount_list);
5679         }
5680 +       mnt->mnt_flags = mnt_flags;
5681  
5682  out:
5683         up_write(&namespace_sem);
5684 @@ -1531,12 +1592,12 @@ static int change_mount_flags(struct vfs
5685   * noinline this do_mount helper to save do_mount stack space.
5686   */
5687  static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags,
5688 -                     void *data)
5689 +       void *data, xid_t xid)
5690  {
5691         int err;
5692         struct super_block *sb = nd->path.mnt->mnt_sb;
5693  
5694 -       if (!capable(CAP_SYS_ADMIN))
5695 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5696                 return -EPERM;
5697  
5698         if (!check_mnt(nd->path.mnt))
5699 @@ -1577,7 +1638,7 @@ static noinline int do_move_mount(struct
5700         struct path parent_path;
5701         struct vfsmount *p;
5702         int err = 0;
5703 -       if (!capable(CAP_SYS_ADMIN))
5704 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5705                 return -EPERM;
5706         if (!old_name || !*old_name)
5707                 return -EINVAL;
5708 @@ -1660,7 +1721,7 @@ static noinline int do_new_mount(struct 
5709                 return -EINVAL;
5710  
5711         /* we need capabilities... */
5712 -       if (!capable(CAP_SYS_ADMIN))
5713 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5714                 return -EPERM;
5715  
5716         mnt = do_kern_mount(type, flags, name, data);
5717 @@ -1905,6 +1966,7 @@ long do_mount(char *dev_name, char *dir_
5718         struct nameidata nd;
5719         int retval = 0;
5720         int mnt_flags = 0;
5721 +       tag_t tag = 0;
5722  
5723         /* Discard magic */
5724         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5725 @@ -1920,6 +1982,12 @@ long do_mount(char *dev_name, char *dir_
5726         if (data_page)
5727                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5728  
5729 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5730 +               /* FIXME: bind and re-mounts get the tag flag? */
5731 +               if (flags & (MS_BIND|MS_REMOUNT))
5732 +                       flags |= MS_TAGID;
5733 +       }
5734 +
5735         /* Separate the per-mountpoint flags */
5736         if (flags & MS_NOSUID)
5737                 mnt_flags |= MNT_NOSUID;
5738 @@ -1936,6 +2004,8 @@ long do_mount(char *dev_name, char *dir_
5739         if (flags & MS_RDONLY)
5740                 mnt_flags |= MNT_READONLY;
5741  
5742 +       if (!capable(CAP_SYS_ADMIN))
5743 +               mnt_flags |= MNT_NODEV;
5744         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5745                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5746  
5747 @@ -1951,9 +2021,9 @@ long do_mount(char *dev_name, char *dir_
5748  
5749         if (flags & MS_REMOUNT)
5750                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
5751 -                                   data_page);
5752 +                                   data_page, tag);
5753         else if (flags & MS_BIND)
5754 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
5755 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
5756         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5757                 retval = do_change_type(&nd, flags);
5758         else if (flags & MS_MOVE)
5759 @@ -2022,6 +2092,7 @@ static struct mnt_namespace *dup_mnt_ns(
5760                 q = next_mnt(q, new_ns->root);
5761         }
5762         up_write(&namespace_sem);
5763 +       atomic_inc(&vs_global_mnt_ns);
5764  
5765         if (rootmnt)
5766                 mntput(rootmnt);
5767 @@ -2350,5 +2421,6 @@ void __put_mnt_ns(struct mnt_namespace *
5768         spin_unlock(&vfsmount_lock);
5769         up_write(&namespace_sem);
5770         release_mounts(&umount_list);
5771 +       atomic_dec(&vs_global_mnt_ns);
5772         kfree(ns);
5773  }
5774 diff -NurpP --minimal linux-2.6.27.3/fs/nfs/client.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/client.c
5775 --- linux-2.6.27.3/fs/nfs/client.c      2008-10-13 14:52:05.000000000 +0200
5776 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/client.c 2008-10-13 14:54:20.000000000 +0200
5777 @@ -601,6 +601,9 @@ static int nfs_init_server_rpcclient(str
5778         if (server->flags & NFS_MOUNT_SOFT)
5779                 server->client->cl_softrtry = 1;
5780  
5781 +       server->client->cl_tag = 0;
5782 +       if (server->flags & NFS_MOUNT_TAGGED)
5783 +               server->client->cl_tag = 1;
5784         return 0;
5785  }
5786  
5787 @@ -766,6 +769,10 @@ static void nfs_server_set_fsinfo(struct
5788                 server->acdirmin = server->acdirmax = 0;
5789         }
5790  
5791 +       /* FIXME: needs fsinfo
5792 +       if (server->flags & NFS_MOUNT_TAGGED)
5793 +               sb->s_flags |= MS_TAGGED;       */
5794 +
5795         server->maxfilesize = fsinfo->maxfilesize;
5796  
5797         /* We're airborne Set socket buffersize */
5798 diff -NurpP --minimal linux-2.6.27.3/fs/nfs/dir.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/dir.c
5799 --- linux-2.6.27.3/fs/nfs/dir.c 2008-10-13 14:52:05.000000000 +0200
5800 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/dir.c    2008-10-13 14:54:20.000000000 +0200
5801 @@ -34,6 +34,7 @@
5802  #include <linux/namei.h>
5803  #include <linux/mount.h>
5804  #include <linux/sched.h>
5805 +#include <linux/vs_tag.h>
5806  
5807  #include "nfs4_fs.h"
5808  #include "delegation.h"
5809 @@ -938,6 +939,7 @@ static struct dentry *nfs_lookup(struct 
5810         if (IS_ERR(res))
5811                 goto out_unblock_sillyrename;
5812  
5813 +       dx_propagate_tag(nd, inode);
5814  no_entry:
5815         res = d_materialise_unique(dentry, inode);
5816         if (res != NULL) {
5817 diff -NurpP --minimal linux-2.6.27.3/fs/nfs/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/inode.c
5818 --- linux-2.6.27.3/fs/nfs/inode.c       2008-10-13 14:52:05.000000000 +0200
5819 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/inode.c  2008-10-13 14:54:20.000000000 +0200
5820 @@ -37,6 +37,7 @@
5821  #include <linux/vfs.h>
5822  #include <linux/inet.h>
5823  #include <linux/nfs_xdr.h>
5824 +#include <linux/vs_tag.h>
5825  
5826  #include <asm/system.h>
5827  #include <asm/uaccess.h>
5828 @@ -314,8 +315,10 @@ nfs_fhget(struct super_block *sb, struct
5829                         nfsi->change_attr = fattr->change_attr;
5830                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5831                 inode->i_nlink = fattr->nlink;
5832 -               inode->i_uid = fattr->uid;
5833 -               inode->i_gid = fattr->gid;
5834 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5835 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5836 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5837 +                                        /* maybe fattr->xid someday */
5838                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5839                         /*
5840                          * report the blocks in 512byte units
5841 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5842                         inode->i_uid = attr->ia_uid;
5843                 if ((attr->ia_valid & ATTR_GID) != 0)
5844                         inode->i_gid = attr->ia_gid;
5845 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5846 +                       inode->i_tag = attr->ia_tag;
5847                 spin_lock(&inode->i_lock);
5848                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5849                 spin_unlock(&inode->i_lock);
5850 @@ -900,6 +905,9 @@ static int nfs_check_inode_attributes(st
5851         struct nfs_inode *nfsi = NFS_I(inode);
5852         loff_t cur_size, new_isize;
5853         unsigned long invalid = 0;
5854 +       uid_t uid;
5855 +       gid_t gid;
5856 +       tag_t tag;
5857  
5858  
5859         /* Has the inode gone and changed behind our back? */
5860 @@ -924,10 +932,15 @@ static int nfs_check_inode_attributes(st
5861         if (cur_size != new_isize && nfsi->npages == 0)
5862                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5863  
5864 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5865 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5866 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5867 +
5868         /* Have any file permissions changed? */
5869         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5870 -                       || inode->i_uid != fattr->uid
5871 -                       || inode->i_gid != fattr->gid)
5872 +                       || inode->i_uid != uid
5873 +                       || inode->i_gid != gid
5874 +                       || inode->i_tag != tag)
5875                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5876  
5877         /* Has the link count changed? */
5878 @@ -1048,6 +1061,9 @@ static int nfs_update_inode(struct inode
5879         loff_t cur_isize, new_isize;
5880         unsigned long invalid = 0;
5881         unsigned long now = jiffies;
5882 +       uid_t uid;
5883 +       gid_t gid;
5884 +       tag_t tag;
5885  
5886         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5887                         __func__, inode->i_sb->s_id, inode->i_ino,
5888 @@ -1121,15 +1137,21 @@ static int nfs_update_inode(struct inode
5889         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5890         nfsi->change_attr = fattr->change_attr;
5891  
5892 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5893 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5894 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5895 +
5896         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5897 -           inode->i_uid != fattr->uid ||
5898 -           inode->i_gid != fattr->gid)
5899 +           inode->i_uid != uid ||
5900 +           inode->i_gid != gid ||
5901 +           inode->i_tag != tag)
5902                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5903  
5904         inode->i_mode = fattr->mode;
5905         inode->i_nlink = fattr->nlink;
5906 -       inode->i_uid = fattr->uid;
5907 -       inode->i_gid = fattr->gid;
5908 +       inode->i_uid = uid;
5909 +       inode->i_gid = gid;
5910 +       inode->i_tag = tag;
5911  
5912         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5913                 /*
5914 diff -NurpP --minimal linux-2.6.27.3/fs/nfs/nfs3xdr.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/nfs3xdr.c
5915 --- linux-2.6.27.3/fs/nfs/nfs3xdr.c     2008-07-13 23:51:29.000000000 +0200
5916 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/nfs3xdr.c        2008-10-13 14:54:20.000000000 +0200
5917 @@ -22,6 +22,7 @@
5918  #include <linux/nfs3.h>
5919  #include <linux/nfs_fs.h>
5920  #include <linux/nfsacl.h>
5921 +#include <linux/vs_tag.h>
5922  #include "internal.h"
5923  
5924  #define NFSDBG_FACILITY                NFSDBG_XDR
5925 @@ -180,7 +181,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5926  }
5927  
5928  static inline __be32 *
5929 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5930 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5931  {
5932         if (attr->ia_valid & ATTR_MODE) {
5933                 *p++ = xdr_one;
5934 @@ -188,15 +189,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5935         } else {
5936                 *p++ = xdr_zero;
5937         }
5938 -       if (attr->ia_valid & ATTR_UID) {
5939 +       if (attr->ia_valid & ATTR_UID ||
5940 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5941                 *p++ = xdr_one;
5942 -               *p++ = htonl(attr->ia_uid);
5943 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5944         } else {
5945                 *p++ = xdr_zero;
5946         }
5947 -       if (attr->ia_valid & ATTR_GID) {
5948 +       if (attr->ia_valid & ATTR_GID ||
5949 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5950                 *p++ = xdr_one;
5951 -               *p++ = htonl(attr->ia_gid);
5952 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5953         } else {
5954                 *p++ = xdr_zero;
5955         }
5956 @@ -281,7 +284,8 @@ static int
5957  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5958  {
5959         p = xdr_encode_fhandle(p, args->fh);
5960 -       p = xdr_encode_sattr(p, args->sattr);
5961 +       p = xdr_encode_sattr(p, args->sattr,
5962 +               req->rq_task->tk_client->cl_tag);
5963         *p++ = htonl(args->guard);
5964         if (args->guard)
5965                 p = xdr_encode_time3(p, &args->guardtime);
5966 @@ -386,7 +390,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5967                 *p++ = args->verifier[0];
5968                 *p++ = args->verifier[1];
5969         } else
5970 -               p = xdr_encode_sattr(p, args->sattr);
5971 +               p = xdr_encode_sattr(p, args->sattr,
5972 +                       req->rq_task->tk_client->cl_tag);
5973  
5974         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5975         return 0;
5976 @@ -400,7 +405,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5977  {
5978         p = xdr_encode_fhandle(p, args->fh);
5979         p = xdr_encode_array(p, args->name, args->len);
5980 -       p = xdr_encode_sattr(p, args->sattr);
5981 +       p = xdr_encode_sattr(p, args->sattr,
5982 +               req->rq_task->tk_client->cl_tag);
5983         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5984         return 0;
5985  }
5986 @@ -413,7 +419,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5987  {
5988         p = xdr_encode_fhandle(p, args->fromfh);
5989         p = xdr_encode_array(p, args->fromname, args->fromlen);
5990 -       p = xdr_encode_sattr(p, args->sattr);
5991 +       p = xdr_encode_sattr(p, args->sattr,
5992 +               req->rq_task->tk_client->cl_tag);
5993         *p++ = htonl(args->pathlen);
5994         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5995  
5996 @@ -431,7 +438,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5997         p = xdr_encode_fhandle(p, args->fh);
5998         p = xdr_encode_array(p, args->name, args->len);
5999         *p++ = htonl(args->type);
6000 -       p = xdr_encode_sattr(p, args->sattr);
6001 +       p = xdr_encode_sattr(p, args->sattr,
6002 +               req->rq_task->tk_client->cl_tag);
6003         if (args->type == NF3CHR || args->type == NF3BLK) {
6004                 *p++ = htonl(MAJOR(args->rdev));
6005                 *p++ = htonl(MINOR(args->rdev));
6006 diff -NurpP --minimal linux-2.6.27.3/fs/nfs/nfsroot.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/nfsroot.c
6007 --- linux-2.6.27.3/fs/nfs/nfsroot.c     2008-10-13 14:52:05.000000000 +0200
6008 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/nfsroot.c        2008-10-13 14:54:20.000000000 +0200
6009 @@ -117,12 +117,12 @@ static int mount_port __initdata = 0;             /
6010  enum {
6011         /* Options that take integer arguments */
6012         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6013 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6014 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6015         /* Options that take no arguments */
6016         Opt_soft, Opt_hard, Opt_intr,
6017         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6018         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6019 -       Opt_acl, Opt_noacl,
6020 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6021         /* Error token */
6022         Opt_err
6023  };
6024 @@ -159,6 +159,9 @@ static match_table_t __initdata tokens =
6025         {Opt_tcp, "tcp"},
6026         {Opt_acl, "acl"},
6027         {Opt_noacl, "noacl"},
6028 +       {Opt_tag, "tag"},
6029 +       {Opt_notag, "notag"},
6030 +       {Opt_tagid, "tagid=%u"},
6031         {Opt_err, NULL}
6032         
6033  };
6034 @@ -270,6 +273,20 @@ static int __init root_nfs_parse(char *n
6035                         case Opt_noacl:
6036                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6037                                 break;
6038 +#ifndef CONFIG_TAGGING_NONE
6039 +                       case Opt_tag:
6040 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6041 +                               break;
6042 +                       case Opt_notag:
6043 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6044 +                               break;
6045 +#endif
6046 +#ifdef CONFIG_PROPAGATE
6047 +                       case Opt_tagid:
6048 +                               /* use args[0] */
6049 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6050 +                               break;
6051 +#endif
6052                         default:
6053                                 printk(KERN_WARNING "Root-NFS: unknown "
6054                                         "option: %s\n", p);
6055 diff -NurpP --minimal linux-2.6.27.3/fs/nfs/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/super.c
6056 --- linux-2.6.27.3/fs/nfs/super.c       2008-10-13 14:52:05.000000000 +0200
6057 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfs/super.c  2008-10-13 14:54:20.000000000 +0200
6058 @@ -51,6 +51,7 @@
6059  #include <linux/nfs_xdr.h>
6060  #include <linux/magic.h>
6061  #include <linux/parser.h>
6062 +#include <linux/vs_tag.h>
6063  
6064  #include <asm/system.h>
6065  #include <asm/uaccess.h>
6066 @@ -504,6 +505,7 @@ static void nfs_show_mount_options(struc
6067                 { NFS_MOUNT_NOACL, ",noacl", "" },
6068                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6069                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
6070 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6071                 { 0, NULL, NULL }
6072         };
6073         const struct proc_nfs_info *nfs_infop;
6074 diff -NurpP --minimal linux-2.6.27.3/fs/nfsd/auth.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/auth.c
6075 --- linux-2.6.27.3/fs/nfsd/auth.c       2008-07-13 23:51:29.000000000 +0200
6076 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/auth.c  2008-10-13 14:54:20.000000000 +0200
6077 @@ -10,6 +10,7 @@
6078  #include <linux/sunrpc/svcauth.h>
6079  #include <linux/nfsd/nfsd.h>
6080  #include <linux/nfsd/export.h>
6081 +#include <linux/vs_tag.h>
6082  #include "auth.h"
6083  
6084  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6085 @@ -55,19 +56,23 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6086                 get_group_info(cred.cr_group_info);
6087  
6088         if (cred.cr_uid != (uid_t) -1)
6089 -               current->fsuid = cred.cr_uid;
6090 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6091         else
6092                 current->fsuid = exp->ex_anon_uid;
6093         if (cred.cr_gid != (gid_t) -1)
6094 -               current->fsgid = cred.cr_gid;
6095 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6096         else
6097                 current->fsgid = exp->ex_anon_gid;
6098  
6099 +       /* this desperately needs a tag :) */
6100 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6101 +
6102         if (!cred.cr_group_info)
6103                 return -ENOMEM;
6104         ret = set_current_groups(cred.cr_group_info);
6105         put_group_info(cred.cr_group_info);
6106 -       if ((cred.cr_uid)) {
6107 +
6108 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
6109                 current->cap_effective =
6110                         cap_drop_nfsd_set(current->cap_effective);
6111         } else {
6112 diff -NurpP --minimal linux-2.6.27.3/fs/nfsd/nfs3xdr.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/nfs3xdr.c
6113 --- linux-2.6.27.3/fs/nfsd/nfs3xdr.c    2008-07-13 23:51:29.000000000 +0200
6114 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/nfs3xdr.c       2008-10-13 14:54:20.000000000 +0200
6115 @@ -21,6 +21,7 @@
6116  #include <linux/sunrpc/svc.h>
6117  #include <linux/nfsd/nfsd.h>
6118  #include <linux/nfsd/xdr3.h>
6119 +#include <linux/vs_tag.h>
6120  #include "auth.h"
6121  
6122  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6123 @@ -108,6 +109,8 @@ static __be32 *
6124  decode_sattr3(__be32 *p, struct iattr *iap)
6125  {
6126         u32     tmp;
6127 +       uid_t   uid = 0;
6128 +       gid_t   gid = 0;
6129  
6130         iap->ia_valid = 0;
6131  
6132 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6133         }
6134         if (*p++) {
6135                 iap->ia_valid |= ATTR_UID;
6136 -               iap->ia_uid = ntohl(*p++);
6137 +               uid = ntohl(*p++);
6138         }
6139         if (*p++) {
6140                 iap->ia_valid |= ATTR_GID;
6141 -               iap->ia_gid = ntohl(*p++);
6142 +               gid = ntohl(*p++);
6143         }
6144 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6145 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6146 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6147         if (*p++) {
6148                 u64     newsize;
6149  
6150 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6151         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6152         *p++ = htonl((u32) stat->mode);
6153         *p++ = htonl((u32) stat->nlink);
6154 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6155 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6156 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6157 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6158 +               stat->uid, stat->tag)));
6159 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6160 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6161 +               stat->gid, stat->tag)));
6162         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6163                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6164         } else {
6165 diff -NurpP --minimal linux-2.6.27.3/fs/nfsd/nfs4xdr.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/nfs4xdr.c
6166 --- linux-2.6.27.3/fs/nfsd/nfs4xdr.c    2008-10-13 14:52:06.000000000 +0200
6167 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/nfs4xdr.c       2008-10-13 14:54:20.000000000 +0200
6168 @@ -58,6 +58,7 @@
6169  #include <linux/nfs4_acl.h>
6170  #include <linux/sunrpc/gss_api.h>
6171  #include <linux/sunrpc/svcauth_gss.h>
6172 +#include <linux/vs_tag.h>
6173  
6174  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6175  
6176 @@ -1704,14 +1705,18 @@ out_acl:
6177                 WRITE32(stat.nlink);
6178         }
6179         if (bmval1 & FATTR4_WORD1_OWNER) {
6180 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6181 +               status = nfsd4_encode_user(rqstp,
6182 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6183 +                       stat.uid, stat.tag), &p, &buflen);
6184                 if (status == nfserr_resource)
6185                         goto out_resource;
6186                 if (status)
6187                         goto out;
6188         }
6189         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6190 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6191 +               status = nfsd4_encode_group(rqstp,
6192 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6193 +                       stat.gid, stat.tag), &p, &buflen);
6194                 if (status == nfserr_resource)
6195                         goto out_resource;
6196                 if (status)
6197 diff -NurpP --minimal linux-2.6.27.3/fs/nfsd/nfsxdr.c linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/nfsxdr.c
6198 --- linux-2.6.27.3/fs/nfsd/nfsxdr.c     2008-07-13 23:51:29.000000000 +0200
6199 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/nfsd/nfsxdr.c        2008-10-13 14:54:20.000000000 +0200
6200 @@ -15,6 +15,7 @@
6201  #include <linux/nfsd/nfsd.h>
6202  #include <linux/nfsd/xdr.h>
6203  #include <linux/mm.h>
6204 +#include <linux/vs_tag.h>
6205  #include "auth.h"
6206  
6207  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6208 @@ -98,6 +99,8 @@ static __be32 *
6209  decode_sattr(__be32 *p, struct iattr *iap)
6210  {
6211         u32     tmp, tmp1;
6212 +       uid_t   uid = 0;
6213 +       gid_t   gid = 0;
6214  
6215         iap->ia_valid = 0;
6216  
6217 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6218         }
6219         if ((tmp = ntohl(*p++)) != (u32)-1) {
6220                 iap->ia_valid |= ATTR_UID;
6221 -               iap->ia_uid = tmp;
6222 +               uid = tmp;
6223         }
6224         if ((tmp = ntohl(*p++)) != (u32)-1) {
6225                 iap->ia_valid |= ATTR_GID;
6226 -               iap->ia_gid = tmp;
6227 +               gid = tmp;
6228         }
6229 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6230 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6231 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6232         if ((tmp = ntohl(*p++)) != (u32)-1) {
6233                 iap->ia_valid |= ATTR_SIZE;
6234                 iap->ia_size = tmp;
6235 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6236         *p++ = htonl(nfs_ftypes[type >> 12]);
6237         *p++ = htonl((u32) stat->mode);
6238         *p++ = htonl((u32) stat->nlink);
6239 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6240 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6241 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6242 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6243 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6244 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6245  
6246         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6247                 *p++ = htonl(NFS_MAXPATHLEN);
6248 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/dlm/dlmfs.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/dlm/dlmfs.c
6249 --- linux-2.6.27.3/fs/ocfs2/dlm/dlmfs.c 2008-10-13 14:52:06.000000000 +0200
6250 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/dlm/dlmfs.c    2008-10-13 14:54:20.000000000 +0200
6251 @@ -43,6 +43,7 @@
6252  #include <linux/init.h>
6253  #include <linux/string.h>
6254  #include <linux/backing-dev.h>
6255 +#include <linux/vs_tag.h>
6256  
6257  #include <asm/uaccess.h>
6258  
6259 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6260                 inode->i_mode = mode;
6261                 inode->i_uid = current->fsuid;
6262                 inode->i_gid = current->fsgid;
6263 +               inode->i_tag = dx_current_fstag(sb);
6264                 inode->i_blocks = 0;
6265                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6266                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6267 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6268         inode->i_mode = mode;
6269         inode->i_uid = current->fsuid;
6270         inode->i_gid = current->fsgid;
6271 +       inode->i_tag = dx_current_fstag(sb);
6272         inode->i_blocks = 0;
6273         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6274         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6275 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/dlmglue.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/dlmglue.c
6276 --- linux-2.6.27.3/fs/ocfs2/dlmglue.c   2008-10-13 14:52:06.000000000 +0200
6277 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/dlmglue.c      2008-10-13 14:54:20.000000000 +0200
6278 @@ -1846,6 +1846,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6279         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6280         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6281         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6282 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6283         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6284         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6285         lvb->lvb_iatime_packed  =
6286 @@ -1900,6 +1901,7 @@ static void ocfs2_refresh_inode_from_lvb
6287  
6288         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6289         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6290 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6291         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6292         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6293         ocfs2_unpack_timespec(&inode->i_atime,
6294 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/dlmglue.h linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/dlmglue.h
6295 --- linux-2.6.27.3/fs/ocfs2/dlmglue.h   2008-07-13 23:51:29.000000000 +0200
6296 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/dlmglue.h      2008-10-13 14:54:20.000000000 +0200
6297 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6298         __be16       lvb_inlink;
6299         __be32       lvb_iattr;
6300         __be32       lvb_igeneration;
6301 -       __be32       lvb_reserved2;
6302 +       __be16       lvb_itag;
6303 +       __be16       lvb_reserved2;
6304  };
6305  
6306  /* ocfs2_inode_lock_full() 'arg_flags' flags */
6307 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/file.c
6308 --- linux-2.6.27.3/fs/ocfs2/file.c      2008-10-13 14:52:06.000000000 +0200
6309 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/file.c 2008-10-13 14:54:20.000000000 +0200
6310 @@ -1058,13 +1058,15 @@ int ocfs2_setattr(struct dentry *dentry,
6311                 mlog(0, "uid change: %d\n", attr->ia_uid);
6312         if (attr->ia_valid & ATTR_GID)
6313                 mlog(0, "gid change: %d\n", attr->ia_gid);
6314 +       if (attr->ia_valid & ATTR_TAG)
6315 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6316         if (attr->ia_valid & ATTR_SIZE)
6317                 mlog(0, "size change...\n");
6318         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6319                 mlog(0, "time change...\n");
6320  
6321  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6322 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6323 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6324         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6325                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6326                 return 0;
6327 @@ -2227,6 +2229,7 @@ const struct inode_operations ocfs2_file
6328         .setattr        = ocfs2_setattr,
6329         .getattr        = ocfs2_getattr,
6330         .permission     = ocfs2_permission,
6331 +       .sync_flags     = ocfs2_sync_flags,
6332         .fallocate      = ocfs2_fallocate,
6333  };
6334  
6335 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/inode.c
6336 --- linux-2.6.27.3/fs/ocfs2/inode.c     2008-07-13 23:51:29.000000000 +0200
6337 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/inode.c        2008-10-13 14:54:20.000000000 +0200
6338 @@ -28,6 +28,7 @@
6339  #include <linux/slab.h>
6340  #include <linux/highmem.h>
6341  #include <linux/pagemap.h>
6342 +#include <linux/vs_tag.h>
6343  
6344  #include <asm/byteorder.h>
6345  
6346 @@ -42,6 +43,7 @@
6347  #include "file.h"
6348  #include "heartbeat.h"
6349  #include "inode.h"
6350 +#include "ioctl.h"
6351  #include "journal.h"
6352  #include "namei.h"
6353  #include "suballoc.h"
6354 @@ -74,11 +76,13 @@ void ocfs2_set_inode_flags(struct inode 
6355  {
6356         unsigned int flags = OCFS2_I(inode)->ip_attr;
6357  
6358 -       inode->i_flags &= ~(S_IMMUTABLE |
6359 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6360                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6361  
6362         if (flags & OCFS2_IMMUTABLE_FL)
6363                 inode->i_flags |= S_IMMUTABLE;
6364 +       if (flags & OCFS2_IXUNLINK_FL)
6365 +               inode->i_flags |= S_IXUNLINK;
6366  
6367         if (flags & OCFS2_SYNC_FL)
6368                 inode->i_flags |= S_SYNC;
6369 @@ -88,25 +92,85 @@ void ocfs2_set_inode_flags(struct inode 
6370                 inode->i_flags |= S_NOATIME;
6371         if (flags & OCFS2_DIRSYNC_FL)
6372                 inode->i_flags |= S_DIRSYNC;
6373 +
6374 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6375 +
6376 +       if (flags & OCFS2_BARRIER_FL)
6377 +               inode->i_vflags |= V_BARRIER;
6378 +       if (flags & OCFS2_COW_FL)
6379 +               inode->i_vflags |= V_COW;
6380  }
6381  
6382  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6383  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6384  {
6385         unsigned int flags = oi->vfs_inode.i_flags;
6386 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6387 +
6388 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6389 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6390 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6391 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6392 +
6393 +       if (flags & S_IMMUTABLE)
6394 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6395 +       if (flags & S_IXUNLINK)
6396 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6397  
6398 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6399 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6400         if (flags & S_SYNC)
6401                 oi->ip_attr |= OCFS2_SYNC_FL;
6402         if (flags & S_APPEND)
6403                 oi->ip_attr |= OCFS2_APPEND_FL;
6404 -       if (flags & S_IMMUTABLE)
6405 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6406         if (flags & S_NOATIME)
6407                 oi->ip_attr |= OCFS2_NOATIME_FL;
6408         if (flags & S_DIRSYNC)
6409                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6410 +
6411 +       if (vflags & V_BARRIER)
6412 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6413 +       if (vflags & V_COW)
6414 +               oi->ip_attr |= OCFS2_COW_FL;
6415 +}
6416 +
6417 +int ocfs2_sync_flags(struct inode *inode)
6418 +{
6419 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6420 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6421 +       handle_t *handle = NULL;
6422 +       struct buffer_head *bh = NULL;
6423 +       int status;
6424 +
6425 +       status = ocfs2_inode_lock(inode, &bh, 1);
6426 +       if (status < 0) {
6427 +               mlog_errno(status);
6428 +               goto bail;
6429 +       }
6430 +
6431 +       status = -EROFS;
6432 +       if (IS_RDONLY(inode))
6433 +               goto bail_unlock;
6434 +
6435 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6436 +       if (IS_ERR(handle)) {
6437 +               status = PTR_ERR(handle);
6438 +               mlog_errno(status);
6439 +               goto bail_unlock;
6440 +       }
6441 +
6442 +       ocfs2_get_inode_flags(ocfs2_inode);
6443 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6444 +       if (status < 0)
6445 +               mlog_errno(status);
6446 +
6447 +       ocfs2_commit_trans(osb, handle);
6448 +bail_unlock:
6449 +       ocfs2_inode_unlock(inode, 1);
6450 +bail:
6451 +       if (bh)
6452 +               brelse(bh);
6453 +
6454 +       mlog_exit(status);
6455 +       return status;
6456  }
6457  
6458  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6459 @@ -219,6 +283,8 @@ int ocfs2_populate_inode(struct inode *i
6460         struct super_block *sb;
6461         struct ocfs2_super *osb;
6462         int status = -EINVAL;
6463 +       uid_t uid;
6464 +       gid_t gid;
6465  
6466         mlog_entry("(0x%p, size:%llu)\n", inode,
6467                    (unsigned long long)le64_to_cpu(fe->i_size));
6468 @@ -254,8 +320,12 @@ int ocfs2_populate_inode(struct inode *i
6469         inode->i_generation = le32_to_cpu(fe->i_generation);
6470         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6471         inode->i_mode = le16_to_cpu(fe->i_mode);
6472 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6473 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6474 +       uid = le32_to_cpu(fe->i_uid);
6475 +       gid = le32_to_cpu(fe->i_gid);
6476 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6477 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6478 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6479 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6480  
6481         /* Fast symlinks will have i_size but no allocated clusters. */
6482         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6483 @@ -1230,8 +1300,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6484  
6485         fe->i_size = cpu_to_le64(i_size_read(inode));
6486         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6487 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6488 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6489 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6490 +               inode->i_uid, inode->i_tag));
6491 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6492 +               inode->i_gid, inode->i_tag));
6493 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6494         fe->i_mode = cpu_to_le16(inode->i_mode);
6495         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6496         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6497 @@ -1259,16 +1332,25 @@ leave:
6498  void ocfs2_refresh_inode(struct inode *inode,
6499                          struct ocfs2_dinode *fe)
6500  {
6501 +       uid_t uid;
6502 +       gid_t gid;
6503 +
6504         spin_lock(&OCFS2_I(inode)->ip_lock);
6505  
6506         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6507         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6508 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6509 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6510         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6511         ocfs2_set_inode_flags(inode);
6512         i_size_write(inode, le64_to_cpu(fe->i_size));
6513         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6514 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6515 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6516 +       uid = le32_to_cpu(fe->i_uid);
6517 +       gid = le32_to_cpu(fe->i_gid);
6518 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6519 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6520 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6521 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6522         inode->i_mode = le16_to_cpu(fe->i_mode);
6523         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6524                 inode->i_blocks = 0;
6525 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/inode.h linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/inode.h
6526 --- linux-2.6.27.3/fs/ocfs2/inode.h     2008-07-13 23:51:29.000000000 +0200
6527 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/inode.h        2008-10-13 14:54:20.000000000 +0200
6528 @@ -143,6 +143,7 @@ int ocfs2_aio_write(struct file *file, s
6529  
6530  void ocfs2_set_inode_flags(struct inode *inode);
6531  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6532 +int ocfs2_sync_flags(struct inode *inode);
6533  
6534  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6535  {
6536 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ioctl.c
6537 --- linux-2.6.27.3/fs/ocfs2/ioctl.c     2008-07-13 23:51:29.000000000 +0200
6538 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ioctl.c        2008-10-13 14:54:20.000000000 +0200
6539 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6540         return status;
6541  }
6542  
6543 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6544 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6545                                 unsigned mask)
6546  {
6547         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6548 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6549         if (!S_ISDIR(inode->i_mode))
6550                 flags &= ~OCFS2_DIRSYNC_FL;
6551  
6552 +       if (IS_BARRIER(inode)) {
6553 +               vxwprintk_task(1, "messing with the barrier.");
6554 +               goto bail_unlock;
6555 +       }
6556 +
6557         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6558         if (IS_ERR(handle)) {
6559                 status = PTR_ERR(handle);
6560 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/ioctl.h linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ioctl.h
6561 --- linux-2.6.27.3/fs/ocfs2/ioctl.h     2008-07-13 23:51:29.000000000 +0200
6562 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ioctl.h        2008-10-13 14:54:20.000000000 +0200
6563 @@ -10,6 +10,9 @@
6564  #ifndef OCFS2_IOCTL_H
6565  #define OCFS2_IOCTL_H
6566  
6567 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6568 +                               unsigned mask);
6569 +
6570  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6571  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6572  
6573 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/namei.c
6574 --- linux-2.6.27.3/fs/ocfs2/namei.c     2008-07-13 23:51:29.000000000 +0200
6575 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/namei.c        2008-10-13 14:54:20.000000000 +0200
6576 @@ -40,6 +40,7 @@
6577  #include <linux/types.h>
6578  #include <linux/slab.h>
6579  #include <linux/highmem.h>
6580 +#include <linux/vs_tag.h>
6581  
6582  #define MLOG_MASK_PREFIX ML_NAMEI
6583  #include <cluster/masklog.h>
6584 @@ -366,6 +367,9 @@ static int ocfs2_mknod_locked(struct ocf
6585         u64 fe_blkno = 0;
6586         u16 suballoc_bit;
6587         struct inode *inode = NULL;
6588 +       uid_t uid;
6589 +       gid_t gid;
6590 +       tag_t tag;
6591  
6592         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
6593                    (unsigned long)dev, dentry->d_name.len,
6594 @@ -425,13 +429,19 @@ static int ocfs2_mknod_locked(struct ocf
6595         fe->i_blkno = cpu_to_le64(fe_blkno);
6596         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6597         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6598 -       fe->i_uid = cpu_to_le32(current->fsuid);
6599 +
6600 +       tag = dx_current_fstag(osb->sb);
6601 +       uid = current->fsuid;
6602         if (dir->i_mode & S_ISGID) {
6603 -               fe->i_gid = cpu_to_le32(dir->i_gid);
6604 +               gid = dir->i_gid;
6605                 if (S_ISDIR(mode))
6606                         mode |= S_ISGID;
6607         } else
6608 -               fe->i_gid = cpu_to_le32(current->fsgid);
6609 +               gid = current->fsgid;
6610 +
6611 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
6612 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
6613 +       inode->i_tag = tag;
6614         fe->i_mode = cpu_to_le16(mode);
6615         if (S_ISCHR(mode) || S_ISBLK(mode))
6616                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6617 @@ -1917,5 +1927,6 @@ const struct inode_operations ocfs2_dir_
6618         .rename         = ocfs2_rename,
6619         .setattr        = ocfs2_setattr,
6620         .getattr        = ocfs2_getattr,
6621 +       .sync_flags     = ocfs2_sync_flags,
6622         .permission     = ocfs2_permission,
6623  };
6624 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/ocfs2_fs.h linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ocfs2_fs.h
6625 --- linux-2.6.27.3/fs/ocfs2/ocfs2_fs.h  2008-10-13 14:52:06.000000000 +0200
6626 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ocfs2_fs.h     2008-10-13 14:54:20.000000000 +0200
6627 @@ -195,18 +195,23 @@
6628  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6629  
6630  /* Inode attributes, keep in sync with EXT2 */
6631 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6632 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6633 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6634 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6635 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6636 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6637 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6638 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6639 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6640 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6641 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6642 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6643 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6644 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6645 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6646 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6647 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6648  
6649 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6650 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6651 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6652 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6653 +
6654 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6655 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6656 +
6657 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6658 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6659  
6660  /*
6661   * Extent record flags (e_node.leaf.flags)
6662 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/ocfs2.h linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ocfs2.h
6663 --- linux-2.6.27.3/fs/ocfs2/ocfs2.h     2008-10-13 14:52:06.000000000 +0200
6664 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/ocfs2.h        2008-10-13 14:54:20.000000000 +0200
6665 @@ -184,6 +184,7 @@ enum ocfs2_mount_options
6666         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
6667         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
6668         OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
6669 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
6670  };
6671  
6672  #define OCFS2_OSB_SOFT_RO      0x0001
6673 diff -NurpP --minimal linux-2.6.27.3/fs/ocfs2/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/super.c
6674 --- linux-2.6.27.3/fs/ocfs2/super.c     2008-10-13 14:52:06.000000000 +0200
6675 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/ocfs2/super.c        2008-10-13 14:54:20.000000000 +0200
6676 @@ -154,6 +154,7 @@ enum {
6677         Opt_localalloc,
6678         Opt_localflocks,
6679         Opt_stack,
6680 +       Opt_tag, Opt_notag, Opt_tagid,
6681         Opt_err,
6682  };
6683  
6684 @@ -173,6 +174,9 @@ static match_table_t tokens = {
6685         {Opt_localalloc, "localalloc=%d"},
6686         {Opt_localflocks, "localflocks"},
6687         {Opt_stack, "cluster_stack=%s"},
6688 +       {Opt_tag, "tag"},
6689 +       {Opt_notag, "notag"},
6690 +       {Opt_tagid, "tagid=%u"},
6691         {Opt_err, NULL}
6692  };
6693  
6694 @@ -392,6 +396,13 @@ static int ocfs2_remount(struct super_bl
6695                 goto out;
6696         }
6697  
6698 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6699 +               !(sb->s_flags & MS_TAGGED)) {
6700 +               ret = -EINVAL;
6701 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6702 +               goto out;
6703 +       }
6704 +
6705         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6706             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6707                 ret = -EINVAL;
6708 @@ -725,6 +736,9 @@ static int ocfs2_fill_super(struct super
6709  
6710         ocfs2_complete_mount_recovery(osb);
6711  
6712 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6713 +               sb->s_flags |= MS_TAGGED;
6714 +
6715         if (ocfs2_mount_local(osb))
6716                 snprintf(nodestr, sizeof(nodestr), "local");
6717         else
6718 @@ -918,6 +932,20 @@ static int ocfs2_parse_options(struct su
6719                                OCFS2_STACK_LABEL_LEN);
6720                         mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
6721                         break;
6722 +#ifndef CONFIG_TAGGING_NONE
6723 +               case Opt_tag:
6724 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6725 +                       break;
6726 +               case Opt_notag:
6727 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6728 +                       break;
6729 +#endif
6730 +#ifdef CONFIG_PROPAGATE
6731 +               case Opt_tagid:
6732 +                       /* use args[0] */
6733 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6734 +                       break;
6735 +#endif
6736                 default:
6737                         mlog(ML_ERROR,
6738                              "Unrecognized mount option \"%s\" "
6739 diff -NurpP --minimal linux-2.6.27.3/fs/open.c linux-2.6.27.3-vs2.3.0.35.7/fs/open.c
6740 --- linux-2.6.27.3/fs/open.c    2008-10-13 14:52:06.000000000 +0200
6741 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/open.c       2008-10-13 14:54:20.000000000 +0200
6742 @@ -29,22 +29,31 @@
6743  #include <linux/rcupdate.h>
6744  #include <linux/audit.h>
6745  #include <linux/falloc.h>
6746 +#include <linux/vs_base.h>
6747 +#include <linux/vs_limit.h>
6748 +#include <linux/vs_dlimit.h>
6749 +#include <linux/vs_tag.h>
6750 +#include <linux/vs_cowbl.h>
6751  
6752  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6753  {
6754         int retval = -ENODEV;
6755  
6756         if (dentry) {
6757 +               struct super_block *sb = dentry->d_sb;
6758 +
6759                 retval = -ENOSYS;
6760 -               if (dentry->d_sb->s_op->statfs) {
6761 +               if (sb->s_op->statfs) {
6762                         memset(buf, 0, sizeof(*buf));
6763                         retval = security_sb_statfs(dentry);
6764                         if (retval)
6765                                 return retval;
6766 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6767 +                       retval = sb->s_op->statfs(dentry, buf);
6768                         if (retval == 0 && buf->f_frsize == 0)
6769                                 buf->f_frsize = buf->f_bsize;
6770                 }
6771 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6772 +                       vx_vsi_statfs(sb, buf);
6773         }
6774         return retval;
6775  }
6776 @@ -625,6 +634,10 @@ asmlinkage long sys_fchmodat(int dfd, co
6777         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6778         if (error)
6779                 goto out;
6780 +
6781 +       error = cow_check_and_break(&path);
6782 +       if (error)
6783 +               goto dput_and_out;
6784         inode = path.dentry->d_inode;
6785  
6786         error = mnt_want_write(path.mnt);
6787 @@ -658,11 +671,11 @@ static int chown_common(struct dentry * 
6788         newattrs.ia_valid =  ATTR_CTIME;
6789         if (user != (uid_t) -1) {
6790                 newattrs.ia_valid |= ATTR_UID;
6791 -               newattrs.ia_uid = user;
6792 +               newattrs.ia_uid = dx_map_uid(user);
6793         }
6794         if (group != (gid_t) -1) {
6795                 newattrs.ia_valid |= ATTR_GID;
6796 -               newattrs.ia_gid = group;
6797 +               newattrs.ia_gid = dx_map_gid(group);
6798         }
6799         if (!S_ISDIR(inode->i_mode))
6800                 newattrs.ia_valid |=
6801 @@ -685,7 +698,11 @@ asmlinkage long sys_chown(const char __u
6802         error = mnt_want_write(path.mnt);
6803         if (error)
6804                 goto out_release;
6805 -       error = chown_common(path.dentry, user, group);
6806 +#ifdef CONFIG_VSERVER_COWBL
6807 +       error = cow_check_and_break(&path);
6808 +       if (!error)
6809 +#endif
6810 +               error = chown_common(path.dentry, user, group);
6811         mnt_drop_write(path.mnt);
6812  out_release:
6813         path_put(&path);
6814 @@ -710,7 +727,11 @@ asmlinkage long sys_fchownat(int dfd, co
6815         error = mnt_want_write(path.mnt);
6816         if (error)
6817                 goto out_release;
6818 -       error = chown_common(path.dentry, user, group);
6819 +#ifdef CONFIG_VSERVER_COWBL
6820 +       error = cow_check_and_break(&path);
6821 +       if (!error)
6822 +#endif
6823 +               error = chown_common(path.dentry, user, group);
6824         mnt_drop_write(path.mnt);
6825  out_release:
6826         path_put(&path);
6827 @@ -729,7 +750,11 @@ asmlinkage long sys_lchown(const char __
6828         error = mnt_want_write(path.mnt);
6829         if (error)
6830                 goto out_release;
6831 -       error = chown_common(path.dentry, user, group);
6832 +#ifdef CONFIG_VSERVER_COWBL
6833 +       error = cow_check_and_break(&path);
6834 +       if (!error)
6835 +#endif
6836 +               error = chown_common(path.dentry, user, group);
6837         mnt_drop_write(path.mnt);
6838  out_release:
6839         path_put(&path);
6840 @@ -969,6 +994,7 @@ static void __put_unused_fd(struct files
6841         __FD_CLR(fd, fdt->open_fds);
6842         if (fd < files->next_fd)
6843                 files->next_fd = fd;
6844 +       vx_openfd_dec(fd);
6845  }
6846  
6847  void put_unused_fd(unsigned int fd)
6848 diff -NurpP --minimal linux-2.6.27.3/fs/proc/array.c linux-2.6.27.3-vs2.3.0.35.7/fs/proc/array.c
6849 --- linux-2.6.27.3/fs/proc/array.c      2008-10-13 14:52:06.000000000 +0200
6850 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/array.c 2008-10-13 14:54:20.000000000 +0200
6851 @@ -81,6 +81,8 @@
6852  #include <linux/seq_file.h>
6853  #include <linux/pid_namespace.h>
6854  #include <linux/tracehook.h>
6855 +#include <linux/vs_context.h>
6856 +#include <linux/vs_network.h>
6857  
6858  #include <asm/pgtable.h>
6859  #include <asm/processor.h>
6860 @@ -142,8 +144,9 @@ static const char *task_state_array[] = 
6861         "D (disk sleep)",       /*  2 */
6862         "T (stopped)",          /*  4 */
6863         "T (tracing stop)",     /*  8 */
6864 -       "Z (zombie)",           /* 16 */
6865 -       "X (dead)"              /* 32 */
6866 +       "H (on hold)",          /* 16 */
6867 +       "Z (zombie)",           /* 32 */
6868 +       "X (dead)",             /* 64 */
6869  };
6870  
6871  static inline const char *get_task_state(struct task_struct *tsk)
6872 @@ -164,6 +167,7 @@ static inline void task_state(struct seq
6873         struct group_info *group_info;
6874         int g;
6875         struct fdtable *fdt = NULL;
6876 +/* +   pid_t pid, ptgid, tppid, tgid; */
6877         pid_t ppid, tpid;
6878  
6879         rcu_read_lock();
6880 @@ -175,6 +179,12 @@ static inline void task_state(struct seq
6881                 if (tracer)
6882                         tpid = task_pid_nr_ns(tracer, ns);
6883         }
6884 +/*     tgid = vx_map_tgid(p->tgid);
6885 +       pid = vx_map_pid(p->pid);
6886 +       ptgid = vx_map_pid(pid_alive(p) ?
6887 +               rcu_dereference(p->real_parent)->tgid : 0);
6888 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
6889 +               rcu_dereference(p->parent)->pid : 0); */
6890         seq_printf(m,
6891                 "State:\t%s\n"
6892                 "Tgid:\t%d\n"
6893 @@ -286,7 +296,7 @@ static inline void task_sig(struct seq_f
6894  }
6895  
6896  static void render_cap_t(struct seq_file *m, const char *header,
6897 -                       kernel_cap_t *a)
6898 +                       struct vx_info *vxi, kernel_cap_t *a)
6899  {
6900         unsigned __capi;
6901  
6902 @@ -300,10 +310,10 @@ static void render_cap_t(struct seq_file
6903  
6904  static inline void task_cap(struct seq_file *m, struct task_struct *p)
6905  {
6906 -       render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
6907 -       render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
6908 -       render_cap_t(m, "CapEff:\t", &p->cap_effective);
6909 -       render_cap_t(m, "CapBnd:\t", &p->cap_bset);
6910 +       render_cap_t(m, "CapInh:\t", p->vx_info, &p->cap_inheritable);
6911 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &p->cap_permitted);
6912 +       render_cap_t(m, "CapEff:\t", p->vx_info, &p->cap_effective);
6913 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &p->cap_bset);
6914  }
6915  
6916  static inline void task_context_switch_counts(struct seq_file *m,
6917 @@ -315,6 +325,45 @@ static inline void task_context_switch_c
6918                         p->nivcsw);
6919  }
6920  
6921 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6922 +                       struct pid *pid, struct task_struct *task)
6923 +{
6924 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6925 +                       "Count:\t%u\n"
6926 +                       "uts:\t%p(%c)\n"
6927 +                       "ipc:\t%p(%c)\n"
6928 +                       "mnt:\t%p(%c)\n"
6929 +                       "pid:\t%p(%c)\n"
6930 +                       "user:\t%p(%c)\n"
6931 +                       "net:\t%p(%c)\n",
6932 +                       task->nsproxy,
6933 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6934 +                       atomic_read(&task->nsproxy->count),
6935 +                       task->nsproxy->uts_ns,
6936 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6937 +                       task->nsproxy->ipc_ns,
6938 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6939 +                       task->nsproxy->mnt_ns,
6940 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6941 +                       task->nsproxy->pid_ns,
6942 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6943 +                       task->nsproxy->user_ns,
6944 +                       (task->nsproxy->user_ns == init_task.nsproxy->user_ns ? 'I' : '-'),
6945 +                       task->nsproxy->net_ns,
6946 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6947 +       return 0;
6948 +}
6949 +
6950 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6951 +{
6952 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6953 +               return;
6954 +
6955 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6956 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6957 +}
6958 +
6959 +
6960  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6961                         struct pid *pid, struct task_struct *task)
6962  {
6963 @@ -330,6 +379,7 @@ int proc_pid_status(struct seq_file *m, 
6964         task_sig(m, task);
6965         task_cap(m, task);
6966         cpuset_task_status_allowed(m, task);
6967 +       task_vs_id(m, task);
6968  #if defined(CONFIG_S390)
6969         task_show_regs(m, task);
6970  #endif
6971 @@ -442,6 +492,17 @@ static int do_task_stat(struct seq_file 
6972         /* convert nsec -> ticks */
6973         start_time = nsec_to_clock_t(start_time);
6974  
6975 +       /* fixup start time for virt uptime */
6976 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6977 +               unsigned long long bias =
6978 +                       current->vx_info->cvirt.bias_clock;
6979 +
6980 +               if (start_time > bias)
6981 +                       start_time -= bias;
6982 +               else
6983 +                       start_time = 0;
6984 +       }
6985 +
6986         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6987  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6988  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6989 diff -NurpP --minimal linux-2.6.27.3/fs/proc/base.c linux-2.6.27.3-vs2.3.0.35.7/fs/proc/base.c
6990 --- linux-2.6.27.3/fs/proc/base.c       2008-10-13 14:52:06.000000000 +0200
6991 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/base.c  2008-10-13 14:54:20.000000000 +0200
6992 @@ -79,6 +79,8 @@
6993  #include <linux/oom.h>
6994  #include <linux/elf.h>
6995  #include <linux/pid_namespace.h>
6996 +#include <linux/vs_context.h>
6997 +#include <linux/vs_network.h>
6998  #include "internal.h"
6999  
7000  /* NOTE:
7001 @@ -1439,6 +1441,8 @@ static struct inode *proc_pid_make_inode
7002                 inode->i_uid = task->euid;
7003                 inode->i_gid = task->egid;
7004         }
7005 +       /* procfs is xid tagged */
7006 +       inode->i_tag = (tag_t)vx_task_xid(task);
7007         security_task_to_inode(task, inode);
7008  
7009  out:
7010 @@ -1979,6 +1983,13 @@ static struct dentry *proc_pident_lookup
7011         if (!task)
7012                 goto out_no_task;
7013  
7014 +       /* TODO: maybe we can come up with a generic approach? */
7015 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7016 +               (dentry->d_name.len == 5) &&
7017 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7018 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7019 +               goto out;
7020 +
7021         /*
7022          * Yes, it does not scale. And it should not. Don't add
7023          * new entries into /proc/<tgid>/ without very good reasons.
7024 @@ -2366,7 +2377,7 @@ out_iput:
7025  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7026  {
7027         struct dentry *error;
7028 -       struct task_struct *task = get_proc_task(dir);
7029 +       struct task_struct *task = get_proc_task_real(dir);
7030         const struct pid_entry *p, *last;
7031  
7032         error = ERR_PTR(-ENOENT);
7033 @@ -2449,6 +2460,9 @@ static int proc_tgid_io_accounting(struc
7034  static const struct file_operations proc_task_operations;
7035  static const struct inode_operations proc_task_inode_operations;
7036  
7037 +extern int proc_pid_vx_info(struct task_struct *, char *);
7038 +extern int proc_pid_nx_info(struct task_struct *, char *);
7039 +
7040  static const struct pid_entry tgid_base_stuff[] = {
7041         DIR("task",       S_IRUGO|S_IXUGO, task),
7042         DIR("fd",         S_IRUSR|S_IXUSR, fd),
7043 @@ -2503,6 +2517,8 @@ static const struct pid_entry tgid_base_
7044  #ifdef CONFIG_CGROUPS
7045         REG("cgroup",  S_IRUGO, cgroup),
7046  #endif
7047 +       INF("vinfo",      S_IRUGO, pid_vx_info),
7048 +       INF("ninfo",      S_IRUGO, pid_nx_info),
7049         INF("oom_score",  S_IRUGO, oom_score),
7050         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
7051  #ifdef CONFIG_AUDITSYSCALL
7052 @@ -2518,6 +2534,7 @@ static const struct pid_entry tgid_base_
7053  #ifdef CONFIG_TASK_IO_ACCOUNTING
7054         INF("io",       S_IRUGO, tgid_io_accounting),
7055  #endif
7056 +       ONE("nsproxy",  S_IRUGO, pid_nsproxy),
7057  };
7058  
7059  static int proc_tgid_base_readdir(struct file * filp,
7060 @@ -2714,7 +2731,7 @@ retry:
7061         iter.task = NULL;
7062         pid = find_ge_pid(iter.tgid, ns);
7063         if (pid) {
7064 -               iter.tgid = pid_nr_ns(pid, ns);
7065 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7066                 iter.task = pid_task(pid, PIDTYPE_PID);
7067                 /* What we to know is if the pid we have find is the
7068                  * pid of a thread_group_leader.  Testing for task
7069 @@ -2744,7 +2761,7 @@ static int proc_pid_fill_cache(struct fi
7070         struct tgid_iter iter)
7071  {
7072         char name[PROC_NUMBUF];
7073 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7074 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7075         return proc_fill_cache(filp, dirent, filldir, name, len,
7076                                 proc_pid_instantiate, iter.task, NULL);
7077  }
7078 @@ -2753,7 +2770,7 @@ static int proc_pid_fill_cache(struct fi
7079  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7080  {
7081         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7082 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7083 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7084         struct tgid_iter iter;
7085         struct pid_namespace *ns;
7086  
7087 @@ -2773,6 +2790,8 @@ int proc_pid_readdir(struct file * filp,
7088              iter.task;
7089              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7090                 filp->f_pos = iter.tgid + TGID_OFFSET;
7091 +               if (!vx_proc_task_visible(iter.task))
7092 +                       continue;
7093                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7094                         put_task_struct(iter.task);
7095                         goto out;
7096 @@ -2915,6 +2934,8 @@ static struct dentry *proc_task_lookup(s
7097         tid = name_to_int(dentry);
7098         if (tid == ~0U)
7099                 goto out;
7100 +       if (vx_current_initpid(tid))
7101 +               goto out;
7102  
7103         ns = dentry->d_sb->s_fs_info;
7104         rcu_read_lock();
7105 diff -NurpP --minimal linux-2.6.27.3/fs/proc/generic.c linux-2.6.27.3-vs2.3.0.35.7/fs/proc/generic.c
7106 --- linux-2.6.27.3/fs/proc/generic.c    2008-10-13 14:52:06.000000000 +0200
7107 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/generic.c       2008-10-13 14:54:20.000000000 +0200
7108 @@ -21,6 +21,7 @@
7109  #include <linux/bitops.h>
7110  #include <linux/spinlock.h>
7111  #include <linux/completion.h>
7112 +#include <linux/vserver/inode.h>
7113  #include <asm/uaccess.h>
7114  
7115  #include "internal.h"
7116 @@ -384,6 +385,8 @@ struct dentry *proc_lookup_de(struct pro
7117         for (de = de->subdir; de ; de = de->next) {
7118                 if (de->namelen != dentry->d_name.len)
7119                         continue;
7120 +                       if (!vx_hide_check(0, de->vx_flags))
7121 +                               continue;
7122                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7123                         unsigned int ino;
7124  
7125 @@ -392,6 +395,8 @@ struct dentry *proc_lookup_de(struct pro
7126                         spin_unlock(&proc_subdir_lock);
7127                         error = -EINVAL;
7128                         inode = proc_get_inode(dir->i_sb, ino, de);
7129 +                               /* generic proc entries belong to the host */
7130 +                               inode->i_tag = 0;
7131                         goto out_unlock;
7132                 }
7133         }
7134 @@ -472,6 +477,8 @@ int proc_readdir_de(struct proc_dir_entr
7135  
7136                                 /* filldir passes info to user space */
7137                                 de_get(de);
7138 +                               if (!vx_hide_check(0, de->vx_flags))
7139 +                                       goto skip;
7140                                 spin_unlock(&proc_subdir_lock);
7141                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7142                                             de->low_ino, de->mode >> 12) < 0) {
7143 @@ -479,6 +486,7 @@ int proc_readdir_de(struct proc_dir_entr
7144                                         goto out;
7145                                 }
7146                                 spin_lock(&proc_subdir_lock);
7147 +                       skip:
7148                                 filp->f_pos++;
7149                                 next = de->next;
7150                                 de_put(de);
7151 @@ -593,6 +601,7 @@ static struct proc_dir_entry *__proc_cre
7152         ent->nlink = nlink;
7153         atomic_set(&ent->count, 1);
7154         ent->pde_users = 0;
7155 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7156         spin_lock_init(&ent->pde_unload_lock);
7157         ent->pde_unload_completion = NULL;
7158         INIT_LIST_HEAD(&ent->pde_openers);
7159 @@ -616,7 +625,8 @@ struct proc_dir_entry *proc_symlink(cons
7160                                 kfree(ent->data);
7161                                 kfree(ent);
7162                                 ent = NULL;
7163 -                       }
7164 +                       } else
7165 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7166                 } else {
7167                         kfree(ent);
7168                         ent = NULL;
7169 diff -NurpP --minimal linux-2.6.27.3/fs/proc/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/proc/inode.c
7170 --- linux-2.6.27.3/fs/proc/inode.c      2008-10-13 14:52:06.000000000 +0200
7171 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/inode.c 2008-10-13 14:54:20.000000000 +0200
7172 @@ -469,6 +469,8 @@ struct inode *proc_get_inode(struct supe
7173                         inode->i_uid = de->uid;
7174                         inode->i_gid = de->gid;
7175                 }
7176 +               if (de->vx_flags)
7177 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7178                 if (de->size)
7179                         inode->i_size = de->size;
7180                 if (de->nlink)
7181 diff -NurpP --minimal linux-2.6.27.3/fs/proc/internal.h linux-2.6.27.3-vs2.3.0.35.7/fs/proc/internal.h
7182 --- linux-2.6.27.3/fs/proc/internal.h   2008-10-13 14:52:06.000000000 +0200
7183 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/internal.h      2008-10-13 14:54:20.000000000 +0200
7184 @@ -10,6 +10,7 @@
7185   */
7186  
7187  #include <linux/proc_fs.h>
7188 +#include <linux/vs_pid.h>
7189  
7190  extern struct proc_dir_entry proc_root;
7191  #ifdef CONFIG_PROC_SYSCTL
7192 @@ -55,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
7193                                 struct pid *pid, struct task_struct *task);
7194  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7195                                 struct pid *pid, struct task_struct *task);
7196 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7197 +                               struct pid *pid, struct task_struct *task);
7198 +
7199  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7200  
7201  extern const struct file_operations proc_maps_operations;
7202 @@ -75,11 +79,16 @@ static inline struct pid *proc_pid(struc
7203         return PROC_I(inode)->pid;
7204  }
7205  
7206 -static inline struct task_struct *get_proc_task(struct inode *inode)
7207 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7208  {
7209         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7210  }
7211  
7212 +static inline struct task_struct *get_proc_task(struct inode *inode)
7213 +{
7214 +       return vx_get_proc_task(inode, proc_pid(inode));
7215 +}
7216 +
7217  static inline int proc_fd(struct inode *inode)
7218  {
7219         return PROC_I(inode)->fd;
7220 diff -NurpP --minimal linux-2.6.27.3/fs/proc/proc_misc.c linux-2.6.27.3-vs2.3.0.35.7/fs/proc/proc_misc.c
7221 --- linux-2.6.27.3/fs/proc/proc_misc.c  2008-10-13 14:52:06.000000000 +0200
7222 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/proc_misc.c     2008-10-13 14:54:20.000000000 +0200
7223 @@ -57,6 +57,8 @@
7224  #include <asm/div64.h>
7225  #include "internal.h"
7226  
7227 +#include <linux/vs_cvirt.h>
7228 +
7229  #define LOAD_INT(x) ((x) >> FSHIFT)
7230  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
7231  /*
7232 @@ -84,22 +86,38 @@ static int proc_calc_metrics(char *page,
7233  static int loadavg_read_proc(char *page, char **start, off_t off,
7234                                  int count, int *eof, void *data)
7235  {
7236 +       unsigned long running;
7237 +       unsigned int threads;
7238         int a, b, c;
7239         int len;
7240         unsigned long seq;
7241  
7242         do {
7243                 seq = read_seqbegin(&xtime_lock);
7244 -               a = avenrun[0] + (FIXED_1/200);
7245 -               b = avenrun[1] + (FIXED_1/200);
7246 -               c = avenrun[2] + (FIXED_1/200);
7247 +               if (vx_flags(VXF_VIRT_LOAD, 0)) {
7248 +                       struct vx_info *vxi = current->vx_info;
7249 +
7250 +                       a = vxi->cvirt.load[0] + (FIXED_1/200);
7251 +                       b = vxi->cvirt.load[1] + (FIXED_1/200);
7252 +                       c = vxi->cvirt.load[2] + (FIXED_1/200);
7253 +
7254 +                       running = atomic_read(&vxi->cvirt.nr_running);
7255 +                       threads = atomic_read(&vxi->cvirt.nr_threads);
7256 +               } else {
7257 +                       a = avenrun[0] + (FIXED_1/200);
7258 +                       b = avenrun[1] + (FIXED_1/200);
7259 +                       c = avenrun[2] + (FIXED_1/200);
7260 +
7261 +                       running = nr_running();
7262 +                       threads = nr_threads;
7263 +               }
7264         } while (read_seqretry(&xtime_lock, seq));
7265  
7266         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
7267                 LOAD_INT(a), LOAD_FRAC(a),
7268                 LOAD_INT(b), LOAD_FRAC(b),
7269                 LOAD_INT(c), LOAD_FRAC(c),
7270 -               nr_running(), nr_threads,
7271 +               running, threads,
7272                 task_active_pid_ns(current)->last_pid);
7273         return proc_calc_metrics(page, start, off, count, eof, len);
7274  }
7275 @@ -115,6 +133,9 @@ static int uptime_read_proc(char *page, 
7276         do_posix_clock_monotonic_gettime(&uptime);
7277         monotonic_to_bootbased(&uptime);
7278         cputime_to_timespec(idletime, &idle);
7279 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7280 +               vx_vsi_uptime(&uptime, &idle);
7281 +
7282         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
7283                         (unsigned long) uptime.tv_sec,
7284                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7285 @@ -151,7 +172,7 @@ static int meminfo_read_proc(char *page,
7286  
7287         cached = global_page_state(NR_FILE_PAGES) -
7288                         total_swapcache_pages - i.bufferram;
7289 -       if (cached < 0)
7290 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7291                 cached = 0;
7292  
7293         get_vmalloc_info(&vmi);
7294 diff -NurpP --minimal linux-2.6.27.3/fs/proc/root.c linux-2.6.27.3-vs2.3.0.35.7/fs/proc/root.c
7295 --- linux-2.6.27.3/fs/proc/root.c       2008-07-13 23:51:29.000000000 +0200
7296 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/proc/root.c  2008-10-13 14:54:20.000000000 +0200
7297 @@ -22,6 +22,10 @@
7298  
7299  #include "internal.h"
7300  
7301 +struct proc_dir_entry *proc_virtual;
7302 +
7303 +extern void proc_vx_init(void);
7304 +
7305  static int proc_test_super(struct super_block *sb, void *data)
7306  {
7307         return sb->s_fs_info == data;
7308 @@ -137,6 +141,7 @@ void __init proc_root_init(void)
7309  #endif
7310         proc_mkdir("bus", NULL);
7311         proc_sys_init();
7312 +       proc_vx_init();
7313  }
7314  
7315  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7316 diff -NurpP --minimal linux-2.6.27.3/fs/quota.c linux-2.6.27.3-vs2.3.0.35.7/fs/quota.c
7317 --- linux-2.6.27.3/fs/quota.c   2008-10-13 14:52:06.000000000 +0200
7318 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/quota.c      2008-10-13 14:54:20.000000000 +0200
7319 @@ -18,6 +18,7 @@
7320  #include <linux/capability.h>
7321  #include <linux/quotaops.h>
7322  #include <linux/types.h>
7323 +#include <linux/vs_context.h>
7324  
7325  /* Check validity of generic quotactl commands */
7326  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7327 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7328         if (cmd == Q_GETQUOTA) {
7329                 if (((type == USRQUOTA && current->euid != id) ||
7330                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7331 -                   !capable(CAP_SYS_ADMIN))
7332 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7333                         return -EPERM;
7334         }
7335         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7336 -               if (!capable(CAP_SYS_ADMIN))
7337 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7338                         return -EPERM;
7339  
7340         return 0;
7341 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7342         if (cmd == Q_XGETQUOTA) {
7343                 if (((type == XQM_USRQUOTA && current->euid != id) ||
7344                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7345 -                    !capable(CAP_SYS_ADMIN))
7346 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7347                         return -EPERM;
7348         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7349 -               if (!capable(CAP_SYS_ADMIN))
7350 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7351                         return -EPERM;
7352         }
7353  
7354 @@ -334,6 +335,46 @@ static int do_quotactl(struct super_bloc
7355         return 0;
7356  }
7357  
7358 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7359 +
7360 +#include <linux/vroot.h>
7361 +#include <linux/major.h>
7362 +#include <linux/module.h>
7363 +#include <linux/kallsyms.h>
7364 +#include <linux/vserver/debug.h>
7365 +
7366 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7367 +
7368 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7369 +
7370 +int register_vroot_grb(vroot_grb_func *func) {
7371 +       int ret = -EBUSY;
7372 +
7373 +       spin_lock(&vroot_grb_lock);
7374 +       if (!vroot_get_real_bdev) {
7375 +               vroot_get_real_bdev = func;
7376 +               ret = 0;
7377 +       }
7378 +       spin_unlock(&vroot_grb_lock);
7379 +       return ret;
7380 +}
7381 +EXPORT_SYMBOL(register_vroot_grb);
7382 +
7383 +int unregister_vroot_grb(vroot_grb_func *func) {
7384 +       int ret = -EINVAL;
7385 +
7386 +       spin_lock(&vroot_grb_lock);
7387 +       if (vroot_get_real_bdev) {
7388 +               vroot_get_real_bdev = NULL;
7389 +               ret = 0;
7390 +       }
7391 +       spin_unlock(&vroot_grb_lock);
7392 +       return ret;
7393 +}
7394 +EXPORT_SYMBOL(unregister_vroot_grb);
7395 +
7396 +#endif
7397 +
7398  /*
7399   * look up a superblock on which quota ops will be performed
7400   * - use the name of a block device to find the superblock thereon
7401 @@ -351,6 +392,22 @@ static inline struct super_block *quotac
7402         putname(tmp);
7403         if (IS_ERR(bdev))
7404                 return ERR_CAST(bdev);
7405 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7406 +       if (bdev && bdev->bd_inode &&
7407 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7408 +               struct block_device *bdnew = (void *)-EINVAL;
7409 +
7410 +               if (vroot_get_real_bdev)
7411 +                       bdnew = vroot_get_real_bdev(bdev);
7412 +               else
7413 +                       vxdprintk(VXD_CBIT(misc, 0),
7414 +                                       "vroot_get_real_bdev not set");
7415 +               bdput(bdev);
7416 +               if (IS_ERR(bdnew))
7417 +                       return ERR_PTR(PTR_ERR(bdnew));
7418 +               bdev = bdnew;
7419 +       }
7420 +#endif
7421         sb = get_super(bdev);
7422         bdput(bdev);
7423         if (!sb)
7424 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/bitmap.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/bitmap.c
7425 --- linux-2.6.27.3/fs/reiserfs/bitmap.c 2008-07-13 23:51:29.000000000 +0200
7426 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/bitmap.c    2008-10-13 14:54:20.000000000 +0200
7427 @@ -13,6 +13,7 @@
7428  #include <linux/reiserfs_fs_sb.h>
7429  #include <linux/reiserfs_fs_i.h>
7430  #include <linux/quotaops.h>
7431 +#include <linux/vs_dlimit.h>
7432  
7433  #define PREALLOCATION_SIZE 9
7434  
7435 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7436         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7437  
7438         journal_mark_dirty(th, s, sbh);
7439 -       if (for_unformatted)
7440 +       if (for_unformatted) {
7441 +               DLIMIT_FREE_BLOCK(inode, 1);
7442                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7443 +       }
7444  }
7445  
7446  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7447 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7448         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7449         int passno = 0;
7450         int nr_allocated = 0;
7451 +       int blocks;
7452  
7453         determine_prealloc_size(hint);
7454         if (!hint->formatted_node) {
7455 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7456                                "reiserquota: allocating %d blocks id=%u",
7457                                amount_needed, hint->inode->i_uid);
7458  #endif
7459 -               quota_ret =
7460 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7461 -               if (quota_ret)  /* Quota exceeded? */
7462 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7463 +                       amount_needed);
7464 +               if (quota_ret)
7465                         return QUOTA_EXCEEDED;
7466 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7467 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7468 +                               amount_needed);
7469 +                       return NO_DISK_SPACE;
7470 +               }
7471 +
7472                 if (hint->preallocate && hint->prealloc_size) {
7473  #ifdef REISERQUOTA_DEBUG
7474                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7475                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7476                                        hint->prealloc_size, hint->inode->i_uid);
7477  #endif
7478 -                       quota_ret =
7479 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7480 -                                                        hint->prealloc_size);
7481 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7482 +                               hint->prealloc_size);
7483 +                       if (!quota_ret &&
7484 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7485 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7486 +                                       hint->prealloc_size);
7487 +                               quota_ret = 1;
7488 +                       }
7489                         if (quota_ret)
7490                                 hint->preallocate = hint->prealloc_size = 0;
7491                 }
7492 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7493                                                nr_allocated,
7494                                                hint->inode->i_uid);
7495  #endif
7496 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7497 +                               /* Free not allocated blocks */
7498 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7499 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7500 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7501                         }
7502                         while (nr_allocated--)
7503                                 reiserfs_free_block(hint->th, hint->inode,
7504 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7505                                REISERFS_I(hint->inode)->i_prealloc_count,
7506                                hint->inode->i_uid);
7507  #endif
7508 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7509 -                                        hint->prealloc_size - nr_allocated -
7510 -                                        REISERFS_I(hint->inode)->
7511 -                                        i_prealloc_count);
7512 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7513 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7514 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7515 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7516         }
7517  
7518         return CARRY_ON;
7519 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/file.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/file.c
7520 --- linux-2.6.27.3/fs/reiserfs/file.c   2008-07-13 23:51:29.000000000 +0200
7521 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/file.c      2008-10-13 14:54:20.000000000 +0200
7522 @@ -306,4 +306,5 @@ const struct inode_operations reiserfs_f
7523         .listxattr = reiserfs_listxattr,
7524         .removexattr = reiserfs_removexattr,
7525         .permission = reiserfs_permission,
7526 +       .sync_flags = reiserfs_sync_flags,
7527  };
7528 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/inode.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/inode.c
7529 --- linux-2.6.27.3/fs/reiserfs/inode.c  2008-10-13 14:52:06.000000000 +0200
7530 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/inode.c     2008-10-13 14:54:20.000000000 +0200
7531 @@ -18,6 +18,8 @@
7532  #include <linux/writeback.h>
7533  #include <linux/quotaops.h>
7534  #include <linux/swap.h>
7535 +#include <linux/vs_dlimit.h>
7536 +#include <linux/vs_tag.h>
7537  
7538  int reiserfs_commit_write(struct file *f, struct page *page,
7539                           unsigned from, unsigned to);
7540 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7541                  * stat data deletion */
7542                 if (!err) 
7543                         DQUOT_FREE_INODE(inode);
7544 +               DLIMIT_FREE_INODE(inode);
7545  
7546                 if (journal_end(&th, inode->i_sb, jbegin_count))
7547                         goto out;
7548 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7549         struct buffer_head *bh;
7550         struct item_head *ih;
7551         __u32 rdev;
7552 +       uid_t uid;
7553 +       gid_t gid;
7554         //int version = ITEM_VERSION_1;
7555  
7556         bh = PATH_PLAST_BUFFER(path);
7557 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7558                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7559                 unsigned long blocks;
7560  
7561 +               uid = sd_v1_uid(sd);
7562 +               gid = sd_v1_gid(sd);
7563 +
7564                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7565                 set_inode_sd_version(inode, STAT_DATA_V1);
7566                 inode->i_mode = sd_v1_mode(sd);
7567                 inode->i_nlink = sd_v1_nlink(sd);
7568 -               inode->i_uid = sd_v1_uid(sd);
7569 -               inode->i_gid = sd_v1_gid(sd);
7570                 inode->i_size = sd_v1_size(sd);
7571                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7572                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7573 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7574                 // (directories and symlinks)
7575                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7576  
7577 +               uid    = sd_v2_uid(sd);
7578 +               gid    = sd_v2_gid(sd);
7579 +
7580                 inode->i_mode = sd_v2_mode(sd);
7581                 inode->i_nlink = sd_v2_nlink(sd);
7582 -               inode->i_uid = sd_v2_uid(sd);
7583                 inode->i_size = sd_v2_size(sd);
7584 -               inode->i_gid = sd_v2_gid(sd);
7585                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7586                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7587                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7588 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7589                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7590         }
7591  
7592 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7593 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7594 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7595 +
7596         pathrelse(path);
7597         if (S_ISREG(inode->i_mode)) {
7598                 inode->i_op = &reiserfs_file_inode_operations;
7599 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7600  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7601  {
7602         struct stat_data *sd_v2 = (struct stat_data *)sd;
7603 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7604 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7605         __u16 flags;
7606  
7607 +       set_sd_v2_uid(sd_v2, uid);
7608 +       set_sd_v2_gid(sd_v2, gid);
7609         set_sd_v2_mode(sd_v2, inode->i_mode);
7610         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7611 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7612         set_sd_v2_size(sd_v2, size);
7613 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7614         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7615         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7616         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7617 @@ -1771,6 +1784,10 @@ int reiserfs_new_inode(struct reiserfs_t
7618  
7619         BUG_ON(!th->t_trans_id);
7620  
7621 +       if (DLIMIT_ALLOC_INODE(inode)) {
7622 +               err = -ENOSPC;
7623 +               goto out_bad_dlimit;
7624 +       }
7625         if (DQUOT_ALLOC_INODE(inode)) {
7626                 err = -EDQUOT;
7627                 goto out_end_trans;
7628 @@ -1956,6 +1973,9 @@ int reiserfs_new_inode(struct reiserfs_t
7629         DQUOT_FREE_INODE(inode);
7630  
7631        out_end_trans:
7632 +       DLIMIT_FREE_INODE(inode);
7633 +
7634 +      out_bad_dlimit:
7635         journal_end(th, th->t_super, th->t_blocks_allocated);
7636         /* Drop can be outside and it needs more credits so it's better to have it outside */
7637         DQUOT_DROP(inode);
7638 @@ -2842,14 +2862,19 @@ int reiserfs_commit_write(struct file *f
7639  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7640  {
7641         if (reiserfs_attrs(inode->i_sb)) {
7642 -               if (sd_attrs & REISERFS_SYNC_FL)
7643 -                       inode->i_flags |= S_SYNC;
7644 -               else
7645 -                       inode->i_flags &= ~S_SYNC;
7646                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7647                         inode->i_flags |= S_IMMUTABLE;
7648                 else
7649                         inode->i_flags &= ~S_IMMUTABLE;
7650 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7651 +                       inode->i_flags |= S_IXUNLINK;
7652 +               else
7653 +                       inode->i_flags &= ~S_IXUNLINK;
7654 +
7655 +               if (sd_attrs & REISERFS_SYNC_FL)
7656 +                       inode->i_flags |= S_SYNC;
7657 +               else
7658 +                       inode->i_flags &= ~S_SYNC;
7659                 if (sd_attrs & REISERFS_APPEND_FL)
7660                         inode->i_flags |= S_APPEND;
7661                 else
7662 @@ -2862,6 +2887,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7663                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7664                 else
7665                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7666 +
7667 +               if (sd_attrs & REISERFS_BARRIER_FL)
7668 +                       inode->i_vflags |= V_BARRIER;
7669 +               else
7670 +                       inode->i_vflags &= ~V_BARRIER;
7671 +               if (sd_attrs & REISERFS_COW_FL)
7672 +                       inode->i_vflags |= V_COW;
7673 +               else
7674 +                       inode->i_vflags &= ~V_COW;
7675         }
7676  }
7677  
7678 @@ -2872,6 +2906,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7679                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7680                 else
7681                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7682 +               if (inode->i_flags & S_IXUNLINK)
7683 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7684 +               else
7685 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7686 +
7687                 if (inode->i_flags & S_SYNC)
7688                         *sd_attrs |= REISERFS_SYNC_FL;
7689                 else
7690 @@ -2884,6 +2923,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7691                         *sd_attrs |= REISERFS_NOTAIL_FL;
7692                 else
7693                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7694 +
7695 +               if (inode->i_vflags & V_BARRIER)
7696 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7697 +               else
7698 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7699 +               if (inode->i_vflags & V_COW)
7700 +                       *sd_attrs |= REISERFS_COW_FL;
7701 +               else
7702 +                       *sd_attrs &= ~REISERFS_COW_FL;
7703         }
7704  }
7705  
7706 @@ -3051,6 +3099,22 @@ static ssize_t reiserfs_direct_IO(int rw
7707                                   reiserfs_get_blocks_direct_io, NULL);
7708  }
7709  
7710 +int reiserfs_sync_flags(struct inode *inode)
7711 +{
7712 +       u16 oldflags, newflags;
7713 +
7714 +       oldflags = REISERFS_I(inode)->i_attrs;
7715 +       newflags = oldflags;
7716 +       i_attrs_to_sd_attrs(inode, &newflags);
7717 +
7718 +       if (oldflags ^ newflags) {
7719 +               REISERFS_I(inode)->i_attrs = newflags;
7720 +               inode->i_ctime = CURRENT_TIME_SEC;
7721 +               mark_inode_dirty(inode);
7722 +       }
7723 +       return 0;
7724 +}
7725 +
7726  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7727  {
7728         struct inode *inode = dentry->d_inode;
7729 @@ -3104,9 +3168,11 @@ int reiserfs_setattr(struct dentry *dent
7730         }
7731  
7732         error = inode_change_ok(inode, attr);
7733 +
7734         if (!error) {
7735                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7736 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7737 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7738 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7739                         error = reiserfs_chown_xattrs(inode, attr);
7740  
7741                         if (!error) {
7742 @@ -3136,6 +3202,9 @@ int reiserfs_setattr(struct dentry *dent
7743                                         inode->i_uid = attr->ia_uid;
7744                                 if (attr->ia_valid & ATTR_GID)
7745                                         inode->i_gid = attr->ia_gid;
7746 +                               if ((attr->ia_valid & ATTR_TAG) &&
7747 +                                       IS_TAGGED(inode))
7748 +                                       inode->i_tag = attr->ia_tag;
7749                                 mark_inode_dirty(inode);
7750                                 error =
7751                                     journal_end(&th, inode->i_sb, jbegin_count);
7752 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/ioctl.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/ioctl.c
7753 --- linux-2.6.27.3/fs/reiserfs/ioctl.c  2008-07-13 23:51:29.000000000 +0200
7754 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/ioctl.c     2008-10-13 14:54:20.000000000 +0200
7755 @@ -7,6 +7,7 @@
7756  #include <linux/mount.h>
7757  #include <linux/reiserfs_fs.h>
7758  #include <linux/time.h>
7759 +#include <linux/mount.h>
7760  #include <asm/uaccess.h>
7761  #include <linux/pagemap.h>
7762  #include <linux/smp_lock.h>
7763 @@ -23,7 +24,7 @@
7764  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7765                    unsigned long arg)
7766  {
7767 -       unsigned int flags;
7768 +       unsigned int flags, oldflags;
7769         int err = 0;
7770  
7771         switch (cmd) {
7772 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7773  
7774                 flags = REISERFS_I(inode)->i_attrs;
7775                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7776 +               flags &= REISERFS_FL_USER_VISIBLE;
7777                 return put_user(flags, (int __user *)arg);
7778         case REISERFS_IOC_SETFLAGS:{
7779                         if (!reiserfs_attrs(inode->i_sb))
7780 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7781                                 err = -EFAULT;
7782                                 goto setflags_out;
7783                         }
7784 +                       if (IS_BARRIER(inode)) {
7785 +                               vxwprintk_task(1, "messing with the barrier.");
7786 +                               return -EACCES;
7787 +                       }
7788                         /*
7789                          * Is it quota file? Do not allow user to mess with it
7790                          */
7791 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7792                                         goto setflags_out;
7793                                 }
7794                         }
7795 +
7796 +                       oldflags = REISERFS_I(inode)->i_attrs;
7797 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7798 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7799                         sd_attrs_to_i_attrs(flags, inode);
7800                         REISERFS_I(inode)->i_attrs = flags;
7801                         inode->i_ctime = CURRENT_TIME_SEC;
7802 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/namei.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/namei.c
7803 --- linux-2.6.27.3/fs/reiserfs/namei.c  2008-07-13 23:51:29.000000000 +0200
7804 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/namei.c     2008-10-13 14:54:20.000000000 +0200
7805 @@ -17,6 +17,7 @@
7806  #include <linux/reiserfs_acl.h>
7807  #include <linux/reiserfs_xattr.h>
7808  #include <linux/quotaops.h>
7809 +#include <linux/vs_tag.h>
7810  
7811  #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; }
7812  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7813 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7814                         reiserfs_write_unlock(dir->i_sb);
7815                         return ERR_PTR(-EACCES);
7816                 }
7817 +               dx_propagate_tag(nd, inode);
7818  
7819                 /* Propogate the priv_object flag so we know we're in the priv tree */
7820                 if (is_reiserfs_priv_object(dir))
7821 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
7822         } else {
7823                 inode->i_gid = current->fsgid;
7824         }
7825 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7826         DQUOT_INIT(inode);
7827         return 0;
7828  }
7829 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
7830         .listxattr = reiserfs_listxattr,
7831         .removexattr = reiserfs_removexattr,
7832         .permission = reiserfs_permission,
7833 +       .sync_flags = reiserfs_sync_flags,
7834  };
7835  
7836  /*
7837 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
7838         .listxattr = reiserfs_listxattr,
7839         .removexattr = reiserfs_removexattr,
7840         .permission = reiserfs_permission,
7841 +       .sync_flags = reiserfs_sync_flags,
7842  
7843  };
7844  
7845 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
7846         .listxattr = reiserfs_listxattr,
7847         .removexattr = reiserfs_removexattr,
7848         .permission = reiserfs_permission,
7849 +       .sync_flags = reiserfs_sync_flags,
7850  
7851  };
7852 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/stree.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/stree.c
7853 --- linux-2.6.27.3/fs/reiserfs/stree.c  2008-07-13 23:51:29.000000000 +0200
7854 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/stree.c     2008-10-13 14:54:20.000000000 +0200
7855 @@ -55,6 +55,7 @@
7856  #include <linux/reiserfs_fs.h>
7857  #include <linux/buffer_head.h>
7858  #include <linux/quotaops.h>
7859 +#include <linux/vs_dlimit.h>
7860  
7861  /* Does the buffer contain a disk block which is in the tree. */
7862  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7863 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7864                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7865                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7866  #endif
7867 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7868         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7869  
7870         /* Return deleted body length */
7871 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7872  #endif
7873                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7874                                                          quota_cut_bytes);
7875 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7876                         }
7877                         break;
7878                 }
7879 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7880                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7881                        quota_cut_bytes, p_s_inode->i_uid, '?');
7882  #endif
7883 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7884         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7885         return n_ret_value;
7886  }
7887 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7888                 pathrelse(p_s_search_path);
7889                 return -EDQUOT;
7890         }
7891 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7892 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7893 +               pathrelse(p_s_search_path);
7894 +               return -ENOSPC;
7895 +       }
7896         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7897                        n_pasted_size);
7898  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7899 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7900                        n_pasted_size, inode->i_uid,
7901                        key2type(&(p_s_key->on_disk_key)));
7902  #endif
7903 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7904         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7905         return retval;
7906  }
7907 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7908                         pathrelse(p_s_path);
7909                         return -EDQUOT;
7910                 }
7911 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7912 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7913 +                       pathrelse(p_s_path);
7914 +                       return -ENOSPC;
7915 +               }
7916         }
7917         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7918                        IH_SIZE + ih_item_len(p_s_ih));
7919 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7920                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7921                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7922  #endif
7923 -       if (inode)
7924 +       if (inode) {
7925 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7926                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7927 +       }
7928         return retval;
7929  }
7930 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/super.c
7931 --- linux-2.6.27.3/fs/reiserfs/super.c  2008-10-13 14:52:06.000000000 +0200
7932 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/super.c     2008-10-13 14:54:20.000000000 +0200
7933 @@ -898,6 +898,14 @@ static int reiserfs_parse_options(struct
7934                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7935                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7936  #endif
7937 +#ifndef CONFIG_TAGGING_NONE
7938 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7939 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7940 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7941 +#endif
7942 +#ifdef CONFIG_PROPAGATE
7943 +               {"tag",.arg_required = 'T',.values = NULL},
7944 +#endif
7945  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7946                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7947                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7948 @@ -1193,6 +1201,12 @@ static int reiserfs_remount(struct super
7949         handle_quota_files(s, qf_names, &qfmt);
7950  #endif
7951  
7952 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7953 +               !(s->s_flags & MS_TAGGED)) {
7954 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7955 +               return -EINVAL;
7956 +       }
7957 +
7958         handle_attrs(s);
7959  
7960         /* Add options that are safe here */
7961 @@ -1657,6 +1671,10 @@ static int reiserfs_fill_super(struct su
7962                 goto error;
7963         }
7964  
7965 +       /* map mount option tagxid */
7966 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7967 +               s->s_flags |= MS_TAGGED;
7968 +
7969         rs = SB_DISK_SUPER_BLOCK(s);
7970         /* Let's do basic sanity check to verify that underlying device is not
7971            smaller than the filesystem. If the check fails then abort and scream,
7972 diff -NurpP --minimal linux-2.6.27.3/fs/reiserfs/xattr.c linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/xattr.c
7973 --- linux-2.6.27.3/fs/reiserfs/xattr.c  2008-10-13 14:52:06.000000000 +0200
7974 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/reiserfs/xattr.c     2008-10-13 14:54:20.000000000 +0200
7975 @@ -35,6 +35,7 @@
7976  #include <linux/namei.h>
7977  #include <linux/errno.h>
7978  #include <linux/fs.h>
7979 +#include <linux/mount.h>
7980  #include <linux/file.h>
7981  #include <linux/pagemap.h>
7982  #include <linux/xattr.h>
7983 diff -NurpP --minimal linux-2.6.27.3/fs/stat.c linux-2.6.27.3-vs2.3.0.35.7/fs/stat.c
7984 --- linux-2.6.27.3/fs/stat.c    2008-10-13 14:52:06.000000000 +0200
7985 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/stat.c       2008-10-13 14:54:20.000000000 +0200
7986 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7987         stat->nlink = inode->i_nlink;
7988         stat->uid = inode->i_uid;
7989         stat->gid = inode->i_gid;
7990 +       stat->tag = inode->i_tag;
7991         stat->rdev = inode->i_rdev;
7992         stat->atime = inode->i_atime;
7993         stat->mtime = inode->i_mtime;
7994 diff -NurpP --minimal linux-2.6.27.3/fs/super.c linux-2.6.27.3-vs2.3.0.35.7/fs/super.c
7995 --- linux-2.6.27.3/fs/super.c   2008-10-13 14:52:06.000000000 +0200
7996 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/super.c      2008-10-13 14:54:20.000000000 +0200
7997 @@ -38,6 +38,9 @@
7998  #include <linux/kobject.h>
7999  #include <linux/mutex.h>
8000  #include <linux/file.h>
8001 +#include <linux/devpts_fs.h>
8002 +#include <linux/proc_fs.h>
8003 +#include <linux/vs_context.h>
8004  #include <asm/uaccess.h>
8005  #include "internal.h"
8006  
8007 @@ -887,12 +890,18 @@ struct vfsmount *
8008  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
8009  {
8010         struct vfsmount *mnt;
8011 +       struct super_block *sb;
8012         char *secdata = NULL;
8013         int error;
8014  
8015         if (!type)
8016                 return ERR_PTR(-ENODEV);
8017  
8018 +       error = -EPERM;
8019 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
8020 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
8021 +               goto out;
8022 +
8023         error = -ENOMEM;
8024         mnt = alloc_vfsmnt(name);
8025         if (!mnt)
8026 @@ -913,7 +922,14 @@ vfs_kern_mount(struct file_system_type *
8027                 goto out_free_secdata;
8028         BUG_ON(!mnt->mnt_sb);
8029  
8030 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
8031 +       sb = mnt->mnt_sb;
8032 +       error = -EPERM;
8033 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
8034 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8035 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8036 +               goto out_sb;
8037 +
8038 +       error = security_sb_kern_mount(sb, secdata);
8039         if (error)
8040                 goto out_sb;
8041  
8042 diff -NurpP --minimal linux-2.6.27.3/fs/sysfs/mount.c linux-2.6.27.3-vs2.3.0.35.7/fs/sysfs/mount.c
8043 --- linux-2.6.27.3/fs/sysfs/mount.c     2008-07-13 23:51:29.000000000 +0200
8044 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/sysfs/mount.c        2008-10-13 14:54:20.000000000 +0200
8045 @@ -19,8 +19,6 @@
8046  
8047  #include "sysfs.h"
8048  
8049 -/* Random magic number */
8050 -#define SYSFS_MAGIC 0x62656572
8051  
8052  static struct vfsmount *sysfs_mount;
8053  struct super_block * sysfs_sb = NULL;
8054 @@ -46,7 +44,7 @@ static int sysfs_fill_super(struct super
8055  
8056         sb->s_blocksize = PAGE_CACHE_SIZE;
8057         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8058 -       sb->s_magic = SYSFS_MAGIC;
8059 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8060         sb->s_op = &sysfs_ops;
8061         sb->s_time_gran = 1;
8062         sysfs_sb = sb;
8063 diff -NurpP --minimal linux-2.6.27.3/fs/utimes.c linux-2.6.27.3-vs2.3.0.35.7/fs/utimes.c
8064 --- linux-2.6.27.3/fs/utimes.c  2008-10-13 14:52:06.000000000 +0200
8065 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/utimes.c     2008-10-13 14:54:20.000000000 +0200
8066 @@ -8,6 +8,8 @@
8067  #include <linux/stat.h>
8068  #include <linux/utime.h>
8069  #include <linux/syscalls.h>
8070 +#include <linux/mount.h>
8071 +#include <linux/vs_cowbl.h>
8072  #include <asm/uaccess.h>
8073  #include <asm/unistd.h>
8074  
8075 diff -NurpP --minimal linux-2.6.27.3/fs/xattr.c linux-2.6.27.3-vs2.3.0.35.7/fs/xattr.c
8076 --- linux-2.6.27.3/fs/xattr.c   2008-10-13 14:52:06.000000000 +0200
8077 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xattr.c      2008-10-13 14:54:20.000000000 +0200
8078 @@ -18,6 +18,7 @@
8079  #include <linux/module.h>
8080  #include <linux/fsnotify.h>
8081  #include <linux/audit.h>
8082 +#include <linux/mount.h>
8083  #include <asm/uaccess.h>
8084  
8085  
8086 diff -NurpP --minimal linux-2.6.27.3/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/linux-2.6/xfs_linux.h
8087 --- linux-2.6.27.3/fs/xfs/linux-2.6/xfs_linux.h 2008-10-13 14:52:06.000000000 +0200
8088 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/linux-2.6/xfs_linux.h    2008-10-13 15:35:26.000000000 +0200
8089 @@ -126,6 +126,7 @@
8090  
8091  #define current_cpu()          (raw_smp_processor_id())
8092  #define current_pid()          (current->pid)
8093 +#define current_fstag(cred,vp) (dx_current_fstag(vp->i_sb))
8094  #define current_test_flags(f)  (current->flags & (f))
8095  #define current_set_flags_nested(sp, f)                \
8096                 (*(sp) = current->flags, current->flags |= (f))
8097 diff -NurpP --minimal linux-2.6.27.3/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/quota/xfs_qm_syscalls.c
8098 --- linux-2.6.27.3/fs/xfs/quota/xfs_qm_syscalls.c       2008-10-13 14:52:06.000000000 +0200
8099 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/quota/xfs_qm_syscalls.c  2008-10-24 03:47:08.000000000 +0200
8100 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8101         uint            accflags;
8102         __int64_t       sbflags;
8103  
8104 -       if (!capable(CAP_SYS_ADMIN))
8105 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8106                 return XFS_ERROR(EPERM);
8107  
8108         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8109 diff -NurpP --minimal linux-2.6.27.3/fs/xfs/xfs_clnt.h linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_clnt.h
8110 --- linux-2.6.27.3/fs/xfs/xfs_clnt.h    2008-10-13 14:52:06.000000000 +0200
8111 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_clnt.h       2008-10-13 14:54:20.000000000 +0200
8112 @@ -101,5 +101,6 @@ struct xfs_mount_args {
8113                                                  * I/O size in stat(2) */
8114  #define XFSMNT2_FILESTREAMS    0x00000002      /* enable the filestreams
8115                                                  * allocator */
8116 +#define XFSMNT2_TAGGED         0x10000000      /* context tagging */
8117  
8118  #endif /* __XFS_CLNT_H__ */
8119 diff -NurpP --minimal linux-2.6.27.3/fs/xfs/xfs_dinode.h linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_dinode.h
8120 --- linux-2.6.27.3/fs/xfs/xfs_dinode.h  2008-07-13 23:51:29.000000000 +0200
8121 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_dinode.h     2008-10-24 03:47:08.000000000 +0200
8122 @@ -136,7 +136,9 @@ typedef struct xfs_dinode
8123  #define        XFS_DI_NEXT_UNLINKED    0x1000000
8124  #define        XFS_DI_U                0x2000000
8125  #define        XFS_DI_A                0x4000000
8126 -#define        XFS_DI_NUM_BITS         27
8127 +#define        XFS_DI_TAG              0x8000000
8128 +#define        XFS_DI_VFLAGS           0x10000000
8129 +#define        XFS_DI_NUM_BITS         29
8130  #define        XFS_DI_ALL_BITS         ((1 << XFS_DI_NUM_BITS) - 1)
8131  #define        XFS_DI_CORE_BITS        (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
8132  
8133 @@ -223,6 +225,8 @@ typedef enum xfs_dinode_fmt
8134  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8135  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8136  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8137 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8138 +
8139  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8140  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8141  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8142 @@ -238,6 +242,7 @@ typedef enum xfs_dinode_fmt
8143  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8144  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8145  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8146 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8147  
8148  #ifdef CONFIG_XFS_RT
8149  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8150 @@ -250,6 +255,10 @@ typedef enum xfs_dinode_fmt
8151          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8152          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8153          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8154 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8155 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8156 +        XFS_DIFLAG_IXUNLINK)
8157 +
8158 +#define XFS_DIVFLAG_BARRIER    0x01
8159 +#define XFS_DIVFLAG_COW                0x02
8160  
8161  #endif /* __XFS_DINODE_H__ */
8162 diff -NurpP --minimal linux-2.6.27.3/fs/xfs/xfs_fs.h linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_fs.h
8163 --- linux-2.6.27.3/fs/xfs/xfs_fs.h      2008-10-13 14:52:06.000000000 +0200
8164 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_fs.h 2008-10-13 14:54:20.000000000 +0200
8165 @@ -67,6 +67,9 @@ struct fsxattr {
8166  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8167  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8168  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8169 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8170 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8171 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8172  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8173  
8174  /*
8175 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8176         __s32           bs_extents;     /* number of extents            */
8177         __u32           bs_gen;         /* generation count             */
8178         __u16           bs_projid;      /* project id                   */
8179 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8180 +       __u16           bs_tag;         /* context tagging              */
8181 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8182         __u32           bs_dmevmask;    /* DMIG event mask              */
8183         __u16           bs_dmstate;     /* DMIG state info              */
8184         __u16           bs_aextents;    /* attribute number of extents  */
8185 diff -NurpP --minimal linux-2.6.27.3/fs/xfs/xfs_mount.h linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_mount.h
8186 --- linux-2.6.27.3/fs/xfs/xfs_mount.h   2008-10-13 14:52:06.000000000 +0200
8187 +++ linux-2.6.27.3-vs2.3.0.35.7/fs/xfs/xfs_mount.h      2008-10-13 14:54:20.000000000 +0200
8188 @@ -384,6 +384,7 @@ typedef struct xfs_mount {
8189                                                    allocator */
8190  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8191  
8192 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8193  
8194  /*
8195   * Default minimum read and write sizes.
8196 diff -NurpP --minimal linux-2.6.27.3/include/asm-generic/tlb.h linux-2.6.27.3-vs2.3.0.35.7/include/asm-generic/tlb.h
8197 --- linux-2.6.27.3/include/asm-generic/tlb.h    2008-07-13 23:51:29.000000000 +0200
8198 +++ linux-2.6.27.3-vs2.3.0.35.7/include/asm-generic/tlb.h       2008-10-13 14:54:20.000000000 +0200
8199 @@ -14,6 +14,7 @@
8200  #define _ASM_GENERIC__TLB_H
8201  
8202  #include <linux/swap.h>
8203 +#include <linux/vs_memory.h>
8204  #include <asm/pgalloc.h>
8205  #include <asm/tlbflush.h>
8206  
8207 diff -NurpP --minimal linux-2.6.27.3/include/asm-x86/unistd_64.h linux-2.6.27.3-vs2.3.0.35.7/include/asm-x86/unistd_64.h
8208 --- linux-2.6.27.3/include/asm-x86/unistd_64.h  2008-10-13 14:52:08.000000000 +0200
8209 +++ linux-2.6.27.3-vs2.3.0.35.7/include/asm-x86/unistd_64.h     2008-10-13 14:54:20.000000000 +0200
8210 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
8211  #define __NR_utimes                            235
8212  __SYSCALL(__NR_utimes, sys_utimes)
8213  #define __NR_vserver                           236
8214 -__SYSCALL(__NR_vserver, sys_ni_syscall)
8215 +__SYSCALL(__NR_vserver, sys_vserver)
8216  #define __NR_mbind                             237
8217  __SYSCALL(__NR_mbind, sys_mbind)
8218  #define __NR_set_mempolicy                     238
8219 diff -NurpP --minimal linux-2.6.27.3/include/linux/capability.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/capability.h
8220 --- linux-2.6.27.3/include/linux/capability.h   2008-10-13 14:52:09.000000000 +0200
8221 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/capability.h      2008-10-13 14:54:20.000000000 +0200
8222 @@ -274,6 +274,7 @@ typedef struct kernel_cap_struct {
8223     arbitrary SCSI commands */
8224  /* Allow setting encryption key on loopback filesystem */
8225  /* Allow setting zone reclaim policy */
8226 +/* Allow the selection of a security context */
8227  
8228  #define CAP_SYS_ADMIN        21
8229  
8230 @@ -346,7 +347,13 @@ typedef struct kernel_cap_struct {
8231  
8232  #define CAP_MAC_ADMIN        33
8233  
8234 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8235 +/* Allow context manipulations */
8236 +/* Allow changing context info on files */
8237 +
8238 +#define CAP_CONTEXT         34
8239 +
8240 +
8241 +#define CAP_LAST_CAP         CAP_CONTEXT
8242  
8243  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8244  
8245 diff -NurpP --minimal linux-2.6.27.3/include/linux/devpts_fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/devpts_fs.h
8246 --- linux-2.6.27.3/include/linux/devpts_fs.h    2008-07-13 23:51:29.000000000 +0200
8247 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/devpts_fs.h       2008-10-13 14:54:20.000000000 +0200
8248 @@ -34,5 +34,4 @@ static inline void devpts_pty_kill(int n
8249  
8250  #endif
8251  
8252 -
8253  #endif /* _LINUX_DEVPTS_FS_H */
8254 diff -NurpP --minimal linux-2.6.27.3/include/linux/ext2_fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/ext2_fs.h
8255 --- linux-2.6.27.3/include/linux/ext2_fs.h      2008-10-13 14:52:09.000000000 +0200
8256 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/ext2_fs.h 2008-10-13 14:54:20.000000000 +0200
8257 @@ -189,8 +189,12 @@ struct ext2_group_desc
8258  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8259  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8260  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8261 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8262  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8263  
8264 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8265 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8266 +
8267  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8268  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8269  
8270 @@ -247,7 +251,7 @@ struct ext2_inode {
8271                 struct {
8272                         __u8    l_i_frag;       /* Fragment number */
8273                         __u8    l_i_fsize;      /* Fragment size */
8274 -                       __u16   i_pad1;
8275 +                       __u16   l_i_tag;        /* Context Tag */
8276                         __le16  l_i_uid_high;   /* these 2 fields    */
8277                         __le16  l_i_gid_high;   /* were reserved2[0] */
8278                         __u32   l_i_reserved2;
8279 @@ -279,6 +283,7 @@ struct ext2_inode {
8280  #define i_gid_low      i_gid
8281  #define i_uid_high     osd2.linux2.l_i_uid_high
8282  #define i_gid_high     osd2.linux2.l_i_gid_high
8283 +#define i_raw_tag      osd2.linux2.l_i_tag
8284  #define i_reserved2    osd2.linux2.l_i_reserved2
8285  #endif
8286  
8287 @@ -323,6 +328,7 @@ struct ext2_inode {
8288  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8289  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8290  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8291 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8292  
8293  
8294  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8295 diff -NurpP --minimal linux-2.6.27.3/include/linux/ext3_fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/ext3_fs.h
8296 --- linux-2.6.27.3/include/linux/ext3_fs.h      2008-10-13 14:52:09.000000000 +0200
8297 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/ext3_fs.h 2008-10-24 03:34:52.000000000 +0200
8298 @@ -173,10 +173,14 @@ struct ext3_group_desc
8299  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8300  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8301  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8302 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8303  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8304  
8305 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8306 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8307 +#define EXT3_BARRIER_FL                        0x10000000 /* Barrier for chroot() */
8308 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8309 +
8310 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8311 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8312  
8313  /*
8314   * Inode dynamic state flags
8315 @@ -292,7 +296,7 @@ struct ext3_inode {
8316                 struct {
8317                         __u8    l_i_frag;       /* Fragment number */
8318                         __u8    l_i_fsize;      /* Fragment size */
8319 -                       __u16   i_pad1;
8320 +                       __u16   l_i_tag;        /* Context Tag */
8321                         __le16  l_i_uid_high;   /* these 2 fields    */
8322                         __le16  l_i_gid_high;   /* were reserved2[0] */
8323                         __u32   l_i_reserved2;
8324 @@ -326,6 +330,7 @@ struct ext3_inode {
8325  #define i_gid_low      i_gid
8326  #define i_uid_high     osd2.linux2.l_i_uid_high
8327  #define i_gid_high     osd2.linux2.l_i_gid_high
8328 +#define i_raw_tag      osd2.linux2.l_i_tag
8329  #define i_reserved2    osd2.linux2.l_i_reserved2
8330  
8331  #elif defined(__GNU__)
8332 @@ -380,6 +385,7 @@ struct ext3_inode {
8333  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
8334  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
8335  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8336 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8337  
8338  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8339  #ifndef _LINUX_EXT2_FS_H
8340 @@ -822,6 +828,7 @@ struct buffer_head * ext3_bread (handle_
8341  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
8342         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
8343         int create, int extend_disksize);
8344 +extern int ext3_sync_flags(struct inode *inode);
8345  
8346  extern struct inode *ext3_iget(struct super_block *, unsigned long);
8347  extern int  ext3_write_inode (struct inode *, int);
8348 diff -NurpP --minimal linux-2.6.27.3/include/linux/fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/fs.h
8349 --- linux-2.6.27.3/include/linux/fs.h   2008-10-13 14:52:09.000000000 +0200
8350 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/fs.h      2008-10-24 03:34:52.000000000 +0200
8351 @@ -130,6 +130,9 @@ extern int dir_notify_enable;
8352  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
8353  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8354  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8355 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
8356 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
8357 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
8358  #define MS_ACTIVE      (1<<30)
8359  #define MS_NOUSER      (1<<31)
8360  
8361 @@ -137,7 +140,7 @@ extern int dir_notify_enable;
8362  /*
8363   * Superblock flags that can be altered by MS_REMOUNT
8364   */
8365 -#define MS_RMT_MASK    (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK)
8366 +#define MS_RMT_MASK    (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOTAGCHECK)
8367  
8368  /*
8369   * Old magic mount flag and mask
8370 @@ -154,6 +157,14 @@ extern int dir_notify_enable;
8371  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8372  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8373  #define S_PRIVATE      512     /* Inode is fs-internal */
8374 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8375 +
8376 +/* Linux-VServer related Inode flags */
8377 +
8378 +#define V_VALID                1
8379 +#define V_XATTR                2
8380 +#define V_BARRIER      4       /* Barrier for chroot() */
8381 +#define V_COW          8       /* Copy on Write */
8382  
8383  /*
8384   * Note that nosuid etc flags are inode-specific: setting some file-system
8385 @@ -176,12 +187,15 @@ extern int dir_notify_enable;
8386  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8387                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8388  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8389 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8390 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8391 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8392 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8393 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8394  
8395  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8396  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8397  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8398 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8399 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8400  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8401  
8402  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8403 @@ -189,6 +203,16 @@ extern int dir_notify_enable;
8404  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8405  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8406  
8407 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8408 +
8409 +#ifdef CONFIG_VSERVER_COWBL
8410 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8411 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8412 +#else
8413 +#  define IS_COW(inode)                (0)
8414 +#  define IS_COW_LINK(inode)   (0)
8415 +#endif
8416 +
8417  /* the read-only stuff doesn't really belong here, but any other place is
8418     probably as bad and I don't want to create yet another include file. */
8419  
8420 @@ -262,11 +286,14 @@ extern int dir_notify_enable;
8421  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8422  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8423  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8424 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8425  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8426  
8427 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8428 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8429 +#define FS_BARRIER_FL                  0x10000000 /* Barrier for chroot() */
8430 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8431  
8432 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8433 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8434  
8435  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8436  #define SYNC_FILE_RANGE_WRITE          2
8437 @@ -337,6 +364,7 @@ typedef void (dio_iodone_t)(struct kiocb
8438  #define ATTR_KILL_PRIV (1 << 14)
8439  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8440  #define ATTR_TIMES_SET (1 << 16)
8441 +#define ATTR_TAG       (1 << 17)
8442  
8443  /*
8444   * This is the Inode Attributes structure, used for notify_change().  It
8445 @@ -352,6 +380,7 @@ struct iattr {
8446         umode_t         ia_mode;
8447         uid_t           ia_uid;
8448         gid_t           ia_gid;
8449 +       tag_t           ia_tag;
8450         loff_t          ia_size;
8451         struct timespec ia_atime;
8452         struct timespec ia_mtime;
8453 @@ -365,6 +394,9 @@ struct iattr {
8454         struct file     *ia_file;
8455  };
8456  
8457 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8458 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8459 +
8460  /*
8461   * Includes for diskquotas.
8462   */
8463 @@ -626,7 +658,9 @@ struct inode {
8464         unsigned int            i_nlink;
8465         uid_t                   i_uid;
8466         gid_t                   i_gid;
8467 +       tag_t                   i_tag;
8468         dev_t                   i_rdev;
8469 +       dev_t                   i_mdev;
8470         u64                     i_version;
8471         loff_t                  i_size;
8472  #ifdef __NEED_I_SIZE_ORDERED
8473 @@ -674,7 +708,8 @@ struct inode {
8474         unsigned long           i_state;
8475         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8476  
8477 -       unsigned int            i_flags;
8478 +       unsigned short          i_flags;
8479 +       unsigned short          i_vflags;
8480  
8481         atomic_t                i_writecount;
8482  #ifdef CONFIG_SECURITY
8483 @@ -761,12 +796,12 @@ static inline void i_size_write(struct i
8484  
8485  static inline unsigned iminor(const struct inode *inode)
8486  {
8487 -       return MINOR(inode->i_rdev);
8488 +       return MINOR(inode->i_mdev);
8489  }
8490  
8491  static inline unsigned imajor(const struct inode *inode)
8492  {
8493 -       return MAJOR(inode->i_rdev);
8494 +       return MAJOR(inode->i_mdev);
8495  }
8496  
8497  extern struct block_device *I_BDEV(struct inode *inode);
8498 @@ -824,6 +859,7 @@ struct file {
8499         loff_t                  f_pos;
8500         struct fown_struct      f_owner;
8501         unsigned int            f_uid, f_gid;
8502 +       xid_t                   f_xid;
8503         struct file_ra_state    f_ra;
8504  
8505         u64                     f_version;
8506 @@ -958,6 +994,7 @@ struct file_lock {
8507         struct file *fl_file;
8508         loff_t fl_start;
8509         loff_t fl_end;
8510 +       xid_t fl_xid;
8511  
8512         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8513         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8514 @@ -1287,6 +1324,7 @@ struct inode_operations {
8515         void (*truncate_range)(struct inode *, loff_t, loff_t);
8516         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8517                           loff_t len);
8518 +       int (*sync_flags) (struct inode *);
8519  };
8520  
8521  struct seq_file;
8522 @@ -1302,6 +1340,7 @@ extern ssize_t vfs_readv(struct file *, 
8523                 unsigned long, loff_t *);
8524  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8525                 unsigned long, loff_t *);
8526 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8527  
8528  struct super_operations {
8529         struct inode *(*alloc_inode)(struct super_block *sb);
8530 @@ -1992,6 +2031,7 @@ extern int dcache_dir_open(struct inode 
8531  extern int dcache_dir_close(struct inode *, struct file *);
8532  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8533  extern int dcache_readdir(struct file *, void *, filldir_t);
8534 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8535  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8536  extern int simple_statfs(struct dentry *, struct kstatfs *);
8537  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8538 diff -NurpP --minimal linux-2.6.27.3/include/linux/if_tun.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/if_tun.h
8539 --- linux-2.6.27.3/include/linux/if_tun.h       2008-10-13 14:52:09.000000000 +0200
8540 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/if_tun.h  2008-10-13 14:54:20.000000000 +0200
8541 @@ -46,6 +46,7 @@
8542  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
8543  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
8544  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8545 +#define TUNSETNID     _IOW('T', 215, int)
8546  
8547  /* TUNSETIFF ifr flags */
8548  #define IFF_TUN                0x0001
8549 diff -NurpP --minimal linux-2.6.27.3/include/linux/init_task.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/init_task.h
8550 --- linux-2.6.27.3/include/linux/init_task.h    2008-10-13 14:52:09.000000000 +0200
8551 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/init_task.h       2008-10-13 14:54:20.000000000 +0200
8552 @@ -179,6 +179,10 @@ extern struct group_info init_groups;
8553         INIT_IDS                                                        \
8554         INIT_TRACE_IRQFLAGS                                             \
8555         INIT_LOCKDEP                                                    \
8556 +       .xid            = 0,                                            \
8557 +       .vx_info        = NULL,                                         \
8558 +       .nid            = 0,                                            \
8559 +       .nx_info        = NULL,                                         \
8560  }
8561  
8562  
8563 diff -NurpP --minimal linux-2.6.27.3/include/linux/interrupt.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/interrupt.h
8564 --- linux-2.6.27.3/include/linux/interrupt.h    2008-10-13 14:52:09.000000000 +0200
8565 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/interrupt.h       2008-10-13 14:54:20.000000000 +0200
8566 @@ -8,8 +8,8 @@
8567  #include <linux/preempt.h>
8568  #include <linux/cpumask.h>
8569  #include <linux/irqreturn.h>
8570 -#include <linux/hardirq.h>
8571  #include <linux/sched.h>
8572 +#include <linux/hardirq.h>
8573  #include <linux/irqflags.h>
8574  #include <asm/atomic.h>
8575  #include <asm/ptrace.h>
8576 diff -NurpP --minimal linux-2.6.27.3/include/linux/ipc.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/ipc.h
8577 --- linux-2.6.27.3/include/linux/ipc.h  2008-07-13 23:51:29.000000000 +0200
8578 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/ipc.h     2008-10-13 14:54:20.000000000 +0200
8579 @@ -93,6 +93,7 @@ struct kern_ipc_perm
8580         key_t           key;
8581         uid_t           uid;
8582         gid_t           gid;
8583 +       xid_t           xid;
8584         uid_t           cuid;
8585         gid_t           cgid;
8586         mode_t          mode; 
8587 diff -NurpP --minimal linux-2.6.27.3/include/linux/Kbuild linux-2.6.27.3-vs2.3.0.35.7/include/linux/Kbuild
8588 --- linux-2.6.27.3/include/linux/Kbuild 2008-10-13 14:52:09.000000000 +0200
8589 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/Kbuild    2008-10-13 14:54:20.000000000 +0200
8590 @@ -369,3 +369,6 @@ unifdef-y += xattr.h
8591  unifdef-y += xfrm.h
8592  
8593  objhdr-y += version.h
8594 +
8595 +header-y += vserver/
8596 +
8597 diff -NurpP --minimal linux-2.6.27.3/include/linux/loop.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/loop.h
8598 --- linux-2.6.27.3/include/linux/loop.h 2008-07-13 23:51:29.000000000 +0200
8599 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/loop.h    2008-10-13 14:54:20.000000000 +0200
8600 @@ -45,6 +45,7 @@ struct loop_device {
8601         struct loop_func_table *lo_encryption;
8602         __u32           lo_init[2];
8603         uid_t           lo_key_owner;   /* Who set the key */
8604 +       xid_t           lo_xid;
8605         int             (*ioctl)(struct loop_device *, int cmd, 
8606                                  unsigned long arg); 
8607  
8608 diff -NurpP --minimal linux-2.6.27.3/include/linux/magic.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/magic.h
8609 --- linux-2.6.27.3/include/linux/magic.h        2008-07-13 23:51:29.000000000 +0200
8610 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/magic.h   2008-10-13 14:54:20.000000000 +0200
8611 @@ -3,7 +3,7 @@
8612  
8613  #define ADFS_SUPER_MAGIC       0xadf5
8614  #define AFFS_SUPER_MAGIC       0xadff
8615 -#define AFS_SUPER_MAGIC                0x5346414F
8616 +#define AFS_SUPER_MAGIC                0x5346414F
8617  #define AUTOFS_SUPER_MAGIC     0x0187
8618  #define CODA_SUPER_MAGIC       0x73757245
8619  #define EFS_SUPER_MAGIC                0x414A53
8620 @@ -26,6 +26,7 @@
8621  #define NFS_SUPER_MAGIC                0x6969
8622  #define OPENPROM_SUPER_MAGIC   0x9fa1
8623  #define PROC_SUPER_MAGIC       0x9fa0
8624 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8625  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8626  
8627  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8628 diff -NurpP --minimal linux-2.6.27.3/include/linux/major.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/major.h
8629 --- linux-2.6.27.3/include/linux/major.h        2008-10-13 14:52:09.000000000 +0200
8630 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/major.h   2008-10-13 14:54:20.000000000 +0200
8631 @@ -15,6 +15,7 @@
8632  #define HD_MAJOR               IDE0_MAJOR
8633  #define PTY_SLAVE_MAJOR                3
8634  #define TTY_MAJOR              4
8635 +#define VROOT_MAJOR            4
8636  #define TTYAUX_MAJOR           5
8637  #define LP_MAJOR               6
8638  #define VCS_MAJOR              7
8639 diff -NurpP --minimal linux-2.6.27.3/include/linux/mm_types.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/mm_types.h
8640 --- linux-2.6.27.3/include/linux/mm_types.h     2008-10-13 14:52:09.000000000 +0200
8641 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/mm_types.h        2008-10-13 14:54:20.000000000 +0200
8642 @@ -216,6 +216,7 @@ struct mm_struct {
8643  
8644         /* Architecture-specific MM context */
8645         mm_context_t context;
8646 +       struct vx_info *mm_vx_info;
8647  
8648         /* Swap token stuff */
8649         /*
8650 diff -NurpP --minimal linux-2.6.27.3/include/linux/mount.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/mount.h
8651 --- linux-2.6.27.3/include/linux/mount.h        2008-10-13 14:52:09.000000000 +0200
8652 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/mount.h   2008-10-24 03:34:52.000000000 +0200
8653 @@ -37,6 +37,9 @@ struct mnt_namespace;
8654  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8655  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8656  
8657 +#define MNT_TAGID      0x10000
8658 +#define MNT_NOTAG      0x20000
8659 +
8660  struct vfsmount {
8661         struct list_head mnt_hash;
8662         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8663 @@ -71,6 +74,7 @@ struct vfsmount {
8664          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
8665          */
8666         atomic_t __mnt_writers;
8667 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8668  };
8669  
8670  static inline struct vfsmount *mntget(struct vfsmount *mnt)
8671 diff -NurpP --minimal linux-2.6.27.3/include/linux/net.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/net.h
8672 --- linux-2.6.27.3/include/linux/net.h  2008-10-13 14:52:09.000000000 +0200
8673 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/net.h     2008-10-13 14:54:20.000000000 +0200
8674 @@ -68,6 +68,7 @@ struct net;
8675  #define SOCK_NOSPACE           2
8676  #define SOCK_PASSCRED          3
8677  #define SOCK_PASSSEC           4
8678 +#define SOCK_USER_SOCKET       5
8679  
8680  #ifndef ARCH_HAS_SOCKET_TYPES
8681  /**
8682 diff -NurpP --minimal linux-2.6.27.3/include/linux/nfs_mount.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/nfs_mount.h
8683 --- linux-2.6.27.3/include/linux/nfs_mount.h    2008-07-13 23:51:29.000000000 +0200
8684 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/nfs_mount.h       2008-10-13 14:54:20.000000000 +0200
8685 @@ -63,6 +63,7 @@ struct nfs_mount_data {
8686  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8687  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8688  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8689 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8690 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8691 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8692  
8693  #endif
8694 diff -NurpP --minimal linux-2.6.27.3/include/linux/nsproxy.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/nsproxy.h
8695 --- linux-2.6.27.3/include/linux/nsproxy.h      2008-10-13 14:52:09.000000000 +0200
8696 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/nsproxy.h 2008-10-13 14:54:20.000000000 +0200
8697 @@ -3,6 +3,7 @@
8698  
8699  #include <linux/spinlock.h>
8700  #include <linux/sched.h>
8701 +#include <linux/vserver/debug.h>
8702  
8703  struct mnt_namespace;
8704  struct uts_namespace;
8705 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8706  }
8707  
8708  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8709 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8710  void exit_task_namespaces(struct task_struct *tsk);
8711  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8712  void free_nsproxy(struct nsproxy *ns);
8713  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8714         struct fs_struct *);
8715  
8716 -static inline void put_nsproxy(struct nsproxy *ns)
8717 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8718 +
8719 +static inline void __get_nsproxy(struct nsproxy *ns,
8720 +       const char *_file, int _line)
8721  {
8722 -       if (atomic_dec_and_test(&ns->count)) {
8723 -               free_nsproxy(ns);
8724 -       }
8725 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8726 +               ns, atomic_read(&ns->count), _file, _line);
8727 +       atomic_inc(&ns->count);
8728  }
8729  
8730 -static inline void get_nsproxy(struct nsproxy *ns)
8731 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8732 +
8733 +static inline void __put_nsproxy(struct nsproxy *ns,
8734 +       const char *_file, int _line)
8735  {
8736 -       atomic_inc(&ns->count);
8737 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8738 +               ns, atomic_read(&ns->count), _file, _line);
8739 +       if (atomic_dec_and_test(&ns->count)) {
8740 +               free_nsproxy(ns);
8741 +       }
8742  }
8743  
8744  #ifdef CONFIG_CGROUP_NS
8745 diff -NurpP --minimal linux-2.6.27.3/include/linux/pid.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/pid.h
8746 --- linux-2.6.27.3/include/linux/pid.h  2008-10-13 14:52:09.000000000 +0200
8747 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/pid.h     2008-10-13 14:54:20.000000000 +0200
8748 @@ -8,7 +8,8 @@ enum pid_type
8749         PIDTYPE_PID,
8750         PIDTYPE_PGID,
8751         PIDTYPE_SID,
8752 -       PIDTYPE_MAX
8753 +       PIDTYPE_MAX,
8754 +       PIDTYPE_REALPID
8755  };
8756  
8757  /*
8758 @@ -142,6 +143,7 @@ static inline pid_t pid_nr(struct pid *p
8759  }
8760  
8761  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8762 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8763  pid_t pid_vnr(struct pid *pid);
8764  
8765  #define do_each_pid_task(pid, type, task)                              \
8766 diff -NurpP --minimal linux-2.6.27.3/include/linux/proc_fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/proc_fs.h
8767 --- linux-2.6.27.3/include/linux/proc_fs.h      2008-10-13 14:52:09.000000000 +0200
8768 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/proc_fs.h 2008-10-13 14:54:20.000000000 +0200
8769 @@ -59,6 +59,7 @@ struct proc_dir_entry {
8770         nlink_t nlink;
8771         uid_t uid;
8772         gid_t gid;
8773 +       int vx_flags;
8774         loff_t size;
8775         const struct inode_operations *proc_iops;
8776         /*
8777 @@ -274,12 +275,18 @@ static inline void kclist_add(struct kco
8778  extern void kclist_add(struct kcore_list *, void *, size_t);
8779  #endif
8780  
8781 +struct vx_info;
8782 +struct nx_info;
8783 +
8784  union proc_op {
8785         int (*proc_get_link)(struct inode *, struct path *);
8786         int (*proc_read)(struct task_struct *task, char *page);
8787         int (*proc_show)(struct seq_file *m,
8788                 struct pid_namespace *ns, struct pid *pid,
8789                 struct task_struct *task);
8790 +       int (*proc_vs_read)(char *page);
8791 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8792 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8793  };
8794  
8795  struct ctl_table_header;
8796 @@ -287,6 +294,7 @@ struct ctl_table;
8797  
8798  struct proc_inode {
8799         struct pid *pid;
8800 +       int vx_flags;
8801         int fd;
8802         union proc_op op;
8803         struct proc_dir_entry *pde;
8804 diff -NurpP --minimal linux-2.6.27.3/include/linux/reiserfs_fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/reiserfs_fs.h
8805 --- linux-2.6.27.3/include/linux/reiserfs_fs.h  2008-10-13 14:52:09.000000000 +0200
8806 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/reiserfs_fs.h     2008-10-13 14:54:20.000000000 +0200
8807 @@ -837,6 +837,11 @@ struct stat_data_v1 {
8808  #define REISERFS_COMPR_FL     FS_COMPR_FL
8809  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8810  
8811 +/* unfortunately reiserfs sdattr is only 16 bit */
8812 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8813 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8814 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8815 +
8816  /* persistent flags that file inherits from the parent directory */
8817  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8818                                 REISERFS_SYNC_FL |      \
8819 @@ -846,6 +851,9 @@ struct stat_data_v1 {
8820                                 REISERFS_COMPR_FL |     \
8821                                 REISERFS_NOTAIL_FL )
8822  
8823 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8824 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8825 +
8826  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8827     address blocks) */
8828  struct stat_data {
8829 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
8830  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8831  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8832  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8833 +int reiserfs_sync_flags(struct inode *inode);
8834  
8835  /* namei.c */
8836  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
8837 diff -NurpP --minimal linux-2.6.27.3/include/linux/reiserfs_fs_sb.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/reiserfs_fs_sb.h
8838 --- linux-2.6.27.3/include/linux/reiserfs_fs_sb.h       2008-10-13 14:52:09.000000000 +0200
8839 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/reiserfs_fs_sb.h  2008-10-13 14:54:20.000000000 +0200
8840 @@ -455,6 +455,7 @@ enum reiserfs_mount_options {
8841         REISERFS_POSIXACL,
8842         REISERFS_BARRIER_NONE,
8843         REISERFS_BARRIER_FLUSH,
8844 +       REISERFS_TAGGED,
8845  
8846         /* Actions on error */
8847         REISERFS_ERROR_PANIC,
8848 diff -NurpP --minimal linux-2.6.27.3/include/linux/sched.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/sched.h
8849 --- linux-2.6.27.3/include/linux/sched.h        2008-10-13 14:52:09.000000000 +0200
8850 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/sched.h   2008-10-13 14:54:20.000000000 +0200
8851 @@ -71,7 +71,6 @@ struct sched_param {
8852  #include <linux/fs_struct.h>
8853  #include <linux/compiler.h>
8854  #include <linux/completion.h>
8855 -#include <linux/pid.h>
8856  #include <linux/percpu.h>
8857  #include <linux/topology.h>
8858  #include <linux/proportions.h>
8859 @@ -88,6 +87,7 @@ struct sched_param {
8860  #include <linux/kobject.h>
8861  #include <linux/latencytop.h>
8862  #include <linux/cred.h>
8863 +#include <linux/pid.h>
8864  
8865  #include <asm/processor.h>
8866  
8867 @@ -357,25 +357,27 @@ extern void arch_unmap_area_topdown(stru
8868   * The mm counters are not protected by its page_table_lock,
8869   * so must be incremented atomically.
8870   */
8871 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
8872 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
8873 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
8874 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
8875 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
8876 -
8877 +#define __set_mm_counter(mm, member, value) \
8878 +       atomic_long_set(&(mm)->_##member, value)
8879 +#define get_mm_counter(mm, member) \
8880 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
8881  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
8882  /*
8883   * The mm counters are protected by its page_table_lock,
8884   * so can be incremented directly.
8885   */
8886 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
8887 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
8888  #define get_mm_counter(mm, member) ((mm)->_##member)
8889 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
8890 -#define inc_mm_counter(mm, member) (mm)->_##member++
8891 -#define dec_mm_counter(mm, member) (mm)->_##member--
8892  
8893  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
8894  
8895 +#define set_mm_counter(mm, member, value) \
8896 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
8897 +#define add_mm_counter(mm, member, value) \
8898 +       vx_ ## member ## pages_add((mm), (value))
8899 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
8900 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
8901 +
8902  #define get_mm_rss(mm)                                 \
8903         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
8904  #define update_hiwater_rss(mm) do {                    \
8905 @@ -1196,6 +1198,14 @@ struct task_struct {
8906  #endif
8907         seccomp_t seccomp;
8908  
8909 +/* vserver context data */
8910 +       struct vx_info *vx_info;
8911 +       struct nx_info *nx_info;
8912 +
8913 +       xid_t xid;
8914 +       nid_t nid;
8915 +       tag_t tag;
8916 +
8917  /* Thread group tracking */
8918         u32 parent_exec_id;
8919         u32 self_exec_id;
8920 @@ -1380,6 +1390,11 @@ struct pid_namespace;
8921   * see also pid_nr() etc in include/linux/pid.h
8922   */
8923  
8924 +#include <linux/vserver/base.h>
8925 +#include <linux/vserver/context.h>
8926 +#include <linux/vserver/debug.h>
8927 +#include <linux/vserver/pid.h>
8928 +
8929  static inline pid_t task_pid_nr(struct task_struct *tsk)
8930  {
8931         return tsk->pid;
8932 @@ -1389,7 +1404,7 @@ pid_t task_pid_nr_ns(struct task_struct 
8933  
8934  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8935  {
8936 -       return pid_vnr(task_pid(tsk));
8937 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
8938  }
8939  
8940  
8941 @@ -1402,7 +1417,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8942  
8943  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8944  {
8945 -       return pid_vnr(task_tgid(tsk));
8946 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8947  }
8948  
8949  
8950 diff -NurpP --minimal linux-2.6.27.3/include/linux/shmem_fs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/shmem_fs.h
8951 --- linux-2.6.27.3/include/linux/shmem_fs.h     2008-10-13 14:52:09.000000000 +0200
8952 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/shmem_fs.h        2008-10-13 14:54:20.000000000 +0200
8953 @@ -8,6 +8,9 @@
8954  
8955  #define SHMEM_NR_DIRECT 16
8956  
8957 +#define TMPFS_SUPER_MAGIC      0x01021994
8958 +
8959 +
8960  struct shmem_inode_info {
8961         spinlock_t              lock;
8962         unsigned long           flags;
8963 diff -NurpP --minimal linux-2.6.27.3/include/linux/stat.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/stat.h
8964 --- linux-2.6.27.3/include/linux/stat.h 2008-07-13 23:51:29.000000000 +0200
8965 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/stat.h    2008-10-13 14:54:20.000000000 +0200
8966 @@ -66,6 +66,7 @@ struct kstat {
8967         unsigned int    nlink;
8968         uid_t           uid;
8969         gid_t           gid;
8970 +       tag_t           tag;
8971         dev_t           rdev;
8972         loff_t          size;
8973         struct timespec  atime;
8974 diff -NurpP --minimal linux-2.6.27.3/include/linux/sunrpc/auth.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/sunrpc/auth.h
8975 --- linux-2.6.27.3/include/linux/sunrpc/auth.h  2008-07-13 23:51:29.000000000 +0200
8976 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/sunrpc/auth.h     2008-10-13 14:54:20.000000000 +0200
8977 @@ -25,6 +25,7 @@
8978  struct auth_cred {
8979         uid_t   uid;
8980         gid_t   gid;
8981 +       tag_t   tag;
8982         struct group_info *group_info;
8983         unsigned char machine_cred : 1;
8984  };
8985 diff -NurpP --minimal linux-2.6.27.3/include/linux/sunrpc/clnt.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/sunrpc/clnt.h
8986 --- linux-2.6.27.3/include/linux/sunrpc/clnt.h  2008-10-13 14:52:09.000000000 +0200
8987 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/sunrpc/clnt.h     2008-10-13 14:54:20.000000000 +0200
8988 @@ -43,7 +43,8 @@ struct rpc_clnt {
8989         unsigned int            cl_softrtry : 1,/* soft timeouts */
8990                                 cl_discrtry : 1,/* disconnect before retry */
8991                                 cl_autobind : 1,/* use getport() */
8992 -                               cl_chatty   : 1;/* be verbose */
8993 +                               cl_chatty   : 1,/* be verbose */
8994 +                               cl_tag      : 1;/* context tagging */
8995  
8996         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8997         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8998 diff -NurpP --minimal linux-2.6.27.3/include/linux/syscalls.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/syscalls.h
8999 --- linux-2.6.27.3/include/linux/syscalls.h     2008-10-13 14:52:09.000000000 +0200
9000 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/syscalls.h        2008-10-13 14:54:20.000000000 +0200
9001 @@ -295,6 +295,8 @@ asmlinkage long sys_symlink(const char _
9002  asmlinkage long sys_unlink(const char __user *pathname);
9003  asmlinkage long sys_rename(const char __user *oldname,
9004                                 const char __user *newname);
9005 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9006 +                               umode_t mode);
9007  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9008  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9009  
9010 diff -NurpP --minimal linux-2.6.27.3/include/linux/sysctl.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/sysctl.h
9011 --- linux-2.6.27.3/include/linux/sysctl.h       2008-10-13 14:52:09.000000000 +0200
9012 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/sysctl.h  2008-10-13 14:54:20.000000000 +0200
9013 @@ -70,6 +70,7 @@ enum
9014         CTL_ABI=9,              /* Binary emulation */
9015         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9016         CTL_ARLAN=254,          /* arlan wireless driver */
9017 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9018         CTL_S390DBF=5677,       /* s390 debug */
9019         CTL_SUNRPC=7249,        /* sunrpc debug */
9020         CTL_PM=9899,            /* frv power management */
9021 @@ -104,6 +105,7 @@ enum
9022  
9023         KERN_PANIC=15,          /* int: panic timeout */
9024         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9025 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9026  
9027         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9028         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9029 diff -NurpP --minimal linux-2.6.27.3/include/linux/sysfs.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/sysfs.h
9030 --- linux-2.6.27.3/include/linux/sysfs.h        2008-10-13 14:52:09.000000000 +0200
9031 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/sysfs.h   2008-10-13 14:54:20.000000000 +0200
9032 @@ -17,6 +17,8 @@
9033  #include <linux/list.h>
9034  #include <asm/atomic.h>
9035  
9036 +#define SYSFS_SUPER_MAGIC      0x62656572
9037 +
9038  struct kobject;
9039  struct module;
9040  
9041 diff -NurpP --minimal linux-2.6.27.3/include/linux/time.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/time.h
9042 --- linux-2.6.27.3/include/linux/time.h 2008-07-13 23:51:29.000000000 +0200
9043 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/time.h    2008-10-13 14:54:20.000000000 +0200
9044 @@ -179,6 +179,9 @@ static __always_inline void timespec_add
9045         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9046         a->tv_nsec = ns;
9047  }
9048 +
9049 +#include <linux/vs_time.h>
9050 +
9051  #endif /* __KERNEL__ */
9052  
9053  #define NFDBITS                        __NFDBITS
9054 diff -NurpP --minimal linux-2.6.27.3/include/linux/types.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/types.h
9055 --- linux-2.6.27.3/include/linux/types.h        2008-07-13 23:51:29.000000000 +0200
9056 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/types.h   2008-10-13 14:54:20.000000000 +0200
9057 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9058  typedef __kernel_gid32_t       gid_t;
9059  typedef __kernel_uid16_t        uid16_t;
9060  typedef __kernel_gid16_t        gid16_t;
9061 +typedef unsigned int           xid_t;
9062 +typedef unsigned int           nid_t;
9063 +typedef unsigned int           tag_t;
9064  
9065  typedef unsigned long          uintptr_t;
9066  
9067 diff -NurpP --minimal linux-2.6.27.3/include/linux/vroot.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vroot.h
9068 --- linux-2.6.27.3/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9069 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vroot.h   2008-10-13 14:54:20.000000000 +0200
9070 @@ -0,0 +1,51 @@
9071 +
9072 +/*
9073 + * include/linux/vroot.h
9074 + *
9075 + * written by Herbert Pötzl, 9/11/2002
9076 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9077 + *
9078 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9079 + * Redistribution of this file is permitted under the
9080 + * GNU General Public License.
9081 + */
9082 +
9083 +#ifndef _LINUX_VROOT_H
9084 +#define _LINUX_VROOT_H
9085 +
9086 +
9087 +#ifdef __KERNEL__
9088 +
9089 +/* Possible states of device */
9090 +enum {
9091 +       Vr_unbound,
9092 +       Vr_bound,
9093 +};
9094 +
9095 +struct vroot_device {
9096 +       int             vr_number;
9097 +       int             vr_refcnt;
9098 +
9099 +       struct semaphore        vr_ctl_mutex;
9100 +       struct block_device    *vr_device;
9101 +       int                     vr_state;
9102 +};
9103 +
9104 +
9105 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9106 +
9107 +extern int register_vroot_grb(vroot_grb_func *);
9108 +extern int unregister_vroot_grb(vroot_grb_func *);
9109 +
9110 +#endif /* __KERNEL__ */
9111 +
9112 +#define MAX_VROOT_DEFAULT      8
9113 +
9114 +/*
9115 + * IOCTL commands --- we will commandeer 0x56 ('V')
9116 + */
9117 +
9118 +#define VROOT_SET_DEV          0x5600
9119 +#define VROOT_CLR_DEV          0x5601
9120 +
9121 +#endif /* _LINUX_VROOT_H */
9122 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_base.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_base.h
9123 --- linux-2.6.27.3/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9124 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_base.h 2008-10-13 14:54:20.000000000 +0200
9125 @@ -0,0 +1,10 @@
9126 +#ifndef _VS_BASE_H
9127 +#define _VS_BASE_H
9128 +
9129 +#include "vserver/base.h"
9130 +#include "vserver/check.h"
9131 +#include "vserver/debug.h"
9132 +
9133 +#else
9134 +#warning duplicate inclusion
9135 +#endif
9136 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_context.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_context.h
9137 --- linux-2.6.27.3/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9138 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_context.h      2008-10-13 14:54:20.000000000 +0200
9139 @@ -0,0 +1,227 @@
9140 +#ifndef _VS_CONTEXT_H
9141 +#define _VS_CONTEXT_H
9142 +
9143 +#include "vserver/base.h"
9144 +#include "vserver/check.h"
9145 +#include "vserver/context.h"
9146 +#include "vserver/history.h"
9147 +#include "vserver/debug.h"
9148 +
9149 +#include <linux/sched.h>
9150 +
9151 +
9152 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9153 +
9154 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9155 +       const char *_file, int _line, void *_here)
9156 +{
9157 +       if (!vxi)
9158 +               return NULL;
9159 +
9160 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9161 +               vxi, vxi ? vxi->vx_id : 0,
9162 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9163 +               _file, _line);
9164 +       __vxh_get_vx_info(vxi, _here);
9165 +
9166 +       atomic_inc(&vxi->vx_usecnt);
9167 +       return vxi;
9168 +}
9169 +
9170 +
9171 +extern void free_vx_info(struct vx_info *);
9172 +
9173 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9174 +
9175 +static inline void __put_vx_info(struct vx_info *vxi,
9176 +       const char *_file, int _line, void *_here)
9177 +{
9178 +       if (!vxi)
9179 +               return;
9180 +
9181 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9182 +               vxi, vxi ? vxi->vx_id : 0,
9183 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9184 +               _file, _line);
9185 +       __vxh_put_vx_info(vxi, _here);
9186 +
9187 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9188 +               free_vx_info(vxi);
9189 +}
9190 +
9191 +
9192 +#define init_vx_info(p, i) \
9193 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9194 +
9195 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9196 +       const char *_file, int _line, void *_here)
9197 +{
9198 +       if (vxi) {
9199 +               vxlprintk(VXD_CBIT(xid, 3),
9200 +                       "init_vx_info(%p[#%d.%d])",
9201 +                       vxi, vxi ? vxi->vx_id : 0,
9202 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9203 +                       _file, _line);
9204 +               __vxh_init_vx_info(vxi, vxp, _here);
9205 +
9206 +               atomic_inc(&vxi->vx_usecnt);
9207 +       }
9208 +       *vxp = vxi;
9209 +}
9210 +
9211 +
9212 +#define set_vx_info(p, i) \
9213 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9214 +
9215 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9216 +       const char *_file, int _line, void *_here)
9217 +{
9218 +       struct vx_info *vxo;
9219 +
9220 +       if (!vxi)
9221 +               return;
9222 +
9223 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9224 +               vxi, vxi ? vxi->vx_id : 0,
9225 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9226 +               _file, _line);
9227 +       __vxh_set_vx_info(vxi, vxp, _here);
9228 +
9229 +       atomic_inc(&vxi->vx_usecnt);
9230 +       vxo = xchg(vxp, vxi);
9231 +       BUG_ON(vxo);
9232 +}
9233 +
9234 +
9235 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9236 +
9237 +static inline void __clr_vx_info(struct vx_info **vxp,
9238 +       const char *_file, int _line, void *_here)
9239 +{
9240 +       struct vx_info *vxo;
9241 +
9242 +       vxo = xchg(vxp, NULL);
9243 +       if (!vxo)
9244 +               return;
9245 +
9246 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9247 +               vxo, vxo ? vxo->vx_id : 0,
9248 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9249 +               _file, _line);
9250 +       __vxh_clr_vx_info(vxo, vxp, _here);
9251 +
9252 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9253 +               free_vx_info(vxo);
9254 +}
9255 +
9256 +
9257 +#define claim_vx_info(v, p) \
9258 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9259 +
9260 +static inline void __claim_vx_info(struct vx_info *vxi,
9261 +       struct task_struct *task,
9262 +       const char *_file, int _line, void *_here)
9263 +{
9264 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9265 +               vxi, vxi ? vxi->vx_id : 0,
9266 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9267 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9268 +               task, _file, _line);
9269 +       __vxh_claim_vx_info(vxi, task, _here);
9270 +
9271 +       atomic_inc(&vxi->vx_tasks);
9272 +}
9273 +
9274 +
9275 +extern void unhash_vx_info(struct vx_info *);
9276 +
9277 +#define release_vx_info(v, p) \
9278 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9279 +
9280 +static inline void __release_vx_info(struct vx_info *vxi,
9281 +       struct task_struct *task,
9282 +       const char *_file, int _line, void *_here)
9283 +{
9284 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9285 +               vxi, vxi ? vxi->vx_id : 0,
9286 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9287 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9288 +               task, _file, _line);
9289 +       __vxh_release_vx_info(vxi, task, _here);
9290 +
9291 +       might_sleep();
9292 +
9293 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9294 +               unhash_vx_info(vxi);
9295 +}
9296 +
9297 +
9298 +#define task_get_vx_info(p) \
9299 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9300 +
9301 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9302 +       const char *_file, int _line, void *_here)
9303 +{
9304 +       struct vx_info *vxi;
9305 +
9306 +       task_lock(p);
9307 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9308 +               p, _file, _line);
9309 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9310 +       task_unlock(p);
9311 +       return vxi;
9312 +}
9313 +
9314 +
9315 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9316 +{
9317 +       if (waitqueue_active(&vxi->vx_wait))
9318 +               wake_up_interruptible(&vxi->vx_wait);
9319 +}
9320 +
9321 +
9322 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9323 +
9324 +static inline void __enter_vx_info(struct vx_info *vxi,
9325 +       struct vx_info_save *vxis, const char *_file, int _line)
9326 +{
9327 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9328 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9329 +               current->xid, current->vx_info, _file, _line);
9330 +       vxis->vxi = xchg(&current->vx_info, vxi);
9331 +       vxis->xid = current->xid;
9332 +       current->xid = vxi ? vxi->vx_id : 0;
9333 +}
9334 +
9335 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9336 +
9337 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9338 +       const char *_file, int _line)
9339 +{
9340 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9341 +               vxis, vxis->xid, vxis->vxi, current,
9342 +               current->xid, current->vx_info, _file, _line);
9343 +       (void)xchg(&current->vx_info, vxis->vxi);
9344 +       current->xid = vxis->xid;
9345 +}
9346 +
9347 +
9348 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9349 +{
9350 +       vxis->vxi = xchg(&current->vx_info, NULL);
9351 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9352 +}
9353 +
9354 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9355 +{
9356 +       (void)xchg(&current->xid, vxis->xid);
9357 +       (void)xchg(&current->vx_info, vxis->vxi);
9358 +}
9359 +
9360 +extern void exit_vx_info(struct task_struct *, int);
9361 +extern void exit_vx_info_early(struct task_struct *, int);
9362 +
9363 +
9364 +#else
9365 +#warning duplicate inclusion
9366 +#endif
9367 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_cowbl.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_cowbl.h
9368 --- linux-2.6.27.3/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9369 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_cowbl.h        2008-10-13 14:54:20.000000000 +0200
9370 @@ -0,0 +1,47 @@
9371 +#ifndef _VS_COWBL_H
9372 +#define _VS_COWBL_H
9373 +
9374 +#include <linux/fs.h>
9375 +#include <linux/dcache.h>
9376 +#include <linux/namei.h>
9377 +
9378 +extern struct dentry *cow_break_link(const char *pathname);
9379 +
9380 +static inline int cow_check_and_break(struct path *path)
9381 +{
9382 +       struct inode *inode = path->dentry->d_inode;
9383 +       int error = 0;
9384 +
9385 +       /* do we need this check? */
9386 +       if (IS_RDONLY(inode))
9387 +               return -EROFS;
9388 +
9389 +       if (IS_COW(inode)) {
9390 +               if (IS_COW_LINK(inode)) {
9391 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9392 +                       char *pp, *buf;
9393 +
9394 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9395 +                       if (!buf) {
9396 +                               return -ENOMEM;
9397 +                       }
9398 +                       pp = d_path(path, buf, PATH_MAX);
9399 +                       new_dentry = cow_break_link(pp);
9400 +                       kfree(buf);
9401 +                       if (!IS_ERR(new_dentry)) {
9402 +                               path->dentry = new_dentry;
9403 +                               dput(old_dentry);
9404 +                       } else
9405 +                               error = PTR_ERR(new_dentry);
9406 +               } else {
9407 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9408 +                       inode->i_ctime = CURRENT_TIME;
9409 +                       mark_inode_dirty(inode);
9410 +               }
9411 +       }
9412 +       return error;
9413 +}
9414 +
9415 +#else
9416 +#warning duplicate inclusion
9417 +#endif
9418 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_cvirt.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_cvirt.h
9419 --- linux-2.6.27.3/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9420 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_cvirt.h        2008-10-13 14:54:20.000000000 +0200
9421 @@ -0,0 +1,50 @@
9422 +#ifndef _VS_CVIRT_H
9423 +#define _VS_CVIRT_H
9424 +
9425 +#include "vserver/cvirt.h"
9426 +#include "vserver/context.h"
9427 +#include "vserver/base.h"
9428 +#include "vserver/check.h"
9429 +#include "vserver/debug.h"
9430 +
9431 +
9432 +static inline void vx_activate_task(struct task_struct *p)
9433 +{
9434 +       struct vx_info *vxi;
9435 +
9436 +       if ((vxi = p->vx_info)) {
9437 +               vx_update_load(vxi);
9438 +               atomic_inc(&vxi->cvirt.nr_running);
9439 +       }
9440 +}
9441 +
9442 +static inline void vx_deactivate_task(struct task_struct *p)
9443 +{
9444 +       struct vx_info *vxi;
9445 +
9446 +       if ((vxi = p->vx_info)) {
9447 +               vx_update_load(vxi);
9448 +               atomic_dec(&vxi->cvirt.nr_running);
9449 +       }
9450 +}
9451 +
9452 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9453 +{
9454 +       struct vx_info *vxi;
9455 +
9456 +       if ((vxi = p->vx_info))
9457 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9458 +}
9459 +
9460 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9461 +{
9462 +       struct vx_info *vxi;
9463 +
9464 +       if ((vxi = p->vx_info))
9465 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9466 +}
9467 +
9468 +
9469 +#else
9470 +#warning duplicate inclusion
9471 +#endif
9472 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_device.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_device.h
9473 --- linux-2.6.27.3/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9474 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_device.h       2008-10-13 14:54:20.000000000 +0200
9475 @@ -0,0 +1,45 @@
9476 +#ifndef _VS_DEVICE_H
9477 +#define _VS_DEVICE_H
9478 +
9479 +#include "vserver/base.h"
9480 +#include "vserver/device.h"
9481 +#include "vserver/debug.h"
9482 +
9483 +
9484 +#ifdef CONFIG_VSERVER_DEVICE
9485 +
9486 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9487 +
9488 +#define vs_device_perm(v, d, m, p) \
9489 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9490 +
9491 +#else
9492 +
9493 +static inline
9494 +int vs_map_device(struct vx_info *vxi,
9495 +       dev_t device, dev_t *target, umode_t mode)
9496 +{
9497 +       if (target)
9498 +               *target = device;
9499 +       return ~0;
9500 +}
9501 +
9502 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9503 +
9504 +#endif
9505 +
9506 +
9507 +#define vs_map_chrdev(d, t, p) \
9508 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9509 +#define vs_map_blkdev(d, t, p) \
9510 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9511 +
9512 +#define vs_chrdev_perm(d, p) \
9513 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9514 +#define vs_blkdev_perm(d, p) \
9515 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9516 +
9517 +
9518 +#else
9519 +#warning duplicate inclusion
9520 +#endif
9521 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_dlimit.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_dlimit.h
9522 --- linux-2.6.27.3/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
9523 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_dlimit.h       2008-10-13 14:54:20.000000000 +0200
9524 @@ -0,0 +1,211 @@
9525 +#ifndef _VS_DLIMIT_H
9526 +#define _VS_DLIMIT_H
9527 +
9528 +#include <linux/fs.h>
9529 +
9530 +#include "vserver/dlimit.h"
9531 +#include "vserver/base.h"
9532 +#include "vserver/debug.h"
9533 +
9534 +
9535 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9536 +
9537 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9538 +       const char *_file, int _line)
9539 +{
9540 +       if (!dli)
9541 +               return NULL;
9542 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9543 +               dli, dli ? dli->dl_tag : 0,
9544 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9545 +               _file, _line);
9546 +       atomic_inc(&dli->dl_usecnt);
9547 +       return dli;
9548 +}
9549 +
9550 +
9551 +#define free_dl_info(i) \
9552 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9553 +
9554 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9555 +
9556 +static inline void __put_dl_info(struct dl_info *dli,
9557 +       const char *_file, int _line)
9558 +{
9559 +       if (!dli)
9560 +               return;
9561 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9562 +               dli, dli ? dli->dl_tag : 0,
9563 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9564 +               _file, _line);
9565 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9566 +               free_dl_info(dli);
9567 +}
9568 +
9569 +
9570 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9571 +
9572 +static inline int __dl_alloc_space(struct super_block *sb,
9573 +       tag_t tag, dlsize_t nr, const char *file, int line)
9574 +{
9575 +       struct dl_info *dli = NULL;
9576 +       int ret = 0;
9577 +
9578 +       if (nr == 0)
9579 +               goto out;
9580 +       dli = locate_dl_info(sb, tag);
9581 +       if (!dli)
9582 +               goto out;
9583 +
9584 +       spin_lock(&dli->dl_lock);
9585 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9586 +       if (!ret)
9587 +               dli->dl_space_used += nr;
9588 +       spin_unlock(&dli->dl_lock);
9589 +       put_dl_info(dli);
9590 +out:
9591 +       vxlprintk(VXD_CBIT(dlim, 1),
9592 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9593 +               sb, tag, __dlimit_char(dli), (long long)nr,
9594 +               ret, file, line);
9595 +       return ret;
9596 +}
9597 +
9598 +static inline void __dl_free_space(struct super_block *sb,
9599 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9600 +{
9601 +       struct dl_info *dli = NULL;
9602 +
9603 +       if (nr == 0)
9604 +               goto out;
9605 +       dli = locate_dl_info(sb, tag);
9606 +       if (!dli)
9607 +               goto out;
9608 +
9609 +       spin_lock(&dli->dl_lock);
9610 +       if (dli->dl_space_used > nr)
9611 +               dli->dl_space_used -= nr;
9612 +       else
9613 +               dli->dl_space_used = 0;
9614 +       spin_unlock(&dli->dl_lock);
9615 +       put_dl_info(dli);
9616 +out:
9617 +       vxlprintk(VXD_CBIT(dlim, 1),
9618 +               "FREE  (%p,#%d)%c %lld bytes",
9619 +               sb, tag, __dlimit_char(dli), (long long)nr,
9620 +               _file, _line);
9621 +}
9622 +
9623 +static inline int __dl_alloc_inode(struct super_block *sb,
9624 +       tag_t tag, const char *_file, int _line)
9625 +{
9626 +       struct dl_info *dli;
9627 +       int ret = 0;
9628 +
9629 +       dli = locate_dl_info(sb, tag);
9630 +       if (!dli)
9631 +               goto out;
9632 +
9633 +       spin_lock(&dli->dl_lock);
9634 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
9635 +       if (!ret)
9636 +               dli->dl_inodes_used++;
9637 +       spin_unlock(&dli->dl_lock);
9638 +       put_dl_info(dli);
9639 +out:
9640 +       vxlprintk(VXD_CBIT(dlim, 0),
9641 +               "ALLOC (%p,#%d)%c inode (%d)",
9642 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9643 +       return ret;
9644 +}
9645 +
9646 +static inline void __dl_free_inode(struct super_block *sb,
9647 +       tag_t tag, const char *_file, int _line)
9648 +{
9649 +       struct dl_info *dli;
9650 +
9651 +       dli = locate_dl_info(sb, tag);
9652 +       if (!dli)
9653 +               goto out;
9654 +
9655 +       spin_lock(&dli->dl_lock);
9656 +       if (dli->dl_inodes_used > 1)
9657 +               dli->dl_inodes_used--;
9658 +       else
9659 +               dli->dl_inodes_used = 0;
9660 +       spin_unlock(&dli->dl_lock);
9661 +       put_dl_info(dli);
9662 +out:
9663 +       vxlprintk(VXD_CBIT(dlim, 0),
9664 +               "FREE  (%p,#%d)%c inode",
9665 +               sb, tag, __dlimit_char(dli), _file, _line);
9666 +}
9667 +
9668 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9669 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9670 +       const char *_file, int _line)
9671 +{
9672 +       struct dl_info *dli;
9673 +       uint64_t broot, bfree;
9674 +
9675 +       dli = locate_dl_info(sb, tag);
9676 +       if (!dli)
9677 +               return;
9678 +
9679 +       spin_lock(&dli->dl_lock);
9680 +       broot = (dli->dl_space_total -
9681 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9682 +               >> sb->s_blocksize_bits;
9683 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9684 +                       >> sb->s_blocksize_bits;
9685 +       spin_unlock(&dli->dl_lock);
9686 +
9687 +       vxlprintk(VXD_CBIT(dlim, 2),
9688 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9689 +               (long long)bfree, (long long)broot,
9690 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9691 +               _file, _line);
9692 +       if (free_blocks) {
9693 +               if (*free_blocks > bfree)
9694 +                       *free_blocks = bfree;
9695 +       }
9696 +       if (root_blocks) {
9697 +               if (*root_blocks > broot)
9698 +                       *root_blocks = broot;
9699 +       }
9700 +       put_dl_info(dli);
9701 +}
9702 +
9703 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
9704 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9705 +               __FILE__, __LINE__ )
9706 +
9707 +#define DLIMIT_FREE_SPACE(in, bytes) \
9708 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9709 +               __FILE__, __LINE__ )
9710 +
9711 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
9712 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
9713 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
9714 +               __FILE__, __LINE__ )
9715 +
9716 +#define DLIMIT_FREE_BLOCK(in, nr) \
9717 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
9718 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
9719 +               __FILE__, __LINE__ )
9720 +
9721 +
9722 +#define DLIMIT_ALLOC_INODE(in) \
9723 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9724 +
9725 +#define DLIMIT_FREE_INODE(in) \
9726 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9727 +
9728 +
9729 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
9730 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9731 +
9732 +
9733 +#else
9734 +#warning duplicate inclusion
9735 +#endif
9736 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/base.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/base.h
9737 --- linux-2.6.27.3/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
9738 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/base.h    2008-10-13 14:54:20.000000000 +0200
9739 @@ -0,0 +1,157 @@
9740 +#ifndef _VX_BASE_H
9741 +#define _VX_BASE_H
9742 +
9743 +
9744 +/* context state changes */
9745 +
9746 +enum {
9747 +       VSC_STARTUP = 1,
9748 +       VSC_SHUTDOWN,
9749 +
9750 +       VSC_NETUP,
9751 +       VSC_NETDOWN,
9752 +};
9753 +
9754 +
9755 +
9756 +#define vx_task_xid(t) ((t)->xid)
9757 +
9758 +#define vx_current_xid() vx_task_xid(current)
9759 +
9760 +#define current_vx_info() (current->vx_info)
9761 +
9762 +
9763 +#define nx_task_nid(t) ((t)->nid)
9764 +
9765 +#define nx_current_nid() nx_task_nid(current)
9766 +
9767 +#define current_nx_info() (current->nx_info)
9768 +
9769 +
9770 +/* generic flag merging */
9771 +
9772 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9773 +
9774 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9775 +
9776 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9777 +
9778 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9779 +
9780 +
9781 +/* context flags */
9782 +
9783 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9784 +
9785 +#define vx_current_flags()     __vx_flags(current->vx_info)
9786 +
9787 +#define vx_info_flags(v, m, f) \
9788 +       vs_check_flags(__vx_flags(v), m, f)
9789 +
9790 +#define task_vx_flags(t, m, f) \
9791 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9792 +
9793 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
9794 +
9795 +
9796 +/* context caps */
9797 +
9798 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9799 +
9800 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
9801 +
9802 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9803 +
9804 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
9805 +
9806 +
9807 +
9808 +/* network flags */
9809 +
9810 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9811 +
9812 +#define nx_current_flags()     __nx_flags(current->nx_info)
9813 +
9814 +#define nx_info_flags(n, m, f) \
9815 +       vs_check_flags(__nx_flags(n), m, f)
9816 +
9817 +#define task_nx_flags(t, m, f) \
9818 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9819 +
9820 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
9821 +
9822 +
9823 +/* network caps */
9824 +
9825 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9826 +
9827 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
9828 +
9829 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9830 +
9831 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
9832 +
9833 +
9834 +/* context mask capabilities */
9835 +
9836 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9837 +
9838 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9839 +
9840 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
9841 +
9842 +
9843 +/* context bcap mask */
9844 +
9845 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9846 +
9847 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
9848 +
9849 +
9850 +/* mask given bcaps */
9851 +
9852 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9853 +
9854 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
9855 +
9856 +
9857 +/* masked cap_bset */
9858 +
9859 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9860 +
9861 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
9862 +
9863 +#if 0
9864 +#define vx_info_mbcap(v, b) \
9865 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9866 +       vx_info_bcaps(v, b) : (b))
9867 +
9868 +#define task_vx_mbcap(t, b) \
9869 +       vx_info_mbcap((t)->vx_info, (t)->b)
9870 +
9871 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9872 +#endif
9873 +
9874 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9875 +
9876 +#define vx_capable(b, c) (capable(b) || \
9877 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
9878 +
9879 +#define nx_capable(b, c) (capable(b) || \
9880 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
9881 +
9882 +#define vx_current_initpid(n) \
9883 +       (current->vx_info && \
9884 +       (current->vx_info->vx_initpid == (n)))
9885 +
9886 +
9887 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9888 +
9889 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9890 +
9891 +
9892 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9893 +
9894 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9895 +
9896 +#endif
9897 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cacct_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct_cmd.h
9898 --- linux-2.6.27.3/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
9899 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct_cmd.h       2008-10-13 14:54:20.000000000 +0200
9900 @@ -0,0 +1,23 @@
9901 +#ifndef _VX_CACCT_CMD_H
9902 +#define _VX_CACCT_CMD_H
9903 +
9904 +
9905 +/* virtual host info name commands */
9906 +
9907 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
9908 +
9909 +struct vcmd_sock_stat_v0 {
9910 +       uint32_t field;
9911 +       uint32_t count[3];
9912 +       uint64_t total[3];
9913 +};
9914 +
9915 +
9916 +#ifdef __KERNEL__
9917 +
9918 +#include <linux/compiler.h>
9919 +
9920 +extern int vc_sock_stat(struct vx_info *, void __user *);
9921 +
9922 +#endif /* __KERNEL__ */
9923 +#endif /* _VX_CACCT_CMD_H */
9924 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cacct_def.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct_def.h
9925 --- linux-2.6.27.3/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
9926 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct_def.h       2008-10-13 14:54:20.000000000 +0200
9927 @@ -0,0 +1,43 @@
9928 +#ifndef _VX_CACCT_DEF_H
9929 +#define _VX_CACCT_DEF_H
9930 +
9931 +#include <asm/atomic.h>
9932 +#include <linux/vserver/cacct.h>
9933 +
9934 +
9935 +struct _vx_sock_acc {
9936 +       atomic_long_t count;
9937 +       atomic_long_t total;
9938 +};
9939 +
9940 +/* context sub struct */
9941 +
9942 +struct _vx_cacct {
9943 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9944 +       atomic_t slab[8];
9945 +       atomic_t page[6][8];
9946 +};
9947 +
9948 +#ifdef CONFIG_VSERVER_DEBUG
9949 +
9950 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9951 +{
9952 +       int i, j;
9953 +
9954 +       printk("\t_vx_cacct:");
9955 +       for (i = 0; i < 6; i++) {
9956 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9957 +
9958 +               printk("\t [%d] =", i);
9959 +               for (j = 0; j < 3; j++) {
9960 +                       printk(" [%d] = %8lu, %8lu", j,
9961 +                               atomic_long_read(&ptr[j].count),
9962 +                               atomic_long_read(&ptr[j].total));
9963 +               }
9964 +               printk("\n");
9965 +       }
9966 +}
9967 +
9968 +#endif
9969 +
9970 +#endif /* _VX_CACCT_DEF_H */
9971 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cacct.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct.h
9972 --- linux-2.6.27.3/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
9973 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct.h   2008-10-13 14:54:20.000000000 +0200
9974 @@ -0,0 +1,15 @@
9975 +#ifndef _VX_CACCT_H
9976 +#define _VX_CACCT_H
9977 +
9978 +
9979 +enum sock_acc_field {
9980 +       VXA_SOCK_UNSPEC = 0,
9981 +       VXA_SOCK_UNIX,
9982 +       VXA_SOCK_INET,
9983 +       VXA_SOCK_INET6,
9984 +       VXA_SOCK_PACKET,
9985 +       VXA_SOCK_OTHER,
9986 +       VXA_SOCK_SIZE   /* array size */
9987 +};
9988 +
9989 +#endif /* _VX_CACCT_H */
9990 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cacct_int.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct_int.h
9991 --- linux-2.6.27.3/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
9992 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cacct_int.h       2008-10-13 14:54:20.000000000 +0200
9993 @@ -0,0 +1,21 @@
9994 +#ifndef _VX_CACCT_INT_H
9995 +#define _VX_CACCT_INT_H
9996 +
9997 +
9998 +#ifdef __KERNEL__
9999 +
10000 +static inline
10001 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10002 +{
10003 +       return atomic_long_read(&cacct->sock[type][pos].count);
10004 +}
10005 +
10006 +
10007 +static inline
10008 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10009 +{
10010 +       return atomic_long_read(&cacct->sock[type][pos].total);
10011 +}
10012 +
10013 +#endif /* __KERNEL__ */
10014 +#endif /* _VX_CACCT_INT_H */
10015 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/check.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/check.h
10016 --- linux-2.6.27.3/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10017 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/check.h   2008-10-13 14:54:20.000000000 +0200
10018 @@ -0,0 +1,89 @@
10019 +#ifndef _VS_CHECK_H
10020 +#define _VS_CHECK_H
10021 +
10022 +
10023 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10024 +
10025 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10026 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10027 +#else
10028 +#define MIN_D_CONTEXT  65536
10029 +#endif
10030 +
10031 +/* check conditions */
10032 +
10033 +#define VS_ADMIN       0x0001
10034 +#define VS_WATCH       0x0002
10035 +#define VS_HIDE                0x0004
10036 +#define VS_HOSTID      0x0008
10037 +
10038 +#define VS_IDENT       0x0010
10039 +#define VS_EQUIV       0x0020
10040 +#define VS_PARENT      0x0040
10041 +#define VS_CHILD       0x0080
10042 +
10043 +#define VS_ARG_MASK    0x00F0
10044 +
10045 +#define VS_DYNAMIC     0x0100
10046 +#define VS_STATIC      0x0200
10047 +
10048 +#define VS_ATR_MASK    0x0F00
10049 +
10050 +#ifdef CONFIG_VSERVER_PRIVACY
10051 +#define VS_ADMIN_P     (0)
10052 +#define VS_WATCH_P     (0)
10053 +#else
10054 +#define VS_ADMIN_P     VS_ADMIN
10055 +#define VS_WATCH_P     VS_WATCH
10056 +#endif
10057 +
10058 +#define VS_HARDIRQ     0x1000
10059 +#define VS_SOFTIRQ     0x2000
10060 +#define VS_IRQ         0x4000
10061 +
10062 +#define VS_IRQ_MASK    0xF000
10063 +
10064 +#include <linux/hardirq.h>
10065 +
10066 +/*
10067 + * check current context for ADMIN/WATCH and
10068 + * optionally against supplied argument
10069 + */
10070 +static inline int __vs_check(int cid, int id, unsigned int mode)
10071 +{
10072 +       if (mode & VS_ARG_MASK) {
10073 +               if ((mode & VS_IDENT) && (id == cid))
10074 +                       return 1;
10075 +       }
10076 +       if (mode & VS_ATR_MASK) {
10077 +               if ((mode & VS_DYNAMIC) &&
10078 +                       (id >= MIN_D_CONTEXT) &&
10079 +                       (id <= MAX_S_CONTEXT))
10080 +                       return 1;
10081 +               if ((mode & VS_STATIC) &&
10082 +                       (id > 1) && (id < MIN_D_CONTEXT))
10083 +                       return 1;
10084 +       }
10085 +       if (mode & VS_IRQ_MASK) {
10086 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10087 +                       return 1;
10088 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10089 +                       return 1;
10090 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10091 +                       return 1;
10092 +       }
10093 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10094 +               ((mode & VS_WATCH) && (cid == 1)) ||
10095 +               ((mode & VS_HOSTID) && (id == 0)));
10096 +}
10097 +
10098 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10099 +
10100 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10101 +
10102 +
10103 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10104 +
10105 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10106 +
10107 +#endif
10108 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/context_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/context_cmd.h
10109 --- linux-2.6.27.3/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10110 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/context_cmd.h     2008-10-13 14:54:20.000000000 +0200
10111 @@ -0,0 +1,128 @@
10112 +#ifndef _VX_CONTEXT_CMD_H
10113 +#define _VX_CONTEXT_CMD_H
10114 +
10115 +
10116 +/* vinfo commands */
10117 +
10118 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10119 +
10120 +#ifdef __KERNEL__
10121 +extern int vc_task_xid(uint32_t);
10122 +
10123 +#endif /* __KERNEL__ */
10124 +
10125 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10126 +
10127 +struct vcmd_vx_info_v0 {
10128 +       uint32_t xid;
10129 +       uint32_t initpid;
10130 +       /* more to come */
10131 +};
10132 +
10133 +#ifdef __KERNEL__
10134 +extern int vc_vx_info(struct vx_info *, void __user *);
10135 +
10136 +#endif /* __KERNEL__ */
10137 +
10138 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10139 +
10140 +struct vcmd_ctx_stat_v0 {
10141 +       uint32_t usecnt;
10142 +       uint32_t tasks;
10143 +       /* more to come */
10144 +};
10145 +
10146 +#ifdef __KERNEL__
10147 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10148 +
10149 +#endif /* __KERNEL__ */
10150 +
10151 +/* context commands */
10152 +
10153 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10154 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10155 +
10156 +struct vcmd_ctx_create {
10157 +       uint64_t flagword;
10158 +};
10159 +
10160 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10161 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10162 +
10163 +struct vcmd_ctx_migrate {
10164 +       uint64_t flagword;
10165 +};
10166 +
10167 +#ifdef __KERNEL__
10168 +extern int vc_ctx_create(uint32_t, void __user *);
10169 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10170 +
10171 +#endif /* __KERNEL__ */
10172 +
10173 +
10174 +/* flag commands */
10175 +
10176 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10177 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10178 +
10179 +struct vcmd_ctx_flags_v0 {
10180 +       uint64_t flagword;
10181 +       uint64_t mask;
10182 +};
10183 +
10184 +#ifdef __KERNEL__
10185 +extern int vc_get_cflags(struct vx_info *, void __user *);
10186 +extern int vc_set_cflags(struct vx_info *, void __user *);
10187 +
10188 +#endif /* __KERNEL__ */
10189 +
10190 +
10191 +/* context caps commands */
10192 +
10193 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10194 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10195 +
10196 +struct vcmd_ctx_caps_v1 {
10197 +       uint64_t ccaps;
10198 +       uint64_t cmask;
10199 +};
10200 +
10201 +#ifdef __KERNEL__
10202 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10203 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10204 +
10205 +#endif /* __KERNEL__ */
10206 +
10207 +
10208 +/* bcaps commands */
10209 +
10210 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10211 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10212 +
10213 +struct vcmd_bcaps {
10214 +       uint64_t bcaps;
10215 +       uint64_t bmask;
10216 +};
10217 +
10218 +#ifdef __KERNEL__
10219 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10220 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10221 +
10222 +#endif /* __KERNEL__ */
10223 +
10224 +
10225 +/* OOM badness */
10226 +
10227 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10228 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10229 +
10230 +struct vcmd_badness_v0 {
10231 +       int64_t bias;
10232 +};
10233 +
10234 +#ifdef __KERNEL__
10235 +extern int vc_get_badness(struct vx_info *, void __user *);
10236 +extern int vc_set_badness(struct vx_info *, void __user *);
10237 +
10238 +#endif /* __KERNEL__ */
10239 +#endif /* _VX_CONTEXT_CMD_H */
10240 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/context.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/context.h
10241 --- linux-2.6.27.3/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10242 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/context.h 2008-10-13 14:54:20.000000000 +0200
10243 @@ -0,0 +1,176 @@
10244 +#ifndef _VX_CONTEXT_H
10245 +#define _VX_CONTEXT_H
10246 +
10247 +#include <linux/types.h>
10248 +#include <linux/capability.h>
10249 +
10250 +
10251 +/* context flags */
10252 +
10253 +#define VXF_INFO_SCHED         0x00000002
10254 +#define VXF_INFO_NPROC         0x00000004
10255 +#define VXF_INFO_PRIVATE       0x00000008
10256 +
10257 +#define VXF_INFO_INIT          0x00000010
10258 +#define VXF_INFO_HIDE          0x00000020
10259 +#define VXF_INFO_ULIMIT                0x00000040
10260 +#define VXF_INFO_NSPACE                0x00000080
10261 +
10262 +#define VXF_SCHED_HARD         0x00000100
10263 +#define VXF_SCHED_PRIO         0x00000200
10264 +#define VXF_SCHED_PAUSE                0x00000400
10265 +
10266 +#define VXF_VIRT_MEM           0x00010000
10267 +#define VXF_VIRT_UPTIME                0x00020000
10268 +#define VXF_VIRT_CPU           0x00040000
10269 +#define VXF_VIRT_LOAD          0x00080000
10270 +#define VXF_VIRT_TIME          0x00100000
10271 +
10272 +#define VXF_HIDE_MOUNT         0x01000000
10273 +/* was VXF_HIDE_NETIF          0x02000000 */
10274 +#define VXF_HIDE_VINFO         0x04000000
10275 +
10276 +#define VXF_STATE_SETUP                (1ULL << 32)
10277 +#define VXF_STATE_INIT         (1ULL << 33)
10278 +#define VXF_STATE_ADMIN                (1ULL << 34)
10279 +
10280 +#define VXF_SC_HELPER          (1ULL << 36)
10281 +#define VXF_REBOOT_KILL                (1ULL << 37)
10282 +#define VXF_PERSISTENT         (1ULL << 38)
10283 +
10284 +#define VXF_FORK_RSS           (1ULL << 48)
10285 +#define VXF_PROLIFIC           (1ULL << 49)
10286 +
10287 +#define VXF_IGNEG_NICE         (1ULL << 52)
10288 +
10289 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10290 +
10291 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10292 +
10293 +
10294 +/* context migration */
10295 +
10296 +#define VXM_SET_INIT           0x00000001
10297 +#define VXM_SET_REAPER         0x00000002
10298 +
10299 +/* context caps */
10300 +
10301 +#define VXC_CAP_MASK           0x00000000
10302 +
10303 +#define VXC_SET_UTSNAME                0x00000001
10304 +#define VXC_SET_RLIMIT         0x00000002
10305 +
10306 +/* was VXC_RAW_ICMP            0x00000100 */
10307 +#define VXC_SYSLOG             0x00001000
10308 +
10309 +#define VXC_SECURE_MOUNT       0x00010000
10310 +#define VXC_SECURE_REMOUNT     0x00020000
10311 +#define VXC_BINARY_MOUNT       0x00040000
10312 +
10313 +#define VXC_QUOTA_CTL          0x00100000
10314 +#define VXC_ADMIN_MAPPER       0x00200000
10315 +#define VXC_ADMIN_CLOOP                0x00400000
10316 +
10317 +#define VXC_KTHREAD            0x01000000
10318 +
10319 +
10320 +#ifdef __KERNEL__
10321 +
10322 +#include <linux/list.h>
10323 +#include <linux/spinlock.h>
10324 +#include <linux/rcupdate.h>
10325 +
10326 +#include "limit_def.h"
10327 +#include "sched_def.h"
10328 +#include "cvirt_def.h"
10329 +#include "cacct_def.h"
10330 +#include "device_def.h"
10331 +
10332 +struct _vx_info_pc {
10333 +       struct _vx_sched_pc sched_pc;
10334 +       struct _vx_cvirt_pc cvirt_pc;
10335 +};
10336 +
10337 +struct vx_info {
10338 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10339 +       xid_t vx_id;                            /* context id */
10340 +       atomic_t vx_usecnt;                     /* usage count */
10341 +       atomic_t vx_tasks;                      /* tasks count */
10342 +       struct vx_info *vx_parent;              /* parent context */
10343 +       int vx_state;                           /* context state */
10344 +
10345 +       unsigned long vx_nsmask;                /* assignment mask */
10346 +       struct nsproxy *vx_nsproxy;             /* private namespace */
10347 +       struct fs_struct *vx_fs;                /* private namespace fs */
10348 +
10349 +       uint64_t vx_flags;                      /* context flags */
10350 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10351 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10352 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
10353 +
10354 +       struct task_struct *vx_reaper;          /* guest reaper process */
10355 +       pid_t vx_initpid;                       /* PID of guest init */
10356 +       int64_t vx_badness_bias;                /* OOM points bias */
10357 +
10358 +       struct _vx_limit limit;                 /* vserver limits */
10359 +       struct _vx_sched sched;                 /* vserver scheduler */
10360 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10361 +       struct _vx_cacct cacct;                 /* context accounting */
10362 +
10363 +       struct _vx_device dmap;                 /* default device map targets */
10364 +
10365 +#ifndef CONFIG_SMP
10366 +       struct _vx_info_pc info_pc;             /* per cpu data */
10367 +#else
10368 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10369 +#endif
10370 +
10371 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10372 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10373 +       int exit_code;                          /* last process exit code */
10374 +
10375 +       char vx_name[65];                       /* vserver name */
10376 +};
10377 +
10378 +#ifndef CONFIG_SMP
10379 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10380 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10381 +#else
10382 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10383 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10384 +#endif
10385 +
10386 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10387 +
10388 +
10389 +struct vx_info_save {
10390 +       struct vx_info *vxi;
10391 +       xid_t xid;
10392 +};
10393 +
10394 +
10395 +/* status flags */
10396 +
10397 +#define VXS_HASHED     0x0001
10398 +#define VXS_PAUSED     0x0010
10399 +#define VXS_SHUTDOWN   0x0100
10400 +#define VXS_HELPER     0x1000
10401 +#define VXS_RELEASED   0x8000
10402 +
10403 +
10404 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10405 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10406 +
10407 +extern struct vx_info *lookup_vx_info(int);
10408 +extern struct vx_info *lookup_or_create_vx_info(int);
10409 +
10410 +extern int get_xid_list(int, unsigned int *, int);
10411 +extern int xid_is_hashed(xid_t);
10412 +
10413 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10414 +
10415 +extern long vs_state_change(struct vx_info *, unsigned int);
10416 +
10417 +
10418 +#endif /* __KERNEL__ */
10419 +#endif /* _VX_CONTEXT_H */
10420 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cvirt_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cvirt_cmd.h
10421 --- linux-2.6.27.3/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
10422 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cvirt_cmd.h       2008-10-13 14:54:20.000000000 +0200
10423 @@ -0,0 +1,53 @@
10424 +#ifndef _VX_CVIRT_CMD_H
10425 +#define _VX_CVIRT_CMD_H
10426 +
10427 +
10428 +/* virtual host info name commands */
10429 +
10430 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10431 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10432 +
10433 +struct vcmd_vhi_name_v0 {
10434 +       uint32_t field;
10435 +       char name[65];
10436 +};
10437 +
10438 +
10439 +enum vhi_name_field {
10440 +       VHIN_CONTEXT = 0,
10441 +       VHIN_SYSNAME,
10442 +       VHIN_NODENAME,
10443 +       VHIN_RELEASE,
10444 +       VHIN_VERSION,
10445 +       VHIN_MACHINE,
10446 +       VHIN_DOMAINNAME,
10447 +};
10448 +
10449 +
10450 +#ifdef __KERNEL__
10451 +
10452 +#include <linux/compiler.h>
10453 +
10454 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10455 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10456 +
10457 +#endif /* __KERNEL__ */
10458 +
10459 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10460 +
10461 +struct vcmd_virt_stat_v0 {
10462 +       uint64_t offset;
10463 +       uint64_t uptime;
10464 +       uint32_t nr_threads;
10465 +       uint32_t nr_running;
10466 +       uint32_t nr_uninterruptible;
10467 +       uint32_t nr_onhold;
10468 +       uint32_t nr_forks;
10469 +       uint32_t load[3];
10470 +};
10471 +
10472 +#ifdef __KERNEL__
10473 +extern int vc_virt_stat(struct vx_info *, void __user *);
10474 +
10475 +#endif /* __KERNEL__ */
10476 +#endif /* _VX_CVIRT_CMD_H */
10477 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cvirt_def.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cvirt_def.h
10478 --- linux-2.6.27.3/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
10479 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cvirt_def.h       2008-10-13 14:54:20.000000000 +0200
10480 @@ -0,0 +1,80 @@
10481 +#ifndef _VX_CVIRT_DEF_H
10482 +#define _VX_CVIRT_DEF_H
10483 +
10484 +#include <linux/jiffies.h>
10485 +#include <linux/spinlock.h>
10486 +#include <linux/wait.h>
10487 +#include <linux/time.h>
10488 +#include <asm/atomic.h>
10489 +
10490 +
10491 +struct _vx_usage_stat {
10492 +       uint64_t user;
10493 +       uint64_t nice;
10494 +       uint64_t system;
10495 +       uint64_t softirq;
10496 +       uint64_t irq;
10497 +       uint64_t idle;
10498 +       uint64_t iowait;
10499 +};
10500 +
10501 +struct _vx_syslog {
10502 +       wait_queue_head_t log_wait;
10503 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10504 +
10505 +       unsigned long log_start;        /* next char to be read by syslog() */
10506 +       unsigned long con_start;        /* next char to be sent to consoles */
10507 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10508 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10509 +
10510 +       char log_buf[1024];
10511 +};
10512 +
10513 +
10514 +/* context sub struct */
10515 +
10516 +struct _vx_cvirt {
10517 +       atomic_t nr_threads;            /* number of current threads */
10518 +       atomic_t nr_running;            /* number of running threads */
10519 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10520 +
10521 +       atomic_t nr_onhold;             /* processes on hold */
10522 +       uint32_t onhold_last;           /* jiffies when put on hold */
10523 +
10524 +       struct timeval bias_tv;         /* time offset to the host */
10525 +       struct timespec bias_idle;
10526 +       struct timespec bias_uptime;    /* context creation point */
10527 +       uint64_t bias_clock;            /* offset in clock_t */
10528 +
10529 +       spinlock_t load_lock;           /* lock for the load averages */
10530 +       atomic_t load_updates;          /* nr of load updates done so far */
10531 +       uint32_t load_last;             /* last time load was calculated */
10532 +       uint32_t load[3];               /* load averages 1,5,15 */
10533 +
10534 +       atomic_t total_forks;           /* number of forks so far */
10535 +
10536 +       struct _vx_syslog syslog;
10537 +};
10538 +
10539 +struct _vx_cvirt_pc {
10540 +       struct _vx_usage_stat cpustat;
10541 +};
10542 +
10543 +
10544 +#ifdef CONFIG_VSERVER_DEBUG
10545 +
10546 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10547 +{
10548 +       printk("\t_vx_cvirt:\n");
10549 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10550 +               atomic_read(&cvirt->nr_threads),
10551 +               atomic_read(&cvirt->nr_running),
10552 +               atomic_read(&cvirt->nr_uninterruptible),
10553 +               atomic_read(&cvirt->nr_onhold));
10554 +       /* add rest here */
10555 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10556 +}
10557 +
10558 +#endif
10559 +
10560 +#endif /* _VX_CVIRT_DEF_H */
10561 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/cvirt.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cvirt.h
10562 --- linux-2.6.27.3/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
10563 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/cvirt.h   2008-10-13 14:54:20.000000000 +0200
10564 @@ -0,0 +1,20 @@
10565 +#ifndef _VX_CVIRT_H
10566 +#define _VX_CVIRT_H
10567 +
10568 +
10569 +#ifdef __KERNEL__
10570 +
10571 +struct timespec;
10572 +
10573 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10574 +
10575 +
10576 +struct vx_info;
10577 +
10578 +void vx_update_load(struct vx_info *);
10579 +
10580 +
10581 +int vx_do_syslog(int, char __user *, int);
10582 +
10583 +#endif /* __KERNEL__ */
10584 +#endif /* _VX_CVIRT_H */
10585 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/debug_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/debug_cmd.h
10586 --- linux-2.6.27.3/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
10587 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/debug_cmd.h       2008-10-13 14:54:20.000000000 +0200
10588 @@ -0,0 +1,58 @@
10589 +#ifndef _VX_DEBUG_CMD_H
10590 +#define _VX_DEBUG_CMD_H
10591 +
10592 +
10593 +/* debug commands */
10594 +
10595 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10596 +
10597 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10598 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10599 +
10600 +struct  vcmd_read_history_v0 {
10601 +       uint32_t index;
10602 +       uint32_t count;
10603 +       char __user *data;
10604 +};
10605 +
10606 +struct  vcmd_read_monitor_v0 {
10607 +       uint32_t index;
10608 +       uint32_t count;
10609 +       char __user *data;
10610 +};
10611 +
10612 +
10613 +#ifdef __KERNEL__
10614 +
10615 +#ifdef CONFIG_COMPAT
10616 +
10617 +#include <asm/compat.h>
10618 +
10619 +struct vcmd_read_history_v0_x32 {
10620 +       uint32_t index;
10621 +       uint32_t count;
10622 +       compat_uptr_t data_ptr;
10623 +};
10624 +
10625 +struct vcmd_read_monitor_v0_x32 {
10626 +       uint32_t index;
10627 +       uint32_t count;
10628 +       compat_uptr_t data_ptr;
10629 +};
10630 +
10631 +#endif  /* CONFIG_COMPAT */
10632 +
10633 +extern int vc_dump_history(uint32_t);
10634 +
10635 +extern int vc_read_history(uint32_t, void __user *);
10636 +extern int vc_read_monitor(uint32_t, void __user *);
10637 +
10638 +#ifdef CONFIG_COMPAT
10639 +
10640 +extern int vc_read_history_x32(uint32_t, void __user *);
10641 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10642 +
10643 +#endif  /* CONFIG_COMPAT */
10644 +
10645 +#endif /* __KERNEL__ */
10646 +#endif /* _VX_DEBUG_CMD_H */
10647 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/debug.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/debug.h
10648 --- linux-2.6.27.3/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
10649 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/debug.h   2008-10-13 14:54:20.000000000 +0200
10650 @@ -0,0 +1,127 @@
10651 +#ifndef _VX_DEBUG_H
10652 +#define _VX_DEBUG_H
10653 +
10654 +
10655 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
10656 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
10657 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
10658 +
10659 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10660 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10661 +#define VXF_DEV                "%p[%lu,%d:%d]"
10662 +
10663 +
10664 +#define vxd_path(p)                                            \
10665 +       ({ static char _buffer[PATH_MAX];                       \
10666 +          d_path(p, _buffer, sizeof(_buffer)); })
10667 +
10668 +#define vxd_cond_path(n)                                       \
10669 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10670 +
10671 +
10672 +#ifdef CONFIG_VSERVER_DEBUG
10673 +
10674 +extern unsigned int vx_debug_switch;
10675 +extern unsigned int vx_debug_xid;
10676 +extern unsigned int vx_debug_nid;
10677 +extern unsigned int vx_debug_tag;
10678 +extern unsigned int vx_debug_net;
10679 +extern unsigned int vx_debug_limit;
10680 +extern unsigned int vx_debug_cres;
10681 +extern unsigned int vx_debug_dlim;
10682 +extern unsigned int vx_debug_quota;
10683 +extern unsigned int vx_debug_cvirt;
10684 +extern unsigned int vx_debug_space;
10685 +extern unsigned int vx_debug_misc;
10686 +
10687 +
10688 +#define VX_LOGLEVEL    "vxD: "
10689 +#define VX_PROC_FMT    "%p: "
10690 +#define VX_PROCESS     current
10691 +
10692 +#define vxdprintk(c, f, x...)                                  \
10693 +       do {                                                    \
10694 +               if (c)                                          \
10695 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10696 +                               VX_PROCESS , ##x);              \
10697 +       } while (0)
10698 +
10699 +#define vxlprintk(c, f, x...)                                  \
10700 +       do {                                                    \
10701 +               if (c)                                          \
10702 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10703 +       } while (0)
10704 +
10705 +#define vxfprintk(c, f, x...)                                  \
10706 +       do {                                                    \
10707 +               if (c)                                          \
10708 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10709 +       } while (0)
10710 +
10711 +
10712 +struct vx_info;
10713 +
10714 +void dump_vx_info(struct vx_info *, int);
10715 +void dump_vx_info_inactive(int);
10716 +
10717 +#else  /* CONFIG_VSERVER_DEBUG */
10718 +
10719 +#define vx_debug_switch 0
10720 +#define vx_debug_xid   0
10721 +#define vx_debug_nid   0
10722 +#define vx_debug_tag   0
10723 +#define vx_debug_net   0
10724 +#define vx_debug_limit 0
10725 +#define vx_debug_cres  0
10726 +#define vx_debug_dlim  0
10727 +#define vx_debug_cvirt 0
10728 +
10729 +#define vxdprintk(x...) do { } while (0)
10730 +#define vxlprintk(x...) do { } while (0)
10731 +#define vxfprintk(x...) do { } while (0)
10732 +
10733 +#endif /* CONFIG_VSERVER_DEBUG */
10734 +
10735 +
10736 +#ifdef CONFIG_VSERVER_WARN
10737 +
10738 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10739 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
10740 +#define VX_WARN_XID    "[xid #%u] "
10741 +#define VX_WARN_NID    "[nid #%u] "
10742 +#define VX_WARN_TAG    "[tag #%u] "
10743 +
10744 +#define vxwprintk(c, f, x...)                                  \
10745 +       do {                                                    \
10746 +               if (c)                                          \
10747 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10748 +       } while (0)
10749 +
10750 +#else  /* CONFIG_VSERVER_WARN */
10751 +
10752 +#define vxwprintk(x...) do { } while (0)
10753 +
10754 +#endif /* CONFIG_VSERVER_WARN */
10755 +
10756 +#define vxwprintk_task(c, f, x...)                             \
10757 +       vxwprintk(c, VX_WARN_TASK f,                            \
10758 +               current->comm, current->pid,                    \
10759 +               current->xid, current->nid, current->tag, ##x)
10760 +#define vxwprintk_xid(c, f, x...)                              \
10761 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10762 +#define vxwprintk_nid(c, f, x...)                              \
10763 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10764 +#define vxwprintk_tag(c, f, x...)                              \
10765 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10766 +
10767 +#ifdef CONFIG_VSERVER_DEBUG
10768 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10769 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10770 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10771 +#else
10772 +#define vxd_assert_lock(l)     do { } while (0)
10773 +#define vxd_assert(c, f, x...) do { } while (0)
10774 +#endif
10775 +
10776 +
10777 +#endif /* _VX_DEBUG_H */
10778 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/device_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/device_cmd.h
10779 --- linux-2.6.27.3/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
10780 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/device_cmd.h      2008-10-13 14:54:20.000000000 +0200
10781 @@ -0,0 +1,44 @@
10782 +#ifndef _VX_DEVICE_CMD_H
10783 +#define _VX_DEVICE_CMD_H
10784 +
10785 +
10786 +/*  device vserver commands */
10787 +
10788 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
10789 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
10790 +
10791 +struct vcmd_set_mapping_v0 {
10792 +       const char __user *device;
10793 +       const char __user *target;
10794 +       uint32_t flags;
10795 +};
10796 +
10797 +
10798 +#ifdef __KERNEL__
10799 +
10800 +#ifdef CONFIG_COMPAT
10801 +
10802 +#include <asm/compat.h>
10803 +
10804 +struct vcmd_set_mapping_v0_x32 {
10805 +       compat_uptr_t device_ptr;
10806 +       compat_uptr_t target_ptr;
10807 +       uint32_t flags;
10808 +};
10809 +
10810 +#endif /* CONFIG_COMPAT */
10811 +
10812 +#include <linux/compiler.h>
10813 +
10814 +extern int vc_set_mapping(struct vx_info *, void __user *);
10815 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10816 +
10817 +#ifdef CONFIG_COMPAT
10818 +
10819 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10820 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10821 +
10822 +#endif /* CONFIG_COMPAT */
10823 +
10824 +#endif /* __KERNEL__ */
10825 +#endif /* _VX_DEVICE_CMD_H */
10826 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/device_def.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/device_def.h
10827 --- linux-2.6.27.3/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
10828 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/device_def.h      2008-10-13 14:54:20.000000000 +0200
10829 @@ -0,0 +1,17 @@
10830 +#ifndef _VX_DEVICE_DEF_H
10831 +#define _VX_DEVICE_DEF_H
10832 +
10833 +#include <linux/types.h>
10834 +
10835 +struct vx_dmap_target {
10836 +       dev_t target;
10837 +       uint32_t flags;
10838 +};
10839 +
10840 +struct _vx_device {
10841 +#ifdef CONFIG_VSERVER_DEVICE
10842 +       struct vx_dmap_target targets[2];
10843 +#endif
10844 +};
10845 +
10846 +#endif /* _VX_DEVICE_DEF_H */
10847 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/device.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/device.h
10848 --- linux-2.6.27.3/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
10849 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/device.h  2008-10-13 14:54:20.000000000 +0200
10850 @@ -0,0 +1,15 @@
10851 +#ifndef _VX_DEVICE_H
10852 +#define _VX_DEVICE_H
10853 +
10854 +
10855 +#define DATTR_CREATE   0x00000001
10856 +#define DATTR_OPEN     0x00000002
10857 +
10858 +#define DATTR_REMAP    0x00000010
10859 +
10860 +#define DATTR_MASK     0x00000013
10861 +
10862 +
10863 +#else  /* _VX_DEVICE_H */
10864 +#warning duplicate inclusion
10865 +#endif /* _VX_DEVICE_H */
10866 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/dlimit_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/dlimit_cmd.h
10867 --- linux-2.6.27.3/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
10868 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/dlimit_cmd.h      2008-10-13 14:54:20.000000000 +0200
10869 @@ -0,0 +1,74 @@
10870 +#ifndef _VX_DLIMIT_CMD_H
10871 +#define _VX_DLIMIT_CMD_H
10872 +
10873 +
10874 +/*  dlimit vserver commands */
10875 +
10876 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
10877 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
10878 +
10879 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
10880 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
10881 +
10882 +struct vcmd_ctx_dlimit_base_v0 {
10883 +       const char __user *name;
10884 +       uint32_t flags;
10885 +};
10886 +
10887 +struct vcmd_ctx_dlimit_v0 {
10888 +       const char __user *name;
10889 +       uint32_t space_used;                    /* used space in kbytes */
10890 +       uint32_t space_total;                   /* maximum space in kbytes */
10891 +       uint32_t inodes_used;                   /* used inodes */
10892 +       uint32_t inodes_total;                  /* maximum inodes */
10893 +       uint32_t reserved;                      /* reserved for root in % */
10894 +       uint32_t flags;
10895 +};
10896 +
10897 +#define CDLIM_UNSET            ((uint32_t)0UL)
10898 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
10899 +#define CDLIM_KEEP             ((uint32_t)~1UL)
10900 +
10901 +#ifdef __KERNEL__
10902 +
10903 +#ifdef CONFIG_COMPAT
10904 +
10905 +#include <asm/compat.h>
10906 +
10907 +struct vcmd_ctx_dlimit_base_v0_x32 {
10908 +       compat_uptr_t name_ptr;
10909 +       uint32_t flags;
10910 +};
10911 +
10912 +struct vcmd_ctx_dlimit_v0_x32 {
10913 +       compat_uptr_t name_ptr;
10914 +       uint32_t space_used;                    /* used space in kbytes */
10915 +       uint32_t space_total;                   /* maximum space in kbytes */
10916 +       uint32_t inodes_used;                   /* used inodes */
10917 +       uint32_t inodes_total;                  /* maximum inodes */
10918 +       uint32_t reserved;                      /* reserved for root in % */
10919 +       uint32_t flags;
10920 +};
10921 +
10922 +#endif /* CONFIG_COMPAT */
10923 +
10924 +#include <linux/compiler.h>
10925 +
10926 +extern int vc_add_dlimit(uint32_t, void __user *);
10927 +extern int vc_rem_dlimit(uint32_t, void __user *);
10928 +
10929 +extern int vc_set_dlimit(uint32_t, void __user *);
10930 +extern int vc_get_dlimit(uint32_t, void __user *);
10931 +
10932 +#ifdef CONFIG_COMPAT
10933 +
10934 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10935 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10936 +
10937 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10938 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10939 +
10940 +#endif /* CONFIG_COMPAT */
10941 +
10942 +#endif /* __KERNEL__ */
10943 +#endif /* _VX_DLIMIT_CMD_H */
10944 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/dlimit.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/dlimit.h
10945 --- linux-2.6.27.3/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
10946 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/dlimit.h  2008-10-13 14:54:20.000000000 +0200
10947 @@ -0,0 +1,54 @@
10948 +#ifndef _VX_DLIMIT_H
10949 +#define _VX_DLIMIT_H
10950 +
10951 +#include "switch.h"
10952 +
10953 +
10954 +#ifdef __KERNEL__
10955 +
10956 +/*      keep in sync with CDLIM_INFINITY       */
10957 +
10958 +#define DLIM_INFINITY          (~0ULL)
10959 +
10960 +#include <linux/spinlock.h>
10961 +#include <linux/rcupdate.h>
10962 +
10963 +struct super_block;
10964 +
10965 +struct dl_info {
10966 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10967 +       struct rcu_head dl_rcu;                 /* the rcu head */
10968 +       tag_t dl_tag;                           /* context tag */
10969 +       atomic_t dl_usecnt;                     /* usage count */
10970 +       atomic_t dl_refcnt;                     /* reference count */
10971 +
10972 +       struct super_block *dl_sb;              /* associated superblock */
10973 +
10974 +       spinlock_t dl_lock;                     /* protect the values */
10975 +
10976 +       unsigned long long dl_space_used;       /* used space in bytes */
10977 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10978 +       unsigned long dl_inodes_used;           /* used inodes */
10979 +       unsigned long dl_inodes_total;          /* maximum inodes */
10980 +
10981 +       unsigned int dl_nrlmult;                /* non root limit mult */
10982 +};
10983 +
10984 +struct rcu_head;
10985 +
10986 +extern void rcu_free_dl_info(struct rcu_head *);
10987 +extern void unhash_dl_info(struct dl_info *);
10988 +
10989 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
10990 +
10991 +
10992 +struct kstatfs;
10993 +
10994 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10995 +
10996 +typedef uint64_t dlsize_t;
10997 +
10998 +#endif /* __KERNEL__ */
10999 +#else  /* _VX_DLIMIT_H */
11000 +#warning duplicate inclusion
11001 +#endif /* _VX_DLIMIT_H */
11002 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/global.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/global.h
11003 --- linux-2.6.27.3/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11004 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/global.h  2008-10-13 14:54:20.000000000 +0200
11005 @@ -0,0 +1,20 @@
11006 +#ifndef _VX_GLOBAL_H
11007 +#define _VX_GLOBAL_H
11008 +
11009 +
11010 +extern atomic_t vx_global_ctotal;
11011 +extern atomic_t vx_global_cactive;
11012 +
11013 +extern atomic_t nx_global_ctotal;
11014 +extern atomic_t nx_global_cactive;
11015 +
11016 +extern atomic_t vs_global_nsproxy;
11017 +extern atomic_t vs_global_fs;
11018 +extern atomic_t vs_global_mnt_ns;
11019 +extern atomic_t vs_global_uts_ns;
11020 +extern atomic_t vs_global_ipc_ns;
11021 +extern atomic_t vs_global_user_ns;
11022 +extern atomic_t vs_global_pid_ns;
11023 +
11024 +
11025 +#endif /* _VX_GLOBAL_H */
11026 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/history.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/history.h
11027 --- linux-2.6.27.3/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11028 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/history.h 2008-10-13 14:54:20.000000000 +0200
11029 @@ -0,0 +1,197 @@
11030 +#ifndef _VX_HISTORY_H
11031 +#define _VX_HISTORY_H
11032 +
11033 +
11034 +enum {
11035 +       VXH_UNUSED = 0,
11036 +       VXH_THROW_OOPS = 1,
11037 +
11038 +       VXH_GET_VX_INFO,
11039 +       VXH_PUT_VX_INFO,
11040 +       VXH_INIT_VX_INFO,
11041 +       VXH_SET_VX_INFO,
11042 +       VXH_CLR_VX_INFO,
11043 +       VXH_CLAIM_VX_INFO,
11044 +       VXH_RELEASE_VX_INFO,
11045 +       VXH_ALLOC_VX_INFO,
11046 +       VXH_DEALLOC_VX_INFO,
11047 +       VXH_HASH_VX_INFO,
11048 +       VXH_UNHASH_VX_INFO,
11049 +       VXH_LOC_VX_INFO,
11050 +       VXH_LOOKUP_VX_INFO,
11051 +       VXH_CREATE_VX_INFO,
11052 +};
11053 +
11054 +struct _vxhe_vxi {
11055 +       struct vx_info *ptr;
11056 +       unsigned xid;
11057 +       unsigned usecnt;
11058 +       unsigned tasks;
11059 +};
11060 +
11061 +struct _vxhe_set_clr {
11062 +       void *data;
11063 +};
11064 +
11065 +struct _vxhe_loc_lookup {
11066 +       unsigned arg;
11067 +};
11068 +
11069 +struct _vx_hist_entry {
11070 +       void *loc;
11071 +       unsigned short seq;
11072 +       unsigned short type;
11073 +       struct _vxhe_vxi vxi;
11074 +       union {
11075 +               struct _vxhe_set_clr sc;
11076 +               struct _vxhe_loc_lookup ll;
11077 +       };
11078 +};
11079 +
11080 +#ifdef CONFIG_VSERVER_HISTORY
11081 +
11082 +extern unsigned volatile int vxh_active;
11083 +
11084 +struct _vx_hist_entry *vxh_advance(void *loc);
11085 +
11086 +
11087 +static inline
11088 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11089 +{
11090 +       entry->vxi.ptr = vxi;
11091 +       if (vxi) {
11092 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11093 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11094 +               entry->vxi.xid = vxi->vx_id;
11095 +       }
11096 +}
11097 +
11098 +
11099 +#define        __HERE__ current_text_addr()
11100 +
11101 +#define __VXH_BODY(__type, __data, __here)     \
11102 +       struct _vx_hist_entry *entry;           \
11103 +                                               \
11104 +       preempt_disable();                      \
11105 +       entry = vxh_advance(__here);            \
11106 +       __data;                                 \
11107 +       entry->type = __type;                   \
11108 +       preempt_enable();
11109 +
11110 +
11111 +       /* pass vxi only */
11112 +
11113 +#define __VXH_SMPL                             \
11114 +       __vxh_copy_vxi(entry, vxi)
11115 +
11116 +static inline
11117 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11118 +{
11119 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11120 +}
11121 +
11122 +       /* pass vxi and data (void *) */
11123 +
11124 +#define __VXH_DATA                             \
11125 +       __vxh_copy_vxi(entry, vxi);             \
11126 +       entry->sc.data = data
11127 +
11128 +static inline
11129 +void   __vxh_data(struct vx_info *vxi, void *data,
11130 +                       int __type, void *__here)
11131 +{
11132 +       __VXH_BODY(__type, __VXH_DATA, __here)
11133 +}
11134 +
11135 +       /* pass vxi and arg (long) */
11136 +
11137 +#define __VXH_LONG                             \
11138 +       __vxh_copy_vxi(entry, vxi);             \
11139 +       entry->ll.arg = arg
11140 +
11141 +static inline
11142 +void   __vxh_long(struct vx_info *vxi, long arg,
11143 +                       int __type, void *__here)
11144 +{
11145 +       __VXH_BODY(__type, __VXH_LONG, __here)
11146 +}
11147 +
11148 +
11149 +static inline
11150 +void   __vxh_throw_oops(void *__here)
11151 +{
11152 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11153 +       /* prevent further acquisition */
11154 +       vxh_active = 0;
11155 +}
11156 +
11157 +
11158 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11159 +
11160 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11161 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11162 +
11163 +#define __vxh_init_vx_info(v, d, h) \
11164 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11165 +#define __vxh_set_vx_info(v, d, h) \
11166 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11167 +#define __vxh_clr_vx_info(v, d, h) \
11168 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11169 +
11170 +#define __vxh_claim_vx_info(v, d, h) \
11171 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11172 +#define __vxh_release_vx_info(v, d, h) \
11173 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11174 +
11175 +#define vxh_alloc_vx_info(v) \
11176 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11177 +#define vxh_dealloc_vx_info(v) \
11178 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11179 +
11180 +#define vxh_hash_vx_info(v) \
11181 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11182 +#define vxh_unhash_vx_info(v) \
11183 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11184 +
11185 +#define vxh_loc_vx_info(v, l) \
11186 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11187 +#define vxh_lookup_vx_info(v, l) \
11188 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11189 +#define vxh_create_vx_info(v, l) \
11190 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11191 +
11192 +extern void vxh_dump_history(void);
11193 +
11194 +
11195 +#else  /* CONFIG_VSERVER_HISTORY */
11196 +
11197 +#define        __HERE__        0
11198 +
11199 +#define vxh_throw_oops()               do { } while (0)
11200 +
11201 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11202 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11203 +
11204 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11205 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11206 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11207 +
11208 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11209 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11210 +
11211 +#define vxh_alloc_vx_info(v)           do { } while (0)
11212 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11213 +
11214 +#define vxh_hash_vx_info(v)            do { } while (0)
11215 +#define vxh_unhash_vx_info(v)          do { } while (0)
11216 +
11217 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11218 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11219 +#define vxh_create_vx_info(v, l)       do { } while (0)
11220 +
11221 +#define vxh_dump_history()             do { } while (0)
11222 +
11223 +
11224 +#endif /* CONFIG_VSERVER_HISTORY */
11225 +
11226 +#endif /* _VX_HISTORY_H */
11227 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/inode_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/inode_cmd.h
11228 --- linux-2.6.27.3/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11229 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/inode_cmd.h       2008-10-13 14:54:20.000000000 +0200
11230 @@ -0,0 +1,59 @@
11231 +#ifndef _VX_INODE_CMD_H
11232 +#define _VX_INODE_CMD_H
11233 +
11234 +
11235 +/*  inode vserver commands */
11236 +
11237 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11238 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11239 +
11240 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11241 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11242 +
11243 +struct vcmd_ctx_iattr_v1 {
11244 +       const char __user *name;
11245 +       uint32_t tag;
11246 +       uint32_t flags;
11247 +       uint32_t mask;
11248 +};
11249 +
11250 +struct vcmd_ctx_fiattr_v0 {
11251 +       uint32_t tag;
11252 +       uint32_t flags;
11253 +       uint32_t mask;
11254 +};
11255 +
11256 +
11257 +#ifdef __KERNEL__
11258 +
11259 +
11260 +#ifdef CONFIG_COMPAT
11261 +
11262 +#include <asm/compat.h>
11263 +
11264 +struct vcmd_ctx_iattr_v1_x32 {
11265 +       compat_uptr_t name_ptr;
11266 +       uint32_t tag;
11267 +       uint32_t flags;
11268 +       uint32_t mask;
11269 +};
11270 +
11271 +#endif /* CONFIG_COMPAT */
11272 +
11273 +#include <linux/compiler.h>
11274 +
11275 +extern int vc_get_iattr(void __user *);
11276 +extern int vc_set_iattr(void __user *);
11277 +
11278 +extern int vc_fget_iattr(uint32_t, void __user *);
11279 +extern int vc_fset_iattr(uint32_t, void __user *);
11280 +
11281 +#ifdef CONFIG_COMPAT
11282 +
11283 +extern int vc_get_iattr_x32(void __user *);
11284 +extern int vc_set_iattr_x32(void __user *);
11285 +
11286 +#endif /* CONFIG_COMPAT */
11287 +
11288 +#endif /* __KERNEL__ */
11289 +#endif /* _VX_INODE_CMD_H */
11290 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/inode.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/inode.h
11291 --- linux-2.6.27.3/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11292 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/inode.h   2008-10-13 14:54:20.000000000 +0200
11293 @@ -0,0 +1,38 @@
11294 +#ifndef _VX_INODE_H
11295 +#define _VX_INODE_H
11296 +
11297 +
11298 +#define IATTR_TAG      0x01000000
11299 +
11300 +#define IATTR_ADMIN    0x00000001
11301 +#define IATTR_WATCH    0x00000002
11302 +#define IATTR_HIDE     0x00000004
11303 +#define IATTR_FLAGS    0x00000007
11304 +
11305 +#define IATTR_BARRIER  0x00010000
11306 +#define IATTR_IXUNLINK 0x00020000
11307 +#define IATTR_IMMUTABLE 0x00040000
11308 +
11309 +#ifdef __KERNEL__
11310 +
11311 +
11312 +#ifdef CONFIG_VSERVER_PROC_SECURE
11313 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11314 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11315 +#else
11316 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11317 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11318 +#endif
11319 +
11320 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11321 +
11322 +#endif /* __KERNEL__ */
11323 +
11324 +/* inode ioctls */
11325 +
11326 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11327 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11328 +
11329 +#else  /* _VX_INODE_H */
11330 +#warning duplicate inclusion
11331 +#endif /* _VX_INODE_H */
11332 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/Kbuild linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/Kbuild
11333 --- linux-2.6.27.3/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11334 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/Kbuild    2008-10-13 14:54:20.000000000 +0200
11335 @@ -0,0 +1,8 @@
11336 +
11337 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11338 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11339 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11340 +       debug_cmd.h device_cmd.h
11341 +
11342 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11343 +
11344 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/limit_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit_cmd.h
11345 --- linux-2.6.27.3/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11346 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit_cmd.h       2008-10-13 14:54:20.000000000 +0200
11347 @@ -0,0 +1,69 @@
11348 +#ifndef _VX_LIMIT_CMD_H
11349 +#define _VX_LIMIT_CMD_H
11350 +
11351 +
11352 +/*  rlimit vserver commands */
11353 +
11354 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11355 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11356 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11357 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11358 +
11359 +struct vcmd_ctx_rlimit_v0 {
11360 +       uint32_t id;
11361 +       uint64_t minimum;
11362 +       uint64_t softlimit;
11363 +       uint64_t maximum;
11364 +};
11365 +
11366 +struct vcmd_ctx_rlimit_mask_v0 {
11367 +       uint32_t minimum;
11368 +       uint32_t softlimit;
11369 +       uint32_t maximum;
11370 +};
11371 +
11372 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11373 +
11374 +struct vcmd_rlimit_stat_v0 {
11375 +       uint32_t id;
11376 +       uint32_t hits;
11377 +       uint64_t value;
11378 +       uint64_t minimum;
11379 +       uint64_t maximum;
11380 +};
11381 +
11382 +#define CRLIM_UNSET            (0ULL)
11383 +#define CRLIM_INFINITY         (~0ULL)
11384 +#define CRLIM_KEEP             (~1ULL)
11385 +
11386 +#ifdef __KERNEL__
11387 +
11388 +#ifdef CONFIG_IA32_EMULATION
11389 +
11390 +struct vcmd_ctx_rlimit_v0_x32 {
11391 +       uint32_t id;
11392 +       uint64_t minimum;
11393 +       uint64_t softlimit;
11394 +       uint64_t maximum;
11395 +} __attribute__ ((aligned (4)));
11396 +
11397 +#endif /* CONFIG_IA32_EMULATION */
11398 +
11399 +#include <linux/compiler.h>
11400 +
11401 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11402 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11403 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11404 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11405 +
11406 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11407 +
11408 +#ifdef CONFIG_IA32_EMULATION
11409 +
11410 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11411 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11412 +
11413 +#endif /* CONFIG_IA32_EMULATION */
11414 +
11415 +#endif /* __KERNEL__ */
11416 +#endif /* _VX_LIMIT_CMD_H */
11417 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/limit_def.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit_def.h
11418 --- linux-2.6.27.3/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
11419 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit_def.h       2008-10-13 14:54:20.000000000 +0200
11420 @@ -0,0 +1,47 @@
11421 +#ifndef _VX_LIMIT_DEF_H
11422 +#define _VX_LIMIT_DEF_H
11423 +
11424 +#include <asm/atomic.h>
11425 +#include <asm/resource.h>
11426 +
11427 +#include "limit.h"
11428 +
11429 +
11430 +struct _vx_res_limit {
11431 +       rlim_t soft;            /* Context soft limit */
11432 +       rlim_t hard;            /* Context hard limit */
11433 +
11434 +       rlim_atomic_t rcur;     /* Current value */
11435 +       rlim_t rmin;            /* Context minimum */
11436 +       rlim_t rmax;            /* Context maximum */
11437 +
11438 +       atomic_t lhit;          /* Limit hits */
11439 +};
11440 +
11441 +/* context sub struct */
11442 +
11443 +struct _vx_limit {
11444 +       struct _vx_res_limit res[NUM_LIMITS];
11445 +};
11446 +
11447 +#ifdef CONFIG_VSERVER_DEBUG
11448 +
11449 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11450 +{
11451 +       int i;
11452 +
11453 +       printk("\t_vx_limit:");
11454 +       for (i = 0; i < NUM_LIMITS; i++) {
11455 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11456 +                       i, (unsigned long)__rlim_get(limit, i),
11457 +                       (unsigned long)__rlim_rmin(limit, i),
11458 +                       (unsigned long)__rlim_rmax(limit, i),
11459 +                       (long)__rlim_soft(limit, i),
11460 +                       (long)__rlim_hard(limit, i),
11461 +                       atomic_read(&__rlim_lhit(limit, i)));
11462 +       }
11463 +}
11464 +
11465 +#endif
11466 +
11467 +#endif /* _VX_LIMIT_DEF_H */
11468 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/limit.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit.h
11469 --- linux-2.6.27.3/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
11470 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit.h   2008-10-13 14:54:20.000000000 +0200
11471 @@ -0,0 +1,70 @@
11472 +#ifndef _VX_LIMIT_H
11473 +#define _VX_LIMIT_H
11474 +
11475 +#define VLIMIT_NSOCK   16
11476 +#define VLIMIT_OPENFD  17
11477 +#define VLIMIT_ANON    18
11478 +#define VLIMIT_SHMEM   19
11479 +#define VLIMIT_SEMARY  20
11480 +#define VLIMIT_NSEMS   21
11481 +#define VLIMIT_DENTRY  22
11482 +#define VLIMIT_MAPPED  23
11483 +
11484 +
11485 +#ifdef __KERNEL__
11486 +
11487 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11488 +
11489 +/*     keep in sync with CRLIM_INFINITY */
11490 +
11491 +#define        VLIM_INFINITY   (~0ULL)
11492 +
11493 +#include <asm/atomic.h>
11494 +#include <asm/resource.h>
11495 +
11496 +#ifndef RLIM_INFINITY
11497 +#warning RLIM_INFINITY is undefined
11498 +#endif
11499 +
11500 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11501 +
11502 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11503 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11504 +
11505 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11506 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11507 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11508 +
11509 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11510 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11511 +
11512 +typedef atomic_long_t rlim_atomic_t;
11513 +typedef unsigned long rlim_t;
11514 +
11515 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11516 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11517 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11518 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11519 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11520 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11521 +
11522 +
11523 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11524 +#define        VX_VLIM(r) ((long long)(long)(r))
11525 +#define        VX_RLIM(v) ((rlim_t)(v))
11526 +#else
11527 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11528 +               ? VLIM_INFINITY : (long long)(r))
11529 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11530 +               ? RLIM_INFINITY : (rlim_t)(v))
11531 +#endif
11532 +
11533 +struct sysinfo;
11534 +
11535 +void vx_vsi_meminfo(struct sysinfo *);
11536 +void vx_vsi_swapinfo(struct sysinfo *);
11537 +
11538 +#define NUM_LIMITS     24
11539 +
11540 +#endif /* __KERNEL__ */
11541 +#endif /* _VX_LIMIT_H */
11542 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/limit_int.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit_int.h
11543 --- linux-2.6.27.3/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
11544 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/limit_int.h       2008-10-13 14:54:20.000000000 +0200
11545 @@ -0,0 +1,198 @@
11546 +#ifndef _VX_LIMIT_INT_H
11547 +#define _VX_LIMIT_INT_H
11548 +
11549 +#include "context.h"
11550 +
11551 +#ifdef __KERNEL__
11552 +
11553 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11554 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11555 +
11556 +extern const char *vlimit_name[NUM_LIMITS];
11557 +
11558 +static inline void __vx_acc_cres(struct vx_info *vxi,
11559 +       int res, int dir, void *_data, char *_file, int _line)
11560 +{
11561 +       if (VXD_RCRES_COND(res))
11562 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11563 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11564 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11565 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11566 +       if (!vxi)
11567 +               return;
11568 +
11569 +       if (dir > 0)
11570 +               __rlim_inc(&vxi->limit, res);
11571 +       else
11572 +               __rlim_dec(&vxi->limit, res);
11573 +}
11574 +
11575 +static inline void __vx_add_cres(struct vx_info *vxi,
11576 +       int res, int amount, void *_data, char *_file, int _line)
11577 +{
11578 +       if (VXD_RCRES_COND(res))
11579 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11580 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11581 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11582 +                       amount, _data, _file, _line);
11583 +       if (amount == 0)
11584 +               return;
11585 +       if (!vxi)
11586 +               return;
11587 +       __rlim_add(&vxi->limit, res, amount);
11588 +}
11589 +
11590 +static inline
11591 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11592 +{
11593 +       int cond = (value > __rlim_rmax(limit, res));
11594 +
11595 +       if (cond)
11596 +               __rlim_rmax(limit, res) = value;
11597 +       return cond;
11598 +}
11599 +
11600 +static inline
11601 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11602 +{
11603 +       int cond = (value < __rlim_rmin(limit, res));
11604 +
11605 +       if (cond)
11606 +               __rlim_rmin(limit, res) = value;
11607 +       return cond;
11608 +}
11609 +
11610 +static inline
11611 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11612 +{
11613 +       if (!__vx_cres_adjust_max(limit, res, value))
11614 +               __vx_cres_adjust_min(limit, res, value);
11615 +}
11616 +
11617 +
11618 +/*     return values:
11619 +        +1 ... no limit hit
11620 +        -1 ... over soft limit
11621 +         0 ... over hard limit         */
11622 +
11623 +static inline int __vx_cres_avail(struct vx_info *vxi,
11624 +       int res, int num, char *_file, int _line)
11625 +{
11626 +       struct _vx_limit *limit;
11627 +       rlim_t value;
11628 +
11629 +       if (VXD_RLIMIT_COND(res))
11630 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11631 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11632 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11633 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11634 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11635 +                       num, _file, _line);
11636 +       if (!vxi)
11637 +               return 1;
11638 +
11639 +       limit = &vxi->limit;
11640 +       value = __rlim_get(limit, res);
11641 +
11642 +       if (!__vx_cres_adjust_max(limit, res, value))
11643 +               __vx_cres_adjust_min(limit, res, value);
11644 +
11645 +       if (num == 0)
11646 +               return 1;
11647 +
11648 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11649 +               return -1;
11650 +       if (value + num <= __rlim_soft(limit, res))
11651 +               return -1;
11652 +
11653 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11654 +               return 1;
11655 +       if (value + num <= __rlim_hard(limit, res))
11656 +               return 1;
11657 +
11658 +       __rlim_hit(limit, res);
11659 +       return 0;
11660 +}
11661 +
11662 +
11663 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11664 +
11665 +static inline
11666 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11667 +{
11668 +       rlim_t value, sum = 0;
11669 +       int res;
11670 +
11671 +       while ((res = *array++)) {
11672 +               value = __rlim_get(limit, res);
11673 +               __vx_cres_fixup(limit, res, value);
11674 +               sum += value;
11675 +       }
11676 +       return sum;
11677 +}
11678 +
11679 +static inline
11680 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11681 +{
11682 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11683 +       int res = *array;
11684 +
11685 +       if (value == __rlim_get(limit, res))
11686 +               return value;
11687 +
11688 +       __rlim_set(limit, res, value);
11689 +       /* now adjust min/max */
11690 +       if (!__vx_cres_adjust_max(limit, res, value))
11691 +               __vx_cres_adjust_min(limit, res, value);
11692 +
11693 +       return value;
11694 +}
11695 +
11696 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11697 +       const int *array, int num, char *_file, int _line)
11698 +{
11699 +       struct _vx_limit *limit;
11700 +       rlim_t value = 0;
11701 +       int res;
11702 +
11703 +       if (num == 0)
11704 +               return 1;
11705 +       if (!vxi)
11706 +               return 1;
11707 +
11708 +       limit = &vxi->limit;
11709 +       res = *array;
11710 +       value = __vx_cres_array_sum(limit, array + 1);
11711 +
11712 +       __rlim_set(limit, res, value);
11713 +       __vx_cres_fixup(limit, res, value);
11714 +
11715 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11716 +}
11717 +
11718 +
11719 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11720 +{
11721 +       rlim_t value;
11722 +       int res;
11723 +
11724 +       /* complex resources first */
11725 +       if ((id < 0) || (id == RLIMIT_RSS))
11726 +               __vx_cres_array_fixup(limit, VLA_RSS);
11727 +
11728 +       for (res = 0; res < NUM_LIMITS; res++) {
11729 +               if ((id > 0) && (res != id))
11730 +                       continue;
11731 +
11732 +               value = __rlim_get(limit, res);
11733 +               __vx_cres_fixup(limit, res, value);
11734 +
11735 +               /* not supposed to happen, maybe warn? */
11736 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11737 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11738 +       }
11739 +}
11740 +
11741 +
11742 +#endif /* __KERNEL__ */
11743 +#endif /* _VX_LIMIT_INT_H */
11744 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/monitor.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/monitor.h
11745 --- linux-2.6.27.3/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
11746 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/monitor.h 2008-10-13 14:54:20.000000000 +0200
11747 @@ -0,0 +1,96 @@
11748 +#ifndef _VX_MONITOR_H
11749 +#define _VX_MONITOR_H
11750 +
11751 +#include <linux/types.h>
11752 +
11753 +enum {
11754 +       VXM_UNUSED = 0,
11755 +
11756 +       VXM_SYNC = 0x10,
11757 +
11758 +       VXM_UPDATE = 0x20,
11759 +       VXM_UPDATE_1,
11760 +       VXM_UPDATE_2,
11761 +
11762 +       VXM_RQINFO_1 = 0x24,
11763 +       VXM_RQINFO_2,
11764 +
11765 +       VXM_ACTIVATE = 0x40,
11766 +       VXM_DEACTIVATE,
11767 +       VXM_IDLE,
11768 +
11769 +       VXM_HOLD = 0x44,
11770 +       VXM_UNHOLD,
11771 +
11772 +       VXM_MIGRATE = 0x48,
11773 +       VXM_RESCHED,
11774 +
11775 +       /* all other bits are flags */
11776 +       VXM_SCHED = 0x80,
11777 +};
11778 +
11779 +struct _vxm_update_1 {
11780 +       uint32_t tokens_max;
11781 +       uint32_t fill_rate;
11782 +       uint32_t interval;
11783 +};
11784 +
11785 +struct _vxm_update_2 {
11786 +       uint32_t tokens_min;
11787 +       uint32_t fill_rate;
11788 +       uint32_t interval;
11789 +};
11790 +
11791 +struct _vxm_rqinfo_1 {
11792 +       uint16_t running;
11793 +       uint16_t onhold;
11794 +       uint16_t iowait;
11795 +       uint16_t uintr;
11796 +       uint32_t idle_tokens;
11797 +};
11798 +
11799 +struct _vxm_rqinfo_2 {
11800 +       uint32_t norm_time;
11801 +       uint32_t idle_time;
11802 +       uint32_t idle_skip;
11803 +};
11804 +
11805 +struct _vxm_sched {
11806 +       uint32_t tokens;
11807 +       uint32_t norm_time;
11808 +       uint32_t idle_time;
11809 +};
11810 +
11811 +struct _vxm_task {
11812 +       uint16_t pid;
11813 +       uint16_t state;
11814 +};
11815 +
11816 +struct _vxm_event {
11817 +       uint32_t jif;
11818 +       union {
11819 +               uint32_t seq;
11820 +               uint32_t sec;
11821 +       };
11822 +       union {
11823 +               uint32_t tokens;
11824 +               uint32_t nsec;
11825 +               struct _vxm_task tsk;
11826 +       };
11827 +};
11828 +
11829 +struct _vx_mon_entry {
11830 +       uint16_t type;
11831 +       uint16_t xid;
11832 +       union {
11833 +               struct _vxm_event ev;
11834 +               struct _vxm_sched sd;
11835 +               struct _vxm_update_1 u1;
11836 +               struct _vxm_update_2 u2;
11837 +               struct _vxm_rqinfo_1 q1;
11838 +               struct _vxm_rqinfo_2 q2;
11839 +       };
11840 +};
11841 +
11842 +
11843 +#endif /* _VX_MONITOR_H */
11844 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/network_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/network_cmd.h
11845 --- linux-2.6.27.3/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
11846 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/network_cmd.h     2008-10-13 14:54:20.000000000 +0200
11847 @@ -0,0 +1,150 @@
11848 +#ifndef _VX_NETWORK_CMD_H
11849 +#define _VX_NETWORK_CMD_H
11850 +
11851 +
11852 +/* vinfo commands */
11853 +
11854 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
11855 +
11856 +#ifdef __KERNEL__
11857 +extern int vc_task_nid(uint32_t);
11858 +
11859 +#endif /* __KERNEL__ */
11860 +
11861 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
11862 +
11863 +struct vcmd_nx_info_v0 {
11864 +       uint32_t nid;
11865 +       /* more to come */
11866 +};
11867 +
11868 +#ifdef __KERNEL__
11869 +extern int vc_nx_info(struct nx_info *, void __user *);
11870 +
11871 +#endif /* __KERNEL__ */
11872 +
11873 +#include <linux/in.h>
11874 +#include <linux/in6.h>
11875 +
11876 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
11877 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
11878 +
11879 +struct  vcmd_net_create {
11880 +       uint64_t flagword;
11881 +};
11882 +
11883 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
11884 +
11885 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
11886 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
11887 +
11888 +struct vcmd_net_addr_v0 {
11889 +       uint16_t type;
11890 +       uint16_t count;
11891 +       struct in_addr ip[4];
11892 +       struct in_addr mask[4];
11893 +};
11894 +
11895 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
11896 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
11897 +
11898 +struct vcmd_net_addr_ipv4_v1 {
11899 +       uint16_t type;
11900 +       uint16_t flags;
11901 +       struct in_addr ip;
11902 +       struct in_addr mask;
11903 +};
11904 +
11905 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
11906 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
11907 +
11908 +struct vcmd_net_addr_ipv6_v1 {
11909 +       uint16_t type;
11910 +       uint16_t flags;
11911 +       uint32_t prefix;
11912 +       struct in6_addr ip;
11913 +       struct in6_addr mask;
11914 +};
11915 +
11916 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
11917 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
11918 +
11919 +struct vcmd_match_ipv4_v0 {
11920 +       uint16_t type;
11921 +       uint16_t flags;
11922 +       uint16_t parent;
11923 +       uint16_t prefix;
11924 +       struct in_addr ip;
11925 +       struct in_addr ip2;
11926 +       struct in_addr mask;
11927 +};
11928 +
11929 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
11930 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
11931 +
11932 +struct vcmd_match_ipv6_v0 {
11933 +       uint16_t type;
11934 +       uint16_t flags;
11935 +       uint16_t parent;
11936 +       uint16_t prefix;
11937 +       struct in6_addr ip;
11938 +       struct in6_addr ip2;
11939 +       struct in6_addr mask;
11940 +};
11941 +
11942 +
11943 +#ifdef __KERNEL__
11944 +extern int vc_net_create(uint32_t, void __user *);
11945 +extern int vc_net_migrate(struct nx_info *, void __user *);
11946 +
11947 +extern int vc_net_add(struct nx_info *, void __user *);
11948 +extern int vc_net_remove(struct nx_info *, void __user *);
11949 +
11950 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11951 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
11952 +
11953 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11954 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11955 +
11956 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11957 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11958 +
11959 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11960 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11961 +
11962 +#endif /* __KERNEL__ */
11963 +
11964 +
11965 +/* flag commands */
11966 +
11967 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
11968 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
11969 +
11970 +struct vcmd_net_flags_v0 {
11971 +       uint64_t flagword;
11972 +       uint64_t mask;
11973 +};
11974 +
11975 +#ifdef __KERNEL__
11976 +extern int vc_get_nflags(struct nx_info *, void __user *);
11977 +extern int vc_set_nflags(struct nx_info *, void __user *);
11978 +
11979 +#endif /* __KERNEL__ */
11980 +
11981 +
11982 +/* network caps commands */
11983 +
11984 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
11985 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
11986 +
11987 +struct vcmd_net_caps_v0 {
11988 +       uint64_t ncaps;
11989 +       uint64_t cmask;
11990 +};
11991 +
11992 +#ifdef __KERNEL__
11993 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11994 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11995 +
11996 +#endif /* __KERNEL__ */
11997 +#endif /* _VX_CONTEXT_CMD_H */
11998 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/network.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/network.h
11999 --- linux-2.6.27.3/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12000 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/network.h 2008-10-13 14:54:20.000000000 +0200
12001 @@ -0,0 +1,146 @@
12002 +#ifndef _VX_NETWORK_H
12003 +#define _VX_NETWORK_H
12004 +
12005 +#include <linux/types.h>
12006 +
12007 +
12008 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12009 +
12010 +
12011 +/* network flags */
12012 +
12013 +#define NXF_INFO_PRIVATE       0x00000008
12014 +
12015 +#define NXF_SINGLE_IP          0x00000100
12016 +#define NXF_LBACK_REMAP                0x00000200
12017 +#define NXF_LBACK_ALLOW                0x00000400
12018 +
12019 +#define NXF_HIDE_NETIF         0x02000000
12020 +#define NXF_HIDE_LBACK         0x04000000
12021 +
12022 +#define NXF_STATE_SETUP                (1ULL << 32)
12023 +#define NXF_STATE_ADMIN                (1ULL << 34)
12024 +
12025 +#define NXF_SC_HELPER          (1ULL << 36)
12026 +#define NXF_PERSISTENT         (1ULL << 38)
12027 +
12028 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12029 +
12030 +
12031 +#define        NXF_INIT_SET            (__nxf_init_set())
12032 +
12033 +static inline uint64_t __nxf_init_set(void) {
12034 +       return    NXF_STATE_ADMIN
12035 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12036 +               | NXF_LBACK_REMAP
12037 +               | NXF_HIDE_LBACK
12038 +#endif
12039 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12040 +               | NXF_SINGLE_IP
12041 +#endif
12042 +               | NXF_HIDE_NETIF;
12043 +}
12044 +
12045 +
12046 +/* network caps */
12047 +
12048 +#define NXC_TUN_CREATE         0x00000001
12049 +
12050 +#define NXC_RAW_ICMP           0x00000100
12051 +
12052 +
12053 +/* address types */
12054 +
12055 +#define NXA_TYPE_IPV4          0x0001
12056 +#define NXA_TYPE_IPV6          0x0002
12057 +
12058 +#define NXA_TYPE_NONE          0x0000
12059 +#define NXA_TYPE_ANY           0x00FF
12060 +
12061 +#define NXA_TYPE_ADDR          0x0010
12062 +#define NXA_TYPE_MASK          0x0020
12063 +#define NXA_TYPE_RANGE         0x0040
12064 +
12065 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12066 +
12067 +#define NXA_MOD_BCAST          0x0100
12068 +#define NXA_MOD_LBACK          0x0200
12069 +
12070 +#define NXA_LOOPBACK           0x1000
12071 +
12072 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12073 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12074 +
12075 +#ifdef __KERNEL__
12076 +
12077 +#include <linux/list.h>
12078 +#include <linux/spinlock.h>
12079 +#include <linux/rcupdate.h>
12080 +#include <linux/in.h>
12081 +#include <linux/in6.h>
12082 +#include <asm/atomic.h>
12083 +
12084 +struct nx_addr_v4 {
12085 +       struct nx_addr_v4 *next;
12086 +       struct in_addr ip[2];
12087 +       struct in_addr mask;
12088 +       uint16_t type;
12089 +       uint16_t flags;
12090 +};
12091 +
12092 +struct nx_addr_v6 {
12093 +       struct nx_addr_v6 *next;
12094 +       struct in6_addr ip;
12095 +       struct in6_addr mask;
12096 +       uint32_t prefix;
12097 +       uint16_t type;
12098 +       uint16_t flags;
12099 +};
12100 +
12101 +struct nx_info {
12102 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12103 +       nid_t nx_id;                    /* vnet id */
12104 +       atomic_t nx_usecnt;             /* usage count */
12105 +       atomic_t nx_tasks;              /* tasks count */
12106 +       int nx_state;                   /* context state */
12107 +
12108 +       uint64_t nx_flags;              /* network flag word */
12109 +       uint64_t nx_ncaps;              /* network capabilities */
12110 +
12111 +       struct in_addr v4_lback;        /* Loopback address */
12112 +       struct in_addr v4_bcast;        /* Broadcast address */
12113 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12114 +#ifdef CONFIG_IPV6
12115 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12116 +#endif
12117 +       char nx_name[65];               /* network context name */
12118 +};
12119 +
12120 +
12121 +/* status flags */
12122 +
12123 +#define NXS_HASHED      0x0001
12124 +#define NXS_SHUTDOWN    0x0100
12125 +#define NXS_RELEASED    0x8000
12126 +
12127 +extern struct nx_info *lookup_nx_info(int);
12128 +
12129 +extern int get_nid_list(int, unsigned int *, int);
12130 +extern int nid_is_hashed(nid_t);
12131 +
12132 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12133 +
12134 +extern long vs_net_change(struct nx_info *, unsigned int);
12135 +
12136 +struct sock;
12137 +
12138 +
12139 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12140 +#ifdef  CONFIG_IPV6
12141 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12142 +#else
12143 +#define NX_IPV6(n)     (0)
12144 +#endif
12145 +
12146 +#endif /* __KERNEL__ */
12147 +#endif /* _VX_NETWORK_H */
12148 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/percpu.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/percpu.h
12149 --- linux-2.6.27.3/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12150 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/percpu.h  2008-10-13 14:54:20.000000000 +0200
12151 @@ -0,0 +1,14 @@
12152 +#ifndef _VX_PERCPU_H
12153 +#define _VX_PERCPU_H
12154 +
12155 +#include "cvirt_def.h"
12156 +#include "sched_def.h"
12157 +
12158 +struct _vx_percpu {
12159 +       struct _vx_cvirt_pc cvirt;
12160 +       struct _vx_sched_pc sched;
12161 +};
12162 +
12163 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12164 +
12165 +#endif /* _VX_PERCPU_H */
12166 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/pid.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/pid.h
12167 --- linux-2.6.27.3/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12168 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/pid.h     2008-10-13 14:54:20.000000000 +0200
12169 @@ -0,0 +1,51 @@
12170 +#ifndef _VSERVER_PID_H
12171 +#define _VSERVER_PID_H
12172 +
12173 +/* pid faking stuff */
12174 +
12175 +#define vx_info_map_pid(v, p) \
12176 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12177 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12178 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12179 +#define vx_map_tgid(p) vx_map_pid(p)
12180 +
12181 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12182 +       const char *func, const char *file, int line)
12183 +{
12184 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12185 +               vxfprintk(VXD_CBIT(cvirt, 2),
12186 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12187 +                       vxi, (long long)vxi->vx_flags, pid,
12188 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12189 +                       func, file, line);
12190 +               if (pid == 0)
12191 +                       return 0;
12192 +               if (pid == vxi->vx_initpid)
12193 +                       return 1;
12194 +       }
12195 +       return pid;
12196 +}
12197 +
12198 +#define vx_info_rmap_pid(v, p) \
12199 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12200 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12201 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12202 +
12203 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12204 +       const char *func, const char *file, int line)
12205 +{
12206 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12207 +               vxfprintk(VXD_CBIT(cvirt, 2),
12208 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12209 +                       vxi, (long long)vxi->vx_flags, pid,
12210 +                       (pid == 1) ? vxi->vx_initpid : pid,
12211 +                       func, file, line);
12212 +               if ((pid == 1) && vxi->vx_initpid)
12213 +                       return vxi->vx_initpid;
12214 +               if (pid == vxi->vx_initpid)
12215 +                       return ~0U;
12216 +       }
12217 +       return pid;
12218 +}
12219 +
12220 +#endif
12221 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/sched_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/sched_cmd.h
12222 --- linux-2.6.27.3/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12223 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/sched_cmd.h       2008-10-13 14:54:20.000000000 +0200
12224 @@ -0,0 +1,108 @@
12225 +#ifndef _VX_SCHED_CMD_H
12226 +#define _VX_SCHED_CMD_H
12227 +
12228 +
12229 +/*  sched vserver commands */
12230 +
12231 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12232 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12233 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12234 +
12235 +struct vcmd_set_sched_v2 {
12236 +       int32_t fill_rate;
12237 +       int32_t interval;
12238 +       int32_t tokens;
12239 +       int32_t tokens_min;
12240 +       int32_t tokens_max;
12241 +       uint64_t cpu_mask;
12242 +};
12243 +
12244 +struct vcmd_set_sched_v3 {
12245 +       uint32_t set_mask;
12246 +       int32_t fill_rate;
12247 +       int32_t interval;
12248 +       int32_t tokens;
12249 +       int32_t tokens_min;
12250 +       int32_t tokens_max;
12251 +       int32_t priority_bias;
12252 +};
12253 +
12254 +struct vcmd_set_sched_v4 {
12255 +       uint32_t set_mask;
12256 +       int32_t fill_rate;
12257 +       int32_t interval;
12258 +       int32_t tokens;
12259 +       int32_t tokens_min;
12260 +       int32_t tokens_max;
12261 +       int32_t prio_bias;
12262 +       int32_t cpu_id;
12263 +       int32_t bucket_id;
12264 +};
12265 +
12266 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12267 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12268 +
12269 +struct vcmd_sched_v5 {
12270 +       uint32_t mask;
12271 +       int32_t cpu_id;
12272 +       int32_t bucket_id;
12273 +       int32_t fill_rate[2];
12274 +       int32_t interval[2];
12275 +       int32_t tokens;
12276 +       int32_t tokens_min;
12277 +       int32_t tokens_max;
12278 +       int32_t prio_bias;
12279 +};
12280 +
12281 +#define VXSM_FILL_RATE         0x0001
12282 +#define VXSM_INTERVAL          0x0002
12283 +#define VXSM_FILL_RATE2                0x0004
12284 +#define VXSM_INTERVAL2         0x0008
12285 +#define VXSM_TOKENS            0x0010
12286 +#define VXSM_TOKENS_MIN                0x0020
12287 +#define VXSM_TOKENS_MAX                0x0040
12288 +#define VXSM_PRIO_BIAS         0x0100
12289 +
12290 +#define VXSM_IDLE_TIME         0x0200
12291 +#define VXSM_FORCE             0x0400
12292 +
12293 +#define        VXSM_V3_MASK            0x0173
12294 +#define        VXSM_SET_MASK           0x01FF
12295 +
12296 +#define VXSM_CPU_ID            0x1000
12297 +#define VXSM_BUCKET_ID         0x2000
12298 +
12299 +#define VXSM_MSEC              0x4000
12300 +
12301 +#define SCHED_KEEP             (-2)    /* only for v2 */
12302 +
12303 +#ifdef __KERNEL__
12304 +
12305 +#include <linux/compiler.h>
12306 +
12307 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12308 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12309 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12310 +extern int vc_set_sched(struct vx_info *, void __user *);
12311 +extern int vc_get_sched(struct vx_info *, void __user *);
12312 +
12313 +#endif /* __KERNEL__ */
12314 +
12315 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12316 +
12317 +struct vcmd_sched_info {
12318 +       int32_t cpu_id;
12319 +       int32_t bucket_id;
12320 +       uint64_t user_msec;
12321 +       uint64_t sys_msec;
12322 +       uint64_t hold_msec;
12323 +       uint32_t token_usec;
12324 +       int32_t vavavoom;
12325 +};
12326 +
12327 +#ifdef __KERNEL__
12328 +
12329 +extern int vc_sched_info(struct vx_info *, void __user *);
12330 +
12331 +#endif /* __KERNEL__ */
12332 +#endif /* _VX_SCHED_CMD_H */
12333 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/sched_def.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/sched_def.h
12334 --- linux-2.6.27.3/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12335 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/sched_def.h       2008-10-13 14:54:20.000000000 +0200
12336 @@ -0,0 +1,68 @@
12337 +#ifndef _VX_SCHED_DEF_H
12338 +#define _VX_SCHED_DEF_H
12339 +
12340 +#include <linux/spinlock.h>
12341 +#include <linux/jiffies.h>
12342 +#include <linux/cpumask.h>
12343 +#include <asm/atomic.h>
12344 +#include <asm/param.h>
12345 +
12346 +
12347 +/* context sub struct */
12348 +
12349 +struct _vx_sched {
12350 +       spinlock_t tokens_lock;         /* lock for token bucket */
12351 +
12352 +       int tokens;                     /* number of CPU tokens */
12353 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12354 +       int interval[2];                /* Divisor:   per Y jiffies   */
12355 +       int tokens_min;                 /* Limit:     minimum for unhold */
12356 +       int tokens_max;                 /* Limit:     no more than N tokens */
12357 +
12358 +       int prio_bias;                  /* bias offset for priority */
12359 +
12360 +       unsigned update_mask;           /* which features should be updated */
12361 +       cpumask_t update;               /* CPUs which should update */
12362 +};
12363 +
12364 +struct _vx_sched_pc {
12365 +       int tokens;                     /* number of CPU tokens */
12366 +       int flags;                      /* bucket flags */
12367 +
12368 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12369 +       int interval[2];                /* Divisor:   per Y jiffies   */
12370 +       int tokens_min;                 /* Limit:     minimum for unhold */
12371 +       int tokens_max;                 /* Limit:     no more than N tokens */
12372 +
12373 +       int prio_bias;                  /* bias offset for priority */
12374 +       int vavavoom;                   /* last calculated vavavoom */
12375 +
12376 +       unsigned long norm_time;        /* last time accounted */
12377 +       unsigned long idle_time;        /* non linear time for fair sched */
12378 +       unsigned long token_time;       /* token time for accounting */
12379 +       unsigned long onhold;           /* jiffies when put on hold */
12380 +
12381 +       uint64_t user_ticks;            /* token tick events */
12382 +       uint64_t sys_ticks;             /* token tick events */
12383 +       uint64_t hold_ticks;            /* token ticks paused */
12384 +};
12385 +
12386 +
12387 +#define VXSF_ONHOLD    0x0001
12388 +#define VXSF_IDLE_TIME 0x0100
12389 +
12390 +#ifdef CONFIG_VSERVER_DEBUG
12391 +
12392 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12393 +{
12394 +       printk("\t_vx_sched:\n");
12395 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12396 +               sched->fill_rate[0], sched->interval[0],
12397 +               sched->fill_rate[1], sched->interval[1],
12398 +               sched->tokens_min, sched->tokens_max);
12399 +       printk("\t priority = %4d\n", sched->prio_bias);
12400 +}
12401 +
12402 +#endif
12403 +
12404 +#endif /* _VX_SCHED_DEF_H */
12405 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/sched.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/sched.h
12406 --- linux-2.6.27.3/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
12407 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/sched.h   2008-10-13 14:54:20.000000000 +0200
12408 @@ -0,0 +1,26 @@
12409 +#ifndef _VX_SCHED_H
12410 +#define _VX_SCHED_H
12411 +
12412 +
12413 +#ifdef __KERNEL__
12414 +
12415 +struct timespec;
12416 +
12417 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12418 +
12419 +
12420 +struct vx_info;
12421 +
12422 +void vx_update_load(struct vx_info *);
12423 +
12424 +
12425 +int vx_tokens_recalc(struct _vx_sched_pc *,
12426 +       unsigned long *, unsigned long *, int [2]);
12427 +
12428 +void vx_update_sched_param(struct _vx_sched *sched,
12429 +       struct _vx_sched_pc *sched_pc);
12430 +
12431 +#endif /* __KERNEL__ */
12432 +#else  /* _VX_SCHED_H */
12433 +#warning duplicate inclusion
12434 +#endif /* _VX_SCHED_H */
12435 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/signal_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/signal_cmd.h
12436 --- linux-2.6.27.3/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
12437 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/signal_cmd.h      2008-10-13 14:54:20.000000000 +0200
12438 @@ -0,0 +1,43 @@
12439 +#ifndef _VX_SIGNAL_CMD_H
12440 +#define _VX_SIGNAL_CMD_H
12441 +
12442 +
12443 +/*  signalling vserver commands */
12444 +
12445 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12446 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12447 +
12448 +struct vcmd_ctx_kill_v0 {
12449 +       int32_t pid;
12450 +       int32_t sig;
12451 +};
12452 +
12453 +struct vcmd_wait_exit_v0 {
12454 +       int32_t reboot_cmd;
12455 +       int32_t exit_code;
12456 +};
12457 +
12458 +#ifdef __KERNEL__
12459 +
12460 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12461 +extern int vc_wait_exit(struct vx_info *, void __user *);
12462 +
12463 +#endif /* __KERNEL__ */
12464 +
12465 +/*  process alteration commands */
12466 +
12467 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12468 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12469 +
12470 +struct vcmd_pflags_v0 {
12471 +       uint32_t flagword;
12472 +       uint32_t mask;
12473 +};
12474 +
12475 +#ifdef __KERNEL__
12476 +
12477 +extern int vc_get_pflags(uint32_t pid, void __user *);
12478 +extern int vc_set_pflags(uint32_t pid, void __user *);
12479 +
12480 +#endif /* __KERNEL__ */
12481 +#endif /* _VX_SIGNAL_CMD_H */
12482 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/signal.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/signal.h
12483 --- linux-2.6.27.3/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
12484 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/signal.h  2008-10-13 14:54:20.000000000 +0200
12485 @@ -0,0 +1,14 @@
12486 +#ifndef _VX_SIGNAL_H
12487 +#define _VX_SIGNAL_H
12488 +
12489 +
12490 +#ifdef __KERNEL__
12491 +
12492 +struct vx_info;
12493 +
12494 +int vx_info_kill(struct vx_info *, int, int);
12495 +
12496 +#endif /* __KERNEL__ */
12497 +#else  /* _VX_SIGNAL_H */
12498 +#warning duplicate inclusion
12499 +#endif /* _VX_SIGNAL_H */
12500 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/space_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/space_cmd.h
12501 --- linux-2.6.27.3/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
12502 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/space_cmd.h       2008-10-13 14:54:20.000000000 +0200
12503 @@ -0,0 +1,29 @@
12504 +#ifndef _VX_SPACE_CMD_H
12505 +#define _VX_SPACE_CMD_H
12506 +
12507 +
12508 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12509 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
12510 +
12511 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12512 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
12513 +
12514 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12515 +
12516 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12517 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12518 +
12519 +
12520 +struct vcmd_space_mask {
12521 +       uint64_t mask;
12522 +};
12523 +
12524 +
12525 +#ifdef __KERNEL__
12526 +
12527 +extern int vc_enter_space(struct vx_info *, void __user *);
12528 +extern int vc_set_space(struct vx_info *, void __user *);
12529 +extern int vc_get_space_mask(void __user *, int);
12530 +
12531 +#endif /* __KERNEL__ */
12532 +#endif /* _VX_SPACE_CMD_H */
12533 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/space.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/space.h
12534 --- linux-2.6.27.3/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
12535 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/space.h   2008-10-13 14:54:20.000000000 +0200
12536 @@ -0,0 +1,13 @@
12537 +#ifndef _VX_SPACE_H
12538 +#define _VX_SPACE_H
12539 +
12540 +
12541 +#include <linux/types.h>
12542 +
12543 +struct vx_info;
12544 +
12545 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
12546 +
12547 +#else  /* _VX_SPACE_H */
12548 +#warning duplicate inclusion
12549 +#endif /* _VX_SPACE_H */
12550 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/switch.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/switch.h
12551 --- linux-2.6.27.3/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
12552 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/switch.h  2008-10-13 14:54:20.000000000 +0200
12553 @@ -0,0 +1,100 @@
12554 +#ifndef _VX_SWITCH_H
12555 +#define _VX_SWITCH_H
12556 +
12557 +#include <linux/types.h>
12558 +
12559 +
12560 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12561 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12562 +#define VC_VERSION(c)          ((c) & 0xFFF)
12563 +
12564 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12565 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12566 +
12567 +/*
12568 +
12569 +  Syscall Matrix V2.8
12570 +
12571 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12572 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12573 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12574 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12575 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12576 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12577 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12578 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12579 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12580 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12581 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12582 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12583 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12584 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12585 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12586 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12587 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12588 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12589 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12590 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12591 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12592 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12593 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12594 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12595 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12596 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12597 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12598 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12599 +
12600 +*/
12601 +
12602 +#define VC_CAT_VERSION         0
12603 +
12604 +#define VC_CAT_VSETUP          1
12605 +#define VC_CAT_VHOST           2
12606 +
12607 +#define VC_CAT_DEVICE          6
12608 +
12609 +#define VC_CAT_VPROC           9
12610 +#define VC_CAT_PROCALT         10
12611 +#define VC_CAT_PROCMIG         11
12612 +#define VC_CAT_PROCTRL         12
12613 +
12614 +#define VC_CAT_SCHED           14
12615 +#define VC_CAT_MEMCTRL         20
12616 +
12617 +#define VC_CAT_VNET            25
12618 +#define VC_CAT_NETALT          26
12619 +#define VC_CAT_NETMIG          27
12620 +#define VC_CAT_NETCTRL         28
12621 +
12622 +#define VC_CAT_TAGMIG          35
12623 +#define VC_CAT_DLIMIT          36
12624 +#define VC_CAT_INODE           38
12625 +
12626 +#define VC_CAT_VSTAT           40
12627 +#define VC_CAT_VINFO           46
12628 +#define VC_CAT_EVENT           48
12629 +
12630 +#define VC_CAT_FLAGS           52
12631 +#define VC_CAT_VSPACE          54
12632 +#define VC_CAT_DEBUG           56
12633 +#define VC_CAT_RLIMIT          60
12634 +
12635 +#define VC_CAT_SYSTEST         61
12636 +#define VC_CAT_COMPAT          63
12637 +
12638 +/*  query version */
12639 +
12640 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12641 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12642 +
12643 +
12644 +#ifdef __KERNEL__
12645 +
12646 +#include <linux/errno.h>
12647 +
12648 +
12649 +#else  /* __KERNEL__ */
12650 +#define __user
12651 +#endif /* __KERNEL__ */
12652 +
12653 +#endif /* _VX_SWITCH_H */
12654 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/tag_cmd.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/tag_cmd.h
12655 --- linux-2.6.27.3/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
12656 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/tag_cmd.h 2008-10-13 14:54:20.000000000 +0200
12657 @@ -0,0 +1,22 @@
12658 +#ifndef _VX_TAG_CMD_H
12659 +#define _VX_TAG_CMD_H
12660 +
12661 +
12662 +/* vinfo commands */
12663 +
12664 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12665 +
12666 +#ifdef __KERNEL__
12667 +extern int vc_task_tag(uint32_t);
12668 +
12669 +#endif /* __KERNEL__ */
12670 +
12671 +/* context commands */
12672 +
12673 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12674 +
12675 +#ifdef __KERNEL__
12676 +extern int vc_tag_migrate(uint32_t);
12677 +
12678 +#endif /* __KERNEL__ */
12679 +#endif /* _VX_TAG_CMD_H */
12680 diff -NurpP --minimal linux-2.6.27.3/include/linux/vserver/tag.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/tag.h
12681 --- linux-2.6.27.3/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
12682 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vserver/tag.h     2008-10-24 03:34:52.000000000 +0200
12683 @@ -0,0 +1,143 @@
12684 +#ifndef _DX_TAG_H
12685 +#define _DX_TAG_H
12686 +
12687 +#include <linux/types.h>
12688 +
12689 +
12690 +#define DX_TAG(in)     (IS_TAGGED(in))
12691 +
12692 +
12693 +#ifdef CONFIG_TAG_NFSD
12694 +#define DX_TAG_NFSD    1
12695 +#else
12696 +#define DX_TAG_NFSD    0
12697 +#endif
12698 +
12699 +
12700 +#ifdef CONFIG_TAGGING_NONE
12701 +
12702 +#define MAX_UID                0xFFFFFFFF
12703 +#define MAX_GID                0xFFFFFFFF
12704 +
12705 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12706 +
12707 +#define TAGINO_UID(cond, uid, tag)     (uid)
12708 +#define TAGINO_GID(cond, gid, tag)     (gid)
12709 +
12710 +#endif
12711 +
12712 +
12713 +#ifdef CONFIG_TAGGING_GID16
12714 +
12715 +#define MAX_UID                0xFFFFFFFF
12716 +#define MAX_GID                0x0000FFFF
12717 +
12718 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12719 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12720 +
12721 +#define TAGINO_UID(cond, uid, tag)     (uid)
12722 +#define TAGINO_GID(cond, gid, tag)     \
12723 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12724 +
12725 +#endif
12726 +
12727 +
12728 +#ifdef CONFIG_TAGGING_ID24
12729 +
12730 +#define MAX_UID                0x00FFFFFF
12731 +#define MAX_GID                0x00FFFFFF
12732 +
12733 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12734 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12735 +
12736 +#define TAGINO_UID(cond, uid, tag)     \
12737 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12738 +#define TAGINO_GID(cond, gid, tag)     \
12739 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12740 +
12741 +#endif
12742 +
12743 +
12744 +#ifdef CONFIG_TAGGING_UID16
12745 +
12746 +#define MAX_UID                0x0000FFFF
12747 +#define MAX_GID                0xFFFFFFFF
12748 +
12749 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12750 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12751 +
12752 +#define TAGINO_UID(cond, uid, tag)     \
12753 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12754 +#define TAGINO_GID(cond, gid, tag)     (gid)
12755 +
12756 +#endif
12757 +
12758 +
12759 +#ifdef CONFIG_TAGGING_INTERN
12760 +
12761 +#define MAX_UID                0xFFFFFFFF
12762 +#define MAX_GID                0xFFFFFFFF
12763 +
12764 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12765 +       ((cond) ? (tag) : 0)
12766 +
12767 +#define TAGINO_UID(cond, uid, tag)     (uid)
12768 +#define TAGINO_GID(cond, gid, tag)     (gid)
12769 +
12770 +#endif
12771 +
12772 +
12773 +#ifndef CONFIG_TAGGING_NONE
12774 +#define dx_current_fstag(sb)   \
12775 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12776 +#else
12777 +#define dx_current_fstag(sb)   (0)
12778 +#endif
12779 +
12780 +#ifndef CONFIG_TAGGING_INTERN
12781 +#define TAGINO_TAG(cond, tag)  (0)
12782 +#else
12783 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12784 +#endif
12785 +
12786 +#define INOTAG_UID(cond, uid, gid)     \
12787 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12788 +#define INOTAG_GID(cond, uid, gid)     \
12789 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12790 +
12791 +
12792 +static inline uid_t dx_map_uid(uid_t uid)
12793 +{
12794 +       if ((uid > MAX_UID) && (uid != -1))
12795 +               uid = -2;
12796 +       return (uid & MAX_UID);
12797 +}
12798 +
12799 +static inline gid_t dx_map_gid(gid_t gid)
12800 +{
12801 +       if ((gid > MAX_GID) && (gid != -1))
12802 +               gid = -2;
12803 +       return (gid & MAX_GID);
12804 +}
12805 +
12806 +struct peer_tag {
12807 +       int32_t xid;
12808 +       int32_t nid;
12809 +};
12810 +
12811 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12812 +
12813 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12814 +                unsigned long *flags);
12815 +
12816 +#ifdef CONFIG_PROPAGATE
12817 +
12818 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12819 +
12820 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12821 +
12822 +#else
12823 +#define dx_propagate_tag(n, i) do { } while (0)
12824 +#endif
12825 +
12826 +#endif /* _DX_TAG_H */
12827 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_inet6.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_inet6.h
12828 --- linux-2.6.27.3/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
12829 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_inet6.h        2008-10-13 14:54:20.000000000 +0200
12830 @@ -0,0 +1,229 @@
12831 +#ifndef _VS_INET6_H
12832 +#define _VS_INET6_H
12833 +
12834 +#include "vserver/base.h"
12835 +#include "vserver/network.h"
12836 +#include "vserver/debug.h"
12837 +
12838 +#include <net/ipv6.h>
12839 +
12840 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
12841 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
12842 +
12843 +
12844 +#ifdef CONFIG_IPV6
12845 +
12846 +static inline
12847 +int v6_addr_match(struct nx_addr_v6 *nxa,
12848 +       const struct in6_addr *addr, uint16_t mask)
12849 +{
12850 +       switch (nxa->type & mask) {
12851 +       case NXA_TYPE_MASK:
12852 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
12853 +       case NXA_TYPE_ADDR:
12854 +               return ipv6_addr_equal(&nxa->ip, addr);
12855 +       case NXA_TYPE_ANY:
12856 +               return 1;
12857 +       default:
12858 +               return 0;
12859 +       }
12860 +}
12861 +
12862 +static inline
12863 +int v6_addr_in_nx_info(struct nx_info *nxi,
12864 +       const struct in6_addr *addr, uint16_t mask)
12865 +{
12866 +       struct nx_addr_v6 *nxa;
12867 +
12868 +       if (!nxi)
12869 +               return 1;
12870 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
12871 +               if (v6_addr_match(nxa, addr, mask))
12872 +                       return 1;
12873 +       return 0;
12874 +}
12875 +
12876 +static inline
12877 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
12878 +{
12879 +       /* FIXME: needs full range checks */
12880 +       return v6_addr_match(nxa, &addr->ip, mask);
12881 +}
12882 +
12883 +static inline
12884 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
12885 +{
12886 +       struct nx_addr_v6 *ptr;
12887 +
12888 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
12889 +               if (v6_nx_addr_match(ptr, nxa, mask))
12890 +                       return 1;
12891 +       return 0;
12892 +}
12893 +
12894 +
12895 +/*
12896 + *     Check if a given address matches for a socket
12897 + *
12898 + *     nxi:            the socket's nx_info if any
12899 + *     addr:           to be verified address
12900 + */
12901 +static inline
12902 +int v6_sock_addr_match (
12903 +       struct nx_info *nxi,
12904 +       struct inet_sock *inet,
12905 +       struct in6_addr *addr)
12906 +{
12907 +       struct sock *sk = &inet->sk;
12908 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12909 +
12910 +       if (!ipv6_addr_any(addr) &&
12911 +               ipv6_addr_equal(saddr, addr))
12912 +               return 1;
12913 +       if (ipv6_addr_any(saddr))
12914 +               return v6_addr_in_nx_info(nxi, addr, -1);
12915 +       return 0;
12916 +}
12917 +
12918 +/*
12919 + *     check if address is covered by socket
12920 + *
12921 + *     sk:     the socket to check against
12922 + *     addr:   the address in question (must be != 0)
12923 + */
12924 +
12925 +static inline
12926 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
12927 +{
12928 +       struct nx_info *nxi = sk->sk_nx_info;
12929 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12930 +
12931 +       vxdprintk(VXD_CBIT(net, 5),
12932 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
12933 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
12934 +               (sk->sk_socket?sk->sk_socket->flags:0));
12935 +
12936 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
12937 +               return v6_addr_match(nxa, saddr, -1);
12938 +       } else if (nxi) {               /* match against nx_info */
12939 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
12940 +       } else {                        /* unrestricted any socket */
12941 +               return 1;
12942 +       }
12943 +}
12944 +
12945 +
12946 +/* inet related checks and helpers */
12947 +
12948 +
12949 +struct in_ifaddr;
12950 +struct net_device;
12951 +struct sock;
12952 +
12953 +
12954 +#include <linux/netdevice.h>
12955 +#include <linux/inetdevice.h>
12956 +#include <net/inet_timewait_sock.h>
12957 +
12958 +
12959 +int dev_in_nx_info(struct net_device *, struct nx_info *);
12960 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
12961 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
12962 +
12963 +
12964 +
12965 +static inline
12966 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
12967 +{
12968 +       if (!nxi)
12969 +               return 1;
12970 +       if (!ifa)
12971 +               return 0;
12972 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
12973 +}
12974 +
12975 +static inline
12976 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
12977 +{
12978 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12979 +               return 1;
12980 +       if (v6_ifa_in_nx_info(ifa, nxi))
12981 +               return 1;
12982 +       return 0;
12983 +}
12984 +
12985 +
12986 +struct nx_v6_sock_addr {
12987 +       struct in6_addr saddr;  /* Address used for validation */
12988 +       struct in6_addr baddr;  /* Address used for socket bind */
12989 +};
12990 +
12991 +static inline
12992 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
12993 +       struct nx_v6_sock_addr *nsa)
12994 +{
12995 +       // struct sock *sk = &inet->sk;
12996 +       // struct nx_info *nxi = sk->sk_nx_info;
12997 +       struct in6_addr saddr = addr->sin6_addr;
12998 +       struct in6_addr baddr = saddr;
12999 +
13000 +       nsa->saddr = saddr;
13001 +       nsa->baddr = baddr;
13002 +       return 0;
13003 +}
13004 +
13005 +static inline
13006 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13007 +{
13008 +       // struct sock *sk = &inet->sk;
13009 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13010 +
13011 +       // *saddr = nsa->baddr;
13012 +       // inet->saddr = nsa->baddr;
13013 +}
13014 +
13015 +static inline
13016 +int nx_info_has_v6(struct nx_info *nxi)
13017 +{
13018 +       if (!nxi)
13019 +               return 1;
13020 +       if (NX_IPV6(nxi))
13021 +               return 1;
13022 +       return 0;
13023 +}
13024 +
13025 +#else /* CONFIG_IPV6 */
13026 +
13027 +static inline
13028 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13029 +{
13030 +       return 1;
13031 +}
13032 +
13033 +
13034 +static inline
13035 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13036 +{
13037 +       return 1;
13038 +}
13039 +
13040 +static inline
13041 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13042 +{
13043 +       return 1;
13044 +}
13045 +
13046 +static inline
13047 +int nx_info_has_v6(struct nx_info *nxi)
13048 +{
13049 +       return 0;
13050 +}
13051 +
13052 +#endif /* CONFIG_IPV6 */
13053 +
13054 +#define current_nx_info_has_v6() \
13055 +       nx_info_has_v6(current_nx_info())
13056 +
13057 +#else
13058 +#warning duplicate inclusion
13059 +#endif
13060 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_inet.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_inet.h
13061 --- linux-2.6.27.3/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13062 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_inet.h 2008-10-13 14:54:20.000000000 +0200
13063 @@ -0,0 +1,342 @@
13064 +#ifndef _VS_INET_H
13065 +#define _VS_INET_H
13066 +
13067 +#include "vserver/base.h"
13068 +#include "vserver/network.h"
13069 +#include "vserver/debug.h"
13070 +
13071 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13072 +
13073 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13074 +                       NIPQUAD((a)->mask), (a)->type
13075 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13076 +
13077 +
13078 +static inline
13079 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13080 +{
13081 +       __be32 ip = nxa->ip[0].s_addr;
13082 +       __be32 mask = nxa->mask.s_addr;
13083 +       __be32 bcast = ip | ~mask;
13084 +       int ret = 0;
13085 +
13086 +       switch (nxa->type & tmask) {
13087 +       case NXA_TYPE_MASK:
13088 +               ret = (ip == (addr & mask));
13089 +               break;
13090 +       case NXA_TYPE_ADDR:
13091 +               ret = 3;
13092 +               if (addr == ip)
13093 +                       break;
13094 +               /* fall through to broadcast */
13095 +       case NXA_MOD_BCAST:
13096 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13097 +               break;
13098 +       case NXA_TYPE_RANGE:
13099 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13100 +                       (nxa->ip[1].s_addr > addr));
13101 +               break;
13102 +       case NXA_TYPE_ANY:
13103 +               ret = 2;
13104 +               break;
13105 +       }
13106 +
13107 +       vxdprintk(VXD_CBIT(net, 0),
13108 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13109 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13110 +       return ret;
13111 +}
13112 +
13113 +static inline
13114 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13115 +{
13116 +       struct nx_addr_v4 *nxa;
13117 +       int ret = 1;
13118 +
13119 +       if (!nxi)
13120 +               goto out;
13121 +
13122 +       ret = 2;
13123 +       /* allow 127.0.0.1 when remapping lback */
13124 +       if ((tmask & NXA_LOOPBACK) &&
13125 +               (addr == IPI_LOOPBACK) &&
13126 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13127 +               goto out;
13128 +       ret = 3;
13129 +       /* check for lback address */
13130 +       if ((tmask & NXA_MOD_LBACK) &&
13131 +               (nxi->v4_lback.s_addr == addr))
13132 +               goto out;
13133 +       ret = 4;
13134 +       /* check for broadcast address */
13135 +       if ((tmask & NXA_MOD_BCAST) &&
13136 +               (nxi->v4_bcast.s_addr == addr))
13137 +               goto out;
13138 +       ret = 5;
13139 +       /* check for v4 addresses */
13140 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13141 +               if (v4_addr_match(nxa, addr, tmask))
13142 +                       goto out;
13143 +       ret = 0;
13144 +out:
13145 +       vxdprintk(VXD_CBIT(net, 0),
13146 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13147 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13148 +       return ret;
13149 +}
13150 +
13151 +static inline
13152 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13153 +{
13154 +       /* FIXME: needs full range checks */
13155 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13156 +}
13157 +
13158 +static inline
13159 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13160 +{
13161 +       struct nx_addr_v4 *ptr;
13162 +
13163 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13164 +               if (v4_nx_addr_match(ptr, nxa, mask))
13165 +                       return 1;
13166 +       return 0;
13167 +}
13168 +
13169 +#include <net/inet_sock.h>
13170 +
13171 +/*
13172 + *     Check if a given address matches for a socket
13173 + *
13174 + *     nxi:            the socket's nx_info if any
13175 + *     addr:           to be verified address
13176 + */
13177 +static inline
13178 +int v4_sock_addr_match (
13179 +       struct nx_info *nxi,
13180 +       struct inet_sock *inet,
13181 +       __be32 addr)
13182 +{
13183 +       __be32 saddr = inet->rcv_saddr;
13184 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13185 +
13186 +       if (addr && (saddr == addr || bcast == addr))
13187 +               return 1;
13188 +       if (!saddr)
13189 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13190 +       return 0;
13191 +}
13192 +
13193 +
13194 +/* inet related checks and helpers */
13195 +
13196 +
13197 +struct in_ifaddr;
13198 +struct net_device;
13199 +struct sock;
13200 +
13201 +#ifdef CONFIG_INET
13202 +
13203 +#include <linux/netdevice.h>
13204 +#include <linux/inetdevice.h>
13205 +#include <net/inet_sock.h>
13206 +#include <net/inet_timewait_sock.h>
13207 +
13208 +
13209 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13210 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13211 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13212 +
13213 +
13214 +/*
13215 + *     check if address is covered by socket
13216 + *
13217 + *     sk:     the socket to check against
13218 + *     addr:   the address in question (must be != 0)
13219 + */
13220 +
13221 +static inline
13222 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13223 +{
13224 +       struct nx_info *nxi = sk->sk_nx_info;
13225 +       __be32 saddr = inet_rcv_saddr(sk);
13226 +
13227 +       vxdprintk(VXD_CBIT(net, 5),
13228 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13229 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13230 +               (sk->sk_socket?sk->sk_socket->flags:0));
13231 +
13232 +       if (saddr) {            /* direct address match */
13233 +               return v4_addr_match(nxa, saddr, -1);
13234 +       } else if (nxi) {       /* match against nx_info */
13235 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13236 +       } else {                /* unrestricted any socket */
13237 +               return 1;
13238 +       }
13239 +}
13240 +
13241 +
13242 +
13243 +static inline
13244 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13245 +{
13246 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13247 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13248 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13249 +
13250 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13251 +               return 1;
13252 +       if (dev_in_nx_info(dev, nxi))
13253 +               return 1;
13254 +       return 0;
13255 +}
13256 +
13257 +
13258 +static inline
13259 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13260 +{
13261 +       if (!nxi)
13262 +               return 1;
13263 +       if (!ifa)
13264 +               return 0;
13265 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13266 +}
13267 +
13268 +static inline
13269 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13270 +{
13271 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13272 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13273 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13274 +
13275 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13276 +               return 1;
13277 +       if (v4_ifa_in_nx_info(ifa, nxi))
13278 +               return 1;
13279 +       return 0;
13280 +}
13281 +
13282 +
13283 +struct nx_v4_sock_addr {
13284 +       __be32 saddr;   /* Address used for validation */
13285 +       __be32 baddr;   /* Address used for socket bind */
13286 +};
13287 +
13288 +static inline
13289 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13290 +       struct nx_v4_sock_addr *nsa)
13291 +{
13292 +       struct sock *sk = &inet->sk;
13293 +       struct nx_info *nxi = sk->sk_nx_info;
13294 +       __be32 saddr = addr->sin_addr.s_addr;
13295 +       __be32 baddr = saddr;
13296 +
13297 +       vxdprintk(VXD_CBIT(net, 3),
13298 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13299 +               sk, sk->sk_nx_info, sk->sk_socket,
13300 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13301 +               NIPQUAD(saddr));
13302 +
13303 +       if (nxi) {
13304 +               if (saddr == INADDR_ANY) {
13305 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13306 +                               baddr = nxi->v4.ip[0].s_addr;
13307 +               } else if (saddr == IPI_LOOPBACK) {
13308 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13309 +                               baddr = nxi->v4_lback.s_addr;
13310 +               } else {        /* normal address bind */
13311 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13312 +                               return -EADDRNOTAVAIL;
13313 +               }
13314 +       }
13315 +
13316 +       vxdprintk(VXD_CBIT(net, 3),
13317 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13318 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13319 +
13320 +       nsa->saddr = saddr;
13321 +       nsa->baddr = baddr;
13322 +       return 0;
13323 +}
13324 +
13325 +static inline
13326 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13327 +{
13328 +       inet->saddr = nsa->baddr;
13329 +       inet->rcv_saddr = nsa->baddr;
13330 +}
13331 +
13332 +
13333 +/*
13334 + *      helper to simplify inet_lookup_listener
13335 + *
13336 + *      nxi:   the socket's nx_info if any
13337 + *      addr:  to be verified address
13338 + *      saddr: socket address
13339 + */
13340 +static inline int v4_inet_addr_match (
13341 +       struct nx_info *nxi,
13342 +       __be32 addr,
13343 +       __be32 saddr)
13344 +{
13345 +       if (addr && (saddr == addr))
13346 +               return 1;
13347 +       if (!saddr)
13348 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13349 +       return 0;
13350 +}
13351 +
13352 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13353 +{
13354 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13355 +               (addr == nxi->v4_lback.s_addr))
13356 +               return IPI_LOOPBACK;
13357 +       return addr;
13358 +}
13359 +
13360 +static inline
13361 +int nx_info_has_v4(struct nx_info *nxi)
13362 +{
13363 +       if (!nxi)
13364 +               return 1;
13365 +       if (NX_IPV4(nxi))
13366 +               return 1;
13367 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13368 +               return 1;
13369 +       return 0;
13370 +}
13371 +
13372 +#else /* CONFIG_INET */
13373 +
13374 +static inline
13375 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13376 +{
13377 +       return 1;
13378 +}
13379 +
13380 +static inline
13381 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13382 +{
13383 +       return 1;
13384 +}
13385 +
13386 +static inline
13387 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13388 +{
13389 +       return 1;
13390 +}
13391 +
13392 +static inline
13393 +int nx_info_has_v4(struct nx_info *nxi)
13394 +{
13395 +       return 0;
13396 +}
13397 +
13398 +#endif /* CONFIG_INET */
13399 +
13400 +#define current_nx_info_has_v4() \
13401 +       nx_info_has_v4(current_nx_info())
13402 +
13403 +#else
13404 +// #warning duplicate inclusion
13405 +#endif
13406 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_limit.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_limit.h
13407 --- linux-2.6.27.3/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
13408 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_limit.h        2008-10-13 14:54:20.000000000 +0200
13409 @@ -0,0 +1,140 @@
13410 +#ifndef _VS_LIMIT_H
13411 +#define _VS_LIMIT_H
13412 +
13413 +#include "vserver/limit.h"
13414 +#include "vserver/base.h"
13415 +#include "vserver/context.h"
13416 +#include "vserver/debug.h"
13417 +#include "vserver/context.h"
13418 +#include "vserver/limit_int.h"
13419 +
13420 +
13421 +#define vx_acc_cres(v, d, p, r) \
13422 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13423 +
13424 +#define vx_acc_cres_cond(x, d, p, r) \
13425 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13426 +       r, d, p, __FILE__, __LINE__)
13427 +
13428 +
13429 +#define vx_add_cres(v, a, p, r) \
13430 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13431 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13432 +
13433 +#define vx_add_cres_cond(x, a, p, r) \
13434 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13435 +       r, a, p, __FILE__, __LINE__)
13436 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13437 +
13438 +
13439 +/* process and file limits */
13440 +
13441 +#define vx_nproc_inc(p) \
13442 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13443 +
13444 +#define vx_nproc_dec(p) \
13445 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13446 +
13447 +#define vx_files_inc(f) \
13448 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13449 +
13450 +#define vx_files_dec(f) \
13451 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13452 +
13453 +#define vx_locks_inc(l) \
13454 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13455 +
13456 +#define vx_locks_dec(l) \
13457 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13458 +
13459 +#define vx_openfd_inc(f) \
13460 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13461 +
13462 +#define vx_openfd_dec(f) \
13463 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13464 +
13465 +
13466 +#define vx_cres_avail(v, n, r) \
13467 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13468 +
13469 +
13470 +#define vx_nproc_avail(n) \
13471 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13472 +
13473 +#define vx_files_avail(n) \
13474 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13475 +
13476 +#define vx_locks_avail(n) \
13477 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13478 +
13479 +#define vx_openfd_avail(n) \
13480 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13481 +
13482 +
13483 +/* dentry limits */
13484 +
13485 +#define vx_dentry_inc(d) do {                                          \
13486 +       if (atomic_read(&d->d_count) == 1)                              \
13487 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13488 +       } while (0)
13489 +
13490 +#define vx_dentry_dec(d) do {                                          \
13491 +       if (atomic_read(&d->d_count) == 0)                              \
13492 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
13493 +       } while (0)
13494 +
13495 +#define vx_dentry_avail(n) \
13496 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
13497 +
13498 +
13499 +/* socket limits */
13500 +
13501 +#define vx_sock_inc(s) \
13502 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13503 +
13504 +#define vx_sock_dec(s) \
13505 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13506 +
13507 +#define vx_sock_avail(n) \
13508 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
13509 +
13510 +
13511 +/* ipc resource limits */
13512 +
13513 +#define vx_ipcmsg_add(v, u, a) \
13514 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13515 +
13516 +#define vx_ipcmsg_sub(v, u, a) \
13517 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13518 +
13519 +#define vx_ipcmsg_avail(v, a) \
13520 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13521 +
13522 +
13523 +#define vx_ipcshm_add(v, k, a) \
13524 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13525 +
13526 +#define vx_ipcshm_sub(v, k, a) \
13527 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13528 +
13529 +#define vx_ipcshm_avail(v, a) \
13530 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13531 +
13532 +
13533 +#define vx_semary_inc(a) \
13534 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
13535 +
13536 +#define vx_semary_dec(a) \
13537 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
13538 +
13539 +
13540 +#define vx_nsems_add(a,n) \
13541 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13542 +
13543 +#define vx_nsems_sub(a,n) \
13544 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13545 +
13546 +
13547 +#else
13548 +#warning duplicate inclusion
13549 +#endif
13550 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_memory.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_memory.h
13551 --- linux-2.6.27.3/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
13552 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_memory.h       2008-10-13 14:54:20.000000000 +0200
13553 @@ -0,0 +1,159 @@
13554 +#ifndef _VS_MEMORY_H
13555 +#define _VS_MEMORY_H
13556 +
13557 +#include "vserver/limit.h"
13558 +#include "vserver/base.h"
13559 +#include "vserver/context.h"
13560 +#include "vserver/debug.h"
13561 +#include "vserver/context.h"
13562 +#include "vserver/limit_int.h"
13563 +
13564 +
13565 +#define __acc_add_long(a, v)   (*(v) += (a))
13566 +#define __acc_inc_long(v)      (++*(v))
13567 +#define __acc_dec_long(v)      (--*(v))
13568 +
13569 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
13570 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
13571 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
13572 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
13573 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13574 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
13575 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
13576 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
13577 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13578 +
13579 +
13580 +#define vx_acc_page(m, d, v, r) do {                                   \
13581 +       if ((d) > 0)                                                    \
13582 +               __acc_inc_long(&(m)->v);                                \
13583 +       else                                                            \
13584 +               __acc_dec_long(&(m)->v);                                \
13585 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13586 +} while (0)
13587 +
13588 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
13589 +       if ((d) > 0)                                                    \
13590 +               __acc_inc_atomic(&(m)->v);                              \
13591 +       else                                                            \
13592 +               __acc_dec_atomic(&(m)->v);                              \
13593 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13594 +} while (0)
13595 +
13596 +
13597 +#define vx_acc_pages(m, p, v, r) do {                                  \
13598 +       unsigned long __p = (p);                                        \
13599 +       __acc_add_long(__p, &(m)->v);                                   \
13600 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13601 +} while (0)
13602 +
13603 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
13604 +       unsigned long __p = (p);                                        \
13605 +       __acc_add_atomic(__p, &(m)->v);                                 \
13606 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13607 +} while (0)
13608 +
13609 +
13610 +
13611 +#define vx_acc_vmpage(m, d) \
13612 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
13613 +#define vx_acc_vmlpage(m, d) \
13614 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
13615 +#define vx_acc_file_rsspage(m, d) \
13616 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
13617 +#define vx_acc_anon_rsspage(m, d) \
13618 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
13619 +
13620 +#define vx_acc_vmpages(m, p) \
13621 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
13622 +#define vx_acc_vmlpages(m, p) \
13623 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
13624 +#define vx_acc_file_rsspages(m, p) \
13625 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
13626 +#define vx_acc_anon_rsspages(m, p) \
13627 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
13628 +
13629 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
13630 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
13631 +
13632 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
13633 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
13634 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
13635 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
13636 +
13637 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
13638 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
13639 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
13640 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
13641 +
13642 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
13643 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
13644 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
13645 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
13646 +
13647 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
13648 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
13649 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
13650 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
13651 +
13652 +
13653 +#define vx_pages_avail(m, p, r) \
13654 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
13655 +
13656 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
13657 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
13658 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
13659 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
13660 +
13661 +#define vx_rss_avail(m, p) \
13662 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
13663 +
13664 +
13665 +enum {
13666 +       VXPT_UNKNOWN = 0,
13667 +       VXPT_ANON,
13668 +       VXPT_NONE,
13669 +       VXPT_FILE,
13670 +       VXPT_SWAP,
13671 +       VXPT_WRITE
13672 +};
13673 +
13674 +#if 0
13675 +#define        vx_page_fault(mm, vma, type, ret)
13676 +#else
13677 +
13678 +static inline
13679 +void __vx_page_fault(struct mm_struct *mm,
13680 +       struct vm_area_struct *vma, int type, int ret)
13681 +{
13682 +       struct vx_info *vxi = mm->mm_vx_info;
13683 +       int what;
13684 +/*
13685 +       static char *page_type[6] =
13686 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
13687 +       static char *page_what[4] =
13688 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
13689 +*/
13690 +
13691 +       if (!vxi)
13692 +               return;
13693 +
13694 +       what = (ret & 0x3);
13695 +
13696 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
13697 +               type, what, ret, page_type[type], page_what[what]);
13698 +*/
13699 +       if (ret & VM_FAULT_WRITE)
13700 +               what |= 0x4;
13701 +       atomic_inc(&vxi->cacct.page[type][what]);
13702 +}
13703 +
13704 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
13705 +#endif
13706 +
13707 +
13708 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
13709 +
13710 +#else
13711 +#warning duplicate inclusion
13712 +#endif
13713 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_network.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_network.h
13714 --- linux-2.6.27.3/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
13715 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_network.h      2008-10-13 14:54:20.000000000 +0200
13716 @@ -0,0 +1,169 @@
13717 +#ifndef _NX_VS_NETWORK_H
13718 +#define _NX_VS_NETWORK_H
13719 +
13720 +#include "vserver/context.h"
13721 +#include "vserver/network.h"
13722 +#include "vserver/base.h"
13723 +#include "vserver/check.h"
13724 +#include "vserver/debug.h"
13725 +
13726 +#include <linux/sched.h>
13727 +
13728 +
13729 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
13730 +
13731 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
13732 +       const char *_file, int _line)
13733 +{
13734 +       if (!nxi)
13735 +               return NULL;
13736 +
13737 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
13738 +               nxi, nxi ? nxi->nx_id : 0,
13739 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13740 +               _file, _line);
13741 +
13742 +       atomic_inc(&nxi->nx_usecnt);
13743 +       return nxi;
13744 +}
13745 +
13746 +
13747 +extern void free_nx_info(struct nx_info *);
13748 +
13749 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
13750 +
13751 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
13752 +{
13753 +       if (!nxi)
13754 +               return;
13755 +
13756 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
13757 +               nxi, nxi ? nxi->nx_id : 0,
13758 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13759 +               _file, _line);
13760 +
13761 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
13762 +               free_nx_info(nxi);
13763 +}
13764 +
13765 +
13766 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
13767 +
13768 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13769 +               const char *_file, int _line)
13770 +{
13771 +       if (nxi) {
13772 +               vxlprintk(VXD_CBIT(nid, 3),
13773 +                       "init_nx_info(%p[#%d.%d])",
13774 +                       nxi, nxi ? nxi->nx_id : 0,
13775 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13776 +                       _file, _line);
13777 +
13778 +               atomic_inc(&nxi->nx_usecnt);
13779 +       }
13780 +       *nxp = nxi;
13781 +}
13782 +
13783 +
13784 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
13785 +
13786 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13787 +       const char *_file, int _line)
13788 +{
13789 +       struct nx_info *nxo;
13790 +
13791 +       if (!nxi)
13792 +               return;
13793 +
13794 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
13795 +               nxi, nxi ? nxi->nx_id : 0,
13796 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13797 +               _file, _line);
13798 +
13799 +       atomic_inc(&nxi->nx_usecnt);
13800 +       nxo = xchg(nxp, nxi);
13801 +       BUG_ON(nxo);
13802 +}
13803 +
13804 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
13805 +
13806 +static inline void __clr_nx_info(struct nx_info **nxp,
13807 +       const char *_file, int _line)
13808 +{
13809 +       struct nx_info *nxo;
13810 +
13811 +       nxo = xchg(nxp, NULL);
13812 +       if (!nxo)
13813 +               return;
13814 +
13815 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
13816 +               nxo, nxo ? nxo->nx_id : 0,
13817 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
13818 +               _file, _line);
13819 +
13820 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
13821 +               free_nx_info(nxo);
13822 +}
13823 +
13824 +
13825 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
13826 +
13827 +static inline void __claim_nx_info(struct nx_info *nxi,
13828 +       struct task_struct *task, const char *_file, int _line)
13829 +{
13830 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
13831 +               nxi, nxi ? nxi->nx_id : 0,
13832 +               nxi?atomic_read(&nxi->nx_usecnt):0,
13833 +               nxi?atomic_read(&nxi->nx_tasks):0,
13834 +               task, _file, _line);
13835 +
13836 +       atomic_inc(&nxi->nx_tasks);
13837 +}
13838 +
13839 +
13840 +extern void unhash_nx_info(struct nx_info *);
13841 +
13842 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
13843 +
13844 +static inline void __release_nx_info(struct nx_info *nxi,
13845 +       struct task_struct *task, const char *_file, int _line)
13846 +{
13847 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
13848 +               nxi, nxi ? nxi->nx_id : 0,
13849 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13850 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
13851 +               task, _file, _line);
13852 +
13853 +       might_sleep();
13854 +
13855 +       if (atomic_dec_and_test(&nxi->nx_tasks))
13856 +               unhash_nx_info(nxi);
13857 +}
13858 +
13859 +
13860 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
13861 +
13862 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
13863 +       const char *_file, int _line)
13864 +{
13865 +       struct nx_info *nxi;
13866 +
13867 +       task_lock(p);
13868 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
13869 +               p, _file, _line);
13870 +       nxi = __get_nx_info(p->nx_info, _file, _line);
13871 +       task_unlock(p);
13872 +       return nxi;
13873 +}
13874 +
13875 +
13876 +static inline void exit_nx_info(struct task_struct *p)
13877 +{
13878 +       if (p->nx_info)
13879 +               release_nx_info(p->nx_info, p);
13880 +}
13881 +
13882 +
13883 +#else
13884 +#warning duplicate inclusion
13885 +#endif
13886 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_pid.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_pid.h
13887 --- linux-2.6.27.3/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
13888 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_pid.h  2008-10-13 14:54:20.000000000 +0200
13889 @@ -0,0 +1,95 @@
13890 +#ifndef _VS_PID_H
13891 +#define _VS_PID_H
13892 +
13893 +#include "vserver/base.h"
13894 +#include "vserver/check.h"
13895 +#include "vserver/context.h"
13896 +#include "vserver/debug.h"
13897 +#include "vserver/pid.h"
13898 +#include <linux/pid_namespace.h>
13899 +
13900 +
13901 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
13902 +
13903 +static inline
13904 +int vx_proc_task_visible(struct task_struct *task)
13905 +{
13906 +       if ((task->pid == 1) &&
13907 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
13908 +               /* show a blend through init */
13909 +               goto visible;
13910 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
13911 +               goto visible;
13912 +       return 0;
13913 +visible:
13914 +       return 1;
13915 +}
13916 +
13917 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
13918 +
13919 +#if 0
13920 +
13921 +static inline
13922 +struct task_struct *vx_find_proc_task_by_pid(int pid)
13923 +{
13924 +       struct task_struct *task = find_task_by_real_pid(pid);
13925 +
13926 +       if (task && !vx_proc_task_visible(task)) {
13927 +               vxdprintk(VXD_CBIT(misc, 6),
13928 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
13929 +                       task, task->xid, task->pid,
13930 +                       current, current->xid, current->pid);
13931 +               task = NULL;
13932 +       }
13933 +       return task;
13934 +}
13935 +
13936 +#endif
13937 +
13938 +static inline
13939 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
13940 +{
13941 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
13942 +
13943 +       if (task && !vx_proc_task_visible(task)) {
13944 +               vxdprintk(VXD_CBIT(misc, 6),
13945 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
13946 +                       task, task->xid, task->pid,
13947 +                       current, current->xid, current->pid);
13948 +               put_task_struct(task);
13949 +               task = NULL;
13950 +       }
13951 +       return task;
13952 +}
13953 +
13954 +#if 0
13955 +
13956 +static inline
13957 +struct task_struct *vx_child_reaper(struct task_struct *p)
13958 +{
13959 +       struct vx_info *vxi = p->vx_info;
13960 +       struct task_struct *reaper = child_reaper(p);
13961 +
13962 +       if (!vxi)
13963 +               goto out;
13964 +
13965 +       BUG_ON(!p->vx_info->vx_reaper);
13966 +
13967 +       /* child reaper for the guest reaper */
13968 +       if (vxi->vx_reaper == p)
13969 +               goto out;
13970 +
13971 +       reaper = vxi->vx_reaper;
13972 +out:
13973 +       vxdprintk(VXD_CBIT(xid, 7),
13974 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
13975 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
13976 +       return reaper;
13977 +}
13978 +
13979 +#endif
13980 +
13981 +
13982 +#else
13983 +#warning duplicate inclusion
13984 +#endif
13985 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_sched.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_sched.h
13986 --- linux-2.6.27.3/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
13987 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_sched.h        2008-10-13 14:54:20.000000000 +0200
13988 @@ -0,0 +1,110 @@
13989 +#ifndef _VS_SCHED_H
13990 +#define _VS_SCHED_H
13991 +
13992 +#include "vserver/base.h"
13993 +#include "vserver/context.h"
13994 +#include "vserver/sched.h"
13995 +
13996 +
13997 +#define VAVAVOOM_RATIO          50
13998 +
13999 +#define MAX_PRIO_BIAS           20
14000 +#define MIN_PRIO_BIAS          -20
14001 +
14002 +
14003 +#ifdef CONFIG_VSERVER_HARDCPU
14004 +
14005 +/*
14006 + * effective_prio - return the priority that is based on the static
14007 + * priority but is modified by bonuses/penalties.
14008 + *
14009 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14010 + * into a -4 ... 0 ... +4 bonus/penalty range.
14011 + *
14012 + * Additionally, we scale another amount based on the number of
14013 + * CPU tokens currently held by the context, if the process is
14014 + * part of a context (and the appropriate SCHED flag is set).
14015 + * This ranges from -5 ... 0 ... +15, quadratically.
14016 + *
14017 + * So, the total bonus is -9 .. 0 .. +19
14018 + * We use ~50% of the full 0...39 priority range so that:
14019 + *
14020 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14021 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14022 + *    unless that context is far exceeding its CPU allocation.
14023 + *
14024 + * Both properties are important to certain workloads.
14025 + */
14026 +static inline
14027 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14028 +{
14029 +       int vavavoom, max;
14030 +
14031 +       /* lots of tokens = lots of vavavoom
14032 +        *      no tokens = no vavavoom      */
14033 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14034 +               max = sched_pc->tokens_max;
14035 +               vavavoom = max - vavavoom;
14036 +               max = max * max;
14037 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14038 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14039 +               return vavavoom;
14040 +       }
14041 +       return 0;
14042 +}
14043 +
14044 +
14045 +static inline
14046 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14047 +{
14048 +       struct vx_info *vxi = p->vx_info;
14049 +       struct _vx_sched_pc *sched_pc;
14050 +
14051 +       if (!vxi)
14052 +               return prio;
14053 +
14054 +       sched_pc = &vx_cpu(vxi, sched_pc);
14055 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14056 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14057 +
14058 +               sched_pc->vavavoom = vavavoom;
14059 +               prio += vavavoom;
14060 +       }
14061 +       prio += sched_pc->prio_bias;
14062 +       return prio;
14063 +}
14064 +
14065 +#else /* !CONFIG_VSERVER_HARDCPU */
14066 +
14067 +static inline
14068 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14069 +{
14070 +       struct vx_info *vxi = p->vx_info;
14071 +
14072 +       if (vxi)
14073 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14074 +       return prio;
14075 +}
14076 +
14077 +#endif /* CONFIG_VSERVER_HARDCPU */
14078 +
14079 +
14080 +static inline void vx_account_user(struct vx_info *vxi,
14081 +       cputime_t cputime, int nice)
14082 +{
14083 +       if (!vxi)
14084 +               return;
14085 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14086 +}
14087 +
14088 +static inline void vx_account_system(struct vx_info *vxi,
14089 +       cputime_t cputime, int idle)
14090 +{
14091 +       if (!vxi)
14092 +               return;
14093 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14094 +}
14095 +
14096 +#else
14097 +#warning duplicate inclusion
14098 +#endif
14099 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_socket.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_socket.h
14100 --- linux-2.6.27.3/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14101 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_socket.h       2008-10-13 14:54:20.000000000 +0200
14102 @@ -0,0 +1,67 @@
14103 +#ifndef _VS_SOCKET_H
14104 +#define _VS_SOCKET_H
14105 +
14106 +#include "vserver/debug.h"
14107 +#include "vserver/base.h"
14108 +#include "vserver/cacct.h"
14109 +#include "vserver/context.h"
14110 +#include "vserver/tag.h"
14111 +
14112 +
14113 +/* socket accounting */
14114 +
14115 +#include <linux/socket.h>
14116 +
14117 +static inline int vx_sock_type(int family)
14118 +{
14119 +       switch (family) {
14120 +       case PF_UNSPEC:
14121 +               return VXA_SOCK_UNSPEC;
14122 +       case PF_UNIX:
14123 +               return VXA_SOCK_UNIX;
14124 +       case PF_INET:
14125 +               return VXA_SOCK_INET;
14126 +       case PF_INET6:
14127 +               return VXA_SOCK_INET6;
14128 +       case PF_PACKET:
14129 +               return VXA_SOCK_PACKET;
14130 +       default:
14131 +               return VXA_SOCK_OTHER;
14132 +       }
14133 +}
14134 +
14135 +#define vx_acc_sock(v, f, p, s) \
14136 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14137 +
14138 +static inline void __vx_acc_sock(struct vx_info *vxi,
14139 +       int family, int pos, int size, char *file, int line)
14140 +{
14141 +       if (vxi) {
14142 +               int type = vx_sock_type(family);
14143 +
14144 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14145 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14146 +       }
14147 +}
14148 +
14149 +#define vx_sock_recv(sk, s) \
14150 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14151 +#define vx_sock_send(sk, s) \
14152 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14153 +#define vx_sock_fail(sk, s) \
14154 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14155 +
14156 +
14157 +#define sock_vx_init(s) do {           \
14158 +       (s)->sk_xid = 0;                \
14159 +       (s)->sk_vx_info = NULL;         \
14160 +       } while (0)
14161 +
14162 +#define sock_nx_init(s) do {           \
14163 +       (s)->sk_nid = 0;                \
14164 +       (s)->sk_nx_info = NULL;         \
14165 +       } while (0)
14166 +
14167 +#else
14168 +#warning duplicate inclusion
14169 +#endif
14170 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_tag.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_tag.h
14171 --- linux-2.6.27.3/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14172 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_tag.h  2008-10-24 03:34:52.000000000 +0200
14173 @@ -0,0 +1,47 @@
14174 +#ifndef _VS_TAG_H
14175 +#define _VS_TAG_H
14176 +
14177 +#include <linux/vserver/tag.h>
14178 +
14179 +/* check conditions */
14180 +
14181 +#define DX_ADMIN       0x0001
14182 +#define DX_WATCH       0x0002
14183 +#define DX_HOSTID      0x0008
14184 +
14185 +#define DX_IDENT       0x0010
14186 +
14187 +#define DX_ARG_MASK    0x0010
14188 +
14189 +
14190 +#define dx_task_tag(t) ((t)->tag)
14191 +
14192 +#define dx_current_tag() dx_task_tag(current)
14193 +
14194 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14195 +
14196 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14197 +
14198 +
14199 +/*
14200 + * check current context for ADMIN/WATCH and
14201 + * optionally against supplied argument
14202 + */
14203 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14204 +{
14205 +       if (mode & DX_ARG_MASK) {
14206 +               if ((mode & DX_IDENT) && (id == cid))
14207 +                       return 1;
14208 +       }
14209 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14210 +               ((mode & DX_WATCH) && (cid == 1)) ||
14211 +               ((mode & DX_HOSTID) && (id == 0)));
14212 +}
14213 +
14214 +struct inode;
14215 +int dx_permission(struct inode *inode, int mask);
14216 +
14217 +
14218 +#else
14219 +#warning duplicate inclusion
14220 +#endif
14221 diff -NurpP --minimal linux-2.6.27.3/include/linux/vs_time.h linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_time.h
14222 --- linux-2.6.27.3/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14223 +++ linux-2.6.27.3-vs2.3.0.35.7/include/linux/vs_time.h 2008-10-13 14:54:20.000000000 +0200
14224 @@ -0,0 +1,19 @@
14225 +#ifndef _VS_TIME_H
14226 +#define _VS_TIME_H
14227 +
14228 +
14229 +/* time faking stuff */
14230 +
14231 +#ifdef CONFIG_VSERVER_VTIME
14232 +
14233 +extern void vx_gettimeofday(struct timeval *tv);
14234 +extern int vx_settimeofday(struct timespec *ts);
14235 +
14236 +#else
14237 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14238 +#define        vx_settimeofday(t)      do_settimeofday(t)
14239 +#endif
14240 +
14241 +#else
14242 +#warning duplicate inclusion
14243 +#endif
14244 diff -NurpP --minimal linux-2.6.27.3/include/net/addrconf.h linux-2.6.27.3-vs2.3.0.35.7/include/net/addrconf.h
14245 --- linux-2.6.27.3/include/net/addrconf.h       2008-10-13 14:52:09.000000000 +0200
14246 +++ linux-2.6.27.3-vs2.3.0.35.7/include/net/addrconf.h  2008-10-13 14:54:20.000000000 +0200
14247 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14248                                                struct net_device *dev,
14249                                                const struct in6_addr *daddr,
14250                                                unsigned int srcprefs,
14251 -                                              struct in6_addr *saddr);
14252 +                                              struct in6_addr *saddr,
14253 +                                              struct nx_info *nxi);
14254  extern int                     ipv6_get_lladdr(struct net_device *dev,
14255                                                 struct in6_addr *addr,
14256                                                 unsigned char banned_flags);
14257 diff -NurpP --minimal linux-2.6.27.3/include/net/af_unix.h linux-2.6.27.3-vs2.3.0.35.7/include/net/af_unix.h
14258 --- linux-2.6.27.3/include/net/af_unix.h        2008-10-13 14:52:09.000000000 +0200
14259 +++ linux-2.6.27.3-vs2.3.0.35.7/include/net/af_unix.h   2008-10-13 14:54:20.000000000 +0200
14260 @@ -4,6 +4,7 @@
14261  #include <linux/socket.h>
14262  #include <linux/un.h>
14263  #include <linux/mutex.h>
14264 +#include <linux/vs_base.h>
14265  #include <net/sock.h>
14266  
14267  extern void unix_inflight(struct file *fp);
14268 diff -NurpP --minimal linux-2.6.27.3/include/net/inet_sock.h linux-2.6.27.3-vs2.3.0.35.7/include/net/inet_sock.h
14269 --- linux-2.6.27.3/include/net/inet_sock.h      2008-10-13 14:52:09.000000000 +0200
14270 +++ linux-2.6.27.3-vs2.3.0.35.7/include/net/inet_sock.h 2008-10-13 14:54:20.000000000 +0200
14271 @@ -24,7 +24,7 @@
14272  #include <net/flow.h>
14273  #include <net/sock.h>
14274  #include <net/request_sock.h>
14275 -#include <net/route.h>
14276 +// #include <net/route.h>
14277  #include <net/netns/hash.h>
14278  
14279  /** struct ip_options - IP Options
14280 @@ -195,11 +195,6 @@ static inline int inet_sk_ehashfn(const 
14281  }
14282  
14283  
14284 -static inline int inet_iif(const struct sk_buff *skb)
14285 -{
14286 -       return skb->rtable->rt_iif;
14287 -}
14288 -
14289  static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
14290  {
14291         struct request_sock *req = reqsk_alloc(ops);
14292 diff -NurpP --minimal linux-2.6.27.3/include/net/inet_timewait_sock.h linux-2.6.27.3-vs2.3.0.35.7/include/net/inet_timewait_sock.h
14293 --- linux-2.6.27.3/include/net/inet_timewait_sock.h     2008-10-13 14:52:09.000000000 +0200
14294 +++ linux-2.6.27.3-vs2.3.0.35.7/include/net/inet_timewait_sock.h        2008-10-13 14:54:20.000000000 +0200
14295 @@ -15,15 +15,14 @@
14296  #ifndef _INET_TIMEWAIT_SOCK_
14297  #define _INET_TIMEWAIT_SOCK_
14298  
14299 +// #include <net/inet_sock.h>
14300 +#include <net/sock.h>
14301  
14302  #include <linux/list.h>
14303  #include <linux/module.h>
14304  #include <linux/timer.h>
14305  #include <linux/types.h>
14306  #include <linux/workqueue.h>
14307 -
14308 -#include <net/inet_sock.h>
14309 -#include <net/sock.h>
14310  #include <net/tcp_states.h>
14311  #include <net/timewait_sock.h>
14312  
14313 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14314  #define tw_hash                        __tw_common.skc_hash
14315  #define tw_prot                        __tw_common.skc_prot
14316  #define tw_net                 __tw_common.skc_net
14317 +#define tw_xid                 __tw_common.skc_xid
14318 +#define tw_vx_info             __tw_common.skc_vx_info
14319 +#define tw_nid                 __tw_common.skc_nid
14320 +#define tw_nx_info             __tw_common.skc_nx_info
14321         int                     tw_timeout;
14322         volatile unsigned char  tw_substate;
14323         /* 3 bits hole, try to pack */
14324 diff -NurpP --minimal linux-2.6.27.3/include/net/route.h linux-2.6.27.3-vs2.3.0.35.7/include/net/route.h
14325 --- linux-2.6.27.3/include/net/route.h  2008-10-13 14:52:09.000000000 +0200
14326 +++ linux-2.6.27.3-vs2.3.0.35.7/include/net/route.h     2008-10-13 14:54:20.000000000 +0200
14327 @@ -28,6 +28,7 @@
14328  #include <net/inetpeer.h>
14329  #include <net/flow.h>
14330  #include <net/sock.h>
14331 +// #include <linux/in.h>
14332  #include <linux/in_route.h>
14333  #include <linux/rtnetlink.h>
14334  #include <linux/route.h>
14335 @@ -85,6 +86,11 @@ struct ip_rt_acct
14336         __u32   i_packets;
14337  };
14338  
14339 +static inline int inet_iif(const struct sk_buff *skb)
14340 +{
14341 +       return skb->rtable->rt_iif;
14342 +}
14343 +
14344  struct rt_cache_stat 
14345  {
14346          unsigned int in_hit;
14347 @@ -135,6 +141,9 @@ static inline void ip_rt_put(struct rtab
14348                 dst_release(&rt->u.dst);
14349  }
14350  
14351 +#include <linux/vs_base.h>
14352 +#include <linux/vs_inet.h>
14353 +
14354  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14355  
14356  extern const __u8 ip_tos2prio[16];
14357 @@ -144,6 +153,9 @@ static inline char rt_tos2priority(u8 to
14358         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14359  }
14360  
14361 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14362 +       struct rtable **, struct flowi *);
14363 +
14364  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14365                                    __be32 src, u32 tos, int oif, u8 protocol,
14366                                    __be16 sport, __be16 dport, struct sock *sk,
14367 @@ -161,7 +173,21 @@ static inline int ip_route_connect(struc
14368  
14369         int err;
14370         struct net *net = sock_net(sk);
14371 -       if (!dst || !src) {
14372 +       struct nx_info *nx_info = current->nx_info;
14373 +
14374 +       if (sk)
14375 +               nx_info = sk->sk_nx_info;
14376 +
14377 +       vxdprintk(VXD_CBIT(net, 4),
14378 +               "ip_route_connect(%p) %p,%p;%lx",
14379 +               sk, nx_info, sk->sk_socket,
14380 +               (sk->sk_socket?sk->sk_socket->flags:0));
14381 +
14382 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14383 +       if (err)
14384 +               return err;
14385 +
14386 +       if (!fl.fl4_dst || !fl.fl4_src) {
14387                 err = __ip_route_output_key(net, rp, &fl);
14388                 if (err)
14389                         return err;
14390 diff -NurpP --minimal linux-2.6.27.3/include/net/sock.h linux-2.6.27.3-vs2.3.0.35.7/include/net/sock.h
14391 --- linux-2.6.27.3/include/net/sock.h   2008-10-13 14:52:09.000000000 +0200
14392 +++ linux-2.6.27.3-vs2.3.0.35.7/include/net/sock.h      2008-10-13 14:54:20.000000000 +0200
14393 @@ -128,6 +128,10 @@ struct sock_common {
14394  #ifdef CONFIG_NET_NS
14395         struct net              *skc_net;
14396  #endif
14397 +       xid_t                   skc_xid;
14398 +       struct vx_info          *skc_vx_info;
14399 +       nid_t                   skc_nid;
14400 +       struct nx_info          *skc_nx_info;
14401  };
14402  
14403  /**
14404 @@ -211,6 +215,10 @@ struct sock {
14405  #define sk_hash                        __sk_common.skc_hash
14406  #define sk_prot                        __sk_common.skc_prot
14407  #define sk_net                 __sk_common.skc_net
14408 +#define sk_xid                 __sk_common.skc_xid
14409 +#define sk_vx_info             __sk_common.skc_vx_info
14410 +#define sk_nid                 __sk_common.skc_nid
14411 +#define sk_nx_info             __sk_common.skc_nx_info
14412         unsigned char           sk_shutdown : 2,
14413                                 sk_no_check : 2,
14414                                 sk_userlocks : 4;
14415 diff -NurpP --minimal linux-2.6.27.3/init/main.c linux-2.6.27.3-vs2.3.0.35.7/init/main.c
14416 --- linux-2.6.27.3/init/main.c  2008-10-13 14:52:09.000000000 +0200
14417 +++ linux-2.6.27.3-vs2.3.0.35.7/init/main.c     2008-10-13 14:54:20.000000000 +0200
14418 @@ -60,6 +60,7 @@
14419  #include <linux/sched.h>
14420  #include <linux/signal.h>
14421  #include <linux/idr.h>
14422 +#include <linux/vserver/percpu.h>
14423  
14424  #include <asm/io.h>
14425  #include <asm/bugs.h>
14426 @@ -391,12 +392,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
14427  
14428  static void __init setup_per_cpu_areas(void)
14429  {
14430 -       unsigned long size, i;
14431 +       unsigned long size, vspc, i;
14432         char *ptr;
14433         unsigned long nr_possible_cpus = num_possible_cpus();
14434  
14435 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
14436 +
14437         /* Copy section for each CPU (we discard the original) */
14438 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
14439 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
14440         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
14441  
14442         for_each_possible_cpu(i) {
14443 diff -NurpP --minimal linux-2.6.27.3/ipc/mqueue.c linux-2.6.27.3-vs2.3.0.35.7/ipc/mqueue.c
14444 --- linux-2.6.27.3/ipc/mqueue.c 2008-10-13 14:52:09.000000000 +0200
14445 +++ linux-2.6.27.3-vs2.3.0.35.7/ipc/mqueue.c    2008-10-13 14:54:20.000000000 +0200
14446 @@ -31,6 +31,8 @@
14447  #include <linux/mutex.h>
14448  #include <linux/nsproxy.h>
14449  #include <linux/pid.h>
14450 +#include <linux/vs_context.h>
14451 +#include <linux/vs_limit.h>
14452  
14453  #include <net/sock.h>
14454  #include "util.h"
14455 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
14456         struct sigevent notify;
14457         struct pid* notify_owner;
14458         struct user_struct *user;       /* user who created, for accounting */
14459 +       struct vx_info *vxi;
14460         struct sock *notify_sock;
14461         struct sk_buff *notify_cookie;
14462  
14463 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
14464                         struct mqueue_inode_info *info;
14465                         struct task_struct *p = current;
14466                         struct user_struct *u = p->user;
14467 +                       struct vx_info *vxi = p->vx_info;
14468                         unsigned long mq_bytes, mq_msg_tblsz;
14469  
14470                         inode->i_fop = &mqueue_file_operations;
14471 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
14472                         info->notify_owner = NULL;
14473                         info->qsize = 0;
14474                         info->user = NULL;      /* set when all is ok */
14475 +                       info->vxi = NULL;
14476                         memset(&info->attr, 0, sizeof(info->attr));
14477                         info->attr.mq_maxmsg = DFLT_MSGMAX;
14478                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
14479 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
14480                         spin_lock(&mq_lock);
14481                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14482                             u->mq_bytes + mq_bytes >
14483 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14484 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14485 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14486                                 spin_unlock(&mq_lock);
14487                                 goto out_inode;
14488                         }
14489                         u->mq_bytes += mq_bytes;
14490 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14491                         spin_unlock(&mq_lock);
14492  
14493                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14494                         if (!info->messages) {
14495                                 spin_lock(&mq_lock);
14496                                 u->mq_bytes -= mq_bytes;
14497 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14498                                 spin_unlock(&mq_lock);
14499                                 goto out_inode;
14500                         }
14501                         /* all is ok */
14502                         info->user = get_uid(u);
14503 +                       info->vxi = get_vx_info(vxi);
14504                 } else if (S_ISDIR(mode)) {
14505                         inc_nlink(inode);
14506                         /* Some things misbehave if size == 0 on a directory */
14507 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
14508                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14509         user = info->user;
14510         if (user) {
14511 +               struct vx_info *vxi = info->vxi;
14512 +
14513                 spin_lock(&mq_lock);
14514                 user->mq_bytes -= mq_bytes;
14515 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14516                 queues_count--;
14517                 spin_unlock(&mq_lock);
14518 +               put_vx_info(vxi);
14519                 free_uid(user);
14520         }
14521  }
14522 diff -NurpP --minimal linux-2.6.27.3/ipc/msg.c linux-2.6.27.3-vs2.3.0.35.7/ipc/msg.c
14523 --- linux-2.6.27.3/ipc/msg.c    2008-07-13 23:51:29.000000000 +0200
14524 +++ linux-2.6.27.3-vs2.3.0.35.7/ipc/msg.c       2008-10-13 14:54:20.000000000 +0200
14525 @@ -38,6 +38,7 @@
14526  #include <linux/rwsem.h>
14527  #include <linux/nsproxy.h>
14528  #include <linux/ipc_namespace.h>
14529 +#include <linux/vs_base.h>
14530  
14531  #include <asm/current.h>
14532  #include <asm/uaccess.h>
14533 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14534  
14535         msq->q_perm.mode = msgflg & S_IRWXUGO;
14536         msq->q_perm.key = key;
14537 +       msq->q_perm.xid = vx_current_xid();
14538  
14539         msq->q_perm.security = NULL;
14540         retval = security_msg_queue_alloc(msq);
14541 diff -NurpP --minimal linux-2.6.27.3/ipc/namespace.c linux-2.6.27.3-vs2.3.0.35.7/ipc/namespace.c
14542 --- linux-2.6.27.3/ipc/namespace.c      2008-07-13 23:51:29.000000000 +0200
14543 +++ linux-2.6.27.3-vs2.3.0.35.7/ipc/namespace.c 2008-10-13 14:54:20.000000000 +0200
14544 @@ -9,6 +9,8 @@
14545  #include <linux/rcupdate.h>
14546  #include <linux/nsproxy.h>
14547  #include <linux/slab.h>
14548 +#include <linux/vs_base.h>
14549 +#include <linux/vserver/global.h>
14550  
14551  #include "util.h"
14552  
14553 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
14554         register_ipcns_notifier(ns);
14555  
14556         kref_init(&ns->kref);
14557 +       atomic_inc(&vs_global_ipc_ns);
14558         return ns;
14559  }
14560  
14561 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
14562         sem_exit_ns(ns);
14563         msg_exit_ns(ns);
14564         shm_exit_ns(ns);
14565 +       atomic_dec(&vs_global_ipc_ns);
14566         kfree(ns);
14567         atomic_dec(&nr_ipc_ns);
14568  
14569 diff -NurpP --minimal linux-2.6.27.3/ipc/sem.c linux-2.6.27.3-vs2.3.0.35.7/ipc/sem.c
14570 --- linux-2.6.27.3/ipc/sem.c    2008-10-13 14:52:09.000000000 +0200
14571 +++ linux-2.6.27.3-vs2.3.0.35.7/ipc/sem.c       2008-10-13 14:54:20.000000000 +0200
14572 @@ -83,6 +83,8 @@
14573  #include <linux/rwsem.h>
14574  #include <linux/nsproxy.h>
14575  #include <linux/ipc_namespace.h>
14576 +#include <linux/vs_base.h>
14577 +#include <linux/vs_limit.h>
14578  
14579  #include <asm/uaccess.h>
14580  #include "util.h"
14581 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
14582  
14583         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14584         sma->sem_perm.key = key;
14585 +       sma->sem_perm.xid = vx_current_xid();
14586  
14587         sma->sem_perm.security = NULL;
14588         retval = security_sem_alloc(sma);
14589 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
14590                 return id;
14591         }
14592         ns->used_sems += nsems;
14593 +       /* FIXME: obsoleted? */
14594 +       vx_semary_inc(sma);
14595 +       vx_nsems_add(sma, nsems);
14596  
14597         sma->sem_base = (struct sem *) &sma[1];
14598         INIT_LIST_HEAD(&sma->sem_pending);
14599 diff -NurpP --minimal linux-2.6.27.3/ipc/shm.c linux-2.6.27.3-vs2.3.0.35.7/ipc/shm.c
14600 --- linux-2.6.27.3/ipc/shm.c    2008-10-13 14:52:09.000000000 +0200
14601 +++ linux-2.6.27.3-vs2.3.0.35.7/ipc/shm.c       2008-10-13 14:54:20.000000000 +0200
14602 @@ -39,6 +39,8 @@
14603  #include <linux/nsproxy.h>
14604  #include <linux/mount.h>
14605  #include <linux/ipc_namespace.h>
14606 +#include <linux/vs_context.h>
14607 +#include <linux/vs_limit.h>
14608  
14609  #include <asm/uaccess.h>
14610  
14611 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
14612   */
14613  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14614  {
14615 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14616 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14617 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14618 +
14619 +       vx_ipcshm_sub(vxi, shp, numpages);
14620 +       ns->shm_tot -= numpages;
14621 +
14622         shm_rmid(ns, shp);
14623         shm_unlock(shp);
14624         if (!is_file_hugepages(shp->shm_file))
14625 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
14626                                                 shp->mlock_user);
14627         fput (shp->shm_file);
14628         security_shm_free(shp);
14629 +       put_vx_info(vxi);
14630         ipc_rcu_putref(shp);
14631  }
14632  
14633 @@ -347,11 +355,15 @@ static int newseg(struct ipc_namespace *
14634         if (ns->shm_tot + numpages > ns->shm_ctlall)
14635                 return -ENOSPC;
14636  
14637 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
14638 +               return -ENOSPC;
14639 +
14640         shp = ipc_rcu_alloc(sizeof(*shp));
14641         if (!shp)
14642                 return -ENOMEM;
14643  
14644         shp->shm_perm.key = key;
14645 +       shp->shm_perm.xid = vx_current_xid();
14646         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14647         shp->mlock_user = NULL;
14648  
14649 @@ -404,6 +416,7 @@ static int newseg(struct ipc_namespace *
14650         ns->shm_tot += numpages;
14651         error = shp->shm_perm.id;
14652         shm_unlock(shp);
14653 +       vx_ipcshm_add(current->vx_info, key, numpages);
14654         return error;
14655  
14656  no_id:
14657 diff -NurpP --minimal linux-2.6.27.3/kernel/capability.c linux-2.6.27.3-vs2.3.0.35.7/kernel/capability.c
14658 --- linux-2.6.27.3/kernel/capability.c  2008-10-13 14:52:09.000000000 +0200
14659 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/capability.c     2008-10-13 14:54:20.000000000 +0200
14660 @@ -13,6 +13,7 @@
14661  #include <linux/security.h>
14662  #include <linux/syscalls.h>
14663  #include <linux/pid_namespace.h>
14664 +#include <linux/vs_context.h>
14665  #include <asm/uaccess.h>
14666  
14667  /*
14668 @@ -166,6 +167,8 @@ static inline int cap_set_pg(int pgrp_nr
14669  
14670         pgrp = find_vpid(pgrp_nr);
14671         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
14672 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
14673 +                       continue;
14674                 target = g;
14675                 while_each_thread(g, target) {
14676                         if (!security_capset_check(target, effective,
14677 @@ -486,6 +489,8 @@ asmlinkage long sys_capset(cap_user_head
14678         return ret;
14679  }
14680  
14681 +#include <linux/vserver/base.h>
14682 +
14683  /**
14684   * capable - Determine if the current task has a superior capability in effect
14685   * @cap: The capability to be tested for
14686 @@ -498,6 +503,9 @@ asmlinkage long sys_capset(cap_user_head
14687   */
14688  int capable(int cap)
14689  {
14690 +       /* here for now so we don't require task locking */
14691 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14692 +               return 0;
14693         if (has_capability(current, cap)) {
14694                 current->flags |= PF_SUPERPRIV;
14695                 return 1;
14696 diff -NurpP --minimal linux-2.6.27.3/kernel/compat.c linux-2.6.27.3-vs2.3.0.35.7/kernel/compat.c
14697 --- linux-2.6.27.3/kernel/compat.c      2008-07-13 23:51:29.000000000 +0200
14698 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/compat.c 2008-10-13 14:54:20.000000000 +0200
14699 @@ -845,7 +845,7 @@ asmlinkage long compat_sys_time(compat_t
14700         compat_time_t i;
14701         struct timeval tv;
14702  
14703 -       do_gettimeofday(&tv);
14704 +       vx_gettimeofday(&tv);
14705         i = tv.tv_sec;
14706  
14707         if (tloc) {
14708 @@ -869,7 +869,7 @@ asmlinkage long compat_sys_stime(compat_
14709         if (err)
14710                 return err;
14711  
14712 -       do_settimeofday(&tv);
14713 +       vx_settimeofday(&tv);
14714         return 0;
14715  }
14716  
14717 diff -NurpP --minimal linux-2.6.27.3/kernel/exit.c linux-2.6.27.3-vs2.3.0.35.7/kernel/exit.c
14718 --- linux-2.6.27.3/kernel/exit.c        2008-10-13 14:52:09.000000000 +0200
14719 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/exit.c   2008-10-13 14:54:20.000000000 +0200
14720 @@ -47,6 +47,11 @@
14721  #include <linux/blkdev.h>
14722  #include <linux/task_io_accounting_ops.h>
14723  #include <linux/tracehook.h>
14724 +#include <linux/vs_limit.h>
14725 +#include <linux/vs_context.h>
14726 +#include <linux/vs_network.h>
14727 +#include <linux/vs_pid.h>
14728 +#include <linux/vserver/global.h>
14729  
14730  #include <asm/uaccess.h>
14731  #include <asm/unistd.h>
14732 @@ -485,9 +490,11 @@ static void close_files(struct files_str
14733                                         filp_close(file, files);
14734                                         cond_resched();
14735                                 }
14736 +                               vx_openfd_dec(i);
14737                         }
14738                         i++;
14739                         set >>= 1;
14740 +                       cond_resched();
14741                 }
14742         }
14743  }
14744 @@ -554,6 +561,7 @@ void put_fs_struct(struct fs_struct *fs)
14745         if (atomic_dec_and_test(&fs->count)) {
14746                 path_put(&fs->root);
14747                 path_put(&fs->pwd);
14748 +               atomic_dec(&vs_global_fs);
14749                 kmem_cache_free(fs_cachep, fs);
14750         }
14751  }
14752 @@ -1122,6 +1130,10 @@ NORET_TYPE void do_exit(long code)
14753         if (tsk->splice_pipe)
14754                 __free_pipe_info(tsk->splice_pipe);
14755  
14756 +       /* needs to stay after exit_notify() */
14757 +       exit_vx_info(tsk, code);
14758 +       exit_nx_info(tsk);
14759 +
14760         preempt_disable();
14761         /* causes final put_task_struct in finish_task_switch(). */
14762         tsk->state = TASK_DEAD;
14763 diff -NurpP --minimal linux-2.6.27.3/kernel/fork.c linux-2.6.27.3-vs2.3.0.35.7/kernel/fork.c
14764 --- linux-2.6.27.3/kernel/fork.c        2008-10-13 14:52:09.000000000 +0200
14765 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/fork.c   2008-10-13 14:54:20.000000000 +0200
14766 @@ -58,6 +58,11 @@
14767  #include <linux/tty.h>
14768  #include <linux/proc_fs.h>
14769  #include <linux/blkdev.h>
14770 +#include <linux/vs_context.h>
14771 +#include <linux/vs_network.h>
14772 +#include <linux/vs_limit.h>
14773 +#include <linux/vs_memory.h>
14774 +#include <linux/vserver/global.h>
14775  
14776  #include <asm/pgtable.h>
14777  #include <asm/pgalloc.h>
14778 @@ -135,6 +140,8 @@ void free_task(struct task_struct *tsk)
14779         prop_local_destroy_single(&tsk->dirties);
14780         free_thread_info(tsk->stack);
14781         rt_mutex_debug_task_free(tsk);
14782 +       clr_vx_info(&tsk->vx_info);
14783 +       clr_nx_info(&tsk->nx_info);
14784         free_task_struct(tsk);
14785  }
14786  EXPORT_SYMBOL(free_task);
14787 @@ -274,6 +281,8 @@ static int dup_mmap(struct mm_struct *mm
14788         mm->free_area_cache = oldmm->mmap_base;
14789         mm->cached_hole_size = ~0UL;
14790         mm->map_count = 0;
14791 +       __set_mm_counter(mm, file_rss, 0);
14792 +       __set_mm_counter(mm, anon_rss, 0);
14793         cpus_clear(mm->cpu_vm_mask);
14794         mm->mm_rb = RB_ROOT;
14795         rb_link = &mm->mm_rb.rb_node;
14796 @@ -285,7 +294,7 @@ static int dup_mmap(struct mm_struct *mm
14797  
14798                 if (mpnt->vm_flags & VM_DONTCOPY) {
14799                         long pages = vma_pages(mpnt);
14800 -                       mm->total_vm -= pages;
14801 +                       vx_vmpages_sub(mm, pages);
14802                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
14803                                                                 -pages);
14804                         continue;
14805 @@ -404,8 +413,8 @@ static struct mm_struct * mm_init(struct
14806                                   : MMF_DUMP_FILTER_DEFAULT;
14807         mm->core_state = NULL;
14808         mm->nr_ptes = 0;
14809 -       set_mm_counter(mm, file_rss, 0);
14810 -       set_mm_counter(mm, anon_rss, 0);
14811 +       __set_mm_counter(mm, file_rss, 0);
14812 +       __set_mm_counter(mm, anon_rss, 0);
14813         spin_lock_init(&mm->page_table_lock);
14814         rwlock_init(&mm->ioctx_list_lock);
14815         mm->ioctx_list = NULL;
14816 @@ -416,6 +425,7 @@ static struct mm_struct * mm_init(struct
14817         if (likely(!mm_alloc_pgd(mm))) {
14818                 mm->def_flags = 0;
14819                 mmu_notifier_mm_init(mm);
14820 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14821                 return mm;
14822         }
14823  
14824 @@ -449,6 +459,7 @@ void __mmdrop(struct mm_struct *mm)
14825         mm_free_pgd(mm);
14826         destroy_context(mm);
14827         mmu_notifier_mm_destroy(mm);
14828 +       clr_vx_info(&mm->mm_vx_info);
14829         free_mm(mm);
14830  }
14831  EXPORT_SYMBOL_GPL(__mmdrop);
14832 @@ -565,6 +576,7 @@ struct mm_struct *dup_mm(struct task_str
14833                 goto fail_nomem;
14834  
14835         memcpy(mm, oldmm, sizeof(*mm));
14836 +       mm->mm_vx_info = NULL;
14837  
14838         /* Initializing for Swap token stuff */
14839         mm->token_priority = 0;
14840 @@ -598,6 +610,7 @@ fail_nocontext:
14841          * If init_new_context() failed, we cannot use mmput() to free the mm
14842          * because it calls destroy_context()
14843          */
14844 +       clr_vx_info(&mm->mm_vx_info);
14845         mm_free_pgd(mm);
14846         free_mm(mm);
14847         return NULL;
14848 @@ -661,6 +674,7 @@ static struct fs_struct *__copy_fs_struc
14849                 fs->pwd = old->pwd;
14850                 path_get(&old->pwd);
14851                 read_unlock(&old->lock);
14852 +               atomic_inc(&vs_global_fs);
14853         }
14854         return fs;
14855  }
14856 @@ -904,6 +918,8 @@ static struct task_struct *copy_process(
14857         int retval;
14858         struct task_struct *p;
14859         int cgroup_callbacks_done = 0;
14860 +       struct vx_info *vxi;
14861 +       struct nx_info *nxi;
14862  
14863         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14864                 return ERR_PTR(-EINVAL);
14865 @@ -938,12 +954,28 @@ static struct task_struct *copy_process(
14866         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14867         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14868  #endif
14869 +       init_vx_info(&p->vx_info, current->vx_info);
14870 +       init_nx_info(&p->nx_info, current->nx_info);
14871 +
14872 +       /* check vserver memory */
14873 +       if (p->mm && !(clone_flags & CLONE_VM)) {
14874 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
14875 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
14876 +               else
14877 +                       goto bad_fork_free;
14878 +       }
14879 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
14880 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
14881 +                       goto bad_fork_cleanup_vm;
14882 +       }
14883         retval = -EAGAIN;
14884 +       if (!vx_nproc_avail(1))
14885 +               goto bad_fork_cleanup_vm;
14886         if (atomic_read(&p->user->processes) >=
14887                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
14888                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14889                     p->user != current->nsproxy->user_ns->root_user)
14890 -                       goto bad_fork_free;
14891 +                       goto bad_fork_cleanup_vm;
14892         }
14893  
14894         atomic_inc(&p->user->__count);
14895 @@ -1241,6 +1273,18 @@ static struct task_struct *copy_process(
14896  
14897         total_forks++;
14898         spin_unlock(&current->sighand->siglock);
14899 +
14900 +       /* p is copy of current */
14901 +       vxi = p->vx_info;
14902 +       if (vxi) {
14903 +               claim_vx_info(vxi, p);
14904 +               atomic_inc(&vxi->cvirt.nr_threads);
14905 +               atomic_inc(&vxi->cvirt.total_forks);
14906 +               vx_nproc_inc(p);
14907 +       }
14908 +       nxi = p->nx_info;
14909 +       if (nxi)
14910 +               claim_nx_info(nxi, p);
14911         write_unlock_irq(&tasklist_lock);
14912         proc_fork_connector(p);
14913         cgroup_post_fork(p);
14914 @@ -1287,6 +1331,9 @@ bad_fork_cleanup_count:
14915         put_group_info(p->group_info);
14916         atomic_dec(&p->user->processes);
14917         free_uid(p->user);
14918 +bad_fork_cleanup_vm:
14919 +       if (p->mm && !(clone_flags & CLONE_VM))
14920 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
14921  bad_fork_free:
14922         free_task(p);
14923  fork_out:
14924 diff -NurpP --minimal linux-2.6.27.3/kernel/kthread.c linux-2.6.27.3-vs2.3.0.35.7/kernel/kthread.c
14925 --- linux-2.6.27.3/kernel/kthread.c     2008-10-13 14:52:09.000000000 +0200
14926 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/kthread.c        2008-10-13 14:54:20.000000000 +0200
14927 @@ -13,6 +13,7 @@
14928  #include <linux/file.h>
14929  #include <linux/module.h>
14930  #include <linux/mutex.h>
14931 +#include <linux/vs_pid.h>
14932  
14933  #define KTHREAD_NICE_LEVEL (-5)
14934  
14935 @@ -98,7 +99,7 @@ static void create_kthread(struct kthrea
14936                 struct sched_param param = { .sched_priority = 0 };
14937                 wait_for_completion(&create->started);
14938                 read_lock(&tasklist_lock);
14939 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
14940 +               create->result = find_task_by_real_pid(pid);
14941                 read_unlock(&tasklist_lock);
14942                 /*
14943                  * root may have changed our (kthreadd's) priority or CPU mask.
14944 diff -NurpP --minimal linux-2.6.27.3/kernel/Makefile linux-2.6.27.3-vs2.3.0.35.7/kernel/Makefile
14945 --- linux-2.6.27.3/kernel/Makefile      2008-10-13 14:52:09.000000000 +0200
14946 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/Makefile 2008-10-13 14:54:20.000000000 +0200
14947 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14948  CFLAGS_REMOVE_sched.o = -mno-spe -pg
14949  endif
14950  
14951 +obj-y += vserver/
14952  obj-$(CONFIG_PROFILING) += profile.o
14953  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14954  obj-$(CONFIG_STACKTRACE) += stacktrace.o
14955 diff -NurpP --minimal linux-2.6.27.3/kernel/nsproxy.c linux-2.6.27.3-vs2.3.0.35.7/kernel/nsproxy.c
14956 --- linux-2.6.27.3/kernel/nsproxy.c     2008-10-13 14:52:09.000000000 +0200
14957 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/nsproxy.c        2008-10-13 14:54:20.000000000 +0200
14958 @@ -19,6 +19,8 @@
14959  #include <linux/mnt_namespace.h>
14960  #include <linux/utsname.h>
14961  #include <linux/pid_namespace.h>
14962 +#include <linux/vserver/global.h>
14963 +#include <linux/vserver/debug.h>
14964  #include <net/net_namespace.h>
14965  #include <linux/ipc_namespace.h>
14966  
14967 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
14968         if (ns) {
14969                 memcpy(ns, orig, sizeof(struct nsproxy));
14970                 atomic_set(&ns->count, 1);
14971 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
14972 +                       orig, atomic_read(&orig->count), ns);
14973 +               atomic_inc(&vs_global_nsproxy);
14974         }
14975         return ns;
14976  }
14977 @@ -46,47 +51,51 @@ static inline struct nsproxy *clone_nspr
14978   * Return the newly created nsproxy.  Do not attach this to the task,
14979   * leave it to the caller to do proper locking and attach it to task.
14980   */
14981 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14982 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14983 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14984 +                       struct nsproxy *orig, struct fs_struct *new_fs)
14985  {
14986         struct nsproxy *new_nsp;
14987         int err;
14988  
14989 -       new_nsp = clone_nsproxy(tsk->nsproxy);
14990 +       vxdprintk(VXD_CBIT(space, 4),
14991 +               "unshare_namespaces(0x%08lx,%p,%p)",
14992 +               flags, orig, new_fs);
14993 +
14994 +       new_nsp = clone_nsproxy(orig);
14995         if (!new_nsp)
14996                 return ERR_PTR(-ENOMEM);
14997  
14998 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14999 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15000         if (IS_ERR(new_nsp->mnt_ns)) {
15001                 err = PTR_ERR(new_nsp->mnt_ns);
15002                 goto out_ns;
15003         }
15004  
15005 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15006 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15007         if (IS_ERR(new_nsp->uts_ns)) {
15008                 err = PTR_ERR(new_nsp->uts_ns);
15009                 goto out_uts;
15010         }
15011  
15012 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15013 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15014         if (IS_ERR(new_nsp->ipc_ns)) {
15015                 err = PTR_ERR(new_nsp->ipc_ns);
15016                 goto out_ipc;
15017         }
15018  
15019 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15020 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15021         if (IS_ERR(new_nsp->pid_ns)) {
15022                 err = PTR_ERR(new_nsp->pid_ns);
15023                 goto out_pid;
15024         }
15025  
15026 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
15027 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15028         if (IS_ERR(new_nsp->user_ns)) {
15029                 err = PTR_ERR(new_nsp->user_ns);
15030                 goto out_user;
15031         }
15032  
15033 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15034 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15035         if (IS_ERR(new_nsp->net_ns)) {
15036                 err = PTR_ERR(new_nsp->net_ns);
15037                 goto out_net;
15038 @@ -114,6 +123,37 @@ out_ns:
15039         return ERR_PTR(err);
15040  }
15041  
15042 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15043 +                       struct fs_struct *new_fs)
15044 +{
15045 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15046 +}
15047 +
15048 +/*
15049 + * copies the nsproxy, setting refcount to 1, and grabbing a
15050 + * reference to all contained namespaces.
15051 + */
15052 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15053 +{
15054 +       struct nsproxy *ns = clone_nsproxy(orig);
15055 +
15056 +       if (ns) {
15057 +               if (ns->mnt_ns)
15058 +                       get_mnt_ns(ns->mnt_ns);
15059 +               if (ns->uts_ns)
15060 +                       get_uts_ns(ns->uts_ns);
15061 +               if (ns->ipc_ns)
15062 +                       get_ipc_ns(ns->ipc_ns);
15063 +               if (ns->pid_ns)
15064 +                       get_pid_ns(ns->pid_ns);
15065 +               if (ns->user_ns)
15066 +                       get_user_ns(ns->user_ns);
15067 +               if (ns->net_ns)
15068 +                       get_net(ns->net_ns);
15069 +       }
15070 +       return ns;
15071 +}
15072 +
15073  /*
15074   * called from clone.  This now handles copy for nsproxy and all
15075   * namespaces therein.
15076 @@ -121,9 +161,12 @@ out_ns:
15077  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15078  {
15079         struct nsproxy *old_ns = tsk->nsproxy;
15080 -       struct nsproxy *new_ns;
15081 +       struct nsproxy *new_ns = NULL;
15082         int err = 0;
15083  
15084 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15085 +               flags, tsk, old_ns);
15086 +
15087         if (!old_ns)
15088                 return 0;
15089  
15090 @@ -160,6 +203,9 @@ int copy_namespaces(unsigned long flags,
15091  
15092  out:
15093         put_nsproxy(old_ns);
15094 +       vxdprintk(VXD_CBIT(space, 3),
15095 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15096 +               flags, tsk, old_ns, err, new_ns);
15097         return err;
15098  }
15099  
15100 @@ -175,7 +221,9 @@ void free_nsproxy(struct nsproxy *ns)
15101                 put_pid_ns(ns->pid_ns);
15102         if (ns->user_ns)
15103                 put_user_ns(ns->user_ns);
15104 -       put_net(ns->net_ns);
15105 +       if (ns->net_ns)
15106 +               put_net(ns->net_ns);
15107 +       atomic_dec(&vs_global_nsproxy);
15108         kmem_cache_free(nsproxy_cachep, ns);
15109  }
15110  
15111 @@ -188,6 +236,10 @@ int unshare_nsproxy_namespaces(unsigned 
15112  {
15113         int err = 0;
15114  
15115 +       vxdprintk(VXD_CBIT(space, 4),
15116 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15117 +               unshare_flags, current->nsproxy);
15118 +
15119         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15120                                CLONE_NEWUSER | CLONE_NEWNET)))
15121                 return 0;
15122 diff -NurpP --minimal linux-2.6.27.3/kernel/pid.c linux-2.6.27.3-vs2.3.0.35.7/kernel/pid.c
15123 --- linux-2.6.27.3/kernel/pid.c 2008-10-13 14:52:09.000000000 +0200
15124 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/pid.c    2008-10-13 14:54:20.000000000 +0200
15125 @@ -36,6 +36,8 @@
15126  #include <linux/pid_namespace.h>
15127  #include <linux/init_task.h>
15128  #include <linux/syscalls.h>
15129 +#include <linux/vs_pid.h>
15130 +#include <linux/vserver/global.h>
15131  
15132  #define pid_hashfn(nr, ns)     \
15133         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15134 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15135  
15136  struct pid *find_vpid(int nr)
15137  {
15138 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15139 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15140  }
15141  EXPORT_SYMBOL_GPL(find_vpid);
15142  
15143 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15144  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15145  {
15146         struct task_struct *result = NULL;
15147 +
15148 +       if (type == PIDTYPE_REALPID)
15149 +               type = PIDTYPE_PID;
15150         if (pid) {
15151                 struct hlist_node *first;
15152                 first = rcu_dereference(pid->tasks[type].first);
15153 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15154  
15155  struct task_struct *find_task_by_vpid(pid_t vnr)
15156  {
15157 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15158 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15159                         current->nsproxy->pid_ns);
15160  }
15161  EXPORT_SYMBOL(find_task_by_vpid);
15162  
15163  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15164  {
15165 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15166 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15167  }
15168  EXPORT_SYMBOL(find_task_by_pid_ns);
15169  
15170 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15171  }
15172  EXPORT_SYMBOL_GPL(find_get_pid);
15173  
15174 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15175 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15176  {
15177         struct upid *upid;
15178         pid_t nr = 0;
15179 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15180         return nr;
15181  }
15182  
15183 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15184 +{
15185 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15186 +}
15187 +
15188  pid_t pid_vnr(struct pid *pid)
15189  {
15190         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15191 diff -NurpP --minimal linux-2.6.27.3/kernel/pid_namespace.c linux-2.6.27.3-vs2.3.0.35.7/kernel/pid_namespace.c
15192 --- linux-2.6.27.3/kernel/pid_namespace.c       2008-10-13 14:52:09.000000000 +0200
15193 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/pid_namespace.c  2008-10-13 14:54:20.000000000 +0200
15194 @@ -13,6 +13,7 @@
15195  #include <linux/syscalls.h>
15196  #include <linux/err.h>
15197  #include <linux/acct.h>
15198 +#include <linux/vserver/global.h>
15199  
15200  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15201  
15202 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15203                 goto out_free_map;
15204  
15205         kref_init(&ns->kref);
15206 +       atomic_inc(&vs_global_pid_ns);
15207         ns->level = level;
15208  
15209         set_bit(0, ns->pidmap[0].page);
15210 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15211  
15212         for (i = 0; i < PIDMAP_ENTRIES; i++)
15213                 kfree(ns->pidmap[i].page);
15214 +       atomic_dec(&vs_global_pid_ns);
15215         kmem_cache_free(pid_ns_cachep, ns);
15216  }
15217  
15218 diff -NurpP --minimal linux-2.6.27.3/kernel/posix-timers.c linux-2.6.27.3-vs2.3.0.35.7/kernel/posix-timers.c
15219 --- linux-2.6.27.3/kernel/posix-timers.c        2008-10-13 14:52:09.000000000 +0200
15220 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/posix-timers.c   2008-10-13 14:54:20.000000000 +0200
15221 @@ -46,6 +46,7 @@
15222  #include <linux/wait.h>
15223  #include <linux/workqueue.h>
15224  #include <linux/module.h>
15225 +#include <linux/vs_context.h>
15226  
15227  /*
15228   * Management arrays for POSIX timers.  Timers are kept in slab memory
15229 @@ -298,6 +299,12 @@ void do_schedule_next_timer(struct sigin
15230  
15231  int posix_timer_event(struct k_itimer *timr, int si_private)
15232  {
15233 +       struct vx_info_save vxis;
15234 +       struct vx_info *vxi;
15235 +       int ret;
15236 +
15237 +       vxi = task_get_vx_info(timr->it_process);
15238 +       enter_vx_info(vxi, &vxis);
15239         /*
15240          * FIXME: if ->sigq is queued we can race with
15241          * dequeue_signal()->do_schedule_next_timer().
15242 @@ -318,10 +325,11 @@ int posix_timer_event(struct k_itimer *t
15243  
15244         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
15245                 struct task_struct *leader;
15246 -               int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15247 +
15248 +               ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15249  
15250                 if (likely(ret >= 0))
15251 -                       return ret;
15252 +                       goto out;
15253  
15254                 timr->it_sigev_notify = SIGEV_SIGNAL;
15255                 leader = timr->it_process->group_leader;
15256 @@ -329,7 +337,11 @@ int posix_timer_event(struct k_itimer *t
15257                 timr->it_process = leader;
15258         }
15259  
15260 -       return send_sigqueue(timr->sigq, timr->it_process, 1);
15261 +       ret = send_sigqueue(timr->sigq, timr->it_process, 1);
15262 +out:
15263 +       leave_vx_info(&vxis);
15264 +       put_vx_info(vxi);
15265 +       return ret;
15266  }
15267  EXPORT_SYMBOL_GPL(posix_timer_event);
15268  
15269 diff -NurpP --minimal linux-2.6.27.3/kernel/printk.c linux-2.6.27.3-vs2.3.0.35.7/kernel/printk.c
15270 --- linux-2.6.27.3/kernel/printk.c      2008-10-13 14:52:09.000000000 +0200
15271 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/printk.c 2008-10-13 14:54:20.000000000 +0200
15272 @@ -32,6 +32,7 @@
15273  #include <linux/security.h>
15274  #include <linux/bootmem.h>
15275  #include <linux/syscalls.h>
15276 +#include <linux/vs_cvirt.h>
15277  
15278  #include <asm/uaccess.h>
15279  
15280 @@ -291,18 +292,13 @@ int do_syslog(int type, char __user *buf
15281         unsigned i, j, limit, count;
15282         int do_clear = 0;
15283         char c;
15284 -       int error = 0;
15285 +       int error;
15286  
15287         error = security_syslog(type);
15288         if (error)
15289                 return error;
15290  
15291 -       switch (type) {
15292 -       case 0:         /* Close log */
15293 -               break;
15294 -       case 1:         /* Open log */
15295 -               break;
15296 -       case 2:         /* Read from log */
15297 +       if ((type >= 2) && (type <= 4)) {
15298                 error = -EINVAL;
15299                 if (!buf || len < 0)
15300                         goto out;
15301 @@ -313,6 +309,16 @@ int do_syslog(int type, char __user *buf
15302                         error = -EFAULT;
15303                         goto out;
15304                 }
15305 +       }
15306 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15307 +               return vx_do_syslog(type, buf, len);
15308 +
15309 +       switch (type) {
15310 +       case 0:         /* Close log */
15311 +               break;
15312 +       case 1:         /* Open log */
15313 +               break;
15314 +       case 2:         /* Read from log */
15315                 error = wait_event_interruptible(log_wait,
15316                                                         (log_start - log_end));
15317                 if (error)
15318 @@ -337,16 +343,6 @@ int do_syslog(int type, char __user *buf
15319                 do_clear = 1;
15320                 /* FALL THRU */
15321         case 3:         /* Read last kernel messages */
15322 -               error = -EINVAL;
15323 -               if (!buf || len < 0)
15324 -                       goto out;
15325 -               error = 0;
15326 -               if (!len)
15327 -                       goto out;
15328 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15329 -                       error = -EFAULT;
15330 -                       goto out;
15331 -               }
15332                 count = len;
15333                 if (count > log_buf_len)
15334                         count = log_buf_len;
15335 diff -NurpP --minimal linux-2.6.27.3/kernel/ptrace.c linux-2.6.27.3-vs2.3.0.35.7/kernel/ptrace.c
15336 --- linux-2.6.27.3/kernel/ptrace.c      2008-10-13 14:52:09.000000000 +0200
15337 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/ptrace.c 2008-10-13 14:54:20.000000000 +0200
15338 @@ -21,6 +21,7 @@
15339  #include <linux/audit.h>
15340  #include <linux/pid_namespace.h>
15341  #include <linux/syscalls.h>
15342 +#include <linux/vs_context.h>
15343  
15344  #include <asm/pgtable.h>
15345  #include <asm/uaccess.h>
15346 @@ -139,6 +140,11 @@ int __ptrace_may_access(struct task_stru
15347                 dumpable = get_dumpable(task->mm);
15348         if (!dumpable && !capable(CAP_SYS_PTRACE))
15349                 return -EPERM;
15350 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15351 +               return -EPERM;
15352 +       if (!vx_check(task->xid, VS_IDENT) &&
15353 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15354 +               return -EACCES;
15355  
15356         return security_ptrace_may_access(task, mode);
15357  }
15358 @@ -567,6 +573,10 @@ asmlinkage long sys_ptrace(long request,
15359                 goto out;
15360         }
15361  
15362 +       ret = -EPERM;
15363 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15364 +               goto out_put_task_struct;
15365 +
15366         if (request == PTRACE_ATTACH) {
15367                 ret = ptrace_attach(child);
15368                 /*
15369 diff -NurpP --minimal linux-2.6.27.3/kernel/sched.c linux-2.6.27.3-vs2.3.0.35.7/kernel/sched.c
15370 --- linux-2.6.27.3/kernel/sched.c       2008-10-13 14:52:09.000000000 +0200
15371 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sched.c  2008-10-13 14:54:20.000000000 +0200
15372 @@ -71,6 +71,8 @@
15373  #include <linux/debugfs.h>
15374  #include <linux/ctype.h>
15375  #include <linux/ftrace.h>
15376 +#include <linux/vs_sched.h>
15377 +#include <linux/vs_cvirt.h>
15378  
15379  #include <asm/tlb.h>
15380  #include <asm/irq_regs.h>
15381 @@ -497,6 +499,16 @@ struct root_domain {
15382  static struct root_domain def_root_domain;
15383  
15384  #endif
15385 +       unsigned long norm_time;
15386 +       unsigned long idle_time;
15387 +#ifdef CONFIG_VSERVER_IDLETIME
15388 +       int idle_skip;
15389 +#endif
15390 +#ifdef CONFIG_VSERVER_HARDCPU
15391 +       struct list_head hold_queue;
15392 +       unsigned long nr_onhold;
15393 +       int idle_tokens;
15394 +#endif
15395  
15396  /*
15397   * This is the main, per-CPU runqueue data structure.
15398 @@ -1640,6 +1652,7 @@ static void update_avg(u64 *avg, u64 sam
15399  
15400  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
15401  {
15402 +       // BUG_ON(p->state & TASK_ONHOLD);
15403         sched_info_queued(p);
15404         p->sched_class->enqueue_task(rq, p, wakeup);
15405         p->se.on_rq = 1;
15406 @@ -1837,6 +1850,9 @@ struct migration_req {
15407         struct completion done;
15408  };
15409  
15410 +#include "sched_mon.h"
15411 +
15412 +
15413  /*
15414   * The task's runqueue lock must be held.
15415   * Returns true if you have to wait for migration thread.
15416 @@ -1846,6 +1862,7 @@ migrate_task(struct task_struct *p, int 
15417  {
15418         struct rq *rq = task_rq(p);
15419  
15420 +       vxm_migrate_task(p, rq, dest_cpu);
15421         /*
15422          * If the task is not on a runqueue (and not running), then
15423          * it is sufficient to simply update the task's cpu field.
15424 @@ -2242,6 +2259,12 @@ static int try_to_wake_up(struct task_st
15425                 /* might preempt at this point */
15426                 rq = task_rq_lock(p, &flags);
15427                 old_state = p->state;
15428 +
15429 +       /* we need to unhold suspended tasks
15430 +       if (old_state & TASK_ONHOLD) {
15431 +               vx_unhold_task(p, rq);
15432 +               old_state = p->state;
15433 +       } */
15434                 if (!(old_state & state))
15435                         goto out;
15436                 if (p->se.on_rq)
15437 @@ -4067,13 +4090,16 @@ unsigned long long task_sched_runtime(st
15438  void account_user_time(struct task_struct *p, cputime_t cputime)
15439  {
15440         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15441 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15442         cputime64_t tmp;
15443 +       int nice = (TASK_NICE(p) > 0);
15444  
15445         p->utime = cputime_add(p->utime, cputime);
15446 +       vx_account_user(vxi, cputime, nice);
15447  
15448         /* Add user time to cpustat. */
15449         tmp = cputime_to_cputime64(cputime);
15450 -       if (TASK_NICE(p) > 0)
15451 +       if (nice)
15452                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15453         else
15454                 cpustat->user = cputime64_add(cpustat->user, tmp);
15455 @@ -4120,6 +4146,7 @@ void account_system_time(struct task_str
15456                          cputime_t cputime)
15457  {
15458         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15459 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15460         struct rq *rq = this_rq();
15461         cputime64_t tmp;
15462  
15463 @@ -4129,6 +4156,7 @@ void account_system_time(struct task_str
15464         }
15465  
15466         p->stime = cputime_add(p->stime, cputime);
15467 +       vx_account_system(vxi, cputime, (p == rq->idle));
15468  
15469         /* Add system time to cpustat. */
15470         tmp = cputime_to_cputime64(cputime);
15471 @@ -4963,7 +4991,7 @@ asmlinkage long sys_nice(int increment)
15472                 nice = 19;
15473  
15474         if (increment < 0 && !can_nice(current, nice))
15475 -               return -EPERM;
15476 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15477  
15478         retval = security_task_setnice(current, nice);
15479         if (retval)
15480 diff -NurpP --minimal linux-2.6.27.3/kernel/sched_fair.c linux-2.6.27.3-vs2.3.0.35.7/kernel/sched_fair.c
15481 --- linux-2.6.27.3/kernel/sched_fair.c  2008-10-13 14:52:09.000000000 +0200
15482 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sched_fair.c     2008-10-13 14:54:20.000000000 +0200
15483 @@ -724,6 +724,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15484         check_spread(cfs_rq, se);
15485         if (se != cfs_rq->curr)
15486                 __enqueue_entity(cfs_rq, se);
15487 +
15488 +       if (entity_is_task(se))
15489 +               vx_activate_task(task_of(se));
15490  }
15491  
15492  static void
15493 @@ -750,6 +753,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15494  
15495         if (se != cfs_rq->curr)
15496                 __dequeue_entity(cfs_rq, se);
15497 +       if (entity_is_task(se))
15498 +               vx_deactivate_task(task_of(se));
15499         account_entity_dequeue(cfs_rq, se);
15500  }
15501  
15502 diff -NurpP --minimal linux-2.6.27.3/kernel/sched_hard.h linux-2.6.27.3-vs2.3.0.35.7/kernel/sched_hard.h
15503 --- linux-2.6.27.3/kernel/sched_hard.h  1970-01-01 01:00:00.000000000 +0100
15504 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sched_hard.h     2008-10-13 14:54:20.000000000 +0200
15505 @@ -0,0 +1,324 @@
15506 +
15507 +#ifdef CONFIG_VSERVER_IDLELIMIT
15508 +
15509 +/*
15510 + * vx_idle_resched - reschedule after maxidle
15511 + */
15512 +static inline
15513 +void vx_idle_resched(struct rq *rq)
15514 +{
15515 +       /* maybe have a better criterion for paused */
15516 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
15517 +               set_need_resched();
15518 +}
15519 +
15520 +#else /* !CONFIG_VSERVER_IDLELIMIT */
15521 +
15522 +#define vx_idle_resched(rq)
15523 +
15524 +#endif /* CONFIG_VSERVER_IDLELIMIT */
15525 +
15526 +
15527 +
15528 +#ifdef CONFIG_VSERVER_IDLETIME
15529 +
15530 +#define vx_set_rq_min_skip(rq, min)            \
15531 +       (rq)->idle_skip = (min)
15532 +
15533 +#define vx_save_min_skip(ret, min, val)                \
15534 +       __vx_save_min_skip(ret, min, val)
15535 +
15536 +static inline
15537 +void __vx_save_min_skip(int ret, int *min, int val)
15538 +{
15539 +       if (ret > -2)
15540 +               return;
15541 +       if ((*min > val) || !*min)
15542 +               *min = val;
15543 +}
15544 +
15545 +static inline
15546 +int vx_try_skip(struct rq *rq, int cpu)
15547 +{
15548 +       /* artificially advance time */
15549 +       if (rq->idle_skip > 0) {
15550 +               vxdprintk(list_empty(&rq->hold_queue),
15551 +                       "hold queue empty on cpu %d", cpu);
15552 +               rq->idle_time += rq->idle_skip;
15553 +               vxm_idle_skip(rq, cpu);
15554 +               return 1;
15555 +       }
15556 +       return 0;
15557 +}
15558 +
15559 +#else /* !CONFIG_VSERVER_IDLETIME */
15560 +
15561 +#define vx_set_rq_min_skip(rq, min)            \
15562 +       ({ int dummy = (min); dummy; })
15563 +
15564 +#define vx_save_min_skip(ret, min, val)
15565 +
15566 +static inline
15567 +int vx_try_skip(struct rq *rq, int cpu)
15568 +{
15569 +       return 0;
15570 +}
15571 +
15572 +#endif /* CONFIG_VSERVER_IDLETIME */
15573 +
15574 +
15575 +
15576 +#ifdef CONFIG_VSERVER_HARDCPU
15577 +
15578 +#define vx_set_rq_max_idle(rq, max)            \
15579 +       (rq)->idle_tokens = (max)
15580 +
15581 +#define vx_save_max_idle(ret, min, val)                \
15582 +       __vx_save_max_idle(ret, min, val)
15583 +
15584 +static inline
15585 +void __vx_save_max_idle(int ret, int *min, int val)
15586 +{
15587 +       if (*min > val)
15588 +               *min = val;
15589 +}
15590 +
15591 +
15592 +/*
15593 + * vx_hold_task - put a task on the hold queue
15594 + */
15595 +static inline
15596 +void vx_hold_task(struct task_struct *p, struct rq *rq)
15597 +{
15598 +       __deactivate_task(p, rq);
15599 +       p->state |= TASK_ONHOLD;
15600 +       /* a new one on hold */
15601 +       rq->nr_onhold++;
15602 +       vxm_hold_task(p, rq);
15603 +       list_add_tail(&p->run_list, &rq->hold_queue);
15604 +}
15605 +
15606 +/*
15607 + * vx_unhold_task - put a task back to the runqueue
15608 + */
15609 +static inline
15610 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
15611 +{
15612 +       list_del(&p->run_list);
15613 +       /* one less waiting */
15614 +       rq->nr_onhold--;
15615 +       p->state &= ~TASK_ONHOLD;
15616 +       enqueue_task(p, rq->expired);
15617 +       inc_nr_running(p, rq);
15618 +       vxm_unhold_task(p, rq);
15619 +
15620 +       if (p->static_prio < rq->best_expired_prio)
15621 +               rq->best_expired_prio = p->static_prio;
15622 +}
15623 +
15624 +unsigned long nr_onhold(void)
15625 +{
15626 +       unsigned long i, sum = 0;
15627 +
15628 +       for_each_online_cpu(i)
15629 +               sum += cpu_rq(i)->nr_onhold;
15630 +
15631 +       return sum;
15632 +}
15633 +
15634 +
15635 +
15636 +static inline
15637 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
15638 +{
15639 +       return sched_pc->tokens;
15640 +}
15641 +
15642 +static inline
15643 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
15644 +{
15645 +       sched_pc->tokens--;
15646 +}
15647 +
15648 +static inline
15649 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
15650 +{
15651 +       struct vx_info *vxi = p->vx_info;
15652 +
15653 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
15654 +               struct _vx_sched_pc *sched_pc =
15655 +                       &vx_per_cpu(vxi, sched_pc, cpu);
15656 +               int tokens;
15657 +
15658 +               /* maybe we can simplify that to decrement
15659 +                  the token counter unconditional? */
15660 +
15661 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
15662 +                       __vx_consume_token(sched_pc);
15663 +
15664 +               /* for tokens > 0, one token was consumed */
15665 +               if (tokens < 2)
15666 +                       slice = 0;
15667 +       }
15668 +       vxm_need_resched(p, slice, cpu);
15669 +       return (slice == 0);
15670 +}
15671 +
15672 +
15673 +#define vx_set_rq_time(rq, time) do {  \
15674 +       rq->norm_time = time;           \
15675 +} while (0)
15676 +
15677 +
15678 +static inline
15679 +void vx_try_unhold(struct rq *rq, int cpu)
15680 +{
15681 +       struct vx_info *vxi = NULL;
15682 +       struct list_head *l, *n;
15683 +       int maxidle = HZ;
15684 +       int minskip = 0;
15685 +
15686 +       /* nothing to do? what about pause? */
15687 +       if (list_empty(&rq->hold_queue))
15688 +               return;
15689 +
15690 +       list_for_each_safe(l, n, &rq->hold_queue) {
15691 +               int ret, delta_min[2];
15692 +               struct _vx_sched_pc *sched_pc;
15693 +               struct task_struct *p;
15694 +
15695 +               p = list_entry(l, struct task_struct, run_list);
15696 +               /* don't bother with same context */
15697 +               if (vxi == p->vx_info)
15698 +                       continue;
15699 +
15700 +               vxi = p->vx_info;
15701 +               /* ignore paused contexts */
15702 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
15703 +                       continue;
15704 +
15705 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
15706 +
15707 +               /* recalc tokens */
15708 +               vxm_sched_info(sched_pc, vxi, cpu);
15709 +               ret = vx_tokens_recalc(sched_pc,
15710 +                       &rq->norm_time, &rq->idle_time, delta_min);
15711 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
15712 +
15713 +               if (ret > 0) {
15714 +                       /* we found a runable context */
15715 +                       vx_unhold_task(p, rq);
15716 +                       break;
15717 +               }
15718 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
15719 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
15720 +       }
15721 +       vx_set_rq_max_idle(rq, maxidle);
15722 +       vx_set_rq_min_skip(rq, minskip);
15723 +       vxm_rq_max_min(rq, cpu);
15724 +}
15725 +
15726 +
15727 +static inline
15728 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
15729 +{
15730 +       struct vx_info *vxi = next->vx_info;
15731 +       struct _vx_sched_pc *sched_pc;
15732 +       int delta_min[2];
15733 +       int flags, ret;
15734 +
15735 +       if (!vxi)
15736 +               return 1;
15737 +
15738 +       flags = vxi->vx_flags;
15739 +
15740 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
15741 +               goto put_on_hold;
15742 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
15743 +               return 1;
15744 +
15745 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
15746 +#ifdef CONFIG_SMP
15747 +       /* update scheduler params */
15748 +       if (cpu_isset(cpu, vxi->sched.update)) {
15749 +               vx_update_sched_param(&vxi->sched, sched_pc);
15750 +               vxm_update_sched(sched_pc, vxi, cpu);
15751 +               cpu_clear(cpu, vxi->sched.update);
15752 +       }
15753 +#endif
15754 +       vxm_sched_info(sched_pc, vxi, cpu);
15755 +       ret  = vx_tokens_recalc(sched_pc,
15756 +               &rq->norm_time, &rq->idle_time, delta_min);
15757 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
15758 +
15759 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
15760 +               return 1;
15761 +
15762 +       if (unlikely(ret < 0)) {
15763 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
15764 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
15765 +               vxm_rq_max_min(rq, cpu);
15766 +       put_on_hold:
15767 +               vx_hold_task(next, rq);
15768 +               return 0;
15769 +       }
15770 +       return 1;
15771 +}
15772 +
15773 +
15774 +#else /* CONFIG_VSERVER_HARDCPU */
15775 +
15776 +static inline
15777 +void vx_hold_task(struct task_struct *p, struct rq *rq)
15778 +{
15779 +       return;
15780 +}
15781 +
15782 +static inline
15783 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
15784 +{
15785 +       return;
15786 +}
15787 +
15788 +unsigned long nr_onhold(void)
15789 +{
15790 +       return 0;
15791 +}
15792 +
15793 +
15794 +static inline
15795 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
15796 +{
15797 +       return (slice == 0);
15798 +}
15799 +
15800 +
15801 +#define vx_set_rq_time(rq, time)
15802 +
15803 +static inline
15804 +void vx_try_unhold(struct rq *rq, int cpu)
15805 +{
15806 +       return;
15807 +}
15808 +
15809 +static inline
15810 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
15811 +{
15812 +       struct vx_info *vxi = next->vx_info;
15813 +       struct _vx_sched_pc *sched_pc;
15814 +       int delta_min[2];
15815 +       int ret;
15816 +
15817 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
15818 +               return 1;
15819 +
15820 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
15821 +       vxm_sched_info(sched_pc, vxi, cpu);
15822 +       ret  = vx_tokens_recalc(sched_pc,
15823 +               &rq->norm_time, &rq->idle_time, delta_min);
15824 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
15825 +       return 1;
15826 +}
15827 +
15828 +#endif /* CONFIG_VSERVER_HARDCPU */
15829 +
15830 diff -NurpP --minimal linux-2.6.27.3/kernel/sched_mon.h linux-2.6.27.3-vs2.3.0.35.7/kernel/sched_mon.h
15831 --- linux-2.6.27.3/kernel/sched_mon.h   1970-01-01 01:00:00.000000000 +0100
15832 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sched_mon.h      2008-10-13 14:54:20.000000000 +0200
15833 @@ -0,0 +1,200 @@
15834 +
15835 +#include <linux/vserver/monitor.h>
15836 +
15837 +#ifdef  CONFIG_VSERVER_MONITOR
15838 +
15839 +#ifdef CONFIG_VSERVER_HARDCPU
15840 +#define HARDCPU(x) (x)
15841 +#else
15842 +#define HARDCPU(x) (0)
15843 +#endif
15844 +
15845 +#ifdef CONFIG_VSERVER_IDLETIME
15846 +#define IDLETIME(x) (x)
15847 +#else
15848 +#define IDLETIME(x) (0)
15849 +#endif
15850 +
15851 +struct _vx_mon_entry *vxm_advance(int cpu);
15852 +
15853 +
15854 +static inline
15855 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
15856 +{
15857 +       entry->type = type;
15858 +       entry->xid = xid;
15859 +}
15860 +
15861 +static inline
15862 +void   __vxm_sync(int cpu)
15863 +{
15864 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15865 +
15866 +       __vxm_basic(entry, 0, VXM_SYNC);
15867 +       entry->ev.sec = xtime.tv_sec;
15868 +       entry->ev.nsec = xtime.tv_nsec;
15869 +}
15870 +
15871 +static inline
15872 +void   __vxm_task(struct task_struct *p, int type)
15873 +{
15874 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
15875 +
15876 +       __vxm_basic(entry, p->xid, type);
15877 +       entry->ev.tsk.pid = p->pid;
15878 +       entry->ev.tsk.state = p->state;
15879 +}
15880 +
15881 +static inline
15882 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
15883 +{
15884 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15885 +
15886 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
15887 +       entry->sd.tokens = s->tokens;
15888 +       entry->sd.norm_time = s->norm_time;
15889 +       entry->sd.idle_time = s->idle_time;
15890 +}
15891 +
15892 +static inline
15893 +void   __vxm_rqinfo1(struct rq *q, int cpu)
15894 +{
15895 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15896 +
15897 +       entry->type = VXM_RQINFO_1;
15898 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
15899 +       entry->q1.running = q->nr_running;
15900 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
15901 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
15902 +       entry->q1.uintr = q->nr_uninterruptible;
15903 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
15904 +}
15905 +
15906 +static inline
15907 +void   __vxm_rqinfo2(struct rq *q, int cpu)
15908 +{
15909 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15910 +
15911 +       entry->type = VXM_RQINFO_2;
15912 +       entry->xid = (unsigned long)q & 0xffff;
15913 +       entry->q2.norm_time = q->norm_time;
15914 +       entry->q2.idle_time = q->idle_time;
15915 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
15916 +}
15917 +
15918 +static inline
15919 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
15920 +{
15921 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15922 +
15923 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
15924 +       entry->ev.tokens = s->tokens;
15925 +}
15926 +
15927 +static inline
15928 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
15929 +{
15930 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15931 +
15932 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
15933 +       entry->u1.tokens_max = s->tokens_max;
15934 +       entry->u1.fill_rate = s->fill_rate[0];
15935 +       entry->u1.interval = s->interval[0];
15936 +}
15937 +
15938 +static inline
15939 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
15940 +{
15941 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
15942 +
15943 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
15944 +       entry->u2.tokens_min = s->tokens_min;
15945 +       entry->u2.fill_rate = s->fill_rate[1];
15946 +       entry->u2.interval = s->interval[1];
15947 +}
15948 +
15949 +
15950 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
15951 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
15952 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
15953 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
15954 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
15955 +
15956 +static inline
15957 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
15958 +{
15959 +       __vxm_task(p, VXM_MIGRATE);
15960 +       __vxm_rqinfo1(rq, task_cpu(p));
15961 +       __vxm_rqinfo2(rq, task_cpu(p));
15962 +}
15963 +
15964 +static inline
15965 +void   vxm_idle_skip(struct rq *rq, int cpu)
15966 +{
15967 +       __vxm_rqinfo1(rq, cpu);
15968 +       __vxm_rqinfo2(rq, cpu);
15969 +}
15970 +
15971 +static inline
15972 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
15973 +{
15974 +       if (slice)
15975 +               return;
15976 +
15977 +       __vxm_task(p, VXM_RESCHED);
15978 +}
15979 +
15980 +static inline
15981 +void   vxm_sync(unsigned long now, int cpu)
15982 +{
15983 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
15984 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
15985 +               return;
15986 +
15987 +       __vxm_sync(cpu);
15988 +}
15989 +
15990 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
15991 +
15992 +static inline
15993 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
15994 +       struct vx_info *vxi, int cpu)
15995 +{
15996 +       __vxm_sched(s, vxi, cpu);
15997 +       __vxm_rqinfo2(rq, cpu);
15998 +}
15999 +
16000 +static inline
16001 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16002 +{
16003 +       __vxm_sched(s, vxi, cpu);
16004 +       __vxm_update(s, vxi, cpu);
16005 +       __vxm_update1(s, vxi, cpu);
16006 +       __vxm_update2(s, vxi, cpu);
16007 +}
16008 +
16009 +static inline
16010 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16011 +{
16012 +       __vxm_rqinfo1(rq, cpu);
16013 +       __vxm_rqinfo2(rq, cpu);
16014 +}
16015 +
16016 +#else  /* CONFIG_VSERVER_MONITOR */
16017 +
16018 +#define        vxm_activate_task(t,q)          do { } while (0)
16019 +#define        vxm_activate_idle(t,q)          do { } while (0)
16020 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16021 +#define        vxm_hold_task(t,q)              do { } while (0)
16022 +#define        vxm_unhold_task(t,q)            do { } while (0)
16023 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16024 +#define        vxm_idle_skip(q,c)              do { } while (0)
16025 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16026 +#define        vxm_sync(s,c)                   do { } while (0)
16027 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16028 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16029 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16030 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16031 +
16032 +#endif /* CONFIG_VSERVER_MONITOR */
16033 +
16034 diff -NurpP --minimal linux-2.6.27.3/kernel/signal.c linux-2.6.27.3-vs2.3.0.35.7/kernel/signal.c
16035 --- linux-2.6.27.3/kernel/signal.c      2008-10-13 14:52:09.000000000 +0200
16036 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/signal.c 2008-10-13 14:54:20.000000000 +0200
16037 @@ -27,6 +27,8 @@
16038  #include <linux/freezer.h>
16039  #include <linux/pid_namespace.h>
16040  #include <linux/nsproxy.h>
16041 +#include <linux/vs_context.h>
16042 +#include <linux/vs_pid.h>
16043  
16044  #include <asm/param.h>
16045  #include <asm/uaccess.h>
16046 @@ -571,6 +573,14 @@ static int check_kill_permission(int sig
16047         if (!valid_signal(sig))
16048                 return -EINVAL;
16049  
16050 +       if ((info != SEND_SIG_NOINFO) &&
16051 +               (is_si_special(info) || !SI_FROMUSER(info)))
16052 +               goto skip;
16053 +
16054 +       vxdprintk(VXD_CBIT(misc, 7),
16055 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16056 +               sig, info, t, vx_task_xid(t), t->pid);
16057 +
16058         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16059                 return 0;
16060  
16061 @@ -595,6 +605,18 @@ static int check_kill_permission(int sig
16062                 }
16063         }
16064  
16065 +       error = -EPERM;
16066 +       if (t->pid == 1 && current->xid)
16067 +               return error;
16068 +
16069 +       error = -ESRCH;
16070 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16071 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16072 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16073 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16074 +               return error;
16075 +       }
16076 +skip:
16077         return security_task_kill(t, info, sig, 0);
16078  }
16079  
16080 @@ -1051,7 +1073,7 @@ int kill_pid_info(int sig, struct siginf
16081         rcu_read_lock();
16082  retry:
16083         p = pid_task(pid, PIDTYPE_PID);
16084 -       if (p) {
16085 +       if (p && vx_check(vx_task_xid(p), VS_WATCH | VS_IDENT)) {
16086                 error = group_send_sig_info(sig, info, p);
16087                 if (unlikely(error == -ESRCH))
16088                         /*
16089 @@ -1089,7 +1111,7 @@ int kill_pid_info_as_uid(int sig, struct
16090  
16091         read_lock(&tasklist_lock);
16092         p = pid_task(pid, PIDTYPE_PID);
16093 -       if (!p) {
16094 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16095                 ret = -ESRCH;
16096                 goto out_unlock;
16097         }
16098 @@ -1141,7 +1163,9 @@ static int kill_something_info(int sig, 
16099                 struct task_struct * p;
16100  
16101                 for_each_process(p) {
16102 -                       if (p->pid > 1 && !same_thread_group(p, current)) {
16103 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16104 +                               p->pid > 1 && !same_thread_group(p, current) &&
16105 +                               !vx_current_initpid(p->pid)) {
16106                                 int err = group_send_sig_info(sig, info, p);
16107                                 ++count;
16108                                 if (err != -EPERM)
16109 @@ -1814,6 +1838,11 @@ relock:
16110                     !signal_group_exit(signal))
16111                         continue;
16112  
16113 +               /* virtual init is protected against user signals */
16114 +               if ((info->si_code == SI_USER) &&
16115 +                       vx_current_initpid(current->pid))
16116 +                       continue;
16117 +
16118                 if (sig_kernel_stop(signr)) {
16119                         /*
16120                          * The default action is to stop all threads in
16121 diff -NurpP --minimal linux-2.6.27.3/kernel/softirq.c linux-2.6.27.3-vs2.3.0.35.7/kernel/softirq.c
16122 --- linux-2.6.27.3/kernel/softirq.c     2008-10-13 14:52:09.000000000 +0200
16123 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/softirq.c        2008-10-13 14:54:20.000000000 +0200
16124 @@ -21,6 +21,7 @@
16125  #include <linux/rcupdate.h>
16126  #include <linux/smp.h>
16127  #include <linux/tick.h>
16128 +#include <linux/vs_context.h>
16129  
16130  #include <asm/irq.h>
16131  /*
16132 diff -NurpP --minimal linux-2.6.27.3/kernel/sys.c linux-2.6.27.3-vs2.3.0.35.7/kernel/sys.c
16133 --- linux-2.6.27.3/kernel/sys.c 2008-10-13 14:52:09.000000000 +0200
16134 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sys.c    2008-10-13 14:54:20.000000000 +0200
16135 @@ -38,6 +38,7 @@
16136  #include <linux/syscalls.h>
16137  #include <linux/kprobes.h>
16138  #include <linux/user_namespace.h>
16139 +#include <linux/vs_pid.h>
16140  
16141  #include <asm/uaccess.h>
16142  #include <asm/io.h>
16143 @@ -122,7 +123,10 @@ static int set_one_prio(struct task_stru
16144                 goto out;
16145         }
16146         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16147 -               error = -EACCES;
16148 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16149 +                       error = 0;
16150 +               else
16151 +                       error = -EACCES;
16152                 goto out;
16153         }
16154         no_nice = security_task_setnice(p, niceval);
16155 @@ -170,6 +174,8 @@ asmlinkage long sys_setpriority(int whic
16156                         else
16157                                 pgrp = task_pgrp(current);
16158                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16159 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16160 +                                       continue;
16161                                 error = set_one_prio(p, niceval, error);
16162                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16163                         break;
16164 @@ -230,6 +236,8 @@ asmlinkage long sys_getpriority(int whic
16165                         else
16166                                 pgrp = task_pgrp(current);
16167                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16168 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16169 +                                       continue;
16170                                 niceval = 20 - task_nice(p);
16171                                 if (niceval > retval)
16172                                         retval = niceval;
16173 @@ -339,6 +347,9 @@ void kernel_power_off(void)
16174         machine_power_off();
16175  }
16176  EXPORT_SYMBOL_GPL(kernel_power_off);
16177 +
16178 +long vs_reboot(unsigned int, void __user *);
16179 +
16180  /*
16181   * Reboot system call: for obvious reasons only root may call it,
16182   * and even root needs to set up some magic numbers in the registers
16183 @@ -369,6 +380,9 @@ asmlinkage long sys_reboot(int magic1, i
16184         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16185                 cmd = LINUX_REBOOT_CMD_HALT;
16186  
16187 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16188 +               return vs_reboot(cmd, arg);
16189 +
16190         lock_kernel();
16191         switch (cmd) {
16192         case LINUX_REBOOT_CMD_RESTART:
16193 @@ -1344,7 +1358,7 @@ asmlinkage long sys_sethostname(char __u
16194         int errno;
16195         char tmp[__NEW_UTS_LEN];
16196  
16197 -       if (!capable(CAP_SYS_ADMIN))
16198 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16199                 return -EPERM;
16200         if (len < 0 || len > __NEW_UTS_LEN)
16201                 return -EINVAL;
16202 @@ -1389,7 +1403,7 @@ asmlinkage long sys_setdomainname(char _
16203         int errno;
16204         char tmp[__NEW_UTS_LEN];
16205  
16206 -       if (!capable(CAP_SYS_ADMIN))
16207 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16208                 return -EPERM;
16209         if (len < 0 || len > __NEW_UTS_LEN)
16210                 return -EINVAL;
16211 @@ -1456,7 +1470,7 @@ asmlinkage long sys_setrlimit(unsigned i
16212                 return -EINVAL;
16213         old_rlim = current->signal->rlim + resource;
16214         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16215 -           !capable(CAP_SYS_RESOURCE))
16216 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16217                 return -EPERM;
16218         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16219                 return -EPERM;
16220 diff -NurpP --minimal linux-2.6.27.3/kernel/sysctl.c linux-2.6.27.3-vs2.3.0.35.7/kernel/sysctl.c
16221 --- linux-2.6.27.3/kernel/sysctl.c      2008-10-13 14:52:09.000000000 +0200
16222 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sysctl.c 2008-10-13 14:54:20.000000000 +0200
16223 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16224  #ifdef CONFIG_MODULES
16225  extern char modprobe_path[];
16226  #endif
16227 +extern char vshelper_path[];
16228  #ifdef CONFIG_CHR_DEV_SG
16229  extern int sg_big_buff;
16230  #endif
16231 @@ -500,6 +501,15 @@ static struct ctl_table kern_table[] = {
16232                 .strategy       = &sysctl_string,
16233         },
16234  #endif
16235 +       {
16236 +               .ctl_name       = KERN_VSHELPER,
16237 +               .procname       = "vshelper",
16238 +               .data           = &vshelper_path,
16239 +               .maxlen         = 256,
16240 +               .mode           = 0644,
16241 +               .proc_handler   = &proc_dostring,
16242 +               .strategy       = &sysctl_string,
16243 +       },
16244  #ifdef CONFIG_CHR_DEV_SG
16245         {
16246                 .ctl_name       = KERN_SG_BIG_BUFF,
16247 diff -NurpP --minimal linux-2.6.27.3/kernel/sysctl_check.c linux-2.6.27.3-vs2.3.0.35.7/kernel/sysctl_check.c
16248 --- linux-2.6.27.3/kernel/sysctl_check.c        2008-10-13 14:52:09.000000000 +0200
16249 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/sysctl_check.c   2008-10-13 14:54:20.000000000 +0200
16250 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16251  
16252         { KERN_PANIC,                   "panic" },
16253         { KERN_REALROOTDEV,             "real-root-dev" },
16254 +       { KERN_VSHELPER,                "vshelper", },
16255  
16256         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16257         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16258 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
16259         {}
16260  };
16261  
16262 +static struct trans_ctl_table trans_vserver_table[] = {
16263 +       { 1,    "debug_switch" },
16264 +       { 2,    "debug_xid" },
16265 +       { 3,    "debug_nid" },
16266 +       { 4,    "debug_tag" },
16267 +       { 5,    "debug_net" },
16268 +       { 6,    "debug_limit" },
16269 +       { 7,    "debug_cres" },
16270 +       { 8,    "debug_dlim" },
16271 +       { 9,    "debug_quota" },
16272 +       { 10,   "debug_cvirt" },
16273 +       { 11,   "debug_space" },
16274 +       { 12,   "debug_misc" },
16275 +       {}
16276 +};
16277 +
16278  static const struct trans_ctl_table trans_root_table[] = {
16279         { CTL_KERN,     "kernel",       trans_kern_table },
16280         { CTL_VM,       "vm",           trans_vm_table },
16281 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
16282         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16283         { CTL_PM,       "pm",           trans_pm_table },
16284         { CTL_FRV,      "frv",          trans_frv_table },
16285 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16286         {}
16287  };
16288  
16289 diff -NurpP --minimal linux-2.6.27.3/kernel/time.c linux-2.6.27.3-vs2.3.0.35.7/kernel/time.c
16290 --- linux-2.6.27.3/kernel/time.c        2008-07-13 23:51:29.000000000 +0200
16291 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/time.c   2008-10-13 14:54:20.000000000 +0200
16292 @@ -62,6 +62,7 @@ EXPORT_SYMBOL(sys_tz);
16293  asmlinkage long sys_time(time_t __user * tloc)
16294  {
16295         time_t i = get_seconds();
16296 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16297  
16298         if (tloc) {
16299                 if (put_user(i,tloc))
16300 @@ -91,7 +92,7 @@ asmlinkage long sys_stime(time_t __user 
16301         if (err)
16302                 return err;
16303  
16304 -       do_settimeofday(&tv);
16305 +       vx_settimeofday(&tv);
16306         return 0;
16307  }
16308  
16309 @@ -102,7 +103,7 @@ asmlinkage long sys_gettimeofday(struct 
16310  {
16311         if (likely(tv != NULL)) {
16312                 struct timeval ktv;
16313 -               do_gettimeofday(&ktv);
16314 +               vx_gettimeofday(&ktv);
16315                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16316                         return -EFAULT;
16317         }
16318 @@ -177,7 +178,7 @@ int do_sys_settimeofday(struct timespec 
16319                 /* SMP safe, again the code in arch/foo/time.c should
16320                  * globally block out interrupts when it runs.
16321                  */
16322 -               return do_settimeofday(tv);
16323 +               return vx_settimeofday(tv);
16324         }
16325         return 0;
16326  }
16327 @@ -309,7 +310,7 @@ void getnstimeofday(struct timespec *tv)
16328  {
16329         struct timeval x;
16330  
16331 -       do_gettimeofday(&x);
16332 +       vx_gettimeofday(&x);
16333         tv->tv_sec = x.tv_sec;
16334         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16335  }
16336 diff -NurpP --minimal linux-2.6.27.3/kernel/timer.c linux-2.6.27.3-vs2.3.0.35.7/kernel/timer.c
16337 --- linux-2.6.27.3/kernel/timer.c       2008-10-13 14:52:09.000000000 +0200
16338 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/timer.c  2008-10-13 14:54:20.000000000 +0200
16339 @@ -37,6 +37,10 @@
16340  #include <linux/delay.h>
16341  #include <linux/tick.h>
16342  #include <linux/kallsyms.h>
16343 +#include <linux/vs_base.h>
16344 +#include <linux/vs_cvirt.h>
16345 +#include <linux/vs_pid.h>
16346 +#include <linux/vserver/sched.h>
16347  
16348  #include <asm/uaccess.h>
16349  #include <asm/unistd.h>
16350 @@ -1081,12 +1085,6 @@ asmlinkage unsigned long sys_alarm(unsig
16351  
16352  #endif
16353  
16354 -#ifndef __alpha__
16355 -
16356 -/*
16357 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16358 - * should be moved into arch/i386 instead?
16359 - */
16360  
16361  /**
16362   * sys_getpid - return the thread group id of the current process
16363 @@ -1115,10 +1113,23 @@ asmlinkage long sys_getppid(void)
16364         rcu_read_lock();
16365         pid = task_tgid_vnr(current->real_parent);
16366         rcu_read_unlock();
16367 +       return vx_map_pid(pid);
16368 +}
16369  
16370 -       return pid;
16371 +#ifdef __alpha__
16372 +
16373 +/*
16374 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16375 + */
16376 +
16377 +asmlinkage long do_getxpid(long *ppid)
16378 +{
16379 +       *ppid = sys_getppid();
16380 +       return sys_getpid();
16381  }
16382  
16383 +#else /* _alpha_ */
16384 +
16385  asmlinkage long sys_getuid(void)
16386  {
16387         /* Only we change this so SMP safe */
16388 @@ -1289,6 +1300,8 @@ int do_sysinfo(struct sysinfo *info)
16389                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
16390                         tp.tv_sec++;
16391                 }
16392 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
16393 +                       vx_vsi_uptime(&tp, NULL);
16394                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
16395  
16396                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
16397 diff -NurpP --minimal linux-2.6.27.3/kernel/user.c linux-2.6.27.3-vs2.3.0.35.7/kernel/user.c
16398 --- linux-2.6.27.3/kernel/user.c        2008-07-13 23:51:29.000000000 +0200
16399 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/user.c   2008-10-13 14:54:20.000000000 +0200
16400 @@ -243,12 +243,15 @@ static struct kobj_type uids_ktype = {
16401  };
16402  
16403  /* create /sys/kernel/uids/<uid>/cpu_share file for this user */
16404 -static int uids_user_create(struct user_struct *up)
16405 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
16406  {
16407         struct kobject *kobj = &up->kobj;
16408 -       int error;
16409 +       int error = 0;
16410  
16411         memset(kobj, 0, sizeof(struct kobject));
16412 +       if (ns != &init_user_ns)
16413 +               goto done;
16414 +
16415         kobj->kset = uids_kset;
16416         error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
16417         if (error) {
16418 @@ -272,7 +275,7 @@ int __init uids_sysfs_init(void)
16419         if (!uids_kset)
16420                 return -ENOMEM;
16421  
16422 -       return uids_user_create(&root_user);
16423 +       return uids_user_create(NULL, &root_user);
16424  }
16425  
16426  /* work function to remove sysfs directory for a user and free up
16427 @@ -302,9 +305,11 @@ static void remove_user_sysfs_dir(struct
16428         if (!remove_user)
16429                 goto done;
16430  
16431 -       kobject_uevent(&up->kobj, KOBJ_REMOVE);
16432 -       kobject_del(&up->kobj);
16433 -       kobject_put(&up->kobj);
16434 +       if (up->kobj.name) {
16435 +               kobject_uevent(&up->kobj, KOBJ_REMOVE);
16436 +               kobject_del(&up->kobj);
16437 +               kobject_put(&up->kobj);
16438 +       }
16439  
16440         sched_destroy_user(up);
16441         key_put(up->uid_keyring);
16442 @@ -332,7 +337,8 @@ static inline void free_user(struct user
16443  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
16444  
16445  int uids_sysfs_init(void) { return 0; }
16446 -static inline int uids_user_create(struct user_struct *up) { return 0; }
16447 +static inline int uids_user_create(struct user_namespace *ns,
16448 +       struct user_struct *up) { return 0; }
16449  static inline void uids_mutex_lock(void) { }
16450  static inline void uids_mutex_unlock(void) { }
16451  
16452 @@ -409,7 +415,7 @@ struct user_struct *alloc_uid(struct use
16453                 if (sched_create_user(new) < 0)
16454                         goto out_free_user;
16455  
16456 -               if (uids_user_create(new))
16457 +               if (uids_user_create(ns, new))
16458                         goto out_destoy_sched;
16459  
16460                 /*
16461 diff -NurpP --minimal linux-2.6.27.3/kernel/user_namespace.c linux-2.6.27.3-vs2.3.0.35.7/kernel/user_namespace.c
16462 --- linux-2.6.27.3/kernel/user_namespace.c      2008-10-13 14:52:09.000000000 +0200
16463 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/user_namespace.c 2008-10-13 14:54:20.000000000 +0200
16464 @@ -9,6 +9,7 @@
16465  #include <linux/nsproxy.h>
16466  #include <linux/slab.h>
16467  #include <linux/user_namespace.h>
16468 +#include <linux/vserver/global.h>
16469  
16470  /*
16471   * Clone a new ns copying an original user ns, setting refcount to 1
16472 @@ -26,6 +27,7 @@ static struct user_namespace *clone_user
16473                 return ERR_PTR(-ENOMEM);
16474  
16475         kref_init(&ns->kref);
16476 +       atomic_inc(&vs_global_user_ns);
16477  
16478         for (n = 0; n < UIDHASH_SZ; ++n)
16479                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16480 @@ -71,6 +73,7 @@ void free_user_ns(struct kref *kref)
16481  
16482         ns = container_of(kref, struct user_namespace, kref);
16483         release_uids(ns);
16484 +       atomic_dec(&vs_global_user_ns);
16485         kfree(ns);
16486  }
16487  EXPORT_SYMBOL(free_user_ns);
16488 diff -NurpP --minimal linux-2.6.27.3/kernel/utsname.c linux-2.6.27.3-vs2.3.0.35.7/kernel/utsname.c
16489 --- linux-2.6.27.3/kernel/utsname.c     2008-10-13 14:52:09.000000000 +0200
16490 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/utsname.c        2008-10-13 14:54:20.000000000 +0200
16491 @@ -14,6 +14,7 @@
16492  #include <linux/utsname.h>
16493  #include <linux/err.h>
16494  #include <linux/slab.h>
16495 +#include <linux/vserver/global.h>
16496  
16497  /*
16498   * Clone a new ns copying an original utsname, setting refcount to 1
16499 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
16500         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
16501         up_read(&uts_sem);
16502         kref_init(&ns->kref);
16503 +       atomic_inc(&vs_global_uts_ns);
16504         return ns;
16505  }
16506  
16507 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
16508         struct uts_namespace *ns;
16509  
16510         ns = container_of(kref, struct uts_namespace, kref);
16511 +       atomic_dec(&vs_global_uts_ns);
16512         kfree(ns);
16513  }
16514 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/cacct.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cacct.c
16515 --- linux-2.6.27.3/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
16516 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cacct.c  2008-10-13 14:54:20.000000000 +0200
16517 @@ -0,0 +1,42 @@
16518 +/*
16519 + *  linux/kernel/vserver/cacct.c
16520 + *
16521 + *  Virtual Server: Context Accounting
16522 + *
16523 + *  Copyright (C) 2006-2007 Herbert Pötzl
16524 + *
16525 + *  V0.01  added accounting stats
16526 + *
16527 + */
16528 +
16529 +#include <linux/types.h>
16530 +#include <linux/vs_context.h>
16531 +#include <linux/vserver/cacct_cmd.h>
16532 +#include <linux/vserver/cacct_int.h>
16533 +
16534 +#include <asm/errno.h>
16535 +#include <asm/uaccess.h>
16536 +
16537 +
16538 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16539 +{
16540 +       struct vcmd_sock_stat_v0 vc_data;
16541 +       int j, field;
16542 +
16543 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16544 +               return -EFAULT;
16545 +
16546 +       field = vc_data.field;
16547 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16548 +               return -EINVAL;
16549 +
16550 +       for (j = 0; j < 3; j++) {
16551 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16552 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16553 +       }
16554 +
16555 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16556 +               return -EFAULT;
16557 +       return 0;
16558 +}
16559 +
16560 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/cacct_init.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cacct_init.h
16561 --- linux-2.6.27.3/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
16562 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cacct_init.h     2008-10-13 14:54:20.000000000 +0200
16563 @@ -0,0 +1,25 @@
16564 +
16565 +
16566 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16567 +{
16568 +       int i, j;
16569 +
16570 +
16571 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16572 +               for (j = 0; j < 3; j++) {
16573 +                       atomic_set(&cacct->sock[i][j].count, 0);
16574 +                       atomic_set(&cacct->sock[i][j].total, 0);
16575 +               }
16576 +       }
16577 +       for (i = 0; i < 8; i++)
16578 +               atomic_set(&cacct->slab[i], 0);
16579 +       for (i = 0; i < 5; i++)
16580 +               for (j = 0; j < 4; j++)
16581 +                       atomic_set(&cacct->page[i][j], 0);
16582 +}
16583 +
16584 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16585 +{
16586 +       return;
16587 +}
16588 +
16589 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/cacct_proc.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cacct_proc.h
16590 --- linux-2.6.27.3/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
16591 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cacct_proc.h     2008-10-13 14:54:20.000000000 +0200
16592 @@ -0,0 +1,53 @@
16593 +#ifndef _VX_CACCT_PROC_H
16594 +#define _VX_CACCT_PROC_H
16595 +
16596 +#include <linux/vserver/cacct_int.h>
16597 +
16598 +
16599 +#define VX_SOCKA_TOP   \
16600 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16601 +
16602 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16603 +{
16604 +       int i, j, length = 0;
16605 +       static char *type[VXA_SOCK_SIZE] = {
16606 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16607 +       };
16608 +
16609 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16610 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16611 +               length += sprintf(buffer + length, "%s:", type[i]);
16612 +               for (j = 0; j < 3; j++) {
16613 +                       length += sprintf(buffer + length,
16614 +                               "\t%10lu/%-10lu",
16615 +                               vx_sock_count(cacct, i, j),
16616 +                               vx_sock_total(cacct, i, j));
16617 +               }
16618 +               buffer[length++] = '\n';
16619 +       }
16620 +
16621 +       length += sprintf(buffer + length, "\n");
16622 +       length += sprintf(buffer + length,
16623 +               "slab:\t %8u %8u %8u %8u\n",
16624 +               atomic_read(&cacct->slab[1]),
16625 +               atomic_read(&cacct->slab[4]),
16626 +               atomic_read(&cacct->slab[0]),
16627 +               atomic_read(&cacct->slab[2]));
16628 +
16629 +       length += sprintf(buffer + length, "\n");
16630 +       for (i = 0; i < 5; i++) {
16631 +               length += sprintf(buffer + length,
16632 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16633 +                       atomic_read(&cacct->page[i][0]),
16634 +                       atomic_read(&cacct->page[i][1]),
16635 +                       atomic_read(&cacct->page[i][2]),
16636 +                       atomic_read(&cacct->page[i][3]),
16637 +                       atomic_read(&cacct->page[i][4]),
16638 +                       atomic_read(&cacct->page[i][5]),
16639 +                       atomic_read(&cacct->page[i][6]),
16640 +                       atomic_read(&cacct->page[i][7]));
16641 +       }
16642 +       return length;
16643 +}
16644 +
16645 +#endif /* _VX_CACCT_PROC_H */
16646 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/context.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/context.c
16647 --- linux-2.6.27.3/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
16648 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/context.c        2008-10-13 14:54:20.000000000 +0200
16649 @@ -0,0 +1,1010 @@
16650 +/*
16651 + *  linux/kernel/vserver/context.c
16652 + *
16653 + *  Virtual Server: Context Support
16654 + *
16655 + *  Copyright (C) 2003-2007  Herbert Pötzl
16656 + *
16657 + *  V0.01  context helper
16658 + *  V0.02  vx_ctx_kill syscall command
16659 + *  V0.03  replaced context_info calls
16660 + *  V0.04  redesign of struct (de)alloc
16661 + *  V0.05  rlimit basic implementation
16662 + *  V0.06  task_xid and info commands
16663 + *  V0.07  context flags and caps
16664 + *  V0.08  switch to RCU based hash
16665 + *  V0.09  revert to non RCU for now
16666 + *  V0.10  and back to working RCU hash
16667 + *  V0.11  and back to locking again
16668 + *  V0.12  referenced context store
16669 + *  V0.13  separate per cpu data
16670 + *  V0.14  changed vcmds to vxi arg
16671 + *  V0.15  added context stat
16672 + *  V0.16  have __create claim() the vxi
16673 + *  V0.17  removed older and legacy stuff
16674 + *
16675 + */
16676 +
16677 +#include <linux/slab.h>
16678 +#include <linux/types.h>
16679 +#include <linux/security.h>
16680 +#include <linux/pid_namespace.h>
16681 +
16682 +#include <linux/vserver/context.h>
16683 +#include <linux/vserver/network.h>
16684 +#include <linux/vserver/debug.h>
16685 +#include <linux/vserver/limit.h>
16686 +#include <linux/vserver/limit_int.h>
16687 +#include <linux/vserver/space.h>
16688 +
16689 +#include <linux/vs_context.h>
16690 +#include <linux/vs_limit.h>
16691 +#include <linux/vs_pid.h>
16692 +#include <linux/vserver/context_cmd.h>
16693 +
16694 +#include "cvirt_init.h"
16695 +#include "cacct_init.h"
16696 +#include "limit_init.h"
16697 +#include "sched_init.h"
16698 +
16699 +
16700 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16701 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16702 +
16703 +
16704 +/*     now inactive context structures */
16705 +
16706 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16707 +
16708 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16709 +
16710 +
16711 +/*     __alloc_vx_info()
16712 +
16713 +       * allocate an initialized vx_info struct
16714 +       * doesn't make it visible (hash)                        */
16715 +
16716 +static struct vx_info *__alloc_vx_info(xid_t xid)
16717 +{
16718 +       struct vx_info *new = NULL;
16719 +       int cpu;
16720 +
16721 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16722 +
16723 +       /* would this benefit from a slab cache? */
16724 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16725 +       if (!new)
16726 +               return 0;
16727 +
16728 +       memset(new, 0, sizeof(struct vx_info));
16729 +#ifdef CONFIG_SMP
16730 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16731 +       if (!new->ptr_pc)
16732 +               goto error;
16733 +#endif
16734 +       new->vx_id = xid;
16735 +       INIT_HLIST_NODE(&new->vx_hlist);
16736 +       atomic_set(&new->vx_usecnt, 0);
16737 +       atomic_set(&new->vx_tasks, 0);
16738 +       new->vx_parent = NULL;
16739 +       new->vx_state = 0;
16740 +       init_waitqueue_head(&new->vx_wait);
16741 +
16742 +       /* prepare reaper */
16743 +       get_task_struct(init_pid_ns.child_reaper);
16744 +       new->vx_reaper = init_pid_ns.child_reaper;
16745 +       new->vx_badness_bias = 0;
16746 +
16747 +       /* rest of init goes here */
16748 +       vx_info_init_limit(&new->limit);
16749 +       vx_info_init_sched(&new->sched);
16750 +       vx_info_init_cvirt(&new->cvirt);
16751 +       vx_info_init_cacct(&new->cacct);
16752 +
16753 +       /* per cpu data structures */
16754 +       for_each_possible_cpu(cpu) {
16755 +               vx_info_init_sched_pc(
16756 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16757 +               vx_info_init_cvirt_pc(
16758 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16759 +       }
16760 +
16761 +       new->vx_flags = VXF_INIT_SET;
16762 +       cap_set_init_eff(new->vx_bcaps);
16763 +       new->vx_ccaps = 0;
16764 +       // new->vx_cap_bset = current->cap_bset;
16765 +
16766 +       new->reboot_cmd = 0;
16767 +       new->exit_code = 0;
16768 +
16769 +       vxdprintk(VXD_CBIT(xid, 0),
16770 +               "alloc_vx_info(%d) = %p", xid, new);
16771 +       vxh_alloc_vx_info(new);
16772 +       atomic_inc(&vx_global_ctotal);
16773 +       return new;
16774 +#ifdef CONFIG_SMP
16775 +error:
16776 +       kfree(new);
16777 +       return 0;
16778 +#endif
16779 +}
16780 +
16781 +/*     __dealloc_vx_info()
16782 +
16783 +       * final disposal of vx_info                             */
16784 +
16785 +static void __dealloc_vx_info(struct vx_info *vxi)
16786 +{
16787 +       struct vx_info_save vxis;
16788 +       int cpu;
16789 +
16790 +       vxdprintk(VXD_CBIT(xid, 0),
16791 +               "dealloc_vx_info(%p)", vxi);
16792 +       vxh_dealloc_vx_info(vxi);
16793 +
16794 +#ifdef CONFIG_VSERVER_WARN
16795 +       enter_vx_info(vxi, &vxis);
16796 +       vx_info_exit_limit(&vxi->limit);
16797 +       vx_info_exit_sched(&vxi->sched);
16798 +       vx_info_exit_cvirt(&vxi->cvirt);
16799 +       vx_info_exit_cacct(&vxi->cacct);
16800 +
16801 +       for_each_possible_cpu(cpu) {
16802 +               vx_info_exit_sched_pc(
16803 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16804 +               vx_info_exit_cvirt_pc(
16805 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16806 +       }
16807 +       leave_vx_info(&vxis);
16808 +#endif
16809 +
16810 +       vxi->vx_id = -1;
16811 +       vxi->vx_state |= VXS_RELEASED;
16812 +
16813 +#ifdef CONFIG_SMP
16814 +       free_percpu(vxi->ptr_pc);
16815 +#endif
16816 +       kfree(vxi);
16817 +       atomic_dec(&vx_global_ctotal);
16818 +}
16819 +
16820 +static void __shutdown_vx_info(struct vx_info *vxi)
16821 +{
16822 +       struct nsproxy *nsproxy;
16823 +       struct fs_struct *fs;
16824 +
16825 +       might_sleep();
16826 +
16827 +       vxi->vx_state |= VXS_SHUTDOWN;
16828 +       vs_state_change(vxi, VSC_SHUTDOWN);
16829 +
16830 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
16831 +       fs = xchg(&vxi->vx_fs, NULL);
16832 +
16833 +       if (nsproxy)
16834 +               put_nsproxy(nsproxy);
16835 +       if (fs)
16836 +               put_fs_struct(fs);
16837 +}
16838 +
16839 +/* exported stuff */
16840 +
16841 +void free_vx_info(struct vx_info *vxi)
16842 +{
16843 +       unsigned long flags;
16844 +
16845 +       /* check for reference counts first */
16846 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16847 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16848 +
16849 +       /* context must not be hashed */
16850 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16851 +
16852 +       /* context shutdown is mandatory */
16853 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16854 +
16855 +       BUG_ON(vxi->vx_nsproxy);
16856 +       BUG_ON(vxi->vx_fs);
16857 +
16858 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16859 +       hlist_del(&vxi->vx_hlist);
16860 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16861 +
16862 +       __dealloc_vx_info(vxi);
16863 +}
16864 +
16865 +
16866 +/*     hash table for vx_info hash */
16867 +
16868 +#define VX_HASH_SIZE   13
16869 +
16870 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16871 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16872 +
16873 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16874 +
16875 +
16876 +static inline unsigned int __hashval(xid_t xid)
16877 +{
16878 +       return (xid % VX_HASH_SIZE);
16879 +}
16880 +
16881 +
16882 +
16883 +/*     __hash_vx_info()
16884 +
16885 +       * add the vxi to the global hash table
16886 +       * requires the hash_lock to be held                     */
16887 +
16888 +static inline void __hash_vx_info(struct vx_info *vxi)
16889 +{
16890 +       struct hlist_head *head;
16891 +
16892 +       vxd_assert_lock(&vx_info_hash_lock);
16893 +       vxdprintk(VXD_CBIT(xid, 4),
16894 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16895 +       vxh_hash_vx_info(vxi);
16896 +
16897 +       /* context must not be hashed */
16898 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16899 +
16900 +       vxi->vx_state |= VXS_HASHED;
16901 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16902 +       hlist_add_head(&vxi->vx_hlist, head);
16903 +       atomic_inc(&vx_global_cactive);
16904 +}
16905 +
16906 +/*     __unhash_vx_info()
16907 +
16908 +       * remove the vxi from the global hash table
16909 +       * requires the hash_lock to be held                     */
16910 +
16911 +static inline void __unhash_vx_info(struct vx_info *vxi)
16912 +{
16913 +       unsigned long flags;
16914 +
16915 +       vxd_assert_lock(&vx_info_hash_lock);
16916 +       vxdprintk(VXD_CBIT(xid, 4),
16917 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16918 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16919 +       vxh_unhash_vx_info(vxi);
16920 +
16921 +       /* context must be hashed */
16922 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16923 +       /* but without tasks */
16924 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16925 +
16926 +       vxi->vx_state &= ~VXS_HASHED;
16927 +       hlist_del_init(&vxi->vx_hlist);
16928 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16929 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16930 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16931 +       atomic_dec(&vx_global_cactive);
16932 +}
16933 +
16934 +
16935 +/*     __lookup_vx_info()
16936 +
16937 +       * requires the hash_lock to be held
16938 +       * doesn't increment the vx_refcnt                       */
16939 +
16940 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16941 +{
16942 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16943 +       struct hlist_node *pos;
16944 +       struct vx_info *vxi;
16945 +
16946 +       vxd_assert_lock(&vx_info_hash_lock);
16947 +       hlist_for_each(pos, head) {
16948 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16949 +
16950 +               if (vxi->vx_id == xid)
16951 +                       goto found;
16952 +       }
16953 +       vxi = NULL;
16954 +found:
16955 +       vxdprintk(VXD_CBIT(xid, 0),
16956 +               "__lookup_vx_info(#%u): %p[#%u]",
16957 +               xid, vxi, vxi ? vxi->vx_id : 0);
16958 +       vxh_lookup_vx_info(vxi, xid);
16959 +       return vxi;
16960 +}
16961 +
16962 +
16963 +/*     __create_vx_info()
16964 +
16965 +       * create the requested context
16966 +       * get(), claim() and hash it                            */
16967 +
16968 +static struct vx_info *__create_vx_info(int id)
16969 +{
16970 +       struct vx_info *new, *vxi = NULL;
16971 +
16972 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16973 +
16974 +       if (!(new = __alloc_vx_info(id)))
16975 +               return ERR_PTR(-ENOMEM);
16976 +
16977 +       /* required to make dynamic xids unique */
16978 +       spin_lock(&vx_info_hash_lock);
16979 +
16980 +       /* static context requested */
16981 +       if ((vxi = __lookup_vx_info(id))) {
16982 +               vxdprintk(VXD_CBIT(xid, 0),
16983 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16984 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16985 +                       vxi = ERR_PTR(-EBUSY);
16986 +               else
16987 +                       vxi = ERR_PTR(-EEXIST);
16988 +               goto out_unlock;
16989 +       }
16990 +       /* new context */
16991 +       vxdprintk(VXD_CBIT(xid, 0),
16992 +               "create_vx_info(%d) = %p (new)", id, new);
16993 +       claim_vx_info(new, NULL);
16994 +       __hash_vx_info(get_vx_info(new));
16995 +       vxi = new, new = NULL;
16996 +
16997 +out_unlock:
16998 +       spin_unlock(&vx_info_hash_lock);
16999 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17000 +       if (new)
17001 +               __dealloc_vx_info(new);
17002 +       return vxi;
17003 +}
17004 +
17005 +
17006 +/*     exported stuff                                          */
17007 +
17008 +
17009 +void unhash_vx_info(struct vx_info *vxi)
17010 +{
17011 +       __shutdown_vx_info(vxi);
17012 +       spin_lock(&vx_info_hash_lock);
17013 +       __unhash_vx_info(vxi);
17014 +       spin_unlock(&vx_info_hash_lock);
17015 +       __wakeup_vx_info(vxi);
17016 +}
17017 +
17018 +
17019 +/*     lookup_vx_info()
17020 +
17021 +       * search for a vx_info and get() it
17022 +       * negative id means current                             */
17023 +
17024 +struct vx_info *lookup_vx_info(int id)
17025 +{
17026 +       struct vx_info *vxi = NULL;
17027 +
17028 +       if (id < 0) {
17029 +               vxi = get_vx_info(current->vx_info);
17030 +       } else if (id > 1) {
17031 +               spin_lock(&vx_info_hash_lock);
17032 +               vxi = get_vx_info(__lookup_vx_info(id));
17033 +               spin_unlock(&vx_info_hash_lock);
17034 +       }
17035 +       return vxi;
17036 +}
17037 +
17038 +/*     xid_is_hashed()
17039 +
17040 +       * verify that xid is still hashed                       */
17041 +
17042 +int xid_is_hashed(xid_t xid)
17043 +{
17044 +       int hashed;
17045 +
17046 +       spin_lock(&vx_info_hash_lock);
17047 +       hashed = (__lookup_vx_info(xid) != NULL);
17048 +       spin_unlock(&vx_info_hash_lock);
17049 +       return hashed;
17050 +}
17051 +
17052 +#ifdef CONFIG_PROC_FS
17053 +
17054 +/*     get_xid_list()
17055 +
17056 +       * get a subset of hashed xids for proc
17057 +       * assumes size is at least one                          */
17058 +
17059 +int get_xid_list(int index, unsigned int *xids, int size)
17060 +{
17061 +       int hindex, nr_xids = 0;
17062 +
17063 +       /* only show current and children */
17064 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17065 +               if (index > 0)
17066 +                       return 0;
17067 +               xids[nr_xids] = vx_current_xid();
17068 +               return 1;
17069 +       }
17070 +
17071 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17072 +               struct hlist_head *head = &vx_info_hash[hindex];
17073 +               struct hlist_node *pos;
17074 +
17075 +               spin_lock(&vx_info_hash_lock);
17076 +               hlist_for_each(pos, head) {
17077 +                       struct vx_info *vxi;
17078 +
17079 +                       if (--index > 0)
17080 +                               continue;
17081 +
17082 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17083 +                       xids[nr_xids] = vxi->vx_id;
17084 +                       if (++nr_xids >= size) {
17085 +                               spin_unlock(&vx_info_hash_lock);
17086 +                               goto out;
17087 +                       }
17088 +               }
17089 +               /* keep the lock time short */
17090 +               spin_unlock(&vx_info_hash_lock);
17091 +       }
17092 +out:
17093 +       return nr_xids;
17094 +}
17095 +#endif
17096 +
17097 +#ifdef CONFIG_VSERVER_DEBUG
17098 +
17099 +void   dump_vx_info_inactive(int level)
17100 +{
17101 +       struct hlist_node *entry, *next;
17102 +
17103 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17104 +               struct vx_info *vxi =
17105 +                       list_entry(entry, struct vx_info, vx_hlist);
17106 +
17107 +               dump_vx_info(vxi, level);
17108 +       }
17109 +}
17110 +
17111 +#endif
17112 +
17113 +#if 0
17114 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17115 +{
17116 +       struct user_struct *new_user, *old_user;
17117 +
17118 +       if (!p || !vxi)
17119 +               BUG();
17120 +
17121 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17122 +               return -EACCES;
17123 +
17124 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17125 +       if (!new_user)
17126 +               return -ENOMEM;
17127 +
17128 +       old_user = p->user;
17129 +       if (new_user != old_user) {
17130 +               atomic_inc(&new_user->processes);
17131 +               atomic_dec(&old_user->processes);
17132 +               p->user = new_user;
17133 +       }
17134 +       free_uid(old_user);
17135 +       return 0;
17136 +}
17137 +#endif
17138 +
17139 +#if 0
17140 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17141 +{
17142 +       // p->cap_effective &= vxi->vx_cap_bset;
17143 +       p->cap_effective =
17144 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17145 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17146 +       p->cap_inheritable =
17147 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17148 +       // p->cap_permitted &= vxi->vx_cap_bset;
17149 +       p->cap_permitted =
17150 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17151 +}
17152 +#endif
17153 +
17154 +
17155 +#include <linux/file.h>
17156 +#include <linux/fdtable.h>
17157 +
17158 +static int vx_openfd_task(struct task_struct *tsk)
17159 +{
17160 +       struct files_struct *files = tsk->files;
17161 +       struct fdtable *fdt;
17162 +       const unsigned long *bptr;
17163 +       int count, total;
17164 +
17165 +       /* no rcu_read_lock() because of spin_lock() */
17166 +       spin_lock(&files->file_lock);
17167 +       fdt = files_fdtable(files);
17168 +       bptr = fdt->open_fds->fds_bits;
17169 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17170 +       for (total = 0; count > 0; count--) {
17171 +               if (*bptr)
17172 +                       total += hweight_long(*bptr);
17173 +               bptr++;
17174 +       }
17175 +       spin_unlock(&files->file_lock);
17176 +       return total;
17177 +}
17178 +
17179 +
17180 +/*     for *space compatibility */
17181 +
17182 +asmlinkage long sys_unshare(unsigned long);
17183 +
17184 +/*
17185 + *     migrate task to new context
17186 + *     gets vxi, puts old_vxi on change
17187 + *     optionally unshares namespaces (hack)
17188 + */
17189 +
17190 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17191 +{
17192 +       struct vx_info *old_vxi;
17193 +       int ret = 0;
17194 +
17195 +       if (!p || !vxi)
17196 +               BUG();
17197 +
17198 +       vxdprintk(VXD_CBIT(xid, 5),
17199 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17200 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17201 +
17202 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17203 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17204 +               return -EACCES;
17205 +
17206 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17207 +               return -EFAULT;
17208 +
17209 +       old_vxi = task_get_vx_info(p);
17210 +       if (old_vxi == vxi)
17211 +               goto out;
17212 +
17213 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17214 +       {
17215 +               int openfd;
17216 +
17217 +               task_lock(p);
17218 +               openfd = vx_openfd_task(p);
17219 +
17220 +               if (old_vxi) {
17221 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17222 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17223 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17224 +                       /* FIXME: what about the struct files here? */
17225 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17226 +                       /* account for the executable */
17227 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17228 +               }
17229 +               atomic_inc(&vxi->cvirt.nr_threads);
17230 +               atomic_inc(&vxi->cvirt.nr_running);
17231 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17232 +               /* FIXME: what about the struct files here? */
17233 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17234 +               /* account for the executable */
17235 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17236 +
17237 +               if (old_vxi) {
17238 +                       release_vx_info(old_vxi, p);
17239 +                       clr_vx_info(&p->vx_info);
17240 +               }
17241 +               claim_vx_info(vxi, p);
17242 +               set_vx_info(&p->vx_info, vxi);
17243 +               p->xid = vxi->vx_id;
17244 +
17245 +               vxdprintk(VXD_CBIT(xid, 5),
17246 +                       "moved task %p into vxi:%p[#%d]",
17247 +                       p, vxi, vxi->vx_id);
17248 +
17249 +               // vx_mask_cap_bset(vxi, p);
17250 +               task_unlock(p);
17251 +
17252 +               /* hack for *spaces to provide compatibility */
17253 +               if (unshare) {
17254 +                       struct nsproxy *old_nsp, *new_nsp;
17255 +
17256 +                       ret = unshare_nsproxy_namespaces(
17257 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17258 +                               &new_nsp, NULL);
17259 +                       if (ret)
17260 +                               goto out;
17261 +
17262 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17263 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER);
17264 +                       put_nsproxy(old_nsp);
17265 +               }
17266 +       }
17267 +out:
17268 +       put_vx_info(old_vxi);
17269 +       return ret;
17270 +}
17271 +
17272 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17273 +{
17274 +       struct task_struct *old_reaper;
17275 +
17276 +       if (!vxi)
17277 +               return -EINVAL;
17278 +
17279 +       vxdprintk(VXD_CBIT(xid, 6),
17280 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17281 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17282 +
17283 +       old_reaper = vxi->vx_reaper;
17284 +       if (old_reaper == p)
17285 +               return 0;
17286 +
17287 +       /* set new child reaper */
17288 +       get_task_struct(p);
17289 +       vxi->vx_reaper = p;
17290 +       put_task_struct(old_reaper);
17291 +       return 0;
17292 +}
17293 +
17294 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17295 +{
17296 +       if (!vxi)
17297 +               return -EINVAL;
17298 +
17299 +       vxdprintk(VXD_CBIT(xid, 6),
17300 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17301 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17302 +
17303 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17304 +       vxi->vx_initpid = p->tgid;
17305 +       return 0;
17306 +}
17307 +
17308 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17309 +{
17310 +       vxdprintk(VXD_CBIT(xid, 6),
17311 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17312 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17313 +
17314 +       vxi->exit_code = code;
17315 +       vxi->vx_initpid = 0;
17316 +}
17317 +
17318 +
17319 +void vx_set_persistent(struct vx_info *vxi)
17320 +{
17321 +       vxdprintk(VXD_CBIT(xid, 6),
17322 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17323 +
17324 +       get_vx_info(vxi);
17325 +       claim_vx_info(vxi, NULL);
17326 +}
17327 +
17328 +void vx_clear_persistent(struct vx_info *vxi)
17329 +{
17330 +       vxdprintk(VXD_CBIT(xid, 6),
17331 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17332 +
17333 +       release_vx_info(vxi, NULL);
17334 +       put_vx_info(vxi);
17335 +}
17336 +
17337 +void vx_update_persistent(struct vx_info *vxi)
17338 +{
17339 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17340 +               vx_set_persistent(vxi);
17341 +       else
17342 +               vx_clear_persistent(vxi);
17343 +}
17344 +
17345 +
17346 +/*     task must be current or locked          */
17347 +
17348 +void   exit_vx_info(struct task_struct *p, int code)
17349 +{
17350 +       struct vx_info *vxi = p->vx_info;
17351 +
17352 +       if (vxi) {
17353 +               atomic_dec(&vxi->cvirt.nr_threads);
17354 +               vx_nproc_dec(p);
17355 +
17356 +               vxi->exit_code = code;
17357 +               release_vx_info(vxi, p);
17358 +       }
17359 +}
17360 +
17361 +void   exit_vx_info_early(struct task_struct *p, int code)
17362 +{
17363 +       struct vx_info *vxi = p->vx_info;
17364 +
17365 +       if (vxi) {
17366 +               if (vxi->vx_initpid == p->tgid)
17367 +                       vx_exit_init(vxi, p, code);
17368 +               if (vxi->vx_reaper == p)
17369 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17370 +       }
17371 +}
17372 +
17373 +
17374 +/* vserver syscall commands below here */
17375 +
17376 +/* taks xid and vx_info functions */
17377 +
17378 +#include <asm/uaccess.h>
17379 +
17380 +
17381 +int vc_task_xid(uint32_t id)
17382 +{
17383 +       xid_t xid;
17384 +
17385 +       if (id) {
17386 +               struct task_struct *tsk;
17387 +
17388 +               read_lock(&tasklist_lock);
17389 +               tsk = find_task_by_real_pid(id);
17390 +               xid = (tsk) ? tsk->xid : -ESRCH;
17391 +               read_unlock(&tasklist_lock);
17392 +       } else
17393 +               xid = vx_current_xid();
17394 +       return xid;
17395 +}
17396 +
17397 +
17398 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17399 +{
17400 +       struct vcmd_vx_info_v0 vc_data;
17401 +
17402 +       vc_data.xid = vxi->vx_id;
17403 +       vc_data.initpid = vxi->vx_initpid;
17404 +
17405 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17406 +               return -EFAULT;
17407 +       return 0;
17408 +}
17409 +
17410 +
17411 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17412 +{
17413 +       struct vcmd_ctx_stat_v0 vc_data;
17414 +
17415 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17416 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17417 +
17418 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17419 +               return -EFAULT;
17420 +       return 0;
17421 +}
17422 +
17423 +
17424 +/* context functions */
17425 +
17426 +int vc_ctx_create(uint32_t xid, void __user *data)
17427 +{
17428 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17429 +       struct vx_info *new_vxi;
17430 +       int ret;
17431 +
17432 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17433 +               return -EFAULT;
17434 +
17435 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17436 +               return -EINVAL;
17437 +
17438 +       new_vxi = __create_vx_info(xid);
17439 +       if (IS_ERR(new_vxi))
17440 +               return PTR_ERR(new_vxi);
17441 +
17442 +       /* initial flags */
17443 +       new_vxi->vx_flags = vc_data.flagword;
17444 +
17445 +       ret = -ENOEXEC;
17446 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17447 +               goto out;
17448 +
17449 +       ret = vx_migrate_task(current, new_vxi, (!data));
17450 +       if (ret)
17451 +               goto out;
17452 +
17453 +       /* return context id on success */
17454 +       ret = new_vxi->vx_id;
17455 +
17456 +       /* get a reference for persistent contexts */
17457 +       if ((vc_data.flagword & VXF_PERSISTENT))
17458 +               vx_set_persistent(new_vxi);
17459 +out:
17460 +       release_vx_info(new_vxi, NULL);
17461 +       put_vx_info(new_vxi);
17462 +       return ret;
17463 +}
17464 +
17465 +
17466 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17467 +{
17468 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17469 +       int ret;
17470 +
17471 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17472 +               return -EFAULT;
17473 +
17474 +       ret = vx_migrate_task(current, vxi, 0);
17475 +       if (ret)
17476 +               return ret;
17477 +       if (vc_data.flagword & VXM_SET_INIT)
17478 +               ret = vx_set_init(vxi, current);
17479 +       if (ret)
17480 +               return ret;
17481 +       if (vc_data.flagword & VXM_SET_REAPER)
17482 +               ret = vx_set_reaper(vxi, current);
17483 +       return ret;
17484 +}
17485 +
17486 +
17487 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17488 +{
17489 +       struct vcmd_ctx_flags_v0 vc_data;
17490 +
17491 +       vc_data.flagword = vxi->vx_flags;
17492 +
17493 +       /* special STATE flag handling */
17494 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17495 +
17496 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17497 +               return -EFAULT;
17498 +       return 0;
17499 +}
17500 +
17501 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17502 +{
17503 +       struct vcmd_ctx_flags_v0 vc_data;
17504 +       uint64_t mask, trigger;
17505 +
17506 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17507 +               return -EFAULT;
17508 +
17509 +       /* special STATE flag handling */
17510 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17511 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17512 +
17513 +       if (vxi == current->vx_info) {
17514 +               /* if (trigger & VXF_STATE_SETUP)
17515 +                       vx_mask_cap_bset(vxi, current); */
17516 +               if (trigger & VXF_STATE_INIT) {
17517 +                       int ret;
17518 +
17519 +                       ret = vx_set_init(vxi, current);
17520 +                       if (ret)
17521 +                               return ret;
17522 +                       ret = vx_set_reaper(vxi, current);
17523 +                       if (ret)
17524 +                               return ret;
17525 +               }
17526 +       }
17527 +
17528 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17529 +               vc_data.flagword, mask);
17530 +       if (trigger & VXF_PERSISTENT)
17531 +               vx_update_persistent(vxi);
17532 +
17533 +       return 0;
17534 +}
17535 +
17536 +
17537 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17538 +{
17539 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17540 +
17541 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17542 +       return v;
17543 +}
17544 +
17545 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17546 +{
17547 +       kernel_cap_t c = __cap_empty_set;
17548 +
17549 +       c.cap[0] = v & 0xFFFFFFFF;
17550 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17551 +
17552 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17553 +       return c;
17554 +}
17555 +
17556 +
17557 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17558 +{
17559 +       if (bcaps)
17560 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17561 +       if (ccaps)
17562 +               *ccaps = vxi->vx_ccaps;
17563 +
17564 +       return 0;
17565 +}
17566 +
17567 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17568 +{
17569 +       struct vcmd_ctx_caps_v1 vc_data;
17570 +       int ret;
17571 +
17572 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17573 +       if (ret)
17574 +               return ret;
17575 +       vc_data.cmask = ~0ULL;
17576 +
17577 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17578 +               return -EFAULT;
17579 +       return 0;
17580 +}
17581 +
17582 +static int do_set_caps(struct vx_info *vxi,
17583 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17584 +{
17585 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17586 +
17587 +#if 0
17588 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17589 +               bcaps, bmask, ccaps, cmask);
17590 +#endif
17591 +       vxi->vx_bcaps = cap_t_from_caps(
17592 +               vs_mask_flags(bcold, bcaps, bmask));
17593 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17594 +
17595 +       return 0;
17596 +}
17597 +
17598 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17599 +{
17600 +       struct vcmd_ctx_caps_v1 vc_data;
17601 +
17602 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17603 +               return -EFAULT;
17604 +
17605 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17606 +}
17607 +
17608 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17609 +{
17610 +       struct vcmd_bcaps vc_data;
17611 +       int ret;
17612 +
17613 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17614 +       if (ret)
17615 +               return ret;
17616 +       vc_data.bmask = ~0ULL;
17617 +
17618 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17619 +               return -EFAULT;
17620 +       return 0;
17621 +}
17622 +
17623 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17624 +{
17625 +       struct vcmd_bcaps vc_data;
17626 +
17627 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17628 +               return -EFAULT;
17629 +
17630 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17631 +}
17632 +
17633 +
17634 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17635 +{
17636 +       struct vcmd_badness_v0 vc_data;
17637 +
17638 +       vc_data.bias = vxi->vx_badness_bias;
17639 +
17640 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17641 +               return -EFAULT;
17642 +       return 0;
17643 +}
17644 +
17645 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17646 +{
17647 +       struct vcmd_badness_v0 vc_data;
17648 +
17649 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17650 +               return -EFAULT;
17651 +
17652 +       vxi->vx_badness_bias = vc_data.bias;
17653 +       return 0;
17654 +}
17655 +
17656 +#include <linux/module.h>
17657 +
17658 +EXPORT_SYMBOL_GPL(free_vx_info);
17659 +
17660 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/cvirt.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cvirt.c
17661 --- linux-2.6.27.3/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
17662 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cvirt.c  2008-10-13 14:54:20.000000000 +0200
17663 @@ -0,0 +1,301 @@
17664 +/*
17665 + *  linux/kernel/vserver/cvirt.c
17666 + *
17667 + *  Virtual Server: Context Virtualization
17668 + *
17669 + *  Copyright (C) 2004-2007  Herbert Pötzl
17670 + *
17671 + *  V0.01  broken out from limit.c
17672 + *  V0.02  added utsname stuff
17673 + *  V0.03  changed vcmds to vxi arg
17674 + *
17675 + */
17676 +
17677 +#include <linux/types.h>
17678 +#include <linux/utsname.h>
17679 +#include <linux/vs_cvirt.h>
17680 +#include <linux/vserver/switch.h>
17681 +#include <linux/vserver/cvirt_cmd.h>
17682 +
17683 +#include <asm/uaccess.h>
17684 +
17685 +
17686 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17687 +{
17688 +       struct vx_info *vxi = current->vx_info;
17689 +
17690 +       set_normalized_timespec(uptime,
17691 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17692 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17693 +       if (!idle)
17694 +               return;
17695 +       set_normalized_timespec(idle,
17696 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17697 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17698 +       return;
17699 +}
17700 +
17701 +uint64_t vx_idle_jiffies(void)
17702 +{
17703 +       return init_task.utime + init_task.stime;
17704 +}
17705 +
17706 +
17707 +
17708 +static inline uint32_t __update_loadavg(uint32_t load,
17709 +       int wsize, int delta, int n)
17710 +{
17711 +       unsigned long long calc, prev;
17712 +
17713 +       /* just set it to n */
17714 +       if (unlikely(delta >= wsize))
17715 +               return (n << FSHIFT);
17716 +
17717 +       calc = delta * n;
17718 +       calc <<= FSHIFT;
17719 +       prev = (wsize - delta);
17720 +       prev *= load;
17721 +       calc += prev;
17722 +       do_div(calc, wsize);
17723 +       return calc;
17724 +}
17725 +
17726 +
17727 +void vx_update_load(struct vx_info *vxi)
17728 +{
17729 +       uint32_t now, last, delta;
17730 +       unsigned int nr_running, nr_uninterruptible;
17731 +       unsigned int total;
17732 +       unsigned long flags;
17733 +
17734 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17735 +
17736 +       now = jiffies;
17737 +       last = vxi->cvirt.load_last;
17738 +       delta = now - last;
17739 +
17740 +       if (delta < 5*HZ)
17741 +               goto out;
17742 +
17743 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17744 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17745 +       total = nr_running + nr_uninterruptible;
17746 +
17747 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17748 +               60*HZ, delta, total);
17749 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17750 +               5*60*HZ, delta, total);
17751 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17752 +               15*60*HZ, delta, total);
17753 +
17754 +       vxi->cvirt.load_last = now;
17755 +out:
17756 +       atomic_inc(&vxi->cvirt.load_updates);
17757 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17758 +}
17759 +
17760 +
17761 +/*
17762 + * Commands to do_syslog:
17763 + *
17764 + *      0 -- Close the log.  Currently a NOP.
17765 + *      1 -- Open the log. Currently a NOP.
17766 + *      2 -- Read from the log.
17767 + *      3 -- Read all messages remaining in the ring buffer.
17768 + *      4 -- Read and clear all messages remaining in the ring buffer
17769 + *      5 -- Clear ring buffer.
17770 + *      6 -- Disable printk's to console
17771 + *      7 -- Enable printk's to console
17772 + *      8 -- Set level of messages printed to console
17773 + *      9 -- Return number of unread characters in the log buffer
17774 + *     10 -- Return size of the log buffer
17775 + */
17776 +int vx_do_syslog(int type, char __user *buf, int len)
17777 +{
17778 +       int error = 0;
17779 +       int do_clear = 0;
17780 +       struct vx_info *vxi = current->vx_info;
17781 +       struct _vx_syslog *log;
17782 +
17783 +       if (!vxi)
17784 +               return -EINVAL;
17785 +       log = &vxi->cvirt.syslog;
17786 +
17787 +       switch (type) {
17788 +       case 0:         /* Close log */
17789 +       case 1:         /* Open log */
17790 +               break;
17791 +       case 2:         /* Read from log */
17792 +               error = wait_event_interruptible(log->log_wait,
17793 +                       (log->log_start - log->log_end));
17794 +               if (error)
17795 +                       break;
17796 +               spin_lock_irq(&log->logbuf_lock);
17797 +               spin_unlock_irq(&log->logbuf_lock);
17798 +               break;
17799 +       case 4:         /* Read/clear last kernel messages */
17800 +               do_clear = 1;
17801 +               /* fall through */
17802 +       case 3:         /* Read last kernel messages */
17803 +               return 0;
17804 +
17805 +       case 5:         /* Clear ring buffer */
17806 +               return 0;
17807 +
17808 +       case 6:         /* Disable logging to console */
17809 +       case 7:         /* Enable logging to console */
17810 +       case 8:         /* Set level of messages printed to console */
17811 +               break;
17812 +
17813 +       case 9:         /* Number of chars in the log buffer */
17814 +               return 0;
17815 +       case 10:        /* Size of the log buffer */
17816 +               return 0;
17817 +       default:
17818 +               error = -EINVAL;
17819 +               break;
17820 +       }
17821 +       return error;
17822 +}
17823 +
17824 +
17825 +/* virtual host info names */
17826 +
17827 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17828 +{
17829 +       struct nsproxy *nsproxy;
17830 +       struct uts_namespace *uts;
17831 +
17832 +
17833 +       if (id == VHIN_CONTEXT)
17834 +               return vxi->vx_name;
17835 +
17836 +       nsproxy = vxi->vx_nsproxy;
17837 +       if (!nsproxy)
17838 +               return NULL;
17839 +
17840 +       uts = nsproxy->uts_ns;
17841 +       if (!uts)
17842 +               return NULL;
17843 +
17844 +       switch (id) {
17845 +       case VHIN_SYSNAME:
17846 +               return uts->name.sysname;
17847 +       case VHIN_NODENAME:
17848 +               return uts->name.nodename;
17849 +       case VHIN_RELEASE:
17850 +               return uts->name.release;
17851 +       case VHIN_VERSION:
17852 +               return uts->name.version;
17853 +       case VHIN_MACHINE:
17854 +               return uts->name.machine;
17855 +       case VHIN_DOMAINNAME:
17856 +               return uts->name.domainname;
17857 +       default:
17858 +               return NULL;
17859 +       }
17860 +       return NULL;
17861 +}
17862 +
17863 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17864 +{
17865 +       struct vcmd_vhi_name_v0 vc_data;
17866 +       char *name;
17867 +
17868 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17869 +               return -EFAULT;
17870 +
17871 +       name = vx_vhi_name(vxi, vc_data.field);
17872 +       if (!name)
17873 +               return -EINVAL;
17874 +
17875 +       memcpy(name, vc_data.name, 65);
17876 +       return 0;
17877 +}
17878 +
17879 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17880 +{
17881 +       struct vcmd_vhi_name_v0 vc_data;
17882 +       char *name;
17883 +
17884 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17885 +               return -EFAULT;
17886 +
17887 +       name = vx_vhi_name(vxi, vc_data.field);
17888 +       if (!name)
17889 +               return -EINVAL;
17890 +
17891 +       memcpy(vc_data.name, name, 65);
17892 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17893 +               return -EFAULT;
17894 +       return 0;
17895 +}
17896 +
17897 +
17898 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17899 +{
17900 +       struct vcmd_virt_stat_v0 vc_data;
17901 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17902 +       struct timespec uptime;
17903 +
17904 +       do_posix_clock_monotonic_gettime(&uptime);
17905 +       set_normalized_timespec(&uptime,
17906 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17907 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17908 +
17909 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
17910 +       vc_data.uptime = timespec_to_ns(&uptime);
17911 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17912 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17913 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17914 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17915 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17916 +       vc_data.load[0] = cvirt->load[0];
17917 +       vc_data.load[1] = cvirt->load[1];
17918 +       vc_data.load[2] = cvirt->load[2];
17919 +
17920 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17921 +               return -EFAULT;
17922 +       return 0;
17923 +}
17924 +
17925 +
17926 +#ifdef CONFIG_VSERVER_VTIME
17927 +
17928 +/* virtualized time base */
17929 +
17930 +void vx_gettimeofday(struct timeval *tv)
17931 +{
17932 +       do_gettimeofday(tv);
17933 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17934 +               return;
17935 +
17936 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
17937 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
17938 +
17939 +       if (tv->tv_usec >= USEC_PER_SEC) {
17940 +               tv->tv_sec++;
17941 +               tv->tv_usec -= USEC_PER_SEC;
17942 +       } else if (tv->tv_usec < 0) {
17943 +               tv->tv_sec--;
17944 +               tv->tv_usec += USEC_PER_SEC;
17945 +       }
17946 +}
17947 +
17948 +int vx_settimeofday(struct timespec *ts)
17949 +{
17950 +       struct timeval tv;
17951 +
17952 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17953 +               return do_settimeofday(ts);
17954 +
17955 +       do_gettimeofday(&tv);
17956 +       current->vx_info->cvirt.bias_tv.tv_sec =
17957 +               ts->tv_sec - tv.tv_sec;
17958 +       current->vx_info->cvirt.bias_tv.tv_usec =
17959 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
17960 +       return 0;
17961 +}
17962 +
17963 +#endif
17964 +
17965 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/cvirt_init.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cvirt_init.h
17966 --- linux-2.6.27.3/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
17967 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cvirt_init.h     2008-10-13 14:54:20.000000000 +0200
17968 @@ -0,0 +1,69 @@
17969 +
17970 +
17971 +extern uint64_t vx_idle_jiffies(void);
17972 +
17973 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17974 +{
17975 +       uint64_t idle_jiffies = vx_idle_jiffies();
17976 +       uint64_t nsuptime;
17977 +
17978 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17979 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17980 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17981 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17982 +       cvirt->bias_tv.tv_sec = 0;
17983 +       cvirt->bias_tv.tv_usec = 0;
17984 +
17985 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17986 +       atomic_set(&cvirt->nr_threads, 0);
17987 +       atomic_set(&cvirt->nr_running, 0);
17988 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17989 +       atomic_set(&cvirt->nr_onhold, 0);
17990 +
17991 +       spin_lock_init(&cvirt->load_lock);
17992 +       cvirt->load_last = jiffies;
17993 +       atomic_set(&cvirt->load_updates, 0);
17994 +       cvirt->load[0] = 0;
17995 +       cvirt->load[1] = 0;
17996 +       cvirt->load[2] = 0;
17997 +       atomic_set(&cvirt->total_forks, 0);
17998 +
17999 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18000 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18001 +       cvirt->syslog.log_start = 0;
18002 +       cvirt->syslog.log_end = 0;
18003 +       cvirt->syslog.con_start = 0;
18004 +       cvirt->syslog.logged_chars = 0;
18005 +}
18006 +
18007 +static inline
18008 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18009 +{
18010 +       // cvirt_pc->cpustat = { 0 };
18011 +}
18012 +
18013 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18014 +{
18015 +       int value;
18016 +
18017 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18018 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18019 +               cvirt, value);
18020 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18021 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18022 +               cvirt, value);
18023 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18024 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18025 +               cvirt, value);
18026 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18027 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18028 +               cvirt, value);
18029 +       return;
18030 +}
18031 +
18032 +static inline
18033 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18034 +{
18035 +       return;
18036 +}
18037 +
18038 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/cvirt_proc.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cvirt_proc.h
18039 --- linux-2.6.27.3/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
18040 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/cvirt_proc.h     2008-10-13 14:54:20.000000000 +0200
18041 @@ -0,0 +1,135 @@
18042 +#ifndef _VX_CVIRT_PROC_H
18043 +#define _VX_CVIRT_PROC_H
18044 +
18045 +#include <linux/nsproxy.h>
18046 +#include <linux/mnt_namespace.h>
18047 +#include <linux/ipc_namespace.h>
18048 +#include <linux/utsname.h>
18049 +#include <linux/ipc.h>
18050 +
18051 +
18052 +static inline
18053 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18054 +{
18055 +       struct mnt_namespace *ns;
18056 +       struct uts_namespace *uts;
18057 +       struct ipc_namespace *ipc;
18058 +       struct path path;
18059 +       char *pstr, *root;
18060 +       int length = 0;
18061 +
18062 +       if (!nsproxy)
18063 +               goto out;
18064 +
18065 +       length += sprintf(buffer + length,
18066 +               "NSProxy:\t%p [%p,%p,%p]\n",
18067 +               nsproxy, nsproxy->mnt_ns,
18068 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18069 +
18070 +       ns = nsproxy->mnt_ns;
18071 +       if (!ns)
18072 +               goto skip_ns;
18073 +
18074 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18075 +       if (!pstr)
18076 +               goto skip_ns;
18077 +
18078 +       path.mnt = ns->root;
18079 +       path.dentry = ns->root->mnt_root;
18080 +       root = d_path(&path, pstr, PATH_MAX - 2);
18081 +       length += sprintf(buffer + length,
18082 +               "Namespace:\t%p [#%u]\n"
18083 +               "RootPath:\t%s\n",
18084 +               ns, atomic_read(&ns->count),
18085 +               root);
18086 +       kfree(pstr);
18087 +skip_ns:
18088 +
18089 +       uts = nsproxy->uts_ns;
18090 +       if (!uts)
18091 +               goto skip_uts;
18092 +
18093 +       length += sprintf(buffer + length,
18094 +               "SysName:\t%.*s\n"
18095 +               "NodeName:\t%.*s\n"
18096 +               "Release:\t%.*s\n"
18097 +               "Version:\t%.*s\n"
18098 +               "Machine:\t%.*s\n"
18099 +               "DomainName:\t%.*s\n",
18100 +               __NEW_UTS_LEN, uts->name.sysname,
18101 +               __NEW_UTS_LEN, uts->name.nodename,
18102 +               __NEW_UTS_LEN, uts->name.release,
18103 +               __NEW_UTS_LEN, uts->name.version,
18104 +               __NEW_UTS_LEN, uts->name.machine,
18105 +               __NEW_UTS_LEN, uts->name.domainname);
18106 +skip_uts:
18107 +
18108 +       ipc = nsproxy->ipc_ns;
18109 +       if (!ipc)
18110 +               goto skip_ipc;
18111 +
18112 +       length += sprintf(buffer + length,
18113 +               "SEMS:\t\t%d %d %d %d  %d\n"
18114 +               "MSG:\t\t%d %d %d\n"
18115 +               "SHM:\t\t%lu %lu  %d %d\n",
18116 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18117 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18118 +               ipc->used_sems,
18119 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18120 +               (unsigned long)ipc->shm_ctlmax,
18121 +               (unsigned long)ipc->shm_ctlall,
18122 +               ipc->shm_ctlmni, ipc->shm_tot);
18123 +skip_ipc:
18124 +out:
18125 +       return length;
18126 +}
18127 +
18128 +
18129 +#include <linux/sched.h>
18130 +
18131 +#define LOAD_INT(x) ((x) >> FSHIFT)
18132 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18133 +
18134 +static inline
18135 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18136 +{
18137 +       int length = 0;
18138 +       int a, b, c;
18139 +
18140 +       length += sprintf(buffer + length,
18141 +               "BiasUptime:\t%lu.%02lu\n",
18142 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18143 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18144 +
18145 +       a = cvirt->load[0] + (FIXED_1 / 200);
18146 +       b = cvirt->load[1] + (FIXED_1 / 200);
18147 +       c = cvirt->load[2] + (FIXED_1 / 200);
18148 +       length += sprintf(buffer + length,
18149 +               "nr_threads:\t%d\n"
18150 +               "nr_running:\t%d\n"
18151 +               "nr_unintr:\t%d\n"
18152 +               "nr_onhold:\t%d\n"
18153 +               "load_updates:\t%d\n"
18154 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18155 +               "total_forks:\t%d\n",
18156 +               atomic_read(&cvirt->nr_threads),
18157 +               atomic_read(&cvirt->nr_running),
18158 +               atomic_read(&cvirt->nr_uninterruptible),
18159 +               atomic_read(&cvirt->nr_onhold),
18160 +               atomic_read(&cvirt->load_updates),
18161 +               LOAD_INT(a), LOAD_FRAC(a),
18162 +               LOAD_INT(b), LOAD_FRAC(b),
18163 +               LOAD_INT(c), LOAD_FRAC(c),
18164 +               atomic_read(&cvirt->total_forks));
18165 +       return length;
18166 +}
18167 +
18168 +static inline
18169 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18170 +       char *buffer, int cpu)
18171 +{
18172 +       int length = 0;
18173 +       return length;
18174 +}
18175 +
18176 +#endif /* _VX_CVIRT_PROC_H */
18177 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/debug.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/debug.c
18178 --- linux-2.6.27.3/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
18179 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/debug.c  2008-10-13 14:54:20.000000000 +0200
18180 @@ -0,0 +1,32 @@
18181 +/*
18182 + *  kernel/vserver/debug.c
18183 + *
18184 + *  Copyright (C) 2005-2007 Herbert Pötzl
18185 + *
18186 + *  V0.01  vx_info dump support
18187 + *
18188 + */
18189 +
18190 +#include <linux/module.h>
18191 +
18192 +#include <linux/vserver/context.h>
18193 +
18194 +
18195 +void   dump_vx_info(struct vx_info *vxi, int level)
18196 +{
18197 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18198 +               atomic_read(&vxi->vx_usecnt),
18199 +               atomic_read(&vxi->vx_tasks),
18200 +               vxi->vx_state);
18201 +       if (level > 0) {
18202 +               __dump_vx_limit(&vxi->limit);
18203 +               __dump_vx_sched(&vxi->sched);
18204 +               __dump_vx_cvirt(&vxi->cvirt);
18205 +               __dump_vx_cacct(&vxi->cacct);
18206 +       }
18207 +       printk("---\n");
18208 +}
18209 +
18210 +
18211 +EXPORT_SYMBOL_GPL(dump_vx_info);
18212 +
18213 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/device.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/device.c
18214 --- linux-2.6.27.3/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
18215 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/device.c 2008-10-13 14:54:20.000000000 +0200
18216 @@ -0,0 +1,443 @@
18217 +/*
18218 + *  linux/kernel/vserver/device.c
18219 + *
18220 + *  Linux-VServer: Device Support
18221 + *
18222 + *  Copyright (C) 2006  Herbert Pötzl
18223 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18224 + *
18225 + *  V0.01  device mapping basics
18226 + *  V0.02  added defaults
18227 + *
18228 + */
18229 +
18230 +#include <linux/slab.h>
18231 +#include <linux/rcupdate.h>
18232 +#include <linux/fs.h>
18233 +#include <linux/namei.h>
18234 +#include <linux/hash.h>
18235 +
18236 +#include <asm/errno.h>
18237 +#include <asm/uaccess.h>
18238 +#include <linux/vserver/base.h>
18239 +#include <linux/vserver/debug.h>
18240 +#include <linux/vserver/context.h>
18241 +#include <linux/vserver/device.h>
18242 +#include <linux/vserver/device_cmd.h>
18243 +
18244 +
18245 +#define DMAP_HASH_BITS 4
18246 +
18247 +
18248 +struct vs_mapping {
18249 +       union {
18250 +               struct hlist_node hlist;
18251 +               struct list_head list;
18252 +       } u;
18253 +#define dm_hlist       u.hlist
18254 +#define dm_list                u.list
18255 +       xid_t xid;
18256 +       dev_t device;
18257 +       struct vx_dmap_target target;
18258 +};
18259 +
18260 +
18261 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18262 +
18263 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18264 +
18265 +static struct vx_dmap_target dmap_defaults[2] = {
18266 +       { .flags = DATTR_OPEN },
18267 +       { .flags = DATTR_OPEN },
18268 +};
18269 +
18270 +
18271 +struct kmem_cache *dmap_cachep __read_mostly;
18272 +
18273 +int __init dmap_cache_init(void)
18274 +{
18275 +       dmap_cachep = kmem_cache_create("dmap_cache",
18276 +               sizeof(struct vs_mapping), 0,
18277 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18278 +       return 0;
18279 +}
18280 +
18281 +__initcall(dmap_cache_init);
18282 +
18283 +
18284 +static inline unsigned int __hashval(dev_t dev, int bits)
18285 +{
18286 +       return hash_long((unsigned long)dev, bits);
18287 +}
18288 +
18289 +
18290 +/*     __hash_mapping()
18291 + *     add the mapping to the hash table
18292 + */
18293 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18294 +{
18295 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18296 +       struct hlist_head *head, *hash = dmap_main_hash;
18297 +       int device = vdm->device;
18298 +
18299 +       spin_lock(hash_lock);
18300 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18301 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18302 +
18303 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18304 +       hlist_add_head(&vdm->dm_hlist, head);
18305 +       spin_unlock(hash_lock);
18306 +}
18307 +
18308 +
18309 +static inline int __mode_to_default(umode_t mode)
18310 +{
18311 +       switch (mode) {
18312 +       case S_IFBLK:
18313 +               return 0;
18314 +       case S_IFCHR:
18315 +               return 1;
18316 +       default:
18317 +               BUG();
18318 +       }
18319 +}
18320 +
18321 +
18322 +/*     __set_default()
18323 + *     set a default
18324 + */
18325 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18326 +       struct vx_dmap_target *vdmt)
18327 +{
18328 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18329 +       spin_lock(hash_lock);
18330 +
18331 +       if (vxi)
18332 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18333 +       else
18334 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18335 +
18336 +
18337 +       spin_unlock(hash_lock);
18338 +
18339 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18340 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18341 +}
18342 +
18343 +
18344 +/*     __remove_default()
18345 + *     remove a default
18346 + */
18347 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18348 +{
18349 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18350 +       spin_lock(hash_lock);
18351 +
18352 +       if (vxi)
18353 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18354 +       else    /* remove == reset */
18355 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18356 +
18357 +       spin_unlock(hash_lock);
18358 +       return 0;
18359 +}
18360 +
18361 +
18362 +/*     __find_mapping()
18363 + *     find a mapping in the hash table
18364 + *
18365 + *     caller must hold hash_lock
18366 + */
18367 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18368 +       struct vs_mapping **local, struct vs_mapping **global)
18369 +{
18370 +       struct hlist_head *hash = dmap_main_hash;
18371 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18372 +       struct hlist_node *pos;
18373 +       struct vs_mapping *vdm;
18374 +
18375 +       *local = NULL;
18376 +       if (global)
18377 +               *global = NULL;
18378 +
18379 +       hlist_for_each(pos, head) {
18380 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18381 +
18382 +               if ((vdm->device == device) &&
18383 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18384 +                       if (vdm->xid == xid) {
18385 +                               *local = vdm;
18386 +                               return 1;
18387 +                       } else if (global && vdm->xid == 0)
18388 +                               *global = vdm;
18389 +               }
18390 +       }
18391 +
18392 +       if (global && *global)
18393 +               return 0;
18394 +       else
18395 +               return -ENOENT;
18396 +}
18397 +
18398 +
18399 +/*     __lookup_mapping()
18400 + *     find a mapping and store the result in target and flags
18401 + */
18402 +static inline int __lookup_mapping(struct vx_info *vxi,
18403 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18404 +{
18405 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18406 +       struct vs_mapping *vdm, *global;
18407 +       struct vx_dmap_target *vdmt;
18408 +       int ret = 0;
18409 +       xid_t xid = vxi->vx_id;
18410 +       int index;
18411 +
18412 +       spin_lock(hash_lock);
18413 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18414 +               ret = 1;
18415 +               vdmt = &vdm->target;
18416 +               goto found;
18417 +       }
18418 +
18419 +       index = __mode_to_default(mode);
18420 +       if (vxi && vxi->dmap.targets[index].flags) {
18421 +               ret = 2;
18422 +               vdmt = &vxi->dmap.targets[index];
18423 +       } else if (global) {
18424 +               ret = 3;
18425 +               vdmt = &global->target;
18426 +               goto found;
18427 +       } else {
18428 +               ret = 4;
18429 +               vdmt = &dmap_defaults[index];
18430 +       }
18431 +
18432 +found:
18433 +       if (target && (vdmt->flags & DATTR_REMAP))
18434 +               *target = vdmt->target;
18435 +       else if (target)
18436 +               *target = device;
18437 +       if (flags)
18438 +               *flags = vdmt->flags;
18439 +
18440 +       spin_unlock(hash_lock);
18441 +
18442 +       return ret;
18443 +}
18444 +
18445 +
18446 +/*     __remove_mapping()
18447 + *     remove a mapping from the hash table
18448 + */
18449 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18450 +       umode_t mode)
18451 +{
18452 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18453 +       struct vs_mapping *vdm = NULL;
18454 +       int ret = 0;
18455 +
18456 +       spin_lock(hash_lock);
18457 +
18458 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18459 +               NULL);
18460 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18461 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18462 +       if (ret < 0)
18463 +               goto out;
18464 +       hlist_del(&vdm->dm_hlist);
18465 +
18466 +out:
18467 +       spin_unlock(hash_lock);
18468 +       if (vdm)
18469 +               kmem_cache_free(dmap_cachep, vdm);
18470 +       return ret;
18471 +}
18472 +
18473 +
18474 +
18475 +int vs_map_device(struct vx_info *vxi,
18476 +       dev_t device, dev_t *target, umode_t mode)
18477 +{
18478 +       int ret, flags = DATTR_MASK;
18479 +
18480 +       if (!vxi) {
18481 +               if (target)
18482 +                       *target = device;
18483 +               goto out;
18484 +       }
18485 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18486 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18487 +               device, target ? *target : 0, flags, mode, ret);
18488 +out:
18489 +       return (flags & DATTR_MASK);
18490 +}
18491 +
18492 +
18493 +
18494 +static int do_set_mapping(struct vx_info *vxi,
18495 +       dev_t device, dev_t target, int flags, umode_t mode)
18496 +{
18497 +       if (device) {
18498 +               struct vs_mapping *new;
18499 +
18500 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18501 +               if (!new)
18502 +                       return -ENOMEM;
18503 +
18504 +               INIT_HLIST_NODE(&new->dm_hlist);
18505 +               new->device = device;
18506 +               new->target.target = target;
18507 +               new->target.flags = flags | mode;
18508 +               new->xid = (vxi ? vxi->vx_id : 0);
18509 +
18510 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18511 +               __hash_mapping(vxi, new);
18512 +       } else {
18513 +               struct vx_dmap_target new = {
18514 +                       .target = target,
18515 +                       .flags = flags | mode,
18516 +               };
18517 +               __set_default(vxi, mode, &new);
18518 +       }
18519 +       return 0;
18520 +}
18521 +
18522 +
18523 +static int do_unset_mapping(struct vx_info *vxi,
18524 +       dev_t device, dev_t target, int flags, umode_t mode)
18525 +{
18526 +       int ret = -EINVAL;
18527 +
18528 +       if (device) {
18529 +               ret = __remove_mapping(vxi, device, mode);
18530 +               if (ret < 0)
18531 +                       goto out;
18532 +       } else {
18533 +               ret = __remove_default(vxi, mode);
18534 +               if (ret < 0)
18535 +                       goto out;
18536 +       }
18537 +
18538 +out:
18539 +       return ret;
18540 +}
18541 +
18542 +
18543 +static inline int __user_device(const char __user *name, dev_t *dev,
18544 +       umode_t *mode)
18545 +{
18546 +       struct nameidata nd;
18547 +       int ret;
18548 +
18549 +       if (!name) {
18550 +               *dev = 0;
18551 +               return 0;
18552 +       }
18553 +       ret = user_lpath(name, &nd.path);
18554 +       if (ret)
18555 +               return ret;
18556 +       if (nd.path.dentry->d_inode) {
18557 +               *dev = nd.path.dentry->d_inode->i_rdev;
18558 +               *mode = nd.path.dentry->d_inode->i_mode;
18559 +       }
18560 +       path_put(&nd.path);
18561 +       return 0;
18562 +}
18563 +
18564 +static inline int __mapping_mode(dev_t device, dev_t target,
18565 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18566 +{
18567 +       if (device)
18568 +               *mode = device_mode & S_IFMT;
18569 +       else if (target)
18570 +               *mode = target_mode & S_IFMT;
18571 +       else
18572 +               return -EINVAL;
18573 +
18574 +       /* if both given, device and target mode have to match */
18575 +       if (device && target &&
18576 +               ((device_mode ^ target_mode) & S_IFMT))
18577 +               return -EINVAL;
18578 +       return 0;
18579 +}
18580 +
18581 +
18582 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18583 +       const char __user *target_path, int flags, int set)
18584 +{
18585 +       dev_t device = ~0, target = ~0;
18586 +       umode_t device_mode = 0, target_mode = 0, mode;
18587 +       int ret;
18588 +
18589 +       ret = __user_device(device_path, &device, &device_mode);
18590 +       if (ret)
18591 +               return ret;
18592 +       ret = __user_device(target_path, &target, &target_mode);
18593 +       if (ret)
18594 +               return ret;
18595 +
18596 +       ret = __mapping_mode(device, target,
18597 +               device_mode, target_mode, &mode);
18598 +       if (ret)
18599 +               return ret;
18600 +
18601 +       if (set)
18602 +               return do_set_mapping(vxi, device, target,
18603 +                       flags, mode);
18604 +       else
18605 +               return do_unset_mapping(vxi, device, target,
18606 +                       flags, mode);
18607 +}
18608 +
18609 +
18610 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18611 +{
18612 +       struct vcmd_set_mapping_v0 vc_data;
18613 +
18614 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18615 +               return -EFAULT;
18616 +
18617 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18618 +               vc_data.flags, 1);
18619 +}
18620 +
18621 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18622 +{
18623 +       struct vcmd_set_mapping_v0 vc_data;
18624 +
18625 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18626 +               return -EFAULT;
18627 +
18628 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18629 +               vc_data.flags, 0);
18630 +}
18631 +
18632 +
18633 +#ifdef CONFIG_COMPAT
18634 +
18635 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18636 +{
18637 +       struct vcmd_set_mapping_v0_x32 vc_data;
18638 +
18639 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18640 +               return -EFAULT;
18641 +
18642 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18643 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18644 +}
18645 +
18646 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18647 +{
18648 +       struct vcmd_set_mapping_v0_x32 vc_data;
18649 +
18650 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18651 +               return -EFAULT;
18652 +
18653 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18654 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18655 +}
18656 +
18657 +#endif /* CONFIG_COMPAT */
18658 +
18659 +
18660 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/dlimit.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/dlimit.c
18661 --- linux-2.6.27.3/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
18662 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/dlimit.c 2008-10-13 14:54:20.000000000 +0200
18663 @@ -0,0 +1,522 @@
18664 +/*
18665 + *  linux/kernel/vserver/dlimit.c
18666 + *
18667 + *  Virtual Server: Context Disk Limits
18668 + *
18669 + *  Copyright (C) 2004-2007  Herbert Pötzl
18670 + *
18671 + *  V0.01  initial version
18672 + *  V0.02  compat32 splitup
18673 + *
18674 + */
18675 +
18676 +#include <linux/statfs.h>
18677 +#include <linux/sched.h>
18678 +#include <linux/namei.h>
18679 +#include <linux/vs_tag.h>
18680 +#include <linux/vs_dlimit.h>
18681 +#include <linux/vserver/dlimit_cmd.h>
18682 +
18683 +#include <asm/uaccess.h>
18684 +
18685 +/*     __alloc_dl_info()
18686 +
18687 +       * allocate an initialized dl_info struct
18688 +       * doesn't make it visible (hash)                        */
18689 +
18690 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18691 +{
18692 +       struct dl_info *new = NULL;
18693 +
18694 +       vxdprintk(VXD_CBIT(dlim, 5),
18695 +               "alloc_dl_info(%p,%d)*", sb, tag);
18696 +
18697 +       /* would this benefit from a slab cache? */
18698 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18699 +       if (!new)
18700 +               return 0;
18701 +
18702 +       memset(new, 0, sizeof(struct dl_info));
18703 +       new->dl_tag = tag;
18704 +       new->dl_sb = sb;
18705 +       INIT_RCU_HEAD(&new->dl_rcu);
18706 +       INIT_HLIST_NODE(&new->dl_hlist);
18707 +       spin_lock_init(&new->dl_lock);
18708 +       atomic_set(&new->dl_refcnt, 0);
18709 +       atomic_set(&new->dl_usecnt, 0);
18710 +
18711 +       /* rest of init goes here */
18712 +
18713 +       vxdprintk(VXD_CBIT(dlim, 4),
18714 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18715 +       return new;
18716 +}
18717 +
18718 +/*     __dealloc_dl_info()
18719 +
18720 +       * final disposal of dl_info                             */
18721 +
18722 +static void __dealloc_dl_info(struct dl_info *dli)
18723 +{
18724 +       vxdprintk(VXD_CBIT(dlim, 4),
18725 +               "dealloc_dl_info(%p)", dli);
18726 +
18727 +       dli->dl_hlist.next = LIST_POISON1;
18728 +       dli->dl_tag = -1;
18729 +       dli->dl_sb = 0;
18730 +
18731 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18732 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18733 +
18734 +       kfree(dli);
18735 +}
18736 +
18737 +
18738 +/*     hash table for dl_info hash */
18739 +
18740 +#define DL_HASH_SIZE   13
18741 +
18742 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18743 +
18744 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18745 +
18746 +
18747 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18748 +{
18749 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18750 +}
18751 +
18752 +
18753 +
18754 +/*     __hash_dl_info()
18755 +
18756 +       * add the dli to the global hash table
18757 +       * requires the hash_lock to be held                     */
18758 +
18759 +static inline void __hash_dl_info(struct dl_info *dli)
18760 +{
18761 +       struct hlist_head *head;
18762 +
18763 +       vxdprintk(VXD_CBIT(dlim, 6),
18764 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18765 +       get_dl_info(dli);
18766 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18767 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18768 +}
18769 +
18770 +/*     __unhash_dl_info()
18771 +
18772 +       * remove the dli from the global hash table
18773 +       * requires the hash_lock to be held                     */
18774 +
18775 +static inline void __unhash_dl_info(struct dl_info *dli)
18776 +{
18777 +       vxdprintk(VXD_CBIT(dlim, 6),
18778 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18779 +       hlist_del_rcu(&dli->dl_hlist);
18780 +       put_dl_info(dli);
18781 +}
18782 +
18783 +
18784 +/*     __lookup_dl_info()
18785 +
18786 +       * requires the rcu_read_lock()
18787 +       * doesn't increment the dl_refcnt                       */
18788 +
18789 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18790 +{
18791 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18792 +       struct hlist_node *pos;
18793 +       struct dl_info *dli;
18794 +
18795 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18796 +
18797 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18798 +                       return dli;
18799 +               }
18800 +       }
18801 +       return NULL;
18802 +}
18803 +
18804 +
18805 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18806 +{
18807 +       struct dl_info *dli;
18808 +
18809 +       rcu_read_lock();
18810 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18811 +       vxdprintk(VXD_CBIT(dlim, 7),
18812 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18813 +       rcu_read_unlock();
18814 +       return dli;
18815 +}
18816 +
18817 +void rcu_free_dl_info(struct rcu_head *head)
18818 +{
18819 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18820 +       int usecnt, refcnt;
18821 +
18822 +       BUG_ON(!dli || !head);
18823 +
18824 +       usecnt = atomic_read(&dli->dl_usecnt);
18825 +       BUG_ON(usecnt < 0);
18826 +
18827 +       refcnt = atomic_read(&dli->dl_refcnt);
18828 +       BUG_ON(refcnt < 0);
18829 +
18830 +       vxdprintk(VXD_CBIT(dlim, 3),
18831 +               "rcu_free_dl_info(%p)", dli);
18832 +       if (!usecnt)
18833 +               __dealloc_dl_info(dli);
18834 +       else
18835 +               printk("!!! rcu didn't free\n");
18836 +}
18837 +
18838 +
18839 +
18840 +
18841 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18842 +       uint32_t flags, int add)
18843 +{
18844 +       struct path path;
18845 +       int ret;
18846 +
18847 +       ret = user_lpath(name, &path);
18848 +       if (!ret) {
18849 +               struct super_block *sb;
18850 +               struct dl_info *dli;
18851 +
18852 +               ret = -EINVAL;
18853 +               if (!path.dentry->d_inode)
18854 +                       goto out_release;
18855 +               if (!(sb = path.dentry->d_inode->i_sb))
18856 +                       goto out_release;
18857 +
18858 +               if (add) {
18859 +                       dli = __alloc_dl_info(sb, id);
18860 +                       spin_lock(&dl_info_hash_lock);
18861 +
18862 +                       ret = -EEXIST;
18863 +                       if (__lookup_dl_info(sb, id))
18864 +                               goto out_unlock;
18865 +                       __hash_dl_info(dli);
18866 +                       dli = NULL;
18867 +               } else {
18868 +                       spin_lock(&dl_info_hash_lock);
18869 +                       dli = __lookup_dl_info(sb, id);
18870 +
18871 +                       ret = -ESRCH;
18872 +                       if (!dli)
18873 +                               goto out_unlock;
18874 +                       __unhash_dl_info(dli);
18875 +               }
18876 +               ret = 0;
18877 +       out_unlock:
18878 +               spin_unlock(&dl_info_hash_lock);
18879 +               if (add && dli)
18880 +                       __dealloc_dl_info(dli);
18881 +       out_release:
18882 +               path_put(&path);
18883 +       }
18884 +       return ret;
18885 +}
18886 +
18887 +int vc_add_dlimit(uint32_t id, void __user *data)
18888 +{
18889 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18890 +
18891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18892 +               return -EFAULT;
18893 +
18894 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18895 +}
18896 +
18897 +int vc_rem_dlimit(uint32_t id, void __user *data)
18898 +{
18899 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18900 +
18901 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18902 +               return -EFAULT;
18903 +
18904 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18905 +}
18906 +
18907 +#ifdef CONFIG_COMPAT
18908 +
18909 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18910 +{
18911 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18912 +
18913 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18914 +               return -EFAULT;
18915 +
18916 +       return do_addrem_dlimit(id,
18917 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18918 +}
18919 +
18920 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18921 +{
18922 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18923 +
18924 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18925 +               return -EFAULT;
18926 +
18927 +       return do_addrem_dlimit(id,
18928 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18929 +}
18930 +
18931 +#endif /* CONFIG_COMPAT */
18932 +
18933 +
18934 +static inline
18935 +int do_set_dlimit(uint32_t id, const char __user *name,
18936 +       uint32_t space_used, uint32_t space_total,
18937 +       uint32_t inodes_used, uint32_t inodes_total,
18938 +       uint32_t reserved, uint32_t flags)
18939 +{
18940 +       struct path path;
18941 +       int ret;
18942 +
18943 +       ret = user_lpath(name, &path);
18944 +       if (!ret) {
18945 +               struct super_block *sb;
18946 +               struct dl_info *dli;
18947 +
18948 +               ret = -EINVAL;
18949 +               if (!path.dentry->d_inode)
18950 +                       goto out_release;
18951 +               if (!(sb = path.dentry->d_inode->i_sb))
18952 +                       goto out_release;
18953 +               if ((reserved != CDLIM_KEEP &&
18954 +                       reserved > 100) ||
18955 +                       (inodes_used != CDLIM_KEEP &&
18956 +                       inodes_used > inodes_total) ||
18957 +                       (space_used != CDLIM_KEEP &&
18958 +                       space_used > space_total))
18959 +                       goto out_release;
18960 +
18961 +               ret = -ESRCH;
18962 +               dli = locate_dl_info(sb, id);
18963 +               if (!dli)
18964 +                       goto out_release;
18965 +
18966 +               spin_lock(&dli->dl_lock);
18967 +
18968 +               if (inodes_used != CDLIM_KEEP)
18969 +                       dli->dl_inodes_used = inodes_used;
18970 +               if (inodes_total != CDLIM_KEEP)
18971 +                       dli->dl_inodes_total = inodes_total;
18972 +               if (space_used != CDLIM_KEEP) {
18973 +                       dli->dl_space_used = space_used;
18974 +                       dli->dl_space_used <<= 10;
18975 +               }
18976 +               if (space_total == CDLIM_INFINITY)
18977 +                       dli->dl_space_total = DLIM_INFINITY;
18978 +               else if (space_total != CDLIM_KEEP) {
18979 +                       dli->dl_space_total = space_total;
18980 +                       dli->dl_space_total <<= 10;
18981 +               }
18982 +               if (reserved != CDLIM_KEEP)
18983 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18984 +
18985 +               spin_unlock(&dli->dl_lock);
18986 +
18987 +               put_dl_info(dli);
18988 +               ret = 0;
18989 +
18990 +       out_release:
18991 +               path_put(&path);
18992 +       }
18993 +       return ret;
18994 +}
18995 +
18996 +int vc_set_dlimit(uint32_t id, void __user *data)
18997 +{
18998 +       struct vcmd_ctx_dlimit_v0 vc_data;
18999 +
19000 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19001 +               return -EFAULT;
19002 +
19003 +       return do_set_dlimit(id, vc_data.name,
19004 +               vc_data.space_used, vc_data.space_total,
19005 +               vc_data.inodes_used, vc_data.inodes_total,
19006 +               vc_data.reserved, vc_data.flags);
19007 +}
19008 +
19009 +#ifdef CONFIG_COMPAT
19010 +
19011 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19012 +{
19013 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19014 +
19015 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19016 +               return -EFAULT;
19017 +
19018 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19019 +               vc_data.space_used, vc_data.space_total,
19020 +               vc_data.inodes_used, vc_data.inodes_total,
19021 +               vc_data.reserved, vc_data.flags);
19022 +}
19023 +
19024 +#endif /* CONFIG_COMPAT */
19025 +
19026 +
19027 +static inline
19028 +int do_get_dlimit(uint32_t id, const char __user *name,
19029 +       uint32_t *space_used, uint32_t *space_total,
19030 +       uint32_t *inodes_used, uint32_t *inodes_total,
19031 +       uint32_t *reserved, uint32_t *flags)
19032 +{
19033 +       struct path path;
19034 +       int ret;
19035 +
19036 +       ret = user_lpath(name, &path);
19037 +       if (!ret) {
19038 +               struct super_block *sb;
19039 +               struct dl_info *dli;
19040 +
19041 +               ret = -EINVAL;
19042 +               if (!path.dentry->d_inode)
19043 +                       goto out_release;
19044 +               if (!(sb = path.dentry->d_inode->i_sb))
19045 +                       goto out_release;
19046 +
19047 +               ret = -ESRCH;
19048 +               dli = locate_dl_info(sb, id);
19049 +               if (!dli)
19050 +                       goto out_release;
19051 +
19052 +               spin_lock(&dli->dl_lock);
19053 +               *inodes_used = dli->dl_inodes_used;
19054 +               *inodes_total = dli->dl_inodes_total;
19055 +               *space_used = dli->dl_space_used >> 10;
19056 +               if (dli->dl_space_total == DLIM_INFINITY)
19057 +                       *space_total = CDLIM_INFINITY;
19058 +               else
19059 +                       *space_total = dli->dl_space_total >> 10;
19060 +
19061 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19062 +               spin_unlock(&dli->dl_lock);
19063 +
19064 +               put_dl_info(dli);
19065 +               ret = -EFAULT;
19066 +
19067 +               ret = 0;
19068 +       out_release:
19069 +               path_put(&path);
19070 +       }
19071 +       return ret;
19072 +}
19073 +
19074 +
19075 +int vc_get_dlimit(uint32_t id, void __user *data)
19076 +{
19077 +       struct vcmd_ctx_dlimit_v0 vc_data;
19078 +       int ret;
19079 +
19080 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19081 +               return -EFAULT;
19082 +
19083 +       ret = do_get_dlimit(id, vc_data.name,
19084 +               &vc_data.space_used, &vc_data.space_total,
19085 +               &vc_data.inodes_used, &vc_data.inodes_total,
19086 +               &vc_data.reserved, &vc_data.flags);
19087 +       if (ret)
19088 +               return ret;
19089 +
19090 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19091 +               return -EFAULT;
19092 +       return 0;
19093 +}
19094 +
19095 +#ifdef CONFIG_COMPAT
19096 +
19097 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19098 +{
19099 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19100 +       int ret;
19101 +
19102 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19103 +               return -EFAULT;
19104 +
19105 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19106 +               &vc_data.space_used, &vc_data.space_total,
19107 +               &vc_data.inodes_used, &vc_data.inodes_total,
19108 +               &vc_data.reserved, &vc_data.flags);
19109 +       if (ret)
19110 +               return ret;
19111 +
19112 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19113 +               return -EFAULT;
19114 +       return 0;
19115 +}
19116 +
19117 +#endif /* CONFIG_COMPAT */
19118 +
19119 +
19120 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19121 +{
19122 +       struct dl_info *dli;
19123 +       __u64 blimit, bfree, bavail;
19124 +       __u32 ifree;
19125 +
19126 +       dli = locate_dl_info(sb, dx_current_tag());
19127 +       if (!dli)
19128 +               return;
19129 +
19130 +       spin_lock(&dli->dl_lock);
19131 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19132 +               goto no_ilim;
19133 +
19134 +       /* reduce max inodes available to limit */
19135 +       if (buf->f_files > dli->dl_inodes_total)
19136 +               buf->f_files = dli->dl_inodes_total;
19137 +
19138 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19139 +       /* reduce free inodes to min */
19140 +       if (ifree < buf->f_ffree)
19141 +               buf->f_ffree = ifree;
19142 +
19143 +no_ilim:
19144 +       if (dli->dl_space_total == DLIM_INFINITY)
19145 +               goto no_blim;
19146 +
19147 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19148 +
19149 +       if (dli->dl_space_total < dli->dl_space_used)
19150 +               bfree = 0;
19151 +       else
19152 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19153 +                       >> sb->s_blocksize_bits;
19154 +
19155 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19156 +       if (bavail < dli->dl_space_used)
19157 +               bavail = 0;
19158 +       else
19159 +               bavail = (bavail - dli->dl_space_used)
19160 +                       >> sb->s_blocksize_bits;
19161 +
19162 +       /* reduce max space available to limit */
19163 +       if (buf->f_blocks > blimit)
19164 +               buf->f_blocks = blimit;
19165 +
19166 +       /* reduce free space to min */
19167 +       if (bfree < buf->f_bfree)
19168 +               buf->f_bfree = bfree;
19169 +
19170 +       /* reduce avail space to min */
19171 +       if (bavail < buf->f_bavail)
19172 +               buf->f_bavail = bavail;
19173 +
19174 +no_blim:
19175 +       spin_unlock(&dli->dl_lock);
19176 +       put_dl_info(dli);
19177 +
19178 +       return;
19179 +}
19180 +
19181 +#include <linux/module.h>
19182 +
19183 +EXPORT_SYMBOL_GPL(locate_dl_info);
19184 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19185 +
19186 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/helper.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/helper.c
19187 --- linux-2.6.27.3/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
19188 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/helper.c 2008-10-13 14:54:20.000000000 +0200
19189 @@ -0,0 +1,199 @@
19190 +/*
19191 + *  linux/kernel/vserver/helper.c
19192 + *
19193 + *  Virtual Context Support
19194 + *
19195 + *  Copyright (C) 2004-2007  Herbert Pötzl
19196 + *
19197 + *  V0.01  basic helper
19198 + *
19199 + */
19200 +
19201 +#include <linux/kmod.h>
19202 +#include <linux/reboot.h>
19203 +#include <linux/vs_context.h>
19204 +#include <linux/vs_network.h>
19205 +#include <linux/vserver/signal.h>
19206 +
19207 +
19208 +char vshelper_path[255] = "/sbin/vshelper";
19209 +
19210 +
19211 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19212 +{
19213 +       int ret;
19214 +
19215 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19216 +               printk( KERN_WARNING
19217 +                       "%s: (%s %s) returned %s with %d\n",
19218 +                       name, argv[1], argv[2],
19219 +                       sync ? "sync" : "async", ret);
19220 +       }
19221 +       vxdprintk(VXD_CBIT(switch, 4),
19222 +               "%s: (%s %s) returned %s with %d",
19223 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19224 +       return ret;
19225 +}
19226 +
19227 +/*
19228 + *      vshelper path is set via /proc/sys
19229 + *      invoked by vserver sys_reboot(), with
19230 + *      the following arguments
19231 + *
19232 + *      argv [0] = vshelper_path;
19233 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19234 + *      argv [2] = context identifier
19235 + *
19236 + *      envp [*] = type-specific parameters
19237 + */
19238 +
19239 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19240 +{
19241 +       char id_buf[8], cmd_buf[16];
19242 +       char uid_buf[16], pid_buf[16];
19243 +       int ret;
19244 +
19245 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19246 +       char *envp[] = {"HOME=/", "TERM=linux",
19247 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19248 +                       uid_buf, pid_buf, cmd_buf, 0};
19249 +
19250 +       if (vx_info_state(vxi, VXS_HELPER))
19251 +               return -EAGAIN;
19252 +       vxi->vx_state |= VXS_HELPER;
19253 +
19254 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19255 +
19256 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19257 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
19258 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19259 +
19260 +       switch (cmd) {
19261 +       case LINUX_REBOOT_CMD_RESTART:
19262 +               argv[1] = "restart";
19263 +               break;
19264 +
19265 +       case LINUX_REBOOT_CMD_HALT:
19266 +               argv[1] = "halt";
19267 +               break;
19268 +
19269 +       case LINUX_REBOOT_CMD_POWER_OFF:
19270 +               argv[1] = "poweroff";
19271 +               break;
19272 +
19273 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19274 +               argv[1] = "swsusp";
19275 +               break;
19276 +
19277 +       default:
19278 +               vxi->vx_state &= ~VXS_HELPER;
19279 +               return 0;
19280 +       }
19281 +
19282 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19283 +       vxi->vx_state &= ~VXS_HELPER;
19284 +       __wakeup_vx_info(vxi);
19285 +       return (ret) ? -EPERM : 0;
19286 +}
19287 +
19288 +
19289 +long vs_reboot(unsigned int cmd, void __user *arg)
19290 +{
19291 +       struct vx_info *vxi = current->vx_info;
19292 +       long ret = 0;
19293 +
19294 +       vxdprintk(VXD_CBIT(misc, 5),
19295 +               "vs_reboot(%p[#%d],%d)",
19296 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19297 +
19298 +       ret = vs_reboot_helper(vxi, cmd, arg);
19299 +       if (ret)
19300 +               return ret;
19301 +
19302 +       vxi->reboot_cmd = cmd;
19303 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19304 +               switch (cmd) {
19305 +               case LINUX_REBOOT_CMD_RESTART:
19306 +               case LINUX_REBOOT_CMD_HALT:
19307 +               case LINUX_REBOOT_CMD_POWER_OFF:
19308 +                       vx_info_kill(vxi, 0, SIGKILL);
19309 +                       vx_info_kill(vxi, 1, SIGKILL);
19310 +               default:
19311 +                       break;
19312 +               }
19313 +       }
19314 +       return 0;
19315 +}
19316 +
19317 +
19318 +/*
19319 + *      argv [0] = vshelper_path;
19320 + *      argv [1] = action: "startup", "shutdown"
19321 + *      argv [2] = context identifier
19322 + *
19323 + *      envp [*] = type-specific parameters
19324 + */
19325 +
19326 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19327 +{
19328 +       char id_buf[8], cmd_buf[16];
19329 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19330 +       char *envp[] = {"HOME=/", "TERM=linux",
19331 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19332 +
19333 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19334 +               return 0;
19335 +
19336 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19337 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19338 +
19339 +       switch (cmd) {
19340 +       case VSC_STARTUP:
19341 +               argv[1] = "startup";
19342 +               break;
19343 +       case VSC_SHUTDOWN:
19344 +               argv[1] = "shutdown";
19345 +               break;
19346 +       default:
19347 +               return 0;
19348 +       }
19349 +
19350 +       return do_vshelper(vshelper_path, argv, envp, 1);
19351 +}
19352 +
19353 +
19354 +/*
19355 + *      argv [0] = vshelper_path;
19356 + *      argv [1] = action: "netup", "netdown"
19357 + *      argv [2] = context identifier
19358 + *
19359 + *      envp [*] = type-specific parameters
19360 + */
19361 +
19362 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19363 +{
19364 +       char id_buf[8], cmd_buf[16];
19365 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19366 +       char *envp[] = {"HOME=/", "TERM=linux",
19367 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19368 +
19369 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19370 +               return 0;
19371 +
19372 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19373 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19374 +
19375 +       switch (cmd) {
19376 +       case VSC_NETUP:
19377 +               argv[1] = "netup";
19378 +               break;
19379 +       case VSC_NETDOWN:
19380 +               argv[1] = "netdown";
19381 +               break;
19382 +       default:
19383 +               return 0;
19384 +       }
19385 +
19386 +       return do_vshelper(vshelper_path, argv, envp, 1);
19387 +}
19388 +
19389 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/history.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/history.c
19390 --- linux-2.6.27.3/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
19391 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/history.c        2008-10-13 14:54:20.000000000 +0200
19392 @@ -0,0 +1,258 @@
19393 +/*
19394 + *  kernel/vserver/history.c
19395 + *
19396 + *  Virtual Context History Backtrace
19397 + *
19398 + *  Copyright (C) 2004-2007  Herbert Pötzl
19399 + *
19400 + *  V0.01  basic structure
19401 + *  V0.02  hash/unhash and trace
19402 + *  V0.03  preemption fixes
19403 + *
19404 + */
19405 +
19406 +#include <linux/module.h>
19407 +#include <asm/uaccess.h>
19408 +
19409 +#include <linux/vserver/context.h>
19410 +#include <linux/vserver/debug.h>
19411 +#include <linux/vserver/debug_cmd.h>
19412 +#include <linux/vserver/history.h>
19413 +
19414 +
19415 +#ifdef CONFIG_VSERVER_HISTORY
19416 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19417 +#else
19418 +#define VXH_SIZE       64
19419 +#endif
19420 +
19421 +struct _vx_history {
19422 +       unsigned int counter;
19423 +
19424 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19425 +};
19426 +
19427 +
19428 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19429 +
19430 +unsigned volatile int vxh_active = 1;
19431 +
19432 +static atomic_t sequence = ATOMIC_INIT(0);
19433 +
19434 +
19435 +/*     vxh_advance()
19436 +
19437 +       * requires disabled preemption                          */
19438 +
19439 +struct _vx_hist_entry *vxh_advance(void *loc)
19440 +{
19441 +       unsigned int cpu = smp_processor_id();
19442 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19443 +       struct _vx_hist_entry *entry;
19444 +       unsigned int index;
19445 +
19446 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19447 +       entry = &hist->entry[index];
19448 +
19449 +       entry->seq = atomic_inc_return(&sequence);
19450 +       entry->loc = loc;
19451 +       return entry;
19452 +}
19453 +
19454 +EXPORT_SYMBOL_GPL(vxh_advance);
19455 +
19456 +
19457 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19458 +
19459 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19460 +
19461 +
19462 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19463 +
19464 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19465 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19466 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19467 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19468 +
19469 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19470 +{
19471 +       switch (e->type) {
19472 +       case VXH_THROW_OOPS:
19473 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19474 +               break;
19475 +
19476 +       case VXH_GET_VX_INFO:
19477 +       case VXH_PUT_VX_INFO:
19478 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19479 +                       VXH_LOC_ARGS(e),
19480 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19481 +                       VXH_VXI_ARGS(e));
19482 +               break;
19483 +
19484 +       case VXH_INIT_VX_INFO:
19485 +       case VXH_SET_VX_INFO:
19486 +       case VXH_CLR_VX_INFO:
19487 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19488 +                       VXH_LOC_ARGS(e),
19489 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19490 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19491 +                       VXH_VXI_ARGS(e), e->sc.data);
19492 +               break;
19493 +
19494 +       case VXH_CLAIM_VX_INFO:
19495 +       case VXH_RELEASE_VX_INFO:
19496 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19497 +                       VXH_LOC_ARGS(e),
19498 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19499 +                       VXH_VXI_ARGS(e), e->sc.data);
19500 +               break;
19501 +
19502 +       case VXH_ALLOC_VX_INFO:
19503 +       case VXH_DEALLOC_VX_INFO:
19504 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19505 +                       VXH_LOC_ARGS(e),
19506 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19507 +                       VXH_VXI_ARGS(e));
19508 +               break;
19509 +
19510 +       case VXH_HASH_VX_INFO:
19511 +       case VXH_UNHASH_VX_INFO:
19512 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19513 +                       VXH_LOC_ARGS(e),
19514 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19515 +                       VXH_VXI_ARGS(e));
19516 +               break;
19517 +
19518 +       case VXH_LOC_VX_INFO:
19519 +       case VXH_LOOKUP_VX_INFO:
19520 +       case VXH_CREATE_VX_INFO:
19521 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19522 +                       VXH_LOC_ARGS(e),
19523 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19524 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19525 +                       e->ll.arg, VXH_VXI_ARGS(e));
19526 +               break;
19527 +       }
19528 +}
19529 +
19530 +static void __vxh_dump_history(void)
19531 +{
19532 +       unsigned int i, cpu;
19533 +
19534 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19535 +               atomic_read(&sequence), NR_CPUS);
19536 +
19537 +       for (i = 0; i < VXH_SIZE; i++) {
19538 +               for_each_online_cpu(cpu) {
19539 +                       struct _vx_history *hist =
19540 +                               &per_cpu(vx_history_buffer, cpu);
19541 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19542 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19543 +
19544 +                       vxh_dump_entry(entry, cpu);
19545 +               }
19546 +       }
19547 +}
19548 +
19549 +void   vxh_dump_history(void)
19550 +{
19551 +       vxh_active = 0;
19552 +#ifdef CONFIG_SMP
19553 +       local_irq_enable();
19554 +       smp_send_stop();
19555 +       local_irq_disable();
19556 +#endif
19557 +       __vxh_dump_history();
19558 +}
19559 +
19560 +
19561 +/* vserver syscall commands below here */
19562 +
19563 +
19564 +int vc_dump_history(uint32_t id)
19565 +{
19566 +       vxh_active = 0;
19567 +       __vxh_dump_history();
19568 +       vxh_active = 1;
19569 +
19570 +       return 0;
19571 +}
19572 +
19573 +
19574 +int do_read_history(struct __user _vx_hist_entry *data,
19575 +       int cpu, uint32_t *index, uint32_t *count)
19576 +{
19577 +       int pos, ret = 0;
19578 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19579 +       int end = hist->counter;
19580 +       int start = end - VXH_SIZE + 2;
19581 +       int idx = *index;
19582 +
19583 +       /* special case: get current pos */
19584 +       if (!*count) {
19585 +               *index = end;
19586 +               return 0;
19587 +       }
19588 +
19589 +       /* have we lost some data? */
19590 +       if (idx < start)
19591 +               idx = start;
19592 +
19593 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19594 +               struct _vx_hist_entry *entry =
19595 +                       &hist->entry[idx % VXH_SIZE];
19596 +
19597 +               /* send entry to userspace */
19598 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19599 +               if (ret)
19600 +                       break;
19601 +       }
19602 +       /* save new index and count */
19603 +       *index = idx;
19604 +       *count = pos;
19605 +       return ret ? ret : (*index < end);
19606 +}
19607 +
19608 +int vc_read_history(uint32_t id, void __user *data)
19609 +{
19610 +       struct vcmd_read_history_v0 vc_data;
19611 +       int ret;
19612 +
19613 +       if (id >= NR_CPUS)
19614 +               return -EINVAL;
19615 +
19616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19617 +               return -EFAULT;
19618 +
19619 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19620 +               id, &vc_data.index, &vc_data.count);
19621 +
19622 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19623 +               return -EFAULT;
19624 +       return ret;
19625 +}
19626 +
19627 +#ifdef CONFIG_COMPAT
19628 +
19629 +int vc_read_history_x32(uint32_t id, void __user *data)
19630 +{
19631 +       struct vcmd_read_history_v0_x32 vc_data;
19632 +       int ret;
19633 +
19634 +       if (id >= NR_CPUS)
19635 +               return -EINVAL;
19636 +
19637 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19638 +               return -EFAULT;
19639 +
19640 +       ret = do_read_history((struct __user _vx_hist_entry *)
19641 +               compat_ptr(vc_data.data_ptr),
19642 +               id, &vc_data.index, &vc_data.count);
19643 +
19644 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19645 +               return -EFAULT;
19646 +       return ret;
19647 +}
19648 +
19649 +#endif /* CONFIG_COMPAT */
19650 +
19651 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/inet.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/inet.c
19652 --- linux-2.6.27.3/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
19653 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/inet.c   2008-10-13 14:54:20.000000000 +0200
19654 @@ -0,0 +1,225 @@
19655 +
19656 +#include <linux/in.h>
19657 +#include <linux/inetdevice.h>
19658 +#include <linux/vs_inet.h>
19659 +#include <linux/vs_inet6.h>
19660 +#include <linux/vserver/debug.h>
19661 +#include <net/route.h>
19662 +#include <net/addrconf.h>
19663 +
19664 +
19665 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19666 +{
19667 +       int ret = 0;
19668 +
19669 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19670 +               ret = 1;
19671 +       else {
19672 +               struct nx_addr_v4 *ptr;
19673 +
19674 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19675 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19676 +                               ret = 1;
19677 +                               break;
19678 +                       }
19679 +               }
19680 +       }
19681 +
19682 +       vxdprintk(VXD_CBIT(net, 2),
19683 +               "nx_v4_addr_conflict(%p,%p): %d",
19684 +               nxi1, nxi2, ret);
19685 +
19686 +       return ret;
19687 +}
19688 +
19689 +
19690 +#ifdef CONFIG_IPV6
19691 +
19692 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19693 +{
19694 +       int ret = 0;
19695 +
19696 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19697 +               ret = 1;
19698 +       else {
19699 +               struct nx_addr_v6 *ptr;
19700 +
19701 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19702 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19703 +                               ret = 1;
19704 +                               break;
19705 +                       }
19706 +               }
19707 +       }
19708 +
19709 +       vxdprintk(VXD_CBIT(net, 2),
19710 +               "nx_v6_addr_conflict(%p,%p): %d",
19711 +               nxi1, nxi2, ret);
19712 +
19713 +       return ret;
19714 +}
19715 +
19716 +#endif
19717 +
19718 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19719 +{
19720 +       struct in_device *in_dev;
19721 +       struct in_ifaddr **ifap;
19722 +       struct in_ifaddr *ifa;
19723 +       int ret = 0;
19724 +
19725 +       if (!dev)
19726 +               goto out;
19727 +       in_dev = in_dev_get(dev);
19728 +       if (!in_dev)
19729 +               goto out;
19730 +
19731 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19732 +               ifap = &ifa->ifa_next) {
19733 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19734 +                       ret = 1;
19735 +                       break;
19736 +               }
19737 +       }
19738 +       in_dev_put(in_dev);
19739 +out:
19740 +       return ret;
19741 +}
19742 +
19743 +
19744 +#ifdef CONFIG_IPV6
19745 +
19746 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19747 +{
19748 +       struct inet6_dev *in_dev;
19749 +       struct inet6_ifaddr **ifap;
19750 +       struct inet6_ifaddr *ifa;
19751 +       int ret = 0;
19752 +
19753 +       if (!dev)
19754 +               goto out;
19755 +       in_dev = in6_dev_get(dev);
19756 +       if (!in_dev)
19757 +               goto out;
19758 +
19759 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19760 +               ifap = &ifa->if_next) {
19761 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19762 +                       ret = 1;
19763 +                       break;
19764 +               }
19765 +       }
19766 +       in6_dev_put(in_dev);
19767 +out:
19768 +       return ret;
19769 +}
19770 +
19771 +#endif
19772 +
19773 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19774 +{
19775 +       int ret = 1;
19776 +
19777 +       if (!nxi)
19778 +               goto out;
19779 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19780 +               goto out;
19781 +#ifdef CONFIG_IPV6
19782 +       ret = 2;
19783 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19784 +               goto out;
19785 +#endif
19786 +       ret = 0;
19787 +out:
19788 +       vxdprintk(VXD_CBIT(net, 3),
19789 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19790 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19791 +       return ret;
19792 +}
19793 +
19794 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19795 +       struct rtable **rp, struct flowi *fl)
19796 +{
19797 +       if (!nxi)
19798 +               return 0;
19799 +
19800 +       /* FIXME: handle lback only case */
19801 +       if (!NX_IPV4(nxi))
19802 +               return -EPERM;
19803 +
19804 +       vxdprintk(VXD_CBIT(net, 4),
19805 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19806 +               nxi, nxi ? nxi->nx_id : 0,
19807 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19808 +
19809 +       /* single IP is unconditional */
19810 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19811 +               (fl->fl4_src == INADDR_ANY))
19812 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19813 +
19814 +       if (fl->fl4_src == INADDR_ANY) {
19815 +               struct nx_addr_v4 *ptr;
19816 +               __be32 found = 0;
19817 +               int err;
19818 +
19819 +               err = __ip_route_output_key(net, rp, fl);
19820 +               if (!err) {
19821 +                       found = (*rp)->rt_src;
19822 +                       ip_rt_put(*rp);
19823 +                       vxdprintk(VXD_CBIT(net, 4),
19824 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19825 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19826 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19827 +                               goto found;
19828 +               }
19829 +
19830 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19831 +                       __be32 primary = ptr->ip[0].s_addr;
19832 +                       __be32 mask = ptr->mask.s_addr;
19833 +                       __be32 neta = primary & mask;
19834 +
19835 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19836 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19837 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19838 +                               NIPQUAD(mask), NIPQUAD(neta));
19839 +                       if ((found & mask) != neta)
19840 +                               continue;
19841 +
19842 +                       fl->fl4_src = primary;
19843 +                       err = __ip_route_output_key(net, rp, fl);
19844 +                       vxdprintk(VXD_CBIT(net, 4),
19845 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19846 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19847 +                       if (!err) {
19848 +                               found = (*rp)->rt_src;
19849 +                               ip_rt_put(*rp);
19850 +                               if (found == primary)
19851 +                                       goto found;
19852 +                       }
19853 +               }
19854 +               /* still no source ip? */
19855 +               found = ipv4_is_loopback(fl->fl4_dst)
19856 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19857 +       found:
19858 +               /* assign src ip to flow */
19859 +               fl->fl4_src = found;
19860 +
19861 +       } else {
19862 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19863 +                       return -EPERM;
19864 +       }
19865 +
19866 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19867 +               if (ipv4_is_loopback(fl->fl4_dst))
19868 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19869 +               if (ipv4_is_loopback(fl->fl4_src))
19870 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19871 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19872 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19873 +               return -EPERM;
19874 +
19875 +       return 0;
19876 +}
19877 +
19878 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19879 +
19880 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/init.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/init.c
19881 --- linux-2.6.27.3/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
19882 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/init.c   2008-10-13 14:54:20.000000000 +0200
19883 @@ -0,0 +1,45 @@
19884 +/*
19885 + *  linux/kernel/init.c
19886 + *
19887 + *  Virtual Server Init
19888 + *
19889 + *  Copyright (C) 2004-2007  Herbert Pötzl
19890 + *
19891 + *  V0.01  basic structure
19892 + *
19893 + */
19894 +
19895 +#include <linux/init.h>
19896 +
19897 +int    vserver_register_sysctl(void);
19898 +void   vserver_unregister_sysctl(void);
19899 +
19900 +
19901 +static int __init init_vserver(void)
19902 +{
19903 +       int ret = 0;
19904 +
19905 +#ifdef CONFIG_VSERVER_DEBUG
19906 +       vserver_register_sysctl();
19907 +#endif
19908 +       return ret;
19909 +}
19910 +
19911 +
19912 +static void __exit exit_vserver(void)
19913 +{
19914 +
19915 +#ifdef CONFIG_VSERVER_DEBUG
19916 +       vserver_unregister_sysctl();
19917 +#endif
19918 +       return;
19919 +}
19920 +
19921 +/* FIXME: GFP_ZONETYPES gone
19922 +long vx_slab[GFP_ZONETYPES]; */
19923 +long vx_area;
19924 +
19925 +
19926 +module_init(init_vserver);
19927 +module_exit(exit_vserver);
19928 +
19929 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/inode.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/inode.c
19930 --- linux-2.6.27.3/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
19931 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/inode.c  2008-10-24 03:34:52.000000000 +0200
19932 @@ -0,0 +1,422 @@
19933 +/*
19934 + *  linux/kernel/vserver/inode.c
19935 + *
19936 + *  Virtual Server: File System Support
19937 + *
19938 + *  Copyright (C) 2004-2007  Herbert Pötzl
19939 + *
19940 + *  V0.01  separated from vcontext V0.05
19941 + *  V0.02  moved to tag (instead of xid)
19942 + *
19943 + */
19944 +
19945 +#include <linux/tty.h>
19946 +#include <linux/proc_fs.h>
19947 +#include <linux/devpts_fs.h>
19948 +#include <linux/fs.h>
19949 +#include <linux/file.h>
19950 +#include <linux/mount.h>
19951 +#include <linux/parser.h>
19952 +#include <linux/namei.h>
19953 +#include <linux/vserver/inode.h>
19954 +#include <linux/vserver/inode_cmd.h>
19955 +#include <linux/vs_base.h>
19956 +#include <linux/vs_tag.h>
19957 +
19958 +#include <asm/uaccess.h>
19959 +
19960 +
19961 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19962 +{
19963 +       struct proc_dir_entry *entry;
19964 +
19965 +       if (!in || !in->i_sb)
19966 +               return -ESRCH;
19967 +
19968 +       *flags = IATTR_TAG
19969 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19970 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19971 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
19972 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
19973 +
19974 +       if (S_ISDIR(in->i_mode))
19975 +               *mask |= IATTR_BARRIER;
19976 +
19977 +       if (IS_TAGGED(in)) {
19978 +               *tag = in->i_tag;
19979 +               *mask |= IATTR_TAG;
19980 +       }
19981 +
19982 +       switch (in->i_sb->s_magic) {
19983 +       case PROC_SUPER_MAGIC:
19984 +               entry = PROC_I(in)->pde;
19985 +
19986 +               /* check for specific inodes? */
19987 +               if (entry)
19988 +                       *mask |= IATTR_FLAGS;
19989 +               if (entry)
19990 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19991 +               else
19992 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19993 +               break;
19994 +
19995 +       case DEVPTS_SUPER_MAGIC:
19996 +               *tag = in->i_tag;
19997 +               *mask |= IATTR_TAG;
19998 +               break;
19999 +
20000 +       default:
20001 +               break;
20002 +       }
20003 +       return 0;
20004 +}
20005 +
20006 +int vc_get_iattr(void __user *data)
20007 +{
20008 +       struct path path;
20009 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20010 +       int ret;
20011 +
20012 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20013 +               return -EFAULT;
20014 +
20015 +       ret = user_lpath(vc_data.name, &path);
20016 +       if (!ret) {
20017 +               ret = __vc_get_iattr(path.dentry->d_inode,
20018 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20019 +               path_put(&path);
20020 +       }
20021 +       if (ret)
20022 +               return ret;
20023 +
20024 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20025 +               ret = -EFAULT;
20026 +       return ret;
20027 +}
20028 +
20029 +#ifdef CONFIG_COMPAT
20030 +
20031 +int vc_get_iattr_x32(void __user *data)
20032 +{
20033 +       struct path path;
20034 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20035 +       int ret;
20036 +
20037 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20038 +               return -EFAULT;
20039 +
20040 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20041 +       if (!ret) {
20042 +               ret = __vc_get_iattr(path.dentry->d_inode,
20043 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20044 +               path_put(&path);
20045 +       }
20046 +       if (ret)
20047 +               return ret;
20048 +
20049 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20050 +               ret = -EFAULT;
20051 +       return ret;
20052 +}
20053 +
20054 +#endif /* CONFIG_COMPAT */
20055 +
20056 +
20057 +int vc_fget_iattr(uint32_t fd, void __user *data)
20058 +{
20059 +       struct file *filp;
20060 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20061 +       int ret;
20062 +
20063 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20064 +               return -EFAULT;
20065 +
20066 +       filp = fget(fd);
20067 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20068 +               return -EBADF;
20069 +
20070 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20071 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20072 +
20073 +       fput(filp);
20074 +
20075 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20076 +               ret = -EFAULT;
20077 +       return ret;
20078 +}
20079 +
20080 +
20081 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20082 +{
20083 +       struct inode *in = de->d_inode;
20084 +       int error = 0, is_proc = 0, has_tag = 0;
20085 +       struct iattr attr = { 0 };
20086 +
20087 +       if (!in || !in->i_sb)
20088 +               return -ESRCH;
20089 +
20090 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20091 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20092 +               return -EINVAL;
20093 +
20094 +       has_tag = IS_TAGGED(in) ||
20095 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20096 +       if ((*mask & IATTR_TAG) && !has_tag)
20097 +               return -EINVAL;
20098 +
20099 +       mutex_lock(&in->i_mutex);
20100 +       if (*mask & IATTR_TAG) {
20101 +               attr.ia_tag = *tag;
20102 +               attr.ia_valid |= ATTR_TAG;
20103 +       }
20104 +
20105 +       if (*mask & IATTR_FLAGS) {
20106 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20107 +               unsigned int iflags = PROC_I(in)->vx_flags;
20108 +
20109 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20110 +                       | (*flags & IATTR_FLAGS);
20111 +               PROC_I(in)->vx_flags = iflags;
20112 +               if (entry)
20113 +                       entry->vx_flags = iflags;
20114 +       }
20115 +
20116 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20117 +               if (*mask & IATTR_IMMUTABLE) {
20118 +                       if (*flags & IATTR_IMMUTABLE)
20119 +                               in->i_flags |= S_IMMUTABLE;
20120 +                       else
20121 +                               in->i_flags &= ~S_IMMUTABLE;
20122 +               }
20123 +               if (*mask & IATTR_IXUNLINK) {
20124 +                       if (*flags & IATTR_IXUNLINK)
20125 +                               in->i_flags |= S_IXUNLINK;
20126 +                       else
20127 +                               in->i_flags &= ~S_IXUNLINK;
20128 +               }
20129 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20130 +                       if (*flags & IATTR_BARRIER)
20131 +                               in->i_vflags |= V_BARRIER;
20132 +                       else
20133 +                               in->i_vflags &= ~V_BARRIER;
20134 +               }
20135 +               if (in->i_op && in->i_op->sync_flags) {
20136 +                       error = in->i_op->sync_flags(in);
20137 +                       if (error)
20138 +                               goto out;
20139 +               }
20140 +       }
20141 +
20142 +       if (attr.ia_valid) {
20143 +               if (in->i_op && in->i_op->setattr)
20144 +                       error = in->i_op->setattr(de, &attr);
20145 +               else {
20146 +                       error = inode_change_ok(in, &attr);
20147 +                       if (!error)
20148 +                               error = inode_setattr(in, &attr);
20149 +               }
20150 +       }
20151 +
20152 +out:
20153 +       mutex_unlock(&in->i_mutex);
20154 +       return error;
20155 +}
20156 +
20157 +int vc_set_iattr(void __user *data)
20158 +{
20159 +       struct path path;
20160 +       struct vcmd_ctx_iattr_v1 vc_data;
20161 +       int ret;
20162 +
20163 +       if (!capable(CAP_LINUX_IMMUTABLE))
20164 +               return -EPERM;
20165 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20166 +               return -EFAULT;
20167 +
20168 +       ret = user_lpath(vc_data.name, &path);
20169 +       if (!ret) {
20170 +               ret = __vc_set_iattr(path.dentry,
20171 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20172 +               path_put(&path);
20173 +       }
20174 +
20175 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20176 +               ret = -EFAULT;
20177 +       return ret;
20178 +}
20179 +
20180 +#ifdef CONFIG_COMPAT
20181 +
20182 +int vc_set_iattr_x32(void __user *data)
20183 +{
20184 +       struct path path;
20185 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20186 +       int ret;
20187 +
20188 +       if (!capable(CAP_LINUX_IMMUTABLE))
20189 +               return -EPERM;
20190 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20191 +               return -EFAULT;
20192 +
20193 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20194 +       if (!ret) {
20195 +               ret = __vc_set_iattr(path.dentry,
20196 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20197 +               path_put(&path);
20198 +       }
20199 +
20200 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20201 +               ret = -EFAULT;
20202 +       return ret;
20203 +}
20204 +
20205 +#endif /* CONFIG_COMPAT */
20206 +
20207 +int vc_fset_iattr(uint32_t fd, void __user *data)
20208 +{
20209 +       struct file *filp;
20210 +       struct vcmd_ctx_fiattr_v0 vc_data;
20211 +       int ret;
20212 +
20213 +       if (!capable(CAP_LINUX_IMMUTABLE))
20214 +               return -EPERM;
20215 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20216 +               return -EFAULT;
20217 +
20218 +       filp = fget(fd);
20219 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20220 +               return -EBADF;
20221 +
20222 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20223 +               &vc_data.flags, &vc_data.mask);
20224 +
20225 +       fput(filp);
20226 +
20227 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20228 +               return -EFAULT;
20229 +       return ret;
20230 +}
20231 +
20232 +
20233 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20234 +
20235 +static match_table_t tokens = {
20236 +       {Opt_notagcheck, "notagcheck"},
20237 +#ifdef CONFIG_PROPAGATE
20238 +       {Opt_notag, "notag"},
20239 +       {Opt_tag, "tag"},
20240 +       {Opt_tagid, "tagid=%u"},
20241 +#endif
20242 +       {Opt_err, NULL}
20243 +};
20244 +
20245 +
20246 +static void __dx_parse_remove(char *string, char *opt)
20247 +{
20248 +       char *p = strstr(string, opt);
20249 +       char *q = p;
20250 +
20251 +       if (p) {
20252 +               while (*q != '\0' && *q != ',')
20253 +                       q++;
20254 +               while (*q)
20255 +                       *p++ = *q++;
20256 +               while (*p)
20257 +                       *p++ = '\0';
20258 +       }
20259 +}
20260 +
20261 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20262 +                unsigned long *flags)
20263 +{
20264 +       int set = 0;
20265 +       substring_t args[MAX_OPT_ARGS];
20266 +       int token, option = 0;
20267 +       char *s, *p, *opts;
20268 +
20269 +       if (!string)
20270 +               return 0;
20271 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20272 +       if (!s)
20273 +               return 0;
20274 +
20275 +       opts = s;
20276 +       while ((p = strsep(&opts, ",")) != NULL) {
20277 +               token = match_token(p, tokens, args);
20278 +
20279 +               vxdprintk(VXD_CBIT(tag, 7),
20280 +                       "dx_parse_tag(»%s«): %d:#%d",
20281 +                       p, token, option);
20282 +
20283 +               switch (token) {
20284 +#ifdef CONFIG_PROPAGATE
20285 +               case Opt_tag:
20286 +                       if (tag)
20287 +                               *tag = 0;
20288 +                       if (remove)
20289 +                               __dx_parse_remove(s, "tag");
20290 +                       *mnt_flags |= MNT_TAGID;
20291 +                       set |= MNT_TAGID;
20292 +                       break;
20293 +               case Opt_notag:
20294 +                       if (remove)
20295 +                               __dx_parse_remove(s, "notag");
20296 +                       *mnt_flags |= MNT_NOTAG;
20297 +                       set |= MNT_NOTAG;
20298 +                       break;
20299 +               case Opt_tagid:
20300 +                       if (tag && !match_int(args, &option))
20301 +                               *tag = option;
20302 +                       if (remove)
20303 +                               __dx_parse_remove(s, "tagid");
20304 +                       *mnt_flags |= MNT_TAGID;
20305 +                       set |= MNT_TAGID;
20306 +                       break;
20307 +#endif
20308 +               case Opt_notagcheck:
20309 +                       if (remove)
20310 +                               __dx_parse_remove(s, "notagcheck");
20311 +                       *flags |= MS_NOTAGCHECK;
20312 +                       set |= MS_NOTAGCHECK;
20313 +                       break;
20314 +               }
20315 +       }
20316 +       if (set)
20317 +               strcpy(string, s);
20318 +       kfree(s);
20319 +       return set;
20320 +}
20321 +
20322 +#ifdef CONFIG_PROPAGATE
20323 +
20324 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20325 +{
20326 +       tag_t new_tag = 0;
20327 +       struct vfsmount *mnt;
20328 +       int propagate;
20329 +
20330 +       if (!nd)
20331 +               return;
20332 +       mnt = nd->path.mnt;
20333 +       if (!mnt)
20334 +               return;
20335 +
20336 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20337 +       if (propagate)
20338 +               new_tag = mnt->mnt_tag;
20339 +
20340 +       vxdprintk(VXD_CBIT(tag, 7),
20341 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20342 +               inode, inode->i_ino, inode->i_tag,
20343 +               new_tag, (propagate) ? 1 : 0);
20344 +
20345 +       if (propagate)
20346 +               inode->i_tag = new_tag;
20347 +}
20348 +
20349 +#include <linux/module.h>
20350 +
20351 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20352 +
20353 +#endif /* CONFIG_PROPAGATE */
20354 +
20355 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/Kconfig linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/Kconfig
20356 --- linux-2.6.27.3/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
20357 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/Kconfig  2008-10-13 14:54:20.000000000 +0200
20358 @@ -0,0 +1,251 @@
20359 +#
20360 +# Linux VServer configuration
20361 +#
20362 +
20363 +menu "Linux VServer"
20364 +
20365 +config VSERVER_AUTO_LBACK
20366 +       bool    "Automatically Assign Loopback IP"
20367 +       default y
20368 +       help
20369 +         Automatically assign a guest specific loopback
20370 +         IP and add it to the kernel network stack on
20371 +         startup.
20372 +
20373 +config VSERVER_AUTO_SINGLE
20374 +       bool    "Automatic Single IP Special Casing"
20375 +       depends on EXPERIMENTAL
20376 +       default y
20377 +       help
20378 +         This allows network contexts with a single IP to
20379 +         automatically remap 0.0.0.0 bindings to that IP,
20380 +         avoiding further network checks and improving
20381 +         performance.
20382 +
20383 +         (note: such guests do not allow to change the ip
20384 +          on the fly and do not show loopback addresses)
20385 +
20386 +config VSERVER_COWBL
20387 +       bool    "Enable COW Immutable Link Breaking"
20388 +       default y
20389 +       help
20390 +         This enables the COW (Copy-On-Write) link break code.
20391 +         It allows you to treat unified files like normal files
20392 +         when writing to them (which will implicitely break the
20393 +         link and create a copy of the unified file)
20394 +
20395 +config VSERVER_VTIME
20396 +       bool    "Enable Virtualized Guest Time"
20397 +       depends on EXPERIMENTAL
20398 +       default n
20399 +       help
20400 +         This enables per guest time offsets to allow for
20401 +         adjusting the system clock individually per guest.
20402 +         this adds some overhead to the time functions and
20403 +         therefore should not be enabled without good reason.
20404 +
20405 +config VSERVER_DEVICE
20406 +       bool    "Enable Guest Device Mapping"
20407 +       depends on EXPERIMENTAL
20408 +       default n
20409 +       help
20410 +         This enables generic device remapping.
20411 +
20412 +config VSERVER_PROC_SECURE
20413 +       bool    "Enable Proc Security"
20414 +       depends on PROC_FS
20415 +       default y
20416 +       help
20417 +         This configures ProcFS security to initially hide
20418 +         non-process entries for all contexts except the main and
20419 +         spectator context (i.e. for all guests), which is a secure
20420 +         default.
20421 +
20422 +         (note: on 1.2x the entries were visible by default)
20423 +
20424 +config VSERVER_HARDCPU
20425 +       bool    "Enable Hard CPU Limits"
20426 +       default y
20427 +       help
20428 +         Activate the Hard CPU Limits
20429 +
20430 +         This will compile in code that allows the Token Bucket
20431 +         Scheduler to put processes on hold when a context's
20432 +         tokens are depleted (provided that its per-context
20433 +         sched_hard flag is set).
20434 +
20435 +         Processes belonging to that context will not be able
20436 +         to consume CPU resources again until a per-context
20437 +         configured minimum of tokens has been reached.
20438 +
20439 +config VSERVER_IDLETIME
20440 +       bool    "Avoid idle CPUs by skipping Time"
20441 +       depends on VSERVER_HARDCPU
20442 +       default y
20443 +       help
20444 +         This option allows the scheduler to artificially
20445 +         advance time (per cpu) when otherwise the idle
20446 +         task would be scheduled, thus keeping the cpu
20447 +         busy and sharing the available resources among
20448 +         certain contexts.
20449 +
20450 +config VSERVER_IDLELIMIT
20451 +       bool    "Limit the IDLE task"
20452 +       depends on VSERVER_HARDCPU
20453 +       default n
20454 +       help
20455 +         Limit the idle slices, so the the next context
20456 +         will be scheduled as soon as possible.
20457 +
20458 +         This might improve interactivity and latency, but
20459 +         will also marginally increase scheduling overhead.
20460 +
20461 +choice
20462 +       prompt  "Persistent Inode Tagging"
20463 +       default TAGGING_ID24
20464 +       help
20465 +         This adds persistent context information to filesystems
20466 +         mounted with the tagxid option. Tagging is a requirement
20467 +         for per-context disk limits and per-context quota.
20468 +
20469 +
20470 +config TAGGING_NONE
20471 +       bool    "Disabled"
20472 +       help
20473 +         do not store per-context information in inodes.
20474 +
20475 +config TAGGING_UID16
20476 +       bool    "UID16/GID32"
20477 +       help
20478 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20479 +
20480 +config TAGGING_GID16
20481 +       bool    "UID32/GID16"
20482 +       help
20483 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20484 +
20485 +config TAGGING_ID24
20486 +       bool    "UID24/GID24"
20487 +       help
20488 +         uses the upper 8bit from UID and GID for XID tagging
20489 +         which leaves 24bit for UID/GID each, which should be
20490 +         more than sufficient for normal use.
20491 +
20492 +config TAGGING_INTERN
20493 +       bool    "UID32/GID32"
20494 +       help
20495 +         this uses otherwise reserved inode fields in the on
20496 +         disk representation, which limits the use to a few
20497 +         filesystems (currently ext2 and ext3)
20498 +
20499 +endchoice
20500 +
20501 +config TAG_NFSD
20502 +       bool    "Tag NFSD User Auth and Files"
20503 +       default n
20504 +       help
20505 +         Enable this if you do want the in-kernel NFS
20506 +         Server to use the tagging specified above.
20507 +         (will require patched clients too)
20508 +
20509 +config VSERVER_PRIVACY
20510 +       bool    "Honor Privacy Aspects of Guests"
20511 +       default n
20512 +       help
20513 +         When enabled, most context checks will disallow
20514 +         access to structures assigned to a specific context,
20515 +         like ptys or loop devices.
20516 +
20517 +config VSERVER_CONTEXTS
20518 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20519 +       range 1 65533
20520 +       default "768"   if 64BIT
20521 +       default "256"
20522 +       help
20523 +         This setting will optimize certain data structures
20524 +         and memory allocations according to the expected
20525 +         maximum.
20526 +
20527 +         note: this is not a strict upper limit.
20528 +
20529 +config VSERVER_WARN
20530 +       bool    "VServer Warnings"
20531 +       default y
20532 +       help
20533 +         This enables various runtime warnings, which will
20534 +         notify about potential manipulation attempts or
20535 +         resource shortage. It is generally considered to
20536 +         be a good idea to have that enabled.
20537 +
20538 +config VSERVER_DEBUG
20539 +       bool    "VServer Debugging Code"
20540 +       default n
20541 +       help
20542 +         Set this to yes if you want to be able to activate
20543 +         debugging output at runtime. It adds a very small
20544 +         overhead to all vserver related functions and
20545 +         increases the kernel size by about 20k.
20546 +
20547 +config VSERVER_HISTORY
20548 +       bool    "VServer History Tracing"
20549 +       depends on VSERVER_DEBUG
20550 +       default n
20551 +       help
20552 +         Set this to yes if you want to record the history of
20553 +         linux-vserver activities, so they can be replayed in
20554 +         the event of a kernel panic or oops.
20555 +
20556 +config VSERVER_HISTORY_SIZE
20557 +       int     "Per-CPU History Size (32-65536)"
20558 +       depends on VSERVER_HISTORY
20559 +       range 32 65536
20560 +       default 64
20561 +       help
20562 +         This allows you to specify the number of entries in
20563 +         the per-CPU history buffer.
20564 +
20565 +config VSERVER_MONITOR
20566 +       bool    "VServer Scheduling Monitor"
20567 +       depends on VSERVER_DISABLED
20568 +       default n
20569 +       help
20570 +         Set this to yes if you want to record the scheduling
20571 +         decisions, so that they can be relayed to userspace
20572 +         for detailed analysis.
20573 +
20574 +config VSERVER_MONITOR_SIZE
20575 +       int     "Per-CPU Monitor Queue Size (32-65536)"
20576 +       depends on VSERVER_MONITOR
20577 +       range 32 65536
20578 +       default 1024
20579 +       help
20580 +         This allows you to specify the number of entries in
20581 +         the per-CPU scheduling monitor buffer.
20582 +
20583 +config VSERVER_MONITOR_SYNC
20584 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
20585 +       depends on VSERVER_MONITOR
20586 +       range 0 65536
20587 +       default 256
20588 +       help
20589 +         This allows you to specify the interval in ticks
20590 +         when a time sync entry is inserted.
20591 +
20592 +endmenu
20593 +
20594 +
20595 +config VSERVER
20596 +       bool
20597 +       default y
20598 +       select NAMESPACES
20599 +       select UTS_NS
20600 +       select IPC_NS
20601 +       select USER_NS
20602 +       select SYSVIPC
20603 +
20604 +config VSERVER_SECURITY
20605 +       bool
20606 +       depends on SECURITY
20607 +       default y
20608 +       select SECURITY_CAPABILITIES
20609 +
20610 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/limit.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/limit.c
20611 --- linux-2.6.27.3/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
20612 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/limit.c  2008-10-13 14:54:20.000000000 +0200
20613 @@ -0,0 +1,319 @@
20614 +/*
20615 + *  linux/kernel/vserver/limit.c
20616 + *
20617 + *  Virtual Server: Context Limits
20618 + *
20619 + *  Copyright (C) 2004-2007  Herbert Pötzl
20620 + *
20621 + *  V0.01  broken out from vcontext V0.05
20622 + *  V0.02  changed vcmds to vxi arg
20623 + *
20624 + */
20625 +
20626 +#include <linux/sched.h>
20627 +#include <linux/module.h>
20628 +#include <linux/vs_limit.h>
20629 +#include <linux/vserver/limit.h>
20630 +#include <linux/vserver/limit_cmd.h>
20631 +
20632 +#include <asm/uaccess.h>
20633 +
20634 +
20635 +const char *vlimit_name[NUM_LIMITS] = {
20636 +       [RLIMIT_CPU]            = "CPU",
20637 +       [RLIMIT_RSS]            = "RSS",
20638 +       [RLIMIT_NPROC]          = "NPROC",
20639 +       [RLIMIT_NOFILE]         = "NOFILE",
20640 +       [RLIMIT_MEMLOCK]        = "VML",
20641 +       [RLIMIT_AS]             = "VM",
20642 +       [RLIMIT_LOCKS]          = "LOCKS",
20643 +       [RLIMIT_SIGPENDING]     = "SIGP",
20644 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20645 +
20646 +       [VLIMIT_NSOCK]          = "NSOCK",
20647 +       [VLIMIT_OPENFD]         = "OPENFD",
20648 +       [VLIMIT_ANON]           = "ANON",
20649 +       [VLIMIT_SHMEM]          = "SHMEM",
20650 +       [VLIMIT_DENTRY]         = "DENTRY",
20651 +};
20652 +
20653 +EXPORT_SYMBOL_GPL(vlimit_name);
20654 +
20655 +#define MASK_ENTRY(x)  (1 << (x))
20656 +
20657 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20658 +               /* minimum */
20659 +       0
20660 +       ,       /* softlimit */
20661 +       MASK_ENTRY( RLIMIT_RSS          ) |
20662 +       MASK_ENTRY( VLIMIT_ANON         ) |
20663 +       0
20664 +       ,       /* maximum */
20665 +       MASK_ENTRY( RLIMIT_RSS          ) |
20666 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20667 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20668 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
20669 +       MASK_ENTRY( RLIMIT_AS           ) |
20670 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20671 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20672 +
20673 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20674 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20675 +       MASK_ENTRY( VLIMIT_ANON         ) |
20676 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20677 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20678 +       0
20679 +};
20680 +               /* accounting only */
20681 +uint32_t account_mask =
20682 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20683 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20684 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20685 +       0;
20686 +
20687 +
20688 +static int is_valid_vlimit(int id)
20689 +{
20690 +       uint32_t mask = vlimit_mask.minimum |
20691 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20692 +       return mask & (1 << id);
20693 +}
20694 +
20695 +static int is_accounted_vlimit(int id)
20696 +{
20697 +       if (is_valid_vlimit(id))
20698 +               return 1;
20699 +       return account_mask & (1 << id);
20700 +}
20701 +
20702 +
20703 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20704 +{
20705 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20706 +       return VX_VLIM(limit);
20707 +}
20708 +
20709 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20710 +{
20711 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20712 +       return VX_VLIM(limit);
20713 +}
20714 +
20715 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20716 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20717 +{
20718 +       if (!is_valid_vlimit(id))
20719 +               return -EINVAL;
20720 +
20721 +       if (minimum)
20722 +               *minimum = CRLIM_UNSET;
20723 +       if (softlimit)
20724 +               *softlimit = vc_get_soft(vxi, id);
20725 +       if (maximum)
20726 +               *maximum = vc_get_hard(vxi, id);
20727 +       return 0;
20728 +}
20729 +
20730 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20731 +{
20732 +       struct vcmd_ctx_rlimit_v0 vc_data;
20733 +       int ret;
20734 +
20735 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20736 +               return -EFAULT;
20737 +
20738 +       ret = do_get_rlimit(vxi, vc_data.id,
20739 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20740 +       if (ret)
20741 +               return ret;
20742 +
20743 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20744 +               return -EFAULT;
20745 +       return 0;
20746 +}
20747 +
20748 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20749 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20750 +{
20751 +       if (!is_valid_vlimit(id))
20752 +               return -EINVAL;
20753 +
20754 +       if (maximum != CRLIM_KEEP)
20755 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20756 +       if (softlimit != CRLIM_KEEP)
20757 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20758 +
20759 +       /* clamp soft limit */
20760 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20761 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20762 +
20763 +       return 0;
20764 +}
20765 +
20766 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20767 +{
20768 +       struct vcmd_ctx_rlimit_v0 vc_data;
20769 +
20770 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20771 +               return -EFAULT;
20772 +
20773 +       return do_set_rlimit(vxi, vc_data.id,
20774 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20775 +}
20776 +
20777 +#ifdef CONFIG_IA32_EMULATION
20778 +
20779 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20780 +{
20781 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20782 +
20783 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20784 +               return -EFAULT;
20785 +
20786 +       return do_set_rlimit(vxi, vc_data.id,
20787 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20788 +}
20789 +
20790 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20791 +{
20792 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20793 +       int ret;
20794 +
20795 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20796 +               return -EFAULT;
20797 +
20798 +       ret = do_get_rlimit(vxi, vc_data.id,
20799 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20800 +       if (ret)
20801 +               return ret;
20802 +
20803 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20804 +               return -EFAULT;
20805 +       return 0;
20806 +}
20807 +
20808 +#endif /* CONFIG_IA32_EMULATION */
20809 +
20810 +
20811 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20812 +{
20813 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20814 +               return -EFAULT;
20815 +       return 0;
20816 +}
20817 +
20818 +
20819 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20820 +{
20821 +       rlim_t value;
20822 +       int lim;
20823 +
20824 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20825 +               value = __rlim_get(limit, lim);
20826 +               __rlim_rmax(limit, lim) = value;
20827 +               __rlim_rmin(limit, lim) = value;
20828 +       }
20829 +}
20830 +
20831 +
20832 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20833 +{
20834 +       vx_reset_minmax(&vxi->limit);
20835 +       return 0;
20836 +}
20837 +
20838 +
20839 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20840 +{
20841 +       struct vcmd_rlimit_stat_v0 vc_data;
20842 +       struct _vx_limit *limit = &vxi->limit;
20843 +       int id;
20844 +
20845 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20846 +               return -EFAULT;
20847 +
20848 +       id = vc_data.id;
20849 +       if (!is_accounted_vlimit(id))
20850 +               return -EINVAL;
20851 +
20852 +       vx_limit_fixup(limit, id);
20853 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20854 +       vc_data.value = __rlim_get(limit, id);
20855 +       vc_data.minimum = __rlim_rmin(limit, id);
20856 +       vc_data.maximum = __rlim_rmax(limit, id);
20857 +
20858 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20859 +               return -EFAULT;
20860 +       return 0;
20861 +}
20862 +
20863 +
20864 +void vx_vsi_meminfo(struct sysinfo *val)
20865 +{
20866 +       struct vx_info *vxi = current->vx_info;
20867 +       unsigned long totalram, freeram;
20868 +       rlim_t v;
20869 +
20870 +       /* we blindly accept the max */
20871 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20872 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
20873 +
20874 +       /* total minus used equals free */
20875 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20876 +       freeram = (v < totalram) ? totalram - v : 0;
20877 +
20878 +       val->totalram = totalram;
20879 +       val->freeram = freeram;
20880 +       val->bufferram = 0;
20881 +       val->totalhigh = 0;
20882 +       val->freehigh = 0;
20883 +       return;
20884 +}
20885 +
20886 +void vx_vsi_swapinfo(struct sysinfo *val)
20887 +{
20888 +       struct vx_info *vxi = current->vx_info;
20889 +       unsigned long totalswap, freeswap;
20890 +       rlim_t v, w;
20891 +
20892 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20893 +       if (v == RLIM_INFINITY) {
20894 +               val->freeswap = val->totalswap;
20895 +               return;
20896 +       }
20897 +
20898 +       /* we blindly accept the max */
20899 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
20900 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
20901 +
20902 +       /* currently 'used' swap */
20903 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20904 +       w -= (w > v) ? v : w;
20905 +
20906 +       /* total minus used equals free */
20907 +       freeswap = (w < totalswap) ? totalswap - w : 0;
20908 +
20909 +       val->totalswap = totalswap;
20910 +       val->freeswap = freeswap;
20911 +       return;
20912 +}
20913 +
20914 +
20915 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20916 +{
20917 +       struct vx_info *vxi = mm->mm_vx_info;
20918 +       unsigned long points;
20919 +       rlim_t v, w;
20920 +
20921 +       if (!vxi)
20922 +               return 0;
20923 +
20924 +       points = vxi->vx_badness_bias;
20925 +
20926 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20927 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20928 +       points += (v > w) ? (v - w) : 0;
20929 +
20930 +       return points;
20931 +}
20932 +
20933 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/limit_init.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/limit_init.h
20934 --- linux-2.6.27.3/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
20935 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/limit_init.h     2008-10-13 14:54:20.000000000 +0200
20936 @@ -0,0 +1,31 @@
20937 +
20938 +
20939 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20940 +{
20941 +       int lim;
20942 +
20943 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20944 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20945 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20946 +               __rlim_set(limit, lim, 0);
20947 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20948 +               __rlim_rmin(limit, lim) = 0;
20949 +               __rlim_rmax(limit, lim) = 0;
20950 +       }
20951 +}
20952 +
20953 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20954 +{
20955 +       rlim_t value;
20956 +       int lim;
20957 +
20958 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20959 +               if ((1 << lim) & VLIM_NOCHECK)
20960 +                       continue;
20961 +               value = __rlim_get(limit, lim);
20962 +               vxwprintk_xid(value,
20963 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20964 +                       limit, vlimit_name[lim], lim, (long)value);
20965 +       }
20966 +}
20967 +
20968 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/limit_proc.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/limit_proc.h
20969 --- linux-2.6.27.3/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
20970 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/limit_proc.h     2008-10-13 14:54:20.000000000 +0200
20971 @@ -0,0 +1,57 @@
20972 +#ifndef _VX_LIMIT_PROC_H
20973 +#define _VX_LIMIT_PROC_H
20974 +
20975 +#include <linux/vserver/limit_int.h>
20976 +
20977 +
20978 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20979 +#define VX_LIMIT_TOP   \
20980 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20981 +
20982 +#define VX_LIMIT_ARG(r)                                \
20983 +       (unsigned long)__rlim_get(limit, r),    \
20984 +       (unsigned long)__rlim_rmin(limit, r),   \
20985 +       (unsigned long)__rlim_rmax(limit, r),   \
20986 +       VX_VLIM(__rlim_soft(limit, r)),         \
20987 +       VX_VLIM(__rlim_hard(limit, r)),         \
20988 +       atomic_read(&__rlim_lhit(limit, r))
20989 +
20990 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20991 +{
20992 +       vx_limit_fixup(limit, -1);
20993 +       return sprintf(buffer, VX_LIMIT_TOP
20994 +               "PROC"  VX_LIMIT_FMT
20995 +               "VM"    VX_LIMIT_FMT
20996 +               "VML"   VX_LIMIT_FMT
20997 +               "RSS"   VX_LIMIT_FMT
20998 +               "ANON"  VX_LIMIT_FMT
20999 +               "RMAP"  VX_LIMIT_FMT
21000 +               "FILES" VX_LIMIT_FMT
21001 +               "OFD"   VX_LIMIT_FMT
21002 +               "LOCKS" VX_LIMIT_FMT
21003 +               "SOCK"  VX_LIMIT_FMT
21004 +               "MSGQ"  VX_LIMIT_FMT
21005 +               "SHM"   VX_LIMIT_FMT
21006 +               "SEMA"  VX_LIMIT_FMT
21007 +               "SEMS"  VX_LIMIT_FMT
21008 +               "DENT"  VX_LIMIT_FMT,
21009 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21010 +               VX_LIMIT_ARG(RLIMIT_AS),
21011 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21012 +               VX_LIMIT_ARG(RLIMIT_RSS),
21013 +               VX_LIMIT_ARG(VLIMIT_ANON),
21014 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21015 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21016 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21017 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21018 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21019 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21020 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21021 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21022 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21023 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21024 +}
21025 +
21026 +#endif /* _VX_LIMIT_PROC_H */
21027 +
21028 +
21029 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/Makefile linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/Makefile
21030 --- linux-2.6.27.3/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
21031 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/Makefile 2008-10-13 14:54:20.000000000 +0200
21032 @@ -0,0 +1,18 @@
21033 +#
21034 +# Makefile for the Linux vserver routines.
21035 +#
21036 +
21037 +
21038 +obj-y          += vserver.o
21039 +
21040 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21041 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21042 +                  dlimit.o tag.o
21043 +
21044 +vserver-$(CONFIG_INET) += inet.o
21045 +vserver-$(CONFIG_PROC_FS) += proc.o
21046 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21047 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21048 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21049 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21050 +
21051 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/monitor.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/monitor.c
21052 --- linux-2.6.27.3/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
21053 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/monitor.c        2008-10-13 14:54:20.000000000 +0200
21054 @@ -0,0 +1,138 @@
21055 +/*
21056 + *  kernel/vserver/monitor.c
21057 + *
21058 + *  Virtual Context Scheduler Monitor
21059 + *
21060 + *  Copyright (C) 2006-2007 Herbert Pötzl
21061 + *
21062 + *  V0.01  basic design
21063 + *
21064 + */
21065 +
21066 +#include <linux/module.h>
21067 +#include <linux/jiffies.h>
21068 +#include <asm/uaccess.h>
21069 +#include <asm/atomic.h>
21070 +
21071 +#include <linux/vserver/monitor.h>
21072 +#include <linux/vserver/debug_cmd.h>
21073 +
21074 +
21075 +#ifdef CONFIG_VSERVER_MONITOR
21076 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21077 +#else
21078 +#define VXM_SIZE       64
21079 +#endif
21080 +
21081 +struct _vx_monitor {
21082 +       unsigned int counter;
21083 +
21084 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21085 +};
21086 +
21087 +
21088 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21089 +
21090 +unsigned volatile int vxm_active = 1;
21091 +
21092 +static atomic_t sequence = ATOMIC_INIT(0);
21093 +
21094 +
21095 +/*     vxm_advance()
21096 +
21097 +       * requires disabled preemption                          */
21098 +
21099 +struct _vx_mon_entry *vxm_advance(int cpu)
21100 +{
21101 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21102 +       struct _vx_mon_entry *entry;
21103 +       unsigned int index;
21104 +
21105 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21106 +       entry = &mon->entry[index];
21107 +
21108 +       entry->ev.seq = atomic_inc_return(&sequence);
21109 +       entry->ev.jif = jiffies;
21110 +       return entry;
21111 +}
21112 +
21113 +EXPORT_SYMBOL_GPL(vxm_advance);
21114 +
21115 +
21116 +int do_read_monitor(struct __user _vx_mon_entry *data,
21117 +       int cpu, uint32_t *index, uint32_t *count)
21118 +{
21119 +       int pos, ret = 0;
21120 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21121 +       int end = mon->counter;
21122 +       int start = end - VXM_SIZE + 2;
21123 +       int idx = *index;
21124 +
21125 +       /* special case: get current pos */
21126 +       if (!*count) {
21127 +               *index = end;
21128 +               return 0;
21129 +       }
21130 +
21131 +       /* have we lost some data? */
21132 +       if (idx < start)
21133 +               idx = start;
21134 +
21135 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21136 +               struct _vx_mon_entry *entry =
21137 +                       &mon->entry[idx % VXM_SIZE];
21138 +
21139 +               /* send entry to userspace */
21140 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21141 +               if (ret)
21142 +                       break;
21143 +       }
21144 +       /* save new index and count */
21145 +       *index = idx;
21146 +       *count = pos;
21147 +       return ret ? ret : (*index < end);
21148 +}
21149 +
21150 +int vc_read_monitor(uint32_t id, void __user *data)
21151 +{
21152 +       struct vcmd_read_monitor_v0 vc_data;
21153 +       int ret;
21154 +
21155 +       if (id >= NR_CPUS)
21156 +               return -EINVAL;
21157 +
21158 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21159 +               return -EFAULT;
21160 +
21161 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21162 +               id, &vc_data.index, &vc_data.count);
21163 +
21164 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21165 +               return -EFAULT;
21166 +       return ret;
21167 +}
21168 +
21169 +#ifdef CONFIG_COMPAT
21170 +
21171 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21172 +{
21173 +       struct vcmd_read_monitor_v0_x32 vc_data;
21174 +       int ret;
21175 +
21176 +       if (id >= NR_CPUS)
21177 +               return -EINVAL;
21178 +
21179 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21180 +               return -EFAULT;
21181 +
21182 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21183 +               compat_ptr(vc_data.data_ptr),
21184 +               id, &vc_data.index, &vc_data.count);
21185 +
21186 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21187 +               return -EFAULT;
21188 +       return ret;
21189 +}
21190 +
21191 +#endif /* CONFIG_COMPAT */
21192 +
21193 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/network.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/network.c
21194 --- linux-2.6.27.3/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
21195 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/network.c        2008-10-13 14:54:20.000000000 +0200
21196 @@ -0,0 +1,864 @@
21197 +/*
21198 + *  linux/kernel/vserver/network.c
21199 + *
21200 + *  Virtual Server: Network Support
21201 + *
21202 + *  Copyright (C) 2003-2007  Herbert Pötzl
21203 + *
21204 + *  V0.01  broken out from vcontext V0.05
21205 + *  V0.02  cleaned up implementation
21206 + *  V0.03  added equiv nx commands
21207 + *  V0.04  switch to RCU based hash
21208 + *  V0.05  and back to locking again
21209 + *  V0.06  changed vcmds to nxi arg
21210 + *  V0.07  have __create claim() the nxi
21211 + *
21212 + */
21213 +
21214 +#include <linux/err.h>
21215 +#include <linux/slab.h>
21216 +#include <linux/rcupdate.h>
21217 +
21218 +#include <linux/vs_network.h>
21219 +#include <linux/vs_pid.h>
21220 +#include <linux/vserver/network_cmd.h>
21221 +
21222 +
21223 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21224 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21225 +
21226 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21227 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21228 +
21229 +
21230 +static int __init init_network(void)
21231 +{
21232 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21233 +               sizeof(struct nx_addr_v4), 0,
21234 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21235 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21236 +               sizeof(struct nx_addr_v6), 0,
21237 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21238 +       return 0;
21239 +}
21240 +
21241 +
21242 +/*     __alloc_nx_addr_v4()                                    */
21243 +
21244 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21245 +{
21246 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21247 +               nx_addr_v4_cachep, GFP_KERNEL);
21248 +
21249 +       if (!IS_ERR(nxa))
21250 +               memset(nxa, 0, sizeof(*nxa));
21251 +       return nxa;
21252 +}
21253 +
21254 +/*     __dealloc_nx_addr_v4()                                  */
21255 +
21256 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21257 +{
21258 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21259 +}
21260 +
21261 +/*     __dealloc_nx_addr_v4_all()                              */
21262 +
21263 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21264 +{
21265 +       while (nxa) {
21266 +               struct nx_addr_v4 *next = nxa->next;
21267 +
21268 +               __dealloc_nx_addr_v4(nxa);
21269 +               nxa = next;
21270 +       }
21271 +}
21272 +
21273 +
21274 +#ifdef CONFIG_IPV6
21275 +
21276 +/*     __alloc_nx_addr_v6()                                    */
21277 +
21278 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21279 +{
21280 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21281 +               nx_addr_v6_cachep, GFP_KERNEL);
21282 +
21283 +       if (!IS_ERR(nxa))
21284 +               memset(nxa, 0, sizeof(*nxa));
21285 +       return nxa;
21286 +}
21287 +
21288 +/*     __dealloc_nx_addr_v6()                                  */
21289 +
21290 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21291 +{
21292 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21293 +}
21294 +
21295 +/*     __dealloc_nx_addr_v6_all()                              */
21296 +
21297 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21298 +{
21299 +       while (nxa) {
21300 +               struct nx_addr_v6 *next = nxa->next;
21301 +
21302 +               __dealloc_nx_addr_v6(nxa);
21303 +               nxa = next;
21304 +       }
21305 +}
21306 +
21307 +#endif /* CONFIG_IPV6 */
21308 +
21309 +/*     __alloc_nx_info()
21310 +
21311 +       * allocate an initialized nx_info struct
21312 +       * doesn't make it visible (hash)                        */
21313 +
21314 +static struct nx_info *__alloc_nx_info(nid_t nid)
21315 +{
21316 +       struct nx_info *new = NULL;
21317 +
21318 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21319 +
21320 +       /* would this benefit from a slab cache? */
21321 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21322 +       if (!new)
21323 +               return 0;
21324 +
21325 +       memset(new, 0, sizeof(struct nx_info));
21326 +       new->nx_id = nid;
21327 +       INIT_HLIST_NODE(&new->nx_hlist);
21328 +       atomic_set(&new->nx_usecnt, 0);
21329 +       atomic_set(&new->nx_tasks, 0);
21330 +       new->nx_state = 0;
21331 +
21332 +       new->nx_flags = NXF_INIT_SET;
21333 +
21334 +       /* rest of init goes here */
21335 +
21336 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21337 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21338 +
21339 +       vxdprintk(VXD_CBIT(nid, 0),
21340 +               "alloc_nx_info(%d) = %p", nid, new);
21341 +       atomic_inc(&nx_global_ctotal);
21342 +       return new;
21343 +}
21344 +
21345 +/*     __dealloc_nx_info()
21346 +
21347 +       * final disposal of nx_info                             */
21348 +
21349 +static void __dealloc_nx_info(struct nx_info *nxi)
21350 +{
21351 +       vxdprintk(VXD_CBIT(nid, 0),
21352 +               "dealloc_nx_info(%p)", nxi);
21353 +
21354 +       nxi->nx_hlist.next = LIST_POISON1;
21355 +       nxi->nx_id = -1;
21356 +
21357 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21358 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21359 +
21360 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21361 +
21362 +       nxi->nx_state |= NXS_RELEASED;
21363 +       kfree(nxi);
21364 +       atomic_dec(&nx_global_ctotal);
21365 +}
21366 +
21367 +static void __shutdown_nx_info(struct nx_info *nxi)
21368 +{
21369 +       nxi->nx_state |= NXS_SHUTDOWN;
21370 +       vs_net_change(nxi, VSC_NETDOWN);
21371 +}
21372 +
21373 +/*     exported stuff                                          */
21374 +
21375 +void free_nx_info(struct nx_info *nxi)
21376 +{
21377 +       /* context shutdown is mandatory */
21378 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21379 +
21380 +       /* context must not be hashed */
21381 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21382 +
21383 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21384 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21385 +
21386 +       __dealloc_nx_info(nxi);
21387 +}
21388 +
21389 +
21390 +void __nx_set_lback(struct nx_info *nxi)
21391 +{
21392 +       int nid = nxi->nx_id;
21393 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21394 +
21395 +       nxi->v4_lback.s_addr = lback;
21396 +}
21397 +
21398 +extern int __nx_inet_add_lback(__be32 addr);
21399 +extern int __nx_inet_del_lback(__be32 addr);
21400 +
21401 +
21402 +/*     hash table for nx_info hash */
21403 +
21404 +#define NX_HASH_SIZE   13
21405 +
21406 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21407 +
21408 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21409 +
21410 +
21411 +static inline unsigned int __hashval(nid_t nid)
21412 +{
21413 +       return (nid % NX_HASH_SIZE);
21414 +}
21415 +
21416 +
21417 +
21418 +/*     __hash_nx_info()
21419 +
21420 +       * add the nxi to the global hash table
21421 +       * requires the hash_lock to be held                     */
21422 +
21423 +static inline void __hash_nx_info(struct nx_info *nxi)
21424 +{
21425 +       struct hlist_head *head;
21426 +
21427 +       vxd_assert_lock(&nx_info_hash_lock);
21428 +       vxdprintk(VXD_CBIT(nid, 4),
21429 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21430 +
21431 +       /* context must not be hashed */
21432 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21433 +
21434 +       nxi->nx_state |= NXS_HASHED;
21435 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21436 +       hlist_add_head(&nxi->nx_hlist, head);
21437 +       atomic_inc(&nx_global_cactive);
21438 +}
21439 +
21440 +/*     __unhash_nx_info()
21441 +
21442 +       * remove the nxi from the global hash table
21443 +       * requires the hash_lock to be held                     */
21444 +
21445 +static inline void __unhash_nx_info(struct nx_info *nxi)
21446 +{
21447 +       vxd_assert_lock(&nx_info_hash_lock);
21448 +       vxdprintk(VXD_CBIT(nid, 4),
21449 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21450 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21451 +
21452 +       /* context must be hashed */
21453 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21454 +       /* but without tasks */
21455 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21456 +
21457 +       nxi->nx_state &= ~NXS_HASHED;
21458 +       hlist_del(&nxi->nx_hlist);
21459 +       atomic_dec(&nx_global_cactive);
21460 +}
21461 +
21462 +
21463 +/*     __lookup_nx_info()
21464 +
21465 +       * requires the hash_lock to be held
21466 +       * doesn't increment the nx_refcnt                       */
21467 +
21468 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21469 +{
21470 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21471 +       struct hlist_node *pos;
21472 +       struct nx_info *nxi;
21473 +
21474 +       vxd_assert_lock(&nx_info_hash_lock);
21475 +       hlist_for_each(pos, head) {
21476 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21477 +
21478 +               if (nxi->nx_id == nid)
21479 +                       goto found;
21480 +       }
21481 +       nxi = NULL;
21482 +found:
21483 +       vxdprintk(VXD_CBIT(nid, 0),
21484 +               "__lookup_nx_info(#%u): %p[#%u]",
21485 +               nid, nxi, nxi ? nxi->nx_id : 0);
21486 +       return nxi;
21487 +}
21488 +
21489 +
21490 +/*     __create_nx_info()
21491 +
21492 +       * create the requested context
21493 +       * get(), claim() and hash it                            */
21494 +
21495 +static struct nx_info *__create_nx_info(int id)
21496 +{
21497 +       struct nx_info *new, *nxi = NULL;
21498 +
21499 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21500 +
21501 +       if (!(new = __alloc_nx_info(id)))
21502 +               return ERR_PTR(-ENOMEM);
21503 +
21504 +       /* required to make dynamic xids unique */
21505 +       spin_lock(&nx_info_hash_lock);
21506 +
21507 +       /* static context requested */
21508 +       if ((nxi = __lookup_nx_info(id))) {
21509 +               vxdprintk(VXD_CBIT(nid, 0),
21510 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21511 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21512 +                       nxi = ERR_PTR(-EBUSY);
21513 +               else
21514 +                       nxi = ERR_PTR(-EEXIST);
21515 +               goto out_unlock;
21516 +       }
21517 +       /* new context */
21518 +       vxdprintk(VXD_CBIT(nid, 0),
21519 +               "create_nx_info(%d) = %p (new)", id, new);
21520 +       claim_nx_info(new, NULL);
21521 +       __nx_set_lback(new);
21522 +       __hash_nx_info(get_nx_info(new));
21523 +       nxi = new, new = NULL;
21524 +
21525 +out_unlock:
21526 +       spin_unlock(&nx_info_hash_lock);
21527 +       if (new)
21528 +               __dealloc_nx_info(new);
21529 +       return nxi;
21530 +}
21531 +
21532 +
21533 +
21534 +/*     exported stuff                                          */
21535 +
21536 +
21537 +void unhash_nx_info(struct nx_info *nxi)
21538 +{
21539 +       __shutdown_nx_info(nxi);
21540 +       spin_lock(&nx_info_hash_lock);
21541 +       __unhash_nx_info(nxi);
21542 +       spin_unlock(&nx_info_hash_lock);
21543 +}
21544 +
21545 +/*     lookup_nx_info()
21546 +
21547 +       * search for a nx_info and get() it
21548 +       * negative id means current                             */
21549 +
21550 +struct nx_info *lookup_nx_info(int id)
21551 +{
21552 +       struct nx_info *nxi = NULL;
21553 +
21554 +       if (id < 0) {
21555 +               nxi = get_nx_info(current->nx_info);
21556 +       } else if (id > 1) {
21557 +               spin_lock(&nx_info_hash_lock);
21558 +               nxi = get_nx_info(__lookup_nx_info(id));
21559 +               spin_unlock(&nx_info_hash_lock);
21560 +       }
21561 +       return nxi;
21562 +}
21563 +
21564 +/*     nid_is_hashed()
21565 +
21566 +       * verify that nid is still hashed                       */
21567 +
21568 +int nid_is_hashed(nid_t nid)
21569 +{
21570 +       int hashed;
21571 +
21572 +       spin_lock(&nx_info_hash_lock);
21573 +       hashed = (__lookup_nx_info(nid) != NULL);
21574 +       spin_unlock(&nx_info_hash_lock);
21575 +       return hashed;
21576 +}
21577 +
21578 +
21579 +#ifdef CONFIG_PROC_FS
21580 +
21581 +/*     get_nid_list()
21582 +
21583 +       * get a subset of hashed nids for proc
21584 +       * assumes size is at least one                          */
21585 +
21586 +int get_nid_list(int index, unsigned int *nids, int size)
21587 +{
21588 +       int hindex, nr_nids = 0;
21589 +
21590 +       /* only show current and children */
21591 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21592 +               if (index > 0)
21593 +                       return 0;
21594 +               nids[nr_nids] = nx_current_nid();
21595 +               return 1;
21596 +       }
21597 +
21598 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21599 +               struct hlist_head *head = &nx_info_hash[hindex];
21600 +               struct hlist_node *pos;
21601 +
21602 +               spin_lock(&nx_info_hash_lock);
21603 +               hlist_for_each(pos, head) {
21604 +                       struct nx_info *nxi;
21605 +
21606 +                       if (--index > 0)
21607 +                               continue;
21608 +
21609 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21610 +                       nids[nr_nids] = nxi->nx_id;
21611 +                       if (++nr_nids >= size) {
21612 +                               spin_unlock(&nx_info_hash_lock);
21613 +                               goto out;
21614 +                       }
21615 +               }
21616 +               /* keep the lock time short */
21617 +               spin_unlock(&nx_info_hash_lock);
21618 +       }
21619 +out:
21620 +       return nr_nids;
21621 +}
21622 +#endif
21623 +
21624 +
21625 +/*
21626 + *     migrate task to new network
21627 + *     gets nxi, puts old_nxi on change
21628 + */
21629 +
21630 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21631 +{
21632 +       struct nx_info *old_nxi;
21633 +       int ret = 0;
21634 +
21635 +       if (!p || !nxi)
21636 +               BUG();
21637 +
21638 +       vxdprintk(VXD_CBIT(nid, 5),
21639 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21640 +               p, nxi, nxi->nx_id,
21641 +               atomic_read(&nxi->nx_usecnt),
21642 +               atomic_read(&nxi->nx_tasks));
21643 +
21644 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21645 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21646 +               return -EACCES;
21647 +
21648 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21649 +               return -EFAULT;
21650 +
21651 +       /* maybe disallow this completely? */
21652 +       old_nxi = task_get_nx_info(p);
21653 +       if (old_nxi == nxi)
21654 +               goto out;
21655 +
21656 +       task_lock(p);
21657 +       if (old_nxi)
21658 +               clr_nx_info(&p->nx_info);
21659 +       claim_nx_info(nxi, p);
21660 +       set_nx_info(&p->nx_info, nxi);
21661 +       p->nid = nxi->nx_id;
21662 +       task_unlock(p);
21663 +
21664 +       vxdprintk(VXD_CBIT(nid, 5),
21665 +               "moved task %p into nxi:%p[#%d]",
21666 +               p, nxi, nxi->nx_id);
21667 +
21668 +       if (old_nxi)
21669 +               release_nx_info(old_nxi, p);
21670 +       ret = 0;
21671 +out:
21672 +       put_nx_info(old_nxi);
21673 +       return ret;
21674 +}
21675 +
21676 +
21677 +void nx_set_persistent(struct nx_info *nxi)
21678 +{
21679 +       vxdprintk(VXD_CBIT(nid, 6),
21680 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21681 +
21682 +       get_nx_info(nxi);
21683 +       claim_nx_info(nxi, NULL);
21684 +}
21685 +
21686 +void nx_clear_persistent(struct nx_info *nxi)
21687 +{
21688 +       vxdprintk(VXD_CBIT(nid, 6),
21689 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21690 +
21691 +       release_nx_info(nxi, NULL);
21692 +       put_nx_info(nxi);
21693 +}
21694 +
21695 +void nx_update_persistent(struct nx_info *nxi)
21696 +{
21697 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21698 +               nx_set_persistent(nxi);
21699 +       else
21700 +               nx_clear_persistent(nxi);
21701 +}
21702 +
21703 +/* vserver syscall commands below here */
21704 +
21705 +/* taks nid and nx_info functions */
21706 +
21707 +#include <asm/uaccess.h>
21708 +
21709 +
21710 +int vc_task_nid(uint32_t id)
21711 +{
21712 +       nid_t nid;
21713 +
21714 +       if (id) {
21715 +               struct task_struct *tsk;
21716 +
21717 +               read_lock(&tasklist_lock);
21718 +               tsk = find_task_by_real_pid(id);
21719 +               nid = (tsk) ? tsk->nid : -ESRCH;
21720 +               read_unlock(&tasklist_lock);
21721 +       } else
21722 +               nid = nx_current_nid();
21723 +       return nid;
21724 +}
21725 +
21726 +
21727 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21728 +{
21729 +       struct vcmd_nx_info_v0 vc_data;
21730 +
21731 +       vc_data.nid = nxi->nx_id;
21732 +
21733 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21734 +               return -EFAULT;
21735 +       return 0;
21736 +}
21737 +
21738 +
21739 +/* network functions */
21740 +
21741 +int vc_net_create(uint32_t nid, void __user *data)
21742 +{
21743 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21744 +       struct nx_info *new_nxi;
21745 +       int ret;
21746 +
21747 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21748 +               return -EFAULT;
21749 +
21750 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21751 +               return -EINVAL;
21752 +
21753 +       new_nxi = __create_nx_info(nid);
21754 +       if (IS_ERR(new_nxi))
21755 +               return PTR_ERR(new_nxi);
21756 +
21757 +       /* initial flags */
21758 +       new_nxi->nx_flags = vc_data.flagword;
21759 +
21760 +       ret = -ENOEXEC;
21761 +       if (vs_net_change(new_nxi, VSC_NETUP))
21762 +               goto out;
21763 +
21764 +       ret = nx_migrate_task(current, new_nxi);
21765 +       if (ret)
21766 +               goto out;
21767 +
21768 +       /* return context id on success */
21769 +       ret = new_nxi->nx_id;
21770 +
21771 +       /* get a reference for persistent contexts */
21772 +       if ((vc_data.flagword & NXF_PERSISTENT))
21773 +               nx_set_persistent(new_nxi);
21774 +out:
21775 +       release_nx_info(new_nxi, NULL);
21776 +       put_nx_info(new_nxi);
21777 +       return ret;
21778 +}
21779 +
21780 +
21781 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21782 +{
21783 +       return nx_migrate_task(current, nxi);
21784 +}
21785 +
21786 +
21787 +
21788 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21789 +       uint16_t type, uint16_t flags)
21790 +{
21791 +       struct nx_addr_v4 *nxa = &nxi->v4;
21792 +
21793 +       if (NX_IPV4(nxi)) {
21794 +               /* locate last entry */
21795 +               for (; nxa->next; nxa = nxa->next);
21796 +               nxa->next = __alloc_nx_addr_v4();
21797 +               nxa = nxa->next;
21798 +
21799 +               if (IS_ERR(nxa))
21800 +                       return PTR_ERR(nxa);
21801 +       }
21802 +
21803 +       if (nxi->v4.next)
21804 +               /* remove single ip for ip list */
21805 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21806 +
21807 +       nxa->ip[0].s_addr = ip;
21808 +       nxa->ip[1].s_addr = ip2;
21809 +       nxa->mask.s_addr = mask;
21810 +       nxa->type = type;
21811 +       nxa->flags = flags;
21812 +       return 0;
21813 +}
21814 +
21815 +
21816 +int vc_net_add(struct nx_info *nxi, void __user *data)
21817 +{
21818 +       struct vcmd_net_addr_v0 vc_data;
21819 +       int index, ret = 0;
21820 +
21821 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21822 +               return -EFAULT;
21823 +
21824 +       switch (vc_data.type) {
21825 +       case NXA_TYPE_IPV4:
21826 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21827 +                       return -EINVAL;
21828 +
21829 +               index = 0;
21830 +               while (index < vc_data.count) {
21831 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21832 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21833 +                       if (ret)
21834 +                               return ret;
21835 +                       index++;
21836 +               }
21837 +               ret = index;
21838 +               break;
21839 +
21840 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21841 +               nxi->v4_bcast = vc_data.ip[0];
21842 +               ret = 1;
21843 +               break;
21844 +
21845 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21846 +               nxi->v4_lback = vc_data.ip[0];
21847 +               ret = 1;
21848 +               break;
21849 +
21850 +       default:
21851 +               ret = -EINVAL;
21852 +               break;
21853 +       }
21854 +       return ret;
21855 +}
21856 +
21857 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21858 +{
21859 +       struct vcmd_net_addr_v0 vc_data;
21860 +
21861 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21862 +               return -EFAULT;
21863 +
21864 +       switch (vc_data.type) {
21865 +       case NXA_TYPE_ANY:
21866 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21867 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21868 +               break;
21869 +
21870 +       default:
21871 +               return -EINVAL;
21872 +       }
21873 +       return 0;
21874 +}
21875 +
21876 +
21877 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21878 +{
21879 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21880 +
21881 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21882 +               return -EFAULT;
21883 +
21884 +       switch (vc_data.type) {
21885 +       case NXA_TYPE_ADDR:
21886 +       case NXA_TYPE_RANGE:
21887 +       case NXA_TYPE_MASK:
21888 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21889 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21890 +
21891 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21892 +               nxi->v4_bcast = vc_data.ip;
21893 +               break;
21894 +
21895 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21896 +               nxi->v4_lback = vc_data.ip;
21897 +               break;
21898 +
21899 +       default:
21900 +               return -EINVAL;
21901 +       }
21902 +       return 0;
21903 +}
21904 +
21905 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21906 +{
21907 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21908 +
21909 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21910 +               return -EFAULT;
21911 +
21912 +       switch (vc_data.type) {
21913 +/*     case NXA_TYPE_ADDR:
21914 +               break;          */
21915 +
21916 +       case NXA_TYPE_ANY:
21917 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21918 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21919 +               break;
21920 +
21921 +       default:
21922 +               return -EINVAL;
21923 +       }
21924 +       return 0;
21925 +}
21926 +
21927 +
21928 +#ifdef CONFIG_IPV6
21929 +
21930 +int do_add_v6_addr(struct nx_info *nxi,
21931 +       struct in6_addr *ip, struct in6_addr *mask,
21932 +       uint32_t prefix, uint16_t type, uint16_t flags)
21933 +{
21934 +       struct nx_addr_v6 *nxa = &nxi->v6;
21935 +
21936 +       if (NX_IPV6(nxi)) {
21937 +               /* locate last entry */
21938 +               for (; nxa->next; nxa = nxa->next);
21939 +               nxa->next = __alloc_nx_addr_v6();
21940 +               nxa = nxa->next;
21941 +
21942 +               if (IS_ERR(nxa))
21943 +                       return PTR_ERR(nxa);
21944 +       }
21945 +
21946 +       nxa->ip = *ip;
21947 +       nxa->mask = *mask;
21948 +       nxa->prefix = prefix;
21949 +       nxa->type = type;
21950 +       nxa->flags = flags;
21951 +       return 0;
21952 +}
21953 +
21954 +
21955 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21956 +{
21957 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21958 +
21959 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21960 +               return -EFAULT;
21961 +
21962 +       switch (vc_data.type) {
21963 +       case NXA_TYPE_ADDR:
21964 +       case NXA_TYPE_MASK:
21965 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21966 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21967 +       default:
21968 +               return -EINVAL;
21969 +       }
21970 +       return 0;
21971 +}
21972 +
21973 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21974 +{
21975 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21976 +
21977 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21978 +               return -EFAULT;
21979 +
21980 +       switch (vc_data.type) {
21981 +       case NXA_TYPE_ANY:
21982 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21983 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21984 +               break;
21985 +
21986 +       default:
21987 +               return -EINVAL;
21988 +       }
21989 +       return 0;
21990 +}
21991 +
21992 +#endif /* CONFIG_IPV6 */
21993 +
21994 +
21995 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21996 +{
21997 +       struct vcmd_net_flags_v0 vc_data;
21998 +
21999 +       vc_data.flagword = nxi->nx_flags;
22000 +
22001 +       /* special STATE flag handling */
22002 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22003 +
22004 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22005 +               return -EFAULT;
22006 +       return 0;
22007 +}
22008 +
22009 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22010 +{
22011 +       struct vcmd_net_flags_v0 vc_data;
22012 +       uint64_t mask, trigger;
22013 +
22014 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22015 +               return -EFAULT;
22016 +
22017 +       /* special STATE flag handling */
22018 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22019 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22020 +
22021 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22022 +               vc_data.flagword, mask);
22023 +       if (trigger & NXF_PERSISTENT)
22024 +               nx_update_persistent(nxi);
22025 +
22026 +       return 0;
22027 +}
22028 +
22029 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22030 +{
22031 +       struct vcmd_net_caps_v0 vc_data;
22032 +
22033 +       vc_data.ncaps = nxi->nx_ncaps;
22034 +       vc_data.cmask = ~0ULL;
22035 +
22036 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22037 +               return -EFAULT;
22038 +       return 0;
22039 +}
22040 +
22041 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22042 +{
22043 +       struct vcmd_net_caps_v0 vc_data;
22044 +
22045 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22046 +               return -EFAULT;
22047 +
22048 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22049 +               vc_data.ncaps, vc_data.cmask);
22050 +       return 0;
22051 +}
22052 +
22053 +
22054 +#include <linux/module.h>
22055 +
22056 +module_init(init_network);
22057 +
22058 +EXPORT_SYMBOL_GPL(free_nx_info);
22059 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22060 +
22061 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/proc.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/proc.c
22062 --- linux-2.6.27.3/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
22063 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/proc.c   2008-10-13 14:54:20.000000000 +0200
22064 @@ -0,0 +1,1086 @@
22065 +/*
22066 + *  linux/kernel/vserver/proc.c
22067 + *
22068 + *  Virtual Context Support
22069 + *
22070 + *  Copyright (C) 2003-2007  Herbert Pötzl
22071 + *
22072 + *  V0.01  basic structure
22073 + *  V0.02  adaptation vs1.3.0
22074 + *  V0.03  proc permissions
22075 + *  V0.04  locking/generic
22076 + *  V0.05  next generation procfs
22077 + *  V0.06  inode validation
22078 + *  V0.07  generic rewrite vid
22079 + *  V0.08  remove inode type
22080 + *
22081 + */
22082 +
22083 +#include <linux/proc_fs.h>
22084 +#include <asm/unistd.h>
22085 +
22086 +#include <linux/vs_context.h>
22087 +#include <linux/vs_network.h>
22088 +#include <linux/vs_cvirt.h>
22089 +
22090 +#include <linux/in.h>
22091 +#include <linux/inetdevice.h>
22092 +#include <linux/vs_inet.h>
22093 +#include <linux/vs_inet6.h>
22094 +
22095 +#include <linux/vserver/global.h>
22096 +
22097 +#include "cvirt_proc.h"
22098 +#include "cacct_proc.h"
22099 +#include "limit_proc.h"
22100 +#include "sched_proc.h"
22101 +#include "vci_config.h"
22102 +
22103 +
22104 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22105 +{
22106 +       unsigned __capi;
22107 +
22108 +       CAP_FOR_EACH_U32(__capi) {
22109 +               buffer += sprintf(buffer, "%08x",
22110 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22111 +       }
22112 +       return buffer;
22113 +}
22114 +
22115 +
22116 +static struct proc_dir_entry *proc_virtual;
22117 +
22118 +static struct proc_dir_entry *proc_virtnet;
22119 +
22120 +
22121 +/* first the actual feeds */
22122 +
22123 +
22124 +static int proc_vci(char *buffer)
22125 +{
22126 +       return sprintf(buffer,
22127 +               "VCIVersion:\t%04x:%04x\n"
22128 +               "VCISyscall:\t%d\n"
22129 +               "VCIKernel:\t%08x\n",
22130 +               VCI_VERSION >> 16,
22131 +               VCI_VERSION & 0xFFFF,
22132 +               __NR_vserver,
22133 +               vci_kernel_config());
22134 +}
22135 +
22136 +static int proc_virtual_info(char *buffer)
22137 +{
22138 +       return proc_vci(buffer);
22139 +}
22140 +
22141 +static int proc_virtual_status(char *buffer)
22142 +{
22143 +       return sprintf(buffer,
22144 +               "#CTotal:\t%d\n"
22145 +               "#CActive:\t%d\n"
22146 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22147 +               atomic_read(&vx_global_ctotal),
22148 +               atomic_read(&vx_global_cactive),
22149 +               atomic_read(&vs_global_nsproxy),
22150 +               atomic_read(&vs_global_fs),
22151 +               atomic_read(&vs_global_mnt_ns),
22152 +               atomic_read(&vs_global_uts_ns),
22153 +               atomic_read(&vs_global_ipc_ns),
22154 +               atomic_read(&vs_global_user_ns),
22155 +               atomic_read(&vs_global_pid_ns));
22156 +}
22157 +
22158 +
22159 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22160 +{
22161 +       int length;
22162 +
22163 +       length = sprintf(buffer,
22164 +               "ID:\t%d\n"
22165 +               "Info:\t%p\n"
22166 +               "Init:\t%d\n"
22167 +               "OOM:\t%lld\n",
22168 +               vxi->vx_id,
22169 +               vxi,
22170 +               vxi->vx_initpid,
22171 +               vxi->vx_badness_bias);
22172 +       return length;
22173 +}
22174 +
22175 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22176 +{
22177 +       char *orig = buffer;
22178 +
22179 +       buffer += sprintf(buffer,
22180 +               "UseCnt:\t%d\n"
22181 +               "Tasks:\t%d\n"
22182 +               "Flags:\t%016llx\n",
22183 +               atomic_read(&vxi->vx_usecnt),
22184 +               atomic_read(&vxi->vx_tasks),
22185 +               (unsigned long long)vxi->vx_flags);
22186 +
22187 +       buffer += sprintf(buffer, "BCaps:\t");
22188 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22189 +       buffer += sprintf(buffer, "\n");
22190 +
22191 +       buffer += sprintf(buffer,
22192 +               "CCaps:\t%016llx\n"
22193 +               "Spaces:\t%08lx\n",
22194 +               (unsigned long long)vxi->vx_ccaps,
22195 +               vxi->vx_nsmask);
22196 +       return buffer - orig;
22197 +}
22198 +
22199 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22200 +{
22201 +       return vx_info_proc_limit(&vxi->limit, buffer);
22202 +}
22203 +
22204 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22205 +{
22206 +       int cpu, length;
22207 +
22208 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22209 +       for_each_online_cpu(cpu) {
22210 +               length += vx_info_proc_sched_pc(
22211 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22212 +                       buffer + length, cpu);
22213 +       }
22214 +       return length;
22215 +}
22216 +
22217 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
22218 +{
22219 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
22220 +}
22221 +
22222 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22223 +{
22224 +       int cpu, length;
22225 +
22226 +       vx_update_load(vxi);
22227 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22228 +       for_each_online_cpu(cpu) {
22229 +               length += vx_info_proc_cvirt_pc(
22230 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22231 +                       buffer + length, cpu);
22232 +       }
22233 +       return length;
22234 +}
22235 +
22236 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22237 +{
22238 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22239 +}
22240 +
22241 +
22242 +static int proc_virtnet_info(char *buffer)
22243 +{
22244 +       return proc_vci(buffer);
22245 +}
22246 +
22247 +static int proc_virtnet_status(char *buffer)
22248 +{
22249 +       return sprintf(buffer,
22250 +               "#CTotal:\t%d\n"
22251 +               "#CActive:\t%d\n",
22252 +               atomic_read(&nx_global_ctotal),
22253 +               atomic_read(&nx_global_cactive));
22254 +}
22255 +
22256 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22257 +{
22258 +       struct nx_addr_v4 *v4a;
22259 +#ifdef CONFIG_IPV6
22260 +       struct nx_addr_v6 *v6a;
22261 +#endif
22262 +       int length, i;
22263 +
22264 +       length = sprintf(buffer,
22265 +               "ID:\t%d\n"
22266 +               "Info:\t%p\n"
22267 +               "Bcast:\t" NIPQUAD_FMT "\n"
22268 +               "Lback:\t" NIPQUAD_FMT "\n",
22269 +               nxi->nx_id,
22270 +               nxi,
22271 +               NIPQUAD(nxi->v4_bcast.s_addr),
22272 +               NIPQUAD(nxi->v4_lback.s_addr));
22273 +
22274 +       if (!NX_IPV4(nxi))
22275 +               goto skip_v4;
22276 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22277 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22278 +                       i, NXAV4(v4a));
22279 +skip_v4:
22280 +#ifdef CONFIG_IPV6
22281 +       if (!NX_IPV6(nxi))
22282 +               goto skip_v6;
22283 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22284 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22285 +                       i, NXAV6(v6a));
22286 +skip_v6:
22287 +#endif
22288 +       return length;
22289 +}
22290 +
22291 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22292 +{
22293 +       int length;
22294 +
22295 +       length = sprintf(buffer,
22296 +               "UseCnt:\t%d\n"
22297 +               "Tasks:\t%d\n"
22298 +               "Flags:\t%016llx\n"
22299 +               "NCaps:\t%016llx\n",
22300 +               atomic_read(&nxi->nx_usecnt),
22301 +               atomic_read(&nxi->nx_tasks),
22302 +               (unsigned long long)nxi->nx_flags,
22303 +               (unsigned long long)nxi->nx_ncaps);
22304 +       return length;
22305 +}
22306 +
22307 +
22308 +
22309 +/* here the inode helpers */
22310 +
22311 +struct vs_entry {
22312 +       int len;
22313 +       char *name;
22314 +       mode_t mode;
22315 +       struct inode_operations *iop;
22316 +       struct file_operations *fop;
22317 +       union proc_op op;
22318 +};
22319 +
22320 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22321 +{
22322 +       struct inode *inode = new_inode(sb);
22323 +
22324 +       if (!inode)
22325 +               goto out;
22326 +
22327 +       inode->i_mode = p->mode;
22328 +       if (p->iop)
22329 +               inode->i_op = p->iop;
22330 +       if (p->fop)
22331 +               inode->i_fop = p->fop;
22332 +
22333 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22334 +       inode->i_flags |= S_IMMUTABLE;
22335 +
22336 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22337 +
22338 +       inode->i_uid = 0;
22339 +       inode->i_gid = 0;
22340 +       inode->i_tag = 0;
22341 +out:
22342 +       return inode;
22343 +}
22344 +
22345 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22346 +       struct dentry *dentry, int id, void *ptr)
22347 +{
22348 +       struct vs_entry *p = ptr;
22349 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22350 +       struct dentry *error = ERR_PTR(-EINVAL);
22351 +
22352 +       if (!inode)
22353 +               goto out;
22354 +
22355 +       PROC_I(inode)->op = p->op;
22356 +       PROC_I(inode)->fd = id;
22357 +       d_add(dentry, inode);
22358 +       error = NULL;
22359 +out:
22360 +       return error;
22361 +}
22362 +
22363 +/* Lookups */
22364 +
22365 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22366 +
22367 +/*
22368 + * Fill a directory entry.
22369 + *
22370 + * If possible create the dcache entry and derive our inode number and
22371 + * file type from dcache entry.
22372 + *
22373 + * Since all of the proc inode numbers are dynamically generated, the inode
22374 + * numbers do not exist until the inode is cache.  This means creating the
22375 + * the dcache entry in readdir is necessary to keep the inode numbers
22376 + * reported by readdir in sync with the inode numbers reported
22377 + * by stat.
22378 + */
22379 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22380 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22381 +{
22382 +       struct dentry *child, *dir = filp->f_dentry;
22383 +       struct inode *inode;
22384 +       struct qstr qname;
22385 +       ino_t ino = 0;
22386 +       unsigned type = DT_UNKNOWN;
22387 +
22388 +       qname.name = name;
22389 +       qname.len  = len;
22390 +       qname.hash = full_name_hash(name, len);
22391 +
22392 +       child = d_lookup(dir, &qname);
22393 +       if (!child) {
22394 +               struct dentry *new;
22395 +               new = d_alloc(dir, &qname);
22396 +               if (new) {
22397 +                       child = instantiate(dir->d_inode, new, id, ptr);
22398 +                       if (child)
22399 +                               dput(new);
22400 +                       else
22401 +                               child = new;
22402 +               }
22403 +       }
22404 +       if (!child || IS_ERR(child) || !child->d_inode)
22405 +               goto end_instantiate;
22406 +       inode = child->d_inode;
22407 +       if (inode) {
22408 +               ino = inode->i_ino;
22409 +               type = inode->i_mode >> 12;
22410 +       }
22411 +       dput(child);
22412 +end_instantiate:
22413 +       if (!ino)
22414 +               ino = find_inode_number(dir, &qname);
22415 +       if (!ino)
22416 +               ino = 1;
22417 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22418 +}
22419 +
22420 +
22421 +
22422 +/* get and revalidate vx_info/xid */
22423 +
22424 +static inline
22425 +struct vx_info *get_proc_vx_info(struct inode *inode)
22426 +{
22427 +       return lookup_vx_info(PROC_I(inode)->fd);
22428 +}
22429 +
22430 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22431 +{
22432 +       struct inode *inode = dentry->d_inode;
22433 +       xid_t xid = PROC_I(inode)->fd;
22434 +
22435 +       if (!xid || xid_is_hashed(xid))
22436 +               return 1;
22437 +       d_drop(dentry);
22438 +       return 0;
22439 +}
22440 +
22441 +
22442 +/* get and revalidate nx_info/nid */
22443 +
22444 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22445 +{
22446 +       struct inode *inode = dentry->d_inode;
22447 +       nid_t nid = PROC_I(inode)->fd;
22448 +
22449 +       if (!nid || nid_is_hashed(nid))
22450 +               return 1;
22451 +       d_drop(dentry);
22452 +       return 0;
22453 +}
22454 +
22455 +
22456 +
22457 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22458 +
22459 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22460 +                         size_t count, loff_t *ppos)
22461 +{
22462 +       struct inode *inode = file->f_dentry->d_inode;
22463 +       unsigned long page;
22464 +       ssize_t length = 0;
22465 +
22466 +       if (count > PROC_BLOCK_SIZE)
22467 +               count = PROC_BLOCK_SIZE;
22468 +
22469 +       /* fade that out as soon as stable */
22470 +       WARN_ON(PROC_I(inode)->fd);
22471 +
22472 +       if (!(page = __get_free_page(GFP_KERNEL)))
22473 +               return -ENOMEM;
22474 +
22475 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22476 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22477 +
22478 +       if (length >= 0)
22479 +               length = simple_read_from_buffer(buf, count, ppos,
22480 +                       (char *)page, length);
22481 +
22482 +       free_page(page);
22483 +       return length;
22484 +}
22485 +
22486 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22487 +                         size_t count, loff_t *ppos)
22488 +{
22489 +       struct inode *inode = file->f_dentry->d_inode;
22490 +       struct vx_info *vxi = NULL;
22491 +       xid_t xid = PROC_I(inode)->fd;
22492 +       unsigned long page;
22493 +       ssize_t length = 0;
22494 +
22495 +       if (count > PROC_BLOCK_SIZE)
22496 +               count = PROC_BLOCK_SIZE;
22497 +
22498 +       /* fade that out as soon as stable */
22499 +       WARN_ON(!xid);
22500 +       vxi = lookup_vx_info(xid);
22501 +       if (!vxi)
22502 +               goto out;
22503 +
22504 +       length = -ENOMEM;
22505 +       if (!(page = __get_free_page(GFP_KERNEL)))
22506 +               goto out_put;
22507 +
22508 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22509 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22510 +
22511 +       if (length >= 0)
22512 +               length = simple_read_from_buffer(buf, count, ppos,
22513 +                       (char *)page, length);
22514 +
22515 +       free_page(page);
22516 +out_put:
22517 +       put_vx_info(vxi);
22518 +out:
22519 +       return length;
22520 +}
22521 +
22522 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22523 +                         size_t count, loff_t *ppos)
22524 +{
22525 +       struct inode *inode = file->f_dentry->d_inode;
22526 +       struct nx_info *nxi = NULL;
22527 +       nid_t nid = PROC_I(inode)->fd;
22528 +       unsigned long page;
22529 +       ssize_t length = 0;
22530 +
22531 +       if (count > PROC_BLOCK_SIZE)
22532 +               count = PROC_BLOCK_SIZE;
22533 +
22534 +       /* fade that out as soon as stable */
22535 +       WARN_ON(!nid);
22536 +       nxi = lookup_nx_info(nid);
22537 +       if (!nxi)
22538 +               goto out;
22539 +
22540 +       length = -ENOMEM;
22541 +       if (!(page = __get_free_page(GFP_KERNEL)))
22542 +               goto out_put;
22543 +
22544 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22545 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22546 +
22547 +       if (length >= 0)
22548 +               length = simple_read_from_buffer(buf, count, ppos,
22549 +                       (char *)page, length);
22550 +
22551 +       free_page(page);
22552 +out_put:
22553 +       put_nx_info(nxi);
22554 +out:
22555 +       return length;
22556 +}
22557 +
22558 +
22559 +
22560 +/* here comes the lower level */
22561 +
22562 +
22563 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22564 +       .len  = sizeof(NAME) - 1,       \
22565 +       .name = (NAME),                 \
22566 +       .mode = MODE,                   \
22567 +       .iop  = IOP,                    \
22568 +       .fop  = FOP,                    \
22569 +       .op   = OP,                     \
22570 +}
22571 +
22572 +
22573 +#define DIR(NAME, MODE, OTYPE)                         \
22574 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22575 +               &proc_ ## OTYPE ## _inode_operations,   \
22576 +               &proc_ ## OTYPE ## _file_operations, { } )
22577 +
22578 +#define INF(NAME, MODE, OTYPE)                         \
22579 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22580 +               &proc_vs_info_file_operations,          \
22581 +               { .proc_vs_read = &proc_##OTYPE } )
22582 +
22583 +#define VINF(NAME, MODE, OTYPE)                                \
22584 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22585 +               &proc_vx_info_file_operations,          \
22586 +               { .proc_vxi_read = &proc_##OTYPE } )
22587 +
22588 +#define NINF(NAME, MODE, OTYPE)                                \
22589 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22590 +               &proc_nx_info_file_operations,          \
22591 +               { .proc_nxi_read = &proc_##OTYPE } )
22592 +
22593 +
22594 +static struct file_operations proc_vs_info_file_operations = {
22595 +       .read =         proc_vs_info_read,
22596 +};
22597 +
22598 +static struct file_operations proc_vx_info_file_operations = {
22599 +       .read =         proc_vx_info_read,
22600 +};
22601 +
22602 +static struct dentry_operations proc_xid_dentry_operations = {
22603 +       .d_revalidate = proc_xid_revalidate,
22604 +};
22605 +
22606 +static struct vs_entry vx_base_stuff[] = {
22607 +       VINF("info",    S_IRUGO, vxi_info),
22608 +       VINF("status",  S_IRUGO, vxi_status),
22609 +       VINF("limit",   S_IRUGO, vxi_limit),
22610 +       VINF("sched",   S_IRUGO, vxi_sched),
22611 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
22612 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22613 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22614 +       {}
22615 +};
22616 +
22617 +
22618 +
22619 +
22620 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22621 +       struct dentry *dentry, int id, void *ptr)
22622 +{
22623 +       dentry->d_op = &proc_xid_dentry_operations;
22624 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22625 +}
22626 +
22627 +static struct dentry *proc_xid_lookup(struct inode *dir,
22628 +       struct dentry *dentry, struct nameidata *nd)
22629 +{
22630 +       struct vs_entry *p = vx_base_stuff;
22631 +       struct dentry *error = ERR_PTR(-ENOENT);
22632 +
22633 +       for (; p->name; p++) {
22634 +               if (p->len != dentry->d_name.len)
22635 +                       continue;
22636 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22637 +                       break;
22638 +       }
22639 +       if (!p->name)
22640 +               goto out;
22641 +
22642 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22643 +out:
22644 +       return error;
22645 +}
22646 +
22647 +static int proc_xid_readdir(struct file *filp,
22648 +       void *dirent, filldir_t filldir)
22649 +{
22650 +       struct dentry *dentry = filp->f_dentry;
22651 +       struct inode *inode = dentry->d_inode;
22652 +       struct vs_entry *p = vx_base_stuff;
22653 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22654 +       int pos, index;
22655 +       u64 ino;
22656 +
22657 +       pos = filp->f_pos;
22658 +       switch (pos) {
22659 +       case 0:
22660 +               ino = inode->i_ino;
22661 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22662 +                       goto out;
22663 +               pos++;
22664 +               /* fall through */
22665 +       case 1:
22666 +               ino = parent_ino(dentry);
22667 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22668 +                       goto out;
22669 +               pos++;
22670 +               /* fall through */
22671 +       default:
22672 +               index = pos - 2;
22673 +               if (index >= size)
22674 +                       goto out;
22675 +               for (p += index; p->name; p++) {
22676 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22677 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22678 +                               goto out;
22679 +                       pos++;
22680 +               }
22681 +       }
22682 +out:
22683 +       filp->f_pos = pos;
22684 +       return 1;
22685 +}
22686 +
22687 +
22688 +
22689 +static struct file_operations proc_nx_info_file_operations = {
22690 +       .read =         proc_nx_info_read,
22691 +};
22692 +
22693 +static struct dentry_operations proc_nid_dentry_operations = {
22694 +       .d_revalidate = proc_nid_revalidate,
22695 +};
22696 +
22697 +static struct vs_entry nx_base_stuff[] = {
22698 +       NINF("info",    S_IRUGO, nxi_info),
22699 +       NINF("status",  S_IRUGO, nxi_status),
22700 +       {}
22701 +};
22702 +
22703 +
22704 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22705 +       struct dentry *dentry, int id, void *ptr)
22706 +{
22707 +       dentry->d_op = &proc_nid_dentry_operations;
22708 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22709 +}
22710 +
22711 +static struct dentry *proc_nid_lookup(struct inode *dir,
22712 +       struct dentry *dentry, struct nameidata *nd)
22713 +{
22714 +       struct vs_entry *p = nx_base_stuff;
22715 +       struct dentry *error = ERR_PTR(-ENOENT);
22716 +
22717 +       for (; p->name; p++) {
22718 +               if (p->len != dentry->d_name.len)
22719 +                       continue;
22720 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22721 +                       break;
22722 +       }
22723 +       if (!p->name)
22724 +               goto out;
22725 +
22726 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22727 +out:
22728 +       return error;
22729 +}
22730 +
22731 +static int proc_nid_readdir(struct file *filp,
22732 +       void *dirent, filldir_t filldir)
22733 +{
22734 +       struct dentry *dentry = filp->f_dentry;
22735 +       struct inode *inode = dentry->d_inode;
22736 +       struct vs_entry *p = nx_base_stuff;
22737 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22738 +       int pos, index;
22739 +       u64 ino;
22740 +
22741 +       pos = filp->f_pos;
22742 +       switch (pos) {
22743 +       case 0:
22744 +               ino = inode->i_ino;
22745 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22746 +                       goto out;
22747 +               pos++;
22748 +               /* fall through */
22749 +       case 1:
22750 +               ino = parent_ino(dentry);
22751 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22752 +                       goto out;
22753 +               pos++;
22754 +               /* fall through */
22755 +       default:
22756 +               index = pos - 2;
22757 +               if (index >= size)
22758 +                       goto out;
22759 +               for (p += index; p->name; p++) {
22760 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22761 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22762 +                               goto out;
22763 +                       pos++;
22764 +               }
22765 +       }
22766 +out:
22767 +       filp->f_pos = pos;
22768 +       return 1;
22769 +}
22770 +
22771 +
22772 +#define MAX_MULBY10    ((~0U - 9) / 10)
22773 +
22774 +static inline int atovid(const char *str, int len)
22775 +{
22776 +       int vid, c;
22777 +
22778 +       vid = 0;
22779 +       while (len-- > 0) {
22780 +               c = *str - '0';
22781 +               str++;
22782 +               if (c > 9)
22783 +                       return -1;
22784 +               if (vid >= MAX_MULBY10)
22785 +                       return -1;
22786 +               vid *= 10;
22787 +               vid += c;
22788 +               if (!vid)
22789 +                       return -1;
22790 +       }
22791 +       return vid;
22792 +}
22793 +
22794 +/* now the upper level (virtual) */
22795 +
22796 +
22797 +static struct file_operations proc_xid_file_operations = {
22798 +       .read =         generic_read_dir,
22799 +       .readdir =      proc_xid_readdir,
22800 +};
22801 +
22802 +static struct inode_operations proc_xid_inode_operations = {
22803 +       .lookup =       proc_xid_lookup,
22804 +};
22805 +
22806 +static struct vs_entry vx_virtual_stuff[] = {
22807 +       INF("info",     S_IRUGO, virtual_info),
22808 +       INF("status",   S_IRUGO, virtual_status),
22809 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22810 +};
22811 +
22812 +
22813 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22814 +       struct dentry *dentry, struct nameidata *nd)
22815 +{
22816 +       struct vs_entry *p = vx_virtual_stuff;
22817 +       struct dentry *error = ERR_PTR(-ENOENT);
22818 +       int id = 0;
22819 +
22820 +       for (; p->name; p++) {
22821 +               if (p->len != dentry->d_name.len)
22822 +                       continue;
22823 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22824 +                       break;
22825 +       }
22826 +       if (p->name)
22827 +               goto instantiate;
22828 +
22829 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22830 +       if ((id < 0) || !xid_is_hashed(id))
22831 +               goto out;
22832 +
22833 +instantiate:
22834 +       error = proc_xid_instantiate(dir, dentry, id, p);
22835 +out:
22836 +       return error;
22837 +}
22838 +
22839 +static struct file_operations proc_nid_file_operations = {
22840 +       .read =         generic_read_dir,
22841 +       .readdir =      proc_nid_readdir,
22842 +};
22843 +
22844 +static struct inode_operations proc_nid_inode_operations = {
22845 +       .lookup =       proc_nid_lookup,
22846 +};
22847 +
22848 +static struct vs_entry nx_virtnet_stuff[] = {
22849 +       INF("info",     S_IRUGO, virtnet_info),
22850 +       INF("status",   S_IRUGO, virtnet_status),
22851 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22852 +};
22853 +
22854 +
22855 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22856 +       struct dentry *dentry, struct nameidata *nd)
22857 +{
22858 +       struct vs_entry *p = nx_virtnet_stuff;
22859 +       struct dentry *error = ERR_PTR(-ENOENT);
22860 +       int id = 0;
22861 +
22862 +       for (; p->name; p++) {
22863 +               if (p->len != dentry->d_name.len)
22864 +                       continue;
22865 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22866 +                       break;
22867 +       }
22868 +       if (p->name)
22869 +               goto instantiate;
22870 +
22871 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22872 +       if ((id < 0) || !nid_is_hashed(id))
22873 +               goto out;
22874 +
22875 +instantiate:
22876 +       error = proc_nid_instantiate(dir, dentry, id, p);
22877 +out:
22878 +       return error;
22879 +}
22880 +
22881 +
22882 +#define PROC_MAXVIDS 32
22883 +
22884 +int proc_virtual_readdir(struct file *filp,
22885 +       void *dirent, filldir_t filldir)
22886 +{
22887 +       struct dentry *dentry = filp->f_dentry;
22888 +       struct inode *inode = dentry->d_inode;
22889 +       struct vs_entry *p = vx_virtual_stuff;
22890 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22891 +       int pos, index;
22892 +       unsigned int xid_array[PROC_MAXVIDS];
22893 +       char buf[PROC_NUMBUF];
22894 +       unsigned int nr_xids, i;
22895 +       u64 ino;
22896 +
22897 +       pos = filp->f_pos;
22898 +       switch (pos) {
22899 +       case 0:
22900 +               ino = inode->i_ino;
22901 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22902 +                       goto out;
22903 +               pos++;
22904 +               /* fall through */
22905 +       case 1:
22906 +               ino = parent_ino(dentry);
22907 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22908 +                       goto out;
22909 +               pos++;
22910 +               /* fall through */
22911 +       default:
22912 +               index = pos - 2;
22913 +               if (index >= size)
22914 +                       goto entries;
22915 +               for (p += index; p->name; p++) {
22916 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22917 +                               vs_proc_instantiate, 0, p))
22918 +                               goto out;
22919 +                       pos++;
22920 +               }
22921 +       entries:
22922 +               index = pos - size;
22923 +               p = &vx_virtual_stuff[size - 1];
22924 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22925 +               for (i = 0; i < nr_xids; i++) {
22926 +                       int n, xid = xid_array[i];
22927 +                       unsigned int j = PROC_NUMBUF;
22928 +
22929 +                       n = xid;
22930 +                       do
22931 +                               buf[--j] = '0' + (n % 10);
22932 +                       while (n /= 10);
22933 +
22934 +                       if (proc_fill_cache(filp, dirent, filldir,
22935 +                               buf + j, PROC_NUMBUF - j,
22936 +                               vs_proc_instantiate, xid, p))
22937 +                               goto out;
22938 +                       pos++;
22939 +               }
22940 +       }
22941 +out:
22942 +       filp->f_pos = pos;
22943 +       return 0;
22944 +}
22945 +
22946 +static int proc_virtual_getattr(struct vfsmount *mnt,
22947 +       struct dentry *dentry, struct kstat *stat)
22948 +{
22949 +       struct inode *inode = dentry->d_inode;
22950 +
22951 +       generic_fillattr(inode, stat);
22952 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22953 +       return 0;
22954 +}
22955 +
22956 +static struct file_operations proc_virtual_dir_operations = {
22957 +       .read =         generic_read_dir,
22958 +       .readdir =      proc_virtual_readdir,
22959 +};
22960 +
22961 +static struct inode_operations proc_virtual_dir_inode_operations = {
22962 +       .getattr =      proc_virtual_getattr,
22963 +       .lookup =       proc_virtual_lookup,
22964 +};
22965 +
22966 +
22967 +
22968 +
22969 +
22970 +int proc_virtnet_readdir(struct file *filp,
22971 +       void *dirent, filldir_t filldir)
22972 +{
22973 +       struct dentry *dentry = filp->f_dentry;
22974 +       struct inode *inode = dentry->d_inode;
22975 +       struct vs_entry *p = nx_virtnet_stuff;
22976 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22977 +       int pos, index;
22978 +       unsigned int nid_array[PROC_MAXVIDS];
22979 +       char buf[PROC_NUMBUF];
22980 +       unsigned int nr_nids, i;
22981 +       u64 ino;
22982 +
22983 +       pos = filp->f_pos;
22984 +       switch (pos) {
22985 +       case 0:
22986 +               ino = inode->i_ino;
22987 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22988 +                       goto out;
22989 +               pos++;
22990 +               /* fall through */
22991 +       case 1:
22992 +               ino = parent_ino(dentry);
22993 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22994 +                       goto out;
22995 +               pos++;
22996 +               /* fall through */
22997 +       default:
22998 +               index = pos - 2;
22999 +               if (index >= size)
23000 +                       goto entries;
23001 +               for (p += index; p->name; p++) {
23002 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23003 +                               vs_proc_instantiate, 0, p))
23004 +                               goto out;
23005 +                       pos++;
23006 +               }
23007 +       entries:
23008 +               index = pos - size;
23009 +               p = &nx_virtnet_stuff[size - 1];
23010 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23011 +               for (i = 0; i < nr_nids; i++) {
23012 +                       int n, nid = nid_array[i];
23013 +                       unsigned int j = PROC_NUMBUF;
23014 +
23015 +                       n = nid;
23016 +                       do
23017 +                               buf[--j] = '0' + (n % 10);
23018 +                       while (n /= 10);
23019 +
23020 +                       if (proc_fill_cache(filp, dirent, filldir,
23021 +                               buf + j, PROC_NUMBUF - j,
23022 +                               vs_proc_instantiate, nid, p))
23023 +                               goto out;
23024 +                       pos++;
23025 +               }
23026 +       }
23027 +out:
23028 +       filp->f_pos = pos;
23029 +       return 0;
23030 +}
23031 +
23032 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23033 +       struct dentry *dentry, struct kstat *stat)
23034 +{
23035 +       struct inode *inode = dentry->d_inode;
23036 +
23037 +       generic_fillattr(inode, stat);
23038 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23039 +       return 0;
23040 +}
23041 +
23042 +static struct file_operations proc_virtnet_dir_operations = {
23043 +       .read =         generic_read_dir,
23044 +       .readdir =      proc_virtnet_readdir,
23045 +};
23046 +
23047 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23048 +       .getattr =      proc_virtnet_getattr,
23049 +       .lookup =       proc_virtnet_lookup,
23050 +};
23051 +
23052 +
23053 +
23054 +void proc_vx_init(void)
23055 +{
23056 +       struct proc_dir_entry *ent;
23057 +
23058 +       ent = proc_mkdir("virtual", 0);
23059 +       if (ent) {
23060 +               ent->proc_fops = &proc_virtual_dir_operations;
23061 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23062 +       }
23063 +       proc_virtual = ent;
23064 +
23065 +       ent = proc_mkdir("virtnet", 0);
23066 +       if (ent) {
23067 +               ent->proc_fops = &proc_virtnet_dir_operations;
23068 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23069 +       }
23070 +       proc_virtnet = ent;
23071 +}
23072 +
23073 +
23074 +
23075 +
23076 +/* per pid info */
23077 +
23078 +
23079 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23080 +{
23081 +       struct vx_info *vxi;
23082 +       char *orig = buffer;
23083 +
23084 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23085 +
23086 +       vxi = task_get_vx_info(p);
23087 +       if (!vxi)
23088 +               goto out;
23089 +
23090 +       buffer += sprintf(buffer, "BCaps:\t");
23091 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23092 +       buffer += sprintf(buffer, "\n");
23093 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23094 +               (unsigned long long)vxi->vx_ccaps);
23095 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23096 +               (unsigned long long)vxi->vx_flags);
23097 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23098 +
23099 +       put_vx_info(vxi);
23100 +out:
23101 +       return buffer - orig;
23102 +}
23103 +
23104 +
23105 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23106 +{
23107 +       struct nx_info *nxi;
23108 +       struct nx_addr_v4 *v4a;
23109 +#ifdef CONFIG_IPV6
23110 +       struct nx_addr_v6 *v6a;
23111 +#endif
23112 +       char *orig = buffer;
23113 +       int i;
23114 +
23115 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23116 +
23117 +       nxi = task_get_nx_info(p);
23118 +       if (!nxi)
23119 +               goto out;
23120 +
23121 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23122 +               (unsigned long long)nxi->nx_ncaps);
23123 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23124 +               (unsigned long long)nxi->nx_flags);
23125 +
23126 +       buffer += sprintf(buffer,
23127 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23128 +               NIPQUAD(nxi->v4_bcast.s_addr));
23129 +       buffer += sprintf (buffer,
23130 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23131 +               NIPQUAD(nxi->v4_lback.s_addr));
23132 +       if (!NX_IPV4(nxi))
23133 +               goto skip_v4;
23134 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23135 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23136 +                       i, NXAV4(v4a));
23137 +skip_v4:
23138 +#ifdef CONFIG_IPV6
23139 +       if (!NX_IPV6(nxi))
23140 +               goto skip_v6;
23141 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23142 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23143 +                       i, NXAV6(v6a));
23144 +skip_v6:
23145 +#endif
23146 +       put_nx_info(nxi);
23147 +out:
23148 +       return buffer - orig;
23149 +}
23150 +
23151 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/sched.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sched.c
23152 --- linux-2.6.27.3/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
23153 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sched.c  2008-10-13 14:54:20.000000000 +0200
23154 @@ -0,0 +1,413 @@
23155 +/*
23156 + *  linux/kernel/vserver/sched.c
23157 + *
23158 + *  Virtual Server: Scheduler Support
23159 + *
23160 + *  Copyright (C) 2004-2007  Herbert Pötzl
23161 + *
23162 + *  V0.01  adapted Sam Vilains version to 2.6.3
23163 + *  V0.02  removed legacy interface
23164 + *  V0.03  changed vcmds to vxi arg
23165 + *  V0.04  removed older and legacy interfaces
23166 + *
23167 + */
23168 +
23169 +#include <linux/vs_context.h>
23170 +#include <linux/vs_sched.h>
23171 +#include <linux/vserver/sched_cmd.h>
23172 +
23173 +#include <asm/uaccess.h>
23174 +
23175 +
23176 +#define vxd_check_range(val, min, max) do {            \
23177 +       vxlprintk((val < min) || (val > max),           \
23178 +               "check_range(%ld,%ld,%ld)",             \
23179 +               (long)val, (long)min, (long)max,        \
23180 +               __FILE__, __LINE__);                    \
23181 +       } while (0)
23182 +
23183 +
23184 +void vx_update_sched_param(struct _vx_sched *sched,
23185 +       struct _vx_sched_pc *sched_pc)
23186 +{
23187 +       unsigned int set_mask = sched->update_mask;
23188 +
23189 +       if (set_mask & VXSM_FILL_RATE)
23190 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23191 +       if (set_mask & VXSM_INTERVAL)
23192 +               sched_pc->interval[0] = sched->interval[0];
23193 +       if (set_mask & VXSM_FILL_RATE2)
23194 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23195 +       if (set_mask & VXSM_INTERVAL2)
23196 +               sched_pc->interval[1] = sched->interval[1];
23197 +       if (set_mask & VXSM_TOKENS)
23198 +               sched_pc->tokens = sched->tokens;
23199 +       if (set_mask & VXSM_TOKENS_MIN)
23200 +               sched_pc->tokens_min = sched->tokens_min;
23201 +       if (set_mask & VXSM_TOKENS_MAX)
23202 +               sched_pc->tokens_max = sched->tokens_max;
23203 +       if (set_mask & VXSM_PRIO_BIAS)
23204 +               sched_pc->prio_bias = sched->prio_bias;
23205 +
23206 +       if (set_mask & VXSM_IDLE_TIME)
23207 +               sched_pc->flags |= VXSF_IDLE_TIME;
23208 +       else
23209 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23210 +
23211 +       /* reset time */
23212 +       sched_pc->norm_time = jiffies;
23213 +}
23214 +
23215 +
23216 +/*
23217 + * recalculate the context's scheduling tokens
23218 + *
23219 + * ret > 0 : number of tokens available
23220 + * ret < 0 : on hold, check delta_min[]
23221 + *          -1 only jiffies
23222 + *          -2 also idle time
23223 + *
23224 + */
23225 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23226 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23227 +{
23228 +       long delta;
23229 +       long tokens = 0;
23230 +       int flags = sched_pc->flags;
23231 +
23232 +       /* how much time did pass? */
23233 +       delta = *norm_time - sched_pc->norm_time;
23234 +       vxd_check_range(delta, 0, INT_MAX);
23235 +
23236 +       if (delta >= sched_pc->interval[0]) {
23237 +               long tokens, integral;
23238 +
23239 +               /* calc integral token part */
23240 +               tokens = delta / sched_pc->interval[0];
23241 +               integral = tokens * sched_pc->interval[0];
23242 +               tokens *= sched_pc->fill_rate[0];
23243 +#ifdef CONFIG_VSERVER_HARDCPU
23244 +               delta_min[0] = delta - integral;
23245 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23246 +#endif
23247 +               /* advance time */
23248 +               sched_pc->norm_time += delta;
23249 +
23250 +               /* add tokens */
23251 +               sched_pc->tokens += tokens;
23252 +               sched_pc->token_time += tokens;
23253 +       } else
23254 +               delta_min[0] = delta;
23255 +
23256 +#ifdef CONFIG_VSERVER_IDLETIME
23257 +       if (!(flags & VXSF_IDLE_TIME))
23258 +               goto skip_idle;
23259 +
23260 +       /* how much was the idle skip? */
23261 +       delta = *idle_time - sched_pc->idle_time;
23262 +       vxd_check_range(delta, 0, INT_MAX);
23263 +
23264 +       if (delta >= sched_pc->interval[1]) {
23265 +               long tokens, integral;
23266 +
23267 +               /* calc fair share token part */
23268 +               tokens = delta / sched_pc->interval[1];
23269 +               integral = tokens * sched_pc->interval[1];
23270 +               tokens *= sched_pc->fill_rate[1];
23271 +               delta_min[1] = delta - integral;
23272 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23273 +
23274 +               /* advance idle time */
23275 +               sched_pc->idle_time += integral;
23276 +
23277 +               /* add tokens */
23278 +               sched_pc->tokens += tokens;
23279 +               sched_pc->token_time += tokens;
23280 +       } else
23281 +               delta_min[1] = delta;
23282 +skip_idle:
23283 +#endif
23284 +
23285 +       /* clip at maximum */
23286 +       if (sched_pc->tokens > sched_pc->tokens_max)
23287 +               sched_pc->tokens = sched_pc->tokens_max;
23288 +       tokens = sched_pc->tokens;
23289 +
23290 +       if ((flags & VXSF_ONHOLD)) {
23291 +               /* can we unhold? */
23292 +               if (tokens >= sched_pc->tokens_min) {
23293 +                       flags &= ~VXSF_ONHOLD;
23294 +                       sched_pc->hold_ticks +=
23295 +                               *norm_time - sched_pc->onhold;
23296 +               } else
23297 +                       goto on_hold;
23298 +       } else {
23299 +               /* put on hold? */
23300 +               if (tokens <= 0) {
23301 +                       flags |= VXSF_ONHOLD;
23302 +                       sched_pc->onhold = *norm_time;
23303 +                       goto on_hold;
23304 +               }
23305 +       }
23306 +       sched_pc->flags = flags;
23307 +       return tokens;
23308 +
23309 +on_hold:
23310 +       tokens = sched_pc->tokens_min - tokens;
23311 +       sched_pc->flags = flags;
23312 +       BUG_ON(tokens < 0);
23313 +
23314 +#ifdef CONFIG_VSERVER_HARDCPU
23315 +       /* next interval? */
23316 +       if (!sched_pc->fill_rate[0])
23317 +               delta_min[0] = HZ;
23318 +       else if (tokens > sched_pc->fill_rate[0])
23319 +               delta_min[0] += sched_pc->interval[0] *
23320 +                       tokens / sched_pc->fill_rate[0];
23321 +       else
23322 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23323 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23324 +
23325 +#ifdef CONFIG_VSERVER_IDLETIME
23326 +       if (!(flags & VXSF_IDLE_TIME))
23327 +               return -1;
23328 +
23329 +       /* next interval? */
23330 +       if (!sched_pc->fill_rate[1])
23331 +               delta_min[1] = HZ;
23332 +       else if (tokens > sched_pc->fill_rate[1])
23333 +               delta_min[1] += sched_pc->interval[1] *
23334 +                       tokens / sched_pc->fill_rate[1];
23335 +       else
23336 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23337 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23338 +
23339 +       return -2;
23340 +#else
23341 +       return -1;
23342 +#endif /* CONFIG_VSERVER_IDLETIME */
23343 +#else
23344 +       return 0;
23345 +#endif /* CONFIG_VSERVER_HARDCPU */
23346 +}
23347 +
23348 +static inline unsigned long msec_to_ticks(unsigned long msec)
23349 +{
23350 +       return msecs_to_jiffies(msec);
23351 +}
23352 +
23353 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23354 +{
23355 +       return jiffies_to_msecs(ticks);
23356 +}
23357 +
23358 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23359 +{
23360 +       return jiffies_to_usecs(ticks);
23361 +}
23362 +
23363 +
23364 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23365 +{
23366 +       unsigned int set_mask = data->mask;
23367 +       unsigned int update_mask;
23368 +       int i, cpu;
23369 +
23370 +       /* Sanity check data values */
23371 +       if (data->tokens_max <= 0)
23372 +               data->tokens_max = HZ;
23373 +       if (data->tokens_min < 0)
23374 +               data->tokens_min = HZ / 3;
23375 +       if (data->tokens_min >= data->tokens_max)
23376 +               data->tokens_min = data->tokens_max;
23377 +
23378 +       if (data->prio_bias > MAX_PRIO_BIAS)
23379 +               data->prio_bias = MAX_PRIO_BIAS;
23380 +       if (data->prio_bias < MIN_PRIO_BIAS)
23381 +               data->prio_bias = MIN_PRIO_BIAS;
23382 +
23383 +       spin_lock(&vxi->sched.tokens_lock);
23384 +
23385 +       /* sync up on delayed updates */
23386 +       for_each_cpu_mask(cpu, vxi->sched.update)
23387 +               vx_update_sched_param(&vxi->sched,
23388 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23389 +
23390 +       if (set_mask & VXSM_FILL_RATE)
23391 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23392 +       if (set_mask & VXSM_FILL_RATE2)
23393 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23394 +       if (set_mask & VXSM_INTERVAL)
23395 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23396 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23397 +       if (set_mask & VXSM_INTERVAL2)
23398 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23399 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23400 +       if (set_mask & VXSM_TOKENS)
23401 +               vxi->sched.tokens = data->tokens;
23402 +       if (set_mask & VXSM_TOKENS_MIN)
23403 +               vxi->sched.tokens_min = data->tokens_min;
23404 +       if (set_mask & VXSM_TOKENS_MAX)
23405 +               vxi->sched.tokens_max = data->tokens_max;
23406 +       if (set_mask & VXSM_PRIO_BIAS)
23407 +               vxi->sched.prio_bias = data->prio_bias;
23408 +
23409 +       /* Sanity check rate/interval */
23410 +       for (i = 0; i < 2; i++) {
23411 +               if (data->fill_rate[i] < 0)
23412 +                       data->fill_rate[i] = 0;
23413 +               if (data->interval[i] <= 0)
23414 +                       data->interval[i] = HZ;
23415 +       }
23416 +
23417 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23418 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23419 +       vxi->sched.update_mask = update_mask;
23420 +
23421 +#ifdef CONFIG_SMP
23422 +       rmb();
23423 +       if (set_mask & VXSM_CPU_ID) {
23424 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23425 +               cpus_and(vxi->sched.update, cpu_online_map,
23426 +                       vxi->sched.update);
23427 +       } else
23428 +               vxi->sched.update = cpu_online_map;
23429 +
23430 +       /* forced reload? */
23431 +       if (set_mask & VXSM_FORCE) {
23432 +               for_each_cpu_mask(cpu, vxi->sched.update)
23433 +                       vx_update_sched_param(&vxi->sched,
23434 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23435 +               vxi->sched.update = CPU_MASK_NONE;
23436 +       }
23437 +#else
23438 +       /* on UP we update immediately */
23439 +       vx_update_sched_param(&vxi->sched,
23440 +               &vx_per_cpu(vxi, sched_pc, 0));
23441 +#endif
23442 +
23443 +       spin_unlock(&vxi->sched.tokens_lock);
23444 +       return 0;
23445 +}
23446 +
23447 +
23448 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23449 +#define COPY_PRI(C) C(prio_bias)
23450 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23451 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23452 +                   C(fill_rate[1]); C(interval[1]);
23453 +
23454 +#define COPY_VALUE(name) vc_data.name = data->name
23455 +
23456 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23457 +{
23458 +       struct vcmd_sched_v5 vc_data;
23459 +
23460 +       vc_data.mask = data->set_mask;
23461 +       COPY_IDS(COPY_VALUE);
23462 +       COPY_PRI(COPY_VALUE);
23463 +       COPY_TOK(COPY_VALUE);
23464 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23465 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23466 +       return do_set_sched(vxi, &vc_data);
23467 +}
23468 +
23469 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23470 +{
23471 +       struct vcmd_set_sched_v4 vc_data;
23472 +
23473 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23474 +               return -EFAULT;
23475 +
23476 +       return do_set_sched_v4(vxi, &vc_data);
23477 +}
23478 +
23479 +       /* latest interface is v5 */
23480 +
23481 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23482 +{
23483 +       struct vcmd_sched_v5 vc_data;
23484 +
23485 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23486 +               return -EFAULT;
23487 +
23488 +       return do_set_sched(vxi, &vc_data);
23489 +}
23490 +
23491 +
23492 +#define COPY_PRI(C) C(prio_bias)
23493 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23494 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23495 +                   C(fill_rate[1]); C(interval[1]);
23496 +
23497 +#define COPY_VALUE(name) vc_data.name = data->name
23498 +
23499 +
23500 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23501 +{
23502 +       struct vcmd_sched_v5 vc_data;
23503 +
23504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23505 +               return -EFAULT;
23506 +
23507 +       if (vc_data.mask & VXSM_CPU_ID) {
23508 +               int cpu = vc_data.cpu_id;
23509 +               struct _vx_sched_pc *data;
23510 +
23511 +               if (!cpu_possible(cpu))
23512 +                       return -EINVAL;
23513 +
23514 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23515 +               COPY_TOK(COPY_VALUE);
23516 +               COPY_PRI(COPY_VALUE);
23517 +               COPY_FRI(COPY_VALUE);
23518 +
23519 +               if (data->flags & VXSF_IDLE_TIME)
23520 +                       vc_data.mask |= VXSM_IDLE_TIME;
23521 +       } else {
23522 +               struct _vx_sched *data = &vxi->sched;
23523 +
23524 +               COPY_TOK(COPY_VALUE);
23525 +               COPY_PRI(COPY_VALUE);
23526 +               COPY_FRI(COPY_VALUE);
23527 +       }
23528 +
23529 +       if (vc_data.mask & VXSM_MSEC) {
23530 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23531 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23532 +       }
23533 +
23534 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23535 +               return -EFAULT;
23536 +       return 0;
23537 +}
23538 +
23539 +
23540 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23541 +{
23542 +       struct vcmd_sched_info vc_data;
23543 +       int cpu;
23544 +
23545 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23546 +               return -EFAULT;
23547 +
23548 +       cpu = vc_data.cpu_id;
23549 +       if (!cpu_possible(cpu))
23550 +               return -EINVAL;
23551 +
23552 +       if (vxi) {
23553 +               struct _vx_sched_pc *sched_pc =
23554 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23555 +
23556 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23557 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23558 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23559 +               vc_data.vavavoom = sched_pc->vavavoom;
23560 +       }
23561 +       vc_data.token_usec = ticks_to_usec(1);
23562 +
23563 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23564 +               return -EFAULT;
23565 +       return 0;
23566 +}
23567 +
23568 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/sched_init.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sched_init.h
23569 --- linux-2.6.27.3/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
23570 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sched_init.h     2008-10-13 14:54:20.000000000 +0200
23571 @@ -0,0 +1,50 @@
23572 +
23573 +static inline void vx_info_init_sched(struct _vx_sched *sched)
23574 +{
23575 +       static struct lock_class_key tokens_lock_key;
23576 +
23577 +       /* scheduling; hard code starting values as constants */
23578 +       sched->fill_rate[0]     = 1;
23579 +       sched->interval[0]      = 4;
23580 +       sched->fill_rate[1]     = 1;
23581 +       sched->interval[1]      = 8;
23582 +       sched->tokens           = HZ >> 2;
23583 +       sched->tokens_min       = HZ >> 4;
23584 +       sched->tokens_max       = HZ >> 1;
23585 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
23586 +       sched->prio_bias        = 0;
23587 +
23588 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
23589 +}
23590 +
23591 +static inline
23592 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23593 +{
23594 +       sched_pc->fill_rate[0]  = 1;
23595 +       sched_pc->interval[0]   = 4;
23596 +       sched_pc->fill_rate[1]  = 1;
23597 +       sched_pc->interval[1]   = 8;
23598 +       sched_pc->tokens        = HZ >> 2;
23599 +       sched_pc->tokens_min    = HZ >> 4;
23600 +       sched_pc->tokens_max    = HZ >> 1;
23601 +       sched_pc->prio_bias     = 0;
23602 +       sched_pc->vavavoom      = 0;
23603 +       sched_pc->token_time    = 0;
23604 +       sched_pc->idle_time     = 0;
23605 +       sched_pc->norm_time     = jiffies;
23606 +
23607 +       sched_pc->user_ticks = 0;
23608 +       sched_pc->sys_ticks = 0;
23609 +       sched_pc->hold_ticks = 0;
23610 +}
23611 +
23612 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
23613 +{
23614 +       return;
23615 +}
23616 +
23617 +static inline
23618 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23619 +{
23620 +       return;
23621 +}
23622 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/sched_proc.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sched_proc.h
23623 --- linux-2.6.27.3/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
23624 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sched_proc.h     2008-10-13 14:54:20.000000000 +0200
23625 @@ -0,0 +1,57 @@
23626 +#ifndef _VX_SCHED_PROC_H
23627 +#define _VX_SCHED_PROC_H
23628 +
23629 +
23630 +static inline
23631 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
23632 +{
23633 +       int length = 0;
23634 +
23635 +       length += sprintf(buffer,
23636 +               "FillRate:\t%8d,%d\n"
23637 +               "Interval:\t%8d,%d\n"
23638 +               "TokensMin:\t%8d\n"
23639 +               "TokensMax:\t%8d\n"
23640 +               "PrioBias:\t%8d\n",
23641 +               sched->fill_rate[0],
23642 +               sched->fill_rate[1],
23643 +               sched->interval[0],
23644 +               sched->interval[1],
23645 +               sched->tokens_min,
23646 +               sched->tokens_max,
23647 +               sched->prio_bias);
23648 +       return length;
23649 +}
23650 +
23651 +static inline
23652 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
23653 +       char *buffer, int cpu)
23654 +{
23655 +       int length = 0;
23656 +
23657 +       length += sprintf(buffer + length,
23658 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
23659 +               (unsigned long long)sched_pc->user_ticks,
23660 +               (unsigned long long)sched_pc->sys_ticks,
23661 +               (unsigned long long)sched_pc->hold_ticks,
23662 +               sched_pc->token_time,
23663 +               sched_pc->idle_time);
23664 +       length += sprintf(buffer + length,
23665 +               " %c%c %d %d %d %d/%d %d/%d",
23666 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
23667 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
23668 +               sched_pc->tokens,
23669 +               sched_pc->tokens_min,
23670 +               sched_pc->tokens_max,
23671 +               sched_pc->fill_rate[0],
23672 +               sched_pc->interval[0],
23673 +               sched_pc->fill_rate[1],
23674 +               sched_pc->interval[1]);
23675 +       length += sprintf(buffer + length,
23676 +               " %d %d\n",
23677 +               sched_pc->prio_bias,
23678 +               sched_pc->vavavoom);
23679 +       return length;
23680 +}
23681 +
23682 +#endif /* _VX_SCHED_PROC_H */
23683 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/signal.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/signal.c
23684 --- linux-2.6.27.3/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
23685 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/signal.c 2008-10-13 14:54:20.000000000 +0200
23686 @@ -0,0 +1,132 @@
23687 +/*
23688 + *  linux/kernel/vserver/signal.c
23689 + *
23690 + *  Virtual Server: Signal Support
23691 + *
23692 + *  Copyright (C) 2003-2007  Herbert Pötzl
23693 + *
23694 + *  V0.01  broken out from vcontext V0.05
23695 + *  V0.02  changed vcmds to vxi arg
23696 + *  V0.03  adjusted siginfo for kill
23697 + *
23698 + */
23699 +
23700 +#include <asm/uaccess.h>
23701 +
23702 +#include <linux/vs_context.h>
23703 +#include <linux/vs_pid.h>
23704 +#include <linux/vserver/signal_cmd.h>
23705 +
23706 +
23707 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
23708 +{
23709 +       int retval, count = 0;
23710 +       struct task_struct *p;
23711 +       struct siginfo *sip = SEND_SIG_PRIV;
23712 +
23713 +       retval = -ESRCH;
23714 +       vxdprintk(VXD_CBIT(misc, 4),
23715 +               "vx_info_kill(%p[#%d],%d,%d)*",
23716 +               vxi, vxi->vx_id, pid, sig);
23717 +       read_lock(&tasklist_lock);
23718 +       switch (pid) {
23719 +       case  0:
23720 +       case -1:
23721 +               for_each_process(p) {
23722 +                       int err = 0;
23723 +
23724 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
23725 +                               (pid && vxi->vx_initpid == p->pid))
23726 +                               continue;
23727 +
23728 +                       err = group_send_sig_info(sig, sip, p);
23729 +                       ++count;
23730 +                       if (err != -EPERM)
23731 +                               retval = err;
23732 +               }
23733 +               break;
23734 +
23735 +       case 1:
23736 +               if (vxi->vx_initpid) {
23737 +                       pid = vxi->vx_initpid;
23738 +                       /* for now, only SIGINT to private init ... */
23739 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23740 +                               /* ... as long as there are tasks left */
23741 +                               (atomic_read(&vxi->vx_tasks) > 1))
23742 +                               sig = SIGINT;
23743 +               }
23744 +               /* fallthrough */
23745 +       default:
23746 +               p = find_task_by_real_pid(pid);
23747 +               if (p) {
23748 +                       if (vx_task_xid(p) == vxi->vx_id)
23749 +                               retval = group_send_sig_info(sig, sip, p);
23750 +               }
23751 +               break;
23752 +       }
23753 +       read_unlock(&tasklist_lock);
23754 +       vxdprintk(VXD_CBIT(misc, 4),
23755 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
23756 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
23757 +       return retval;
23758 +}
23759 +
23760 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
23761 +{
23762 +       struct vcmd_ctx_kill_v0 vc_data;
23763 +
23764 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23765 +               return -EFAULT;
23766 +
23767 +       /* special check to allow guest shutdown */
23768 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23769 +               /* forbid killall pid=0 when init is present */
23770 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
23771 +               (vc_data.pid > 1)))
23772 +               return -EACCES;
23773 +
23774 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
23775 +}
23776 +
23777 +
23778 +static int __wait_exit(struct vx_info *vxi)
23779 +{
23780 +       DECLARE_WAITQUEUE(wait, current);
23781 +       int ret = 0;
23782 +
23783 +       add_wait_queue(&vxi->vx_wait, &wait);
23784 +       set_current_state(TASK_INTERRUPTIBLE);
23785 +
23786 +wait:
23787 +       if (vx_info_state(vxi,
23788 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
23789 +               goto out;
23790 +       if (signal_pending(current)) {
23791 +               ret = -ERESTARTSYS;
23792 +               goto out;
23793 +       }
23794 +       schedule();
23795 +       goto wait;
23796 +
23797 +out:
23798 +       set_current_state(TASK_RUNNING);
23799 +       remove_wait_queue(&vxi->vx_wait, &wait);
23800 +       return ret;
23801 +}
23802 +
23803 +
23804 +
23805 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
23806 +{
23807 +       struct vcmd_wait_exit_v0 vc_data;
23808 +       int ret;
23809 +
23810 +       ret = __wait_exit(vxi);
23811 +       vc_data.reboot_cmd = vxi->reboot_cmd;
23812 +       vc_data.exit_code = vxi->exit_code;
23813 +
23814 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23815 +               ret = -EFAULT;
23816 +       return ret;
23817 +}
23818 +
23819 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/space.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/space.c
23820 --- linux-2.6.27.3/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
23821 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/space.c  2008-10-13 14:54:20.000000000 +0200
23822 @@ -0,0 +1,372 @@
23823 +/*
23824 + *  linux/kernel/vserver/space.c
23825 + *
23826 + *  Virtual Server: Context Space Support
23827 + *
23828 + *  Copyright (C) 2003-2007  Herbert Pötzl
23829 + *
23830 + *  V0.01  broken out from context.c 0.07
23831 + *  V0.02  added task locking for namespace
23832 + *  V0.03  broken out vx_enter_namespace
23833 + *  V0.04  added *space support and commands
23834 + *
23835 + */
23836 +
23837 +#include <linux/utsname.h>
23838 +#include <linux/nsproxy.h>
23839 +#include <linux/err.h>
23840 +#include <asm/uaccess.h>
23841 +
23842 +#include <linux/vs_context.h>
23843 +#include <linux/vserver/space.h>
23844 +#include <linux/vserver/space_cmd.h>
23845 +
23846 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23847 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23848 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23849 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23850 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
23851 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23852 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23853 +
23854 +
23855 +/* namespace functions */
23856 +
23857 +#include <linux/mnt_namespace.h>
23858 +#include <linux/user_namespace.h>
23859 +#include <linux/pid_namespace.h>
23860 +#include <linux/ipc_namespace.h>
23861 +#include <net/net_namespace.h>
23862 +
23863 +
23864 +static const struct vcmd_space_mask space_mask_v0 = {
23865 +       .mask = CLONE_FS |
23866 +               CLONE_NEWNS |
23867 +               CLONE_NEWUTS |
23868 +               CLONE_NEWIPC |
23869 +               CLONE_NEWUSER |
23870 +               0
23871 +};
23872 +
23873 +static const struct vcmd_space_mask space_mask = {
23874 +       .mask = CLONE_FS |
23875 +               CLONE_NEWNS |
23876 +               CLONE_NEWUTS |
23877 +               CLONE_NEWIPC |
23878 +               CLONE_NEWUSER |
23879 +#ifdef CONFIG_PID_NS
23880 +               CLONE_NEWPID |
23881 +#endif
23882 +#ifdef CONFIG_NET_NS
23883 +               CLONE_NEWNET |
23884 +#endif
23885 +               0
23886 +};
23887 +
23888 +static const struct vcmd_space_mask default_space_mask = {
23889 +       .mask = CLONE_FS |
23890 +               CLONE_NEWNS |
23891 +               CLONE_NEWUTS |
23892 +               CLONE_NEWIPC |
23893 +               CLONE_NEWUSER |
23894 +#ifdef CONFIG_PID_NS
23895 +//             CLONE_NEWPID |
23896 +#endif
23897 +               0
23898 +};
23899 +
23900 +/*
23901 + *     build a new nsproxy mix
23902 + *      assumes that both proxies are 'const'
23903 + *     does not touch nsproxy refcounts
23904 + *     will hold a reference on the result.
23905 + */
23906 +
23907 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23908 +       struct nsproxy *new_nsproxy, unsigned long mask)
23909 +{
23910 +       struct mnt_namespace *old_ns;
23911 +       struct uts_namespace *old_uts;
23912 +       struct ipc_namespace *old_ipc;
23913 +       struct user_namespace *old_user;
23914 +#ifdef CONFIG_PID_NS
23915 +       struct pid_namespace *old_pid;
23916 +#endif
23917 +#ifdef CONFIG_NET_NS
23918 +       struct net *old_net;
23919 +#endif
23920 +       struct nsproxy *nsproxy;
23921 +
23922 +       nsproxy = copy_nsproxy(old_nsproxy);
23923 +       if (!nsproxy)
23924 +               goto out;
23925 +
23926 +       if (mask & CLONE_NEWNS) {
23927 +               old_ns = nsproxy->mnt_ns;
23928 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23929 +               if (nsproxy->mnt_ns)
23930 +                       get_mnt_ns(nsproxy->mnt_ns);
23931 +       } else
23932 +               old_ns = NULL;
23933 +
23934 +       if (mask & CLONE_NEWUTS) {
23935 +               old_uts = nsproxy->uts_ns;
23936 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23937 +               if (nsproxy->uts_ns)
23938 +                       get_uts_ns(nsproxy->uts_ns);
23939 +       } else
23940 +               old_uts = NULL;
23941 +
23942 +       if (mask & CLONE_NEWIPC) {
23943 +               old_ipc = nsproxy->ipc_ns;
23944 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23945 +               if (nsproxy->ipc_ns)
23946 +                       get_ipc_ns(nsproxy->ipc_ns);
23947 +       } else
23948 +               old_ipc = NULL;
23949 +
23950 +       if (mask & CLONE_NEWUSER) {
23951 +               old_user = nsproxy->user_ns;
23952 +               nsproxy->user_ns = new_nsproxy->user_ns;
23953 +               if (nsproxy->user_ns)
23954 +                       get_user_ns(nsproxy->user_ns);
23955 +       } else
23956 +               old_user = NULL;
23957 +
23958 +#ifdef CONFIG_PID_NS
23959 +       if (mask & CLONE_NEWPID) {
23960 +               old_pid = nsproxy->pid_ns;
23961 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23962 +               if (nsproxy->pid_ns)
23963 +                       get_pid_ns(nsproxy->pid_ns);
23964 +       } else
23965 +               old_pid = NULL;
23966 +#endif
23967 +#ifdef CONFIG_NET_NS
23968 +       if (mask & CLONE_NEWNET) {
23969 +               old_net = nsproxy->net_ns;
23970 +               nsproxy->net_ns = new_nsproxy->net_ns;
23971 +               if (nsproxy->net_ns)
23972 +                       get_net(nsproxy->net_ns);
23973 +       } else
23974 +               old_net = NULL;
23975 +#endif
23976 +       if (old_ns)
23977 +               put_mnt_ns(old_ns);
23978 +       if (old_uts)
23979 +               put_uts_ns(old_uts);
23980 +       if (old_ipc)
23981 +               put_ipc_ns(old_ipc);
23982 +       if (old_user)
23983 +               put_user_ns(old_user);
23984 +#ifdef CONFIG_PID_NS
23985 +       if (old_pid)
23986 +               put_pid_ns(old_pid);
23987 +#endif
23988 +#ifdef CONFIG_NET_NS
23989 +       if (old_net)
23990 +               put_net(old_net);
23991 +#endif
23992 +out:
23993 +       return nsproxy;
23994 +}
23995 +
23996 +
23997 +/*
23998 + *     merge two nsproxy structs into a new one.
23999 + *     will hold a reference on the result.
24000 + */
24001 +
24002 +static inline
24003 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24004 +       struct nsproxy *proxy, unsigned long mask)
24005 +{
24006 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24007 +
24008 +       if (!proxy)
24009 +               return NULL;
24010 +
24011 +       if (mask) {
24012 +               /* vs_mix_nsproxy returns with reference */
24013 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24014 +                       proxy, mask);
24015 +       }
24016 +       get_nsproxy(proxy);
24017 +       return proxy;
24018 +}
24019 +
24020 +/*
24021 + *     merge two fs structs into a new one.
24022 + *     will take a reference on the result.
24023 + */
24024 +
24025 +static inline
24026 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24027 +       struct fs_struct *fs, unsigned long mask)
24028 +{
24029 +       if (!(mask & CLONE_FS)) {
24030 +               if (old)
24031 +                       atomic_inc(&old->count);
24032 +               return old;
24033 +       }
24034 +
24035 +       if (!fs)
24036 +               return NULL;
24037 +
24038 +       return copy_fs_struct(fs);
24039 +}
24040 +
24041 +
24042 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
24043 +{
24044 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24045 +       struct fs_struct *fs, *fs_cur, *fs_new;
24046 +       int ret;
24047 +
24048 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx)",
24049 +               vxi, vxi->vx_id, mask);
24050 +
24051 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24052 +               return -EACCES;
24053 +
24054 +       if (!mask)
24055 +               mask = vxi->vx_nsmask;
24056 +
24057 +       if ((mask & vxi->vx_nsmask) != mask)
24058 +               return -EINVAL;
24059 +
24060 +       proxy = vxi->vx_nsproxy;
24061 +       fs = vxi->vx_fs;
24062 +
24063 +       task_lock(current);
24064 +       fs_cur = current->fs;
24065 +       atomic_inc(&fs_cur->count);
24066 +       proxy_cur = current->nsproxy;
24067 +       get_nsproxy(proxy_cur);
24068 +       task_unlock(current);
24069 +
24070 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24071 +       if (IS_ERR(fs_new)) {
24072 +               ret = PTR_ERR(fs_new);
24073 +               goto out_put;
24074 +       }
24075 +
24076 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24077 +       if (IS_ERR(proxy_new)) {
24078 +               ret = PTR_ERR(proxy_new);
24079 +               goto out_put_fs;
24080 +       }
24081 +
24082 +       fs_new = xchg(&current->fs, fs_new);
24083 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24084 +       ret = 0;
24085 +
24086 +       if (proxy_new)
24087 +               put_nsproxy(proxy_new);
24088 +out_put_fs:
24089 +       if (fs_new)
24090 +               put_fs_struct(fs_new);
24091 +out_put:
24092 +       if (proxy_cur)
24093 +               put_nsproxy(proxy_cur);
24094 +       if (fs_cur)
24095 +               put_fs_struct(fs_cur);
24096 +       return ret;
24097 +}
24098 +
24099 +
24100 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
24101 +{
24102 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24103 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24104 +       int ret;
24105 +
24106 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx)",
24107 +               vxi, vxi->vx_id, mask);
24108 +#if 0
24109 +       if (!mask)
24110 +               mask = default_space_mask.mask;
24111 +#endif
24112 +       if ((mask & space_mask.mask) != mask)
24113 +               return -EINVAL;
24114 +
24115 +       proxy_vxi = vxi->vx_nsproxy;
24116 +       fs_vxi = vxi->vx_fs;
24117 +
24118 +       task_lock(current);
24119 +       fs_cur = current->fs;
24120 +       atomic_inc(&fs_cur->count);
24121 +       proxy_cur = current->nsproxy;
24122 +       get_nsproxy(proxy_cur);
24123 +       task_unlock(current);
24124 +
24125 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24126 +       if (IS_ERR(fs_new)) {
24127 +               ret = PTR_ERR(fs_new);
24128 +               goto out_put;
24129 +       }
24130 +
24131 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24132 +       if (IS_ERR(proxy_new)) {
24133 +               ret = PTR_ERR(proxy_new);
24134 +               goto out_put_fs;
24135 +       }
24136 +
24137 +       fs_new = xchg(&vxi->vx_fs, fs_new);
24138 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
24139 +       vxi->vx_nsmask |= mask;
24140 +       ret = 0;
24141 +
24142 +       if (proxy_new)
24143 +               put_nsproxy(proxy_new);
24144 +out_put_fs:
24145 +       if (fs_new)
24146 +               put_fs_struct(fs_new);
24147 +out_put:
24148 +       if (proxy_cur)
24149 +               put_nsproxy(proxy_cur);
24150 +       if (fs_cur)
24151 +               put_fs_struct(fs_cur);
24152 +       return ret;
24153 +}
24154 +
24155 +
24156 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24157 +{
24158 +       struct vcmd_space_mask vc_data = { .mask = 0 };
24159 +
24160 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24161 +               return -EFAULT;
24162 +
24163 +       return vx_enter_space(vxi, vc_data.mask);
24164 +}
24165 +
24166 +int vc_set_space(struct vx_info *vxi, void __user *data)
24167 +{
24168 +       struct vcmd_space_mask vc_data = { .mask = 0 };
24169 +
24170 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24171 +               return -EFAULT;
24172 +
24173 +       return vx_set_space(vxi, vc_data.mask);
24174 +}
24175 +
24176 +int vc_get_space_mask(void __user *data, int type)
24177 +{
24178 +       const struct vcmd_space_mask *mask;
24179 +
24180 +       if (type == 0)
24181 +               mask = &space_mask_v0;
24182 +       else if (type == 1)
24183 +               mask = &space_mask;
24184 +       else
24185 +               mask = &default_space_mask;
24186 +
24187 +       vxdprintk(VXD_CBIT(space, 10),
24188 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24189 +
24190 +       if (copy_to_user(data, mask, sizeof(struct vcmd_space_mask)))
24191 +               return -EFAULT;
24192 +       return 0;
24193 +}
24194 +
24195 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/switch.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/switch.c
24196 --- linux-2.6.27.3/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
24197 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/switch.c 2008-10-13 14:54:20.000000000 +0200
24198 @@ -0,0 +1,537 @@
24199 +/*
24200 + *  linux/kernel/vserver/switch.c
24201 + *
24202 + *  Virtual Server: Syscall Switch
24203 + *
24204 + *  Copyright (C) 2003-2007  Herbert Pötzl
24205 + *
24206 + *  V0.01  syscall switch
24207 + *  V0.02  added signal to context
24208 + *  V0.03  added rlimit functions
24209 + *  V0.04  added iattr, task/xid functions
24210 + *  V0.05  added debug/history stuff
24211 + *  V0.06  added compat32 layer
24212 + *  V0.07  vcmd args and perms
24213 + *  V0.08  added status commands
24214 + *  V0.09  added tag commands
24215 + *  V0.10  added oom bias
24216 + *  V0.11  added device commands
24217 + *
24218 + */
24219 +
24220 +#include <linux/vs_context.h>
24221 +#include <linux/vs_network.h>
24222 +#include <linux/vserver/switch.h>
24223 +
24224 +#include "vci_config.h"
24225 +
24226 +
24227 +static inline
24228 +int vc_get_version(uint32_t id)
24229 +{
24230 +       return VCI_VERSION;
24231 +}
24232 +
24233 +static inline
24234 +int vc_get_vci(uint32_t id)
24235 +{
24236 +       return vci_kernel_config();
24237 +}
24238 +
24239 +#include <linux/vserver/context_cmd.h>
24240 +#include <linux/vserver/cvirt_cmd.h>
24241 +#include <linux/vserver/cacct_cmd.h>
24242 +#include <linux/vserver/limit_cmd.h>
24243 +#include <linux/vserver/network_cmd.h>
24244 +#include <linux/vserver/sched_cmd.h>
24245 +#include <linux/vserver/debug_cmd.h>
24246 +#include <linux/vserver/inode_cmd.h>
24247 +#include <linux/vserver/dlimit_cmd.h>
24248 +#include <linux/vserver/signal_cmd.h>
24249 +#include <linux/vserver/space_cmd.h>
24250 +#include <linux/vserver/tag_cmd.h>
24251 +#include <linux/vserver/device_cmd.h>
24252 +
24253 +#include <linux/vserver/inode.h>
24254 +#include <linux/vserver/dlimit.h>
24255 +
24256 +
24257 +#ifdef CONFIG_COMPAT
24258 +#define __COMPAT(name, id, data, compat)       \
24259 +       (compat) ? name ## _x32(id, data) : name(id, data)
24260 +#define __COMPAT_NO_ID(name, data, compat)     \
24261 +       (compat) ? name ## _x32(data) : name(data)
24262 +#else
24263 +#define __COMPAT(name, id, data, compat)       \
24264 +       name(id, data)
24265 +#define __COMPAT_NO_ID(name, data, compat)     \
24266 +       name(data)
24267 +#endif
24268 +
24269 +
24270 +static inline
24271 +long do_vcmd(uint32_t cmd, uint32_t id,
24272 +       struct vx_info *vxi, struct nx_info *nxi,
24273 +       void __user *data, int compat)
24274 +{
24275 +       switch (cmd) {
24276 +
24277 +       case VCMD_get_version:
24278 +               return vc_get_version(id);
24279 +       case VCMD_get_vci:
24280 +               return vc_get_vci(id);
24281 +
24282 +       case VCMD_task_xid:
24283 +               return vc_task_xid(id);
24284 +       case VCMD_vx_info:
24285 +               return vc_vx_info(vxi, data);
24286 +
24287 +       case VCMD_task_nid:
24288 +               return vc_task_nid(id);
24289 +       case VCMD_nx_info:
24290 +               return vc_nx_info(nxi, data);
24291 +
24292 +       case VCMD_task_tag:
24293 +               return vc_task_tag(id);
24294 +
24295 +       /* this is version 1 */
24296 +       case VCMD_set_space:
24297 +               return vc_set_space(vxi, data);
24298 +
24299 +       case VCMD_get_space_mask_v0:
24300 +               return vc_get_space_mask(data, 0);
24301 +       /* this is version 1 */
24302 +       case VCMD_get_space_mask:
24303 +               return vc_get_space_mask(data, 1);
24304 +
24305 +       case VCMD_get_space_default:
24306 +               return vc_get_space_mask(data, -1);
24307 +
24308 +#ifdef CONFIG_IA32_EMULATION
24309 +       case VCMD_get_rlimit:
24310 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24311 +       case VCMD_set_rlimit:
24312 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24313 +#else
24314 +       case VCMD_get_rlimit:
24315 +               return vc_get_rlimit(vxi, data);
24316 +       case VCMD_set_rlimit:
24317 +               return vc_set_rlimit(vxi, data);
24318 +#endif
24319 +       case VCMD_get_rlimit_mask:
24320 +               return vc_get_rlimit_mask(id, data);
24321 +       case VCMD_reset_minmax:
24322 +               return vc_reset_minmax(vxi, data);
24323 +
24324 +       case VCMD_get_vhi_name:
24325 +               return vc_get_vhi_name(vxi, data);
24326 +       case VCMD_set_vhi_name:
24327 +               return vc_set_vhi_name(vxi, data);
24328 +
24329 +       case VCMD_ctx_stat:
24330 +               return vc_ctx_stat(vxi, data);
24331 +       case VCMD_virt_stat:
24332 +               return vc_virt_stat(vxi, data);
24333 +       case VCMD_sock_stat:
24334 +               return vc_sock_stat(vxi, data);
24335 +       case VCMD_rlimit_stat:
24336 +               return vc_rlimit_stat(vxi, data);
24337 +
24338 +       case VCMD_set_cflags:
24339 +               return vc_set_cflags(vxi, data);
24340 +       case VCMD_get_cflags:
24341 +               return vc_get_cflags(vxi, data);
24342 +
24343 +       /* this is version 1 */
24344 +       case VCMD_set_ccaps:
24345 +               return vc_set_ccaps(vxi, data);
24346 +       /* this is version 1 */
24347 +       case VCMD_get_ccaps:
24348 +               return vc_get_ccaps(vxi, data);
24349 +       case VCMD_set_bcaps:
24350 +               return vc_set_bcaps(vxi, data);
24351 +       case VCMD_get_bcaps:
24352 +               return vc_get_bcaps(vxi, data);
24353 +
24354 +       case VCMD_set_badness:
24355 +               return vc_set_badness(vxi, data);
24356 +       case VCMD_get_badness:
24357 +               return vc_get_badness(vxi, data);
24358 +
24359 +       case VCMD_set_nflags:
24360 +               return vc_set_nflags(nxi, data);
24361 +       case VCMD_get_nflags:
24362 +               return vc_get_nflags(nxi, data);
24363 +
24364 +       case VCMD_set_ncaps:
24365 +               return vc_set_ncaps(nxi, data);
24366 +       case VCMD_get_ncaps:
24367 +               return vc_get_ncaps(nxi, data);
24368 +
24369 +       case VCMD_set_sched_v4:
24370 +               return vc_set_sched_v4(vxi, data);
24371 +       /* this is version 5 */
24372 +       case VCMD_set_sched:
24373 +               return vc_set_sched(vxi, data);
24374 +       case VCMD_get_sched:
24375 +               return vc_get_sched(vxi, data);
24376 +       case VCMD_sched_info:
24377 +               return vc_sched_info(vxi, data);
24378 +
24379 +       case VCMD_add_dlimit:
24380 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24381 +       case VCMD_rem_dlimit:
24382 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24383 +       case VCMD_set_dlimit:
24384 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24385 +       case VCMD_get_dlimit:
24386 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24387 +
24388 +       case VCMD_ctx_kill:
24389 +               return vc_ctx_kill(vxi, data);
24390 +
24391 +       case VCMD_wait_exit:
24392 +               return vc_wait_exit(vxi, data);
24393 +
24394 +       case VCMD_get_iattr:
24395 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24396 +       case VCMD_set_iattr:
24397 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24398 +
24399 +       case VCMD_fget_iattr:
24400 +               return vc_fget_iattr(id, data);
24401 +       case VCMD_fset_iattr:
24402 +               return vc_fset_iattr(id, data);
24403 +
24404 +       case VCMD_enter_space_v0:
24405 +               return vc_enter_space(vxi, NULL);
24406 +       /* this is version 1 */
24407 +       case VCMD_enter_space:
24408 +               return vc_enter_space(vxi, data);
24409 +
24410 +       case VCMD_ctx_create_v0:
24411 +               return vc_ctx_create(id, NULL);
24412 +       case VCMD_ctx_create:
24413 +               return vc_ctx_create(id, data);
24414 +       case VCMD_ctx_migrate_v0:
24415 +               return vc_ctx_migrate(vxi, NULL);
24416 +       case VCMD_ctx_migrate:
24417 +               return vc_ctx_migrate(vxi, data);
24418 +
24419 +       case VCMD_net_create_v0:
24420 +               return vc_net_create(id, NULL);
24421 +       case VCMD_net_create:
24422 +               return vc_net_create(id, data);
24423 +       case VCMD_net_migrate:
24424 +               return vc_net_migrate(nxi, data);
24425 +
24426 +       case VCMD_tag_migrate:
24427 +               return vc_tag_migrate(id);
24428 +
24429 +       case VCMD_net_add:
24430 +               return vc_net_add(nxi, data);
24431 +       case VCMD_net_remove:
24432 +               return vc_net_remove(nxi, data);
24433 +
24434 +       case VCMD_net_add_ipv4:
24435 +               return vc_net_add_ipv4(nxi, data);
24436 +       case VCMD_net_remove_ipv4:
24437 +               return vc_net_remove_ipv4(nxi, data);
24438 +#ifdef CONFIG_IPV6
24439 +       case VCMD_net_add_ipv6:
24440 +               return vc_net_add_ipv6(nxi, data);
24441 +       case VCMD_net_remove_ipv6:
24442 +               return vc_net_remove_ipv6(nxi, data);
24443 +#endif
24444 +/*     case VCMD_add_match_ipv4:
24445 +               return vc_add_match_ipv4(nxi, data);
24446 +       case VCMD_get_match_ipv4:
24447 +               return vc_get_match_ipv4(nxi, data);
24448 +#ifdef CONFIG_IPV6
24449 +       case VCMD_add_match_ipv6:
24450 +               return vc_add_match_ipv6(nxi, data);
24451 +       case VCMD_get_match_ipv6:
24452 +               return vc_get_match_ipv6(nxi, data);
24453 +#endif */
24454 +
24455 +#ifdef CONFIG_VSERVER_DEVICE
24456 +       case VCMD_set_mapping:
24457 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24458 +       case VCMD_unset_mapping:
24459 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24460 +#endif
24461 +#ifdef CONFIG_VSERVER_HISTORY
24462 +       case VCMD_dump_history:
24463 +               return vc_dump_history(id);
24464 +       case VCMD_read_history:
24465 +               return __COMPAT(vc_read_history, id, data, compat);
24466 +#endif
24467 +#ifdef CONFIG_VSERVER_MONITOR
24468 +       case VCMD_read_monitor:
24469 +               return __COMPAT(vc_read_monitor, id, data, compat);
24470 +#endif
24471 +       default:
24472 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24473 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24474 +       }
24475 +       return -ENOSYS;
24476 +}
24477 +
24478 +
24479 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24480 +       case VCMD_ ## vcmd: perm = _perm;               \
24481 +               args = _args; flags = _flags; break
24482 +
24483 +
24484 +#define VCA_NONE       0x00
24485 +#define VCA_VXI                0x01
24486 +#define VCA_NXI                0x02
24487 +
24488 +#define VCF_NONE       0x00
24489 +#define VCF_INFO       0x01
24490 +#define VCF_ADMIN      0x02
24491 +#define VCF_ARES       0x06    /* includes admin */
24492 +#define VCF_SETUP      0x08
24493 +
24494 +#define VCF_ZIDOK      0x10    /* zero id okay */
24495 +
24496 +
24497 +static inline
24498 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24499 +{
24500 +       long ret;
24501 +       int permit = -1, state = 0;
24502 +       int perm = -1, args = 0, flags = 0;
24503 +       struct vx_info *vxi = NULL;
24504 +       struct nx_info *nxi = NULL;
24505 +
24506 +       switch (cmd) {
24507 +       /* unpriviledged commands */
24508 +       __VCMD(get_version,      0, VCA_NONE,   0);
24509 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24510 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24511 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24512 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24513 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24514 +
24515 +       /* info commands */
24516 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24517 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24518 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24519 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24520 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24521 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24522 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24523 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24524 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24525 +
24526 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24527 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24528 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24529 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24530 +
24531 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24532 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24533 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24534 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24535 +
24536 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24537 +
24538 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24539 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24540 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24541 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24542 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24543 +
24544 +       /* lower admin commands */
24545 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24546 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24547 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24548 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24549 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24550 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24551 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24552 +
24553 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24554 +       __VCMD(net_create,       5, VCA_NONE,   0);
24555 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24556 +
24557 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
24558 +
24559 +       /* higher admin commands */
24560 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
24561 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24562 +
24563 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24564 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24565 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24566 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24567 +
24568 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24569 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24570 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24571 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24572 +
24573 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24574 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24575 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24576 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24577 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24578 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24579 +#ifdef CONFIG_IPV6
24580 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24581 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24582 +#endif
24583 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
24584 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
24585 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
24586 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
24587 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
24588 +
24589 +#ifdef CONFIG_VSERVER_DEVICE
24590 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24591 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24592 +#endif
24593 +       /* debug level admin commands */
24594 +#ifdef CONFIG_VSERVER_HISTORY
24595 +       __VCMD(dump_history,     9, VCA_NONE,   0);
24596 +       __VCMD(read_history,     9, VCA_NONE,   0);
24597 +#endif
24598 +#ifdef CONFIG_VSERVER_MONITOR
24599 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
24600 +#endif
24601 +
24602 +       default:
24603 +               perm = -1;
24604 +       }
24605 +
24606 +       vxdprintk(VXD_CBIT(switch, 0),
24607 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
24608 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24609 +               VC_VERSION(cmd), id, data, compat,
24610 +               perm, args, flags);
24611 +
24612 +       ret = -ENOSYS;
24613 +       if (perm < 0)
24614 +               goto out;
24615 +
24616 +       state = 1;
24617 +       if (!capable(CAP_CONTEXT))
24618 +               goto out;
24619 +
24620 +       state = 2;
24621 +       /* moved here from the individual commands */
24622 +       ret = -EPERM;
24623 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
24624 +               goto out;
24625 +
24626 +       state = 3;
24627 +       /* vcmd involves resource management  */
24628 +       ret = -EPERM;
24629 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
24630 +               goto out;
24631 +
24632 +       state = 4;
24633 +       /* various legacy exceptions */
24634 +       switch (cmd) {
24635 +       /* will go away when spectator is a cap */
24636 +       case VCMD_ctx_migrate_v0:
24637 +       case VCMD_ctx_migrate:
24638 +               if (id == 1) {
24639 +                       current->xid = 1;
24640 +                       ret = 1;
24641 +                       goto out;
24642 +               }
24643 +               break;
24644 +
24645 +       /* will go away when spectator is a cap */
24646 +       case VCMD_net_migrate:
24647 +               if (id == 1) {
24648 +                       current->nid = 1;
24649 +                       ret = 1;
24650 +                       goto out;
24651 +               }
24652 +               break;
24653 +       }
24654 +
24655 +       /* vcmds are fine by default */
24656 +       permit = 1;
24657 +
24658 +       /* admin type vcmds require admin ... */
24659 +       if (flags & VCF_ADMIN)
24660 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
24661 +
24662 +       /* ... but setup type vcmds override that */
24663 +       if (!permit && (flags & VCF_SETUP))
24664 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
24665 +
24666 +       state = 5;
24667 +       ret = -EPERM;
24668 +       if (!permit)
24669 +               goto out;
24670 +
24671 +       state = 6;
24672 +       if (!id && (flags & VCF_ZIDOK))
24673 +               goto skip_id;
24674 +
24675 +       ret = -ESRCH;
24676 +       if (args & VCA_VXI) {
24677 +               vxi = lookup_vx_info(id);
24678 +               if (!vxi)
24679 +                       goto out;
24680 +
24681 +               if ((flags & VCF_ADMIN) &&
24682 +                       /* special case kill for shutdown */
24683 +                       (cmd != VCMD_ctx_kill) &&
24684 +                       /* can context be administrated? */
24685 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
24686 +                       ret = -EACCES;
24687 +                       goto out_vxi;
24688 +               }
24689 +       }
24690 +       state = 7;
24691 +       if (args & VCA_NXI) {
24692 +               nxi = lookup_nx_info(id);
24693 +               if (!nxi)
24694 +                       goto out_vxi;
24695 +
24696 +               if ((flags & VCF_ADMIN) &&
24697 +                       /* can context be administrated? */
24698 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
24699 +                       ret = -EACCES;
24700 +                       goto out_nxi;
24701 +               }
24702 +       }
24703 +skip_id:
24704 +       state = 8;
24705 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
24706 +
24707 +out_nxi:
24708 +       if ((args & VCA_NXI) && nxi)
24709 +               put_nx_info(nxi);
24710 +out_vxi:
24711 +       if ((args & VCA_VXI) && vxi)
24712 +               put_vx_info(vxi);
24713 +out:
24714 +       vxdprintk(VXD_CBIT(switch, 1),
24715 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
24716 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24717 +               VC_VERSION(cmd), ret, ret, state, permit);
24718 +       return ret;
24719 +}
24720 +
24721 +asmlinkage long
24722 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
24723 +{
24724 +       return do_vserver(cmd, id, data, 0);
24725 +}
24726 +
24727 +#ifdef CONFIG_COMPAT
24728 +
24729 +asmlinkage long
24730 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
24731 +{
24732 +       return do_vserver(cmd, id, data, 1);
24733 +}
24734 +
24735 +#endif /* CONFIG_COMPAT */
24736 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/sysctl.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sysctl.c
24737 --- linux-2.6.27.3/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
24738 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/sysctl.c 2008-10-13 14:54:20.000000000 +0200
24739 @@ -0,0 +1,244 @@
24740 +/*
24741 + *  kernel/vserver/sysctl.c
24742 + *
24743 + *  Virtual Context Support
24744 + *
24745 + *  Copyright (C) 2004-2007  Herbert Pötzl
24746 + *
24747 + *  V0.01  basic structure
24748 + *
24749 + */
24750 +
24751 +#include <linux/module.h>
24752 +#include <linux/ctype.h>
24753 +#include <linux/sysctl.h>
24754 +#include <linux/parser.h>
24755 +#include <asm/uaccess.h>
24756 +
24757 +
24758 +enum {
24759 +       CTL_DEBUG_ERROR         = 0,
24760 +       CTL_DEBUG_SWITCH        = 1,
24761 +       CTL_DEBUG_XID,
24762 +       CTL_DEBUG_NID,
24763 +       CTL_DEBUG_TAG,
24764 +       CTL_DEBUG_NET,
24765 +       CTL_DEBUG_LIMIT,
24766 +       CTL_DEBUG_CRES,
24767 +       CTL_DEBUG_DLIM,
24768 +       CTL_DEBUG_QUOTA,
24769 +       CTL_DEBUG_CVIRT,
24770 +       CTL_DEBUG_SPACE,
24771 +       CTL_DEBUG_MISC,
24772 +};
24773 +
24774 +
24775 +unsigned int vx_debug_switch   = 0;
24776 +unsigned int vx_debug_xid      = 0;
24777 +unsigned int vx_debug_nid      = 0;
24778 +unsigned int vx_debug_tag      = 0;
24779 +unsigned int vx_debug_net      = 0;
24780 +unsigned int vx_debug_limit    = 0;
24781 +unsigned int vx_debug_cres     = 0;
24782 +unsigned int vx_debug_dlim     = 0;
24783 +unsigned int vx_debug_quota    = 0;
24784 +unsigned int vx_debug_cvirt    = 0;
24785 +unsigned int vx_debug_space    = 0;
24786 +unsigned int vx_debug_misc     = 0;
24787 +
24788 +
24789 +static struct ctl_table_header *vserver_table_header;
24790 +static ctl_table vserver_root_table[];
24791 +
24792 +
24793 +void vserver_register_sysctl(void)
24794 +{
24795 +       if (!vserver_table_header) {
24796 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24797 +       }
24798 +
24799 +}
24800 +
24801 +void vserver_unregister_sysctl(void)
24802 +{
24803 +       if (vserver_table_header) {
24804 +               unregister_sysctl_table(vserver_table_header);
24805 +               vserver_table_header = NULL;
24806 +       }
24807 +}
24808 +
24809 +
24810 +static int proc_dodebug(ctl_table *table, int write,
24811 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
24812 +{
24813 +       char            tmpbuf[20], *p, c;
24814 +       unsigned int    value;
24815 +       size_t          left, len;
24816 +
24817 +       if ((*ppos && !write) || !*lenp) {
24818 +               *lenp = 0;
24819 +               return 0;
24820 +       }
24821 +
24822 +       left = *lenp;
24823 +
24824 +       if (write) {
24825 +               if (!access_ok(VERIFY_READ, buffer, left))
24826 +                       return -EFAULT;
24827 +               p = (char *)buffer;
24828 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24829 +                       left--, p++;
24830 +               if (!left)
24831 +                       goto done;
24832 +
24833 +               if (left > sizeof(tmpbuf) - 1)
24834 +                       return -EINVAL;
24835 +               if (copy_from_user(tmpbuf, p, left))
24836 +                       return -EFAULT;
24837 +               tmpbuf[left] = '\0';
24838 +
24839 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24840 +                       value = 10 * value + (*p - '0');
24841 +               if (*p && !isspace(*p))
24842 +                       return -EINVAL;
24843 +               while (left && isspace(*p))
24844 +                       left--, p++;
24845 +               *(unsigned int *)table->data = value;
24846 +       } else {
24847 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24848 +                       return -EFAULT;
24849 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24850 +               if (len > left)
24851 +                       len = left;
24852 +               if (__copy_to_user(buffer, tmpbuf, len))
24853 +                       return -EFAULT;
24854 +               if ((left -= len) > 0) {
24855 +                       if (put_user('\n', (char *)buffer + len))
24856 +                               return -EFAULT;
24857 +                       left--;
24858 +               }
24859 +       }
24860 +
24861 +done:
24862 +       *lenp -= left;
24863 +       *ppos += *lenp;
24864 +       return 0;
24865 +}
24866 +
24867 +static int zero;
24868 +
24869 +#define        CTL_ENTRY(ctl, name)                            \
24870 +       {                                               \
24871 +               .ctl_name       = ctl,                  \
24872 +               .procname       = #name,                \
24873 +               .data           = &vx_ ## name,         \
24874 +               .maxlen         = sizeof(int),          \
24875 +               .mode           = 0644,                 \
24876 +               .proc_handler   = &proc_dodebug,        \
24877 +               .strategy       = &sysctl_intvec,       \
24878 +               .extra1         = &zero,                \
24879 +       }
24880 +
24881 +static ctl_table vserver_debug_table[] = {
24882 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24883 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24884 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24885 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24886 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24887 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24888 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24889 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24890 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24891 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24892 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24893 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24894 +       { .ctl_name = 0 }
24895 +};
24896 +
24897 +static ctl_table vserver_root_table[] = {
24898 +       {
24899 +               .ctl_name       = CTL_VSERVER,
24900 +               .procname       = "vserver",
24901 +               .mode           = 0555,
24902 +               .child          = vserver_debug_table
24903 +       },
24904 +       { .ctl_name = 0 }
24905 +};
24906 +
24907 +
24908 +static match_table_t tokens = {
24909 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24910 +       { CTL_DEBUG_XID,        "xid=%x"        },
24911 +       { CTL_DEBUG_NID,        "nid=%x"        },
24912 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24913 +       { CTL_DEBUG_NET,        "net=%x"        },
24914 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24915 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24916 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24917 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24918 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24919 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24920 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24921 +       { CTL_DEBUG_ERROR,      NULL            }
24922 +};
24923 +
24924 +#define        HANDLE_CASE(id, name, val)                              \
24925 +       case CTL_DEBUG_ ## id:                                  \
24926 +               vx_debug_ ## name = val;                        \
24927 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24928 +               break
24929 +
24930 +
24931 +static int __init vs_debug_setup(char *str)
24932 +{
24933 +       char *p;
24934 +       int token;
24935 +
24936 +       printk("vs_debug_setup(%s)\n", str);
24937 +       while ((p = strsep(&str, ",")) != NULL) {
24938 +               substring_t args[MAX_OPT_ARGS];
24939 +               unsigned int value;
24940 +
24941 +               if (!*p)
24942 +                       continue;
24943 +
24944 +               token = match_token(p, tokens, args);
24945 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24946 +
24947 +               switch (token) {
24948 +               HANDLE_CASE(SWITCH, switch, value);
24949 +               HANDLE_CASE(XID,    xid,    value);
24950 +               HANDLE_CASE(NID,    nid,    value);
24951 +               HANDLE_CASE(TAG,    tag,    value);
24952 +               HANDLE_CASE(NET,    net,    value);
24953 +               HANDLE_CASE(LIMIT,  limit,  value);
24954 +               HANDLE_CASE(CRES,   cres,   value);
24955 +               HANDLE_CASE(DLIM,   dlim,   value);
24956 +               HANDLE_CASE(QUOTA,  quota,  value);
24957 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24958 +               HANDLE_CASE(SPACE,  space,  value);
24959 +               HANDLE_CASE(MISC,   misc,   value);
24960 +               default:
24961 +                       return -EINVAL;
24962 +                       break;
24963 +               }
24964 +       }
24965 +       return 1;
24966 +}
24967 +
24968 +__setup("vsdebug=", vs_debug_setup);
24969 +
24970 +
24971 +
24972 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24973 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24974 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24975 +EXPORT_SYMBOL_GPL(vx_debug_net);
24976 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24977 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24978 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24979 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24980 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24981 +EXPORT_SYMBOL_GPL(vx_debug_space);
24982 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24983 +
24984 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/tag.c linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/tag.c
24985 --- linux-2.6.27.3/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
24986 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/tag.c    2008-10-13 14:54:20.000000000 +0200
24987 @@ -0,0 +1,63 @@
24988 +/*
24989 + *  linux/kernel/vserver/tag.c
24990 + *
24991 + *  Virtual Server: Shallow Tag Space
24992 + *
24993 + *  Copyright (C) 2007  Herbert Pötzl
24994 + *
24995 + *  V0.01  basic implementation
24996 + *
24997 + */
24998 +
24999 +#include <linux/sched.h>
25000 +#include <linux/vserver/debug.h>
25001 +#include <linux/vs_pid.h>
25002 +#include <linux/vs_tag.h>
25003 +
25004 +#include <linux/vserver/tag_cmd.h>
25005 +
25006 +
25007 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25008 +{
25009 +       if (!p)
25010 +               BUG();
25011 +
25012 +       vxdprintk(VXD_CBIT(tag, 5),
25013 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25014 +
25015 +       task_lock(p);
25016 +       p->tag = tag;
25017 +       task_unlock(p);
25018 +
25019 +       vxdprintk(VXD_CBIT(tag, 5),
25020 +               "moved task %p into [#%d]", p, tag);
25021 +       return 0;
25022 +}
25023 +
25024 +/* vserver syscall commands below here */
25025 +
25026 +/* taks xid and vx_info functions */
25027 +
25028 +
25029 +int vc_task_tag(uint32_t id)
25030 +{
25031 +       tag_t tag;
25032 +
25033 +       if (id) {
25034 +               struct task_struct *tsk;
25035 +               read_lock(&tasklist_lock);
25036 +               tsk = find_task_by_real_pid(id);
25037 +               tag = (tsk) ? tsk->tag : -ESRCH;
25038 +               read_unlock(&tasklist_lock);
25039 +       } else
25040 +               tag = dx_current_tag();
25041 +       return tag;
25042 +}
25043 +
25044 +
25045 +int vc_tag_migrate(uint32_t tag)
25046 +{
25047 +       return dx_migrate_task(current, tag & 0xFFFF);
25048 +}
25049 +
25050 +
25051 diff -NurpP --minimal linux-2.6.27.3/kernel/vserver/vci_config.h linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/vci_config.h
25052 --- linux-2.6.27.3/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
25053 +++ linux-2.6.27.3-vs2.3.0.35.7/kernel/vserver/vci_config.h     2008-10-13 14:54:20.000000000 +0200
25054 @@ -0,0 +1,81 @@
25055 +
25056 +/*  interface version */
25057 +
25058 +#define VCI_VERSION            0x00020303
25059 +
25060 +
25061 +enum {
25062 +       VCI_KCBIT_NO_DYNAMIC = 0,
25063 +
25064 +       VCI_KCBIT_PROC_SECURE = 4,
25065 +       VCI_KCBIT_HARDCPU = 5,
25066 +       VCI_KCBIT_IDLELIMIT = 6,
25067 +       VCI_KCBIT_IDLETIME = 7,
25068 +
25069 +       VCI_KCBIT_COWBL = 8,
25070 +       VCI_KCBIT_FULLCOWBL = 9,
25071 +       VCI_KCBIT_SPACES = 10,
25072 +       VCI_KCBIT_NETV2 = 11,
25073 +
25074 +       VCI_KCBIT_DEBUG = 16,
25075 +       VCI_KCBIT_HISTORY = 20,
25076 +       VCI_KCBIT_TAGGED = 24,
25077 +       VCI_KCBIT_PPTAG = 28,
25078 +
25079 +       VCI_KCBIT_MORE = 31,
25080 +};
25081 +
25082 +
25083 +static inline uint32_t vci_kernel_config(void)
25084 +{
25085 +       return
25086 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25087 +
25088 +       /* configured features */
25089 +#ifdef CONFIG_VSERVER_PROC_SECURE
25090 +       (1 << VCI_KCBIT_PROC_SECURE) |
25091 +#endif
25092 +#ifdef CONFIG_VSERVER_HARDCPU
25093 +       (1 << VCI_KCBIT_HARDCPU) |
25094 +#endif
25095 +#ifdef CONFIG_VSERVER_IDLELIMIT
25096 +       (1 << VCI_KCBIT_IDLELIMIT) |
25097 +#endif
25098 +#ifdef CONFIG_VSERVER_IDLETIME
25099 +       (1 << VCI_KCBIT_IDLETIME) |
25100 +#endif
25101 +#ifdef CONFIG_VSERVER_COWBL
25102 +       (1 << VCI_KCBIT_COWBL) |
25103 +       (1 << VCI_KCBIT_FULLCOWBL) |
25104 +#endif
25105 +       (1 << VCI_KCBIT_SPACES) |
25106 +       (1 << VCI_KCBIT_NETV2) |
25107 +
25108 +       /* debug options */
25109 +#ifdef CONFIG_VSERVER_DEBUG
25110 +       (1 << VCI_KCBIT_DEBUG) |
25111 +#endif
25112 +#ifdef CONFIG_VSERVER_HISTORY
25113 +       (1 << VCI_KCBIT_HISTORY) |
25114 +#endif
25115 +
25116 +       /* inode context tagging */
25117 +#if    defined(CONFIG_TAGGING_NONE)
25118 +       (0 << VCI_KCBIT_TAGGED) |
25119 +#elif  defined(CONFIG_TAGGING_UID16)
25120 +       (1 << VCI_KCBIT_TAGGED) |
25121 +#elif  defined(CONFIG_TAGGING_GID16)
25122 +       (2 << VCI_KCBIT_TAGGED) |
25123 +#elif  defined(CONFIG_TAGGING_ID24)
25124 +       (3 << VCI_KCBIT_TAGGED) |
25125 +#elif  defined(CONFIG_TAGGING_INTERN)
25126 +       (4 << VCI_KCBIT_TAGGED) |
25127 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25128 +       (5 << VCI_KCBIT_TAGGED) |
25129 +#else
25130 +       (7 << VCI_KCBIT_TAGGED) |
25131 +#endif
25132 +       (1 << VCI_KCBIT_PPTAG) |
25133 +       0;
25134 +}
25135 +
25136 diff -NurpP --minimal linux-2.6.27.3/mm/filemap_xip.c linux-2.6.27.3-vs2.3.0.35.7/mm/filemap_xip.c
25137 --- linux-2.6.27.3/mm/filemap_xip.c     2008-10-13 14:52:09.000000000 +0200
25138 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/filemap_xip.c        2008-10-13 14:54:20.000000000 +0200
25139 @@ -17,6 +17,7 @@
25140  #include <linux/sched.h>
25141  #include <linux/seqlock.h>
25142  #include <linux/mutex.h>
25143 +#include <linux/vs_memory.h>
25144  #include <asm/tlbflush.h>
25145  #include <asm/io.h>
25146  
25147 diff -NurpP --minimal linux-2.6.27.3/mm/fremap.c linux-2.6.27.3-vs2.3.0.35.7/mm/fremap.c
25148 --- linux-2.6.27.3/mm/fremap.c  2008-10-13 14:52:09.000000000 +0200
25149 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/fremap.c     2008-10-13 14:54:20.000000000 +0200
25150 @@ -16,6 +16,7 @@
25151  #include <linux/module.h>
25152  #include <linux/syscalls.h>
25153  #include <linux/mmu_notifier.h>
25154 +#include <linux/vs_memory.h>
25155  
25156  #include <asm/mmu_context.h>
25157  #include <asm/cacheflush.h>
25158 diff -NurpP --minimal linux-2.6.27.3/mm/hugetlb.c linux-2.6.27.3-vs2.3.0.35.7/mm/hugetlb.c
25159 --- linux-2.6.27.3/mm/hugetlb.c 2008-10-13 14:52:09.000000000 +0200
25160 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/hugetlb.c    2008-10-13 14:54:20.000000000 +0200
25161 @@ -23,6 +23,7 @@
25162  #include <asm/io.h>
25163  
25164  #include <linux/hugetlb.h>
25165 +#include <linux/vs_memory.h>
25166  #include "internal.h"
25167  
25168  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25169 diff -NurpP --minimal linux-2.6.27.3/mm/memory.c linux-2.6.27.3-vs2.3.0.35.7/mm/memory.c
25170 --- linux-2.6.27.3/mm/memory.c  2008-10-13 14:52:09.000000000 +0200
25171 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/memory.c     2008-10-13 14:54:20.000000000 +0200
25172 @@ -562,6 +562,9 @@ static int copy_pte_range(struct mm_stru
25173         int progress = 0;
25174         int rss[2];
25175  
25176 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25177 +               return -ENOMEM;
25178 +
25179  again:
25180         rss[1] = rss[0] = 0;
25181         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25182 @@ -2294,6 +2297,11 @@ static int do_swap_page(struct mm_struct
25183                 goto out;
25184         }
25185  
25186 +       if (!vx_rss_avail(mm, 1)) {
25187 +               ret = VM_FAULT_OOM;
25188 +               goto out;
25189 +       }
25190 +
25191         mark_page_accessed(page);
25192         lock_page(page);
25193         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
25194 @@ -2365,6 +2373,8 @@ static int do_anonymous_page(struct mm_s
25195         /* Allocate our own private page. */
25196         pte_unmap(page_table);
25197  
25198 +       if (!vx_rss_avail(mm, 1))
25199 +               goto oom;
25200         if (unlikely(anon_vma_prepare(vma)))
25201                 goto oom;
25202         page = alloc_zeroed_user_highpage_movable(vma, address);
25203 @@ -2626,6 +2636,7 @@ static inline int handle_pte_fault(struc
25204  {
25205         pte_t entry;
25206         spinlock_t *ptl;
25207 +       int ret = 0, type = VXPT_UNKNOWN;
25208  
25209         entry = *pte;
25210         if (!pte_present(entry)) {
25211 @@ -2650,9 +2661,12 @@ static inline int handle_pte_fault(struc
25212         if (unlikely(!pte_same(*pte, entry)))
25213                 goto unlock;
25214         if (write_access) {
25215 -               if (!pte_write(entry))
25216 -                       return do_wp_page(mm, vma, address,
25217 +               if (!pte_write(entry)) {
25218 +                       ret = do_wp_page(mm, vma, address,
25219                                         pte, pmd, ptl, entry);
25220 +                       type = VXPT_WRITE;
25221 +                       goto out;
25222 +               }
25223                 entry = pte_mkdirty(entry);
25224         }
25225         entry = pte_mkyoung(entry);
25226 @@ -2670,7 +2684,10 @@ static inline int handle_pte_fault(struc
25227         }
25228  unlock:
25229         pte_unmap_unlock(pte, ptl);
25230 -       return 0;
25231 +       ret = 0;
25232 +out:
25233 +       vx_page_fault(mm, vma, type, ret);
25234 +       return ret;
25235  }
25236  
25237  /*
25238 diff -NurpP --minimal linux-2.6.27.3/mm/mlock.c linux-2.6.27.3-vs2.3.0.35.7/mm/mlock.c
25239 --- linux-2.6.27.3/mm/mlock.c   2008-10-13 14:52:09.000000000 +0200
25240 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/mlock.c      2008-10-13 14:54:20.000000000 +0200
25241 @@ -12,6 +12,7 @@
25242  #include <linux/syscalls.h>
25243  #include <linux/sched.h>
25244  #include <linux/module.h>
25245 +#include <linux/vs_memory.h>
25246  
25247  int can_do_mlock(void)
25248  {
25249 @@ -76,7 +77,7 @@ success:
25250                         ret = make_pages_present(start, end);
25251         }
25252  
25253 -       mm->locked_vm -= pages;
25254 +       vx_vmlocked_sub(mm, pages);
25255  out:
25256         return ret;
25257  }
25258 @@ -132,7 +133,7 @@ static int do_mlock(unsigned long start,
25259  
25260  asmlinkage long sys_mlock(unsigned long start, size_t len)
25261  {
25262 -       unsigned long locked;
25263 +       unsigned long locked, grow;
25264         unsigned long lock_limit;
25265         int error = -ENOMEM;
25266  
25267 @@ -143,8 +144,10 @@ asmlinkage long sys_mlock(unsigned long 
25268         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25269         start &= PAGE_MASK;
25270  
25271 -       locked = len >> PAGE_SHIFT;
25272 -       locked += current->mm->locked_vm;
25273 +       grow = len >> PAGE_SHIFT;
25274 +       if (!vx_vmlocked_avail(current->mm, grow))
25275 +               goto out;
25276 +       locked = current->mm->locked_vm + grow;
25277  
25278         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25279         lock_limit >>= PAGE_SHIFT;
25280 @@ -152,6 +155,7 @@ asmlinkage long sys_mlock(unsigned long 
25281         /* check against resource limits */
25282         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25283                 error = do_mlock(start, len, 1);
25284 +out:
25285         up_write(&current->mm->mmap_sem);
25286         return error;
25287  }
25288 @@ -211,6 +215,8 @@ asmlinkage long sys_mlockall(int flags)
25289         lock_limit >>= PAGE_SHIFT;
25290  
25291         ret = -ENOMEM;
25292 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25293 +               goto out;
25294         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25295             capable(CAP_IPC_LOCK))
25296                 ret = do_mlockall(flags);
25297 diff -NurpP --minimal linux-2.6.27.3/mm/mmap.c linux-2.6.27.3-vs2.3.0.35.7/mm/mmap.c
25298 --- linux-2.6.27.3/mm/mmap.c    2008-10-13 14:52:09.000000000 +0200
25299 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/mmap.c       2008-10-13 14:54:20.000000000 +0200
25300 @@ -1221,10 +1221,10 @@ munmap_back:
25301         if (correct_wcount)
25302                 atomic_inc(&inode->i_writecount);
25303  out:
25304 -       mm->total_vm += len >> PAGE_SHIFT;
25305 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25306         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25307         if (vm_flags & VM_LOCKED) {
25308 -               mm->locked_vm += len >> PAGE_SHIFT;
25309 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25310                 make_pages_present(addr, addr + len);
25311         }
25312         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25313 @@ -1573,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
25314                 return -ENOMEM;
25315  
25316         /* Ok, everything looks good - let it rip */
25317 -       mm->total_vm += grow;
25318 +       vx_vmpages_add(mm, grow);
25319         if (vma->vm_flags & VM_LOCKED)
25320 -               mm->locked_vm += grow;
25321 +               vx_vmlocked_add(mm, grow);
25322         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25323         return 0;
25324  }
25325 @@ -1746,9 +1746,9 @@ static void remove_vma_list(struct mm_st
25326         do {
25327                 long nrpages = vma_pages(vma);
25328  
25329 -               mm->total_vm -= nrpages;
25330 +               vx_vmpages_sub(mm, nrpages);
25331                 if (vma->vm_flags & VM_LOCKED)
25332 -                       mm->locked_vm -= nrpages;
25333 +                       vx_vmlocked_sub(mm, nrpages);
25334                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25335                 vma = remove_vma(vma);
25336         } while (vma);
25337 @@ -1995,6 +1995,8 @@ unsigned long do_brk(unsigned long addr,
25338                 lock_limit >>= PAGE_SHIFT;
25339                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25340                         return -EAGAIN;
25341 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25342 +                       return -ENOMEM;
25343         }
25344  
25345         /*
25346 @@ -2021,7 +2023,8 @@ unsigned long do_brk(unsigned long addr,
25347         if (mm->map_count > sysctl_max_map_count)
25348                 return -ENOMEM;
25349  
25350 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25351 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25352 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25353                 return -ENOMEM;
25354  
25355         /* Can we just expand an old private anonymous mapping? */
25356 @@ -2046,9 +2049,9 @@ unsigned long do_brk(unsigned long addr,
25357         vma->vm_page_prot = vm_get_page_prot(flags);
25358         vma_link(mm, vma, prev, rb_link, rb_parent);
25359  out:
25360 -       mm->total_vm += len >> PAGE_SHIFT;
25361 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25362         if (flags & VM_LOCKED) {
25363 -               mm->locked_vm += len >> PAGE_SHIFT;
25364 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
25365                 make_pages_present(addr, addr + len);
25366         }
25367         return addr;
25368 @@ -2078,6 +2081,11 @@ void exit_mmap(struct mm_struct *mm)
25369         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
25370         tlb_finish_mmu(tlb, 0, end);
25371  
25372 +       set_mm_counter(mm, file_rss, 0);
25373 +       set_mm_counter(mm, anon_rss, 0);
25374 +       vx_vmpages_sub(mm, mm->total_vm);
25375 +       vx_vmlocked_sub(mm, mm->locked_vm);
25376 +
25377         /*
25378          * Walk the list again, actually closing and freeing it,
25379          * with preemption enabled, without holding any MM locks.
25380 @@ -2117,7 +2125,8 @@ int insert_vm_struct(struct mm_struct * 
25381         if (__vma && __vma->vm_start < vma->vm_end)
25382                 return -ENOMEM;
25383         if ((vma->vm_flags & VM_ACCOUNT) &&
25384 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
25385 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
25386 +               !vx_vmpages_avail(mm, vma_pages(vma))))
25387                 return -ENOMEM;
25388         vma_link(mm, vma, prev, rb_link, rb_parent);
25389         return 0;
25390 @@ -2193,6 +2202,8 @@ int may_expand_vm(struct mm_struct *mm, 
25391  
25392         if (cur + npages > lim)
25393                 return 0;
25394 +       if (!vx_vmpages_avail(mm, npages))
25395 +               return 0;
25396         return 1;
25397  }
25398  
25399 @@ -2270,8 +2281,7 @@ int install_special_mapping(struct mm_st
25400                 return -ENOMEM;
25401         }
25402  
25403 -       mm->total_vm += len >> PAGE_SHIFT;
25404 -
25405 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25406         return 0;
25407  }
25408  
25409 diff -NurpP --minimal linux-2.6.27.3/mm/mremap.c linux-2.6.27.3-vs2.3.0.35.7/mm/mremap.c
25410 --- linux-2.6.27.3/mm/mremap.c  2008-10-13 14:52:09.000000000 +0200
25411 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/mremap.c     2008-10-13 14:54:20.000000000 +0200
25412 @@ -19,6 +19,7 @@
25413  #include <linux/security.h>
25414  #include <linux/syscalls.h>
25415  #include <linux/mmu_notifier.h>
25416 +#include <linux/vs_memory.h>
25417  
25418  #include <asm/uaccess.h>
25419  #include <asm/cacheflush.h>
25420 @@ -218,7 +219,7 @@ static unsigned long move_vma(struct vm_
25421          * If this were a serious issue, we'd add a flag to do_munmap().
25422          */
25423         hiwater_vm = mm->hiwater_vm;
25424 -       mm->total_vm += new_len >> PAGE_SHIFT;
25425 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
25426         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
25427  
25428         if (do_munmap(mm, old_addr, old_len) < 0) {
25429 @@ -236,7 +237,7 @@ static unsigned long move_vma(struct vm_
25430         }
25431  
25432         if (vm_flags & VM_LOCKED) {
25433 -               mm->locked_vm += new_len >> PAGE_SHIFT;
25434 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
25435                 if (new_len > old_len)
25436                         make_pages_present(new_addr + old_len,
25437                                            new_addr + new_len);
25438 @@ -347,6 +348,9 @@ unsigned long do_mremap(unsigned long ad
25439                 ret = -EAGAIN;
25440                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25441                         goto out;
25442 +               if (!vx_vmlocked_avail(current->mm,
25443 +                       (new_len - old_len) >> PAGE_SHIFT))
25444 +                       goto out;
25445         }
25446         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
25447                 ret = -ENOMEM;
25448 @@ -375,10 +379,10 @@ unsigned long do_mremap(unsigned long ad
25449                         vma_adjust(vma, vma->vm_start,
25450                                 addr + new_len, vma->vm_pgoff, NULL);
25451  
25452 -                       mm->total_vm += pages;
25453 +                       vx_vmpages_add(mm, pages);
25454                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
25455                         if (vma->vm_flags & VM_LOCKED) {
25456 -                               mm->locked_vm += pages;
25457 +                               vx_vmlocked_add(mm, pages);
25458                                 make_pages_present(addr + old_len,
25459                                                    addr + new_len);
25460                         }
25461 diff -NurpP --minimal linux-2.6.27.3/mm/nommu.c linux-2.6.27.3-vs2.3.0.35.7/mm/nommu.c
25462 --- linux-2.6.27.3/mm/nommu.c   2008-10-13 14:52:09.000000000 +0200
25463 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/nommu.c      2008-10-13 14:54:20.000000000 +0200
25464 @@ -1028,7 +1028,7 @@ unsigned long do_mmap_pgoff(struct file 
25465         realalloc += kobjsize(vma);
25466         askedalloc += sizeof(*vma);
25467  
25468 -       current->mm->total_vm += len >> PAGE_SHIFT;
25469 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
25470  
25471         add_nommu_vma(vma);
25472  
25473 @@ -1160,7 +1160,7 @@ int do_munmap(struct mm_struct *mm, unsi
25474         kfree(vml);
25475  
25476         update_hiwater_vm(mm);
25477 -       mm->total_vm -= len >> PAGE_SHIFT;
25478 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
25479  
25480  #ifdef DEBUG
25481         show_process_blocks();
25482 @@ -1193,7 +1193,7 @@ void exit_mmap(struct mm_struct * mm)
25483                 printk("Exit_mmap:\n");
25484  #endif
25485  
25486 -               mm->total_vm = 0;
25487 +               vx_vmpages_sub(mm, mm->total_vm);
25488  
25489                 while ((tmp = mm->context.vmlist)) {
25490                         mm->context.vmlist = tmp->next;
25491 diff -NurpP --minimal linux-2.6.27.3/mm/oom_kill.c linux-2.6.27.3-vs2.3.0.35.7/mm/oom_kill.c
25492 --- linux-2.6.27.3/mm/oom_kill.c        2008-10-13 14:52:09.000000000 +0200
25493 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/oom_kill.c   2008-10-13 14:54:20.000000000 +0200
25494 @@ -27,6 +27,7 @@
25495  #include <linux/notifier.h>
25496  #include <linux/memcontrol.h>
25497  #include <linux/security.h>
25498 +#include <linux/vs_memory.h>
25499  
25500  int sysctl_panic_on_oom;
25501  int sysctl_oom_kill_allocating_task;
25502 @@ -73,6 +74,12 @@ unsigned long badness(struct task_struct
25503         points = mm->total_vm;
25504  
25505         /*
25506 +        * add points for context badness
25507 +        */
25508 +
25509 +       points += vx_badness(p, mm);
25510 +
25511 +       /*
25512          * After this unlock we can no longer dereference local variable `mm'
25513          */
25514         task_unlock(p);
25515 @@ -163,8 +170,8 @@ unsigned long badness(struct task_struct
25516         }
25517  
25518  #ifdef DEBUG
25519 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
25520 -       p->pid, p->comm, points);
25521 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
25522 +               task_pid_nr(p), p->xid, p->comm, points);
25523  #endif
25524         return points;
25525  }
25526 @@ -325,8 +332,8 @@ static void __oom_kill_task(struct task_
25527         }
25528  
25529         if (verbose)
25530 -               printk(KERN_ERR "Killed process %d (%s)\n",
25531 -                               task_pid_nr(p), p->comm);
25532 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
25533 +                               task_pid_nr(p), p->xid, p->comm);
25534  
25535         /*
25536          * We give our sacrificial lamb high priority and access to
25537 @@ -406,8 +413,8 @@ static int oom_kill_process(struct task_
25538                 return 0;
25539         }
25540  
25541 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
25542 -                                       message, task_pid_nr(p), p->comm, points);
25543 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
25544 +                               message, task_pid_nr(p), p->xid, p->comm, points);
25545  
25546         /* Try to kill a child first */
25547         list_for_each_entry(c, &p->children, sibling) {
25548 diff -NurpP --minimal linux-2.6.27.3/mm/page_alloc.c linux-2.6.27.3-vs2.3.0.35.7/mm/page_alloc.c
25549 --- linux-2.6.27.3/mm/page_alloc.c      2008-10-13 14:52:09.000000000 +0200
25550 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/page_alloc.c 2008-10-13 14:54:20.000000000 +0200
25551 @@ -46,6 +46,8 @@
25552  #include <linux/page-isolation.h>
25553  #include <linux/memcontrol.h>
25554  #include <linux/debugobjects.h>
25555 +#include <linux/vs_base.h>
25556 +#include <linux/vs_limit.h>
25557  
25558  #include <asm/tlbflush.h>
25559  #include <asm/div64.h>
25560 @@ -1809,6 +1811,9 @@ void si_meminfo(struct sysinfo *val)
25561         val->totalhigh = totalhigh_pages;
25562         val->freehigh = nr_free_highpages();
25563         val->mem_unit = PAGE_SIZE;
25564 +
25565 +       if (vx_flags(VXF_VIRT_MEM, 0))
25566 +               vx_vsi_meminfo(val);
25567  }
25568  
25569  EXPORT_SYMBOL(si_meminfo);
25570 @@ -1829,6 +1834,9 @@ void si_meminfo_node(struct sysinfo *val
25571         val->freehigh = 0;
25572  #endif
25573         val->mem_unit = PAGE_SIZE;
25574 +
25575 +       if (vx_flags(VXF_VIRT_MEM, 0))
25576 +               vx_vsi_meminfo(val);
25577  }
25578  #endif
25579  
25580 diff -NurpP --minimal linux-2.6.27.3/mm/rmap.c linux-2.6.27.3-vs2.3.0.35.7/mm/rmap.c
25581 --- linux-2.6.27.3/mm/rmap.c    2008-10-13 14:52:09.000000000 +0200
25582 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/rmap.c       2008-10-13 14:54:20.000000000 +0200
25583 @@ -50,6 +50,7 @@
25584  #include <linux/kallsyms.h>
25585  #include <linux/memcontrol.h>
25586  #include <linux/mmu_notifier.h>
25587 +#include <linux/vs_memory.h>
25588  
25589  #include <asm/tlbflush.h>
25590  
25591 diff -NurpP --minimal linux-2.6.27.3/mm/shmem.c linux-2.6.27.3-vs2.3.0.35.7/mm/shmem.c
25592 --- linux-2.6.27.3/mm/shmem.c   2008-10-13 14:52:09.000000000 +0200
25593 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/shmem.c      2008-10-13 14:54:20.000000000 +0200
25594 @@ -56,7 +56,6 @@
25595  #include <asm/pgtable.h>
25596  
25597  /* This magic number is used in glibc for posix shared memory */
25598 -#define TMPFS_MAGIC    0x01021994
25599  
25600  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
25601  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
25602 @@ -1738,7 +1737,7 @@ static int shmem_statfs(struct dentry *d
25603  {
25604         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
25605  
25606 -       buf->f_type = TMPFS_MAGIC;
25607 +       buf->f_type = TMPFS_SUPER_MAGIC;
25608         buf->f_bsize = PAGE_CACHE_SIZE;
25609         buf->f_namelen = NAME_MAX;
25610         spin_lock(&sbinfo->stat_lock);
25611 @@ -2306,7 +2305,7 @@ static int shmem_fill_super(struct super
25612         sb->s_maxbytes = SHMEM_MAX_BYTES;
25613         sb->s_blocksize = PAGE_CACHE_SIZE;
25614         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
25615 -       sb->s_magic = TMPFS_MAGIC;
25616 +       sb->s_magic = TMPFS_SUPER_MAGIC;
25617         sb->s_op = &shmem_ops;
25618         sb->s_time_gran = 1;
25619  #ifdef CONFIG_TMPFS_POSIX_ACL
25620 diff -NurpP --minimal linux-2.6.27.3/mm/slab.c linux-2.6.27.3-vs2.3.0.35.7/mm/slab.c
25621 --- linux-2.6.27.3/mm/slab.c    2008-10-13 14:52:09.000000000 +0200
25622 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/slab.c       2008-10-13 14:54:20.000000000 +0200
25623 @@ -508,6 +508,8 @@ struct kmem_cache {
25624  #define STATS_INC_FREEMISS(x)  do { } while (0)
25625  #endif
25626  
25627 +#include "slab_vs.h"
25628 +
25629  #if DEBUG
25630  
25631  /*
25632 @@ -3337,6 +3339,7 @@ retry:
25633  
25634         obj = slab_get_obj(cachep, slabp, nodeid);
25635         check_slabp(cachep, slabp);
25636 +       vx_slab_alloc(cachep, flags);
25637         l3->free_objects--;
25638         /* move slabp to correct slabp list: */
25639         list_del(&slabp->list);
25640 @@ -3409,6 +3412,7 @@ __cache_alloc_node(struct kmem_cache *ca
25641         /* ___cache_alloc_node can fall back to other nodes */
25642         ptr = ____cache_alloc_node(cachep, flags, nodeid);
25643    out:
25644 +       vx_slab_alloc(cachep, flags);
25645         local_irq_restore(save_flags);
25646         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
25647  
25648 @@ -3580,6 +3584,7 @@ static inline void __cache_free(struct k
25649  
25650         check_irq_off();
25651         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
25652 +       vx_slab_free(cachep);
25653  
25654         /*
25655          * Skip calling cache_free_alien() when the platform is not numa.
25656 diff -NurpP --minimal linux-2.6.27.3/mm/slab_vs.h linux-2.6.27.3-vs2.3.0.35.7/mm/slab_vs.h
25657 --- linux-2.6.27.3/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
25658 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/slab_vs.h    2008-10-13 14:54:20.000000000 +0200
25659 @@ -0,0 +1,27 @@
25660 +
25661 +#include <linux/vserver/context.h>
25662 +
25663 +#include <linux/vs_context.h>
25664 +
25665 +static inline
25666 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
25667 +{
25668 +       int what = gfp_zone(cachep->gfpflags);
25669 +
25670 +       if (!current->vx_info)
25671 +               return;
25672 +
25673 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
25674 +}
25675 +
25676 +static inline
25677 +void vx_slab_free(struct kmem_cache *cachep)
25678 +{
25679 +       int what = gfp_zone(cachep->gfpflags);
25680 +
25681 +       if (!current->vx_info)
25682 +               return;
25683 +
25684 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
25685 +}
25686 +
25687 diff -NurpP --minimal linux-2.6.27.3/mm/swapfile.c linux-2.6.27.3-vs2.3.0.35.7/mm/swapfile.c
25688 --- linux-2.6.27.3/mm/swapfile.c        2008-10-13 14:52:09.000000000 +0200
25689 +++ linux-2.6.27.3-vs2.3.0.35.7/mm/swapfile.c   2008-10-13 14:54:20.000000000 +0200
25690 @@ -32,6 +32,8 @@
25691  #include <asm/pgtable.h>
25692  #include <asm/tlbflush.h>
25693  #include <linux/swapops.h>
25694 +#include <linux/vs_base.h>
25695 +#include <linux/vs_memory.h>
25696  
25697  static DEFINE_SPINLOCK(swap_lock);
25698  static unsigned int nr_swapfiles;
25699 @@ -1748,6 +1750,8 @@ void si_swapinfo(struct sysinfo *val)
25700         val->freeswap = nr_swap_pages + nr_to_be_unused;
25701         val->totalswap = total_swap_pages + nr_to_be_unused;
25702         spin_unlock(&swap_lock);
25703 +       if (vx_flags(VXF_VIRT_MEM, 0))
25704 +               vx_vsi_swapinfo(val);
25705  }
25706  
25707  /*
25708 diff -NurpP --minimal linux-2.6.27.3/net/core/dev.c linux-2.6.27.3-vs2.3.0.35.7/net/core/dev.c
25709 --- linux-2.6.27.3/net/core/dev.c       2008-10-13 14:52:09.000000000 +0200
25710 +++ linux-2.6.27.3-vs2.3.0.35.7/net/core/dev.c  2008-10-13 14:54:20.000000000 +0200
25711 @@ -127,6 +127,7 @@
25712  #include <linux/in.h>
25713  #include <linux/jhash.h>
25714  #include <linux/random.h>
25715 +#include <linux/vs_inet.h>
25716  
25717  #include "net-sysfs.h"
25718  
25719 @@ -2515,6 +2516,8 @@ static int dev_ifconf(struct net *net, c
25720  
25721         total = 0;
25722         for_each_netdev(net, dev) {
25723 +               if (!nx_dev_visible(current->nx_info, dev))
25724 +                       continue;
25725                 for (i = 0; i < NPROTO; i++) {
25726                         if (gifconf_list[i]) {
25727                                 int done;
25728 @@ -2583,6 +2586,9 @@ static void dev_seq_printf_stats(struct 
25729  {
25730         struct net_device_stats *stats = dev->get_stats(dev);
25731  
25732 +       if (!nx_dev_visible(current->nx_info, dev))
25733 +               return;
25734 +
25735         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
25736                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
25737                    dev->name, stats->rx_bytes, stats->rx_packets,
25738 diff -NurpP --minimal linux-2.6.27.3/net/core/rtnetlink.c linux-2.6.27.3-vs2.3.0.35.7/net/core/rtnetlink.c
25739 --- linux-2.6.27.3/net/core/rtnetlink.c 2008-10-13 14:52:09.000000000 +0200
25740 +++ linux-2.6.27.3-vs2.3.0.35.7/net/core/rtnetlink.c    2008-10-13 14:54:20.000000000 +0200
25741 @@ -686,6 +686,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
25742  
25743         idx = 0;
25744         for_each_netdev(net, dev) {
25745 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
25746 +                       continue;
25747                 if (idx < s_idx)
25748                         goto cont;
25749                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
25750 @@ -1219,6 +1221,9 @@ void rtmsg_ifinfo(int type, struct net_d
25751         struct sk_buff *skb;
25752         int err = -ENOBUFS;
25753  
25754 +       if (!nx_dev_visible(current->nx_info, dev))
25755 +               return;
25756 +
25757         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
25758         if (skb == NULL)
25759                 goto errout;
25760 diff -NurpP --minimal linux-2.6.27.3/net/core/sock.c linux-2.6.27.3-vs2.3.0.35.7/net/core/sock.c
25761 --- linux-2.6.27.3/net/core/sock.c      2008-10-13 14:52:09.000000000 +0200
25762 +++ linux-2.6.27.3-vs2.3.0.35.7/net/core/sock.c 2008-10-13 14:54:20.000000000 +0200
25763 @@ -124,6 +124,10 @@
25764  #include <linux/ipsec.h>
25765  
25766  #include <linux/filter.h>
25767 +#include <linux/vs_socket.h>
25768 +#include <linux/vs_limit.h>
25769 +#include <linux/vs_context.h>
25770 +#include <linux/vs_network.h>
25771  
25772  #ifdef CONFIG_INET
25773  #include <net/tcp.h>
25774 @@ -897,6 +901,8 @@ static struct sock *sk_prot_alloc(struct
25775                 if (!try_module_get(prot->owner))
25776                         goto out_free_sec;
25777         }
25778 +               sock_vx_init(sk);
25779 +               sock_nx_init(sk);
25780  
25781         return sk;
25782  
25783 @@ -973,6 +979,11 @@ void sk_free(struct sock *sk)
25784                        __func__, atomic_read(&sk->sk_omem_alloc));
25785  
25786         put_net(sock_net(sk));
25787 +       vx_sock_dec(sk);
25788 +       clr_vx_info(&sk->sk_vx_info);
25789 +       sk->sk_xid = -1;
25790 +       clr_nx_info(&sk->sk_nx_info);
25791 +       sk->sk_nid = -1;
25792         sk_prot_free(sk->sk_prot_creator, sk);
25793  }
25794  
25795 @@ -1008,6 +1019,8 @@ struct sock *sk_clone(const struct sock 
25796  
25797                 /* SANITY */
25798                 get_net(sock_net(newsk));
25799 +               sock_vx_init(newsk);
25800 +               sock_nx_init(newsk);
25801                 sk_node_init(&newsk->sk_node);
25802                 sock_lock_init(newsk);
25803                 bh_lock_sock(newsk);
25804 @@ -1054,6 +1067,12 @@ struct sock *sk_clone(const struct sock 
25805                 newsk->sk_priority = 0;
25806                 atomic_set(&newsk->sk_refcnt, 2);
25807  
25808 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
25809 +               newsk->sk_xid = sk->sk_xid;
25810 +               vx_sock_inc(newsk);
25811 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
25812 +               newsk->sk_nid = sk->sk_nid;
25813 +
25814                 /*
25815                  * Increment the counter in the same struct proto as the master
25816                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
25817 @@ -1738,6 +1757,11 @@ void sock_init_data(struct socket *sock,
25818  
25819         sk->sk_stamp = ktime_set(-1L, 0);
25820  
25821 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
25822 +       sk->sk_xid = vx_current_xid();
25823 +       vx_sock_inc(sk);
25824 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
25825 +       sk->sk_nid = nx_current_nid();
25826         atomic_set(&sk->sk_refcnt, 1);
25827         atomic_set(&sk->sk_drops, 0);
25828  }
25829 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/af_inet.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/af_inet.c
25830 --- linux-2.6.27.3/net/ipv4/af_inet.c   2008-10-13 14:52:09.000000000 +0200
25831 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/af_inet.c      2008-10-13 14:54:20.000000000 +0200
25832 @@ -114,6 +114,7 @@
25833  #ifdef CONFIG_IP_MROUTE
25834  #include <linux/mroute.h>
25835  #endif
25836 +#include <linux/vs_limit.h>
25837  
25838  extern void ip_mc_drop_socket(struct sock *sk);
25839  
25840 @@ -325,9 +326,12 @@ lookup_protocol:
25841         }
25842  
25843         err = -EPERM;
25844 +       if ((protocol == IPPROTO_ICMP) &&
25845 +               nx_capable(answer->capability, NXC_RAW_ICMP))
25846 +               goto override;
25847         if (answer->capability > 0 && !capable(answer->capability))
25848                 goto out_rcu_unlock;
25849 -
25850 +override:
25851         err = -EAFNOSUPPORT;
25852         if (!inet_netns_ok(net, protocol))
25853                 goto out_rcu_unlock;
25854 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
25855         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
25856         struct sock *sk = sock->sk;
25857         struct inet_sock *inet = inet_sk(sk);
25858 +       struct nx_v4_sock_addr nsa;
25859         unsigned short snum;
25860         int chk_addr_ret;
25861         int err;
25862 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
25863         if (addr_len < sizeof(struct sockaddr_in))
25864                 goto out;
25865  
25866 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25867 +       err = v4_map_sock_addr(inet, addr, &nsa);
25868 +       if (err)
25869 +               goto out;
25870 +
25871 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25872  
25873         /* Not specified by any standard per-se, however it breaks too
25874          * many applications when removed.  It is unfortunate since
25875 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
25876         err = -EADDRNOTAVAIL;
25877         if (!sysctl_ip_nonlocal_bind &&
25878             !inet->freebind &&
25879 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
25880 +           nsa.saddr != htonl(INADDR_ANY) &&
25881             chk_addr_ret != RTN_LOCAL &&
25882             chk_addr_ret != RTN_MULTICAST &&
25883             chk_addr_ret != RTN_BROADCAST)
25884 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
25885         if (sk->sk_state != TCP_CLOSE || inet->num)
25886                 goto out_release_sock;
25887  
25888 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
25889 +       v4_set_sock_addr(inet, &nsa);
25890         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25891                 inet->saddr = 0;  /* Use device */
25892  
25893 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
25894                      peer == 1))
25895                         return -ENOTCONN;
25896                 sin->sin_port = inet->dport;
25897 -               sin->sin_addr.s_addr = inet->daddr;
25898 +               sin->sin_addr.s_addr =
25899 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
25900         } else {
25901                 __be32 addr = inet->rcv_saddr;
25902                 if (!addr)
25903                         addr = inet->saddr;
25904 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
25905                 sin->sin_port = inet->sport;
25906                 sin->sin_addr.s_addr = addr;
25907         }
25908 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/devinet.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/devinet.c
25909 --- linux-2.6.27.3/net/ipv4/devinet.c   2008-10-13 14:52:09.000000000 +0200
25910 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/devinet.c      2008-10-13 14:54:20.000000000 +0200
25911 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
25912         return in_dev;
25913  }
25914  
25915 +
25916  /* Called only from RTNL semaphored context. No locks. */
25917  
25918  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
25919 @@ -662,6 +663,8 @@ int devinet_ioctl(struct net *net, unsig
25920                 *colon = ':';
25921  
25922         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
25923 +               struct nx_info *nxi = current->nx_info;
25924 +
25925                 if (tryaddrmatch) {
25926                         /* Matthias Andree */
25927                         /* compare label and address (4.4BSD style) */
25928 @@ -670,6 +673,8 @@ int devinet_ioctl(struct net *net, unsig
25929                            This is checked above. */
25930                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25931                              ifap = &ifa->ifa_next) {
25932 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25933 +                                       continue;
25934                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25935                                     sin_orig.sin_addr.s_addr ==
25936                                                         ifa->ifa_address) {
25937 @@ -682,9 +687,12 @@ int devinet_ioctl(struct net *net, unsig
25938                    comparing just the label */
25939                 if (!ifa) {
25940                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25941 -                            ifap = &ifa->ifa_next)
25942 +                            ifap = &ifa->ifa_next) {
25943 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25944 +                                       continue;
25945                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25946                                         break;
25947 +                       }
25948                 }
25949         }
25950  
25951 @@ -835,6 +843,8 @@ static int inet_gifconf(struct net_devic
25952                 goto out;
25953  
25954         for (; ifa; ifa = ifa->ifa_next) {
25955 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
25956 +                       continue;
25957                 if (!buf) {
25958                         done += sizeof(ifr);
25959                         continue;
25960 @@ -1165,6 +1175,7 @@ static int inet_dump_ifaddr(struct sk_bu
25961         struct net_device *dev;
25962         struct in_device *in_dev;
25963         struct in_ifaddr *ifa;
25964 +       struct sock *sk = skb->sk;
25965         int s_ip_idx, s_idx = cb->args[0];
25966  
25967         s_ip_idx = ip_idx = cb->args[1];
25968 @@ -1179,6 +1190,8 @@ static int inet_dump_ifaddr(struct sk_bu
25969  
25970                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25971                      ifa = ifa->ifa_next, ip_idx++) {
25972 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25973 +                               continue;
25974                         if (ip_idx < s_ip_idx)
25975                                 continue;
25976                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
25977 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/fib_hash.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/fib_hash.c
25978 --- linux-2.6.27.3/net/ipv4/fib_hash.c  2008-10-13 14:52:09.000000000 +0200
25979 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/fib_hash.c     2008-10-13 14:54:20.000000000 +0200
25980 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
25981         prefix  = f->fn_key;
25982         mask    = FZ_MASK(iter->zone);
25983         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25984 -       if (fi)
25985 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
25986                 seq_printf(seq,
25987                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25988                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25989 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/inet_connection_sock.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/inet_connection_sock.c
25990 --- linux-2.6.27.3/net/ipv4/inet_connection_sock.c      2008-10-13 14:52:09.000000000 +0200
25991 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/inet_connection_sock.c 2008-10-13 14:54:20.000000000 +0200
25992 @@ -47,10 +47,40 @@ void inet_get_local_port_range(int *low,
25993  }
25994  EXPORT_SYMBOL(inet_get_local_port_range);
25995  
25996 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25997 +{
25998 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
25999 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26000 +
26001 +       if (inet_v6_ipv6only(sk2))
26002 +               return 0;
26003 +
26004 +       if (sk1_rcv_saddr &&
26005 +           sk2_rcv_saddr &&
26006 +           sk1_rcv_saddr == sk2_rcv_saddr)
26007 +               return 1;
26008 +
26009 +       if (sk1_rcv_saddr &&
26010 +           !sk2_rcv_saddr &&
26011 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26012 +               return 1;
26013 +
26014 +       if (sk2_rcv_saddr &&
26015 +           !sk1_rcv_saddr &&
26016 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26017 +               return 1;
26018 +
26019 +       if (!sk1_rcv_saddr &&
26020 +           !sk2_rcv_saddr &&
26021 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26022 +               return 1;
26023 +
26024 +       return 0;
26025 +}
26026 +
26027  int inet_csk_bind_conflict(const struct sock *sk,
26028                            const struct inet_bind_bucket *tb)
26029  {
26030 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26031         struct sock *sk2;
26032         struct hlist_node *node;
26033         int reuse = sk->sk_reuse;
26034 @@ -70,9 +100,7 @@ int inet_csk_bind_conflict(const struct 
26035                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26036                         if (!reuse || !sk2->sk_reuse ||
26037                             sk2->sk_state == TCP_LISTEN) {
26038 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26039 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26040 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26041 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26042                                         break;
26043                         }
26044                 }
26045 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/inet_diag.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/inet_diag.c
26046 --- linux-2.6.27.3/net/ipv4/inet_diag.c 2008-10-13 14:52:09.000000000 +0200
26047 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/inet_diag.c    2008-10-13 14:54:20.000000000 +0200
26048 @@ -32,6 +32,8 @@
26049  #include <linux/stddef.h>
26050  
26051  #include <linux/inet_diag.h>
26052 +#include <linux/vs_network.h>
26053 +#include <linux/vs_inet.h>
26054  
26055  static const struct inet_diag_handler **inet_diag_table;
26056  
26057 @@ -120,8 +122,8 @@ static int inet_csk_diag_fill(struct soc
26058  
26059         r->id.idiag_sport = inet->sport;
26060         r->id.idiag_dport = inet->dport;
26061 -       r->id.idiag_src[0] = inet->rcv_saddr;
26062 -       r->id.idiag_dst[0] = inet->daddr;
26063 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26064 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26065  
26066  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26067         if (r->idiag_family == AF_INET6) {
26068 @@ -208,8 +210,8 @@ static int inet_twsk_diag_fill(struct in
26069         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26070         r->id.idiag_sport     = tw->tw_sport;
26071         r->id.idiag_dport     = tw->tw_dport;
26072 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26073 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26074 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26075 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26076         r->idiag_state        = tw->tw_substate;
26077         r->idiag_timer        = 3;
26078         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26079 @@ -266,6 +268,7 @@ static int inet_diag_get_exact(struct sk
26080         err = -EINVAL;
26081  
26082         if (req->idiag_family == AF_INET) {
26083 +               /* TODO: lback */
26084                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26085                                  req->id.idiag_dport, req->id.idiag_src[0],
26086                                  req->id.idiag_sport, req->id.idiag_if);
26087 @@ -508,6 +511,7 @@ static int inet_csk_diag_dump(struct soc
26088                 } else
26089  #endif
26090                 {
26091 +                       /* TODO: lback */
26092                         entry.saddr = &inet->rcv_saddr;
26093                         entry.daddr = &inet->daddr;
26094                 }
26095 @@ -544,6 +548,7 @@ static int inet_twsk_diag_dump(struct in
26096                 } else
26097  #endif
26098                 {
26099 +                       /* TODO: lback */
26100                         entry.saddr = &tw->tw_rcv_saddr;
26101                         entry.daddr = &tw->tw_daddr;
26102                 }
26103 @@ -590,8 +595,8 @@ static int inet_diag_fill_req(struct sk_
26104  
26105         r->id.idiag_sport = inet->sport;
26106         r->id.idiag_dport = ireq->rmt_port;
26107 -       r->id.idiag_src[0] = ireq->loc_addr;
26108 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26109 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26110 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26111         r->idiag_expires = jiffies_to_msecs(tmo);
26112         r->idiag_rqueue = 0;
26113         r->idiag_wqueue = 0;
26114 @@ -661,6 +666,7 @@ static int inet_diag_dump_reqs(struct sk
26115                                 continue;
26116  
26117                         if (bc) {
26118 +                               /* TODO: lback */
26119                                 entry.saddr =
26120  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26121                                         (entry.family == AF_INET6) ?
26122 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26123                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
26124                                 struct inet_sock *inet = inet_sk(sk);
26125  
26126 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26127 +                                       continue;
26128                                 if (num < s_num) {
26129                                         num++;
26130                                         continue;
26131 @@ -790,6 +798,8 @@ skip_listen_ht:
26132                 sk_for_each(sk, node, &head->chain) {
26133                         struct inet_sock *inet = inet_sk(sk);
26134  
26135 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26136 +                               continue;
26137                         if (num < s_num)
26138                                 goto next_normal;
26139                         if (!(r->idiag_states & (1 << sk->sk_state)))
26140 @@ -814,6 +824,8 @@ next_normal:
26141                         inet_twsk_for_each(tw, node,
26142                                     &head->twchain) {
26143  
26144 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26145 +                                       continue;
26146                                 if (num < s_num)
26147                                         goto next_dying;
26148                                 if (r->id.idiag_sport != tw->tw_sport &&
26149 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/inet_hashtables.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/inet_hashtables.c
26150 --- linux-2.6.27.3/net/ipv4/inet_hashtables.c   2008-10-13 14:52:09.000000000 +0200
26151 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/inet_hashtables.c      2008-10-13 14:54:20.000000000 +0200
26152 @@ -21,6 +21,7 @@
26153  
26154  #include <net/inet_connection_sock.h>
26155  #include <net/inet_hashtables.h>
26156 +#include <net/route.h>
26157  #include <net/ip.h>
26158  
26159  /*
26160 @@ -163,11 +164,10 @@ static struct sock *inet_lookup_listener
26161                         const __be32 rcv_saddr = inet->rcv_saddr;
26162                         int score = sk->sk_family == PF_INET ? 1 : 0;
26163  
26164 -                       if (rcv_saddr) {
26165 -                               if (rcv_saddr != daddr)
26166 -                                       continue;
26167 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
26168                                 score += 2;
26169 -                       }
26170 +                       else
26171 +                               continue;
26172                         if (sk->sk_bound_dev_if) {
26173                                 if (sk->sk_bound_dev_if != dif)
26174                                         continue;
26175 @@ -199,7 +199,7 @@ struct sock *__inet_lookup_listener(stru
26176                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
26177  
26178                 if (inet->num == hnum && !sk->sk_node.next &&
26179 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
26180 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
26181                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
26182                     !sk->sk_bound_dev_if && net_eq(sock_net(sk), net))
26183                         goto sherry_cache;
26184 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/netfilter/nf_nat_helper.c
26185 --- linux-2.6.27.3/net/ipv4/netfilter/nf_nat_helper.c   2008-07-13 23:51:29.000000000 +0200
26186 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/netfilter/nf_nat_helper.c      2008-10-13 14:54:20.000000000 +0200
26187 @@ -18,6 +18,7 @@
26188  #include <net/tcp.h>
26189  
26190  #include <linux/netfilter_ipv4.h>
26191 +#include <net/route.h>
26192  #include <net/netfilter/nf_conntrack.h>
26193  #include <net/netfilter/nf_conntrack_helper.h>
26194  #include <net/netfilter/nf_conntrack_ecache.h>
26195 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/netfilter.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/netfilter.c
26196 --- linux-2.6.27.3/net/ipv4/netfilter.c 2008-07-13 23:51:29.000000000 +0200
26197 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/netfilter.c    2008-10-13 14:54:20.000000000 +0200
26198 @@ -4,7 +4,7 @@
26199  #include <linux/netfilter_ipv4.h>
26200  #include <linux/ip.h>
26201  #include <linux/skbuff.h>
26202 -#include <net/route.h>
26203 +// #include <net/route.h>
26204  #include <net/xfrm.h>
26205  #include <net/ip.h>
26206  #include <net/netfilter/nf_queue.h>
26207 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/raw.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/raw.c
26208 --- linux-2.6.27.3/net/ipv4/raw.c       2008-10-13 14:52:09.000000000 +0200
26209 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/raw.c  2008-10-13 14:54:20.000000000 +0200
26210 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26211  
26212                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
26213                     !(inet->daddr && inet->daddr != raddr)              &&
26214 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
26215 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26216                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26217                         goto found; /* gotcha */
26218         }
26219 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
26220                 icmp_out_count(net, ((struct icmphdr *)
26221                         skb_transport_header(skb))->type);
26222  
26223 +       err = -EPERM;
26224 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26225 +               sk->sk_nx_info &&
26226 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26227 +               goto error_free;
26228 +
26229         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26230                       dst_output);
26231         if (err > 0)
26232 @@ -383,6 +389,7 @@ out:
26233  
26234  error_fault:
26235         err = -EFAULT;
26236 +error_free:
26237         kfree_skb(skb);
26238  error:
26239         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
26240 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
26241                 }
26242  
26243                 security_sk_classify_flow(sk, &fl);
26244 +               if (sk->sk_nx_info) {
26245 +                       err = ip_v4_find_src(sock_net(sk),
26246 +                               sk->sk_nx_info, &rt, &fl);
26247 +
26248 +                       if (err)
26249 +                               goto done;
26250 +               }
26251                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
26252         }
26253         if (err)
26254 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
26255  {
26256         struct inet_sock *inet = inet_sk(sk);
26257         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26258 +       struct nx_v4_sock_addr nsa = { 0 };
26259         int ret = -EINVAL;
26260         int chk_addr_ret;
26261  
26262         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26263                 goto out;
26264 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26265 +       v4_map_sock_addr(inet, addr, &nsa);
26266 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26267         ret = -EADDRNOTAVAIL;
26268 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26269 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26270             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26271                 goto out;
26272 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26273 +       v4_set_sock_addr(inet, &nsa);
26274         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26275                 inet->saddr = 0;  /* Use device */
26276         sk_dst_reset(sk);
26277 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
26278         /* Copy the address. */
26279         if (sin) {
26280                 sin->sin_family = AF_INET;
26281 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26282 +               sin->sin_addr.s_addr =
26283 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26284                 sin->sin_port = 0;
26285                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26286         }
26287 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
26288                 struct hlist_node *node;
26289  
26290                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26291 -                       if (sock_net(sk) == seq_file_net(seq))
26292 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26293 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26294                                 goto found;
26295         }
26296         sk = NULL;
26297 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
26298                 sk = sk_next(sk);
26299  try_again:
26300                 ;
26301 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26302 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26303 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26304  
26305         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26306                 sk = sk_head(&state->h->ht[state->bucket]);
26307 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
26308  
26309         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26310                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26311 -               i, src, srcp, dest, destp, sp->sk_state,
26312 +               i,
26313 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26314 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26315 +               sp->sk_state,
26316                 atomic_read(&sp->sk_wmem_alloc),
26317                 atomic_read(&sp->sk_rmem_alloc),
26318                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26319 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/syncookies.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/syncookies.c
26320 --- linux-2.6.27.3/net/ipv4/syncookies.c        2008-10-13 14:52:09.000000000 +0200
26321 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/syncookies.c   2008-10-13 14:54:20.000000000 +0200
26322 @@ -16,6 +16,7 @@
26323  #include <linux/cryptohash.h>
26324  #include <linux/kernel.h>
26325  #include <net/tcp.h>
26326 +#include <net/route.h>
26327  
26328  /* Timestamps: lowest 9 bits store TCP options */
26329  #define TSBITS 9
26330 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/tcp.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/tcp.c
26331 --- linux-2.6.27.3/net/ipv4/tcp.c       2008-10-13 14:52:09.000000000 +0200
26332 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/tcp.c  2008-10-13 14:54:20.000000000 +0200
26333 @@ -264,6 +264,7 @@
26334  #include <linux/cache.h>
26335  #include <linux/err.h>
26336  #include <linux/crypto.h>
26337 +#include <linux/in.h>
26338  
26339  #include <net/icmp.h>
26340  #include <net/tcp.h>
26341 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/tcp_ipv4.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/tcp_ipv4.c
26342 --- linux-2.6.27.3/net/ipv4/tcp_ipv4.c  2008-10-13 14:52:09.000000000 +0200
26343 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/tcp_ipv4.c     2008-10-13 14:54:20.000000000 +0200
26344 @@ -1886,6 +1886,12 @@ static void *listening_get_next(struct s
26345                 req = req->dl_next;
26346                 while (1) {
26347                         while (req) {
26348 +                               vxdprintk(VXD_CBIT(net, 6),
26349 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
26350 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
26351 +                               if (req->sk &&
26352 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
26353 +                                       continue;
26354                                 if (req->rsk_ops->family == st->family) {
26355                                         cur = req;
26356                                         goto out;
26357 @@ -1910,6 +1916,10 @@ get_req:
26358         }
26359  get_sk:
26360         sk_for_each_from(sk, node) {
26361 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
26362 +                       sk, sk->sk_nid, nx_current_nid());
26363 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26364 +                       continue;
26365                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
26366                         cur = sk;
26367                         goto out;
26368 @@ -1960,6 +1970,11 @@ static void *established_get_first(struc
26369  
26370                 read_lock_bh(lock);
26371                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
26372 +                       vxdprintk(VXD_CBIT(net, 6),
26373 +                               "sk,egf: %p [#%d] (from %d)",
26374 +                               sk, sk->sk_nid, nx_current_nid());
26375 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26376 +                               continue;
26377                         if (sk->sk_family != st->family ||
26378                             !net_eq(sock_net(sk), net)) {
26379                                 continue;
26380 @@ -1970,6 +1985,11 @@ static void *established_get_first(struc
26381                 st->state = TCP_SEQ_STATE_TIME_WAIT;
26382                 inet_twsk_for_each(tw, node,
26383                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
26384 +                       vxdprintk(VXD_CBIT(net, 6),
26385 +                               "tw: %p [#%d] (from %d)",
26386 +                               tw, tw->tw_nid, nx_current_nid());
26387 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26388 +                               continue;
26389                         if (tw->tw_family != st->family ||
26390                             !net_eq(twsk_net(tw), net)) {
26391                                 continue;
26392 @@ -1998,7 +2018,9 @@ static void *established_get_next(struct
26393                 tw = cur;
26394                 tw = tw_next(tw);
26395  get_tw:
26396 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
26397 +               while (tw && (tw->tw_family != st->family ||
26398 +                       !net_eq(twsk_net(tw), net) ||
26399 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
26400                         tw = tw_next(tw);
26401                 }
26402                 if (tw) {
26403 @@ -2019,6 +2041,11 @@ get_tw:
26404                 sk = sk_next(sk);
26405  
26406         sk_for_each_from(sk, node) {
26407 +               vxdprintk(VXD_CBIT(net, 6),
26408 +                       "sk,egn: %p [#%d] (from %d)",
26409 +                       sk, sk->sk_nid, nx_current_nid());
26410 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26411 +                       continue;
26412                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
26413                         goto found;
26414         }
26415 @@ -2173,9 +2200,9 @@ static void get_openreq4(struct sock *sk
26416         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26417                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
26418                 i,
26419 -               ireq->loc_addr,
26420 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
26421                 ntohs(inet_sk(sk)->sport),
26422 -               ireq->rmt_addr,
26423 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
26424                 ntohs(ireq->rmt_port),
26425                 TCP_SYN_RECV,
26426                 0, 0, /* could print option size, but that is af dependent. */
26427 @@ -2218,7 +2245,10 @@ static void get_tcp4_sock(struct sock *s
26428  
26429         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
26430                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
26431 -               i, src, srcp, dest, destp, sk->sk_state,
26432 +               i,
26433 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26434 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26435 +               sk->sk_state,
26436                 tp->write_seq - tp->snd_una,
26437                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
26438                                              (tp->rcv_nxt - tp->copied_seq),
26439 @@ -2254,7 +2284,10 @@ static void get_timewait4_sock(struct in
26440  
26441         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26442                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
26443 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
26444 +               i,
26445 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26446 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26447 +               tw->tw_substate, 0, 0,
26448                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
26449                 atomic_read(&tw->tw_refcnt), tw, len);
26450  }
26451 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/tcp_minisocks.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/tcp_minisocks.c
26452 --- linux-2.6.27.3/net/ipv4/tcp_minisocks.c     2008-10-13 14:52:09.000000000 +0200
26453 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/tcp_minisocks.c        2008-10-13 14:54:20.000000000 +0200
26454 @@ -26,6 +26,10 @@
26455  #include <net/inet_common.h>
26456  #include <net/xfrm.h>
26457  
26458 +#include <linux/vs_limit.h>
26459 +#include <linux/vs_socket.h>
26460 +#include <linux/vs_context.h>
26461 +
26462  #ifdef CONFIG_SYSCTL
26463  #define SYNC_INIT 0 /* let the user enable it */
26464  #else
26465 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
26466                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26467                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26468  
26469 +               tw->tw_xid              = sk->sk_xid;
26470 +               tw->tw_vx_info          = NULL;
26471 +               tw->tw_nid              = sk->sk_nid;
26472 +               tw->tw_nx_info          = NULL;
26473 +
26474  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26475                 if (tw->tw_family == PF_INET6) {
26476                         struct ipv6_pinfo *np = inet6_sk(sk);
26477 diff -NurpP --minimal linux-2.6.27.3/net/ipv4/udp.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/udp.c
26478 --- linux-2.6.27.3/net/ipv4/udp.c       2008-10-13 14:52:09.000000000 +0200
26479 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv4/udp.c  2008-10-13 14:54:20.000000000 +0200
26480 @@ -234,20 +234,14 @@ fail:
26481         return error;
26482  }
26483  
26484 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26485 -{
26486 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26487 -
26488 -       return  ( !ipv6_only_sock(sk2)  &&
26489 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
26490 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
26491 -}
26492 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
26493  
26494  int udp_v4_get_port(struct sock *sk, unsigned short snum)
26495  {
26496         return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal);
26497  }
26498  
26499 +
26500  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
26501   * harder than this. -DaveM
26502   */
26503 @@ -267,10 +261,16 @@ static struct sock *__udp4_lib_lookup(st
26504                 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
26505                                 !ipv6_only_sock(sk)) {
26506                         int score = (sk->sk_family == PF_INET ? 1 : 0);
26507 +
26508                         if (inet->rcv_saddr) {
26509                                 if (inet->rcv_saddr != daddr)
26510                                         continue;
26511                                 score+=2;
26512 +                       } else {
26513 +                               /* block non nx_info ips */
26514 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
26515 +                                       daddr, NXA_MASK_BIND))
26516 +                                       continue;
26517                         }
26518                         if (inet->daddr) {
26519                                 if (inet->daddr != saddr)
26520 @@ -296,6 +296,7 @@ static struct sock *__udp4_lib_lookup(st
26521                         }
26522                 }
26523         }
26524 +
26525         if (result)
26526                 sock_hold(result);
26527         read_unlock(&udp_hash_lock);
26528 @@ -317,7 +318,7 @@ static inline struct sock *udp_v4_mcast_
26529                 if (s->sk_hash != hnum                                  ||
26530                     (inet->daddr && inet->daddr != rmt_addr)            ||
26531                     (inet->dport != rmt_port && inet->dport)            ||
26532 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
26533 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
26534                     ipv6_only_sock(s)                                   ||
26535                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
26536                         continue;
26537 @@ -654,8 +655,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
26538                                                { .sport = inet->sport,
26539                                                  .dport = dport } } };
26540                 struct net *net = sock_net(sk);
26541 +               struct nx_info *nxi = sk->sk_nx_info;
26542  
26543                 security_sk_classify_flow(sk, &fl);
26544 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
26545 +               if (err)
26546 +                       goto out;
26547 +
26548                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
26549                 if (err) {
26550                         if (err == -ENETUNREACH)
26551 @@ -900,7 +906,8 @@ try_again:
26552         {
26553                 sin->sin_family = AF_INET;
26554                 sin->sin_port = udp_hdr(skb)->source;
26555 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26556 +               sin->sin_addr.s_addr = nx_map_sock_lback(
26557 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
26558                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
26559         }
26560         if (inet->cmsg_flags)
26561 @@ -1528,6 +1535,8 @@ static struct sock *udp_get_first(struct
26562                 sk_for_each(sk, node, state->hashtable + state->bucket) {
26563                         if (!net_eq(sock_net(sk), net))
26564                                 continue;
26565 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26566 +                               continue;
26567                         if (sk->sk_family == state->family)
26568                                 goto found;
26569                 }
26570 @@ -1546,7 +1555,9 @@ static struct sock *udp_get_next(struct 
26571                 sk = sk_next(sk);
26572  try_again:
26573                 ;
26574 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
26575 +       } while (sk && (!net_eq(sock_net(sk), net) ||
26576 +               sk->sk_family != state->family ||
26577 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26578  
26579         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
26580                 sk = sk_head(state->hashtable + state->bucket);
26581 @@ -1647,7 +1658,10 @@ static void udp4_format_sock(struct sock
26582  
26583         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
26584                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
26585 -               bucket, src, srcp, dest, destp, sp->sk_state,
26586 +               bucket,
26587 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26588 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26589 +               sp->sk_state,
26590                 atomic_read(&sp->sk_wmem_alloc),
26591                 atomic_read(&sp->sk_rmem_alloc),
26592                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26593 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/addrconf.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/addrconf.c
26594 --- linux-2.6.27.3/net/ipv6/addrconf.c  2008-10-13 14:52:09.000000000 +0200
26595 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/addrconf.c     2008-10-13 14:54:20.000000000 +0200
26596 @@ -85,6 +85,8 @@
26597  
26598  #include <linux/proc_fs.h>
26599  #include <linux/seq_file.h>
26600 +#include <linux/vs_network.h>
26601 +#include <linux/vs_inet6.h>
26602  
26603  /* Set to 3 to get tracing... */
26604  #define ACONF_DEBUG 2
26605 @@ -1108,7 +1110,7 @@ out:
26606  
26607  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
26608                        const struct in6_addr *daddr, unsigned int prefs,
26609 -                      struct in6_addr *saddr)
26610 +                      struct in6_addr *saddr, struct nx_info *nxi)
26611  {
26612         struct ipv6_saddr_score scores[2],
26613                                 *score = &scores[0], *hiscore = &scores[1];
26614 @@ -1364,35 +1366,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
26615         return ifp;
26616  }
26617  
26618 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
26619 +
26620  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26621  {
26622         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26623         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26624 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
26625         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26626         int sk_ipv6only = ipv6_only_sock(sk);
26627         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26628         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
26629         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26630  
26631 -       if (!sk2_rcv_saddr && !sk_ipv6only)
26632 +       /* FIXME: needs handling for v4 ANY */
26633 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
26634                 return 1;
26635  
26636         if (addr_type2 == IPV6_ADDR_ANY &&
26637 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26638 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
26639 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
26640                 return 1;
26641  
26642         if (addr_type == IPV6_ADDR_ANY &&
26643 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26644 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
26645 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
26646 +               return 1;
26647 +
26648 +       if (addr_type == IPV6_ADDR_ANY &&
26649 +           addr_type2 == IPV6_ADDR_ANY &&
26650 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
26651                 return 1;
26652  
26653         if (sk2_rcv_saddr6 &&
26654 +           addr_type != IPV6_ADDR_ANY &&
26655 +           addr_type != IPV6_ADDR_ANY &&
26656             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26657                 return 1;
26658  
26659         if (addr_type == IPV6_ADDR_MAPPED &&
26660             !sk2_ipv6only &&
26661 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
26662 +           ipv4_rcv_saddr_equal(sk, sk2))
26663                 return 1;
26664  
26665         return 0;
26666 @@ -2986,7 +2999,10 @@ static void if6_seq_stop(struct seq_file
26667  static int if6_seq_show(struct seq_file *seq, void *v)
26668  {
26669         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
26670 -       seq_printf(seq,
26671 +
26672 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
26673 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
26674 +               seq_printf(seq,
26675                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
26676                    NIP6(ifp->addr),
26677                    ifp->idev->dev->ifindex,
26678 @@ -3481,6 +3497,12 @@ static int inet6_dump_addr(struct sk_buf
26679         struct ifmcaddr6 *ifmca;
26680         struct ifacaddr6 *ifaca;
26681         struct net *net = sock_net(skb->sk);
26682 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26683 +
26684 +       /* disable ipv6 on non v6 guests */
26685 +       if (nxi && !nx_info_has_v6(nxi))
26686 +               return skb->len;
26687 +
26688  
26689         s_idx = cb->args[0];
26690         s_ip_idx = ip_idx = cb->args[1];
26691 @@ -3502,6 +3524,8 @@ static int inet6_dump_addr(struct sk_buf
26692                              ifa = ifa->if_next, ip_idx++) {
26693                                 if (ip_idx < s_ip_idx)
26694                                         continue;
26695 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
26696 +                                       continue;
26697                                 err = inet6_fill_ifaddr(skb, ifa,
26698                                                         NETLINK_CB(cb->skb).pid,
26699                                                         cb->nlh->nlmsg_seq,
26700 @@ -3515,6 +3539,8 @@ static int inet6_dump_addr(struct sk_buf
26701                              ifmca = ifmca->next, ip_idx++) {
26702                                 if (ip_idx < s_ip_idx)
26703                                         continue;
26704 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
26705 +                                       continue;
26706                                 err = inet6_fill_ifmcaddr(skb, ifmca,
26707                                                           NETLINK_CB(cb->skb).pid,
26708                                                           cb->nlh->nlmsg_seq,
26709 @@ -3528,6 +3554,8 @@ static int inet6_dump_addr(struct sk_buf
26710                              ifaca = ifaca->aca_next, ip_idx++) {
26711                                 if (ip_idx < s_ip_idx)
26712                                         continue;
26713 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
26714 +                                       continue;
26715                                 err = inet6_fill_ifacaddr(skb, ifaca,
26716                                                           NETLINK_CB(cb->skb).pid,
26717                                                           cb->nlh->nlmsg_seq,
26718 @@ -3813,12 +3841,19 @@ static int inet6_dump_ifinfo(struct sk_b
26719         int s_idx = cb->args[0];
26720         struct net_device *dev;
26721         struct inet6_dev *idev;
26722 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26723 +
26724 +       /* FIXME: maybe disable ipv6 on non v6 guests?
26725 +       if (skb->sk && skb->sk->sk_vx_info)
26726 +               return skb->len; */
26727  
26728         read_lock(&dev_base_lock);
26729         idx = 0;
26730         for_each_netdev(net, dev) {
26731                 if (idx < s_idx)
26732                         goto cont;
26733 +               if (!v6_dev_in_nx_info(dev, nxi))
26734 +                       goto cont;
26735                 if ((idev = in6_dev_get(dev)) == NULL)
26736                         goto cont;
26737                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
26738 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/af_inet6.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/af_inet6.c
26739 --- linux-2.6.27.3/net/ipv6/af_inet6.c  2008-10-13 14:52:09.000000000 +0200
26740 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/af_inet6.c     2008-10-13 14:54:20.000000000 +0200
26741 @@ -41,6 +41,8 @@
26742  #include <linux/netdevice.h>
26743  #include <linux/icmpv6.h>
26744  #include <linux/netfilter_ipv6.h>
26745 +#include <linux/vs_inet.h>
26746 +#include <linux/vs_inet6.h>
26747  
26748  #include <net/ip.h>
26749  #include <net/ipv6.h>
26750 @@ -49,6 +51,7 @@
26751  #include <net/tcp.h>
26752  #include <net/ipip.h>
26753  #include <net/protocol.h>
26754 +#include <net/route.h>
26755  #include <net/inet_common.h>
26756  #include <net/transp_v6.h>
26757  #include <net/ip6_route.h>
26758 @@ -141,9 +144,12 @@ lookup_protocol:
26759         }
26760  
26761         err = -EPERM;
26762 +       if ((protocol == IPPROTO_ICMPV6) &&
26763 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26764 +               goto override;
26765         if (answer->capability > 0 && !capable(answer->capability))
26766                 goto out_rcu_unlock;
26767 -
26768 +override:
26769         sock->ops = answer->ops;
26770         answer_prot = answer->prot;
26771         answer_no_check = answer->no_check;
26772 @@ -242,6 +248,7 @@ int inet6_bind(struct socket *sock, stru
26773         struct inet_sock *inet = inet_sk(sk);
26774         struct ipv6_pinfo *np = inet6_sk(sk);
26775         struct net *net = sock_net(sk);
26776 +       struct nx_v6_sock_addr nsa;
26777         __be32 v4addr = 0;
26778         unsigned short snum;
26779         int addr_type = 0;
26780 @@ -253,6 +260,11 @@ int inet6_bind(struct socket *sock, stru
26781  
26782         if (addr_len < SIN6_LEN_RFC2133)
26783                 return -EINVAL;
26784 +
26785 +       err = v6_map_sock_addr(inet, addr, &nsa);
26786 +       if (err)
26787 +               return err;
26788 +
26789         addr_type = ipv6_addr_type(&addr->sin6_addr);
26790         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
26791                 return -EINVAL;
26792 @@ -276,6 +288,10 @@ int inet6_bind(struct socket *sock, stru
26793                         err = -EADDRNOTAVAIL;
26794                         goto out;
26795                 }
26796 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
26797 +                       err = -EADDRNOTAVAIL;
26798 +                       goto out;
26799 +               }
26800         } else {
26801                 if (addr_type != IPV6_ADDR_ANY) {
26802                         struct net_device *dev = NULL;
26803 @@ -301,6 +317,11 @@ int inet6_bind(struct socket *sock, stru
26804                                 }
26805                         }
26806  
26807 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26808 +                               err = -EADDRNOTAVAIL;
26809 +                               goto out;
26810 +                       }
26811 +
26812                         /* ipv4 addr of the socket is invalid.  Only the
26813                          * unspecified and mapped address have a v4 equivalent.
26814                          */
26815 @@ -319,6 +340,8 @@ int inet6_bind(struct socket *sock, stru
26816                 }
26817         }
26818  
26819 +       v6_set_sock_addr(inet, &nsa);
26820 +
26821         inet->rcv_saddr = v4addr;
26822         inet->saddr = v4addr;
26823  
26824 @@ -411,9 +434,11 @@ int inet6_getname(struct socket *sock, s
26825                         return -ENOTCONN;
26826                 sin->sin6_port = inet->dport;
26827                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
26828 +               /* FIXME: remap lback? */
26829                 if (np->sndflow)
26830                         sin->sin6_flowinfo = np->flow_label;
26831         } else {
26832 +               /* FIXME: remap lback? */
26833                 if (ipv6_addr_any(&np->rcv_saddr))
26834                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
26835                 else
26836 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/fib6_rules.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/fib6_rules.c
26837 --- linux-2.6.27.3/net/ipv6/fib6_rules.c        2008-10-13 14:52:09.000000000 +0200
26838 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/fib6_rules.c   2008-10-13 14:54:20.000000000 +0200
26839 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
26840                         if (ipv6_dev_get_saddr(net,
26841                                                ip6_dst_idev(&rt->u.dst)->dev,
26842                                                &flp->fl6_dst, srcprefs,
26843 -                                              &saddr))
26844 +                                              &saddr, NULL))
26845                                 goto again;
26846                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
26847                                                r->src.plen))
26848 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/inet6_hashtables.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/inet6_hashtables.c
26849 --- linux-2.6.27.3/net/ipv6/inet6_hashtables.c  2008-10-13 14:52:09.000000000 +0200
26850 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/inet6_hashtables.c     2008-10-13 14:54:20.000000000 +0200
26851 @@ -16,6 +16,7 @@
26852  
26853  #include <linux/module.h>
26854  #include <linux/random.h>
26855 +#include <linux/vs_inet6.h>
26856  
26857  #include <net/inet_connection_sock.h>
26858  #include <net/inet_hashtables.h>
26859 @@ -115,6 +116,9 @@ struct sock *inet6_lookup_listener(struc
26860                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26861                                         continue;
26862                                 score++;
26863 +                       } else {
26864 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26865 +                                       continue;
26866                         }
26867                         if (sk->sk_bound_dev_if) {
26868                                 if (sk->sk_bound_dev_if != dif)
26869 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/ip6_output.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/ip6_output.c
26870 --- linux-2.6.27.3/net/ipv6/ip6_output.c        2008-10-13 14:52:09.000000000 +0200
26871 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/ip6_output.c   2008-10-13 14:54:20.000000000 +0200
26872 @@ -937,7 +937,7 @@ static int ip6_dst_lookup_tail(struct so
26873                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
26874                                          &fl->fl6_dst,
26875                                          sk ? inet6_sk(sk)->srcprefs : 0,
26876 -                                        &fl->fl6_src);
26877 +                                        &fl->fl6_src, sk->sk_nx_info);
26878                 if (err)
26879                         goto out_err_release;
26880         }
26881 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/Kconfig linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/Kconfig
26882 --- linux-2.6.27.3/net/ipv6/Kconfig     2008-10-13 14:52:09.000000000 +0200
26883 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/Kconfig        2008-10-13 14:54:20.000000000 +0200
26884 @@ -4,8 +4,8 @@
26885  
26886  #   IPv6 as module will cause a CRASH if you try to unload it
26887  menuconfig IPV6
26888 -       tristate "The IPv6 protocol"
26889 -       default m
26890 +       bool "The IPv6 protocol"
26891 +       default n
26892         ---help---
26893           This is complemental support for the IP version 6.
26894           You will still be able to do traditional IPv4 networking as well.
26895 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/ndisc.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/ndisc.c
26896 --- linux-2.6.27.3/net/ipv6/ndisc.c     2008-10-13 14:52:09.000000000 +0200
26897 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/ndisc.c        2008-10-13 14:54:20.000000000 +0200
26898 @@ -551,7 +551,7 @@ static void ndisc_send_na(struct net_dev
26899         } else {
26900                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
26901                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
26902 -                                      &tmpaddr))
26903 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
26904                         return;
26905                 src_addr = &tmpaddr;
26906         }
26907 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/route.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/route.c
26908 --- linux-2.6.27.3/net/ipv6/route.c     2008-10-13 14:52:09.000000000 +0200
26909 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/route.c        2008-10-13 14:54:20.000000000 +0200
26910 @@ -2191,7 +2191,8 @@ static int rt6_fill_node(struct net *net
26911                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
26912                 struct in6_addr saddr_buf;
26913                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
26914 -                                      dst, 0, &saddr_buf) == 0)
26915 +                       dst, 0, &saddr_buf,
26916 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
26917                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
26918         }
26919  
26920 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/tcp_ipv6.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/tcp_ipv6.c
26921 --- linux-2.6.27.3/net/ipv6/tcp_ipv6.c  2008-10-13 14:52:09.000000000 +0200
26922 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/tcp_ipv6.c     2008-10-13 14:54:20.000000000 +0200
26923 @@ -67,6 +67,7 @@
26924  
26925  #include <linux/crypto.h>
26926  #include <linux/scatterlist.h>
26927 +#include <linux/vs_inet6.h>
26928  
26929  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26930  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26931 @@ -155,8 +156,15 @@ static int tcp_v6_connect(struct sock *s
26932          *      connect() to INADDR_ANY means loopback (BSD'ism).
26933          */
26934  
26935 -       if(ipv6_addr_any(&usin->sin6_addr))
26936 -               usin->sin6_addr.s6_addr[15] = 0x1;
26937 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26938 +               struct nx_info *nxi =  sk->sk_nx_info;
26939 +
26940 +               if (nxi && nx_info_has_v6(nxi))
26941 +                       /* FIXME: remap lback? */
26942 +                       usin->sin6_addr = nxi->v6.ip;
26943 +               else
26944 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26945 +       }
26946  
26947         addr_type = ipv6_addr_type(&usin->sin6_addr);
26948  
26949 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/udp.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/udp.c
26950 --- linux-2.6.27.3/net/ipv6/udp.c       2008-10-13 14:52:09.000000000 +0200
26951 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/udp.c  2008-10-13 14:54:20.000000000 +0200
26952 @@ -47,6 +47,7 @@
26953  
26954  #include <linux/proc_fs.h>
26955  #include <linux/seq_file.h>
26956 +#include <linux/vs_inet6.h>
26957  #include "udp_impl.h"
26958  
26959  int udp_v6_get_port(struct sock *sk, unsigned short snum)
26960 @@ -81,6 +82,10 @@ static struct sock *__udp6_lib_lookup(st
26961                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26962                                         continue;
26963                                 score++;
26964 +                       } else {
26965 +                               /* block non nx_info ips */
26966 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26967 +                                       continue;
26968                         }
26969                         if (!ipv6_addr_any(&np->daddr)) {
26970                                 if (!ipv6_addr_equal(&np->daddr, saddr))
26971 diff -NurpP --minimal linux-2.6.27.3/net/ipv6/xfrm6_policy.c linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/xfrm6_policy.c
26972 --- linux-2.6.27.3/net/ipv6/xfrm6_policy.c      2008-10-13 14:52:09.000000000 +0200
26973 +++ linux-2.6.27.3-vs2.3.0.35.7/net/ipv6/xfrm6_policy.c 2008-10-13 14:54:20.000000000 +0200
26974 @@ -61,7 +61,7 @@ static int xfrm6_get_saddr(xfrm_address_
26975         dev = ip6_dst_idev(dst)->dev;
26976         ipv6_dev_get_saddr(dev_net(dev), dev,
26977                            (struct in6_addr *)&daddr->a6, 0,
26978 -                          (struct in6_addr *)&saddr->a6);
26979 +                          (struct in6_addr *)&saddr->a6, NULL);
26980         dst_release(dst);
26981         return 0;
26982  }
26983 diff -NurpP --minimal linux-2.6.27.3/net/netlink/af_netlink.c linux-2.6.27.3-vs2.3.0.35.7/net/netlink/af_netlink.c
26984 --- linux-2.6.27.3/net/netlink/af_netlink.c     2008-10-13 14:52:09.000000000 +0200
26985 +++ linux-2.6.27.3-vs2.3.0.35.7/net/netlink/af_netlink.c        2008-10-13 14:54:20.000000000 +0200
26986 @@ -55,6 +55,9 @@
26987  #include <linux/types.h>
26988  #include <linux/audit.h>
26989  #include <linux/mutex.h>
26990 +#include <linux/vs_context.h>
26991 +#include <linux/vs_network.h>
26992 +#include <linux/vs_limit.h>
26993  
26994  #include <net/net_namespace.h>
26995  #include <net/sock.h>
26996 @@ -1761,6 +1764,8 @@ static struct sock *netlink_seq_socket_i
26997                         sk_for_each(s, node, &hash->table[j]) {
26998                                 if (sock_net(s) != seq_file_net(seq))
26999                                         continue;
27000 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27001 +                                       continue;
27002                                 if (off == pos) {
27003                                         iter->link = i;
27004                                         iter->hash_idx = j;
27005 @@ -1795,7 +1800,8 @@ static void *netlink_seq_next(struct seq
27006         s = v;
27007         do {
27008                 s = sk_next(s);
27009 -       } while (s && sock_net(s) != seq_file_net(seq));
27010 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27011 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27012         if (s)
27013                 return s;
27014  
27015 @@ -1807,7 +1813,8 @@ static void *netlink_seq_next(struct seq
27016  
27017                 for (; j <= hash->mask; j++) {
27018                         s = sk_head(&hash->table[j]);
27019 -                       while (s && sock_net(s) != seq_file_net(seq))
27020 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27021 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27022                                 s = sk_next(s);
27023                         if (s) {
27024                                 iter->link = i;
27025 diff -NurpP --minimal linux-2.6.27.3/net/sctp/ipv6.c linux-2.6.27.3-vs2.3.0.35.7/net/sctp/ipv6.c
27026 --- linux-2.6.27.3/net/sctp/ipv6.c      2008-10-13 14:52:09.000000000 +0200
27027 +++ linux-2.6.27.3-vs2.3.0.35.7/net/sctp/ipv6.c 2008-10-13 14:54:20.000000000 +0200
27028 @@ -323,7 +323,8 @@ static void sctp_v6_get_saddr(struct sct
27029                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27030                                    &daddr->v6.sin6_addr,
27031                                    inet6_sk(&sk->inet.sk)->srcprefs,
27032 -                                  &saddr->v6.sin6_addr);
27033 +                                  &saddr->v6.sin6_addr,
27034 +                                  asoc->base.sk->sk_nx_info);
27035                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
27036                                   NIP6(saddr->v6.sin6_addr));
27037                 return;
27038 diff -NurpP --minimal linux-2.6.27.3/net/socket.c linux-2.6.27.3-vs2.3.0.35.7/net/socket.c
27039 --- linux-2.6.27.3/net/socket.c 2008-10-13 14:52:09.000000000 +0200
27040 +++ linux-2.6.27.3-vs2.3.0.35.7/net/socket.c    2008-10-13 14:54:20.000000000 +0200
27041 @@ -96,6 +96,10 @@
27042  
27043  #include <net/sock.h>
27044  #include <linux/netfilter.h>
27045 +#include <linux/vs_base.h>
27046 +#include <linux/vs_socket.h>
27047 +#include <linux/vs_inet.h>
27048 +#include <linux/vs_inet6.h>
27049  
27050  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27051  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27052 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
27053                                  struct msghdr *msg, size_t size)
27054  {
27055         struct sock_iocb *si = kiocb_to_siocb(iocb);
27056 -       int err;
27057 +       int err, len;
27058  
27059         si->sock = sock;
27060         si->scm = NULL;
27061 @@ -561,7 +565,22 @@ static inline int __sock_sendmsg(struct 
27062         if (err)
27063                 return err;
27064  
27065 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27066 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27067 +       if (sock->sk) {
27068 +               if (len == size)
27069 +                       vx_sock_send(sock->sk, size);
27070 +               else
27071 +                       vx_sock_fail(sock->sk, size);
27072 +       }
27073 +       vxdprintk(VXD_CBIT(net, 7),
27074 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27075 +               sock, sock->sk,
27076 +               (sock->sk)?sock->sk->sk_nx_info:0,
27077 +               (sock->sk)?sock->sk->sk_vx_info:0,
27078 +               (sock->sk)?sock->sk->sk_xid:0,
27079 +               (sock->sk)?sock->sk->sk_nid:0,
27080 +               (unsigned int)size, len);
27081 +       return len;
27082  }
27083  
27084  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27085 @@ -630,7 +649,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27086  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27087                                  struct msghdr *msg, size_t size, int flags)
27088  {
27089 -       int err;
27090 +       int err, len;
27091         struct sock_iocb *si = kiocb_to_siocb(iocb);
27092  
27093         si->sock = sock;
27094 @@ -643,7 +662,18 @@ static inline int __sock_recvmsg(struct 
27095         if (err)
27096                 return err;
27097  
27098 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27099 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27100 +       if ((len >= 0) && sock->sk)
27101 +               vx_sock_recv(sock->sk, len);
27102 +       vxdprintk(VXD_CBIT(net, 7),
27103 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27104 +               sock, sock->sk,
27105 +               (sock->sk)?sock->sk->sk_nx_info:0,
27106 +               (sock->sk)?sock->sk->sk_vx_info:0,
27107 +               (sock->sk)?sock->sk->sk_xid:0,
27108 +               (sock->sk)?sock->sk->sk_nid:0,
27109 +               (unsigned int)size, len);
27110 +       return len;
27111  }
27112  
27113  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27114 @@ -1108,6 +1138,13 @@ static int __sock_create(struct net *net
27115         if (type < 0 || type >= SOCK_MAX)
27116                 return -EINVAL;
27117  
27118 +       if (!nx_check(0, VS_ADMIN)) {
27119 +               if (family == PF_INET && !current_nx_info_has_v4())
27120 +                       return -EAFNOSUPPORT;
27121 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27122 +                       return -EAFNOSUPPORT;
27123 +       }
27124 +
27125         /* Compatibility.
27126  
27127            This uglymoron is moved from INET layer to here to avoid
27128 @@ -1240,6 +1277,7 @@ asmlinkage long sys_socket(int family, i
27129         if (retval < 0)
27130                 goto out;
27131  
27132 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27133         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27134         if (retval < 0)
27135                 goto out_release;
27136 @@ -1281,10 +1319,12 @@ asmlinkage long sys_socketpair(int famil
27137         err = sock_create(family, type, protocol, &sock1);
27138         if (err < 0)
27139                 goto out;
27140 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27141  
27142         err = sock_create(family, type, protocol, &sock2);
27143         if (err < 0)
27144                 goto out_release_1;
27145 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27146  
27147         err = sock1->ops->socketpair(sock1, sock2);
27148         if (err < 0)
27149 diff -NurpP --minimal linux-2.6.27.3/net/sunrpc/auth.c linux-2.6.27.3-vs2.3.0.35.7/net/sunrpc/auth.c
27150 --- linux-2.6.27.3/net/sunrpc/auth.c    2008-07-13 23:51:29.000000000 +0200
27151 +++ linux-2.6.27.3-vs2.3.0.35.7/net/sunrpc/auth.c       2008-10-13 14:54:20.000000000 +0200
27152 @@ -14,6 +14,7 @@
27153  #include <linux/hash.h>
27154  #include <linux/sunrpc/clnt.h>
27155  #include <linux/spinlock.h>
27156 +#include <linux/vs_tag.h>
27157  
27158  #ifdef RPC_DEBUG
27159  # define RPCDBG_FACILITY       RPCDBG_AUTH
27160 @@ -353,6 +354,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27161         struct auth_cred acred = {
27162                 .uid = current->fsuid,
27163                 .gid = current->fsgid,
27164 +               .tag = dx_current_tag(),
27165                 .group_info = current->group_info,
27166         };
27167         struct rpc_cred *ret;
27168 @@ -398,6 +400,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27169         struct auth_cred acred = {
27170                 .uid = 0,
27171                 .gid = 0,
27172 +               .tag = dx_current_tag(),
27173         };
27174         struct rpc_cred *ret;
27175  
27176 diff -NurpP --minimal linux-2.6.27.3/net/sunrpc/auth_unix.c linux-2.6.27.3-vs2.3.0.35.7/net/sunrpc/auth_unix.c
27177 --- linux-2.6.27.3/net/sunrpc/auth_unix.c       2008-10-13 14:52:09.000000000 +0200
27178 +++ linux-2.6.27.3-vs2.3.0.35.7/net/sunrpc/auth_unix.c  2008-10-13 14:54:20.000000000 +0200
27179 @@ -11,12 +11,14 @@
27180  #include <linux/module.h>
27181  #include <linux/sunrpc/clnt.h>
27182  #include <linux/sunrpc/auth.h>
27183 +#include <linux/vs_tag.h>
27184  
27185  #define NFS_NGROUPS    16
27186  
27187  struct unx_cred {
27188         struct rpc_cred         uc_base;
27189         gid_t                   uc_gid;
27190 +       tag_t                   uc_tag;
27191         gid_t                   uc_gids[NFS_NGROUPS];
27192  };
27193  #define uc_uid                 uc_base.cr_uid
27194 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27195                 groups = NFS_NGROUPS;
27196  
27197         cred->uc_gid = acred->gid;
27198 +       cred->uc_tag = acred->tag;
27199         for (i = 0; i < groups; i++)
27200                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27201         if (i < NFS_NGROUPS)
27202 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27203         unsigned int i;
27204  
27205  
27206 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27207 +       if (cred->uc_uid != acred->uid ||
27208 +               cred->uc_gid != acred->gid ||
27209 +               cred->uc_tag != acred->tag)
27210                 return 0;
27211  
27212         if (acred->group_info != NULL)
27213 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27214         struct rpc_clnt *clnt = task->tk_client;
27215         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
27216         __be32          *base, *hold;
27217 -       int             i;
27218 +       int             i, tag;
27219  
27220         *p++ = htonl(RPC_AUTH_UNIX);
27221         base = p++;
27222 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27223          * Copy the UTS nodename captured when the client was created.
27224          */
27225         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27226 +       tag = task->tk_client->cl_tag;
27227  
27228 -       *p++ = htonl((u32) cred->uc_uid);
27229 -       *p++ = htonl((u32) cred->uc_gid);
27230 +       *p++ = htonl((u32) TAGINO_UID(tag,
27231 +               cred->uc_uid, cred->uc_tag));
27232 +       *p++ = htonl((u32) TAGINO_GID(tag,
27233 +               cred->uc_gid, cred->uc_tag));
27234         hold = p++;
27235         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27236                 *p++ = htonl((u32) cred->uc_gids[i]);
27237 diff -NurpP --minimal linux-2.6.27.3/net/sunrpc/clnt.c linux-2.6.27.3-vs2.3.0.35.7/net/sunrpc/clnt.c
27238 --- linux-2.6.27.3/net/sunrpc/clnt.c    2008-10-13 14:52:09.000000000 +0200
27239 +++ linux-2.6.27.3-vs2.3.0.35.7/net/sunrpc/clnt.c       2008-10-13 14:54:20.000000000 +0200
27240 @@ -32,6 +32,7 @@
27241  #include <linux/utsname.h>
27242  #include <linux/workqueue.h>
27243  #include <linux/in6.h>
27244 +#include <linux/vs_cvirt.h>
27245  
27246  #include <linux/sunrpc/clnt.h>
27247  #include <linux/sunrpc/rpc_pipe_fs.h>
27248 @@ -327,6 +328,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27249         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27250                 clnt->cl_chatty = 1;
27251  
27252 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27253 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27254 +               clnt->cl_tag = 1; */
27255         return clnt;
27256  }
27257  EXPORT_SYMBOL_GPL(rpc_create);
27258 diff -NurpP --minimal linux-2.6.27.3/net/unix/af_unix.c linux-2.6.27.3-vs2.3.0.35.7/net/unix/af_unix.c
27259 --- linux-2.6.27.3/net/unix/af_unix.c   2008-10-13 14:52:10.000000000 +0200
27260 +++ linux-2.6.27.3-vs2.3.0.35.7/net/unix/af_unix.c      2008-10-13 14:54:20.000000000 +0200
27261 @@ -114,6 +114,8 @@
27262  #include <linux/mount.h>
27263  #include <net/checksum.h>
27264  #include <linux/security.h>
27265 +#include <linux/vs_context.h>
27266 +#include <linux/vs_limit.h>
27267  
27268  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27269  static DEFINE_SPINLOCK(unix_table_lock);
27270 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27271                 if (!net_eq(sock_net(s), net))
27272                         continue;
27273  
27274 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27275 +                       continue;
27276                 if (u->addr->len == len &&
27277                     !memcmp(u->addr->name, sunname, len))
27278                         goto found;
27279 @@ -2084,6 +2088,8 @@ static struct sock *unix_seq_idx(struct 
27280         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
27281                 if (sock_net(s) != seq_file_net(seq))
27282                         continue;
27283 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27284 +                       continue;
27285                 if (off == pos)
27286                         return s;
27287                 ++off;
27288 @@ -2109,7 +2115,8 @@ static void *unix_seq_next(struct seq_fi
27289                 sk = first_unix_socket(&iter->i);
27290         else
27291                 sk = next_unix_socket(&iter->i, sk);
27292 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
27293 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
27294 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
27295                 sk = next_unix_socket(&iter->i, sk);
27296         return sk;
27297  }
27298 diff -NurpP --minimal linux-2.6.27.3/net/x25/af_x25.c linux-2.6.27.3-vs2.3.0.35.7/net/x25/af_x25.c
27299 --- linux-2.6.27.3/net/x25/af_x25.c     2008-10-13 14:52:10.000000000 +0200
27300 +++ linux-2.6.27.3-vs2.3.0.35.7/net/x25/af_x25.c        2008-10-13 14:54:20.000000000 +0200
27301 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
27302  
27303         x25 = x25_sk(sk);
27304  
27305 -       sock_init_data(sock, sk);
27306 +       sk->sk_socket = sock;
27307 +       sk->sk_type = sock->type;
27308 +       sk->sk_sleep = &sock->wait;
27309 +       sock->sk = sk;
27310  
27311         x25_init_timers(sk);
27312  
27313 diff -NurpP --minimal linux-2.6.27.3/scripts/checksyscalls.sh linux-2.6.27.3-vs2.3.0.35.7/scripts/checksyscalls.sh
27314 --- linux-2.6.27.3/scripts/checksyscalls.sh     2008-07-13 23:51:29.000000000 +0200
27315 +++ linux-2.6.27.3-vs2.3.0.35.7/scripts/checksyscalls.sh        2008-10-13 14:54:20.000000000 +0200
27316 @@ -108,7 +108,6 @@ cat << EOF
27317  #define __IGNORE_afs_syscall
27318  #define __IGNORE_getpmsg
27319  #define __IGNORE_putpmsg
27320 -#define __IGNORE_vserver
27321  EOF
27322  }
27323  
27324 diff -NurpP --minimal linux-2.6.27.3/security/commoncap.c linux-2.6.27.3-vs2.3.0.35.7/security/commoncap.c
27325 --- linux-2.6.27.3/security/commoncap.c 2008-10-13 14:52:10.000000000 +0200
27326 +++ linux-2.6.27.3-vs2.3.0.35.7/security/commoncap.c    2008-10-13 14:54:20.000000000 +0200
27327 @@ -26,10 +26,11 @@
27328  #include <linux/sched.h>
27329  #include <linux/prctl.h>
27330  #include <linux/securebits.h>
27331 +#include <linux/vs_context.h>
27332  
27333  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27334  {
27335 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
27336 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
27337         return 0;
27338  }
27339  
27340 @@ -50,9 +51,24 @@ EXPORT_SYMBOL(cap_netlink_recv);
27341   */
27342  int cap_capable (struct task_struct *tsk, int cap)
27343  {
27344 +       struct vx_info *vxi = tsk->vx_info;
27345 +
27346 +#if 0
27347 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
27348 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
27349 +               cap_raised(tsk->cap_effective, cap),
27350 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
27351 +#endif
27352 +
27353 +       /* special case SETUP */
27354 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
27355 +               cap_raised(tsk->cap_effective, cap))
27356 +               return 0;
27357 +
27358         /* Derived from include/linux/sched.h:capable. */
27359 -       if (cap_raised(tsk->cap_effective, cap))
27360 +       if (vx_cap_raised(vxi, tsk->cap_effective, cap))
27361                 return 0;
27362 +
27363         return -EPERM;
27364  }
27365  
27366 @@ -696,7 +712,8 @@ void cap_task_reparent_to_init (struct t
27367  
27368  int cap_syslog (int type)
27369  {
27370 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
27371 +       if ((type != 3 && type != 10) &&
27372 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27373                 return -EPERM;
27374         return 0;
27375  }
27376 diff -NurpP --minimal linux-2.6.27.3/security/selinux/hooks.c linux-2.6.27.3-vs2.3.0.35.7/security/selinux/hooks.c
27377 --- linux-2.6.27.3/security/selinux/hooks.c     2008-10-13 14:52:10.000000000 +0200
27378 +++ linux-2.6.27.3-vs2.3.0.35.7/security/selinux/hooks.c        2008-10-13 14:54:20.000000000 +0200
27379 @@ -64,7 +64,6 @@
27380  #include <linux/dccp.h>
27381  #include <linux/quota.h>
27382  #include <linux/un.h>          /* for Unix socket types */
27383 -#include <net/af_unix.h>       /* for Unix socket types */
27384  #include <linux/parser.h>
27385  #include <linux/nfs_mount.h>
27386  #include <net/ipv6.h>
This page took 2.111342 seconds and 3 git commands to generate.