]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.3.patch
- rel.3 - rebuild with fixed vserver patch
[packages/kernel.git] / linux-2.6-vs2.3.patch
1 diff -NurpP --minimal linux-2.6.27.10/arch/alpha/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/Kconfig
2 --- linux-2.6.27.10/arch/alpha/Kconfig  2008-10-13 14:51:51.000000000 +0200
3 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/Kconfig     2008-10-13 14:54:20.000000000 +0200
4 @@ -667,6 +667,8 @@ config DUMMY_CONSOLE
5         depends on VGA_HOSE
6         default y
7  
8 +source "kernel/vserver/Kconfig"
9 +
10  source "security/Kconfig"
11  
12  source "crypto/Kconfig"
13 diff -NurpP --minimal linux-2.6.27.10/arch/alpha/kernel/entry.S linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/entry.S
14 --- linux-2.6.27.10/arch/alpha/kernel/entry.S   2008-07-13 23:51:29.000000000 +0200
15 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/alpha/kernel/osf_sys.c linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-10-13 14:51:51.000000000 +0200
50 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/osf_sys.c    2008-10-13 14:54:20.000000000 +0200
51 @@ -888,7 +888,7 @@ osf_gettimeofday(struct timeval32 __user
52  {
53         if (tv) {
54                 struct timeval ktv;
55 -               do_gettimeofday(&ktv);
56 +               vx_gettimeofday(&ktv);
57                 if (put_tv32(tv, &ktv))
58                         return -EFAULT;
59         }
60 diff -NurpP --minimal linux-2.6.27.10/arch/alpha/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.27.10/arch/alpha/kernel/ptrace.c  2008-07-13 23:51:29.000000000 +0200
62 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/ptrace.c     2008-10-13 14:54:20.000000000 +0200
63 @@ -15,6 +15,7 @@
64  #include <linux/slab.h>
65  #include <linux/security.h>
66  #include <linux/signal.h>
67 +#include <linux/vs_base.h>
68  
69  #include <asm/uaccess.h>
70  #include <asm/pgtable.h>
71 diff -NurpP --minimal linux-2.6.27.10/arch/alpha/kernel/systbls.S linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/systbls.S
72 --- linux-2.6.27.10/arch/alpha/kernel/systbls.S 2008-07-13 23:51:29.000000000 +0200
73 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/alpha/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/traps.c
84 --- linux-2.6.27.10/arch/alpha/kernel/traps.c   2008-07-13 23:51:29.000000000 +0200
85 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/kernel/traps.c      2008-10-13 14:54:20.000000000 +0200
86 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
87  #ifdef CONFIG_SMP
88         printk("CPU %d ", hard_smp_processor_id());
89  #endif
90 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
91 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
92 +               task_pid_nr(current), current->xid, str, err);
93         dik_show_regs(regs, r9_15);
94         add_taint(TAINT_DIE);
95         dik_show_trace((unsigned long *)(regs+1));
96 diff -NurpP --minimal linux-2.6.27.10/arch/alpha/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/mm/fault.c
97 --- linux-2.6.27.10/arch/alpha/mm/fault.c       2008-07-13 23:51:29.000000000 +0200
98 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/alpha/mm/fault.c  2008-10-13 14:54:20.000000000 +0200
99 @@ -193,8 +193,8 @@ do_page_fault(unsigned long address, uns
100                 down_read(&mm->mmap_sem);
101                 goto survive;
102         }
103 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
104 -              current->comm, task_pid_nr(current));
105 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
106 +              current->comm, task_pid_nr(current), current->xid);
107         if (!user_mode(regs))
108                 goto no_context;
109         do_group_exit(SIGKILL);
110 diff -NurpP --minimal linux-2.6.27.10/arch/arm/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/arm/Kconfig
111 --- linux-2.6.27.10/arch/arm/Kconfig    2008-10-13 14:51:51.000000000 +0200
112 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/arm/Kconfig       2008-10-13 14:54:20.000000000 +0200
113 @@ -1240,6 +1240,8 @@ source "fs/Kconfig"
114  
115  source "arch/arm/Kconfig.debug"
116  
117 +source "kernel/vserver/Kconfig"
118 +
119  source "security/Kconfig"
120  
121  source "crypto/Kconfig"
122 diff -NurpP --minimal linux-2.6.27.10/arch/arm/kernel/calls.S linux-2.6.27.10-vs2.3.0.36.4/arch/arm/kernel/calls.S
123 --- linux-2.6.27.10/arch/arm/kernel/calls.S     2008-10-13 14:51:52.000000000 +0200
124 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/arm/kernel/process.c linux-2.6.27.10-vs2.3.0.36.4/arch/arm/kernel/process.c
135 --- linux-2.6.27.10/arch/arm/kernel/process.c   2008-10-13 14:51:52.000000000 +0200
136 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/arm/kernel/process.c      2008-10-13 14:54:20.000000000 +0200
137 @@ -262,7 +262,8 @@ void __show_regs(struct pt_regs *regs)
138  void show_regs(struct pt_regs * regs)
139  {
140         printk("\n");
141 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
142 +       printk("Pid: %d[#%u], comm: %20s\n",
143 +               task_pid_nr(current), current->xid, current->comm);
144         __show_regs(regs);
145         __backtrace();
146  }
147 diff -NurpP --minimal linux-2.6.27.10/arch/arm/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/arm/kernel/traps.c
148 --- linux-2.6.27.10/arch/arm/kernel/traps.c     2008-10-13 14:51:52.000000000 +0200
149 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/arm/kernel/traps.c        2008-10-13 14:54:20.000000000 +0200
150 @@ -214,8 +214,8 @@ static void __die(const char *str, int e
151                str, err, ++die_counter);
152         print_modules();
153         __show_regs(regs);
154 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
155 -               tsk->comm, task_pid_nr(tsk), thread + 1);
156 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
157 +               tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
158  
159         if (!user_mode(regs) || in_interrupt()) {
160                 dump_mem("Stack: ", regs->ARM_sp,
161 diff -NurpP --minimal linux-2.6.27.10/arch/arm/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/arm/mm/fault.c
162 --- linux-2.6.27.10/arch/arm/mm/fault.c 2008-07-13 23:51:29.000000000 +0200
163 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/arm/mm/fault.c    2008-10-13 14:54:20.000000000 +0200
164 @@ -292,7 +292,8 @@ do_page_fault(unsigned long addr, unsign
165                  * happened to us that made us unable to handle
166                  * the page fault gracefully.
167                  */
168 -               printk("VM: killing process %s\n", tsk->comm);
169 +               printk("VM: killing process %s(%d:#%u)\n",
170 +                       tsk->comm, task_pid_nr(tsk), tsk->xid);
171                 do_group_exit(SIGKILL);
172                 return 0;
173         }
174 diff -NurpP --minimal linux-2.6.27.10/arch/cris/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/cris/Kconfig
175 --- linux-2.6.27.10/arch/cris/Kconfig   2008-07-13 23:51:29.000000000 +0200
176 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/cris/Kconfig      2008-10-13 14:54:20.000000000 +0200
177 @@ -679,6 +679,8 @@ source "drivers/usb/Kconfig"
178  
179  source "arch/cris/Kconfig.debug"
180  
181 +source "kernel/vserver/Kconfig"
182 +
183  source "security/Kconfig"
184  
185  source "crypto/Kconfig"
186 diff -NurpP --minimal linux-2.6.27.10/arch/frv/kernel/kernel_thread.S linux-2.6.27.10-vs2.3.0.36.4/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.27.10/arch/frv/kernel/kernel_thread.S     2008-07-13 23:51:29.000000000 +0200
188 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/frv/kernel/kernel_thread.S        2008-10-13 14:54:20.000000000 +0200
189 @@ -37,7 +37,7 @@ kernel_thread:
190  
191         # start by forking the current process, but with shared VM
192         setlos.p        #__NR_clone,gr7         ; syscall number
193 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
194 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
195         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
196         setlo           #0xe4e4,gr9
197         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
198 diff -NurpP --minimal linux-2.6.27.10/arch/h8300/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/h8300/Kconfig
199 --- linux-2.6.27.10/arch/h8300/Kconfig  2008-10-13 14:51:55.000000000 +0200
200 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/h8300/Kconfig     2008-10-13 14:54:20.000000000 +0200
201 @@ -219,6 +219,8 @@ source "fs/Kconfig"
202  
203  source "arch/h8300/Kconfig.debug"
204  
205 +source "kernel/vserver/Kconfig"
206 +
207  source "security/Kconfig"
208  
209  source "crypto/Kconfig"
210 diff -NurpP --minimal linux-2.6.27.10/arch/ia64/ia32/ia32_entry.S linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.27.10/arch/ia64/ia32/ia32_entry.S 2008-10-13 14:51:55.000000000 +0200
212 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/ia64/ia32/sys_ia32.c linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/ia32/sys_ia32.c
223 --- linux-2.6.27.10/arch/ia64/ia32/sys_ia32.c   2008-10-13 14:51:55.000000000 +0200
224 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/ia32/sys_ia32.c      2008-10-13 14:54:20.000000000 +0200
225 @@ -1178,7 +1178,7 @@ sys32_gettimeofday (struct compat_timeva
226  {
227         if (tv) {
228                 struct timeval ktv;
229 -               do_gettimeofday(&ktv);
230 +               vx_gettimeofday(&ktv);
231                 if (put_tv32(tv, &ktv))
232                         return -EFAULT;
233         }
234 diff -NurpP --minimal linux-2.6.27.10/arch/ia64/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/Kconfig
235 --- linux-2.6.27.10/arch/ia64/Kconfig   2008-10-13 14:51:55.000000000 +0200
236 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/ia64/kernel/entry.S linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/entry.S
247 --- linux-2.6.27.10/arch/ia64/kernel/entry.S    2008-10-13 14:51:55.000000000 +0200
248 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/ia64/kernel/perfmon.c linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/perfmon.c
259 --- linux-2.6.27.10/arch/ia64/kernel/perfmon.c  2008-10-13 14:51:55.000000000 +0200
260 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/perfmon.c     2008-10-13 14:54:20.000000000 +0200
261 @@ -40,6 +40,7 @@
262  #include <linux/capability.h>
263  #include <linux/rcupdate.h>
264  #include <linux/completion.h>
265 +#include <linux/vs_memory.h>
266  
267  #include <asm/errno.h>
268  #include <asm/intrinsics.h>
269 @@ -2376,7 +2377,7 @@ pfm_smpl_buffer_alloc(struct task_struct
270          */
271         insert_vm_struct(mm, vma);
272  
273 -       mm->total_vm  += size >> PAGE_SHIFT;
274 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
275         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
276                                                         vma_pages(vma));
277         up_write(&task->mm->mmap_sem);
278 diff -NurpP --minimal linux-2.6.27.10/arch/ia64/kernel/process.c linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/process.c
279 --- linux-2.6.27.10/arch/ia64/kernel/process.c  2008-10-13 14:51:55.000000000 +0200
280 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/process.c     2008-10-13 14:54:20.000000000 +0200
281 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
282         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
283  
284         print_modules();
285 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
286 -                       smp_processor_id(), current->comm);
287 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
288 +                       current->xid, smp_processor_id(), current->comm);
289         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
290                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
291                init_utsname()->release);
292 diff -NurpP --minimal linux-2.6.27.10/arch/ia64/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/ptrace.c
293 --- linux-2.6.27.10/arch/ia64/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
294 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
295 @@ -22,6 +22,7 @@
296  #include <linux/signal.h>
297  #include <linux/regset.h>
298  #include <linux/elf.h>
299 +#include <linux/vs_base.h>
300  
301  #include <asm/pgtable.h>
302  #include <asm/processor.h>
303 diff -NurpP --minimal linux-2.6.27.10/arch/ia64/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/traps.c
304 --- linux-2.6.27.10/arch/ia64/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
305 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
306 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
307         put_cpu();
308  
309         if (++die.lock_owner_depth < 3) {
310 -               printk("%s[%d]: %s %ld [%d]\n",
311 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
312 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
313 +                       current->comm, task_pid_nr(current), current->xid,
314 +                       str, err, ++die_counter);
315                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
316                     != NOTIFY_STOP)
317                         show_regs(regs);
318 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
319                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
320                                 last.time = current_jiffies + 5 * HZ;
321                                 printk(KERN_WARNING
322 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
323 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
324 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
325 +                                       current->comm, task_pid_nr(current), current->xid,
326 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
327                         }
328                 }
329         }
330 diff -NurpP --minimal linux-2.6.27.10/arch/ia64/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/mm/fault.c
331 --- linux-2.6.27.10/arch/ia64/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
332 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/ia64/mm/fault.c   2008-10-13 14:54:20.000000000 +0200
333 @@ -10,6 +10,7 @@
334  #include <linux/interrupt.h>
335  #include <linux/kprobes.h>
336  #include <linux/kdebug.h>
337 +#include <linux/vs_memory.h>
338  
339  #include <asm/pgtable.h>
340  #include <asm/processor.h>
341 diff -NurpP --minimal linux-2.6.27.10/arch/m32r/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/m32r/kernel/traps.c
342 --- linux-2.6.27.10/arch/m32r/kernel/traps.c    2008-10-13 14:51:55.000000000 +0200
343 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/m32r/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
344 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
345         } else {
346                 printk("SPI: %08lx\n", sp);
347         }
348 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
349 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
350 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
351 +               current->comm, task_pid_nr(current), current->xid,
352 +               0xffff & i, 4096+(unsigned long)current);
353  
354         /*
355          * When in-kernel, we also print out the stack and code at the
356 diff -NurpP --minimal linux-2.6.27.10/arch/m68k/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/m68k/Kconfig
357 --- linux-2.6.27.10/arch/m68k/Kconfig   2008-10-13 14:51:55.000000000 +0200
358 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/m68k/Kconfig      2008-10-13 14:54:20.000000000 +0200
359 @@ -633,6 +633,8 @@ source "fs/Kconfig"
360  
361  source "arch/m68k/Kconfig.debug"
362  
363 +source "kernel/vserver/Kconfig"
364 +
365  source "security/Kconfig"
366  
367  source "crypto/Kconfig"
368 diff -NurpP --minimal linux-2.6.27.10/arch/m68k/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/m68k/kernel/ptrace.c
369 --- linux-2.6.27.10/arch/m68k/kernel/ptrace.c   2008-07-13 23:51:29.000000000 +0200
370 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/m68k/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
371 @@ -18,6 +18,7 @@
372  #include <linux/ptrace.h>
373  #include <linux/user.h>
374  #include <linux/signal.h>
375 +#include <linux/vs_base.h>
376  
377  #include <asm/uaccess.h>
378  #include <asm/page.h>
379 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
380                 ret = ptrace_request(child, request, addr, data);
381                 break;
382         }
383 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
384 +               goto out_tsk;
385  
386         return ret;
387  out_eio:
388 diff -NurpP --minimal linux-2.6.27.10/arch/m68k/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/m68k/kernel/traps.c
389 --- linux-2.6.27.10/arch/m68k/kernel/traps.c    2008-07-13 23:51:29.000000000 +0200
390 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/m68k/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
391 @@ -909,8 +909,8 @@ void show_registers(struct pt_regs *regs
392         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
393                regs->d4, regs->d5, regs->a0, regs->a1);
394  
395 -       printk("Process %s (pid: %d, task=%p)\n",
396 -               current->comm, task_pid_nr(current), current);
397 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
398 +               current->comm, task_pid_nr(current), current->xid, current);
399         addr = (unsigned long)&fp->un;
400         printk("Frame format=%X ", regs->format);
401         switch (regs->format) {
402 diff -NurpP --minimal linux-2.6.27.10/arch/m68knommu/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/m68knommu/Kconfig
403 --- linux-2.6.27.10/arch/m68knommu/Kconfig      2008-10-13 14:51:55.000000000 +0200
404 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/m68knommu/Kconfig 2008-10-13 14:54:20.000000000 +0200
405 @@ -740,6 +740,8 @@ source "fs/Kconfig"
406  
407  source "arch/m68knommu/Kconfig.debug"
408  
409 +source "kernel/vserver/Kconfig"
410 +
411  source "security/Kconfig"
412  
413  source "crypto/Kconfig"
414 diff -NurpP --minimal linux-2.6.27.10/arch/m68knommu/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/m68knommu/kernel/traps.c
415 --- linux-2.6.27.10/arch/m68knommu/kernel/traps.c       2008-10-13 14:51:55.000000000 +0200
416 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/m68knommu/kernel/traps.c  2008-10-13 14:54:20.000000000 +0200
417 @@ -79,8 +79,9 @@ void die_if_kernel(char *str, struct pt_
418         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
419                fp->d4, fp->d5, fp->a0, fp->a1);
420  
421 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
422 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
423 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
424 +               current->comm, task_pid_nr(current), current->xid,
425 +               PAGE_SIZE+(unsigned long)current);
426         show_stack(NULL, (unsigned long *)(fp + 1));
427         add_taint(TAINT_DIE);
428         do_exit(SIGSEGV);
429 diff -NurpP --minimal linux-2.6.27.10/arch/mips/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/mips/Kconfig
430 --- linux-2.6.27.10/arch/mips/Kconfig   2008-10-13 14:51:55.000000000 +0200
431 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/Kconfig      2008-10-13 14:54:20.000000000 +0200
432 @@ -2031,6 +2031,8 @@ source "fs/Kconfig"
433  
434  source "arch/mips/Kconfig.debug"
435  
436 +source "kernel/vserver/Kconfig"
437 +
438  source "security/Kconfig"
439  
440  source "crypto/Kconfig"
441 diff -NurpP --minimal linux-2.6.27.10/arch/mips/kernel/linux32.c linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/linux32.c
442 --- linux-2.6.27.10/arch/mips/kernel/linux32.c  2008-10-13 14:51:56.000000000 +0200
443 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/linux32.c     2008-10-13 14:54:20.000000000 +0200
444 @@ -191,7 +191,7 @@ sys32_gettimeofday(struct compat_timeval
445  {
446         if (tv) {
447                 struct timeval ktv;
448 -               do_gettimeofday(&ktv);
449 +               vx_gettimeofday(&ktv);
450                 if (put_tv32(tv, &ktv))
451                         return -EFAULT;
452         }
453 diff -NurpP --minimal linux-2.6.27.10/arch/mips/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/ptrace.c
454 --- linux-2.6.27.10/arch/mips/kernel/ptrace.c   2008-10-13 14:51:56.000000000 +0200
455 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
456 @@ -25,6 +25,7 @@
457  #include <linux/security.h>
458  #include <linux/audit.h>
459  #include <linux/seccomp.h>
460 +#include <linux/vs_base.h>
461  
462  #include <asm/byteorder.h>
463  #include <asm/cpu.h>
464 @@ -171,6 +172,9 @@ long arch_ptrace(struct task_struct *chi
465  {
466         int ret;
467  
468 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
469 +               goto out;
470 +
471         switch (request) {
472         /* when I and D space are separate, these will need to be fixed. */
473         case PTRACE_PEEKTEXT: /* read word at location addr. */
474 diff -NurpP --minimal linux-2.6.27.10/arch/mips/kernel/scall32-o32.S linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall32-o32.S
475 --- linux-2.6.27.10/arch/mips/kernel/scall32-o32.S      2008-10-13 14:51:56.000000000 +0200
476 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/mips/kernel/scall64-64.S linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall64-64.S
487 --- linux-2.6.27.10/arch/mips/kernel/scall64-64.S       2008-10-13 14:51:56.000000000 +0200
488 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall64-64.S  2008-10-13 14:54:20.000000000 +0200
489 @@ -434,7 +434,7 @@ sys_call_table:
490         PTR     sys_mq_timedreceive
491         PTR     sys_mq_notify
492         PTR     sys_mq_getsetattr               /* 5235 */
493 -       PTR     sys_ni_syscall                  /* sys_vserver */
494 +       PTR     sys_vserver
495         PTR     sys_waitid
496         PTR     sys_ni_syscall                  /* available, was setaltroot */
497         PTR     sys_add_key
498 diff -NurpP --minimal linux-2.6.27.10/arch/mips/kernel/scall64-n32.S linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall64-n32.S
499 --- linux-2.6.27.10/arch/mips/kernel/scall64-n32.S      2008-10-13 14:51:56.000000000 +0200
500 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall64-n32.S 2008-10-13 14:54:20.000000000 +0200
501 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
502         PTR     compat_sys_mq_timedreceive
503         PTR     compat_sys_mq_notify
504         PTR     compat_sys_mq_getsetattr
505 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
506 +       PTR     sys32_vserver                   /* 6240 */
507         PTR     compat_sys_waitid
508         PTR     sys_ni_syscall                  /* available, was setaltroot */
509         PTR     sys_add_key
510 diff -NurpP --minimal linux-2.6.27.10/arch/mips/kernel/scall64-o32.S linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall64-o32.S
511 --- linux-2.6.27.10/arch/mips/kernel/scall64-o32.S      2008-10-13 14:51:56.000000000 +0200
512 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/scall64-o32.S 2008-10-13 14:54:20.000000000 +0200
513 @@ -482,7 +482,7 @@ sys_call_table:
514         PTR     compat_sys_mq_timedreceive
515         PTR     compat_sys_mq_notify            /* 4275 */
516         PTR     compat_sys_mq_getsetattr
517 -       PTR     sys_ni_syscall                  /* sys_vserver */
518 +       PTR     sys32_vserver
519         PTR     sys32_waitid
520         PTR     sys_ni_syscall                  /* available, was setaltroot */
521         PTR     sys_add_key                     /* 4280 */
522 diff -NurpP --minimal linux-2.6.27.10/arch/mips/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/traps.c
523 --- linux-2.6.27.10/arch/mips/kernel/traps.c    2008-10-13 14:51:56.000000000 +0200
524 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/kernel/traps.c       2008-10-13 14:54:20.000000000 +0200
525 @@ -328,9 +328,10 @@ void show_registers(const struct pt_regs
526  
527         __show_regs(regs);
528         print_modules();
529 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
530 -              current->comm, current->pid, current_thread_info(), current,
531 -             field, current_thread_info()->tp_value);
532 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
533 +               current->comm, task_pid_nr(current), current->xid,
534 +               current_thread_info(), current,
535 +               field, current_thread_info()->tp_value);
536         if (cpu_has_userlocal) {
537                 unsigned long tls;
538  
539 diff -NurpP --minimal linux-2.6.27.10/arch/mips/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/mips/mm/fault.c
540 --- linux-2.6.27.10/arch/mips/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
541 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/mips/mm/fault.c   2008-10-13 14:54:20.000000000 +0200
542 @@ -178,7 +178,8 @@ out_of_memory:
543                 down_read(&mm->mmap_sem);
544                 goto survive;
545         }
546 -       printk("VM: killing process %s\n", tsk->comm);
547 +       printk("VM: killing process %s(%d:#%u)\n",
548 +               tsk->comm, tsk->pid, tsk->xid);
549         if (user_mode(regs))
550                 do_group_exit(SIGKILL);
551         goto no_context;
552 diff -NurpP --minimal linux-2.6.27.10/arch/parisc/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/Kconfig
553 --- linux-2.6.27.10/arch/parisc/Kconfig 2008-10-13 14:51:56.000000000 +0200
554 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/Kconfig    2008-10-13 14:54:20.000000000 +0200
555 @@ -279,6 +279,8 @@ source "fs/Kconfig"
556  
557  source "arch/parisc/Kconfig.debug"
558  
559 +source "kernel/vserver/Kconfig"
560 +
561  source "security/Kconfig"
562  
563  source "crypto/Kconfig"
564 diff -NurpP --minimal linux-2.6.27.10/arch/parisc/kernel/syscall_table.S linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/kernel/syscall_table.S
565 --- linux-2.6.27.10/arch/parisc/kernel/syscall_table.S  2008-07-13 23:51:29.000000000 +0200
566 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/kernel/syscall_table.S     2008-10-13 14:54:20.000000000 +0200
567 @@ -361,7 +361,7 @@
568         ENTRY_COMP(mbind)               /* 260 */
569         ENTRY_COMP(get_mempolicy)
570         ENTRY_COMP(set_mempolicy)
571 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
572 +       ENTRY_DIFF(vserver)
573         ENTRY_SAME(add_key)
574         ENTRY_SAME(request_key)         /* 265 */
575         ENTRY_SAME(keyctl)
576 diff -NurpP --minimal linux-2.6.27.10/arch/parisc/kernel/sys_parisc32.c linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/kernel/sys_parisc32.c
577 --- linux-2.6.27.10/arch/parisc/kernel/sys_parisc32.c   2008-07-13 23:51:29.000000000 +0200
578 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/kernel/sys_parisc32.c      2008-10-13 14:54:20.000000000 +0200
579 @@ -203,11 +203,11 @@ static inline long get_ts32(struct times
580  asmlinkage int
581  sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
582  {
583 -    extern void do_gettimeofday(struct timeval *tv);
584 +    extern void vx_gettimeofday(struct timeval *tv);
585  
586      if (tv) {
587             struct timeval ktv;
588 -           do_gettimeofday(&ktv);
589 +           vx_gettimeofday(&ktv);
590             if (put_compat_timeval(tv, &ktv))
591                     return -EFAULT;
592      }
593 diff -NurpP --minimal linux-2.6.27.10/arch/parisc/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/kernel/traps.c
594 --- linux-2.6.27.10/arch/parisc/kernel/traps.c  2008-12-19 12:03:05.000000000 +0100
595 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/kernel/traps.c     2008-12-08 04:52:50.000000000 +0100
596 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
597                 if (err == 0)
598                         return; /* STFU */
599  
600 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
601 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
602 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
603 +                       current->comm, task_pid_nr(current), current->xid,
604 +                       str, err, regs->iaoq[0]);
605  #ifdef PRINT_USER_FAULTS
606                 /* XXX for debugging only */
607                 show_regs(regs);
608 @@ -269,8 +270,8 @@ KERN_CRIT "                     ||     |
609                 pdc_console_restart();
610         
611         if (err)
612 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
613 -                       current->comm, task_pid_nr(current), str, err);
614 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
615 +                       current->comm, task_pid_nr(current), current->xid, str, err);
616  
617         /* Wot's wrong wif bein' racy? */
618         if (current->thread.flags & PARISC_KERNEL_DEATH) {
619 diff -NurpP --minimal linux-2.6.27.10/arch/parisc/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/mm/fault.c
620 --- linux-2.6.27.10/arch/parisc/mm/fault.c      2008-07-13 23:51:29.000000000 +0200
621 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/parisc/mm/fault.c 2008-10-13 14:54:20.000000000 +0200
622 @@ -210,8 +210,9 @@ bad_area:
623  
624  #ifdef PRINT_USER_FAULTS
625                 printk(KERN_DEBUG "\n");
626 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
627 -                   task_pid_nr(tsk), tsk->comm, code, address);
628 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
629 +                   "command='%s' type=%lu address=0x%08lx\n",
630 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
631                 if (vma) {
632                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
633                                         vma->vm_start, vma->vm_end);
634 @@ -261,7 +262,8 @@ no_context:
635  
636    out_of_memory:
637         up_read(&mm->mmap_sem);
638 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
639 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
640 +               current->comm, current->pid, current->xid);
641         if (user_mode(regs))
642                 do_group_exit(SIGKILL);
643         goto no_context;
644 diff -NurpP --minimal linux-2.6.27.10/arch/powerpc/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/Kconfig
645 --- linux-2.6.27.10/arch/powerpc/Kconfig        2008-10-13 14:51:56.000000000 +0200
646 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/powerpc/kernel/irq.c linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/irq.c
657 --- linux-2.6.27.10/arch/powerpc/kernel/irq.c   2008-10-13 14:51:56.000000000 +0200
658 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/irq.c      2008-10-13 14:54:20.000000000 +0200
659 @@ -53,6 +53,7 @@
660  #include <linux/bootmem.h>
661  #include <linux/pci.h>
662  #include <linux/debugfs.h>
663 +#include <linux/vs_context.h>
664  
665  #include <asm/uaccess.h>
666  #include <asm/system.h>
667 diff -NurpP --minimal linux-2.6.27.10/arch/powerpc/kernel/process.c linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/process.c
668 --- linux-2.6.27.10/arch/powerpc/kernel/process.c       2008-10-13 14:51:56.000000000 +0200
669 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/process.c  2008-10-13 14:54:20.000000000 +0200
670 @@ -513,8 +513,9 @@ void show_regs(struct pt_regs * regs)
671  #else
672                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
673  #endif
674 -       printk("TASK = %p[%d] '%s' THREAD: %p",
675 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
676 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
677 +              current, task_pid_nr(current), current->xid,
678 +              current->comm, task_thread_info(current));
679  
680  #ifdef CONFIG_SMP
681         printk(" CPU: %d", raw_smp_processor_id());
682 diff -NurpP --minimal linux-2.6.27.10/arch/powerpc/kernel/sys_ppc32.c linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/sys_ppc32.c
683 --- linux-2.6.27.10/arch/powerpc/kernel/sys_ppc32.c     2008-10-13 14:51:56.000000000 +0200
684 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/sys_ppc32.c        2008-10-13 14:54:20.000000000 +0200
685 @@ -147,7 +147,7 @@ asmlinkage long compat_sys_gettimeofday(
686  {
687         if (tv) {
688                 struct timeval ktv;
689 -               do_gettimeofday(&ktv);
690 +               vx_gettimeofday(&ktv);
691                 if (put_tv32(tv, &ktv))
692                         return -EFAULT;
693         }
694 diff -NurpP --minimal linux-2.6.27.10/arch/powerpc/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/traps.c
695 --- linux-2.6.27.10/arch/powerpc/kernel/traps.c 2008-10-13 14:51:56.000000000 +0200
696 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/traps.c    2008-10-13 14:54:20.000000000 +0200
697 @@ -941,8 +941,9 @@ void nonrecoverable_exception(struct pt_
698  
699  void trace_syscall(struct pt_regs *regs)
700  {
701 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
702 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
703 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
704 +              current, task_pid_nr(current), current->xid,
705 +              regs->nip, regs->link, regs->gpr[0],
706                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
707  }
708  
709 diff -NurpP --minimal linux-2.6.27.10/arch/powerpc/kernel/vdso.c linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/vdso.c
710 --- linux-2.6.27.10/arch/powerpc/kernel/vdso.c  2008-10-13 14:51:56.000000000 +0200
711 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/kernel/vdso.c     2008-10-13 14:54:20.000000000 +0200
712 @@ -22,6 +22,7 @@
713  #include <linux/security.h>
714  #include <linux/bootmem.h>
715  #include <linux/lmb.h>
716 +#include <linux/vs_memory.h>
717  
718  #include <asm/pgtable.h>
719  #include <asm/system.h>
720 diff -NurpP --minimal linux-2.6.27.10/arch/powerpc/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/mm/fault.c
721 --- linux-2.6.27.10/arch/powerpc/mm/fault.c     2008-10-13 14:51:56.000000000 +0200
722 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/powerpc/mm/fault.c        2008-10-13 14:54:20.000000000 +0200
723 @@ -354,7 +354,8 @@ out_of_memory:
724                 down_read(&mm->mmap_sem);
725                 goto survive;
726         }
727 -       printk("VM: killing process %s\n", current->comm);
728 +       printk("VM: killing process %s(%d:#%u)\n",
729 +               current->comm, current->pid, current->xid);
730         if (user_mode(regs))
731                 do_group_exit(SIGKILL);
732         return SIGKILL;
733 diff -NurpP --minimal linux-2.6.27.10/arch/s390/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/s390/Kconfig
734 --- linux-2.6.27.10/arch/s390/Kconfig   2008-10-13 14:51:57.000000000 +0200
735 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/s390/kernel/compat_linux.c linux-2.6.27.10-vs2.3.0.36.4/arch/s390/kernel/compat_linux.c
746 --- linux-2.6.27.10/arch/s390/kernel/compat_linux.c     2008-07-13 23:51:29.000000000 +0200
747 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/s390/kernel/compat_linux.c        2008-10-13 14:54:20.000000000 +0200
748 @@ -566,7 +566,7 @@ asmlinkage long sys32_gettimeofday(struc
749  {
750         if (tv) {
751                 struct timeval ktv;
752 -               do_gettimeofday(&ktv);
753 +               vx_gettimeofday(&ktv);
754                 if (put_tv32(tv, &ktv))
755                         return -EFAULT;
756         }
757 diff -NurpP --minimal linux-2.6.27.10/arch/s390/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/s390/kernel/ptrace.c
758 --- linux-2.6.27.10/arch/s390/kernel/ptrace.c   2008-10-13 14:51:57.000000000 +0200
759 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/s390/kernel/ptrace.c      2008-10-13 14:54:20.000000000 +0200
760 @@ -35,6 +35,7 @@
761  #include <linux/signal.h>
762  #include <linux/elf.h>
763  #include <linux/regset.h>
764 +#include <linux/vs_base.h>
765  
766  #include <asm/segment.h>
767  #include <asm/page.h>
768 diff -NurpP --minimal linux-2.6.27.10/arch/s390/kernel/syscalls.S linux-2.6.27.10-vs2.3.0.36.4/arch/s390/kernel/syscalls.S
769 --- linux-2.6.27.10/arch/s390/kernel/syscalls.S 2008-10-13 14:51:57.000000000 +0200
770 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/s390/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/s390/mm/fault.c
781 --- linux-2.6.27.10/arch/s390/mm/fault.c        2008-07-13 23:51:29.000000000 +0200
782 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/s390/mm/fault.c   2008-10-13 14:54:20.000000000 +0200
783 @@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
784                 down_read(&mm->mmap_sem);
785                 return 1;
786         }
787 -       printk("VM: killing process %s\n", tsk->comm);
788 +       printk("VM: killing process %s(%d:#%u)\n",
789 +               tsk->comm, tsk->pid, tsk->xid);
790         if (regs->psw.mask & PSW_MASK_PSTATE)
791                 do_group_exit(SIGKILL);
792         do_no_context(regs, error_code, address);
793 diff -NurpP --minimal linux-2.6.27.10/arch/sh/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/sh/Kconfig
794 --- linux-2.6.27.10/arch/sh/Kconfig     2008-10-13 14:51:57.000000000 +0200
795 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sh/Kconfig        2008-10-13 14:54:20.000000000 +0200
796 @@ -747,6 +747,8 @@ source "fs/Kconfig"
797  
798  source "arch/sh/Kconfig.debug"
799  
800 +source "kernel/vserver/Kconfig"
801 +
802  source "security/Kconfig"
803  
804  source "crypto/Kconfig"
805 diff -NurpP --minimal linux-2.6.27.10/arch/sh/kernel/irq.c linux-2.6.27.10-vs2.3.0.36.4/arch/sh/kernel/irq.c
806 --- linux-2.6.27.10/arch/sh/kernel/irq.c        2008-10-13 14:51:57.000000000 +0200
807 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sh/kernel/irq.c   2008-10-13 14:54:20.000000000 +0200
808 @@ -11,6 +11,7 @@
809  #include <linux/module.h>
810  #include <linux/kernel_stat.h>
811  #include <linux/seq_file.h>
812 +#include <linux/vs_context.h>
813  #include <asm/processor.h>
814  #include <asm/machvec.h>
815  #include <asm/uaccess.h>
816 diff -NurpP --minimal linux-2.6.27.10/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.27.10-vs2.3.0.36.4/arch/sh/kernel/vsyscall/vsyscall.c
817 --- linux-2.6.27.10/arch/sh/kernel/vsyscall/vsyscall.c  2008-07-13 23:51:29.000000000 +0200
818 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sh/kernel/vsyscall/vsyscall.c     2008-10-13 14:54:20.000000000 +0200
819 @@ -19,6 +19,7 @@
820  #include <linux/elf.h>
821  #include <linux/sched.h>
822  #include <linux/err.h>
823 +#include <linux/vs_memory.h>
824  
825  /*
826   * Should the kernel map a VDSO page into processes and pass its
827 diff -NurpP --minimal linux-2.6.27.10/arch/sparc/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/Kconfig
828 --- linux-2.6.27.10/arch/sparc/Kconfig  2008-10-13 14:51:58.000000000 +0200
829 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/Kconfig     2008-10-13 14:54:20.000000000 +0200
830 @@ -305,6 +305,8 @@ source "fs/Kconfig"
831  
832  source "arch/sparc/Kconfig.debug"
833  
834 +source "kernel/vserver/Kconfig"
835 +
836  source "security/Kconfig"
837  
838  source "crypto/Kconfig"
839 diff -NurpP --minimal linux-2.6.27.10/arch/sparc/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/kernel/ptrace.c
840 --- linux-2.6.27.10/arch/sparc/kernel/ptrace.c  2008-10-13 14:51:58.000000000 +0200
841 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/kernel/ptrace.c     2008-10-13 14:54:20.000000000 +0200
842 @@ -22,6 +22,7 @@
843  #include <linux/regset.h>
844  #include <linux/elf.h>
845  #include <linux/tracehook.h>
846 +#include <linux/vs_base.h>
847  
848  #include <asm/pgtable.h>
849  #include <asm/system.h>
850 diff -NurpP --minimal linux-2.6.27.10/arch/sparc/kernel/systbls.S linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/kernel/systbls.S
851 --- linux-2.6.27.10/arch/sparc/kernel/systbls.S 2008-10-13 14:51:58.000000000 +0200
852 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/sparc/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/kernel/traps.c
863 --- linux-2.6.27.10/arch/sparc/kernel/traps.c   2008-10-13 14:51:58.000000000 +0200
864 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/kernel/traps.c      2008-10-13 14:54:20.000000000 +0200
865 @@ -95,7 +95,8 @@ void die_if_kernel(char *str, struct pt_
866  "              /_| \\__/ |_\\\n"
867  "                 \\__U_/\n");
868  
869 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
870 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
871 +               task_pid_nr(current), current->xid, str, ++die_counter);
872         show_regs(regs);
873         add_taint(TAINT_DIE);
874  
875 diff -NurpP --minimal linux-2.6.27.10/arch/sparc/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/mm/fault.c
876 --- linux-2.6.27.10/arch/sparc/mm/fault.c       2008-10-13 14:51:58.000000000 +0200
877 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc/mm/fault.c  2008-10-13 14:54:20.000000000 +0200
878 @@ -318,7 +318,8 @@ no_context:
879   */
880  out_of_memory:
881         up_read(&mm->mmap_sem);
882 -       printk("VM: killing process %s\n", tsk->comm);
883 +       printk("VM: killing process %s(%d:#%u)\n",
884 +               tsk->comm, tsk->pid, tsk->xid);
885         if (from_user)
886                 do_group_exit(SIGKILL);
887         goto no_context;
888 diff -NurpP --minimal linux-2.6.27.10/arch/sparc64/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/Kconfig
889 --- linux-2.6.27.10/arch/sparc64/Kconfig        2008-10-13 14:51:58.000000000 +0200
890 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/Kconfig   2008-10-13 14:54:20.000000000 +0200
891 @@ -403,6 +403,8 @@ source "fs/Kconfig"
892  
893  source "arch/sparc64/Kconfig.debug"
894  
895 +source "kernel/vserver/Kconfig"
896 +
897  source "security/Kconfig"
898  
899  source "crypto/Kconfig"
900 diff -NurpP --minimal linux-2.6.27.10/arch/sparc64/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/ptrace.c
901 --- linux-2.6.27.10/arch/sparc64/kernel/ptrace.c        2008-12-19 12:03:06.000000000 +0100
902 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/ptrace.c   2008-12-19 12:09:12.000000000 +0100
903 @@ -26,6 +26,7 @@
904  #include <linux/tracehook.h>
905  #include <linux/compat.h>
906  #include <linux/elf.h>
907 +#include <linux/vs_base.h>
908  
909  #include <asm/asi.h>
910  #include <asm/pgtable.h>
911 diff -NurpP --minimal linux-2.6.27.10/arch/sparc64/kernel/sys_sparc32.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/sys_sparc32.c
912 --- linux-2.6.27.10/arch/sparc64/kernel/sys_sparc32.c   2008-10-13 14:51:58.000000000 +0200
913 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/sys_sparc32.c      2008-10-13 14:54:20.000000000 +0200
914 @@ -532,7 +532,7 @@ asmlinkage long sys32_gettimeofday(struc
915  {
916         if (tv) {
917                 struct timeval ktv;
918 -               do_gettimeofday(&ktv);
919 +               vx_gettimeofday(&ktv);
920                 if (put_tv32(tv, &ktv))
921                         return -EFAULT;
922         }
923 diff -NurpP --minimal linux-2.6.27.10/arch/sparc64/kernel/systbls.S linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/systbls.S
924 --- linux-2.6.27.10/arch/sparc64/kernel/systbls.S       2008-10-13 14:51:58.000000000 +0200
925 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/arch/sparc64/kernel/traps.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/traps.c
945 --- linux-2.6.27.10/arch/sparc64/kernel/traps.c 2008-10-13 14:51:58.000000000 +0200
946 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/kernel/traps.c    2008-10-13 14:54:20.000000000 +0200
947 @@ -2186,7 +2186,8 @@ void die_if_kernel(char *str, struct pt_
948  "              /_| \\__/ |_\\\n"
949  "                 \\__U_/\n");
950  
951 -       printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
952 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
953 +               task_pid_nr(current), current->xid, str, ++die_counter);
954         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
955         __asm__ __volatile__("flushw");
956         show_regs(regs);
957 diff -NurpP --minimal linux-2.6.27.10/arch/sparc64/mm/fault.c linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/mm/fault.c
958 --- linux-2.6.27.10/arch/sparc64/mm/fault.c     2008-10-13 14:51:58.000000000 +0200
959 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/sparc64/mm/fault.c        2008-10-13 14:54:20.000000000 +0200
960 @@ -452,7 +452,8 @@ handle_kernel_fault:
961  out_of_memory:
962         insn = get_fault_insn(regs, insn);
963         up_read(&mm->mmap_sem);
964 -       printk("VM: killing process %s\n", current->comm);
965 +       printk("VM: killing process %s(%d:#%u)\n",
966 +               current->comm, current->pid, current->xid);
967         if (!(regs->tstate & TSTATE_PRIV))
968                 do_group_exit(SIGKILL);
969         goto handle_kernel_fault;
970 diff -NurpP --minimal linux-2.6.27.10/arch/um/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/um/Kconfig
971 --- linux-2.6.27.10/arch/um/Kconfig     2008-07-13 23:51:29.000000000 +0200
972 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/um/Kconfig        2008-10-13 14:54:20.000000000 +0200
973 @@ -245,6 +245,8 @@ source "drivers/connector/Kconfig"
974  
975  source "fs/Kconfig"
976  
977 +source "kernel/vserver/Kconfig"
978 +
979  source "security/Kconfig"
980  
981  source "crypto/Kconfig"
982 diff -NurpP --minimal linux-2.6.27.10/arch/um/kernel/trap.c linux-2.6.27.10-vs2.3.0.36.4/arch/um/kernel/trap.c
983 --- linux-2.6.27.10/arch/um/kernel/trap.c       2008-07-13 23:51:29.000000000 +0200
984 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/um/kernel/trap.c  2008-10-13 14:54:20.000000000 +0200
985 @@ -215,7 +215,8 @@ unsigned long segv(struct faultinfo fi, 
986                 current->thread.arch.faultinfo = fi;
987                 force_sig_info(SIGBUS, &si, current);
988         } else if (err == -ENOMEM) {
989 -               printk(KERN_INFO "VM: killing process %s\n", current->comm);
990 +               printk(KERN_INFO "VM: killing process %s(%d:#%u)\n",
991 +                       current->comm, task_pid_nr(current), current->xid);
992                 do_exit(SIGKILL);
993         } else {
994                 BUG_ON(err != -EFAULT);
995 diff -NurpP --minimal linux-2.6.27.10/arch/x86/ia32/ia32entry.S linux-2.6.27.10-vs2.3.0.36.4/arch/x86/ia32/ia32entry.S
996 --- linux-2.6.27.10/arch/x86/ia32/ia32entry.S   2008-10-13 14:51:58.000000000 +0200
997 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/x86/ia32/ia32entry.S      2008-10-13 14:54:20.000000000 +0200
998 @@ -772,7 +772,7 @@ ia32_sys_call_table:
999         .quad sys_tgkill                /* 270 */
1000         .quad compat_sys_utimes
1001         .quad sys32_fadvise64_64
1002 -       .quad quiet_ni_syscall  /* sys_vserver */
1003 +       .quad sys32_vserver
1004         .quad sys_mbind
1005         .quad compat_sys_get_mempolicy  /* 275 */
1006         .quad sys_set_mempolicy
1007 diff -NurpP --minimal linux-2.6.27.10/arch/x86/Kconfig linux-2.6.27.10-vs2.3.0.36.4/arch/x86/Kconfig
1008 --- linux-2.6.27.10/arch/x86/Kconfig    2008-12-19 12:03:06.000000000 +0100
1009 +++ linux-2.6.27.10-vs2.3.0.36.4/arch/x86/Kconfig       2008-11-17 18:20:40.000000000 +0100
1010 @@ -1808,6 +1808,8 @@ source "fs/Kconfig"
1011  
1012  source "arch/x86/Kconfig.debug"
1013  
1014 +source "kernel/vserver/Kconfig"
1015 +
1016  source "security/Kconfig"
1017  
1018  source "crypto/Kconfig"
1019 diff -NurpP --minimal linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S linux-2.6.27.10-vs2.3.0.36.4/arch/x86/kernel/syscall_table_32.S
1020 --- linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S  2008-10-13 14:51:58.000000000 +0200
1021 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/Documentation/vserver/debug.txt linux-2.6.27.10-vs2.3.0.36.4/Documentation/vserver/debug.txt
1032 --- linux-2.6.27.10/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
1033 +++ linux-2.6.27.10-vs2.3.0.36.4/Documentation/vserver/debug.txt        2008-10-13 14:54:20.000000000 +0200
1034 @@ -0,0 +1,154 @@
1035 +
1036 +debug_cvirt:
1037 +
1038 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
1039 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
1040 +
1041 +debug_dlim:
1042 +
1043 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
1044 +       "FREE  (%p,#%d)%c inode"
1045 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
1046 +       "FREE  (%p,#%d)%c %lld bytes"
1047 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
1048 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
1049 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
1050 +       "rcu_free_dl_info(%p)"
1051 + 4  10 "alloc_dl_info(%p,%d) = %p"
1052 +       "dealloc_dl_info(%p)"
1053 +       "get_dl_info(%p[#%d.%d])"
1054 +       "put_dl_info(%p[#%d.%d])"
1055 + 5  20 "alloc_dl_info(%p,%d)*"
1056 + 6  40 "__hash_dl_info: %p[#%d]"
1057 +       "__unhash_dl_info: %p[#%d]"
1058 + 7  80 "locate_dl_info(%p,#%d) = %p"
1059 +
1060 +debug_misc:
1061 +
1062 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
1063 +       "new_dqhash: %p [#0x%08x]"
1064 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
1065 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
1066 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
1067 +       "vroot_get_real_bdev not set"
1068 + 1   2 "cow_break_link(»%s«)"
1069 +       "temp copy Â»%s«"
1070 + 2   4 "dentry_open(new): %p"
1071 +       "dentry_open(old): %p"
1072 +       "lookup_create(new): %p"
1073 +       "old path Â»%s«"
1074 +       "path_lookup(old): %d"
1075 +       "vfs_create(new): %d"
1076 +       "vfs_rename: %d"
1077 +       "vfs_sendfile: %d"
1078 + 3   8 "fput(new_file=%p[#%d])"
1079 +       "fput(old_file=%p[#%d])"
1080 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
1081 +       "vx_info_kill(%p[#%d],%d,%d)*"
1082 + 5  20 "vs_reboot(%p[#%d],%d)"
1083 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
1084 +
1085 +debug_net:
1086 +
1087 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
1088 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
1089 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
1090 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
1091 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
1092 + 6  40 "sk,egf: %p [#%d] (from %d)"
1093 +       "sk,egn: %p [#%d] (from %d)"
1094 +       "sk,req: %p [#%d] (from %d)"
1095 +       "sk: %p [#%d] (from %d)"
1096 +       "tw: %p [#%d] (from %d)"
1097 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
1098 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
1099 +
1100 +debug_nid:
1101 +
1102 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
1103 +       "alloc_nx_info(%d) = %p"
1104 +       "create_nx_info(%d) (dynamic rejected)"
1105 +       "create_nx_info(%d) = %p (already there)"
1106 +       "create_nx_info(%d) = %p (new)"
1107 +       "dealloc_nx_info(%p)"
1108 + 1   2 "alloc_nx_info(%d)*"
1109 +       "create_nx_info(%d)*"
1110 + 2   4 "get_nx_info(%p[#%d.%d])"
1111 +       "put_nx_info(%p[#%d.%d])"
1112 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
1113 +       "clr_nx_info(%p[#%d.%d])"
1114 +       "init_nx_info(%p[#%d.%d])"
1115 +       "release_nx_info(%p[#%d.%d.%d]) %p"
1116 +       "set_nx_info(%p[#%d.%d])"
1117 + 4  10 "__hash_nx_info: %p[#%d]"
1118 +       "__nx_dynamic_id: [#%d]"
1119 +       "__unhash_nx_info: %p[#%d.%d.%d]"
1120 + 5  20 "moved task %p into nxi:%p[#%d]"
1121 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
1122 +       "task_get_nx_info(%p)"
1123 + 6  40 "nx_clear_persistent(%p[#%d])"
1124 +
1125 +debug_quota:
1126 +
1127 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
1128 + 1   2 "quota_sync_dqh(%p,%d)"
1129 +       "sync_dquots(%p,%d)"
1130 +       "sync_dquots_dqh(%p,%d)"
1131 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
1132 +
1133 +debug_switch:
1134 +
1135 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
1136 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
1137 + 4  10 "%s: (%s %s) returned %s with %d"
1138 +
1139 +debug_tag:
1140 +
1141 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
1142 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1143 +
1144 +debug_xid:
1145 +
1146 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1147 +       "alloc_vx_info(%d) = %p"
1148 +       "alloc_vx_info(%d)*"
1149 +       "create_vx_info(%d) (dynamic rejected)"
1150 +       "create_vx_info(%d) = %p (already there)"
1151 +       "create_vx_info(%d) = %p (new)"
1152 +       "dealloc_vx_info(%p)"
1153 +       "loc_vx_info(%d) = %p (found)"
1154 +       "loc_vx_info(%d) = %p (new)"
1155 +       "loc_vx_info(%d) = %p (not available)"
1156 + 1   2 "create_vx_info(%d)*"
1157 +       "loc_vx_info(%d)*"
1158 + 2   4 "get_vx_info(%p[#%d.%d])"
1159 +       "put_vx_info(%p[#%d.%d])"
1160 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1161 +       "clr_vx_info(%p[#%d.%d])"
1162 +       "init_vx_info(%p[#%d.%d])"
1163 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1164 +       "set_vx_info(%p[#%d.%d])"
1165 + 4  10 "__hash_vx_info: %p[#%d]"
1166 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1167 +       "__vx_dynamic_id: [#%d]"
1168 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1169 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1170 +       "moved task %p into vxi:%p[#%d]"
1171 +       "task_get_vx_info(%p)"
1172 +       "vx_migrate_task(%p,%p[#%d.%d])"
1173 + 6  40 "vx_clear_persistent(%p[#%d])"
1174 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1175 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1176 +       "vx_set_persistent(%p[#%d])"
1177 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1178 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1179 +
1180 +
1181 +debug_limit:
1182 +
1183 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1184 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1185 +
1186 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1187 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1188 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1189 diff -NurpP --minimal linux-2.6.27.10/drivers/block/Kconfig linux-2.6.27.10-vs2.3.0.36.4/drivers/block/Kconfig
1190 --- linux-2.6.27.10/drivers/block/Kconfig       2008-10-13 14:51:59.000000000 +0200
1191 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/block/Kconfig  2008-10-13 14:54:20.000000000 +0200
1192 @@ -263,6 +263,13 @@ config BLK_DEV_CRYPTOLOOP
1193           instead, which can be configured to be on-disk compatible with the
1194           cryptoloop device.
1195  
1196 +config BLK_DEV_VROOT
1197 +       tristate "Virtual Root device support"
1198 +       depends on QUOTACTL
1199 +       ---help---
1200 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1201 +         partition within a virtual server without compromising security.
1202 +
1203  config BLK_DEV_NBD
1204         tristate "Network block device support"
1205         depends on NET
1206 diff -NurpP --minimal linux-2.6.27.10/drivers/block/loop.c linux-2.6.27.10-vs2.3.0.36.4/drivers/block/loop.c
1207 --- linux-2.6.27.10/drivers/block/loop.c        2008-07-13 23:51:29.000000000 +0200
1208 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/block/loop.c   2008-10-13 14:54:20.000000000 +0200
1209 @@ -76,6 +76,7 @@
1210  #include <linux/gfp.h>
1211  #include <linux/kthread.h>
1212  #include <linux/splice.h>
1213 +#include <linux/vs_context.h>
1214  
1215  #include <asm/uaccess.h>
1216  
1217 @@ -794,6 +795,7 @@ static int loop_set_fd(struct loop_devic
1218         lo->lo_blocksize = lo_blocksize;
1219         lo->lo_device = bdev;
1220         lo->lo_flags = lo_flags;
1221 +       lo->lo_xid = vx_current_xid();
1222         lo->lo_backing_file = file;
1223         lo->transfer = transfer_none;
1224         lo->ioctl = NULL;
1225 @@ -915,6 +917,7 @@ static int loop_clr_fd(struct loop_devic
1226         lo->lo_encrypt_key_size = 0;
1227         lo->lo_flags = 0;
1228         lo->lo_thread = NULL;
1229 +       lo->lo_xid = 0;
1230         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1231         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1232         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1233 @@ -938,7 +941,7 @@ loop_set_status(struct loop_device *lo, 
1234         struct loop_func_table *xfer;
1235  
1236         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
1237 -           !capable(CAP_SYS_ADMIN))
1238 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1239                 return -EPERM;
1240         if (lo->lo_state != Lo_bound)
1241                 return -ENXIO;
1242 @@ -1022,7 +1025,8 @@ loop_get_status(struct loop_device *lo, 
1243         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1244         info->lo_encrypt_type =
1245                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1246 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1247 +       if (lo->lo_encrypt_key_size &&
1248 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1249                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1250                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1251                        lo->lo_encrypt_key_size);
1252 @@ -1331,6 +1335,9 @@ static int lo_open(struct inode *inode, 
1253  {
1254         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1255  
1256 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1257 +               return -EACCES;
1258 +
1259         mutex_lock(&lo->lo_ctl_mutex);
1260         lo->lo_refcnt++;
1261         mutex_unlock(&lo->lo_ctl_mutex);
1262 diff -NurpP --minimal linux-2.6.27.10/drivers/block/Makefile linux-2.6.27.10-vs2.3.0.36.4/drivers/block/Makefile
1263 --- linux-2.6.27.10/drivers/block/Makefile      2008-10-13 14:51:59.000000000 +0200
1264 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/block/Makefile 2008-10-13 14:54:20.000000000 +0200
1265 @@ -30,5 +30,6 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1266  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1267  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1268  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1269 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1270  
1271  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1272 diff -NurpP --minimal linux-2.6.27.10/drivers/block/vroot.c linux-2.6.27.10-vs2.3.0.36.4/drivers/block/vroot.c
1273 --- linux-2.6.27.10/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
1274 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/block/vroot.c  2008-10-13 14:54:20.000000000 +0200
1275 @@ -0,0 +1,283 @@
1276 +/*
1277 + *  linux/drivers/block/vroot.c
1278 + *
1279 + *  written by Herbert Pötzl, 9/11/2002
1280 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1281 + *
1282 + *  based on the loop.c code by Theodore Ts'o.
1283 + *
1284 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1285 + * Redistribution of this file is permitted under the
1286 + * GNU General Public License.
1287 + *
1288 + */
1289 +
1290 +#include <linux/module.h>
1291 +#include <linux/moduleparam.h>
1292 +#include <linux/file.h>
1293 +#include <linux/major.h>
1294 +#include <linux/blkdev.h>
1295 +
1296 +#include <linux/vroot.h>
1297 +#include <linux/vs_context.h>
1298 +
1299 +
1300 +static int max_vroot = 8;
1301 +
1302 +static struct vroot_device *vroot_dev;
1303 +static struct gendisk **disks;
1304 +
1305 +
1306 +static int vroot_set_dev(
1307 +       struct vroot_device *vr,
1308 +       struct file *vr_file,
1309 +       struct block_device *bdev,
1310 +       unsigned int arg)
1311 +{
1312 +       struct block_device *real_bdev;
1313 +       struct file *file;
1314 +       struct inode *inode;
1315 +       int error;
1316 +
1317 +       error = -EBUSY;
1318 +       if (vr->vr_state != Vr_unbound)
1319 +               goto out;
1320 +
1321 +       error = -EBADF;
1322 +       file = fget(arg);
1323 +       if (!file)
1324 +               goto out;
1325 +
1326 +       error = -EINVAL;
1327 +       inode = file->f_dentry->d_inode;
1328 +
1329 +
1330 +       if (S_ISBLK(inode->i_mode)) {
1331 +               real_bdev = inode->i_bdev;
1332 +               vr->vr_device = real_bdev;
1333 +               __iget(real_bdev->bd_inode);
1334 +       } else
1335 +               goto out_fput;
1336 +
1337 +       vxdprintk(VXD_CBIT(misc, 0),
1338 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1339 +               vr->vr_number, VXD_DEV(real_bdev));
1340 +
1341 +       vr->vr_state = Vr_bound;
1342 +       error = 0;
1343 +
1344 + out_fput:
1345 +       fput(file);
1346 + out:
1347 +       return error;
1348 +}
1349 +
1350 +static int vroot_clr_dev(
1351 +       struct vroot_device *vr,
1352 +       struct file *vr_file,
1353 +       struct block_device *bdev)
1354 +{
1355 +       struct block_device *real_bdev;
1356 +
1357 +       if (vr->vr_state != Vr_bound)
1358 +               return -ENXIO;
1359 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1360 +               return -EBUSY;
1361 +
1362 +       real_bdev = vr->vr_device;
1363 +
1364 +       vxdprintk(VXD_CBIT(misc, 0),
1365 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1366 +               vr->vr_number, VXD_DEV(real_bdev));
1367 +
1368 +       bdput(real_bdev);
1369 +       vr->vr_state = Vr_unbound;
1370 +       vr->vr_device = NULL;
1371 +       return 0;
1372 +}
1373 +
1374 +
1375 +static int vr_ioctl(struct inode *inode, struct file *file,
1376 +       unsigned int cmd, unsigned long arg)
1377 +{
1378 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1379 +       int err;
1380 +
1381 +       down(&vr->vr_ctl_mutex);
1382 +       switch (cmd) {
1383 +       case VROOT_SET_DEV:
1384 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
1385 +               break;
1386 +       case VROOT_CLR_DEV:
1387 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
1388 +               break;
1389 +       default:
1390 +               err = -EINVAL;
1391 +               break;
1392 +       }
1393 +       up(&vr->vr_ctl_mutex);
1394 +       return err;
1395 +}
1396 +
1397 +static int vr_open(struct inode *inode, struct file *file)
1398 +{
1399 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1400 +
1401 +       down(&vr->vr_ctl_mutex);
1402 +       vr->vr_refcnt++;
1403 +       up(&vr->vr_ctl_mutex);
1404 +       return 0;
1405 +}
1406 +
1407 +static int vr_release(struct inode *inode, struct file *file)
1408 +{
1409 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
1410 +
1411 +       down(&vr->vr_ctl_mutex);
1412 +       --vr->vr_refcnt;
1413 +       up(&vr->vr_ctl_mutex);
1414 +       return 0;
1415 +}
1416 +
1417 +static struct block_device_operations vr_fops = {
1418 +       .owner =        THIS_MODULE,
1419 +       .open =         vr_open,
1420 +       .release =      vr_release,
1421 +       .ioctl =        vr_ioctl,
1422 +};
1423 +
1424 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1425 +{
1426 +       struct inode *inode = bdev->bd_inode;
1427 +       struct vroot_device *vr;
1428 +       struct block_device *real_bdev;
1429 +       int minor = iminor(inode);
1430 +
1431 +       vr = &vroot_dev[minor];
1432 +       real_bdev = vr->vr_device;
1433 +
1434 +       vxdprintk(VXD_CBIT(misc, 0),
1435 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1436 +               vr->vr_number, VXD_DEV(real_bdev));
1437 +
1438 +       if (vr->vr_state != Vr_bound)
1439 +               return ERR_PTR(-ENXIO);
1440 +
1441 +       __iget(real_bdev->bd_inode);
1442 +       return real_bdev;
1443 +}
1444 +
1445 +/*
1446 + * And now the modules code and kernel interface.
1447 + */
1448 +
1449 +module_param(max_vroot, int, 0);
1450 +
1451 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1452 +MODULE_LICENSE("GPL");
1453 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1454 +
1455 +MODULE_AUTHOR ("Herbert Pötzl");
1456 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1457 +
1458 +
1459 +int __init vroot_init(void)
1460 +{
1461 +       int err, i;
1462 +
1463 +       if (max_vroot < 1 || max_vroot > 256) {
1464 +               max_vroot = MAX_VROOT_DEFAULT;
1465 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1466 +                       "(must be between 1 and 256), "
1467 +                       "using default (%d)\n", max_vroot);
1468 +       }
1469 +
1470 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1471 +               return -EIO;
1472 +
1473 +       err = -ENOMEM;
1474 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1475 +       if (!vroot_dev)
1476 +               goto out_mem1;
1477 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1478 +
1479 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1480 +       if (!disks)
1481 +               goto out_mem2;
1482 +
1483 +       for (i = 0; i < max_vroot; i++) {
1484 +               disks[i] = alloc_disk(1);
1485 +               if (!disks[i])
1486 +                       goto out_mem3;
1487 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1488 +               if (!disks[i]->queue)
1489 +                       goto out_mem3;
1490 +       }
1491 +
1492 +       for (i = 0; i < max_vroot; i++) {
1493 +               struct vroot_device *vr = &vroot_dev[i];
1494 +               struct gendisk *disk = disks[i];
1495 +
1496 +               memset(vr, 0, sizeof(*vr));
1497 +               init_MUTEX(&vr->vr_ctl_mutex);
1498 +               vr->vr_number = i;
1499 +               disk->major = VROOT_MAJOR;
1500 +               disk->first_minor = i;
1501 +               disk->fops = &vr_fops;
1502 +               sprintf(disk->disk_name, "vroot%d", i);
1503 +               disk->private_data = vr;
1504 +       }
1505 +
1506 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1507 +       if (err)
1508 +               goto out_mem3;
1509 +
1510 +       for (i = 0; i < max_vroot; i++)
1511 +               add_disk(disks[i]);
1512 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1513 +       return 0;
1514 +
1515 +out_mem3:
1516 +       while (i--)
1517 +               put_disk(disks[i]);
1518 +       kfree(disks);
1519 +out_mem2:
1520 +       kfree(vroot_dev);
1521 +out_mem1:
1522 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1523 +       printk(KERN_ERR "vroot: ran out of memory\n");
1524 +       return err;
1525 +}
1526 +
1527 +void vroot_exit(void)
1528 +{
1529 +       int i;
1530 +
1531 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1532 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1533 +
1534 +       for (i = 0; i < max_vroot; i++) {
1535 +               del_gendisk(disks[i]);
1536 +               put_disk(disks[i]);
1537 +       }
1538 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1539 +
1540 +       kfree(disks);
1541 +       kfree(vroot_dev);
1542 +}
1543 +
1544 +module_init(vroot_init);
1545 +module_exit(vroot_exit);
1546 +
1547 +#ifndef MODULE
1548 +
1549 +static int __init max_vroot_setup(char *str)
1550 +{
1551 +       max_vroot = simple_strtol(str, NULL, 0);
1552 +       return 1;
1553 +}
1554 +
1555 +__setup("max_vroot=", max_vroot_setup);
1556 +
1557 +#endif
1558 +
1559 diff -NurpP --minimal linux-2.6.27.10/drivers/char/sysrq.c linux-2.6.27.10-vs2.3.0.36.4/drivers/char/sysrq.c
1560 --- linux-2.6.27.10/drivers/char/sysrq.c        2008-10-13 14:51:59.000000000 +0200
1561 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/char/sysrq.c   2008-10-13 14:54:20.000000000 +0200
1562 @@ -37,6 +37,7 @@
1563  #include <linux/irq.h>
1564  #include <linux/hrtimer.h>
1565  #include <linux/oom.h>
1566 +#include <linux/vserver/debug.h>
1567  
1568  #include <asm/ptrace.h>
1569  #include <asm/irq_regs.h>
1570 @@ -351,6 +352,21 @@ static struct sysrq_key_op sysrq_unrt_op
1571         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1572  };
1573  
1574 +
1575 +#ifdef CONFIG_VSERVER_DEBUG
1576 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1577 +{
1578 +       dump_vx_info_inactive((key == 'x')?0:1);
1579 +}
1580 +
1581 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1582 +       .handler        = sysrq_handle_vxinfo,
1583 +       .help_msg       = "conteXt",
1584 +       .action_msg     = "Show Context Info",
1585 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1586 +};
1587 +#endif
1588 +
1589  /* Key Operations table and lock */
1590  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1591  
1592 @@ -404,7 +420,11 @@ static struct sysrq_key_op *sysrq_key_ta
1593         NULL,                           /* x */
1594         /* y: May be registered on sparc64 for global register dump */
1595         NULL,                           /* y */
1596 -       NULL                            /* z */
1597 +#ifdef CONFIG_VSERVER_DEBUG
1598 +       &sysrq_showvxinfo_op,           /* z */
1599 +#else
1600 +       NULL,                           /* z */
1601 +#endif
1602  };
1603  
1604  /* key2index calculation, -1 on invalid index */
1605 @@ -416,6 +436,8 @@ static int sysrq_key_table_key2index(int
1606                 retval = key - '0';
1607         else if ((key >= 'a') && (key <= 'z'))
1608                 retval = key + 10 - 'a';
1609 +       else if ((key >= 'A') && (key <= 'Z'))
1610 +               retval = key + 10 - 'A';
1611         else
1612                 retval = -1;
1613         return retval;
1614 diff -NurpP --minimal linux-2.6.27.10/drivers/char/tty_io.c linux-2.6.27.10-vs2.3.0.36.4/drivers/char/tty_io.c
1615 --- linux-2.6.27.10/drivers/char/tty_io.c       2008-12-19 12:03:07.000000000 +0100
1616 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.27.10-vs2.3.0.36.4/drivers/infiniband/hw/ipath/ipath_user_pages.c
1634 --- linux-2.6.27.10/drivers/infiniband/hw/ipath/ipath_user_pages.c      2008-07-13 23:51:29.000000000 +0200
1635 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/infiniband/hw/ipath/ipath_user_pages.c 2008-10-13 14:54:20.000000000 +0200
1636 @@ -33,6 +33,7 @@
1637  
1638  #include <linux/mm.h>
1639  #include <linux/device.h>
1640 +#include <linux/vs_memory.h>
1641  
1642  #include "ipath_kernel.h"
1643  
1644 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
1645         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1646                 PAGE_SHIFT;
1647  
1648 -       if (num_pages > lock_limit) {
1649 +       if (num_pages > lock_limit ||
1650 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1651                 ret = -ENOMEM;
1652                 goto bail;
1653         }
1654 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
1655                         goto bail_release;
1656         }
1657  
1658 -       current->mm->locked_vm += num_pages;
1659 +       vx_vmlocked_add(current->mm, num_pages);
1660  
1661         ret = 0;
1662         goto bail;
1663 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
1664  
1665         __ipath_release_user_pages(p, num_pages, 1);
1666  
1667 -       current->mm->locked_vm -= num_pages;
1668 +       vx_vmlocked_sub(current->mm, num_pages);
1669  
1670         up_write(&current->mm->mmap_sem);
1671  }
1672 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
1673                 container_of(_work, struct ipath_user_pages_work, work);
1674  
1675         down_write(&work->mm->mmap_sem);
1676 -       work->mm->locked_vm -= work->num_pages;
1677 +       vx_vmlocked_sub(work->mm, work->num_pages);
1678         up_write(&work->mm->mmap_sem);
1679         mmput(work->mm);
1680         kfree(work);
1681 diff -NurpP --minimal linux-2.6.27.10/drivers/md/dm.c linux-2.6.27.10-vs2.3.0.36.4/drivers/md/dm.c
1682 --- linux-2.6.27.10/drivers/md/dm.c     2008-10-13 14:52:01.000000000 +0200
1683 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/md/dm.c        2008-10-13 14:54:20.000000000 +0200
1684 @@ -22,6 +22,7 @@
1685  #include <linux/hdreg.h>
1686  #include <linux/blktrace_api.h>
1687  #include <linux/smp_lock.h>
1688 +#include <linux/vs_base.h>
1689  
1690  #define DM_MSG_PREFIX "core"
1691  
1692 @@ -91,6 +92,7 @@ struct mapped_device {
1693         rwlock_t map_lock;
1694         atomic_t holders;
1695         atomic_t open_count;
1696 +       xid_t xid;
1697  
1698         unsigned long flags;
1699  
1700 @@ -252,6 +254,7 @@ static void __exit dm_exit(void)
1701  static int dm_blk_open(struct inode *inode, struct file *file)
1702  {
1703         struct mapped_device *md;
1704 +       int ret = -ENXIO;
1705  
1706         spin_lock(&_minor_lock);
1707  
1708 @@ -260,18 +263,19 @@ static int dm_blk_open(struct inode *ino
1709                 goto out;
1710  
1711         if (test_bit(DMF_FREEING, &md->flags) ||
1712 -           test_bit(DMF_DELETING, &md->flags)) {
1713 -               md = NULL;
1714 +           test_bit(DMF_DELETING, &md->flags))
1715 +               goto out;
1716 +
1717 +       ret = -EACCES;
1718 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1719                 goto out;
1720 -       }
1721  
1722         dm_get(md);
1723         atomic_inc(&md->open_count);
1724 -
1725 +       ret = 0;
1726  out:
1727         spin_unlock(&_minor_lock);
1728 -
1729 -       return md ? 0 : -ENXIO;
1730 +       return ret;
1731  }
1732  
1733  static int dm_blk_close(struct inode *inode, struct file *file)
1734 @@ -467,6 +471,14 @@ int dm_set_geometry(struct mapped_device
1735         return 0;
1736  }
1737  
1738 +/*
1739 + * Get the xid associated with a dm device
1740 + */
1741 +xid_t dm_get_xid(struct mapped_device *md)
1742 +{
1743 +       return md->xid;
1744 +}
1745 +
1746  /*-----------------------------------------------------------------
1747   * CRUD START:
1748   *   A more elegant soln is in the works that uses the queue
1749 @@ -1069,6 +1081,7 @@ static struct mapped_device *alloc_dev(i
1750         INIT_LIST_HEAD(&md->uevent_list);
1751         spin_lock_init(&md->uevent_lock);
1752  
1753 +       md->xid = vx_current_xid();
1754         md->queue = blk_alloc_queue(GFP_KERNEL);
1755         if (!md->queue)
1756                 goto bad_queue;
1757 diff -NurpP --minimal linux-2.6.27.10/drivers/md/dm.h linux-2.6.27.10-vs2.3.0.36.4/drivers/md/dm.h
1758 --- linux-2.6.27.10/drivers/md/dm.h     2008-10-13 14:52:01.000000000 +0200
1759 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/md/dm.h        2008-10-13 14:54:20.000000000 +0200
1760 @@ -66,6 +66,8 @@ void dm_put_target_type(struct target_ty
1761  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
1762                                         void *param), void *param);
1763  
1764 +xid_t dm_get_xid(struct mapped_device *md);
1765 +
1766  /*-----------------------------------------------------------------
1767   * Useful inlines.
1768   *---------------------------------------------------------------*/
1769 diff -NurpP --minimal linux-2.6.27.10/drivers/md/dm-ioctl.c linux-2.6.27.10-vs2.3.0.36.4/drivers/md/dm-ioctl.c
1770 --- linux-2.6.27.10/drivers/md/dm-ioctl.c       2008-07-13 23:51:29.000000000 +0200
1771 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/md/dm-ioctl.c  2008-10-13 14:54:20.000000000 +0200
1772 @@ -16,6 +16,7 @@
1773  #include <linux/dm-ioctl.h>
1774  #include <linux/hdreg.h>
1775  #include <linux/compat.h>
1776 +#include <linux/vs_context.h>
1777  
1778  #include <asm/uaccess.h>
1779  
1780 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1781         unsigned int h = hash_str(str);
1782  
1783         list_for_each_entry (hc, _name_buckets + h, name_list)
1784 -               if (!strcmp(hc->name, str)) {
1785 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1786 +                       !strcmp(hc->name, str)) {
1787                         dm_get(hc->md);
1788                         return hc;
1789                 }
1790 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1791         unsigned int h = hash_str(str);
1792  
1793         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1794 -               if (!strcmp(hc->uuid, str)) {
1795 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1796 +                       !strcmp(hc->uuid, str)) {
1797                         dm_get(hc->md);
1798                         return hc;
1799                 }
1800 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1801  
1802  static int remove_all(struct dm_ioctl *param, size_t param_size)
1803  {
1804 +       if (!vx_check(0, VS_ADMIN))
1805 +               return -EPERM;
1806 +
1807         dm_hash_remove_all(1);
1808         param->data_size = 0;
1809         return 0;
1810 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1811          */
1812         for (i = 0; i < NUM_BUCKETS; i++) {
1813                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1814 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1815 +                               continue;
1816                         needed += sizeof(struct dm_name_list);
1817                         needed += strlen(hc->name) + 1;
1818                         needed += ALIGN_MASK;
1819 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1820          */
1821         for (i = 0; i < NUM_BUCKETS; i++) {
1822                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1823 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1824 +                               continue;
1825                         if (old_nl)
1826                                 old_nl->next = (uint32_t) ((void *) nl -
1827                                                            (void *) old_nl);
1828 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
1829         if (!md)
1830                 goto out;
1831  
1832 -       mdptr = dm_get_mdptr(md);
1833 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1834 +               mdptr = dm_get_mdptr(md);
1835 +
1836         if (!mdptr)
1837                 dm_put(md);
1838 -
1839  out:
1840         return mdptr;
1841  }
1842 @@ -1406,8 +1417,8 @@ static int ctl_ioctl(uint command, struc
1843         ioctl_fn fn = NULL;
1844         size_t param_size;
1845  
1846 -       /* only root can play with this */
1847 -       if (!capable(CAP_SYS_ADMIN))
1848 +       /* only root and certain contexts can play with this */
1849 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1850                 return -EACCES;
1851  
1852         if (_IOC_TYPE(command) != DM_IOCTL)
1853 diff -NurpP --minimal linux-2.6.27.10/drivers/net/tun.c linux-2.6.27.10-vs2.3.0.36.4/drivers/net/tun.c
1854 --- linux-2.6.27.10/drivers/net/tun.c   2008-10-13 14:52:02.000000000 +0200
1855 +++ linux-2.6.27.10-vs2.3.0.36.4/drivers/net/tun.c      2008-10-13 14:54:20.000000000 +0200
1856 @@ -61,6 +61,7 @@
1857  #include <linux/crc32.h>
1858  #include <linux/nsproxy.h>
1859  #include <linux/virtio_net.h>
1860 +#include <linux/vs_network.h>
1861  #include <net/net_namespace.h>
1862  #include <net/netns/generic.h>
1863  
1864 @@ -93,6 +94,7 @@ struct tun_struct {
1865         int                     attached;
1866         uid_t                   owner;
1867         gid_t                   group;
1868 +       nid_t                   nid;
1869  
1870         wait_queue_head_t       read_wait;
1871         struct sk_buff_head     readq;
1872 @@ -675,6 +677,7 @@ static void tun_setup(struct net_device 
1873  
1874         tun->owner = -1;
1875         tun->group = -1;
1876 +       tun->nid = current->nid;
1877  
1878         dev->open = tun_net_open;
1879         dev->hard_start_xmit = tun_net_xmit;
1880 @@ -707,6 +710,9 @@ static int tun_set_iff(struct net *net, 
1881         tn = net_generic(net, tun_net_id);
1882         tun = tun_get_by_name(tn, ifr->ifr_name);
1883         if (tun) {
1884 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1885 +                       return -EPERM;
1886 +
1887                 if (tun->attached)
1888                         return -EBUSY;
1889  
1890 @@ -715,7 +721,7 @@ static int tun_set_iff(struct net *net, 
1891                       current->euid != tun->owner) ||
1892                      (tun->group != -1 &&
1893                       current->egid != tun->group)) &&
1894 -                    !capable(CAP_NET_ADMIN))
1895 +                    !cap_raised(current->cap_effective, CAP_NET_ADMIN))
1896                         return -EPERM;
1897         }
1898         else if (__dev_get_by_name(net, ifr->ifr_name))
1899 @@ -726,7 +732,7 @@ static int tun_set_iff(struct net *net, 
1900  
1901                 err = -EINVAL;
1902  
1903 -               if (!capable(CAP_NET_ADMIN))
1904 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1905                         return -EPERM;
1906  
1907                 /* Set dev type */
1908 @@ -966,6 +972,16 @@ static int tun_chr_ioctl(struct inode *i
1909                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1910                 break;
1911  
1912 +       case TUNSETNID:
1913 +               if (!capable(CAP_CONTEXT))
1914 +                       return -EPERM;
1915 +
1916 +               /* Set nid owner of the device */
1917 +               tun->nid = (nid_t) arg;
1918 +
1919 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1920 +               break;
1921 +
1922         case TUNSETLINK:
1923                 /* Only allow setting the type when the interface is down */
1924                 rtnl_lock();
1925 diff -NurpP --minimal linux-2.6.27.10/fs/attr.c linux-2.6.27.10-vs2.3.0.36.4/fs/attr.c
1926 --- linux-2.6.27.10/fs/attr.c   2008-10-13 14:52:05.000000000 +0200
1927 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/attr.c      2008-10-24 03:34:52.000000000 +0200
1928 @@ -14,6 +14,9 @@
1929  #include <linux/fcntl.h>
1930  #include <linux/quotaops.h>
1931  #include <linux/security.h>
1932 +#include <linux/proc_fs.h>
1933 +#include <linux/devpts_fs.h>
1934 +#include <linux/vs_tag.h>
1935  
1936  /* Taken over from the old code... */
1937  
1938 @@ -55,6 +58,10 @@ int inode_change_ok(struct inode *inode,
1939                 if (!is_owner_or_cap(inode))
1940                         goto error;
1941         }
1942 +
1943 +       if (dx_permission(inode, MAY_WRITE))
1944 +               goto error;
1945 +
1946  fine:
1947         retval = 0;
1948  error:
1949 @@ -78,6 +85,8 @@ int inode_setattr(struct inode * inode, 
1950                 inode->i_uid = attr->ia_uid;
1951         if (ia_valid & ATTR_GID)
1952                 inode->i_gid = attr->ia_gid;
1953 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1954 +               inode->i_tag = attr->ia_tag;
1955         if (ia_valid & ATTR_ATIME)
1956                 inode->i_atime = timespec_trunc(attr->ia_atime,
1957                                                 inode->i_sb->s_time_gran);
1958 @@ -172,7 +181,8 @@ int notify_change(struct dentry * dentry
1959                         error = security_inode_setattr(dentry, attr);
1960                 if (!error) {
1961                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
1962 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
1963 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
1964 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
1965                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
1966                         if (!error)
1967                                 error = inode_setattr(inode, attr);
1968 diff -NurpP --minimal linux-2.6.27.10/fs/binfmt_aout.c linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_aout.c
1969 --- linux-2.6.27.10/fs/binfmt_aout.c    2008-10-13 14:52:05.000000000 +0200
1970 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_aout.c       2008-10-13 14:54:20.000000000 +0200
1971 @@ -24,6 +24,7 @@
1972  #include <linux/binfmts.h>
1973  #include <linux/personality.h>
1974  #include <linux/init.h>
1975 +#include <linux/vs_memory.h>
1976  
1977  #include <asm/system.h>
1978  #include <asm/uaccess.h>
1979 diff -NurpP --minimal linux-2.6.27.10/fs/binfmt_elf.c linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_elf.c
1980 --- linux-2.6.27.10/fs/binfmt_elf.c     2008-10-13 14:52:05.000000000 +0200
1981 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_elf.c        2008-10-13 14:54:20.000000000 +0200
1982 @@ -38,6 +38,7 @@
1983  #include <linux/random.h>
1984  #include <linux/elf.h>
1985  #include <linux/utsname.h>
1986 +#include <linux/vs_memory.h>
1987  #include <asm/uaccess.h>
1988  #include <asm/param.h>
1989  #include <asm/page.h>
1990 diff -NurpP --minimal linux-2.6.27.10/fs/binfmt_flat.c linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_flat.c
1991 --- linux-2.6.27.10/fs/binfmt_flat.c    2008-10-13 14:52:05.000000000 +0200
1992 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_flat.c       2008-10-13 14:54:20.000000000 +0200
1993 @@ -35,6 +35,7 @@
1994  #include <linux/init.h>
1995  #include <linux/flat.h>
1996  #include <linux/syscalls.h>
1997 +#include <linux/vs_memory.h>
1998  
1999  #include <asm/byteorder.h>
2000  #include <asm/system.h>
2001 diff -NurpP --minimal linux-2.6.27.10/fs/binfmt_som.c linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_som.c
2002 --- linux-2.6.27.10/fs/binfmt_som.c     2008-10-13 14:52:05.000000000 +0200
2003 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/binfmt_som.c        2008-10-13 14:54:20.000000000 +0200
2004 @@ -28,6 +28,7 @@
2005  #include <linux/shm.h>
2006  #include <linux/personality.h>
2007  #include <linux/init.h>
2008 +#include <linux/vs_memory.h>
2009  
2010  #include <asm/uaccess.h>
2011  #include <asm/pgtable.h>
2012 diff -NurpP --minimal linux-2.6.27.10/fs/block_dev.c linux-2.6.27.10-vs2.3.0.36.4/fs/block_dev.c
2013 --- linux-2.6.27.10/fs/block_dev.c      2008-10-13 14:52:05.000000000 +0200
2014 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/block_dev.c 2008-10-13 14:54:20.000000000 +0200
2015 @@ -24,6 +24,7 @@
2016  #include <linux/uio.h>
2017  #include <linux/namei.h>
2018  #include <linux/log2.h>
2019 +#include <linux/vs_device.h>
2020  #include <asm/uaccess.h>
2021  #include "internal.h"
2022  
2023 @@ -389,6 +390,7 @@ struct block_device *bdget(dev_t dev)
2024                 bdev->bd_invalidated = 0;
2025                 inode->i_mode = S_IFBLK;
2026                 inode->i_rdev = dev;
2027 +               inode->i_mdev = dev;
2028                 inode->i_bdev = bdev;
2029                 inode->i_data.a_ops = &def_blk_aops;
2030                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2031 @@ -425,6 +427,11 @@ EXPORT_SYMBOL(bdput);
2032  static struct block_device *bd_acquire(struct inode *inode)
2033  {
2034         struct block_device *bdev;
2035 +       dev_t mdev;
2036 +
2037 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2038 +               return NULL;
2039 +       inode->i_mdev = mdev;
2040  
2041         spin_lock(&bdev_lock);
2042         bdev = inode->i_bdev;
2043 @@ -435,7 +442,7 @@ static struct block_device *bd_acquire(s
2044         }
2045         spin_unlock(&bdev_lock);
2046  
2047 -       bdev = bdget(inode->i_rdev);
2048 +       bdev = bdget(mdev);
2049         if (bdev) {
2050                 spin_lock(&bdev_lock);
2051                 if (!inode->i_bdev) {
2052 diff -NurpP --minimal linux-2.6.27.10/fs/char_dev.c linux-2.6.27.10-vs2.3.0.36.4/fs/char_dev.c
2053 --- linux-2.6.27.10/fs/char_dev.c       2008-10-13 14:52:05.000000000 +0200
2054 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/char_dev.c  2008-10-13 14:54:20.000000000 +0200
2055 @@ -21,6 +21,8 @@
2056  #include <linux/cdev.h>
2057  #include <linux/mutex.h>
2058  #include <linux/backing-dev.h>
2059 +#include <linux/vs_context.h>
2060 +#include <linux/vs_device.h>
2061  
2062  #ifdef CONFIG_KMOD
2063  #include <linux/kmod.h>
2064 @@ -361,14 +363,21 @@ static int chrdev_open(struct inode *ino
2065         struct cdev *p;
2066         struct cdev *new = NULL;
2067         int ret = 0;
2068 +       dev_t mdev;
2069 +
2070 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2071 +               return -EPERM;
2072 +       inode->i_mdev = mdev;
2073  
2074         spin_lock(&cdev_lock);
2075         p = inode->i_cdev;
2076         if (!p) {
2077                 struct kobject *kobj;
2078                 int idx;
2079 +
2080                 spin_unlock(&cdev_lock);
2081 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2082 +
2083 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2084                 if (!kobj)
2085                         return -ENXIO;
2086                 new = container_of(kobj, struct cdev, kobj);
2087 diff -NurpP --minimal linux-2.6.27.10/fs/dcache.c linux-2.6.27.10-vs2.3.0.36.4/fs/dcache.c
2088 --- linux-2.6.27.10/fs/dcache.c 2008-10-13 14:52:05.000000000 +0200
2089 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/devpts/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/devpts/inode.c
2142 --- linux-2.6.27.10/fs/devpts/inode.c   2008-10-13 14:52:05.000000000 +0200
2143 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/devpts/inode.c      2008-10-13 14:54:20.000000000 +0200
2144 @@ -19,15 +19,29 @@
2145  #include <linux/tty.h>
2146  #include <linux/mutex.h>
2147  #include <linux/idr.h>
2148 +#include <linux/magic.h>
2149  #include <linux/devpts_fs.h>
2150  #include <linux/parser.h>
2151  #include <linux/fsnotify.h>
2152  #include <linux/seq_file.h>
2153 -
2154 -#define DEVPTS_SUPER_MAGIC 0x1cd1
2155 +#include <linux/vs_base.h>
2156  
2157  #define DEVPTS_DEFAULT_MODE 0600
2158  
2159 +static int devpts_permission(struct inode *inode, int mask)
2160 +{
2161 +       int ret = -EACCES;
2162 +
2163 +       /* devpts is xid tagged */
2164 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2165 +               ret = generic_permission(inode, mask, NULL);
2166 +       return ret;
2167 +}
2168 +
2169 +static struct inode_operations devpts_file_inode_operations = {
2170 +       .permission     = devpts_permission,
2171 +};
2172 +
2173  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2174  static DEFINE_IDA(allocated_ptys);
2175  static DEFINE_MUTEX(allocated_ptys_lock);
2176 @@ -112,6 +126,25 @@ static int devpts_show_options(struct se
2177         return 0;
2178  }
2179  
2180 +static int devpts_filter(struct dentry *de)
2181 +{
2182 +       /* devpts is xid tagged */
2183 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2184 +}
2185 +
2186 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2187 +{
2188 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2189 +}
2190 +
2191 +static struct file_operations devpts_dir_operations = {
2192 +       .open           = dcache_dir_open,
2193 +       .release        = dcache_dir_close,
2194 +       .llseek         = dcache_dir_lseek,
2195 +       .read           = generic_read_dir,
2196 +       .readdir        = devpts_readdir,
2197 +};
2198 +
2199  static const struct super_operations devpts_sops = {
2200         .statfs         = simple_statfs,
2201         .remount_fs     = devpts_remount,
2202 @@ -138,8 +171,10 @@ devpts_fill_super(struct super_block *s,
2203         inode->i_uid = inode->i_gid = 0;
2204         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2205         inode->i_op = &simple_dir_inode_operations;
2206 -       inode->i_fop = &simple_dir_operations;
2207 +       inode->i_fop = &devpts_dir_operations;
2208         inode->i_nlink = 2;
2209 +       /* devpts is xid tagged */
2210 +       inode->i_tag = (tag_t)vx_current_xid();
2211  
2212         devpts_root = s->s_root = d_alloc_root(inode);
2213         if (s->s_root)
2214 @@ -232,6 +267,9 @@ int devpts_pty_new(struct tty_struct *tt
2215         inode->i_gid = config.setgid ? config.gid : current->fsgid;
2216         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2217         init_special_inode(inode, S_IFCHR|config.mode, device);
2218 +       /* devpts is xid tagged */
2219 +       inode->i_tag = (tag_t)vx_current_xid();
2220 +       inode->i_op = &devpts_file_inode_operations;
2221         inode->i_private = tty;
2222  
2223         dentry = get_node(number);
2224 diff -NurpP --minimal linux-2.6.27.10/fs/exec.c linux-2.6.27.10-vs2.3.0.36.4/fs/exec.c
2225 --- linux-2.6.27.10/fs/exec.c   2008-12-19 12:03:13.000000000 +0100
2226 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/exec.c      2008-12-19 12:09:13.000000000 +0100
2227 @@ -263,7 +263,9 @@ static int __bprm_mm_init(struct linux_b
2228                 goto err;
2229         }
2230  
2231 -       mm->stack_vm = mm->total_vm = 1;
2232 +       mm->total_vm = 0;
2233 +       vx_vmpages_inc(mm);
2234 +       mm->stack_vm = 1;
2235         up_write(&mm->mmap_sem);
2236  
2237         bprm->p = vma->vm_end - sizeof(void *);
2238 @@ -1461,7 +1463,7 @@ static int format_corename(char *corenam
2239                         /* UNIX time of coredump */
2240                         case 't': {
2241                                 struct timeval tv;
2242 -                               do_gettimeofday(&tv);
2243 +                               vx_gettimeofday(&tv);
2244                                 rc = snprintf(out_ptr, out_end - out_ptr,
2245                                               "%lu", tv.tv_sec);
2246                                 if (rc > out_end - out_ptr)
2247 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/balloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/balloc.c
2248 --- linux-2.6.27.10/fs/ext2/balloc.c    2008-12-19 12:03:13.000000000 +0100
2249 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/balloc.c       2008-12-08 04:52:52.000000000 +0100
2250 @@ -16,6 +16,8 @@
2251  #include <linux/sched.h>
2252  #include <linux/buffer_head.h>
2253  #include <linux/capability.h>
2254 +#include <linux/vs_dlimit.h>
2255 +#include <linux/vs_tag.h>
2256  
2257  /*
2258   * balloc.c contains the blocks allocation and deallocation routines
2259 @@ -569,6 +571,7 @@ do_more:
2260         }
2261  error_return:
2262         brelse(bitmap_bh);
2263 +       DLIMIT_FREE_BLOCK(inode, freed);
2264         release_blocks(sb, freed);
2265         DQUOT_FREE_BLOCK(inode, freed);
2266  }
2267 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2268                         start = 0;
2269                 end = EXT2_BLOCKS_PER_GROUP(sb);
2270         }
2271 -
2272         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2273  
2274  repeat:
2275 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2276                 *errp = -EDQUOT;
2277                 return 0;
2278         }
2279 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2280 +               *errp = -ENOSPC;
2281 +               DQUOT_FREE_BLOCK(inode, num);
2282 +               return 0;
2283 +       }
2284  
2285         sbi = EXT2_SB(sb);
2286         es = EXT2_SB(sb)->s_es;
2287 @@ -1409,6 +1416,7 @@ allocated:
2288  
2289         *errp = 0;
2290         brelse(bitmap_bh);
2291 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2292         DQUOT_FREE_BLOCK(inode, *count-num);
2293         *count = num;
2294         return ret_block;
2295 @@ -1419,8 +1427,10 @@ out:
2296         /*
2297          * Undo the block allocation
2298          */
2299 -       if (!performed_allocation)
2300 +       if (!performed_allocation) {
2301 +               DLIMIT_FREE_BLOCK(inode, *count);
2302                 DQUOT_FREE_BLOCK(inode, *count);
2303 +       }
2304         brelse(bitmap_bh);
2305         return 0;
2306  }
2307 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/ext2.h linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/ext2.h
2308 --- linux-2.6.27.10/fs/ext2/ext2.h      2008-07-13 23:51:29.000000000 +0200
2309 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/ext2.h 2008-10-13 14:54:20.000000000 +0200
2310 @@ -168,6 +168,7 @@ extern const struct file_operations ext2
2311  extern const struct address_space_operations ext2_aops;
2312  extern const struct address_space_operations ext2_aops_xip;
2313  extern const struct address_space_operations ext2_nobh_aops;
2314 +extern int ext2_sync_flags(struct inode *inode);
2315  
2316  /* namei.c */
2317  extern const struct inode_operations ext2_dir_inode_operations;
2318 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/file.c
2319 --- linux-2.6.27.10/fs/ext2/file.c      2008-07-13 23:51:29.000000000 +0200
2320 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/file.c 2008-10-13 14:54:20.000000000 +0200
2321 @@ -86,4 +86,5 @@ const struct inode_operations ext2_file_
2322  #endif
2323         .setattr        = ext2_setattr,
2324         .permission     = ext2_permission,
2325 +       .sync_flags     = ext2_sync_flags,
2326  };
2327 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/ialloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/ialloc.c
2328 --- linux-2.6.27.10/fs/ext2/ialloc.c    2008-07-13 23:51:29.000000000 +0200
2329 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/ialloc.c       2008-10-13 14:54:20.000000000 +0200
2330 @@ -17,6 +17,8 @@
2331  #include <linux/backing-dev.h>
2332  #include <linux/buffer_head.h>
2333  #include <linux/random.h>
2334 +#include <linux/vs_dlimit.h>
2335 +#include <linux/vs_tag.h>
2336  #include "ext2.h"
2337  #include "xattr.h"
2338  #include "acl.h"
2339 @@ -123,6 +125,7 @@ void ext2_free_inode (struct inode * ino
2340                 ext2_xattr_delete_inode(inode);
2341                 DQUOT_FREE_INODE(inode);
2342                 DQUOT_DROP(inode);
2343 +               DLIMIT_FREE_INODE(inode);
2344         }
2345  
2346         es = EXT2_SB(sb)->s_es;
2347 @@ -454,6 +457,11 @@ struct inode *ext2_new_inode(struct inod
2348         if (!inode)
2349                 return ERR_PTR(-ENOMEM);
2350  
2351 +       inode->i_tag = dx_current_fstag(sb);
2352 +       if (DLIMIT_ALLOC_INODE(inode)) {
2353 +               err = -ENOSPC;
2354 +               goto fail_dlim;
2355 +       }
2356         ei = EXT2_I(inode);
2357         sbi = EXT2_SB(sb);
2358         es = sbi->s_es;
2359 @@ -565,7 +573,8 @@ got:
2360         inode->i_blocks = 0;
2361         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
2362         memset(ei->i_data, 0, sizeof(ei->i_data));
2363 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
2364 +       ei->i_flags = EXT2_I(dir)->i_flags &
2365 +               ~(EXT2_BTREE_FL|EXT2_IXUNLINK_FL|EXT2_BARRIER_FL);
2366         if (S_ISLNK(mode))
2367                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
2368         /* dirsync is only applied to directories */
2369 @@ -610,12 +619,15 @@ fail_free_drop:
2370  
2371  fail_drop:
2372         DQUOT_DROP(inode);
2373 +       DLIMIT_FREE_INODE(inode);
2374         inode->i_flags |= S_NOQUOTA;
2375         inode->i_nlink = 0;
2376         iput(inode);
2377         return ERR_PTR(err);
2378  
2379  fail:
2380 +       DLIMIT_FREE_INODE(inode);
2381 +fail_dlim:
2382         make_bad_inode(inode);
2383         iput(inode);
2384         return ERR_PTR(err);
2385 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/inode.c
2386 --- linux-2.6.27.10/fs/ext2/inode.c     2008-10-13 14:52:05.000000000 +0200
2387 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/inode.c        2008-10-13 14:54:20.000000000 +0200
2388 @@ -31,6 +31,7 @@
2389  #include <linux/writeback.h>
2390  #include <linux/buffer_head.h>
2391  #include <linux/mpage.h>
2392 +#include <linux/vs_tag.h>
2393  #include "ext2.h"
2394  #include "acl.h"
2395  #include "xip.h"
2396 @@ -1011,7 +1012,7 @@ void ext2_truncate(struct inode *inode)
2397                 return;
2398         if (ext2_inode_is_fast_symlink(inode))
2399                 return;
2400 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2401 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2402                 return;
2403  
2404         blocksize = inode->i_sb->s_blocksize;
2405 @@ -1149,38 +1150,72 @@ void ext2_set_inode_flags(struct inode *
2406  {
2407         unsigned int flags = EXT2_I(inode)->i_flags;
2408  
2409 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2410 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2411 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2412 +
2413 +
2414 +       if (flags & EXT2_IMMUTABLE_FL)
2415 +               inode->i_flags |= S_IMMUTABLE;
2416 +       if (flags & EXT2_IXUNLINK_FL)
2417 +               inode->i_flags |= S_IXUNLINK;
2418 +
2419         if (flags & EXT2_SYNC_FL)
2420                 inode->i_flags |= S_SYNC;
2421         if (flags & EXT2_APPEND_FL)
2422                 inode->i_flags |= S_APPEND;
2423 -       if (flags & EXT2_IMMUTABLE_FL)
2424 -               inode->i_flags |= S_IMMUTABLE;
2425         if (flags & EXT2_NOATIME_FL)
2426                 inode->i_flags |= S_NOATIME;
2427         if (flags & EXT2_DIRSYNC_FL)
2428                 inode->i_flags |= S_DIRSYNC;
2429 +
2430 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2431 +
2432 +       if (flags & EXT2_BARRIER_FL)
2433 +               inode->i_vflags |= V_BARRIER;
2434 +       if (flags & EXT2_COW_FL)
2435 +               inode->i_vflags |= V_COW;
2436  }
2437  
2438  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2439  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2440  {
2441         unsigned int flags = ei->vfs_inode.i_flags;
2442 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2443 +
2444 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2445 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2446 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2447 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2448 +
2449 +       if (flags & S_IMMUTABLE)
2450 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2451 +       if (flags & S_IXUNLINK)
2452 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2453  
2454 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2455 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2456         if (flags & S_SYNC)
2457                 ei->i_flags |= EXT2_SYNC_FL;
2458         if (flags & S_APPEND)
2459                 ei->i_flags |= EXT2_APPEND_FL;
2460 -       if (flags & S_IMMUTABLE)
2461 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2462         if (flags & S_NOATIME)
2463                 ei->i_flags |= EXT2_NOATIME_FL;
2464         if (flags & S_DIRSYNC)
2465                 ei->i_flags |= EXT2_DIRSYNC_FL;
2466 +
2467 +       if (vflags & V_BARRIER)
2468 +               ei->i_flags |= EXT2_BARRIER_FL;
2469 +       if (vflags & V_COW)
2470 +               ei->i_flags |= EXT2_COW_FL;
2471  }
2472  
2473 +int ext2_sync_flags(struct inode *inode)
2474 +{
2475 +       ext2_get_inode_flags(EXT2_I(inode));
2476 +       inode->i_ctime = CURRENT_TIME;
2477 +       mark_inode_dirty(inode);
2478 +       return 0;
2479 +}
2480 +
2481 +
2482  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2483  {
2484         struct ext2_inode_info *ei;
2485 @@ -1188,6 +1223,8 @@ struct inode *ext2_iget (struct super_bl
2486         struct ext2_inode *raw_inode;
2487         struct inode *inode;
2488         long ret = -EIO;
2489 +       uid_t uid;
2490 +       gid_t gid;
2491         int n;
2492  
2493         inode = iget_locked(sb, ino);
2494 @@ -1210,12 +1247,17 @@ struct inode *ext2_iget (struct super_bl
2495         }
2496  
2497         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2498 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2499 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2500 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2501 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2502         if (!(test_opt (inode->i_sb, NO_UID32))) {
2503 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2504 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2505 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2506 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2507         }
2508 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2509 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2510 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2511 +               le16_to_cpu(raw_inode->i_raw_tag));
2512 +
2513         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2514         inode->i_size = le32_to_cpu(raw_inode->i_size);
2515         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2516 @@ -1311,8 +1353,8 @@ static int ext2_update_inode(struct inod
2517         struct ext2_inode_info *ei = EXT2_I(inode);
2518         struct super_block *sb = inode->i_sb;
2519         ino_t ino = inode->i_ino;
2520 -       uid_t uid = inode->i_uid;
2521 -       gid_t gid = inode->i_gid;
2522 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2523 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2524         struct buffer_head * bh;
2525         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2526         int n;
2527 @@ -1348,6 +1390,9 @@ static int ext2_update_inode(struct inod
2528                 raw_inode->i_uid_high = 0;
2529                 raw_inode->i_gid_high = 0;
2530         }
2531 +#ifdef CONFIG_TAGGING_INTERN
2532 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2533 +#endif
2534         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2535         raw_inode->i_size = cpu_to_le32(inode->i_size);
2536         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2537 @@ -1434,7 +1479,8 @@ int ext2_setattr(struct dentry *dentry, 
2538         if (error)
2539                 return error;
2540         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2541 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2542 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2543 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2544                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2545                 if (error)
2546                         return error;
2547 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/ioctl.c
2548 --- linux-2.6.27.10/fs/ext2/ioctl.c     2008-07-13 23:51:29.000000000 +0200
2549 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/ioctl.c        2008-10-13 14:54:20.000000000 +0200
2550 @@ -14,6 +14,7 @@
2551  #include <linux/compat.h>
2552  #include <linux/mount.h>
2553  #include <linux/smp_lock.h>
2554 +#include <linux/mount.h>
2555  #include <asm/current.h>
2556  #include <asm/uaccess.h>
2557  
2558 @@ -53,6 +54,11 @@ long ext2_ioctl(struct file *filp, unsig
2559                 if (!S_ISDIR(inode->i_mode))
2560                         flags &= ~EXT2_DIRSYNC_FL;
2561  
2562 +               if (IS_BARRIER(inode)) {
2563 +                       vxwprintk_task(1, "messing with the barrier.");
2564 +                       return -EACCES;
2565 +               }
2566 +
2567                 mutex_lock(&inode->i_mutex);
2568                 /* Is it quota file? Do not allow user to mess with it */
2569                 if (IS_NOQUOTA(inode)) {
2570 @@ -68,7 +74,9 @@ long ext2_ioctl(struct file *filp, unsig
2571                  *
2572                  * This test looks nicer. Thanks to Pauline Middelink
2573                  */
2574 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2575 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2576 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2577 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2578                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2579                                 mutex_unlock(&inode->i_mutex);
2580                                 ret = -EPERM;
2581 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/namei.c
2582 --- linux-2.6.27.10/fs/ext2/namei.c     2008-07-13 23:51:29.000000000 +0200
2583 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/namei.c        2008-10-13 14:54:20.000000000 +0200
2584 @@ -31,6 +31,7 @@
2585   */
2586  
2587  #include <linux/pagemap.h>
2588 +#include <linux/vs_tag.h>
2589  #include "ext2.h"
2590  #include "xattr.h"
2591  #include "acl.h"
2592 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
2593                 inode = ext2_iget(dir->i_sb, ino);
2594                 if (IS_ERR(inode))
2595                         return ERR_CAST(inode);
2596 +               dx_propagate_tag(nd, inode);
2597         }
2598         return d_splice_alias(inode, dentry);
2599  }
2600 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
2601  #endif
2602         .setattr        = ext2_setattr,
2603         .permission     = ext2_permission,
2604 +       .sync_flags     = ext2_sync_flags,
2605  };
2606  
2607  const struct inode_operations ext2_special_inode_operations = {
2608 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
2609  #endif
2610         .setattr        = ext2_setattr,
2611         .permission     = ext2_permission,
2612 +       .sync_flags     = ext2_sync_flags,
2613  };
2614 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/super.c
2615 --- linux-2.6.27.10/fs/ext2/super.c     2008-10-13 14:52:05.000000000 +0200
2616 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/super.c        2008-10-13 14:54:20.000000000 +0200
2617 @@ -390,7 +390,8 @@ enum {
2618         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2619         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2620         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2621 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2622 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2623 +       Opt_tag, Opt_notag, Opt_tagid
2624  };
2625  
2626  static match_table_t tokens = {
2627 @@ -418,6 +419,9 @@ static match_table_t tokens = {
2628         {Opt_acl, "acl"},
2629         {Opt_noacl, "noacl"},
2630         {Opt_xip, "xip"},
2631 +       {Opt_tag, "tag"},
2632 +       {Opt_notag, "notag"},
2633 +       {Opt_tagid, "tagid=%u"},
2634         {Opt_grpquota, "grpquota"},
2635         {Opt_ignore, "noquota"},
2636         {Opt_quota, "quota"},
2637 @@ -488,6 +492,20 @@ static int parse_options (char * options
2638                 case Opt_nouid32:
2639                         set_opt (sbi->s_mount_opt, NO_UID32);
2640                         break;
2641 +#ifndef CONFIG_TAGGING_NONE
2642 +               case Opt_tag:
2643 +                       set_opt (sbi->s_mount_opt, TAGGED);
2644 +                       break;
2645 +               case Opt_notag:
2646 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2647 +                       break;
2648 +#endif
2649 +#ifdef CONFIG_PROPAGATE
2650 +               case Opt_tagid:
2651 +                       /* use args[0] */
2652 +                       set_opt (sbi->s_mount_opt, TAGGED);
2653 +                       break;
2654 +#endif
2655                 case Opt_nocheck:
2656                         clear_opt (sbi->s_mount_opt, CHECK);
2657                         break;
2658 @@ -830,6 +848,8 @@ static int ext2_fill_super(struct super_
2659         if (!parse_options ((char *) data, sbi))
2660                 goto failed_mount;
2661  
2662 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2663 +               sb->s_flags |= MS_TAGGED;
2664         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2665                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2666                  MS_POSIXACL : 0);
2667 @@ -1162,6 +1182,13 @@ static int ext2_remount (struct super_bl
2668                 goto restore_opts;
2669         }
2670  
2671 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2672 +               !(sb->s_flags & MS_TAGGED)) {
2673 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2674 +                      sb->s_id);
2675 +               return -EINVAL;
2676 +       }
2677 +
2678         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2679                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2680  
2681 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/symlink.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/symlink.c
2682 --- linux-2.6.27.10/fs/ext2/symlink.c   2008-07-13 23:51:29.000000000 +0200
2683 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/symlink.c      2008-10-13 14:54:20.000000000 +0200
2684 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
2685         .listxattr      = ext2_listxattr,
2686         .removexattr    = generic_removexattr,
2687  #endif
2688 +       .sync_flags     = ext2_sync_flags,
2689  };
2690   
2691  const struct inode_operations ext2_fast_symlink_inode_operations = {
2692 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
2693         .listxattr      = ext2_listxattr,
2694         .removexattr    = generic_removexattr,
2695  #endif
2696 +       .sync_flags     = ext2_sync_flags,
2697  };
2698 diff -NurpP --minimal linux-2.6.27.10/fs/ext2/xattr.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/xattr.c
2699 --- linux-2.6.27.10/fs/ext2/xattr.c     2008-07-13 23:51:29.000000000 +0200
2700 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext2/xattr.c        2008-10-13 14:54:20.000000000 +0200
2701 @@ -60,6 +60,7 @@
2702  #include <linux/mbcache.h>
2703  #include <linux/quotaops.h>
2704  #include <linux/rwsem.h>
2705 +#include <linux/vs_dlimit.h>
2706  #include "ext2.h"
2707  #include "xattr.h"
2708  #include "acl.h"
2709 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
2710                                    the inode.  */
2711                                 ea_bdebug(new_bh, "reusing block");
2712  
2713 +                               error = -ENOSPC;
2714 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
2715 +                                       goto cleanup;
2716                                 error = -EDQUOT;
2717                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2718 +                                       DLIMIT_FREE_BLOCK(inode, 1);
2719                                         unlock_buffer(new_bh);
2720                                         goto cleanup;
2721                                 }
2722 @@ -731,6 +736,7 @@ ext2_xattr_set2(struct inode *inode, str
2723                         le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
2724                         if (ce)
2725                                 mb_cache_entry_release(ce);
2726 +                       DLIMIT_FREE_BLOCK(inode, 1);
2727                         DQUOT_FREE_BLOCK(inode, 1);
2728                         mark_buffer_dirty(old_bh);
2729                         ea_bdebug(old_bh, "refcount now=%d",
2730 @@ -794,6 +800,7 @@ ext2_xattr_delete_inode(struct inode *in
2731                 mark_buffer_dirty(bh);
2732                 if (IS_SYNC(inode))
2733                         sync_dirty_buffer(bh);
2734 +               DLIMIT_FREE_BLOCK(inode, 1);
2735                 DQUOT_FREE_BLOCK(inode, 1);
2736         }
2737         EXT2_I(inode)->i_file_acl = 0;
2738 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/balloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/balloc.c
2739 --- linux-2.6.27.10/fs/ext3/balloc.c    2008-12-19 12:03:13.000000000 +0100
2740 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/balloc.c       2008-12-08 04:52:52.000000000 +0100
2741 @@ -19,6 +19,8 @@
2742  #include <linux/ext3_jbd.h>
2743  #include <linux/quotaops.h>
2744  #include <linux/buffer_head.h>
2745 +#include <linux/vs_dlimit.h>
2746 +#include <linux/vs_tag.h>
2747  
2748  /*
2749   * balloc.c contains the blocks allocation and deallocation routines
2750 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2751                 return;
2752         }
2753         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2754 -       if (dquot_freed_blocks)
2755 +       if (dquot_freed_blocks) {
2756 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2757                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2758 +       }
2759         return;
2760  }
2761  
2762 @@ -1415,18 +1419,33 @@ out:
2763   *
2764   * Check if filesystem has at least 1 free block available for allocation.
2765   */
2766 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2767 +static int ext3_has_free_blocks(struct super_block *sb)
2768  {
2769 -       ext3_fsblk_t free_blocks, root_blocks;
2770 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2771 +       unsigned long long free_blocks, root_blocks;
2772 +       int cond;
2773  
2774         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2775         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2776 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2777 +
2778 +       vxdprintk(VXD_CBIT(dlim, 3),
2779 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2780 +               sb, free_blocks, root_blocks);
2781 +
2782 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2783 +
2784 +       cond = (free_blocks < root_blocks + 1 &&
2785 +               !capable(CAP_SYS_RESOURCE) &&
2786                 sbi->s_resuid != current->fsuid &&
2787 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2788 -               return 0;
2789 -       }
2790 -       return 1;
2791 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2792 +
2793 +       vxdprintk(VXD_CBIT(dlim, 3),
2794 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2795 +               sb, free_blocks, root_blocks,
2796 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2797 +               sbi->s_resuid, current->fsuid, cond?0:1);
2798 +
2799 +       return (cond ? 0 : 1);
2800  }
2801  
2802  /**
2803 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2804   */
2805  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2806  {
2807 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2808 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2809                 return 0;
2810  
2811         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2812 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2813                 *errp = -EDQUOT;
2814                 return 0;
2815         }
2816 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2817 +           goto out_dlimit;
2818  
2819         sbi = EXT3_SB(sb);
2820         es = EXT3_SB(sb)->s_es;
2821 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2822         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2823                 my_rsv = &block_i->rsv_window_node;
2824  
2825 -       if (!ext3_has_free_blocks(sbi)) {
2826 +       if (!ext3_has_free_blocks(sb)) {
2827                 *errp = -ENOSPC;
2828                 goto out;
2829         }
2830 @@ -1715,12 +1736,16 @@ allocated:
2831         *errp = 0;
2832         brelse(bitmap_bh);
2833         DQUOT_FREE_BLOCK(inode, *count-num);
2834 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2835         *count = num;
2836         return ret_block;
2837  
2838  io_error:
2839         *errp = -EIO;
2840  out:
2841 +       if (!performed_allocation)
2842 +               DLIMIT_FREE_BLOCK(inode, *count);
2843 +out_dlimit:
2844         if (fatal) {
2845                 *errp = fatal;
2846                 ext3_std_error(sb, fatal);
2847 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/file.c
2848 --- linux-2.6.27.10/fs/ext3/file.c      2008-07-13 23:51:29.000000000 +0200
2849 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/file.c 2008-10-13 14:54:20.000000000 +0200
2850 @@ -134,5 +134,6 @@ const struct inode_operations ext3_file_
2851         .removexattr    = generic_removexattr,
2852  #endif
2853         .permission     = ext3_permission,
2854 +       .sync_flags     = ext3_sync_flags,
2855  };
2856  
2857 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/ialloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/ialloc.c
2858 --- linux-2.6.27.10/fs/ext3/ialloc.c    2008-10-13 14:52:05.000000000 +0200
2859 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/ialloc.c       2008-10-13 14:54:20.000000000 +0200
2860 @@ -23,6 +23,8 @@
2861  #include <linux/buffer_head.h>
2862  #include <linux/random.h>
2863  #include <linux/bitops.h>
2864 +#include <linux/vs_dlimit.h>
2865 +#include <linux/vs_tag.h>
2866  
2867  #include <asm/byteorder.h>
2868  
2869 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
2870         ext3_xattr_delete_inode(handle, inode);
2871         DQUOT_FREE_INODE(inode);
2872         DQUOT_DROP(inode);
2873 +       DLIMIT_FREE_INODE(inode);
2874  
2875         is_directory = S_ISDIR(inode->i_mode);
2876  
2877 @@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
2878         inode = new_inode(sb);
2879         if (!inode)
2880                 return ERR_PTR(-ENOMEM);
2881 +
2882 +       inode->i_tag = dx_current_fstag(sb);
2883 +       if (DLIMIT_ALLOC_INODE(inode)) {
2884 +               err = -ENOSPC;
2885 +               goto out_dlimit;
2886 +       }
2887         ei = EXT3_I(inode);
2888  
2889         sbi = EXT3_SB(sb);
2890 @@ -559,7 +568,8 @@ got:
2891         ei->i_dir_start_lookup = 0;
2892         ei->i_disksize = 0;
2893  
2894 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
2895 +       ei->i_flags = EXT3_I(dir)->i_flags &
2896 +               ~(EXT3_INDEX_FL|EXT3_IXUNLINK_FL|EXT3_BARRIER_FL);
2897         if (S_ISLNK(mode))
2898                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
2899         /* dirsync only applies to directories */
2900 @@ -614,6 +624,8 @@ got:
2901  fail:
2902         ext3_std_error(sb, err);
2903  out:
2904 +       DLIMIT_FREE_INODE(inode);
2905 +out_dlimit:
2906         iput(inode);
2907         ret = ERR_PTR(err);
2908  really_out:
2909 @@ -625,6 +637,7 @@ fail_free_drop:
2910  
2911  fail_drop:
2912         DQUOT_DROP(inode);
2913 +       DLIMIT_FREE_INODE(inode);
2914         inode->i_flags |= S_NOQUOTA;
2915         inode->i_nlink = 0;
2916         iput(inode);
2917 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/inode.c
2918 --- linux-2.6.27.10/fs/ext3/inode.c     2008-10-13 14:52:05.000000000 +0200
2919 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/ext3/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/ioctl.c
3128 --- linux-2.6.27.10/fs/ext3/ioctl.c     2008-07-13 23:51:29.000000000 +0200
3129 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/ioctl.c        2008-10-13 14:54:20.000000000 +0200
3130 @@ -8,6 +8,7 @@
3131   */
3132  
3133  #include <linux/fs.h>
3134 +#include <linux/mount.h>
3135  #include <linux/jbd.h>
3136  #include <linux/capability.h>
3137  #include <linux/ext3_fs.h>
3138 @@ -16,6 +17,7 @@
3139  #include <linux/time.h>
3140  #include <linux/compat.h>
3141  #include <linux/smp_lock.h>
3142 +#include <linux/vs_tag.h>
3143  #include <asm/uaccess.h>
3144  
3145  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
3146 @@ -56,6 +58,11 @@ int ext3_ioctl (struct inode * inode, st
3147                 if (!S_ISDIR(inode->i_mode))
3148                         flags &= ~EXT3_DIRSYNC_FL;
3149  
3150 +               if (IS_BARRIER(inode)) {
3151 +                       vxwprintk_task(1, "messing with the barrier.");
3152 +                       return -EACCES;
3153 +               }
3154 +
3155                 mutex_lock(&inode->i_mutex);
3156                 /* Is it quota file? Do not allow user to mess with it */
3157                 if (IS_NOQUOTA(inode)) {
3158 @@ -74,7 +81,9 @@ int ext3_ioctl (struct inode * inode, st
3159                  *
3160                  * This test looks nicer. Thanks to Pauline Middelink
3161                  */
3162 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3163 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3164 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3165 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3166                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3167                                 mutex_unlock(&inode->i_mutex);
3168                                 err = -EPERM;
3169 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/namei.c
3170 --- linux-2.6.27.10/fs/ext3/namei.c     2008-10-13 14:52:05.000000000 +0200
3171 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/ext3/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/super.c
3203 --- linux-2.6.27.10/fs/ext3/super.c     2008-12-19 12:03:13.000000000 +0100
3204 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/super.c        2008-11-17 18:20:41.000000000 +0100
3205 @@ -757,7 +757,7 @@ enum {
3206         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3207         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3208         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3209 -       Opt_grpquota
3210 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3211  };
3212  
3213  static match_table_t tokens = {
3214 @@ -808,6 +808,9 @@ static match_table_t tokens = {
3215         {Opt_usrquota, "usrquota"},
3216         {Opt_barrier, "barrier=%u"},
3217         {Opt_resize, "resize"},
3218 +       {Opt_tag, "tag"},
3219 +       {Opt_notag, "notag"},
3220 +       {Opt_tagid, "tagid=%u"},
3221         {Opt_err, NULL},
3222  };
3223  
3224 @@ -900,6 +903,20 @@ static int parse_options (char *options,
3225                 case Opt_nouid32:
3226                         set_opt (sbi->s_mount_opt, NO_UID32);
3227                         break;
3228 +#ifndef CONFIG_TAGGING_NONE
3229 +               case Opt_tag:
3230 +                       set_opt (sbi->s_mount_opt, TAGGED);
3231 +                       break;
3232 +               case Opt_notag:
3233 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3234 +                       break;
3235 +#endif
3236 +#ifdef CONFIG_PROPAGATE
3237 +               case Opt_tagid:
3238 +                       /* use args[0] */
3239 +                       set_opt (sbi->s_mount_opt, TAGGED);
3240 +                       break;
3241 +#endif
3242                 case Opt_nocheck:
3243                         clear_opt (sbi->s_mount_opt, CHECK);
3244                         break;
3245 @@ -1609,6 +1626,9 @@ static int ext3_fill_super (struct super
3246                             NULL, 0))
3247                 goto failed_mount;
3248  
3249 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3250 +               sb->s_flags |= MS_TAGGED;
3251 +
3252         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3253                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3254  
3255 @@ -2446,6 +2466,13 @@ static int ext3_remount (struct super_bl
3256         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3257                 ext3_abort(sb, __func__, "Abort forced by user");
3258  
3259 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3260 +               !(sb->s_flags & MS_TAGGED)) {
3261 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3262 +                       sb->s_id);
3263 +               return -EINVAL;
3264 +       }
3265 +
3266         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3267                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3268  
3269 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/symlink.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/symlink.c
3270 --- linux-2.6.27.10/fs/ext3/symlink.c   2008-07-13 23:51:29.000000000 +0200
3271 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/symlink.c      2008-10-13 14:54:20.000000000 +0200
3272 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3273         .listxattr      = ext3_listxattr,
3274         .removexattr    = generic_removexattr,
3275  #endif
3276 +       .sync_flags     = ext3_sync_flags,
3277  };
3278  
3279  const struct inode_operations ext3_fast_symlink_inode_operations = {
3280 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3281         .listxattr      = ext3_listxattr,
3282         .removexattr    = generic_removexattr,
3283  #endif
3284 +       .sync_flags     = ext3_sync_flags,
3285  };
3286 diff -NurpP --minimal linux-2.6.27.10/fs/ext3/xattr.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/xattr.c
3287 --- linux-2.6.27.10/fs/ext3/xattr.c     2008-07-13 23:51:29.000000000 +0200
3288 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext3/xattr.c        2008-10-13 14:54:20.000000000 +0200
3289 @@ -58,6 +58,7 @@
3290  #include <linux/mbcache.h>
3291  #include <linux/quotaops.h>
3292  #include <linux/rwsem.h>
3293 +#include <linux/vs_dlimit.h>
3294  #include "xattr.h"
3295  #include "acl.h"
3296  
3297 @@ -498,6 +499,7 @@ ext3_xattr_release_block(handle_t *handl
3298                 error = ext3_journal_dirty_metadata(handle, bh);
3299                 if (IS_SYNC(inode))
3300                         handle->h_sync = 1;
3301 +                       DLIMIT_FREE_BLOCK(inode, 1);
3302                 DQUOT_FREE_BLOCK(inode, 1);
3303                 ea_bdebug(bh, "refcount now=%d; releasing",
3304                           le32_to_cpu(BHDR(bh)->h_refcount));
3305 @@ -771,11 +773,14 @@ inserted:
3306                         if (new_bh == bs->bh)
3307                                 ea_bdebug(new_bh, "keeping");
3308                         else {
3309 +                               error = -ENOSPC;
3310 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3311 +                                       goto cleanup;
3312                                 /* The old block is released after updating
3313                                    the inode. */
3314                                 error = -EDQUOT;
3315                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3316 -                                       goto cleanup;
3317 +                                       goto cleanup_dlimit;
3318                                 error = ext3_journal_get_write_access(handle,
3319                                                                       new_bh);
3320                                 if (error)
3321 @@ -849,6 +854,8 @@ cleanup:
3322  
3323  cleanup_dquot:
3324         DQUOT_FREE_BLOCK(inode, 1);
3325 +cleanup_dlimit:
3326 +       DLIMIT_FREE_BLOCK(inode, 1);
3327         goto cleanup;
3328  
3329  bad_block:
3330 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/balloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/balloc.c
3331 --- linux-2.6.27.10/fs/ext4/balloc.c    2008-10-13 14:52:05.000000000 +0200
3332 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/balloc.c       2008-10-13 14:54:20.000000000 +0200
3333 @@ -17,6 +17,8 @@
3334  #include <linux/jbd2.h>
3335  #include <linux/quotaops.h>
3336  #include <linux/buffer_head.h>
3337 +#include <linux/vs_dlimit.h>
3338 +#include <linux/vs_tag.h>
3339  #include "ext4.h"
3340  #include "ext4_jbd2.h"
3341  #include "group.h"
3342 @@ -865,8 +867,10 @@ void ext4_free_blocks(handle_t *handle, 
3343         else
3344                 ext4_mb_free_blocks(handle, inode, block, count,
3345                                                 metadata, &dquot_freed_blocks);
3346 -       if (dquot_freed_blocks)
3347 +       if (dquot_freed_blocks) {
3348 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3349                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3350 +       }
3351         return;
3352  }
3353  
3354 @@ -1726,6 +1730,8 @@ ext4_fsblk_t ext4_old_new_blocks(handle_
3355                 *errp = -EDQUOT;
3356                 return 0;
3357         }
3358 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3359 +           goto out_dlimit;
3360  
3361         sbi = EXT4_SB(sb);
3362         es = EXT4_SB(sb)->s_es;
3363 @@ -1935,12 +1941,16 @@ allocated:
3364         *errp = 0;
3365         brelse(bitmap_bh);
3366         DQUOT_FREE_BLOCK(inode, *count-num);
3367 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3368         *count = num;
3369         return ret_block;
3370  
3371  io_error:
3372         *errp = -EIO;
3373  out:
3374 +       if (!performed_allocation)
3375 +               DLIMIT_FREE_BLOCK(inode, *count);
3376 +out_dlimit:
3377         if (fatal) {
3378                 *errp = fatal;
3379                 ext4_std_error(sb, fatal);
3380 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/ext4.h linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/ext4.h
3381 --- linux-2.6.27.10/fs/ext4/ext4.h      2008-12-19 12:03:13.000000000 +0100
3382 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/ext4.h 2008-12-08 04:52:52.000000000 +0100
3383 @@ -242,8 +242,12 @@ struct flex_groups {
3384  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3385  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3386  #define EXT4_EXT_MIGRATE               0x00100000 /* Inode is migrating */
3387 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3388  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3389  
3390 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3391 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3392 +
3393  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3394  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
3395  
3396 @@ -541,6 +545,7 @@ do {                                                                               \
3397  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3398  #define EXT4_MOUNT_MBALLOC             0x4000000 /* Buddy allocation support */
3399  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3400 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
3401  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
3402  #ifndef _LINUX_EXT2_FS_H
3403  #define clear_opt(o, opt)              o &= ~EXT4_MOUNT_##opt
3404 @@ -1055,6 +1060,7 @@ int ext4_get_blocks_handle(handle_t *han
3405                                 ext4_lblk_t iblock, unsigned long maxblocks,
3406                                 struct buffer_head *bh_result,
3407                                 int create, int extend_disksize);
3408 +extern int ext4_sync_flags(struct inode *inode);
3409  
3410  extern struct inode *ext4_iget(struct super_block *, unsigned long);
3411  extern int  ext4_write_inode (struct inode *, int);
3412 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/file.c
3413 --- linux-2.6.27.10/fs/ext4/file.c      2008-10-13 14:52:05.000000000 +0200
3414 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/file.c 2008-10-13 14:54:20.000000000 +0200
3415 @@ -170,5 +170,6 @@ const struct inode_operations ext4_file_
3416  #endif
3417         .permission     = ext4_permission,
3418         .fallocate      = ext4_fallocate,
3419 +       .sync_flags     = ext4_sync_flags,
3420  };
3421  
3422 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/ialloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/ialloc.c
3423 --- linux-2.6.27.10/fs/ext4/ialloc.c    2008-12-19 12:03:13.000000000 +0100
3424 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/ialloc.c       2008-12-08 04:52:52.000000000 +0100
3425 @@ -22,6 +22,8 @@
3426  #include <linux/random.h>
3427  #include <linux/bitops.h>
3428  #include <linux/blkdev.h>
3429 +#include <linux/vs_dlimit.h>
3430 +#include <linux/vs_tag.h>
3431  #include <asm/byteorder.h>
3432  #include "ext4.h"
3433  #include "ext4_jbd2.h"
3434 @@ -196,6 +198,7 @@ void ext4_free_inode (handle_t *handle, 
3435         ext4_xattr_delete_inode(handle, inode);
3436         DQUOT_FREE_INODE(inode);
3437         DQUOT_DROP(inode);
3438 +       DLIMIT_FREE_INODE(inode);
3439  
3440         is_directory = S_ISDIR(inode->i_mode);
3441  
3442 @@ -602,6 +605,12 @@ struct inode *ext4_new_inode(handle_t *h
3443         inode = new_inode(sb);
3444         if (!inode)
3445                 return ERR_PTR(-ENOMEM);
3446 +
3447 +       inode->i_tag = dx_current_fstag(sb);
3448 +       if (DLIMIT_ALLOC_INODE(inode)) {
3449 +               err = -ENOSPC;
3450 +               goto out_dlimit;
3451 +       }
3452         ei = EXT4_I(inode);
3453  
3454         sbi = EXT4_SB(sb);
3455 @@ -810,7 +819,8 @@ got:
3456          * newly created directory and file only if -o extent mount option is
3457          * specified
3458          */
3459 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3460 +       ei->i_flags = EXT4_I(dir)->i_flags &
3461 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3462         if (S_ISLNK(mode))
3463                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3464         /* dirsync only applies to directories */
3465 @@ -866,6 +876,8 @@ got:
3466  fail:
3467         ext4_std_error(sb, err);
3468  out:
3469 +       DLIMIT_FREE_INODE(inode);
3470 +out_dlimit:
3471         iput(inode);
3472         ret = ERR_PTR(err);
3473  really_out:
3474 @@ -877,6 +889,7 @@ fail_free_drop:
3475  
3476  fail_drop:
3477         DQUOT_DROP(inode);
3478 +       DLIMIT_FREE_INODE(inode);
3479         inode->i_flags |= S_NOQUOTA;
3480         inode->i_nlink = 0;
3481         iput(inode);
3482 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/inode.c
3483 --- linux-2.6.27.10/fs/ext4/inode.c     2008-12-19 12:03:13.000000000 +0100
3484 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/inode.c        2008-12-08 04:52:52.000000000 +0100
3485 @@ -36,6 +36,7 @@
3486  #include <linux/mpage.h>
3487  #include <linux/uio.h>
3488  #include <linux/bio.h>
3489 +#include <linux/vs_tag.h>
3490  #include "ext4_jbd2.h"
3491  #include "xattr.h"
3492  #include "acl.h"
3493 @@ -3485,7 +3486,7 @@ static void ext4_free_branches(handle_t 
3494  
3495  int ext4_can_truncate(struct inode *inode)
3496  {
3497 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3498 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3499                 return 0;
3500         if (S_ISREG(inode->i_mode))
3501                 return 1;
3502 @@ -3844,37 +3845,86 @@ void ext4_set_inode_flags(struct inode *
3503  {
3504         unsigned int flags = EXT4_I(inode)->i_flags;
3505  
3506 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3507 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3508 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3509 +
3510 +       if (flags & EXT4_IMMUTABLE_FL)
3511 +               inode->i_flags |= S_IMMUTABLE;
3512 +       if (flags & EXT4_IXUNLINK_FL)
3513 +               inode->i_flags |= S_IXUNLINK;
3514 +
3515         if (flags & EXT4_SYNC_FL)
3516                 inode->i_flags |= S_SYNC;
3517         if (flags & EXT4_APPEND_FL)
3518                 inode->i_flags |= S_APPEND;
3519 -       if (flags & EXT4_IMMUTABLE_FL)
3520 -               inode->i_flags |= S_IMMUTABLE;
3521         if (flags & EXT4_NOATIME_FL)
3522                 inode->i_flags |= S_NOATIME;
3523         if (flags & EXT4_DIRSYNC_FL)
3524                 inode->i_flags |= S_DIRSYNC;
3525 +
3526 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3527 +
3528 +       if (flags & EXT4_BARRIER_FL)
3529 +               inode->i_vflags |= V_BARRIER;
3530 +       if (flags & EXT4_COW_FL)
3531 +               inode->i_vflags |= V_COW;
3532  }
3533  
3534  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3535  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3536  {
3537         unsigned int flags = ei->vfs_inode.i_flags;
3538 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3539 +
3540 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3541 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3542 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3543 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3544 +
3545 +       if (flags & S_IMMUTABLE)
3546 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3547 +       if (flags & S_IXUNLINK)
3548 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3549  
3550 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3551 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3552         if (flags & S_SYNC)
3553                 ei->i_flags |= EXT4_SYNC_FL;
3554         if (flags & S_APPEND)
3555                 ei->i_flags |= EXT4_APPEND_FL;
3556 -       if (flags & S_IMMUTABLE)
3557 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3558         if (flags & S_NOATIME)
3559                 ei->i_flags |= EXT4_NOATIME_FL;
3560         if (flags & S_DIRSYNC)
3561                 ei->i_flags |= EXT4_DIRSYNC_FL;
3562 +
3563 +       if (vflags & V_BARRIER)
3564 +               ei->i_flags |= EXT4_BARRIER_FL;
3565 +       if (vflags & V_COW)
3566 +               ei->i_flags |= EXT4_COW_FL;
3567  }
3568 +
3569 +int ext4_sync_flags(struct inode *inode)
3570 +{
3571 +       struct ext4_iloc iloc;
3572 +       handle_t *handle;
3573 +       int err;
3574 +
3575 +       handle = ext4_journal_start(inode, 1);
3576 +       if (IS_ERR(handle))
3577 +               return PTR_ERR(handle);
3578 +       if (IS_SYNC(inode))
3579 +               handle->h_sync = 1;
3580 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3581 +       if (err)
3582 +               goto flags_err;
3583 +
3584 +       ext4_get_inode_flags(EXT4_I(inode));
3585 +       inode->i_ctime = CURRENT_TIME;
3586 +
3587 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3588 +flags_err:
3589 +       ext4_journal_stop(handle);
3590 +       return err;
3591 +}
3592 +
3593  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3594                                         struct ext4_inode_info *ei)
3595  {
3596 @@ -3907,6 +3957,8 @@ struct inode *ext4_iget(struct super_blo
3597         struct inode *inode;
3598         long ret;
3599         int block;
3600 +       uid_t uid;
3601 +       gid_t gid;
3602  
3603         inode = iget_locked(sb, ino);
3604         if (!inode)
3605 @@ -3927,12 +3979,17 @@ struct inode *ext4_iget(struct super_blo
3606         bh = iloc.bh;
3607         raw_inode = ext4_raw_inode(&iloc);
3608         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3609 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3610 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3611 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3612 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3613         if(!(test_opt (inode->i_sb, NO_UID32))) {
3614 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3615 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3616 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3617 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3618         }
3619 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3620 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3621 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3622 +               le16_to_cpu(raw_inode->i_raw_tag));
3623 +
3624         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3625  
3626         ei->i_state = 0;
3627 @@ -4106,6 +4163,8 @@ static int ext4_do_update_inode(handle_t
3628         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3629         struct ext4_inode_info *ei = EXT4_I(inode);
3630         struct buffer_head *bh = iloc->bh;
3631 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3632 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3633         int err = 0, rc, block;
3634  
3635         /* For fields not not tracking in the in-memory inode,
3636 @@ -4116,29 +4175,32 @@ static int ext4_do_update_inode(handle_t
3637         ext4_get_inode_flags(ei);
3638         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3639         if(!(test_opt(inode->i_sb, NO_UID32))) {
3640 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3641 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3642 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3643 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3644  /*
3645   * Fix up interoperability with old kernels. Otherwise, old inodes get
3646   * re-used with the upper 16 bits of the uid/gid intact
3647   */
3648                 if(!ei->i_dtime) {
3649                         raw_inode->i_uid_high =
3650 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3651 +                               cpu_to_le16(high_16_bits(uid));
3652                         raw_inode->i_gid_high =
3653 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3654 +                               cpu_to_le16(high_16_bits(gid));
3655                 } else {
3656                         raw_inode->i_uid_high = 0;
3657                         raw_inode->i_gid_high = 0;
3658                 }
3659         } else {
3660                 raw_inode->i_uid_low =
3661 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3662 +                       cpu_to_le16(fs_high2lowuid(uid));
3663                 raw_inode->i_gid_low =
3664 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3665 +                       cpu_to_le16(fs_high2lowgid(gid));
3666                 raw_inode->i_uid_high = 0;
3667                 raw_inode->i_gid_high = 0;
3668         }
3669 +#ifdef CONFIG_TAGGING_INTERN
3670 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3671 +#endif
3672         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3673  
3674         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3675 @@ -4302,7 +4364,8 @@ int ext4_setattr(struct dentry *dentry, 
3676                 return error;
3677  
3678         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3679 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3680 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3681 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3682                 handle_t *handle;
3683  
3684                 /* (user+group)*(old+new) structure, inode write (sb,
3685 @@ -4324,6 +4387,8 @@ int ext4_setattr(struct dentry *dentry, 
3686                         inode->i_uid = attr->ia_uid;
3687                 if (attr->ia_valid & ATTR_GID)
3688                         inode->i_gid = attr->ia_gid;
3689 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3690 +                       inode->i_tag = attr->ia_tag;
3691                 error = ext4_mark_inode_dirty(handle, inode);
3692                 ext4_journal_stop(handle);
3693         }
3694 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/ioctl.c
3695 --- linux-2.6.27.10/fs/ext4/ioctl.c     2008-12-19 12:03:13.000000000 +0100
3696 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/ioctl.c        2008-12-08 04:52:52.000000000 +0100
3697 @@ -8,12 +8,14 @@
3698   */
3699  
3700  #include <linux/fs.h>
3701 +#include <linux/mount.h>
3702  #include <linux/jbd2.h>
3703  #include <linux/capability.h>
3704  #include <linux/time.h>
3705  #include <linux/compat.h>
3706  #include <linux/smp_lock.h>
3707  #include <linux/mount.h>
3708 +#include <linux/vs_tag.h>
3709  #include <asm/uaccess.h>
3710  #include "ext4_jbd2.h"
3711  #include "ext4.h"
3712 @@ -52,6 +54,11 @@ long ext4_ioctl(struct file *filp, unsig
3713                 if (!S_ISDIR(inode->i_mode))
3714                         flags &= ~EXT4_DIRSYNC_FL;
3715  
3716 +               if (IS_BARRIER(inode)) {
3717 +                       vxwprintk_task(1, "messing with the barrier.");
3718 +                       return -EACCES;
3719 +               }
3720 +
3721                 err = -EPERM;
3722                 mutex_lock(&inode->i_mutex);
3723                 /* Is it quota file? Do not allow user to mess with it */
3724 @@ -69,7 +76,9 @@ long ext4_ioctl(struct file *filp, unsig
3725                  *
3726                  * This test looks nicer. Thanks to Pauline Middelink
3727                  */
3728 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3729 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3730 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3731 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3732                         if (!capable(CAP_LINUX_IMMUTABLE))
3733                                 goto flags_out;
3734                 }
3735 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/namei.c
3736 --- linux-2.6.27.10/fs/ext4/namei.c     2008-10-13 14:52:05.000000000 +0200
3737 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/ext4/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/super.c
3769 --- linux-2.6.27.10/fs/ext4/super.c     2008-12-19 12:03:13.000000000 +0100
3770 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/super.c        2008-12-08 04:52:52.000000000 +0100
3771 @@ -907,6 +907,7 @@ enum {
3772         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3773         Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
3774         Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3775 +       Opt_tag, Opt_notag, Opt_tagid
3776  };
3777  
3778  static match_table_t tokens = {
3779 @@ -967,6 +968,9 @@ static match_table_t tokens = {
3780         {Opt_resize, "resize"},
3781         {Opt_delalloc, "delalloc"},
3782         {Opt_nodelalloc, "nodelalloc"},
3783 +       {Opt_tag, "tag"},
3784 +       {Opt_notag, "notag"},
3785 +       {Opt_tagid, "tagid=%u"},
3786         {Opt_err, NULL},
3787  };
3788  
3789 @@ -1060,6 +1064,20 @@ static int parse_options(char *options, 
3790                 case Opt_nouid32:
3791                         set_opt(sbi->s_mount_opt, NO_UID32);
3792                         break;
3793 +#ifndef CONFIG_TAGGING_NONE
3794 +               case Opt_tag:
3795 +                       set_opt (sbi->s_mount_opt, TAGGED);
3796 +                       break;
3797 +               case Opt_notag:
3798 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3799 +                       break;
3800 +#endif
3801 +#ifdef CONFIG_PROPAGATE
3802 +               case Opt_tagid:
3803 +                       /* use args[0] */
3804 +                       set_opt (sbi->s_mount_opt, TAGGED);
3805 +                       break;
3806 +#endif
3807                 case Opt_nocheck:
3808                         clear_opt(sbi->s_mount_opt, CHECK);
3809                         break;
3810 @@ -2033,6 +2051,9 @@ static int ext4_fill_super(struct super_
3811                            NULL, 0))
3812                 goto failed_mount;
3813  
3814 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3815 +               sb->s_flags |= MS_TAGGED;
3816 +
3817         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3818                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3819  
3820 @@ -3015,6 +3036,13 @@ static int ext4_remount(struct super_blo
3821         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3822                 ext4_abort(sb, __func__, "Abort forced by user");
3823  
3824 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3825 +               !(sb->s_flags & MS_TAGGED)) {
3826 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3827 +                       sb->s_id);
3828 +               return -EINVAL;
3829 +       }
3830 +
3831         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3832                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3833  
3834 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/symlink.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/symlink.c
3835 --- linux-2.6.27.10/fs/ext4/symlink.c   2008-07-13 23:51:29.000000000 +0200
3836 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/symlink.c      2008-10-13 14:54:20.000000000 +0200
3837 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
3838         .listxattr      = ext4_listxattr,
3839         .removexattr    = generic_removexattr,
3840  #endif
3841 +       .sync_flags     = ext4_sync_flags,
3842  };
3843  
3844  const struct inode_operations ext4_fast_symlink_inode_operations = {
3845 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
3846         .listxattr      = ext4_listxattr,
3847         .removexattr    = generic_removexattr,
3848  #endif
3849 +       .sync_flags     = ext4_sync_flags,
3850  };
3851 diff -NurpP --minimal linux-2.6.27.10/fs/ext4/xattr.c linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/xattr.c
3852 --- linux-2.6.27.10/fs/ext4/xattr.c     2008-12-19 12:03:13.000000000 +0100
3853 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ext4/xattr.c        2008-12-08 04:52:52.000000000 +0100
3854 @@ -56,6 +56,7 @@
3855  #include <linux/mbcache.h>
3856  #include <linux/quotaops.h>
3857  #include <linux/rwsem.h>
3858 +#include <linux/vs_dlimit.h>
3859  #include "ext4_jbd2.h"
3860  #include "ext4.h"
3861  #include "xattr.h"
3862 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3863                 error = ext4_journal_dirty_metadata(handle, bh);
3864                 if (IS_SYNC(inode))
3865                         handle->h_sync = 1;
3866 +                       DLIMIT_FREE_BLOCK(inode, 1);
3867                 DQUOT_FREE_BLOCK(inode, 1);
3868                 ea_bdebug(bh, "refcount now=%d; releasing",
3869                           le32_to_cpu(BHDR(bh)->h_refcount));
3870 @@ -780,11 +782,14 @@ inserted:
3871                         if (new_bh == bs->bh)
3872                                 ea_bdebug(new_bh, "keeping");
3873                         else {
3874 +                               error = -ENOSPC;
3875 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3876 +                                       goto cleanup;
3877                                 /* The old block is released after updating
3878                                    the inode. */
3879                                 error = -EDQUOT;
3880                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3881 -                                       goto cleanup;
3882 +                                       goto cleanup_dlimit;
3883                                 error = ext4_journal_get_write_access(handle,
3884                                                                       new_bh);
3885                                 if (error)
3886 @@ -858,6 +863,8 @@ cleanup:
3887  
3888  cleanup_dquot:
3889         DQUOT_FREE_BLOCK(inode, 1);
3890 +cleanup_dlimit:
3891 +       DLIMIT_FREE_BLOCK(inode, 1);
3892         goto cleanup;
3893  
3894  bad_block:
3895 diff -NurpP --minimal linux-2.6.27.10/fs/fcntl.c linux-2.6.27.10-vs2.3.0.36.4/fs/fcntl.c
3896 --- linux-2.6.27.10/fs/fcntl.c  2008-12-19 12:03:13.000000000 +0100
3897 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/fcntl.c     2008-12-19 12:12:04.000000000 +0100
3898 @@ -20,6 +20,7 @@
3899  #include <linux/rcupdate.h>
3900  #include <linux/pid_namespace.h>
3901  #include <linux/smp_lock.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  #include <asm/poll.h>
3905  #include <asm/siginfo.h>
3906 @@ -103,6 +104,8 @@ 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 @@ -342,6 +345,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.10/fs/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/file.c
3925 --- linux-2.6.27.10/fs/file.c   2008-10-13 14:52:05.000000000 +0200
3926 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/file.c      2008-10-24 04:44:48.000000000 +0200
3927 @@ -19,6 +19,7 @@
3928  #include <linux/spinlock.h>
3929  #include <linux/rcupdate.h>
3930  #include <linux/workqueue.h>
3931 +#include <linux/vs_limit.h>
3932  
3933  struct fdtable_defer {
3934         spinlock_t lock;
3935 @@ -367,6 +368,8 @@ struct files_struct *dup_fd(struct files
3936                 struct file *f = *old_fds++;
3937                 if (f) {
3938                         get_file(f);
3939 +                       /* TODO: sum it first for check and performance */
3940 +                       vx_openfd_inc(open_files - i);
3941                 } else {
3942                         /*
3943                          * The fd may be claimed in the fd bitmap but not yet
3944 @@ -475,6 +478,7 @@ repeat:
3945         else
3946                 FD_CLR(fd, fdt->close_on_exec);
3947         error = fd;
3948 +       vx_openfd_inc(fd);
3949  #if 1
3950         /* Sanity check */
3951         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3952 diff -NurpP --minimal linux-2.6.27.10/fs/file_table.c linux-2.6.27.10-vs2.3.0.36.4/fs/file_table.c
3953 --- linux-2.6.27.10/fs/file_table.c     2008-10-13 14:52:05.000000000 +0200
3954 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/file_table.c        2008-10-13 14:54:20.000000000 +0200
3955 @@ -21,6 +21,8 @@
3956  #include <linux/fsnotify.h>
3957  #include <linux/sysctl.h>
3958  #include <linux/percpu_counter.h>
3959 +#include <linux/vs_limit.h>
3960 +#include <linux/vs_context.h>
3961  
3962  #include <asm/atomic.h>
3963  
3964 @@ -126,6 +128,8 @@ struct file *get_empty_filp(void)
3965         f->f_gid = tsk->fsgid;
3966         eventpoll_init_file(f);
3967         /* f->f_version: 0 */
3968 +       f->f_xid = vx_current_xid();
3969 +       vx_files_inc(f);
3970         return f;
3971  
3972  over:
3973 @@ -276,6 +280,8 @@ void __fput(struct file *file)
3974                 cdev_put(inode->i_cdev);
3975         fops_put(file->f_op);
3976         put_pid(file->f_owner.pid);
3977 +       vx_files_dec(file);
3978 +       file->f_xid = 0;
3979         file_kill(file);
3980         if (file->f_mode & FMODE_WRITE)
3981                 drop_file_write_access(file);
3982 @@ -343,6 +349,8 @@ void put_filp(struct file *file)
3983  {
3984         if (atomic_long_dec_and_test(&file->f_count)) {
3985                 security_file_free(file);
3986 +               vx_files_dec(file);
3987 +               file->f_xid = 0;
3988                 file_kill(file);
3989                 file_free(file);
3990         }
3991 diff -NurpP --minimal linux-2.6.27.10/fs/hfsplus/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/hfsplus/ioctl.c
3992 --- linux-2.6.27.10/fs/hfsplus/ioctl.c  2008-07-13 23:51:29.000000000 +0200
3993 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/hfsplus/ioctl.c     2008-10-13 14:54:20.000000000 +0200
3994 @@ -17,6 +17,7 @@
3995  #include <linux/mount.h>
3996  #include <linux/sched.h>
3997  #include <linux/xattr.h>
3998 +#include <linux/mount.h>
3999  #include <asm/uaccess.h>
4000  #include "hfsplus_fs.h"
4001  
4002 diff -NurpP --minimal linux-2.6.27.10/fs/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/inode.c
4003 --- linux-2.6.27.10/fs/inode.c  2008-10-13 14:52:05.000000000 +0200
4004 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/inode.c     2008-10-13 14:54:20.000000000 +0200
4005 @@ -124,6 +124,9 @@ static struct inode *alloc_inode(struct 
4006                 struct address_space * const mapping = &inode->i_data;
4007  
4008                 inode->i_sb = sb;
4009 +
4010 +               /* essential because of inode slab reuse */
4011 +               inode->i_tag = 0;
4012                 inode->i_blkbits = sb->s_blocksize_bits;
4013                 inode->i_flags = 0;
4014                 atomic_set(&inode->i_count, 1);
4015 @@ -142,6 +145,7 @@ static struct inode *alloc_inode(struct 
4016                 inode->i_bdev = NULL;
4017                 inode->i_cdev = NULL;
4018                 inode->i_rdev = 0;
4019 +               inode->i_mdev = 0;
4020                 inode->dirtied_when = 0;
4021                 if (security_inode_alloc(inode)) {
4022                         if (inode->i_sb->s_op->destroy_inode)
4023 @@ -247,6 +251,8 @@ void __iget(struct inode * inode)
4024         inodes_stat.nr_unused--;
4025  }
4026  
4027 +EXPORT_SYMBOL_GPL(__iget);
4028 +
4029  /**
4030   * clear_inode - clear an inode
4031   * @inode: inode to clear
4032 @@ -1427,9 +1433,11 @@ void init_special_inode(struct inode *in
4033         if (S_ISCHR(mode)) {
4034                 inode->i_fop = &def_chr_fops;
4035                 inode->i_rdev = rdev;
4036 +               inode->i_mdev = rdev;
4037         } else if (S_ISBLK(mode)) {
4038                 inode->i_fop = &def_blk_fops;
4039                 inode->i_rdev = rdev;
4040 +               inode->i_mdev = rdev;
4041         } else if (S_ISFIFO(mode))
4042                 inode->i_fop = &def_fifo_fops;
4043         else if (S_ISSOCK(mode))
4044 diff -NurpP --minimal linux-2.6.27.10/fs/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/ioctl.c
4045 --- linux-2.6.27.10/fs/ioctl.c  2008-12-19 12:03:13.000000000 +0100
4046 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ioctl.c     2008-12-19 12:09:13.000000000 +0100
4047 @@ -13,6 +13,9 @@
4048  #include <linux/security.h>
4049  #include <linux/module.h>
4050  #include <linux/uaccess.h>
4051 +#include <linux/proc_fs.h>
4052 +#include <linux/vserver/inode.h>
4053 +#include <linux/vs_tag.h>
4054  
4055  #include <asm/ioctls.h>
4056  
4057 diff -NurpP --minimal linux-2.6.27.10/fs/ioprio.c linux-2.6.27.10-vs2.3.0.36.4/fs/ioprio.c
4058 --- linux-2.6.27.10/fs/ioprio.c 2008-10-13 14:52:05.000000000 +0200
4059 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/jfs/acl.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/acl.c
4087 --- linux-2.6.27.10/fs/jfs/acl.c        2008-10-13 14:52:05.000000000 +0200
4088 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/acl.c   2008-10-13 14:54:20.000000000 +0200
4089 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
4090                 return rc;
4091  
4092         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4093 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4094 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4095 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4096                 if (DQUOT_TRANSFER(inode, iattr))
4097                         return -EDQUOT;
4098         }
4099 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/file.c
4100 --- linux-2.6.27.10/fs/jfs/file.c       2008-07-13 23:51:29.000000000 +0200
4101 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/file.c  2008-10-13 14:54:20.000000000 +0200
4102 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4103         .setattr        = jfs_setattr,
4104         .permission     = jfs_permission,
4105  #endif
4106 +       .sync_flags     = jfs_sync_flags,
4107  };
4108  
4109  const struct file_operations jfs_file_operations = {
4110 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/inode.c
4111 --- linux-2.6.27.10/fs/jfs/inode.c      2008-07-13 23:51:29.000000000 +0200
4112 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/inode.c 2008-10-13 14:54:20.000000000 +0200
4113 @@ -22,6 +22,7 @@
4114  #include <linux/buffer_head.h>
4115  #include <linux/pagemap.h>
4116  #include <linux/quotaops.h>
4117 +#include <linux/vs_dlimit.h>
4118  #include "jfs_incore.h"
4119  #include "jfs_inode.h"
4120  #include "jfs_filsys.h"
4121 @@ -155,6 +156,7 @@ void jfs_delete_inode(struct inode *inod
4122                 DQUOT_INIT(inode);
4123                 DQUOT_FREE_INODE(inode);
4124                 DQUOT_DROP(inode);
4125 +               DLIMIT_FREE_INODE(inode);
4126         }
4127  
4128         clear_inode(inode);
4129 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/ioctl.c
4130 --- linux-2.6.27.10/fs/jfs/ioctl.c      2008-07-13 23:51:29.000000000 +0200
4131 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/ioctl.c 2008-10-13 14:54:20.000000000 +0200
4132 @@ -11,6 +11,7 @@
4133  #include <linux/mount.h>
4134  #include <linux/time.h>
4135  #include <linux/sched.h>
4136 +#include <linux/mount.h>
4137  #include <asm/current.h>
4138  #include <asm/uaccess.h>
4139  
4140 @@ -85,6 +86,11 @@ long jfs_ioctl(struct file *filp, unsign
4141                 if (!S_ISDIR(inode->i_mode))
4142                         flags &= ~JFS_DIRSYNC_FL;
4143  
4144 +               if (IS_BARRIER(inode)) {
4145 +                       vxwprintk_task(1, "messing with the barrier.");
4146 +                       return -EACCES;
4147 +               }
4148 +
4149                 /* Is it quota file? Do not allow user to mess with it */
4150                 if (IS_NOQUOTA(inode)) {
4151                         err = -EPERM;
4152 @@ -102,8 +108,8 @@ long jfs_ioctl(struct file *filp, unsign
4153                  * the relevant capability.
4154                  */
4155                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4156 -                       ((flags ^ oldflags) &
4157 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4158 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4159 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4160                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4161                                 mutex_unlock(&inode->i_mutex);
4162                                 err = -EPERM;
4163 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_dinode.h linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_dinode.h
4164 --- linux-2.6.27.10/fs/jfs/jfs_dinode.h 2008-07-13 23:51:29.000000000 +0200
4165 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_dinode.h    2008-10-31 18:15:18.000000000 +0100
4166 @@ -161,9 +161,13 @@ struct dinode {
4167  
4168  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4169  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4170 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4171  
4172 -#define JFS_FL_USER_VISIBLE    0x03F80000
4173 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4174 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4175 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4176 +
4177 +#define JFS_FL_USER_VISIBLE    0x07F80000
4178 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4179  #define JFS_FL_INHERIT         0x03C80000
4180  
4181  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4182 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_dtree.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_dtree.c
4183 --- linux-2.6.27.10/fs/jfs/jfs_dtree.c  2008-07-13 23:51:29.000000000 +0200
4184 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_dtree.c     2008-10-13 14:54:20.000000000 +0200
4185 @@ -102,6 +102,7 @@
4186  
4187  #include <linux/fs.h>
4188  #include <linux/quotaops.h>
4189 +#include <linux/vs_dlimit.h>
4190  #include "jfs_incore.h"
4191  #include "jfs_superblock.h"
4192  #include "jfs_filsys.h"
4193 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
4194                  */
4195                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4196                         goto clean_up;
4197 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4198 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4199 -                       goto clean_up;
4200 -               }
4201 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4202 +                       goto clean_up_dquot;
4203 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4204 +                       goto clean_up_dlimit;
4205  
4206                 /*
4207                  * Save the table, we're going to overwrite it with the
4208 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
4209  
4210         return index;
4211  
4212 +      clean_up_dlimit:
4213 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4214 +
4215 +      clean_up_dquot:
4216 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4217 +
4218        clean_up:
4219  
4220         jfs_ip->next_index--;
4221 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
4222         struct tlock *tlck;
4223         struct lv *lv;
4224         int quota_allocation = 0;
4225 +       int dlimit_allocation = 0;
4226  
4227         /* get split page */
4228         smp = split->mp;
4229 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
4230                 }
4231                 quota_allocation += n;
4232  
4233 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4234 +                       rc = -ENOSPC;
4235 +                       goto extendOut;
4236 +               }
4237 +               dlimit_allocation += n;
4238 +
4239                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4240                                     (s64) n, &nxaddr)))
4241                         goto extendOut;
4242 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
4243        freeKeyName:
4244         kfree(key.name);
4245  
4246 +       /* Rollback dlimit allocation */
4247 +       if (rc && dlimit_allocation)
4248 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4249         /* Rollback quota allocation */
4250         if (rc && quota_allocation)
4251                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4252 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4253                 release_metapage(rmp);
4254                 return -EDQUOT;
4255         }
4256 +       /* Allocate blocks to dlimit. */
4257 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4258 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4259 +               release_metapage(rmp);
4260 +               return -ENOSPC;
4261 +       }
4262  
4263         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4264  
4265 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
4266                 release_metapage(rmp);
4267                 return -EDQUOT;
4268         }
4269 +       /* Allocate blocks to dlimit. */
4270 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4271 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4272 +               release_metapage(rmp);
4273 +               return -ENOSPC;
4274 +       }
4275  
4276         BT_MARK_DIRTY(rmp, ip);
4277         /*
4278 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4279  
4280         xlen = lengthPXD(&fp->header.self);
4281  
4282 +       /* Free dlimit allocation. */
4283 +       DLIMIT_FREE_BLOCK(ip, xlen);
4284         /* Free quota allocation. */
4285         DQUOT_FREE_BLOCK(ip, xlen);
4286  
4287 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4288  
4289                                 xlen = lengthPXD(&p->header.self);
4290  
4291 +                               /* Free dlimit allocation */
4292 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4293                                 /* Free quota allocation */
4294                                 DQUOT_FREE_BLOCK(ip, xlen);
4295  
4296 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_extent.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_extent.c
4297 --- linux-2.6.27.10/fs/jfs/jfs_extent.c 2008-07-13 23:51:29.000000000 +0200
4298 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_extent.c    2008-10-13 14:54:20.000000000 +0200
4299 @@ -18,6 +18,7 @@
4300  
4301  #include <linux/fs.h>
4302  #include <linux/quotaops.h>
4303 +#include <linux/vs_dlimit.h>
4304  #include "jfs_incore.h"
4305  #include "jfs_inode.h"
4306  #include "jfs_superblock.h"
4307 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4308                 return -EDQUOT;
4309         }
4310  
4311 +       /* Allocate blocks to dlimit. */
4312 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4313 +               DQUOT_FREE_BLOCK(ip, nxlen);
4314 +               dbFree(ip, nxaddr, (s64) nxlen);
4315 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4316 +               return -ENOSPC;
4317 +       }
4318 +
4319         /* determine the value of the extent flag */
4320         xflag = abnr ? XAD_NOTRECORDED : 0;
4321  
4322 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4323          */
4324         if (rc) {
4325                 dbFree(ip, nxaddr, nxlen);
4326 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4327                 DQUOT_FREE_BLOCK(ip, nxlen);
4328                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4329                 return (rc);
4330 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4331                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4332                 return -EDQUOT;
4333         }
4334 +       /* Allocate blocks to dlimit. */
4335 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4336 +               DQUOT_FREE_BLOCK(ip, nxlen);
4337 +               dbFree(ip, nxaddr, (s64) nxlen);
4338 +               up(&JFS_IP(ip)->commit_sem);
4339 +               return -ENOSPC;
4340 +       }
4341  
4342         delta = nxlen - xlen;
4343  
4344 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4345                 /* extend the extent */
4346                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4347                         dbFree(ip, xaddr + xlen, delta);
4348 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4349                         DQUOT_FREE_BLOCK(ip, nxlen);
4350                         goto exit;
4351                 }
4352 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4353                  */
4354                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4355                         dbFree(ip, nxaddr, nxlen);
4356 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4357                         DQUOT_FREE_BLOCK(ip, nxlen);
4358                         goto exit;
4359                 }
4360 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_filsys.h linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_filsys.h
4361 --- linux-2.6.27.10/fs/jfs/jfs_filsys.h 2008-07-13 23:51:29.000000000 +0200
4362 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_filsys.h    2008-10-13 14:54:20.000000000 +0200
4363 @@ -263,6 +263,7 @@
4364  #define JFS_NAME_MAX   255
4365  #define JFS_PATH_MAX   BPSIZE
4366  
4367 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4368  
4369  /*
4370   *     file system state (superblock state)
4371 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_imap.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_imap.c
4372 --- linux-2.6.27.10/fs/jfs/jfs_imap.c   2008-10-13 14:52:05.000000000 +0200
4373 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_imap.c      2008-10-13 14:54:20.000000000 +0200
4374 @@ -45,6 +45,7 @@
4375  #include <linux/buffer_head.h>
4376  #include <linux/pagemap.h>
4377  #include <linux/quotaops.h>
4378 +#include <linux/vs_tag.h>
4379  
4380  #include "jfs_incore.h"
4381  #include "jfs_inode.h"
4382 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
4383  {
4384         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4385         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4386 +       uid_t uid;
4387 +       gid_t gid;
4388  
4389         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4390         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4391 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
4392         }
4393         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4394  
4395 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4396 +       uid = le32_to_cpu(dip->di_uid);
4397 +       gid = le32_to_cpu(dip->di_gid);
4398 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4399 +
4400 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4401         if (sbi->uid == -1)
4402                 ip->i_uid = jfs_ip->saved_uid;
4403         else {
4404                 ip->i_uid = sbi->uid;
4405         }
4406  
4407 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4408 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4409         if (sbi->gid == -1)
4410                 ip->i_gid = jfs_ip->saved_gid;
4411         else {
4412 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
4413         dip->di_size = cpu_to_le64(ip->i_size);
4414         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4415         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4416 -       if (sbi->uid == -1)
4417 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4418 -       else
4419 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4420 -       if (sbi->gid == -1)
4421 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4422 -       else
4423 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4424 +
4425 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4426 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4427 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4428 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4429 +
4430         jfs_get_inode_flags(jfs_ip);
4431         /*
4432          * mode2 is only needed for storing the higher order bits.
4433 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_inode.c
4434 --- linux-2.6.27.10/fs/jfs/jfs_inode.c  2008-07-13 23:51:29.000000000 +0200
4435 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_inode.c     2008-10-13 14:54:20.000000000 +0200
4436 @@ -18,6 +18,8 @@
4437  
4438  #include <linux/fs.h>
4439  #include <linux/quotaops.h>
4440 +#include <linux/vs_dlimit.h>
4441 +#include <linux/vs_tag.h>
4442  #include "jfs_incore.h"
4443  #include "jfs_inode.h"
4444  #include "jfs_filsys.h"
4445 @@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
4446  {
4447         unsigned int flags = JFS_IP(inode)->mode2;
4448  
4449 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4450 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4451 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4452 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4453  
4454         if (flags & JFS_IMMUTABLE_FL)
4455                 inode->i_flags |= S_IMMUTABLE;
4456 +       if (flags & JFS_IXUNLINK_FL)
4457 +               inode->i_flags |= S_IXUNLINK;
4458 +
4459 +       if (flags & JFS_SYNC_FL)
4460 +               inode->i_flags |= S_SYNC;
4461         if (flags & JFS_APPEND_FL)
4462                 inode->i_flags |= S_APPEND;
4463         if (flags & JFS_NOATIME_FL)
4464                 inode->i_flags |= S_NOATIME;
4465         if (flags & JFS_DIRSYNC_FL)
4466                 inode->i_flags |= S_DIRSYNC;
4467 -       if (flags & JFS_SYNC_FL)
4468 -               inode->i_flags |= S_SYNC;
4469 +
4470 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4471 +
4472 +       if (flags & JFS_BARRIER_FL)
4473 +               inode->i_vflags |= V_BARRIER;
4474 +       if (flags & JFS_COW_FL)
4475 +               inode->i_vflags |= V_COW;
4476  }
4477  
4478  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4479  {
4480         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4481 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4482 +
4483 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4484 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4485 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4486 +                          JFS_BARRIER_FL | JFS_COW_FL);
4487  
4488 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4489 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4490         if (flags & S_IMMUTABLE)
4491                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4492 +       if (flags & S_IXUNLINK)
4493 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4494 +
4495         if (flags & S_APPEND)
4496                 jfs_ip->mode2 |= JFS_APPEND_FL;
4497         if (flags & S_NOATIME)
4498 @@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
4499                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4500         if (flags & S_SYNC)
4501                 jfs_ip->mode2 |= JFS_SYNC_FL;
4502 +
4503 +       if (vflags & V_BARRIER)
4504 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4505 +       if (vflags & V_COW)
4506 +               jfs_ip->mode2 |= JFS_COW_FL;
4507 +}
4508 +
4509 +int jfs_sync_flags(struct inode *inode)
4510 +{
4511 +       jfs_get_inode_flags(JFS_IP(inode));
4512 +       inode->i_ctime = CURRENT_TIME;
4513 +       mark_inode_dirty(inode);
4514 +       return 0;
4515  }
4516  
4517  /*
4518 @@ -108,10 +140,17 @@ struct inode *ialloc(struct inode *paren
4519         jfs_inode->saved_uid = inode->i_uid;
4520         jfs_inode->saved_gid = inode->i_gid;
4521  
4522 +       inode->i_tag = dx_current_fstag(sb);
4523 +       if (DLIMIT_ALLOC_INODE(inode)) {
4524 +               iput(inode);
4525 +               return ERR_PTR(-ENOSPC);
4526 +       }
4527 +
4528         /*
4529          * Allocate inode to quota.
4530          */
4531         if (DQUOT_ALLOC_INODE(inode)) {
4532 +               DLIMIT_FREE_INODE(inode);
4533                 DQUOT_DROP(inode);
4534                 inode->i_flags |= S_NOQUOTA;
4535                 inode->i_nlink = 0;
4536 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_inode.h linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_inode.h
4537 --- linux-2.6.27.10/fs/jfs/jfs_inode.h  2008-07-13 23:51:29.000000000 +0200
4538 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_inode.h     2008-10-13 14:54:20.000000000 +0200
4539 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4540  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4541         int fh_len, int fh_type);
4542  extern void jfs_set_inode_flags(struct inode *);
4543 +extern int jfs_sync_flags(struct inode *);
4544  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4545  
4546  extern const struct address_space_operations jfs_aops;
4547 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/jfs_xtree.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_xtree.c
4548 --- linux-2.6.27.10/fs/jfs/jfs_xtree.c  2008-10-13 14:52:05.000000000 +0200
4549 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/jfs_xtree.c     2008-10-13 14:54:20.000000000 +0200
4550 @@ -23,6 +23,7 @@
4551  #include <linux/module.h>
4552  #include <linux/quotaops.h>
4553  #include <linux/seq_file.h>
4554 +#include <linux/vs_dlimit.h>
4555  #include "jfs_incore.h"
4556  #include "jfs_filsys.h"
4557  #include "jfs_metapage.h"
4558 @@ -848,7 +849,12 @@ int xtInsert(tid_t tid,            /* transaction 
4559                         hint = 0;
4560                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4561                         goto out;
4562 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4563 +                       DQUOT_FREE_BLOCK(ip, xlen);
4564 +                       goto out;
4565 +               }
4566                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4567 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4568                         DQUOT_FREE_BLOCK(ip, xlen);
4569                         goto out;
4570                 }
4571 @@ -878,6 +884,7 @@ int xtInsert(tid_t tid,             /* transaction 
4572                         /* undo data extent allocation */
4573                         if (*xaddrp == 0) {
4574                                 dbFree(ip, xaddr, (s64) xlen);
4575 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4576                                 DQUOT_FREE_BLOCK(ip, xlen);
4577                         }
4578                         return rc;
4579 @@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4580         struct tlock *tlck;
4581         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4582         int quota_allocation = 0;
4583 +       int dlimit_allocation = 0;
4584  
4585         smp = split->mp;
4586         sp = XT_PAGE(ip, smp);
4587 @@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4588  
4589         quota_allocation += lengthPXD(pxd);
4590  
4591 +       /* Allocate blocks to dlimit. */
4592 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4593 +              rc = -ENOSPC;
4594 +              goto clean_up;
4595 +       }
4596 +       dlimit_allocation += lengthPXD(pxd);
4597 +
4598         /*
4599          * allocate the new right page for the split
4600          */
4601 @@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4602  
4603        clean_up:
4604  
4605 +       /* Rollback dlimit allocation. */
4606 +       if (dlimit_allocation)
4607 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4608         /* Rollback quota allocation. */
4609         if (quota_allocation)
4610                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4611 @@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
4612                 release_metapage(rmp);
4613                 return -EDQUOT;
4614         }
4615 +       /* Allocate blocks to dlimit. */
4616 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4617 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4618 +               release_metapage(rmp);
4619 +               return -ENOSPC;
4620 +       }
4621  
4622         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4623  
4624 @@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4625         else
4626                 ip->i_size = newsize;
4627  
4628 +       /* update dlimit allocation to reflect freed blocks */
4629 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4630         /* update quota allocation to reflect freed blocks */
4631         DQUOT_FREE_BLOCK(ip, nfreed);
4632  
4633 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/namei.c
4634 --- linux-2.6.27.10/fs/jfs/namei.c      2008-10-13 14:52:05.000000000 +0200
4635 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/namei.c 2008-10-13 14:54:20.000000000 +0200
4636 @@ -21,6 +21,7 @@
4637  #include <linux/ctype.h>
4638  #include <linux/quotaops.h>
4639  #include <linux/exportfs.h>
4640 +#include <linux/vs_tag.h>
4641  #include "jfs_incore.h"
4642  #include "jfs_superblock.h"
4643  #include "jfs_inode.h"
4644 @@ -1468,6 +1469,7 @@ static struct dentry *jfs_lookup(struct 
4645                 return ERR_CAST(ip);
4646         }
4647  
4648 +       dx_propagate_tag(nd, ip);
4649         dentry = d_splice_alias(ip, dentry);
4650  
4651         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4652 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
4653         .setattr        = jfs_setattr,
4654         .permission     = jfs_permission,
4655  #endif
4656 +       .sync_flags     = jfs_sync_flags,
4657  };
4658  
4659  const struct file_operations jfs_dir_operations = {
4660 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/super.c
4661 --- linux-2.6.27.10/fs/jfs/super.c      2008-10-13 14:52:05.000000000 +0200
4662 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/super.c 2008-10-13 14:54:20.000000000 +0200
4663 @@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
4664  enum {
4665         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4666         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4667 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4668 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4669 +       Opt_tag, Opt_notag, Opt_tagid
4670  };
4671  
4672  static match_table_t tokens = {
4673 @@ -206,6 +207,10 @@ static match_table_t tokens = {
4674         {Opt_resize, "resize=%u"},
4675         {Opt_resize_nosize, "resize"},
4676         {Opt_errors, "errors=%s"},
4677 +       {Opt_tag, "tag"},
4678 +       {Opt_notag, "notag"},
4679 +       {Opt_tagid, "tagid=%u"},
4680 +       {Opt_tag, "tagxid"},
4681         {Opt_ignore, "noquota"},
4682         {Opt_ignore, "quota"},
4683         {Opt_usrquota, "usrquota"},
4684 @@ -340,6 +345,20 @@ static int parse_options(char *options, 
4685                         }
4686                         break;
4687                 }
4688 +#ifndef CONFIG_TAGGING_NONE
4689 +               case Opt_tag:
4690 +                       *flag |= JFS_TAGGED;
4691 +                       break;
4692 +               case Opt_notag:
4693 +                       *flag &= JFS_TAGGED;
4694 +                       break;
4695 +#endif
4696 +#ifdef CONFIG_PROPAGATE
4697 +               case Opt_tagid:
4698 +                       /* use args[0] */
4699 +                       *flag |= JFS_TAGGED;
4700 +                       break;
4701 +#endif
4702                 default:
4703                         printk("jfs: Unrecognized mount option \"%s\" "
4704                                         " or missing value\n", p);
4705 @@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
4706         if (!parse_options(data, sb, &newLVSize, &flag)) {
4707                 return -EINVAL;
4708         }
4709 +
4710 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4711 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4712 +                       sb->s_id);
4713 +               return -EINVAL;
4714 +       }
4715 +
4716         if (newLVSize) {
4717                 if (sb->s_flags & MS_RDONLY) {
4718                         printk(KERN_ERR
4719 @@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
4720  #ifdef CONFIG_JFS_POSIX_ACL
4721         sb->s_flags |= MS_POSIXACL;
4722  #endif
4723 +       /* map mount option tagxid */
4724 +       if (sbi->flag & JFS_TAGGED)
4725 +               sb->s_flags |= MS_TAGGED;
4726  
4727         if (newLVSize) {
4728                 printk(KERN_ERR "resize option for remount only\n");
4729 diff -NurpP --minimal linux-2.6.27.10/fs/jfs/xattr.c linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/xattr.c
4730 --- linux-2.6.27.10/fs/jfs/xattr.c      2008-07-13 23:51:29.000000000 +0200
4731 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/jfs/xattr.c 2008-10-13 14:54:20.000000000 +0200
4732 @@ -23,6 +23,7 @@
4733  #include <linux/posix_acl_xattr.h>
4734  #include <linux/quotaops.h>
4735  #include <linux/security.h>
4736 +#include <linux/vs_dlimit.h>
4737  #include "jfs_incore.h"
4738  #include "jfs_superblock.h"
4739  #include "jfs_dmap.h"
4740 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
4741         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
4742                 return -EDQUOT;
4743         }
4744 +       /* Allocate new blocks to dlimit. */
4745 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
4746 +               DQUOT_FREE_BLOCK(ip, nblocks);
4747 +               return -ENOSPC;
4748 +       }
4749  
4750         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
4751         if (rc) {
4752 +               /*Rollback dlimit allocation. */
4753 +               DLIMIT_FREE_BLOCK(ip, nblocks);
4754                 /*Rollback quota allocation. */
4755                 DQUOT_FREE_BLOCK(ip, nblocks);
4756                 return rc;
4757 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
4758  
4759        failed:
4760         /* Rollback quota allocation. */
4761 +       DLIMIT_FREE_BLOCK(ip, nblocks);
4762 +       /* Rollback quota allocation. */
4763         DQUOT_FREE_BLOCK(ip, nblocks);
4764  
4765         dbFree(ip, blkno, nblocks);
4766 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
4767         s64 blkno;
4768         int rc;
4769         int quota_allocation = 0;
4770 +       int dlimit_allocation = 0;
4771  
4772         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
4773         if (ji->ea.flag == 0)
4774 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
4775  
4776                 quota_allocation = blocks_needed;
4777  
4778 +               /* Allocate new blocks to dlimit. */
4779 +               rc = -ENOSPC;
4780 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
4781 +                       goto clean_up;
4782 +               dlimit_allocation = blocks_needed;
4783 +
4784                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
4785                              &blkno);
4786                 if (rc)
4787 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
4788         return ea_size;
4789  
4790        clean_up:
4791 +       /* Rollback dlimit allocation */
4792 +       if (dlimit_allocation)
4793 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
4794         /* Rollback quota allocation */
4795         if (quota_allocation)
4796                 DQUOT_FREE_BLOCK(inode, quota_allocation);
4797 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
4798         }
4799  
4800         /* If old blocks exist, they must be removed from quota allocation. */
4801 -       if (old_blocks)
4802 +       if (old_blocks) {
4803 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
4804                 DQUOT_FREE_BLOCK(inode, old_blocks);
4805 +       }
4806  
4807         inode->i_ctime = CURRENT_TIME;
4808  
4809 diff -NurpP --minimal linux-2.6.27.10/fs/libfs.c linux-2.6.27.10-vs2.3.0.36.4/fs/libfs.c
4810 --- linux-2.6.27.10/fs/libfs.c  2008-10-13 14:52:05.000000000 +0200
4811 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/locks.c linux-2.6.27.10-vs2.3.0.36.4/fs/locks.c
4859 --- linux-2.6.27.10/fs/locks.c  2008-10-13 14:52:05.000000000 +0200
4860 +++ linux-2.6.27.10-vs2.3.0.36.4/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.10/fs/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/namei.c
5047 --- linux-2.6.27.10/fs/namei.c  2008-10-13 14:52:05.000000000 +0200
5048 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/namei.c     2008-11-12 18:45:34.000000000 +0100
5049 @@ -31,6 +31,14 @@
5050  #include <linux/file.h>
5051  #include <linux/fcntl.h>
5052  #include <linux/device_cgroup.h>
5053 +#include <linux/proc_fs.h>
5054 +#include <linux/vserver/inode.h>
5055 +#include <linux/vs_base.h>
5056 +#include <linux/vs_tag.h>
5057 +#include <linux/vs_cowbl.h>
5058 +#include <linux/vs_device.h>
5059 +#include <linux/vs_context.h>
5060 +#include <linux/pid_namespace.h>
5061  #include <asm/uaccess.h>
5062  
5063  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
5064 @@ -167,6 +175,77 @@ void putname(const char *name)
5065  EXPORT_SYMBOL(putname);
5066  #endif
5067  
5068 +static inline int dx_barrier(struct inode *inode)
5069 +{
5070 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
5071 +               vxwprintk_task(1, "did hit the barrier.");
5072 +               return 1;
5073 +       }
5074 +       return 0;
5075 +}
5076 +
5077 +static int __dx_permission(struct inode *inode, int mask)
5078 +{
5079 +       if (dx_barrier(inode))
5080 +               return -EACCES;
5081 +
5082 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
5083 +               /* devpts is xid tagged */
5084 +               if (S_ISDIR(inode->i_mode) ||
5085 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
5086 +                       return 0;
5087 +       }
5088 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
5089 +               struct proc_dir_entry *de = PDE(inode);
5090 +
5091 +               if (de && !vx_hide_check(0, de->vx_flags))
5092 +                       goto out;
5093 +
5094 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
5095 +                       struct pid *pid;
5096 +                       struct task_struct *tsk;
5097 +
5098 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
5099 +                           vx_flags(VXF_STATE_SETUP, 0))
5100 +                               return 0;
5101 +
5102 +                       pid = PROC_I(inode)->pid;
5103 +                       if (!pid)
5104 +                               goto out;
5105 +
5106 +                       tsk = pid_task(pid, PIDTYPE_PID);
5107 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
5108 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
5109 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
5110 +                               return 0;
5111 +               }
5112 +               else {
5113 +                       /* FIXME: Should we block some entries here? */
5114 +                       return 0;
5115 +               }
5116 +       }
5117 +       else {
5118 +               if (dx_notagcheck(inode->i_sb) ||
5119 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
5120 +                            DX_IDENT))
5121 +                       return 0;
5122 +       }
5123 +
5124 +out:
5125 +       return -EACCES;
5126 +}
5127 +
5128 +int dx_permission(struct inode *inode, int mask)
5129 +{
5130 +       int ret = __dx_permission(inode, mask);
5131 +       if (unlikely(ret)) {
5132 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
5133 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
5134 +                       inode->i_ino);
5135 +       }
5136 +       return ret;
5137 +}
5138 +
5139  
5140  /**
5141   * generic_permission  -  check for access rights on a Posix-like filesystem
5142 @@ -244,10 +323,14 @@ int inode_permission(struct inode *inode
5143                 /*
5144                  * Nobody gets write access to an immutable file.
5145                  */
5146 -               if (IS_IMMUTABLE(inode))
5147 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5148                         return -EACCES;
5149         }
5150  
5151 +       retval = dx_permission(inode, mask);
5152 +       if (retval)
5153 +               return retval;
5154 +
5155         /* Ordinary permission routines do not understand MAY_APPEND. */
5156         if (inode->i_op && inode->i_op->permission) {
5157                 retval = inode->i_op->permission(inode, mask);
5158 @@ -451,6 +534,8 @@ static int exec_permission_lite(struct i
5159  {
5160         umode_t mode = inode->i_mode;
5161  
5162 +       if (dx_barrier(inode))
5163 +               return -EACCES;
5164         if (inode->i_op && inode->i_op->permission)
5165                 return -EAGAIN;
5166  
5167 @@ -773,7 +858,8 @@ static __always_inline void follow_dotdo
5168                 if (nd->path.dentry == fs->root.dentry &&
5169                     nd->path.mnt == fs->root.mnt) {
5170                          read_unlock(&fs->lock);
5171 -                       break;
5172 +                       /* for sane '/' avoid follow_mount() */
5173 +                       return;
5174                 }
5175                  read_unlock(&fs->lock);
5176                 spin_lock(&dcache_lock);
5177 @@ -810,16 +896,30 @@ static int do_lookup(struct nameidata *n
5178  {
5179         struct vfsmount *mnt = nd->path.mnt;
5180         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5181 +       struct inode *inode;
5182  
5183         if (!dentry)
5184                 goto need_lookup;
5185         if (dentry->d_op && dentry->d_op->d_revalidate)
5186                 goto need_revalidate;
5187 +       inode = dentry->d_inode;
5188 +       if (!inode)
5189 +               goto done;
5190 +
5191 +       if (__dx_permission(inode, MAY_ACCESS))
5192 +               goto hidden;
5193 +
5194  done:
5195         path->mnt = mnt;
5196         path->dentry = dentry;
5197         __follow_mount(path);
5198         return 0;
5199 +hidden:
5200 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s«.",
5201 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5202 +               vxd_path(&nd->path));
5203 +       dput(dentry);
5204 +       return -ENOENT;
5205  
5206  need_lookup:
5207         dentry = real_lookup(nd->path.dentry, name, nd);
5208 @@ -1407,7 +1507,7 @@ static int may_delete(struct inode *dir,
5209         if (IS_APPEND(dir))
5210                 return -EPERM;
5211         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5212 -           IS_IMMUTABLE(victim->d_inode))
5213 +               IS_IXORUNLINK(victim->d_inode))
5214                 return -EPERM;
5215         if (isdir) {
5216                 if (!S_ISDIR(victim->d_inode->i_mode))
5217 @@ -1551,6 +1651,14 @@ int may_open(struct nameidata *nd, int a
5218                 flag &= ~O_TRUNC;
5219         }
5220  
5221 +#ifdef CONFIG_VSERVER_COWBL
5222 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5223 +               if (IS_COW_LINK(inode))
5224 +                       return -EMLINK;
5225 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5226 +               mark_inode_dirty(inode);
5227 +       }
5228 +#endif
5229         error = vfs_permission(nd, acc_mode);
5230         if (error)
5231                 return error;
5232 @@ -1677,6 +1785,11 @@ struct file *do_filp_open(int dfd, const
5233         int will_write;
5234         int flag = open_to_namei_flags(open_flag);
5235  
5236 +#ifdef CONFIG_VSERVER_COWBL
5237 +       int rflag = flag;
5238 +       int rmode = mode;
5239 +restart:
5240 +#endif
5241         acc_mode = MAY_OPEN | ACC_MODE(flag);
5242  
5243         /* O_TRUNC implies we need access checks for write permissions */
5244 @@ -1800,6 +1913,25 @@ ok:
5245                         goto exit;
5246         }
5247         error = may_open(&nd, acc_mode, flag);
5248 +#ifdef CONFIG_VSERVER_COWBL
5249 +       if (error == -EMLINK) {
5250 +               struct dentry *dentry;
5251 +               dentry = cow_break_link(pathname);
5252 +               if (IS_ERR(dentry)) {
5253 +                       error = PTR_ERR(dentry);
5254 +                       goto exit_cow;
5255 +               }
5256 +               dput(dentry);
5257 +               if (will_write)
5258 +                       mnt_drop_write(nd.path.mnt);
5259 +               release_open_intent(&nd);
5260 +               path_put(&nd.path);
5261 +               flag = rflag;
5262 +               mode = rmode;
5263 +               goto restart;
5264 +       }
5265 +exit_cow:
5266 +#endif
5267         if (error) {
5268                 if (will_write)
5269                         mnt_drop_write(nd.path.mnt);
5270 @@ -1952,9 +2084,17 @@ int vfs_mknod(struct inode *dir, struct 
5271         if (error)
5272                 return error;
5273  
5274 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5275 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5276 +               goto okay;
5277 +
5278 +       if (!capable(CAP_MKNOD))
5279                 return -EPERM;
5280  
5281 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5282 +               return -EPERM;
5283 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5284 +               return -EPERM;
5285 +okay:
5286         if (!dir->i_op || !dir->i_op->mknod)
5287                 return -EPERM;
5288  
5289 @@ -2395,7 +2535,7 @@ int vfs_link(struct dentry *old_dentry, 
5290         /*
5291          * A link to an append-only or immutable file cannot be created.
5292          */
5293 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5294 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5295                 return -EPERM;
5296         if (!dir->i_op || !dir->i_op->link)
5297                 return -EPERM;
5298 @@ -2756,6 +2896,217 @@ int vfs_follow_link(struct nameidata *nd
5299         return __vfs_follow_link(nd, link);
5300  }
5301  
5302 +
5303 +#ifdef CONFIG_VSERVER_COWBL
5304 +
5305 +#include <linux/file.h>
5306 +
5307 +static inline
5308 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5309 +{
5310 +       loff_t ppos = 0;
5311 +
5312 +       return do_splice_direct(in, &ppos, out, len, 0);
5313 +}
5314 +
5315 +struct dentry *cow_break_link(const char *pathname)
5316 +{
5317 +       int ret, mode, pathlen, redo = 0;
5318 +       struct nameidata old_nd, dir_nd;
5319 +       struct path old_path, new_path;
5320 +       struct dentry *dir, *res = NULL;
5321 +       struct file *old_file;
5322 +       struct file *new_file;
5323 +       char *to, *path, pad='\251';
5324 +       loff_t size;
5325 +
5326 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5327 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5328 +       ret = -ENOMEM;
5329 +       if (!path)
5330 +               goto out;
5331 +
5332 +       /* old_nd will have refs to dentry and mnt */
5333 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5334 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5335 +       if (ret < 0)
5336 +               goto out_free_path;
5337 +
5338 +       old_path = old_nd.path;
5339 +       mode = old_path.dentry->d_inode->i_mode;
5340 +
5341 +       to = d_path(&old_path, path, PATH_MAX-2);
5342 +       pathlen = strlen(to);
5343 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5344 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5345 +               old_path.dentry->d_name.len);
5346 +
5347 +       to[pathlen + 1] = 0;
5348 +retry:
5349 +       to[pathlen] = pad--;
5350 +       ret = -EMLINK;
5351 +       if (pad <= '\240')
5352 +               goto out_rel_old;
5353 +
5354 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5355 +       /* dir_nd will have refs to dentry and mnt */
5356 +       ret = path_lookup(to,
5357 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5358 +       vxdprintk(VXD_CBIT(misc, 2),
5359 +               "path_lookup(new): %d", ret);
5360 +       if (ret < 0)
5361 +               goto retry;
5362 +
5363 +       /* this puppy downs the inode mutex */
5364 +       new_path.dentry = lookup_create(&dir_nd, 0);
5365 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5366 +               vxdprintk(VXD_CBIT(misc, 2),
5367 +                       "lookup_create(new): %p", new_path.dentry);
5368 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5369 +               path_put(&dir_nd.path);
5370 +               goto retry;
5371 +       }
5372 +       vxdprintk(VXD_CBIT(misc, 2),
5373 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5374 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5375 +               new_path.dentry->d_name.len);
5376 +       dir = dir_nd.path.dentry;
5377 +
5378 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5379 +       vxdprintk(VXD_CBIT(misc, 2),
5380 +               "vfs_create(new): %d", ret);
5381 +       if (ret == -EEXIST) {
5382 +               mutex_unlock(&dir->d_inode->i_mutex);
5383 +               dput(new_path.dentry);
5384 +               path_put(&dir_nd.path);
5385 +               goto retry;
5386 +       }
5387 +       else if (ret < 0)
5388 +               goto out_unlock_new;
5389 +
5390 +       /* drop out early, ret passes ENOENT */
5391 +       ret = -ENOENT;
5392 +       if ((redo = d_unhashed(old_path.dentry)))
5393 +               goto out_unlock_new;
5394 +
5395 +       new_path.mnt = dir_nd.path.mnt;
5396 +       dget(old_path.dentry);
5397 +       mntget(old_path.mnt);
5398 +       /* this one cleans up the dentry/mnt in case of failure */
5399 +       old_file = dentry_open(old_path.dentry, old_path.mnt, O_RDONLY);
5400 +       vxdprintk(VXD_CBIT(misc, 2),
5401 +               "dentry_open(old): %p", old_file);
5402 +       if (!old_file || IS_ERR(old_file)) {
5403 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5404 +               goto out_unlock_new;
5405 +       }
5406 +
5407 +       dget(new_path.dentry);
5408 +       mntget(new_path.mnt);
5409 +       /* this one cleans up the dentry/mnt in case of failure */
5410 +       new_file = dentry_open(new_path.dentry, new_path.mnt, O_WRONLY);
5411 +       vxdprintk(VXD_CBIT(misc, 2),
5412 +               "dentry_open(new): %p", new_file);
5413 +
5414 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5415 +       if (!new_file || IS_ERR(new_file))
5416 +               goto out_fput_old;
5417 +
5418 +       size = i_size_read(old_file->f_dentry->d_inode);
5419 +       ret = do_cow_splice(old_file, new_file, size);
5420 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5421 +       if (ret < 0) {
5422 +               goto out_fput_both;
5423 +       } else if (ret < size) {
5424 +               ret = -ENOSPC;
5425 +               goto out_fput_both;
5426 +       } else {
5427 +               struct inode *old_inode = old_path.dentry->d_inode;
5428 +               struct inode *new_inode = new_path.dentry->d_inode;
5429 +               struct iattr attr = {
5430 +                       .ia_uid = old_inode->i_uid,
5431 +                       .ia_gid = old_inode->i_gid,
5432 +                       .ia_valid = ATTR_UID | ATTR_GID
5433 +                       };
5434 +
5435 +               ret = inode_setattr(new_inode, &attr);
5436 +               if (ret)
5437 +                       goto out_fput_both;
5438 +       }
5439 +
5440 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5441 +
5442 +       /* drop out late */
5443 +       ret = -ENOENT;
5444 +       if ((redo = d_unhashed(old_path.dentry)))
5445 +               goto out_unlock;
5446 +
5447 +       vxdprintk(VXD_CBIT(misc, 2),
5448 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5449 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5450 +               new_path.dentry->d_name.len,
5451 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5452 +               old_path.dentry->d_name.len);
5453 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5454 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5455 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5456 +       res = new_path.dentry;
5457 +
5458 +out_unlock:
5459 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5460 +
5461 +out_fput_both:
5462 +       vxdprintk(VXD_CBIT(misc, 3),
5463 +               "fput(new_file=%p[#%ld])", new_file,
5464 +               atomic_read(&new_file->f_count));
5465 +       fput(new_file);
5466 +
5467 +out_fput_old:
5468 +       vxdprintk(VXD_CBIT(misc, 3),
5469 +               "fput(old_file=%p[#%ld])", old_file,
5470 +               atomic_read(&old_file->f_count));
5471 +       fput(old_file);
5472 +
5473 +out_unlock_new:
5474 +       mutex_unlock(&dir->d_inode->i_mutex);
5475 +       if (!ret)
5476 +               goto out_redo;
5477 +
5478 +       /* error path cleanup */
5479 +       vfs_unlink(dir->d_inode, new_path.dentry);
5480 +       dput(new_path.dentry);
5481 +
5482 +out_redo:
5483 +       if (!redo)
5484 +               goto out_rel_both;
5485 +       /* lookup dentry once again */
5486 +       path_put(&old_nd.path);
5487 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5488 +       if (ret)
5489 +               goto out_rel_both;
5490 +
5491 +       new_path.dentry = old_nd.path.dentry;
5492 +       vxdprintk(VXD_CBIT(misc, 2),
5493 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5494 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5495 +               new_path.dentry->d_name.len);
5496 +       dget(new_path.dentry);
5497 +       res = new_path.dentry;
5498 +
5499 +out_rel_both:
5500 +       path_put(&dir_nd.path);
5501 +out_rel_old:
5502 +       path_put(&old_nd.path);
5503 +out_free_path:
5504 +       kfree(path);
5505 +out:
5506 +       if (ret)
5507 +               res = ERR_PTR(ret);
5508 +       return res;
5509 +}
5510 +
5511 +#endif
5512 +
5513  /* get the link contents into pagecache */
5514  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5515  {
5516 diff -NurpP --minimal linux-2.6.27.10/fs/namespace.c linux-2.6.27.10-vs2.3.0.36.4/fs/namespace.c
5517 --- linux-2.6.27.10/fs/namespace.c      2008-12-19 12:03:13.000000000 +0100
5518 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/namespace.c 2008-12-08 04:52:52.000000000 +0100
5519 @@ -27,6 +27,11 @@
5520  #include <linux/ramfs.h>
5521  #include <linux/log2.h>
5522  #include <linux/idr.h>
5523 +#include <linux/vs_base.h>
5524 +#include <linux/vs_context.h>
5525 +#include <linux/vs_tag.h>
5526 +#include <linux/vserver/space.h>
5527 +#include <linux/vserver/global.h>
5528  #include <asm/uaccess.h>
5529  #include <asm/unistd.h>
5530  #include "pnode.h"
5531 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5532                 mnt->mnt_root = dget(root);
5533                 mnt->mnt_mountpoint = mnt->mnt_root;
5534                 mnt->mnt_parent = mnt;
5535 +               mnt->mnt_tag = old->mnt_tag;
5536  
5537                 if (flag & CL_SLAVE) {
5538                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5539 @@ -685,6 +691,31 @@ static inline void mangle(struct seq_fil
5540         seq_escape(m, s, " \t\n\\");
5541  }
5542  
5543 +static int mnt_is_reachable(struct vfsmount *mnt)
5544 +{
5545 +       struct path root;
5546 +       struct dentry *point;
5547 +       int ret;
5548 +
5549 +       if (mnt == mnt->mnt_ns->root)
5550 +               return 1;
5551 +
5552 +       spin_lock(&vfsmount_lock);
5553 +       root = current->fs->root;
5554 +       point = root.dentry;
5555 +
5556 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5557 +               point = mnt->mnt_mountpoint;
5558 +               mnt = mnt->mnt_parent;
5559 +       }
5560 +
5561 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5562 +
5563 +       spin_unlock(&vfsmount_lock);
5564 +
5565 +       return ret;
5566 +}
5567 +
5568  /*
5569   * Simple .show_options callback for filesystems which don't want to
5570   * implement more complex mount option showing.
5571 @@ -757,6 +788,8 @@ static int show_sb_opts(struct seq_file 
5572                 { MS_SYNCHRONOUS, ",sync" },
5573                 { MS_DIRSYNC, ",dirsync" },
5574                 { MS_MANDLOCK, ",mand" },
5575 +               { MS_TAGGED, ",tag" },
5576 +               { MS_NOTAGCHECK, ",notagcheck" },
5577                 { 0, NULL }
5578         };
5579         const struct proc_fs_info *fs_infop;
5580 @@ -803,10 +836,20 @@ static int show_vfsmnt(struct seq_file *
5581         int err = 0;
5582         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5583  
5584 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5585 -       seq_putc(m, ' ');
5586 -       seq_path(m, &mnt_path, " \t\n\\");
5587 -       seq_putc(m, ' ');
5588 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5589 +               return SEQ_SKIP;
5590 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5591 +               return SEQ_SKIP;
5592 +
5593 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5594 +               mnt == current->fs->root.mnt) {
5595 +               seq_puts(m, "/dev/root / ");
5596 +       } else {
5597 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5598 +               seq_putc(m, ' ');
5599 +               seq_path(m, &mnt_path, " \t\n\\");
5600 +               seq_putc(m, ' ');
5601 +       }
5602         show_type(m, mnt->mnt_sb);
5603         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5604         err = show_sb_opts(m, mnt->mnt_sb);
5605 @@ -836,6 +879,11 @@ static int show_mountinfo(struct seq_fil
5606         struct path root = p->root;
5607         int err = 0;
5608  
5609 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5610 +               return SEQ_SKIP;
5611 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5612 +               return SEQ_SKIP;
5613 +
5614         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5615                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5616         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5617 @@ -894,17 +942,27 @@ static int show_vfsstat(struct seq_file 
5618         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5619         int err = 0;
5620  
5621 -       /* device */
5622 -       if (mnt->mnt_devname) {
5623 -               seq_puts(m, "device ");
5624 -               mangle(m, mnt->mnt_devname);
5625 -       } else
5626 -               seq_puts(m, "no device");
5627 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5628 +               return SEQ_SKIP;
5629 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5630 +               return SEQ_SKIP;
5631  
5632 -       /* mount point */
5633 -       seq_puts(m, " mounted on ");
5634 -       seq_path(m, &mnt_path, " \t\n\\");
5635 -       seq_putc(m, ' ');
5636 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5637 +               mnt == current->fs->root.mnt) {
5638 +               seq_puts(m, "device /dev/root mounted on / ");
5639 +       } else {
5640 +               /* device */
5641 +               if (mnt->mnt_devname) {
5642 +                       seq_puts(m, "device ");
5643 +                       mangle(m, mnt->mnt_devname);
5644 +               } else
5645 +                       seq_puts(m, "no device");
5646 +
5647 +               /* mount point */
5648 +               seq_puts(m, " mounted on ");
5649 +               seq_path(m, &mnt_path, " \t\n\\");
5650 +               seq_putc(m, ' ');
5651 +       }
5652  
5653         /* file system type */
5654         seq_puts(m, "with fstype ");
5655 @@ -1143,7 +1201,7 @@ asmlinkage long sys_umount(char __user *
5656                 goto dput_and_out;
5657  
5658         retval = -EPERM;
5659 -       if (!capable(CAP_SYS_ADMIN))
5660 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5661                 goto dput_and_out;
5662  
5663         retval = do_umount(path.mnt, flags);
5664 @@ -1169,7 +1227,7 @@ asmlinkage long sys_oldumount(char __use
5665  
5666  static int mount_is_safe(struct nameidata *nd)
5667  {
5668 -       if (capable(CAP_SYS_ADMIN))
5669 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5670                 return 0;
5671         return -EPERM;
5672  #ifdef notyet
5673 @@ -1462,11 +1520,13 @@ static noinline int do_change_type(struc
5674   * noinline this do_mount helper to save do_mount stack space.
5675   */
5676  static noinline int do_loopback(struct nameidata *nd, char *old_name,
5677 -                               int recurse)
5678 +       tag_t tag, unsigned long flags, int mnt_flags)
5679  {
5680         struct nameidata old_nd;
5681         struct vfsmount *mnt = NULL;
5682         int err = mount_is_safe(nd);
5683 +       int recurse = flags & MS_REC;
5684 +
5685         if (err)
5686                 return err;
5687         if (!old_name || !*old_name)
5688 @@ -1500,6 +1560,7 @@ static noinline int do_loopback(struct n
5689                 spin_unlock(&vfsmount_lock);
5690                 release_mounts(&umount_list);
5691         }
5692 +       mnt->mnt_flags = mnt_flags;
5693  
5694  out:
5695         up_write(&namespace_sem);
5696 @@ -1531,12 +1592,12 @@ static int change_mount_flags(struct vfs
5697   * noinline this do_mount helper to save do_mount stack space.
5698   */
5699  static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags,
5700 -                     void *data)
5701 +       void *data, xid_t xid)
5702  {
5703         int err;
5704         struct super_block *sb = nd->path.mnt->mnt_sb;
5705  
5706 -       if (!capable(CAP_SYS_ADMIN))
5707 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5708                 return -EPERM;
5709  
5710         if (!check_mnt(nd->path.mnt))
5711 @@ -1582,7 +1643,7 @@ static noinline int do_move_mount(struct
5712         struct path parent_path;
5713         struct vfsmount *p;
5714         int err = 0;
5715 -       if (!capable(CAP_SYS_ADMIN))
5716 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5717                 return -EPERM;
5718         if (!old_name || !*old_name)
5719                 return -EINVAL;
5720 @@ -1665,7 +1726,7 @@ static noinline int do_new_mount(struct 
5721                 return -EINVAL;
5722  
5723         /* we need capabilities... */
5724 -       if (!capable(CAP_SYS_ADMIN))
5725 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5726                 return -EPERM;
5727  
5728         mnt = do_kern_mount(type, flags, name, data);
5729 @@ -1910,6 +1971,7 @@ long do_mount(char *dev_name, char *dir_
5730         struct nameidata nd;
5731         int retval = 0;
5732         int mnt_flags = 0;
5733 +       tag_t tag = 0;
5734  
5735         /* Discard magic */
5736         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5737 @@ -1925,6 +1987,12 @@ long do_mount(char *dev_name, char *dir_
5738         if (data_page)
5739                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5740  
5741 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5742 +               /* FIXME: bind and re-mounts get the tag flag? */
5743 +               if (flags & (MS_BIND|MS_REMOUNT))
5744 +                       flags |= MS_TAGID;
5745 +       }
5746 +
5747         /* Separate the per-mountpoint flags */
5748         if (flags & MS_NOSUID)
5749                 mnt_flags |= MNT_NOSUID;
5750 @@ -1941,6 +2009,8 @@ long do_mount(char *dev_name, char *dir_
5751         if (flags & MS_RDONLY)
5752                 mnt_flags |= MNT_READONLY;
5753  
5754 +       if (!capable(CAP_SYS_ADMIN))
5755 +               mnt_flags |= MNT_NODEV;
5756         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5757                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5758  
5759 @@ -1956,9 +2026,9 @@ long do_mount(char *dev_name, char *dir_
5760  
5761         if (flags & MS_REMOUNT)
5762                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
5763 -                                   data_page);
5764 +                                   data_page, tag);
5765         else if (flags & MS_BIND)
5766 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
5767 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
5768         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5769                 retval = do_change_type(&nd, flags);
5770         else if (flags & MS_MOVE)
5771 @@ -2027,6 +2097,7 @@ static struct mnt_namespace *dup_mnt_ns(
5772                 q = next_mnt(q, new_ns->root);
5773         }
5774         up_write(&namespace_sem);
5775 +       atomic_inc(&vs_global_mnt_ns);
5776  
5777         if (rootmnt)
5778                 mntput(rootmnt);
5779 @@ -2355,5 +2426,6 @@ void __put_mnt_ns(struct mnt_namespace *
5780         spin_unlock(&vfsmount_lock);
5781         up_write(&namespace_sem);
5782         release_mounts(&umount_list);
5783 +       atomic_dec(&vs_global_mnt_ns);
5784         kfree(ns);
5785  }
5786 diff -NurpP --minimal linux-2.6.27.10/fs/nfs/client.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/client.c
5787 --- linux-2.6.27.10/fs/nfs/client.c     2008-10-13 14:52:05.000000000 +0200
5788 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/client.c        2008-10-13 14:54:20.000000000 +0200
5789 @@ -601,6 +601,9 @@ static int nfs_init_server_rpcclient(str
5790         if (server->flags & NFS_MOUNT_SOFT)
5791                 server->client->cl_softrtry = 1;
5792  
5793 +       server->client->cl_tag = 0;
5794 +       if (server->flags & NFS_MOUNT_TAGGED)
5795 +               server->client->cl_tag = 1;
5796         return 0;
5797  }
5798  
5799 @@ -766,6 +769,10 @@ static void nfs_server_set_fsinfo(struct
5800                 server->acdirmin = server->acdirmax = 0;
5801         }
5802  
5803 +       /* FIXME: needs fsinfo
5804 +       if (server->flags & NFS_MOUNT_TAGGED)
5805 +               sb->s_flags |= MS_TAGGED;       */
5806 +
5807         server->maxfilesize = fsinfo->maxfilesize;
5808  
5809         /* We're airborne Set socket buffersize */
5810 diff -NurpP --minimal linux-2.6.27.10/fs/nfs/dir.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/dir.c
5811 --- linux-2.6.27.10/fs/nfs/dir.c        2008-10-13 14:52:05.000000000 +0200
5812 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/dir.c   2008-10-13 14:54:20.000000000 +0200
5813 @@ -34,6 +34,7 @@
5814  #include <linux/namei.h>
5815  #include <linux/mount.h>
5816  #include <linux/sched.h>
5817 +#include <linux/vs_tag.h>
5818  
5819  #include "nfs4_fs.h"
5820  #include "delegation.h"
5821 @@ -938,6 +939,7 @@ static struct dentry *nfs_lookup(struct 
5822         if (IS_ERR(res))
5823                 goto out_unblock_sillyrename;
5824  
5825 +       dx_propagate_tag(nd, inode);
5826  no_entry:
5827         res = d_materialise_unique(dentry, inode);
5828         if (res != NULL) {
5829 diff -NurpP --minimal linux-2.6.27.10/fs/nfs/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/inode.c
5830 --- linux-2.6.27.10/fs/nfs/inode.c      2008-10-13 14:52:05.000000000 +0200
5831 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/inode.c 2008-10-13 14:54:20.000000000 +0200
5832 @@ -37,6 +37,7 @@
5833  #include <linux/vfs.h>
5834  #include <linux/inet.h>
5835  #include <linux/nfs_xdr.h>
5836 +#include <linux/vs_tag.h>
5837  
5838  #include <asm/system.h>
5839  #include <asm/uaccess.h>
5840 @@ -314,8 +315,10 @@ nfs_fhget(struct super_block *sb, struct
5841                         nfsi->change_attr = fattr->change_attr;
5842                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5843                 inode->i_nlink = fattr->nlink;
5844 -               inode->i_uid = fattr->uid;
5845 -               inode->i_gid = fattr->gid;
5846 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5847 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5848 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5849 +                                        /* maybe fattr->xid someday */
5850                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5851                         /*
5852                          * report the blocks in 512byte units
5853 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5854                         inode->i_uid = attr->ia_uid;
5855                 if ((attr->ia_valid & ATTR_GID) != 0)
5856                         inode->i_gid = attr->ia_gid;
5857 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5858 +                       inode->i_tag = attr->ia_tag;
5859                 spin_lock(&inode->i_lock);
5860                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5861                 spin_unlock(&inode->i_lock);
5862 @@ -900,6 +905,9 @@ static int nfs_check_inode_attributes(st
5863         struct nfs_inode *nfsi = NFS_I(inode);
5864         loff_t cur_size, new_isize;
5865         unsigned long invalid = 0;
5866 +       uid_t uid;
5867 +       gid_t gid;
5868 +       tag_t tag;
5869  
5870  
5871         /* Has the inode gone and changed behind our back? */
5872 @@ -924,10 +932,15 @@ static int nfs_check_inode_attributes(st
5873         if (cur_size != new_isize && nfsi->npages == 0)
5874                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5875  
5876 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5877 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5878 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5879 +
5880         /* Have any file permissions changed? */
5881         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5882 -                       || inode->i_uid != fattr->uid
5883 -                       || inode->i_gid != fattr->gid)
5884 +                       || inode->i_uid != uid
5885 +                       || inode->i_gid != gid
5886 +                       || inode->i_tag != tag)
5887                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5888  
5889         /* Has the link count changed? */
5890 @@ -1048,6 +1061,9 @@ static int nfs_update_inode(struct inode
5891         loff_t cur_isize, new_isize;
5892         unsigned long invalid = 0;
5893         unsigned long now = jiffies;
5894 +       uid_t uid;
5895 +       gid_t gid;
5896 +       tag_t tag;
5897  
5898         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5899                         __func__, inode->i_sb->s_id, inode->i_ino,
5900 @@ -1121,15 +1137,21 @@ static int nfs_update_inode(struct inode
5901         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5902         nfsi->change_attr = fattr->change_attr;
5903  
5904 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5905 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5906 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5907 +
5908         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5909 -           inode->i_uid != fattr->uid ||
5910 -           inode->i_gid != fattr->gid)
5911 +           inode->i_uid != uid ||
5912 +           inode->i_gid != gid ||
5913 +           inode->i_tag != tag)
5914                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5915  
5916         inode->i_mode = fattr->mode;
5917         inode->i_nlink = fattr->nlink;
5918 -       inode->i_uid = fattr->uid;
5919 -       inode->i_gid = fattr->gid;
5920 +       inode->i_uid = uid;
5921 +       inode->i_gid = gid;
5922 +       inode->i_tag = tag;
5923  
5924         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5925                 /*
5926 diff -NurpP --minimal linux-2.6.27.10/fs/nfs/nfs3xdr.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/nfs3xdr.c
5927 --- linux-2.6.27.10/fs/nfs/nfs3xdr.c    2008-07-13 23:51:29.000000000 +0200
5928 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/nfs3xdr.c       2008-10-13 14:54:20.000000000 +0200
5929 @@ -22,6 +22,7 @@
5930  #include <linux/nfs3.h>
5931  #include <linux/nfs_fs.h>
5932  #include <linux/nfsacl.h>
5933 +#include <linux/vs_tag.h>
5934  #include "internal.h"
5935  
5936  #define NFSDBG_FACILITY                NFSDBG_XDR
5937 @@ -180,7 +181,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5938  }
5939  
5940  static inline __be32 *
5941 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5942 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5943  {
5944         if (attr->ia_valid & ATTR_MODE) {
5945                 *p++ = xdr_one;
5946 @@ -188,15 +189,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5947         } else {
5948                 *p++ = xdr_zero;
5949         }
5950 -       if (attr->ia_valid & ATTR_UID) {
5951 +       if (attr->ia_valid & ATTR_UID ||
5952 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5953                 *p++ = xdr_one;
5954 -               *p++ = htonl(attr->ia_uid);
5955 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5956         } else {
5957                 *p++ = xdr_zero;
5958         }
5959 -       if (attr->ia_valid & ATTR_GID) {
5960 +       if (attr->ia_valid & ATTR_GID ||
5961 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5962                 *p++ = xdr_one;
5963 -               *p++ = htonl(attr->ia_gid);
5964 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5965         } else {
5966                 *p++ = xdr_zero;
5967         }
5968 @@ -281,7 +284,8 @@ static int
5969  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5970  {
5971         p = xdr_encode_fhandle(p, args->fh);
5972 -       p = xdr_encode_sattr(p, args->sattr);
5973 +       p = xdr_encode_sattr(p, args->sattr,
5974 +               req->rq_task->tk_client->cl_tag);
5975         *p++ = htonl(args->guard);
5976         if (args->guard)
5977                 p = xdr_encode_time3(p, &args->guardtime);
5978 @@ -386,7 +390,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5979                 *p++ = args->verifier[0];
5980                 *p++ = args->verifier[1];
5981         } else
5982 -               p = xdr_encode_sattr(p, args->sattr);
5983 +               p = xdr_encode_sattr(p, args->sattr,
5984 +                       req->rq_task->tk_client->cl_tag);
5985  
5986         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5987         return 0;
5988 @@ -400,7 +405,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5989  {
5990         p = xdr_encode_fhandle(p, args->fh);
5991         p = xdr_encode_array(p, args->name, args->len);
5992 -       p = xdr_encode_sattr(p, args->sattr);
5993 +       p = xdr_encode_sattr(p, args->sattr,
5994 +               req->rq_task->tk_client->cl_tag);
5995         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5996         return 0;
5997  }
5998 @@ -413,7 +419,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5999  {
6000         p = xdr_encode_fhandle(p, args->fromfh);
6001         p = xdr_encode_array(p, args->fromname, args->fromlen);
6002 -       p = xdr_encode_sattr(p, args->sattr);
6003 +       p = xdr_encode_sattr(p, args->sattr,
6004 +               req->rq_task->tk_client->cl_tag);
6005         *p++ = htonl(args->pathlen);
6006         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6007  
6008 @@ -431,7 +438,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6009         p = xdr_encode_fhandle(p, args->fh);
6010         p = xdr_encode_array(p, args->name, args->len);
6011         *p++ = htonl(args->type);
6012 -       p = xdr_encode_sattr(p, args->sattr);
6013 +       p = xdr_encode_sattr(p, args->sattr,
6014 +               req->rq_task->tk_client->cl_tag);
6015         if (args->type == NF3CHR || args->type == NF3BLK) {
6016                 *p++ = htonl(MAJOR(args->rdev));
6017                 *p++ = htonl(MINOR(args->rdev));
6018 diff -NurpP --minimal linux-2.6.27.10/fs/nfs/nfsroot.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/nfsroot.c
6019 --- linux-2.6.27.10/fs/nfs/nfsroot.c    2008-10-13 14:52:05.000000000 +0200
6020 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/nfsroot.c       2008-10-13 14:54:20.000000000 +0200
6021 @@ -117,12 +117,12 @@ static int mount_port __initdata = 0;             /
6022  enum {
6023         /* Options that take integer arguments */
6024         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6025 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6026 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6027         /* Options that take no arguments */
6028         Opt_soft, Opt_hard, Opt_intr,
6029         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6030         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6031 -       Opt_acl, Opt_noacl,
6032 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6033         /* Error token */
6034         Opt_err
6035  };
6036 @@ -159,6 +159,9 @@ static match_table_t __initdata tokens =
6037         {Opt_tcp, "tcp"},
6038         {Opt_acl, "acl"},
6039         {Opt_noacl, "noacl"},
6040 +       {Opt_tag, "tag"},
6041 +       {Opt_notag, "notag"},
6042 +       {Opt_tagid, "tagid=%u"},
6043         {Opt_err, NULL}
6044         
6045  };
6046 @@ -270,6 +273,20 @@ static int __init root_nfs_parse(char *n
6047                         case Opt_noacl:
6048                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6049                                 break;
6050 +#ifndef CONFIG_TAGGING_NONE
6051 +                       case Opt_tag:
6052 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6053 +                               break;
6054 +                       case Opt_notag:
6055 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6056 +                               break;
6057 +#endif
6058 +#ifdef CONFIG_PROPAGATE
6059 +                       case Opt_tagid:
6060 +                               /* use args[0] */
6061 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6062 +                               break;
6063 +#endif
6064                         default:
6065                                 printk(KERN_WARNING "Root-NFS: unknown "
6066                                         "option: %s\n", p);
6067 diff -NurpP --minimal linux-2.6.27.10/fs/nfs/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/super.c
6068 --- linux-2.6.27.10/fs/nfs/super.c      2008-10-13 14:52:05.000000000 +0200
6069 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfs/super.c 2008-10-13 14:54:20.000000000 +0200
6070 @@ -51,6 +51,7 @@
6071  #include <linux/nfs_xdr.h>
6072  #include <linux/magic.h>
6073  #include <linux/parser.h>
6074 +#include <linux/vs_tag.h>
6075  
6076  #include <asm/system.h>
6077  #include <asm/uaccess.h>
6078 @@ -504,6 +505,7 @@ static void nfs_show_mount_options(struc
6079                 { NFS_MOUNT_NOACL, ",noacl", "" },
6080                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6081                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
6082 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6083                 { 0, NULL, NULL }
6084         };
6085         const struct proc_nfs_info *nfs_infop;
6086 diff -NurpP --minimal linux-2.6.27.10/fs/nfsd/auth.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/auth.c
6087 --- linux-2.6.27.10/fs/nfsd/auth.c      2008-07-13 23:51:29.000000000 +0200
6088 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/auth.c 2008-10-13 14:54:20.000000000 +0200
6089 @@ -10,6 +10,7 @@
6090  #include <linux/sunrpc/svcauth.h>
6091  #include <linux/nfsd/nfsd.h>
6092  #include <linux/nfsd/export.h>
6093 +#include <linux/vs_tag.h>
6094  #include "auth.h"
6095  
6096  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6097 @@ -55,19 +56,23 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6098                 get_group_info(cred.cr_group_info);
6099  
6100         if (cred.cr_uid != (uid_t) -1)
6101 -               current->fsuid = cred.cr_uid;
6102 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6103         else
6104                 current->fsuid = exp->ex_anon_uid;
6105         if (cred.cr_gid != (gid_t) -1)
6106 -               current->fsgid = cred.cr_gid;
6107 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
6108         else
6109                 current->fsgid = exp->ex_anon_gid;
6110  
6111 +       /* this desperately needs a tag :) */
6112 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6113 +
6114         if (!cred.cr_group_info)
6115                 return -ENOMEM;
6116         ret = set_current_groups(cred.cr_group_info);
6117         put_group_info(cred.cr_group_info);
6118 -       if ((cred.cr_uid)) {
6119 +
6120 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
6121                 current->cap_effective =
6122                         cap_drop_nfsd_set(current->cap_effective);
6123         } else {
6124 diff -NurpP --minimal linux-2.6.27.10/fs/nfsd/nfs3xdr.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/nfs3xdr.c
6125 --- linux-2.6.27.10/fs/nfsd/nfs3xdr.c   2008-07-13 23:51:29.000000000 +0200
6126 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/nfs3xdr.c      2008-10-13 14:54:20.000000000 +0200
6127 @@ -21,6 +21,7 @@
6128  #include <linux/sunrpc/svc.h>
6129  #include <linux/nfsd/nfsd.h>
6130  #include <linux/nfsd/xdr3.h>
6131 +#include <linux/vs_tag.h>
6132  #include "auth.h"
6133  
6134  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6135 @@ -108,6 +109,8 @@ static __be32 *
6136  decode_sattr3(__be32 *p, struct iattr *iap)
6137  {
6138         u32     tmp;
6139 +       uid_t   uid = 0;
6140 +       gid_t   gid = 0;
6141  
6142         iap->ia_valid = 0;
6143  
6144 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6145         }
6146         if (*p++) {
6147                 iap->ia_valid |= ATTR_UID;
6148 -               iap->ia_uid = ntohl(*p++);
6149 +               uid = ntohl(*p++);
6150         }
6151         if (*p++) {
6152                 iap->ia_valid |= ATTR_GID;
6153 -               iap->ia_gid = ntohl(*p++);
6154 +               gid = ntohl(*p++);
6155         }
6156 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6157 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6158 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6159         if (*p++) {
6160                 u64     newsize;
6161  
6162 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6163         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6164         *p++ = htonl((u32) stat->mode);
6165         *p++ = htonl((u32) stat->nlink);
6166 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6167 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6168 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6169 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6170 +               stat->uid, stat->tag)));
6171 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6172 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6173 +               stat->gid, stat->tag)));
6174         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6175                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6176         } else {
6177 diff -NurpP --minimal linux-2.6.27.10/fs/nfsd/nfs4xdr.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/nfs4xdr.c
6178 --- linux-2.6.27.10/fs/nfsd/nfs4xdr.c   2008-10-13 14:52:06.000000000 +0200
6179 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/nfs4xdr.c      2008-10-13 14:54:20.000000000 +0200
6180 @@ -58,6 +58,7 @@
6181  #include <linux/nfs4_acl.h>
6182  #include <linux/sunrpc/gss_api.h>
6183  #include <linux/sunrpc/svcauth_gss.h>
6184 +#include <linux/vs_tag.h>
6185  
6186  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6187  
6188 @@ -1704,14 +1705,18 @@ out_acl:
6189                 WRITE32(stat.nlink);
6190         }
6191         if (bmval1 & FATTR4_WORD1_OWNER) {
6192 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6193 +               status = nfsd4_encode_user(rqstp,
6194 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6195 +                       stat.uid, stat.tag), &p, &buflen);
6196                 if (status == nfserr_resource)
6197                         goto out_resource;
6198                 if (status)
6199                         goto out;
6200         }
6201         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6202 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6203 +               status = nfsd4_encode_group(rqstp,
6204 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6205 +                       stat.gid, stat.tag), &p, &buflen);
6206                 if (status == nfserr_resource)
6207                         goto out_resource;
6208                 if (status)
6209 diff -NurpP --minimal linux-2.6.27.10/fs/nfsd/nfsxdr.c linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/nfsxdr.c
6210 --- linux-2.6.27.10/fs/nfsd/nfsxdr.c    2008-07-13 23:51:29.000000000 +0200
6211 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/nfsd/nfsxdr.c       2008-10-13 14:54:20.000000000 +0200
6212 @@ -15,6 +15,7 @@
6213  #include <linux/nfsd/nfsd.h>
6214  #include <linux/nfsd/xdr.h>
6215  #include <linux/mm.h>
6216 +#include <linux/vs_tag.h>
6217  #include "auth.h"
6218  
6219  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6220 @@ -98,6 +99,8 @@ static __be32 *
6221  decode_sattr(__be32 *p, struct iattr *iap)
6222  {
6223         u32     tmp, tmp1;
6224 +       uid_t   uid = 0;
6225 +       gid_t   gid = 0;
6226  
6227         iap->ia_valid = 0;
6228  
6229 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6230         }
6231         if ((tmp = ntohl(*p++)) != (u32)-1) {
6232                 iap->ia_valid |= ATTR_UID;
6233 -               iap->ia_uid = tmp;
6234 +               uid = tmp;
6235         }
6236         if ((tmp = ntohl(*p++)) != (u32)-1) {
6237                 iap->ia_valid |= ATTR_GID;
6238 -               iap->ia_gid = tmp;
6239 +               gid = tmp;
6240         }
6241 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6242 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6243 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6244         if ((tmp = ntohl(*p++)) != (u32)-1) {
6245                 iap->ia_valid |= ATTR_SIZE;
6246                 iap->ia_size = tmp;
6247 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6248         *p++ = htonl(nfs_ftypes[type >> 12]);
6249         *p++ = htonl((u32) stat->mode);
6250         *p++ = htonl((u32) stat->nlink);
6251 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6252 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6253 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6254 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6255 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6256 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6257  
6258         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6259                 *p++ = htonl(NFS_MAXPATHLEN);
6260 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/dlm/dlmfs.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/dlm/dlmfs.c
6261 --- linux-2.6.27.10/fs/ocfs2/dlm/dlmfs.c        2008-10-13 14:52:06.000000000 +0200
6262 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/dlm/dlmfs.c   2008-10-13 14:54:20.000000000 +0200
6263 @@ -43,6 +43,7 @@
6264  #include <linux/init.h>
6265  #include <linux/string.h>
6266  #include <linux/backing-dev.h>
6267 +#include <linux/vs_tag.h>
6268  
6269  #include <asm/uaccess.h>
6270  
6271 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6272                 inode->i_mode = mode;
6273                 inode->i_uid = current->fsuid;
6274                 inode->i_gid = current->fsgid;
6275 +               inode->i_tag = dx_current_fstag(sb);
6276                 inode->i_blocks = 0;
6277                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6278                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6279 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6280         inode->i_mode = mode;
6281         inode->i_uid = current->fsuid;
6282         inode->i_gid = current->fsgid;
6283 +       inode->i_tag = dx_current_fstag(sb);
6284         inode->i_blocks = 0;
6285         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6286         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6287 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/dlmglue.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/dlmglue.c
6288 --- linux-2.6.27.10/fs/ocfs2/dlmglue.c  2008-10-13 14:52:06.000000000 +0200
6289 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/dlmglue.c     2008-10-13 14:54:20.000000000 +0200
6290 @@ -1846,6 +1846,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6291         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6292         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6293         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6294 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6295         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6296         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6297         lvb->lvb_iatime_packed  =
6298 @@ -1900,6 +1901,7 @@ static void ocfs2_refresh_inode_from_lvb
6299  
6300         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6301         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6302 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6303         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6304         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6305         ocfs2_unpack_timespec(&inode->i_atime,
6306 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/dlmglue.h linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/dlmglue.h
6307 --- linux-2.6.27.10/fs/ocfs2/dlmglue.h  2008-07-13 23:51:29.000000000 +0200
6308 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/dlmglue.h     2008-10-13 14:54:20.000000000 +0200
6309 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6310         __be16       lvb_inlink;
6311         __be32       lvb_iattr;
6312         __be32       lvb_igeneration;
6313 -       __be32       lvb_reserved2;
6314 +       __be16       lvb_itag;
6315 +       __be16       lvb_reserved2;
6316  };
6317  
6318  /* ocfs2_inode_lock_full() 'arg_flags' flags */
6319 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/file.c
6320 --- linux-2.6.27.10/fs/ocfs2/file.c     2008-10-13 14:52:06.000000000 +0200
6321 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/file.c        2008-10-13 14:54:20.000000000 +0200
6322 @@ -1058,13 +1058,15 @@ int ocfs2_setattr(struct dentry *dentry,
6323                 mlog(0, "uid change: %d\n", attr->ia_uid);
6324         if (attr->ia_valid & ATTR_GID)
6325                 mlog(0, "gid change: %d\n", attr->ia_gid);
6326 +       if (attr->ia_valid & ATTR_TAG)
6327 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6328         if (attr->ia_valid & ATTR_SIZE)
6329                 mlog(0, "size change...\n");
6330         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6331                 mlog(0, "time change...\n");
6332  
6333  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6334 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6335 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6336         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6337                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6338                 return 0;
6339 @@ -2227,6 +2229,7 @@ const struct inode_operations ocfs2_file
6340         .setattr        = ocfs2_setattr,
6341         .getattr        = ocfs2_getattr,
6342         .permission     = ocfs2_permission,
6343 +       .sync_flags     = ocfs2_sync_flags,
6344         .fallocate      = ocfs2_fallocate,
6345  };
6346  
6347 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/inode.c
6348 --- linux-2.6.27.10/fs/ocfs2/inode.c    2008-07-13 23:51:29.000000000 +0200
6349 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/inode.c       2008-10-13 14:54:20.000000000 +0200
6350 @@ -28,6 +28,7 @@
6351  #include <linux/slab.h>
6352  #include <linux/highmem.h>
6353  #include <linux/pagemap.h>
6354 +#include <linux/vs_tag.h>
6355  
6356  #include <asm/byteorder.h>
6357  
6358 @@ -42,6 +43,7 @@
6359  #include "file.h"
6360  #include "heartbeat.h"
6361  #include "inode.h"
6362 +#include "ioctl.h"
6363  #include "journal.h"
6364  #include "namei.h"
6365  #include "suballoc.h"
6366 @@ -74,11 +76,13 @@ void ocfs2_set_inode_flags(struct inode 
6367  {
6368         unsigned int flags = OCFS2_I(inode)->ip_attr;
6369  
6370 -       inode->i_flags &= ~(S_IMMUTABLE |
6371 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6372                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6373  
6374         if (flags & OCFS2_IMMUTABLE_FL)
6375                 inode->i_flags |= S_IMMUTABLE;
6376 +       if (flags & OCFS2_IXUNLINK_FL)
6377 +               inode->i_flags |= S_IXUNLINK;
6378  
6379         if (flags & OCFS2_SYNC_FL)
6380                 inode->i_flags |= S_SYNC;
6381 @@ -88,25 +92,85 @@ void ocfs2_set_inode_flags(struct inode 
6382                 inode->i_flags |= S_NOATIME;
6383         if (flags & OCFS2_DIRSYNC_FL)
6384                 inode->i_flags |= S_DIRSYNC;
6385 +
6386 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6387 +
6388 +       if (flags & OCFS2_BARRIER_FL)
6389 +               inode->i_vflags |= V_BARRIER;
6390 +       if (flags & OCFS2_COW_FL)
6391 +               inode->i_vflags |= V_COW;
6392  }
6393  
6394  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6395  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6396  {
6397         unsigned int flags = oi->vfs_inode.i_flags;
6398 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6399 +
6400 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6401 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6402 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6403 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6404 +
6405 +       if (flags & S_IMMUTABLE)
6406 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6407 +       if (flags & S_IXUNLINK)
6408 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6409  
6410 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6411 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6412         if (flags & S_SYNC)
6413                 oi->ip_attr |= OCFS2_SYNC_FL;
6414         if (flags & S_APPEND)
6415                 oi->ip_attr |= OCFS2_APPEND_FL;
6416 -       if (flags & S_IMMUTABLE)
6417 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6418         if (flags & S_NOATIME)
6419                 oi->ip_attr |= OCFS2_NOATIME_FL;
6420         if (flags & S_DIRSYNC)
6421                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6422 +
6423 +       if (vflags & V_BARRIER)
6424 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6425 +       if (vflags & V_COW)
6426 +               oi->ip_attr |= OCFS2_COW_FL;
6427 +}
6428 +
6429 +int ocfs2_sync_flags(struct inode *inode)
6430 +{
6431 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6432 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6433 +       handle_t *handle = NULL;
6434 +       struct buffer_head *bh = NULL;
6435 +       int status;
6436 +
6437 +       status = ocfs2_inode_lock(inode, &bh, 1);
6438 +       if (status < 0) {
6439 +               mlog_errno(status);
6440 +               goto bail;
6441 +       }
6442 +
6443 +       status = -EROFS;
6444 +       if (IS_RDONLY(inode))
6445 +               goto bail_unlock;
6446 +
6447 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6448 +       if (IS_ERR(handle)) {
6449 +               status = PTR_ERR(handle);
6450 +               mlog_errno(status);
6451 +               goto bail_unlock;
6452 +       }
6453 +
6454 +       ocfs2_get_inode_flags(ocfs2_inode);
6455 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6456 +       if (status < 0)
6457 +               mlog_errno(status);
6458 +
6459 +       ocfs2_commit_trans(osb, handle);
6460 +bail_unlock:
6461 +       ocfs2_inode_unlock(inode, 1);
6462 +bail:
6463 +       if (bh)
6464 +               brelse(bh);
6465 +
6466 +       mlog_exit(status);
6467 +       return status;
6468  }
6469  
6470  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6471 @@ -219,6 +283,8 @@ int ocfs2_populate_inode(struct inode *i
6472         struct super_block *sb;
6473         struct ocfs2_super *osb;
6474         int status = -EINVAL;
6475 +       uid_t uid;
6476 +       gid_t gid;
6477  
6478         mlog_entry("(0x%p, size:%llu)\n", inode,
6479                    (unsigned long long)le64_to_cpu(fe->i_size));
6480 @@ -254,8 +320,12 @@ int ocfs2_populate_inode(struct inode *i
6481         inode->i_generation = le32_to_cpu(fe->i_generation);
6482         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6483         inode->i_mode = le16_to_cpu(fe->i_mode);
6484 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6485 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6486 +       uid = le32_to_cpu(fe->i_uid);
6487 +       gid = le32_to_cpu(fe->i_gid);
6488 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6489 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6490 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6491 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6492  
6493         /* Fast symlinks will have i_size but no allocated clusters. */
6494         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6495 @@ -1230,8 +1300,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6496  
6497         fe->i_size = cpu_to_le64(i_size_read(inode));
6498         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6499 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6500 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6501 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6502 +               inode->i_uid, inode->i_tag));
6503 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6504 +               inode->i_gid, inode->i_tag));
6505 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6506         fe->i_mode = cpu_to_le16(inode->i_mode);
6507         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6508         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6509 @@ -1259,16 +1332,25 @@ leave:
6510  void ocfs2_refresh_inode(struct inode *inode,
6511                          struct ocfs2_dinode *fe)
6512  {
6513 +       uid_t uid;
6514 +       gid_t gid;
6515 +
6516         spin_lock(&OCFS2_I(inode)->ip_lock);
6517  
6518         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6519         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6520 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6521 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6522         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6523         ocfs2_set_inode_flags(inode);
6524         i_size_write(inode, le64_to_cpu(fe->i_size));
6525         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6526 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6527 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6528 +       uid = le32_to_cpu(fe->i_uid);
6529 +       gid = le32_to_cpu(fe->i_gid);
6530 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6531 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6532 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6533 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6534         inode->i_mode = le16_to_cpu(fe->i_mode);
6535         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6536                 inode->i_blocks = 0;
6537 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/inode.h linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/inode.h
6538 --- linux-2.6.27.10/fs/ocfs2/inode.h    2008-07-13 23:51:29.000000000 +0200
6539 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/inode.h       2008-10-13 14:54:20.000000000 +0200
6540 @@ -143,6 +143,7 @@ int ocfs2_aio_write(struct file *file, s
6541  
6542  void ocfs2_set_inode_flags(struct inode *inode);
6543  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6544 +int ocfs2_sync_flags(struct inode *inode);
6545  
6546  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6547  {
6548 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ioctl.c
6549 --- linux-2.6.27.10/fs/ocfs2/ioctl.c    2008-07-13 23:51:29.000000000 +0200
6550 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ioctl.c       2008-10-13 14:54:20.000000000 +0200
6551 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6552         return status;
6553  }
6554  
6555 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6556 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6557                                 unsigned mask)
6558  {
6559         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6560 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6561         if (!S_ISDIR(inode->i_mode))
6562                 flags &= ~OCFS2_DIRSYNC_FL;
6563  
6564 +       if (IS_BARRIER(inode)) {
6565 +               vxwprintk_task(1, "messing with the barrier.");
6566 +               goto bail_unlock;
6567 +       }
6568 +
6569         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6570         if (IS_ERR(handle)) {
6571                 status = PTR_ERR(handle);
6572 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/ioctl.h linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ioctl.h
6573 --- linux-2.6.27.10/fs/ocfs2/ioctl.h    2008-07-13 23:51:29.000000000 +0200
6574 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ioctl.h       2008-10-13 14:54:20.000000000 +0200
6575 @@ -10,6 +10,9 @@
6576  #ifndef OCFS2_IOCTL_H
6577  #define OCFS2_IOCTL_H
6578  
6579 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6580 +                               unsigned mask);
6581 +
6582  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6583  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6584  
6585 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/namei.c
6586 --- linux-2.6.27.10/fs/ocfs2/namei.c    2008-07-13 23:51:29.000000000 +0200
6587 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/namei.c       2008-10-13 14:54:20.000000000 +0200
6588 @@ -40,6 +40,7 @@
6589  #include <linux/types.h>
6590  #include <linux/slab.h>
6591  #include <linux/highmem.h>
6592 +#include <linux/vs_tag.h>
6593  
6594  #define MLOG_MASK_PREFIX ML_NAMEI
6595  #include <cluster/masklog.h>
6596 @@ -366,6 +367,9 @@ static int ocfs2_mknod_locked(struct ocf
6597         u64 fe_blkno = 0;
6598         u16 suballoc_bit;
6599         struct inode *inode = NULL;
6600 +       uid_t uid;
6601 +       gid_t gid;
6602 +       tag_t tag;
6603  
6604         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
6605                    (unsigned long)dev, dentry->d_name.len,
6606 @@ -425,13 +429,19 @@ static int ocfs2_mknod_locked(struct ocf
6607         fe->i_blkno = cpu_to_le64(fe_blkno);
6608         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6609         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6610 -       fe->i_uid = cpu_to_le32(current->fsuid);
6611 +
6612 +       tag = dx_current_fstag(osb->sb);
6613 +       uid = current->fsuid;
6614         if (dir->i_mode & S_ISGID) {
6615 -               fe->i_gid = cpu_to_le32(dir->i_gid);
6616 +               gid = dir->i_gid;
6617                 if (S_ISDIR(mode))
6618                         mode |= S_ISGID;
6619         } else
6620 -               fe->i_gid = cpu_to_le32(current->fsgid);
6621 +               gid = current->fsgid;
6622 +
6623 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
6624 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
6625 +       inode->i_tag = tag;
6626         fe->i_mode = cpu_to_le16(mode);
6627         if (S_ISCHR(mode) || S_ISBLK(mode))
6628                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6629 @@ -1917,5 +1927,6 @@ const struct inode_operations ocfs2_dir_
6630         .rename         = ocfs2_rename,
6631         .setattr        = ocfs2_setattr,
6632         .getattr        = ocfs2_getattr,
6633 +       .sync_flags     = ocfs2_sync_flags,
6634         .permission     = ocfs2_permission,
6635  };
6636 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/ocfs2_fs.h linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ocfs2_fs.h
6637 --- linux-2.6.27.10/fs/ocfs2/ocfs2_fs.h 2008-10-13 14:52:06.000000000 +0200
6638 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ocfs2_fs.h    2008-10-13 14:54:20.000000000 +0200
6639 @@ -195,18 +195,23 @@
6640  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6641  
6642  /* Inode attributes, keep in sync with EXT2 */
6643 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6644 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6645 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6646 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6647 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6648 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6649 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6650 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6651 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6652 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6653 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6654 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6655 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6656 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6657 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6658 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6659 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6660  
6661 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6662 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6663 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6664 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6665 +
6666 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6667 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6668 +
6669 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6670 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6671  
6672  /*
6673   * Extent record flags (e_node.leaf.flags)
6674 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/ocfs2.h linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ocfs2.h
6675 --- linux-2.6.27.10/fs/ocfs2/ocfs2.h    2008-10-13 14:52:06.000000000 +0200
6676 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/ocfs2.h       2008-10-13 14:54:20.000000000 +0200
6677 @@ -184,6 +184,7 @@ enum ocfs2_mount_options
6678         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
6679         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
6680         OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */
6681 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
6682  };
6683  
6684  #define OCFS2_OSB_SOFT_RO      0x0001
6685 diff -NurpP --minimal linux-2.6.27.10/fs/ocfs2/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/super.c
6686 --- linux-2.6.27.10/fs/ocfs2/super.c    2008-10-13 14:52:06.000000000 +0200
6687 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/ocfs2/super.c       2008-10-13 14:54:20.000000000 +0200
6688 @@ -154,6 +154,7 @@ enum {
6689         Opt_localalloc,
6690         Opt_localflocks,
6691         Opt_stack,
6692 +       Opt_tag, Opt_notag, Opt_tagid,
6693         Opt_err,
6694  };
6695  
6696 @@ -173,6 +174,9 @@ static match_table_t tokens = {
6697         {Opt_localalloc, "localalloc=%d"},
6698         {Opt_localflocks, "localflocks"},
6699         {Opt_stack, "cluster_stack=%s"},
6700 +       {Opt_tag, "tag"},
6701 +       {Opt_notag, "notag"},
6702 +       {Opt_tagid, "tagid=%u"},
6703         {Opt_err, NULL}
6704  };
6705  
6706 @@ -392,6 +396,13 @@ static int ocfs2_remount(struct super_bl
6707                 goto out;
6708         }
6709  
6710 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6711 +               !(sb->s_flags & MS_TAGGED)) {
6712 +               ret = -EINVAL;
6713 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6714 +               goto out;
6715 +       }
6716 +
6717         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6718             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6719                 ret = -EINVAL;
6720 @@ -725,6 +736,9 @@ static int ocfs2_fill_super(struct super
6721  
6722         ocfs2_complete_mount_recovery(osb);
6723  
6724 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6725 +               sb->s_flags |= MS_TAGGED;
6726 +
6727         if (ocfs2_mount_local(osb))
6728                 snprintf(nodestr, sizeof(nodestr), "local");
6729         else
6730 @@ -918,6 +932,20 @@ static int ocfs2_parse_options(struct su
6731                                OCFS2_STACK_LABEL_LEN);
6732                         mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
6733                         break;
6734 +#ifndef CONFIG_TAGGING_NONE
6735 +               case Opt_tag:
6736 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6737 +                       break;
6738 +               case Opt_notag:
6739 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6740 +                       break;
6741 +#endif
6742 +#ifdef CONFIG_PROPAGATE
6743 +               case Opt_tagid:
6744 +                       /* use args[0] */
6745 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6746 +                       break;
6747 +#endif
6748                 default:
6749                         mlog(ML_ERROR,
6750                              "Unrecognized mount option \"%s\" "
6751 diff -NurpP --minimal linux-2.6.27.10/fs/open.c linux-2.6.27.10-vs2.3.0.36.4/fs/open.c
6752 --- linux-2.6.27.10/fs/open.c   2008-10-13 14:52:06.000000000 +0200
6753 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/open.c      2008-10-13 14:54:20.000000000 +0200
6754 @@ -29,22 +29,31 @@
6755  #include <linux/rcupdate.h>
6756  #include <linux/audit.h>
6757  #include <linux/falloc.h>
6758 +#include <linux/vs_base.h>
6759 +#include <linux/vs_limit.h>
6760 +#include <linux/vs_dlimit.h>
6761 +#include <linux/vs_tag.h>
6762 +#include <linux/vs_cowbl.h>
6763  
6764  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6765  {
6766         int retval = -ENODEV;
6767  
6768         if (dentry) {
6769 +               struct super_block *sb = dentry->d_sb;
6770 +
6771                 retval = -ENOSYS;
6772 -               if (dentry->d_sb->s_op->statfs) {
6773 +               if (sb->s_op->statfs) {
6774                         memset(buf, 0, sizeof(*buf));
6775                         retval = security_sb_statfs(dentry);
6776                         if (retval)
6777                                 return retval;
6778 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6779 +                       retval = sb->s_op->statfs(dentry, buf);
6780                         if (retval == 0 && buf->f_frsize == 0)
6781                                 buf->f_frsize = buf->f_bsize;
6782                 }
6783 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6784 +                       vx_vsi_statfs(sb, buf);
6785         }
6786         return retval;
6787  }
6788 @@ -625,6 +634,10 @@ asmlinkage long sys_fchmodat(int dfd, co
6789         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6790         if (error)
6791                 goto out;
6792 +
6793 +       error = cow_check_and_break(&path);
6794 +       if (error)
6795 +               goto dput_and_out;
6796         inode = path.dentry->d_inode;
6797  
6798         error = mnt_want_write(path.mnt);
6799 @@ -658,11 +671,11 @@ static int chown_common(struct dentry * 
6800         newattrs.ia_valid =  ATTR_CTIME;
6801         if (user != (uid_t) -1) {
6802                 newattrs.ia_valid |= ATTR_UID;
6803 -               newattrs.ia_uid = user;
6804 +               newattrs.ia_uid = dx_map_uid(user);
6805         }
6806         if (group != (gid_t) -1) {
6807                 newattrs.ia_valid |= ATTR_GID;
6808 -               newattrs.ia_gid = group;
6809 +               newattrs.ia_gid = dx_map_gid(group);
6810         }
6811         if (!S_ISDIR(inode->i_mode))
6812                 newattrs.ia_valid |=
6813 @@ -685,7 +698,11 @@ asmlinkage long sys_chown(const char __u
6814         error = mnt_want_write(path.mnt);
6815         if (error)
6816                 goto out_release;
6817 -       error = chown_common(path.dentry, user, group);
6818 +#ifdef CONFIG_VSERVER_COWBL
6819 +       error = cow_check_and_break(&path);
6820 +       if (!error)
6821 +#endif
6822 +               error = chown_common(path.dentry, user, group);
6823         mnt_drop_write(path.mnt);
6824  out_release:
6825         path_put(&path);
6826 @@ -710,7 +727,11 @@ asmlinkage long sys_fchownat(int dfd, co
6827         error = mnt_want_write(path.mnt);
6828         if (error)
6829                 goto out_release;
6830 -       error = chown_common(path.dentry, user, group);
6831 +#ifdef CONFIG_VSERVER_COWBL
6832 +       error = cow_check_and_break(&path);
6833 +       if (!error)
6834 +#endif
6835 +               error = chown_common(path.dentry, user, group);
6836         mnt_drop_write(path.mnt);
6837  out_release:
6838         path_put(&path);
6839 @@ -729,7 +750,11 @@ asmlinkage long sys_lchown(const char __
6840         error = mnt_want_write(path.mnt);
6841         if (error)
6842                 goto out_release;
6843 -       error = chown_common(path.dentry, user, group);
6844 +#ifdef CONFIG_VSERVER_COWBL
6845 +       error = cow_check_and_break(&path);
6846 +       if (!error)
6847 +#endif
6848 +               error = chown_common(path.dentry, user, group);
6849         mnt_drop_write(path.mnt);
6850  out_release:
6851         path_put(&path);
6852 @@ -969,6 +994,7 @@ static void __put_unused_fd(struct files
6853         __FD_CLR(fd, fdt->open_fds);
6854         if (fd < files->next_fd)
6855                 files->next_fd = fd;
6856 +       vx_openfd_dec(fd);
6857  }
6858  
6859  void put_unused_fd(unsigned int fd)
6860 diff -NurpP --minimal linux-2.6.27.10/fs/proc/array.c linux-2.6.27.10-vs2.3.0.36.4/fs/proc/array.c
6861 --- linux-2.6.27.10/fs/proc/array.c     2008-10-13 14:52:06.000000000 +0200
6862 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/array.c        2008-10-13 14:54:20.000000000 +0200
6863 @@ -81,6 +81,8 @@
6864  #include <linux/seq_file.h>
6865  #include <linux/pid_namespace.h>
6866  #include <linux/tracehook.h>
6867 +#include <linux/vs_context.h>
6868 +#include <linux/vs_network.h>
6869  
6870  #include <asm/pgtable.h>
6871  #include <asm/processor.h>
6872 @@ -142,8 +144,9 @@ static const char *task_state_array[] = 
6873         "D (disk sleep)",       /*  2 */
6874         "T (stopped)",          /*  4 */
6875         "T (tracing stop)",     /*  8 */
6876 -       "Z (zombie)",           /* 16 */
6877 -       "X (dead)"              /* 32 */
6878 +       "H (on hold)",          /* 16 */
6879 +       "Z (zombie)",           /* 32 */
6880 +       "X (dead)",             /* 64 */
6881  };
6882  
6883  static inline const char *get_task_state(struct task_struct *tsk)
6884 @@ -164,6 +167,7 @@ static inline void task_state(struct seq
6885         struct group_info *group_info;
6886         int g;
6887         struct fdtable *fdt = NULL;
6888 +/* +   pid_t pid, ptgid, tppid, tgid; */
6889         pid_t ppid, tpid;
6890  
6891         rcu_read_lock();
6892 @@ -175,6 +179,12 @@ static inline void task_state(struct seq
6893                 if (tracer)
6894                         tpid = task_pid_nr_ns(tracer, ns);
6895         }
6896 +/*     tgid = vx_map_tgid(p->tgid);
6897 +       pid = vx_map_pid(p->pid);
6898 +       ptgid = vx_map_pid(pid_alive(p) ?
6899 +               rcu_dereference(p->real_parent)->tgid : 0);
6900 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
6901 +               rcu_dereference(p->parent)->pid : 0); */
6902         seq_printf(m,
6903                 "State:\t%s\n"
6904                 "Tgid:\t%d\n"
6905 @@ -286,7 +296,7 @@ static inline void task_sig(struct seq_f
6906  }
6907  
6908  static void render_cap_t(struct seq_file *m, const char *header,
6909 -                       kernel_cap_t *a)
6910 +                       struct vx_info *vxi, kernel_cap_t *a)
6911  {
6912         unsigned __capi;
6913  
6914 @@ -300,10 +310,10 @@ static void render_cap_t(struct seq_file
6915  
6916  static inline void task_cap(struct seq_file *m, struct task_struct *p)
6917  {
6918 -       render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
6919 -       render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
6920 -       render_cap_t(m, "CapEff:\t", &p->cap_effective);
6921 -       render_cap_t(m, "CapBnd:\t", &p->cap_bset);
6922 +       render_cap_t(m, "CapInh:\t", p->vx_info, &p->cap_inheritable);
6923 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &p->cap_permitted);
6924 +       render_cap_t(m, "CapEff:\t", p->vx_info, &p->cap_effective);
6925 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &p->cap_bset);
6926  }
6927  
6928  static inline void task_context_switch_counts(struct seq_file *m,
6929 @@ -315,6 +325,45 @@ static inline void task_context_switch_c
6930                         p->nivcsw);
6931  }
6932  
6933 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6934 +                       struct pid *pid, struct task_struct *task)
6935 +{
6936 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6937 +                       "Count:\t%u\n"
6938 +                       "uts:\t%p(%c)\n"
6939 +                       "ipc:\t%p(%c)\n"
6940 +                       "mnt:\t%p(%c)\n"
6941 +                       "pid:\t%p(%c)\n"
6942 +                       "user:\t%p(%c)\n"
6943 +                       "net:\t%p(%c)\n",
6944 +                       task->nsproxy,
6945 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6946 +                       atomic_read(&task->nsproxy->count),
6947 +                       task->nsproxy->uts_ns,
6948 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6949 +                       task->nsproxy->ipc_ns,
6950 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6951 +                       task->nsproxy->mnt_ns,
6952 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6953 +                       task->nsproxy->pid_ns,
6954 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6955 +                       task->nsproxy->user_ns,
6956 +                       (task->nsproxy->user_ns == init_task.nsproxy->user_ns ? 'I' : '-'),
6957 +                       task->nsproxy->net_ns,
6958 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6959 +       return 0;
6960 +}
6961 +
6962 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6963 +{
6964 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6965 +               return;
6966 +
6967 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6968 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6969 +}
6970 +
6971 +
6972  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6973                         struct pid *pid, struct task_struct *task)
6974  {
6975 @@ -330,6 +379,7 @@ int proc_pid_status(struct seq_file *m, 
6976         task_sig(m, task);
6977         task_cap(m, task);
6978         cpuset_task_status_allowed(m, task);
6979 +       task_vs_id(m, task);
6980  #if defined(CONFIG_S390)
6981         task_show_regs(m, task);
6982  #endif
6983 @@ -442,6 +492,17 @@ static int do_task_stat(struct seq_file 
6984         /* convert nsec -> ticks */
6985         start_time = nsec_to_clock_t(start_time);
6986  
6987 +       /* fixup start time for virt uptime */
6988 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6989 +               unsigned long long bias =
6990 +                       current->vx_info->cvirt.bias_clock;
6991 +
6992 +               if (start_time > bias)
6993 +                       start_time -= bias;
6994 +               else
6995 +                       start_time = 0;
6996 +       }
6997 +
6998         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6999  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
7000  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
7001 diff -NurpP --minimal linux-2.6.27.10/fs/proc/base.c linux-2.6.27.10-vs2.3.0.36.4/fs/proc/base.c
7002 --- linux-2.6.27.10/fs/proc/base.c      2008-10-13 14:52:06.000000000 +0200
7003 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/base.c 2008-10-13 14:54:20.000000000 +0200
7004 @@ -79,6 +79,8 @@
7005  #include <linux/oom.h>
7006  #include <linux/elf.h>
7007  #include <linux/pid_namespace.h>
7008 +#include <linux/vs_context.h>
7009 +#include <linux/vs_network.h>
7010  #include "internal.h"
7011  
7012  /* NOTE:
7013 @@ -1439,6 +1441,8 @@ static struct inode *proc_pid_make_inode
7014                 inode->i_uid = task->euid;
7015                 inode->i_gid = task->egid;
7016         }
7017 +       /* procfs is xid tagged */
7018 +       inode->i_tag = (tag_t)vx_task_xid(task);
7019         security_task_to_inode(task, inode);
7020  
7021  out:
7022 @@ -1979,6 +1983,13 @@ static struct dentry *proc_pident_lookup
7023         if (!task)
7024                 goto out_no_task;
7025  
7026 +       /* TODO: maybe we can come up with a generic approach? */
7027 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
7028 +               (dentry->d_name.len == 5) &&
7029 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
7030 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
7031 +               goto out;
7032 +
7033         /*
7034          * Yes, it does not scale. And it should not. Don't add
7035          * new entries into /proc/<tgid>/ without very good reasons.
7036 @@ -2366,7 +2377,7 @@ out_iput:
7037  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
7038  {
7039         struct dentry *error;
7040 -       struct task_struct *task = get_proc_task(dir);
7041 +       struct task_struct *task = get_proc_task_real(dir);
7042         const struct pid_entry *p, *last;
7043  
7044         error = ERR_PTR(-ENOENT);
7045 @@ -2449,6 +2460,9 @@ static int proc_tgid_io_accounting(struc
7046  static const struct file_operations proc_task_operations;
7047  static const struct inode_operations proc_task_inode_operations;
7048  
7049 +extern int proc_pid_vx_info(struct task_struct *, char *);
7050 +extern int proc_pid_nx_info(struct task_struct *, char *);
7051 +
7052  static const struct pid_entry tgid_base_stuff[] = {
7053         DIR("task",       S_IRUGO|S_IXUGO, task),
7054         DIR("fd",         S_IRUSR|S_IXUSR, fd),
7055 @@ -2503,6 +2517,8 @@ static const struct pid_entry tgid_base_
7056  #ifdef CONFIG_CGROUPS
7057         REG("cgroup",  S_IRUGO, cgroup),
7058  #endif
7059 +       INF("vinfo",      S_IRUGO, pid_vx_info),
7060 +       INF("ninfo",      S_IRUGO, pid_nx_info),
7061         INF("oom_score",  S_IRUGO, oom_score),
7062         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
7063  #ifdef CONFIG_AUDITSYSCALL
7064 @@ -2518,6 +2534,7 @@ static const struct pid_entry tgid_base_
7065  #ifdef CONFIG_TASK_IO_ACCOUNTING
7066         INF("io",       S_IRUGO, tgid_io_accounting),
7067  #endif
7068 +       ONE("nsproxy",  S_IRUGO, pid_nsproxy),
7069  };
7070  
7071  static int proc_tgid_base_readdir(struct file * filp,
7072 @@ -2714,7 +2731,7 @@ retry:
7073         iter.task = NULL;
7074         pid = find_ge_pid(iter.tgid, ns);
7075         if (pid) {
7076 -               iter.tgid = pid_nr_ns(pid, ns);
7077 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7078                 iter.task = pid_task(pid, PIDTYPE_PID);
7079                 /* What we to know is if the pid we have find is the
7080                  * pid of a thread_group_leader.  Testing for task
7081 @@ -2744,7 +2761,7 @@ static int proc_pid_fill_cache(struct fi
7082         struct tgid_iter iter)
7083  {
7084         char name[PROC_NUMBUF];
7085 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7086 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7087         return proc_fill_cache(filp, dirent, filldir, name, len,
7088                                 proc_pid_instantiate, iter.task, NULL);
7089  }
7090 @@ -2753,7 +2770,7 @@ static int proc_pid_fill_cache(struct fi
7091  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7092  {
7093         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7094 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7095 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7096         struct tgid_iter iter;
7097         struct pid_namespace *ns;
7098  
7099 @@ -2773,6 +2790,8 @@ int proc_pid_readdir(struct file * filp,
7100              iter.task;
7101              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7102                 filp->f_pos = iter.tgid + TGID_OFFSET;
7103 +               if (!vx_proc_task_visible(iter.task))
7104 +                       continue;
7105                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7106                         put_task_struct(iter.task);
7107                         goto out;
7108 @@ -2915,6 +2934,8 @@ static struct dentry *proc_task_lookup(s
7109         tid = name_to_int(dentry);
7110         if (tid == ~0U)
7111                 goto out;
7112 +       if (vx_current_initpid(tid))
7113 +               goto out;
7114  
7115         ns = dentry->d_sb->s_fs_info;
7116         rcu_read_lock();
7117 diff -NurpP --minimal linux-2.6.27.10/fs/proc/generic.c linux-2.6.27.10-vs2.3.0.36.4/fs/proc/generic.c
7118 --- linux-2.6.27.10/fs/proc/generic.c   2008-10-13 14:52:06.000000000 +0200
7119 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/generic.c      2008-10-13 14:54:20.000000000 +0200
7120 @@ -21,6 +21,7 @@
7121  #include <linux/bitops.h>
7122  #include <linux/spinlock.h>
7123  #include <linux/completion.h>
7124 +#include <linux/vserver/inode.h>
7125  #include <asm/uaccess.h>
7126  
7127  #include "internal.h"
7128 @@ -384,6 +385,8 @@ struct dentry *proc_lookup_de(struct pro
7129         for (de = de->subdir; de ; de = de->next) {
7130                 if (de->namelen != dentry->d_name.len)
7131                         continue;
7132 +                       if (!vx_hide_check(0, de->vx_flags))
7133 +                               continue;
7134                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7135                         unsigned int ino;
7136  
7137 @@ -392,6 +395,8 @@ struct dentry *proc_lookup_de(struct pro
7138                         spin_unlock(&proc_subdir_lock);
7139                         error = -EINVAL;
7140                         inode = proc_get_inode(dir->i_sb, ino, de);
7141 +                               /* generic proc entries belong to the host */
7142 +                               inode->i_tag = 0;
7143                         goto out_unlock;
7144                 }
7145         }
7146 @@ -472,6 +477,8 @@ int proc_readdir_de(struct proc_dir_entr
7147  
7148                                 /* filldir passes info to user space */
7149                                 de_get(de);
7150 +                               if (!vx_hide_check(0, de->vx_flags))
7151 +                                       goto skip;
7152                                 spin_unlock(&proc_subdir_lock);
7153                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7154                                             de->low_ino, de->mode >> 12) < 0) {
7155 @@ -479,6 +486,7 @@ int proc_readdir_de(struct proc_dir_entr
7156                                         goto out;
7157                                 }
7158                                 spin_lock(&proc_subdir_lock);
7159 +                       skip:
7160                                 filp->f_pos++;
7161                                 next = de->next;
7162                                 de_put(de);
7163 @@ -593,6 +601,7 @@ static struct proc_dir_entry *__proc_cre
7164         ent->nlink = nlink;
7165         atomic_set(&ent->count, 1);
7166         ent->pde_users = 0;
7167 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7168         spin_lock_init(&ent->pde_unload_lock);
7169         ent->pde_unload_completion = NULL;
7170         INIT_LIST_HEAD(&ent->pde_openers);
7171 @@ -616,7 +625,8 @@ struct proc_dir_entry *proc_symlink(cons
7172                                 kfree(ent->data);
7173                                 kfree(ent);
7174                                 ent = NULL;
7175 -                       }
7176 +                       } else
7177 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7178                 } else {
7179                         kfree(ent);
7180                         ent = NULL;
7181 diff -NurpP --minimal linux-2.6.27.10/fs/proc/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/proc/inode.c
7182 --- linux-2.6.27.10/fs/proc/inode.c     2008-10-13 14:52:06.000000000 +0200
7183 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/inode.c        2008-10-13 14:54:20.000000000 +0200
7184 @@ -469,6 +469,8 @@ struct inode *proc_get_inode(struct supe
7185                         inode->i_uid = de->uid;
7186                         inode->i_gid = de->gid;
7187                 }
7188 +               if (de->vx_flags)
7189 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7190                 if (de->size)
7191                         inode->i_size = de->size;
7192                 if (de->nlink)
7193 diff -NurpP --minimal linux-2.6.27.10/fs/proc/internal.h linux-2.6.27.10-vs2.3.0.36.4/fs/proc/internal.h
7194 --- linux-2.6.27.10/fs/proc/internal.h  2008-10-13 14:52:06.000000000 +0200
7195 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/internal.h     2008-10-13 14:54:20.000000000 +0200
7196 @@ -10,6 +10,7 @@
7197   */
7198  
7199  #include <linux/proc_fs.h>
7200 +#include <linux/vs_pid.h>
7201  
7202  extern struct proc_dir_entry proc_root;
7203  #ifdef CONFIG_PROC_SYSCTL
7204 @@ -55,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
7205                                 struct pid *pid, struct task_struct *task);
7206  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7207                                 struct pid *pid, struct task_struct *task);
7208 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7209 +                               struct pid *pid, struct task_struct *task);
7210 +
7211  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7212  
7213  extern const struct file_operations proc_maps_operations;
7214 @@ -75,11 +79,16 @@ static inline struct pid *proc_pid(struc
7215         return PROC_I(inode)->pid;
7216  }
7217  
7218 -static inline struct task_struct *get_proc_task(struct inode *inode)
7219 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7220  {
7221         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7222  }
7223  
7224 +static inline struct task_struct *get_proc_task(struct inode *inode)
7225 +{
7226 +       return vx_get_proc_task(inode, proc_pid(inode));
7227 +}
7228 +
7229  static inline int proc_fd(struct inode *inode)
7230  {
7231         return PROC_I(inode)->fd;
7232 diff -NurpP --minimal linux-2.6.27.10/fs/proc/proc_misc.c linux-2.6.27.10-vs2.3.0.36.4/fs/proc/proc_misc.c
7233 --- linux-2.6.27.10/fs/proc/proc_misc.c 2008-10-13 14:52:06.000000000 +0200
7234 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/proc_misc.c    2008-10-13 14:54:20.000000000 +0200
7235 @@ -57,6 +57,8 @@
7236  #include <asm/div64.h>
7237  #include "internal.h"
7238  
7239 +#include <linux/vs_cvirt.h>
7240 +
7241  #define LOAD_INT(x) ((x) >> FSHIFT)
7242  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
7243  /*
7244 @@ -84,22 +86,38 @@ static int proc_calc_metrics(char *page,
7245  static int loadavg_read_proc(char *page, char **start, off_t off,
7246                                  int count, int *eof, void *data)
7247  {
7248 +       unsigned long running;
7249 +       unsigned int threads;
7250         int a, b, c;
7251         int len;
7252         unsigned long seq;
7253  
7254         do {
7255                 seq = read_seqbegin(&xtime_lock);
7256 -               a = avenrun[0] + (FIXED_1/200);
7257 -               b = avenrun[1] + (FIXED_1/200);
7258 -               c = avenrun[2] + (FIXED_1/200);
7259 +               if (vx_flags(VXF_VIRT_LOAD, 0)) {
7260 +                       struct vx_info *vxi = current->vx_info;
7261 +
7262 +                       a = vxi->cvirt.load[0] + (FIXED_1/200);
7263 +                       b = vxi->cvirt.load[1] + (FIXED_1/200);
7264 +                       c = vxi->cvirt.load[2] + (FIXED_1/200);
7265 +
7266 +                       running = atomic_read(&vxi->cvirt.nr_running);
7267 +                       threads = atomic_read(&vxi->cvirt.nr_threads);
7268 +               } else {
7269 +                       a = avenrun[0] + (FIXED_1/200);
7270 +                       b = avenrun[1] + (FIXED_1/200);
7271 +                       c = avenrun[2] + (FIXED_1/200);
7272 +
7273 +                       running = nr_running();
7274 +                       threads = nr_threads;
7275 +               }
7276         } while (read_seqretry(&xtime_lock, seq));
7277  
7278         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
7279                 LOAD_INT(a), LOAD_FRAC(a),
7280                 LOAD_INT(b), LOAD_FRAC(b),
7281                 LOAD_INT(c), LOAD_FRAC(c),
7282 -               nr_running(), nr_threads,
7283 +               running, threads,
7284                 task_active_pid_ns(current)->last_pid);
7285         return proc_calc_metrics(page, start, off, count, eof, len);
7286  }
7287 @@ -115,6 +133,9 @@ static int uptime_read_proc(char *page, 
7288         do_posix_clock_monotonic_gettime(&uptime);
7289         monotonic_to_bootbased(&uptime);
7290         cputime_to_timespec(idletime, &idle);
7291 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7292 +               vx_vsi_uptime(&uptime, &idle);
7293 +
7294         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
7295                         (unsigned long) uptime.tv_sec,
7296                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7297 @@ -151,7 +172,7 @@ static int meminfo_read_proc(char *page,
7298  
7299         cached = global_page_state(NR_FILE_PAGES) -
7300                         total_swapcache_pages - i.bufferram;
7301 -       if (cached < 0)
7302 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7303                 cached = 0;
7304  
7305         get_vmalloc_info(&vmi);
7306 diff -NurpP --minimal linux-2.6.27.10/fs/proc/root.c linux-2.6.27.10-vs2.3.0.36.4/fs/proc/root.c
7307 --- linux-2.6.27.10/fs/proc/root.c      2008-07-13 23:51:29.000000000 +0200
7308 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/proc/root.c 2008-11-20 00:58:27.000000000 +0100
7309 @@ -19,9 +19,14 @@
7310  #include <linux/smp_lock.h>
7311  #include <linux/mount.h>
7312  #include <linux/pid_namespace.h>
7313 +#include <linux/vserver/inode.h>
7314  
7315  #include "internal.h"
7316  
7317 +struct proc_dir_entry *proc_virtual;
7318 +
7319 +extern void proc_vx_init(void);
7320 +
7321  static int proc_test_super(struct super_block *sb, void *data)
7322  {
7323         return sb->s_fs_info == data;
7324 @@ -137,6 +142,7 @@ void __init proc_root_init(void)
7325  #endif
7326         proc_mkdir("bus", NULL);
7327         proc_sys_init();
7328 +       proc_vx_init();
7329  }
7330  
7331  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7332 @@ -209,6 +215,7 @@ struct proc_dir_entry proc_root = {
7333         .proc_iops      = &proc_root_inode_operations, 
7334         .proc_fops      = &proc_root_operations,
7335         .parent         = &proc_root,
7336 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7337  };
7338  
7339  int pid_ns_prepare_proc(struct pid_namespace *ns)
7340 diff -NurpP --minimal linux-2.6.27.10/fs/quota.c linux-2.6.27.10-vs2.3.0.36.4/fs/quota.c
7341 --- linux-2.6.27.10/fs/quota.c  2008-10-13 14:52:06.000000000 +0200
7342 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/quota.c     2008-10-13 14:54:20.000000000 +0200
7343 @@ -18,6 +18,7 @@
7344  #include <linux/capability.h>
7345  #include <linux/quotaops.h>
7346  #include <linux/types.h>
7347 +#include <linux/vs_context.h>
7348  
7349  /* Check validity of generic quotactl commands */
7350  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7351 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7352         if (cmd == Q_GETQUOTA) {
7353                 if (((type == USRQUOTA && current->euid != id) ||
7354                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7355 -                   !capable(CAP_SYS_ADMIN))
7356 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7357                         return -EPERM;
7358         }
7359         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7360 -               if (!capable(CAP_SYS_ADMIN))
7361 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7362                         return -EPERM;
7363  
7364         return 0;
7365 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7366         if (cmd == Q_XGETQUOTA) {
7367                 if (((type == XQM_USRQUOTA && current->euid != id) ||
7368                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7369 -                    !capable(CAP_SYS_ADMIN))
7370 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7371                         return -EPERM;
7372         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7373 -               if (!capable(CAP_SYS_ADMIN))
7374 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7375                         return -EPERM;
7376         }
7377  
7378 @@ -334,6 +335,46 @@ static int do_quotactl(struct super_bloc
7379         return 0;
7380  }
7381  
7382 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7383 +
7384 +#include <linux/vroot.h>
7385 +#include <linux/major.h>
7386 +#include <linux/module.h>
7387 +#include <linux/kallsyms.h>
7388 +#include <linux/vserver/debug.h>
7389 +
7390 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7391 +
7392 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7393 +
7394 +int register_vroot_grb(vroot_grb_func *func) {
7395 +       int ret = -EBUSY;
7396 +
7397 +       spin_lock(&vroot_grb_lock);
7398 +       if (!vroot_get_real_bdev) {
7399 +               vroot_get_real_bdev = func;
7400 +               ret = 0;
7401 +       }
7402 +       spin_unlock(&vroot_grb_lock);
7403 +       return ret;
7404 +}
7405 +EXPORT_SYMBOL(register_vroot_grb);
7406 +
7407 +int unregister_vroot_grb(vroot_grb_func *func) {
7408 +       int ret = -EINVAL;
7409 +
7410 +       spin_lock(&vroot_grb_lock);
7411 +       if (vroot_get_real_bdev) {
7412 +               vroot_get_real_bdev = NULL;
7413 +               ret = 0;
7414 +       }
7415 +       spin_unlock(&vroot_grb_lock);
7416 +       return ret;
7417 +}
7418 +EXPORT_SYMBOL(unregister_vroot_grb);
7419 +
7420 +#endif
7421 +
7422  /*
7423   * look up a superblock on which quota ops will be performed
7424   * - use the name of a block device to find the superblock thereon
7425 @@ -351,6 +392,22 @@ static inline struct super_block *quotac
7426         putname(tmp);
7427         if (IS_ERR(bdev))
7428                 return ERR_CAST(bdev);
7429 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7430 +       if (bdev && bdev->bd_inode &&
7431 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7432 +               struct block_device *bdnew = (void *)-EINVAL;
7433 +
7434 +               if (vroot_get_real_bdev)
7435 +                       bdnew = vroot_get_real_bdev(bdev);
7436 +               else
7437 +                       vxdprintk(VXD_CBIT(misc, 0),
7438 +                                       "vroot_get_real_bdev not set");
7439 +               bdput(bdev);
7440 +               if (IS_ERR(bdnew))
7441 +                       return ERR_PTR(PTR_ERR(bdnew));
7442 +               bdev = bdnew;
7443 +       }
7444 +#endif
7445         sb = get_super(bdev);
7446         bdput(bdev);
7447         if (!sb)
7448 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/bitmap.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/bitmap.c
7449 --- linux-2.6.27.10/fs/reiserfs/bitmap.c        2008-07-13 23:51:29.000000000 +0200
7450 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/bitmap.c   2008-10-13 14:54:20.000000000 +0200
7451 @@ -13,6 +13,7 @@
7452  #include <linux/reiserfs_fs_sb.h>
7453  #include <linux/reiserfs_fs_i.h>
7454  #include <linux/quotaops.h>
7455 +#include <linux/vs_dlimit.h>
7456  
7457  #define PREALLOCATION_SIZE 9
7458  
7459 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7460         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7461  
7462         journal_mark_dirty(th, s, sbh);
7463 -       if (for_unformatted)
7464 +       if (for_unformatted) {
7465 +               DLIMIT_FREE_BLOCK(inode, 1);
7466                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7467 +       }
7468  }
7469  
7470  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7471 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7472         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7473         int passno = 0;
7474         int nr_allocated = 0;
7475 +       int blocks;
7476  
7477         determine_prealloc_size(hint);
7478         if (!hint->formatted_node) {
7479 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7480                                "reiserquota: allocating %d blocks id=%u",
7481                                amount_needed, hint->inode->i_uid);
7482  #endif
7483 -               quota_ret =
7484 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7485 -               if (quota_ret)  /* Quota exceeded? */
7486 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7487 +                       amount_needed);
7488 +               if (quota_ret)
7489                         return QUOTA_EXCEEDED;
7490 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7491 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7492 +                               amount_needed);
7493 +                       return NO_DISK_SPACE;
7494 +               }
7495 +
7496                 if (hint->preallocate && hint->prealloc_size) {
7497  #ifdef REISERQUOTA_DEBUG
7498                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7499                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7500                                        hint->prealloc_size, hint->inode->i_uid);
7501  #endif
7502 -                       quota_ret =
7503 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7504 -                                                        hint->prealloc_size);
7505 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7506 +                               hint->prealloc_size);
7507 +                       if (!quota_ret &&
7508 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7509 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7510 +                                       hint->prealloc_size);
7511 +                               quota_ret = 1;
7512 +                       }
7513                         if (quota_ret)
7514                                 hint->preallocate = hint->prealloc_size = 0;
7515                 }
7516 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7517                                                nr_allocated,
7518                                                hint->inode->i_uid);
7519  #endif
7520 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7521 +                               /* Free not allocated blocks */
7522 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7523 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7524 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7525                         }
7526                         while (nr_allocated--)
7527                                 reiserfs_free_block(hint->th, hint->inode,
7528 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7529                                REISERFS_I(hint->inode)->i_prealloc_count,
7530                                hint->inode->i_uid);
7531  #endif
7532 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7533 -                                        hint->prealloc_size - nr_allocated -
7534 -                                        REISERFS_I(hint->inode)->
7535 -                                        i_prealloc_count);
7536 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7537 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7538 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7539 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7540         }
7541  
7542         return CARRY_ON;
7543 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/file.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/file.c
7544 --- linux-2.6.27.10/fs/reiserfs/file.c  2008-07-13 23:51:29.000000000 +0200
7545 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/file.c     2008-10-13 14:54:20.000000000 +0200
7546 @@ -306,4 +306,5 @@ const struct inode_operations reiserfs_f
7547         .listxattr = reiserfs_listxattr,
7548         .removexattr = reiserfs_removexattr,
7549         .permission = reiserfs_permission,
7550 +       .sync_flags = reiserfs_sync_flags,
7551  };
7552 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/inode.c
7553 --- linux-2.6.27.10/fs/reiserfs/inode.c 2008-10-13 14:52:06.000000000 +0200
7554 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/inode.c    2008-10-13 14:54:20.000000000 +0200
7555 @@ -18,6 +18,8 @@
7556  #include <linux/writeback.h>
7557  #include <linux/quotaops.h>
7558  #include <linux/swap.h>
7559 +#include <linux/vs_dlimit.h>
7560 +#include <linux/vs_tag.h>
7561  
7562  int reiserfs_commit_write(struct file *f, struct page *page,
7563                           unsigned from, unsigned to);
7564 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7565                  * stat data deletion */
7566                 if (!err) 
7567                         DQUOT_FREE_INODE(inode);
7568 +               DLIMIT_FREE_INODE(inode);
7569  
7570                 if (journal_end(&th, inode->i_sb, jbegin_count))
7571                         goto out;
7572 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7573         struct buffer_head *bh;
7574         struct item_head *ih;
7575         __u32 rdev;
7576 +       uid_t uid;
7577 +       gid_t gid;
7578         //int version = ITEM_VERSION_1;
7579  
7580         bh = PATH_PLAST_BUFFER(path);
7581 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7582                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7583                 unsigned long blocks;
7584  
7585 +               uid = sd_v1_uid(sd);
7586 +               gid = sd_v1_gid(sd);
7587 +
7588                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7589                 set_inode_sd_version(inode, STAT_DATA_V1);
7590                 inode->i_mode = sd_v1_mode(sd);
7591                 inode->i_nlink = sd_v1_nlink(sd);
7592 -               inode->i_uid = sd_v1_uid(sd);
7593 -               inode->i_gid = sd_v1_gid(sd);
7594                 inode->i_size = sd_v1_size(sd);
7595                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7596                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7597 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7598                 // (directories and symlinks)
7599                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7600  
7601 +               uid    = sd_v2_uid(sd);
7602 +               gid    = sd_v2_gid(sd);
7603 +
7604                 inode->i_mode = sd_v2_mode(sd);
7605                 inode->i_nlink = sd_v2_nlink(sd);
7606 -               inode->i_uid = sd_v2_uid(sd);
7607                 inode->i_size = sd_v2_size(sd);
7608 -               inode->i_gid = sd_v2_gid(sd);
7609                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7610                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7611                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7612 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7613                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7614         }
7615  
7616 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7617 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7618 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7619 +
7620         pathrelse(path);
7621         if (S_ISREG(inode->i_mode)) {
7622                 inode->i_op = &reiserfs_file_inode_operations;
7623 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7624  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7625  {
7626         struct stat_data *sd_v2 = (struct stat_data *)sd;
7627 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7628 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7629         __u16 flags;
7630  
7631 +       set_sd_v2_uid(sd_v2, uid);
7632 +       set_sd_v2_gid(sd_v2, gid);
7633         set_sd_v2_mode(sd_v2, inode->i_mode);
7634         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7635 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7636         set_sd_v2_size(sd_v2, size);
7637 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7638         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7639         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7640         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7641 @@ -1771,6 +1784,10 @@ int reiserfs_new_inode(struct reiserfs_t
7642  
7643         BUG_ON(!th->t_trans_id);
7644  
7645 +       if (DLIMIT_ALLOC_INODE(inode)) {
7646 +               err = -ENOSPC;
7647 +               goto out_bad_dlimit;
7648 +       }
7649         if (DQUOT_ALLOC_INODE(inode)) {
7650                 err = -EDQUOT;
7651                 goto out_end_trans;
7652 @@ -1956,6 +1973,9 @@ int reiserfs_new_inode(struct reiserfs_t
7653         DQUOT_FREE_INODE(inode);
7654  
7655        out_end_trans:
7656 +       DLIMIT_FREE_INODE(inode);
7657 +
7658 +      out_bad_dlimit:
7659         journal_end(th, th->t_super, th->t_blocks_allocated);
7660         /* Drop can be outside and it needs more credits so it's better to have it outside */
7661         DQUOT_DROP(inode);
7662 @@ -2842,14 +2862,19 @@ int reiserfs_commit_write(struct file *f
7663  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7664  {
7665         if (reiserfs_attrs(inode->i_sb)) {
7666 -               if (sd_attrs & REISERFS_SYNC_FL)
7667 -                       inode->i_flags |= S_SYNC;
7668 -               else
7669 -                       inode->i_flags &= ~S_SYNC;
7670                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7671                         inode->i_flags |= S_IMMUTABLE;
7672                 else
7673                         inode->i_flags &= ~S_IMMUTABLE;
7674 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7675 +                       inode->i_flags |= S_IXUNLINK;
7676 +               else
7677 +                       inode->i_flags &= ~S_IXUNLINK;
7678 +
7679 +               if (sd_attrs & REISERFS_SYNC_FL)
7680 +                       inode->i_flags |= S_SYNC;
7681 +               else
7682 +                       inode->i_flags &= ~S_SYNC;
7683                 if (sd_attrs & REISERFS_APPEND_FL)
7684                         inode->i_flags |= S_APPEND;
7685                 else
7686 @@ -2862,6 +2887,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7687                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7688                 else
7689                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7690 +
7691 +               if (sd_attrs & REISERFS_BARRIER_FL)
7692 +                       inode->i_vflags |= V_BARRIER;
7693 +               else
7694 +                       inode->i_vflags &= ~V_BARRIER;
7695 +               if (sd_attrs & REISERFS_COW_FL)
7696 +                       inode->i_vflags |= V_COW;
7697 +               else
7698 +                       inode->i_vflags &= ~V_COW;
7699         }
7700  }
7701  
7702 @@ -2872,6 +2906,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7703                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7704                 else
7705                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7706 +               if (inode->i_flags & S_IXUNLINK)
7707 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7708 +               else
7709 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7710 +
7711                 if (inode->i_flags & S_SYNC)
7712                         *sd_attrs |= REISERFS_SYNC_FL;
7713                 else
7714 @@ -2884,6 +2923,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7715                         *sd_attrs |= REISERFS_NOTAIL_FL;
7716                 else
7717                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7718 +
7719 +               if (inode->i_vflags & V_BARRIER)
7720 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7721 +               else
7722 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7723 +               if (inode->i_vflags & V_COW)
7724 +                       *sd_attrs |= REISERFS_COW_FL;
7725 +               else
7726 +                       *sd_attrs &= ~REISERFS_COW_FL;
7727         }
7728  }
7729  
7730 @@ -3051,6 +3099,22 @@ static ssize_t reiserfs_direct_IO(int rw
7731                                   reiserfs_get_blocks_direct_io, NULL);
7732  }
7733  
7734 +int reiserfs_sync_flags(struct inode *inode)
7735 +{
7736 +       u16 oldflags, newflags;
7737 +
7738 +       oldflags = REISERFS_I(inode)->i_attrs;
7739 +       newflags = oldflags;
7740 +       i_attrs_to_sd_attrs(inode, &newflags);
7741 +
7742 +       if (oldflags ^ newflags) {
7743 +               REISERFS_I(inode)->i_attrs = newflags;
7744 +               inode->i_ctime = CURRENT_TIME_SEC;
7745 +               mark_inode_dirty(inode);
7746 +       }
7747 +       return 0;
7748 +}
7749 +
7750  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7751  {
7752         struct inode *inode = dentry->d_inode;
7753 @@ -3104,9 +3168,11 @@ int reiserfs_setattr(struct dentry *dent
7754         }
7755  
7756         error = inode_change_ok(inode, attr);
7757 +
7758         if (!error) {
7759                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7760 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7761 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7762 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7763                         error = reiserfs_chown_xattrs(inode, attr);
7764  
7765                         if (!error) {
7766 @@ -3136,6 +3202,9 @@ int reiserfs_setattr(struct dentry *dent
7767                                         inode->i_uid = attr->ia_uid;
7768                                 if (attr->ia_valid & ATTR_GID)
7769                                         inode->i_gid = attr->ia_gid;
7770 +                               if ((attr->ia_valid & ATTR_TAG) &&
7771 +                                       IS_TAGGED(inode))
7772 +                                       inode->i_tag = attr->ia_tag;
7773                                 mark_inode_dirty(inode);
7774                                 error =
7775                                     journal_end(&th, inode->i_sb, jbegin_count);
7776 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/ioctl.c
7777 --- linux-2.6.27.10/fs/reiserfs/ioctl.c 2008-07-13 23:51:29.000000000 +0200
7778 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/ioctl.c    2008-10-13 14:54:20.000000000 +0200
7779 @@ -7,6 +7,7 @@
7780  #include <linux/mount.h>
7781  #include <linux/reiserfs_fs.h>
7782  #include <linux/time.h>
7783 +#include <linux/mount.h>
7784  #include <asm/uaccess.h>
7785  #include <linux/pagemap.h>
7786  #include <linux/smp_lock.h>
7787 @@ -23,7 +24,7 @@
7788  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7789                    unsigned long arg)
7790  {
7791 -       unsigned int flags;
7792 +       unsigned int flags, oldflags;
7793         int err = 0;
7794  
7795         switch (cmd) {
7796 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7797  
7798                 flags = REISERFS_I(inode)->i_attrs;
7799                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7800 +               flags &= REISERFS_FL_USER_VISIBLE;
7801                 return put_user(flags, (int __user *)arg);
7802         case REISERFS_IOC_SETFLAGS:{
7803                         if (!reiserfs_attrs(inode->i_sb))
7804 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7805                                 err = -EFAULT;
7806                                 goto setflags_out;
7807                         }
7808 +                       if (IS_BARRIER(inode)) {
7809 +                               vxwprintk_task(1, "messing with the barrier.");
7810 +                               return -EACCES;
7811 +                       }
7812                         /*
7813                          * Is it quota file? Do not allow user to mess with it
7814                          */
7815 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7816                                         goto setflags_out;
7817                                 }
7818                         }
7819 +
7820 +                       oldflags = REISERFS_I(inode)->i_attrs;
7821 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7822 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7823                         sd_attrs_to_i_attrs(flags, inode);
7824                         REISERFS_I(inode)->i_attrs = flags;
7825                         inode->i_ctime = CURRENT_TIME_SEC;
7826 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/namei.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/namei.c
7827 --- linux-2.6.27.10/fs/reiserfs/namei.c 2008-07-13 23:51:29.000000000 +0200
7828 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/namei.c    2008-10-13 14:54:20.000000000 +0200
7829 @@ -17,6 +17,7 @@
7830  #include <linux/reiserfs_acl.h>
7831  #include <linux/reiserfs_xattr.h>
7832  #include <linux/quotaops.h>
7833 +#include <linux/vs_tag.h>
7834  
7835  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
7836  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7837 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7838                         reiserfs_write_unlock(dir->i_sb);
7839                         return ERR_PTR(-EACCES);
7840                 }
7841 +               dx_propagate_tag(nd, inode);
7842  
7843                 /* Propogate the priv_object flag so we know we're in the priv tree */
7844                 if (is_reiserfs_priv_object(dir))
7845 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
7846         } else {
7847                 inode->i_gid = current->fsgid;
7848         }
7849 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7850         DQUOT_INIT(inode);
7851         return 0;
7852  }
7853 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
7854         .listxattr = reiserfs_listxattr,
7855         .removexattr = reiserfs_removexattr,
7856         .permission = reiserfs_permission,
7857 +       .sync_flags = reiserfs_sync_flags,
7858  };
7859  
7860  /*
7861 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
7862         .listxattr = reiserfs_listxattr,
7863         .removexattr = reiserfs_removexattr,
7864         .permission = reiserfs_permission,
7865 +       .sync_flags = reiserfs_sync_flags,
7866  
7867  };
7868  
7869 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
7870         .listxattr = reiserfs_listxattr,
7871         .removexattr = reiserfs_removexattr,
7872         .permission = reiserfs_permission,
7873 +       .sync_flags = reiserfs_sync_flags,
7874  
7875  };
7876 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/stree.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/stree.c
7877 --- linux-2.6.27.10/fs/reiserfs/stree.c 2008-07-13 23:51:29.000000000 +0200
7878 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/stree.c    2008-10-13 14:54:20.000000000 +0200
7879 @@ -55,6 +55,7 @@
7880  #include <linux/reiserfs_fs.h>
7881  #include <linux/buffer_head.h>
7882  #include <linux/quotaops.h>
7883 +#include <linux/vs_dlimit.h>
7884  
7885  /* Does the buffer contain a disk block which is in the tree. */
7886  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7887 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7888                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7889                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7890  #endif
7891 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7892         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7893  
7894         /* Return deleted body length */
7895 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7896  #endif
7897                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7898                                                          quota_cut_bytes);
7899 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7900                         }
7901                         break;
7902                 }
7903 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7904                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7905                        quota_cut_bytes, p_s_inode->i_uid, '?');
7906  #endif
7907 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7908         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7909         return n_ret_value;
7910  }
7911 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7912                 pathrelse(p_s_search_path);
7913                 return -EDQUOT;
7914         }
7915 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7916 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7917 +               pathrelse(p_s_search_path);
7918 +               return -ENOSPC;
7919 +       }
7920         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7921                        n_pasted_size);
7922  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7923 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7924                        n_pasted_size, inode->i_uid,
7925                        key2type(&(p_s_key->on_disk_key)));
7926  #endif
7927 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7928         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7929         return retval;
7930  }
7931 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7932                         pathrelse(p_s_path);
7933                         return -EDQUOT;
7934                 }
7935 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7936 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7937 +                       pathrelse(p_s_path);
7938 +                       return -ENOSPC;
7939 +               }
7940         }
7941         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7942                        IH_SIZE + ih_item_len(p_s_ih));
7943 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7944                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7945                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7946  #endif
7947 -       if (inode)
7948 +       if (inode) {
7949 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7950                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7951 +       }
7952         return retval;
7953  }
7954 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/super.c
7955 --- linux-2.6.27.10/fs/reiserfs/super.c 2008-10-13 14:52:06.000000000 +0200
7956 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/super.c    2008-10-13 14:54:20.000000000 +0200
7957 @@ -898,6 +898,14 @@ static int reiserfs_parse_options(struct
7958                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7959                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7960  #endif
7961 +#ifndef CONFIG_TAGGING_NONE
7962 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7963 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7964 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7965 +#endif
7966 +#ifdef CONFIG_PROPAGATE
7967 +               {"tag",.arg_required = 'T',.values = NULL},
7968 +#endif
7969  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7970                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7971                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7972 @@ -1193,6 +1201,12 @@ static int reiserfs_remount(struct super
7973         handle_quota_files(s, qf_names, &qfmt);
7974  #endif
7975  
7976 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7977 +               !(s->s_flags & MS_TAGGED)) {
7978 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7979 +               return -EINVAL;
7980 +       }
7981 +
7982         handle_attrs(s);
7983  
7984         /* Add options that are safe here */
7985 @@ -1657,6 +1671,10 @@ static int reiserfs_fill_super(struct su
7986                 goto error;
7987         }
7988  
7989 +       /* map mount option tagxid */
7990 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7991 +               s->s_flags |= MS_TAGGED;
7992 +
7993         rs = SB_DISK_SUPER_BLOCK(s);
7994         /* Let's do basic sanity check to verify that underlying device is not
7995            smaller than the filesystem. If the check fails then abort and scream,
7996 diff -NurpP --minimal linux-2.6.27.10/fs/reiserfs/xattr.c linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/xattr.c
7997 --- linux-2.6.27.10/fs/reiserfs/xattr.c 2008-10-13 14:52:06.000000000 +0200
7998 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/reiserfs/xattr.c    2008-10-13 14:54:20.000000000 +0200
7999 @@ -35,6 +35,7 @@
8000  #include <linux/namei.h>
8001  #include <linux/errno.h>
8002  #include <linux/fs.h>
8003 +#include <linux/mount.h>
8004  #include <linux/file.h>
8005  #include <linux/pagemap.h>
8006  #include <linux/xattr.h>
8007 diff -NurpP --minimal linux-2.6.27.10/fs/stat.c linux-2.6.27.10-vs2.3.0.36.4/fs/stat.c
8008 --- linux-2.6.27.10/fs/stat.c   2008-10-13 14:52:06.000000000 +0200
8009 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/stat.c      2008-10-13 14:54:20.000000000 +0200
8010 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
8011         stat->nlink = inode->i_nlink;
8012         stat->uid = inode->i_uid;
8013         stat->gid = inode->i_gid;
8014 +       stat->tag = inode->i_tag;
8015         stat->rdev = inode->i_rdev;
8016         stat->atime = inode->i_atime;
8017         stat->mtime = inode->i_mtime;
8018 diff -NurpP --minimal linux-2.6.27.10/fs/super.c linux-2.6.27.10-vs2.3.0.36.4/fs/super.c
8019 --- linux-2.6.27.10/fs/super.c  2008-10-13 14:52:06.000000000 +0200
8020 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/super.c     2008-10-13 14:54:20.000000000 +0200
8021 @@ -38,6 +38,9 @@
8022  #include <linux/kobject.h>
8023  #include <linux/mutex.h>
8024  #include <linux/file.h>
8025 +#include <linux/devpts_fs.h>
8026 +#include <linux/proc_fs.h>
8027 +#include <linux/vs_context.h>
8028  #include <asm/uaccess.h>
8029  #include "internal.h"
8030  
8031 @@ -887,12 +890,18 @@ struct vfsmount *
8032  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
8033  {
8034         struct vfsmount *mnt;
8035 +       struct super_block *sb;
8036         char *secdata = NULL;
8037         int error;
8038  
8039         if (!type)
8040                 return ERR_PTR(-ENODEV);
8041  
8042 +       error = -EPERM;
8043 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
8044 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
8045 +               goto out;
8046 +
8047         error = -ENOMEM;
8048         mnt = alloc_vfsmnt(name);
8049         if (!mnt)
8050 @@ -913,7 +922,14 @@ vfs_kern_mount(struct file_system_type *
8051                 goto out_free_secdata;
8052         BUG_ON(!mnt->mnt_sb);
8053  
8054 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
8055 +       sb = mnt->mnt_sb;
8056 +       error = -EPERM;
8057 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
8058 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
8059 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
8060 +               goto out_sb;
8061 +
8062 +       error = security_sb_kern_mount(sb, secdata);
8063         if (error)
8064                 goto out_sb;
8065  
8066 diff -NurpP --minimal linux-2.6.27.10/fs/sysfs/mount.c linux-2.6.27.10-vs2.3.0.36.4/fs/sysfs/mount.c
8067 --- linux-2.6.27.10/fs/sysfs/mount.c    2008-07-13 23:51:29.000000000 +0200
8068 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/sysfs/mount.c       2008-10-13 14:54:20.000000000 +0200
8069 @@ -19,8 +19,6 @@
8070  
8071  #include "sysfs.h"
8072  
8073 -/* Random magic number */
8074 -#define SYSFS_MAGIC 0x62656572
8075  
8076  static struct vfsmount *sysfs_mount;
8077  struct super_block * sysfs_sb = NULL;
8078 @@ -46,7 +44,7 @@ static int sysfs_fill_super(struct super
8079  
8080         sb->s_blocksize = PAGE_CACHE_SIZE;
8081         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
8082 -       sb->s_magic = SYSFS_MAGIC;
8083 +       sb->s_magic = SYSFS_SUPER_MAGIC;
8084         sb->s_op = &sysfs_ops;
8085         sb->s_time_gran = 1;
8086         sysfs_sb = sb;
8087 diff -NurpP --minimal linux-2.6.27.10/fs/utimes.c linux-2.6.27.10-vs2.3.0.36.4/fs/utimes.c
8088 --- linux-2.6.27.10/fs/utimes.c 2008-10-13 14:52:06.000000000 +0200
8089 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/utimes.c    2008-10-13 14:54:20.000000000 +0200
8090 @@ -8,6 +8,8 @@
8091  #include <linux/stat.h>
8092  #include <linux/utime.h>
8093  #include <linux/syscalls.h>
8094 +#include <linux/mount.h>
8095 +#include <linux/vs_cowbl.h>
8096  #include <asm/uaccess.h>
8097  #include <asm/unistd.h>
8098  
8099 diff -NurpP --minimal linux-2.6.27.10/fs/xattr.c linux-2.6.27.10-vs2.3.0.36.4/fs/xattr.c
8100 --- linux-2.6.27.10/fs/xattr.c  2008-10-13 14:52:06.000000000 +0200
8101 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xattr.c     2008-10-13 14:54:20.000000000 +0200
8102 @@ -18,6 +18,7 @@
8103  #include <linux/module.h>
8104  #include <linux/fsnotify.h>
8105  #include <linux/audit.h>
8106 +#include <linux/mount.h>
8107  #include <asm/uaccess.h>
8108  
8109  
8110 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_ioctl.c
8111 --- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_ioctl.c        2008-10-13 14:52:06.000000000 +0200
8112 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_ioctl.c   2008-11-12 18:41:58.000000000 +0100
8113 @@ -806,6 +806,10 @@ xfs_merge_ioc_xflags(
8114                 xflags |= XFS_XFLAG_IMMUTABLE;
8115         else
8116                 xflags &= ~XFS_XFLAG_IMMUTABLE;
8117 +       if (flags & FS_IXUNLINK_FL)
8118 +               xflags |= XFS_XFLAG_IXUNLINK;
8119 +       else
8120 +               xflags &= ~XFS_XFLAG_IXUNLINK;
8121         if (flags & FS_APPEND_FL)
8122                 xflags |= XFS_XFLAG_APPEND;
8123         else
8124 @@ -834,6 +838,8 @@ xfs_di2lxflags(
8125  
8126         if (di_flags & XFS_DIFLAG_IMMUTABLE)
8127                 flags |= FS_IMMUTABLE_FL;
8128 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
8129 +               flags |= FS_IXUNLINK_FL;
8130         if (di_flags & XFS_DIFLAG_APPEND)
8131                 flags |= FS_APPEND_FL;
8132         if (di_flags & XFS_DIFLAG_SYNC)
8133 @@ -892,6 +898,8 @@ xfs_set_diflags(
8134         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
8135         if (xflags & XFS_XFLAG_IMMUTABLE)
8136                 di_flags |= XFS_DIFLAG_IMMUTABLE;
8137 +       if (xflags & XFS_XFLAG_IXUNLINK)
8138 +               di_flags |= XFS_DIFLAG_IXUNLINK;
8139         if (xflags & XFS_XFLAG_APPEND)
8140                 di_flags |= XFS_DIFLAG_APPEND;
8141         if (xflags & XFS_XFLAG_SYNC)
8142 @@ -934,6 +942,10 @@ xfs_diflags_to_linux(
8143                 inode->i_flags |= S_IMMUTABLE;
8144         else
8145                 inode->i_flags &= ~S_IMMUTABLE;
8146 +       if (xflags & XFS_XFLAG_IXUNLINK)
8147 +               inode->i_flags |= S_IXUNLINK;
8148 +       else
8149 +               inode->i_flags &= ~S_IXUNLINK;
8150         if (xflags & XFS_XFLAG_APPEND)
8151                 inode->i_flags |= S_APPEND;
8152         else
8153 @@ -1392,10 +1404,18 @@ xfs_ioctl(
8154         case XFS_IOC_FSGETXATTRA:
8155                 return xfs_ioc_fsgetxattr(ip, 1, arg);
8156         case XFS_IOC_FSSETXATTR:
8157 +               if (IS_BARRIER(inode)) {
8158 +                       vxwprintk_task(1, "messing with the barrier.");
8159 +                       return -XFS_ERROR(EACCES);
8160 +               }
8161                 return xfs_ioc_fssetxattr(ip, filp, arg);
8162         case XFS_IOC_GETXFLAGS:
8163                 return xfs_ioc_getxflags(ip, arg);
8164         case XFS_IOC_SETXFLAGS:
8165 +               if (IS_BARRIER(inode)) {
8166 +                       vxwprintk_task(1, "messing with the barrier.");
8167 +                       return -XFS_ERROR(EACCES);
8168 +               }
8169                 return xfs_ioc_setxflags(ip, filp, arg);
8170  
8171         case XFS_IOC_FSSETDM: {
8172 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_iops.c
8173 --- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-10-13 14:52:06.000000000 +0200
8174 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_iops.c    2008-11-12 18:41:58.000000000 +0100
8175 @@ -53,6 +53,7 @@
8176  #include <linux/namei.h>
8177  #include <linux/security.h>
8178  #include <linux/falloc.h>
8179 +#include <linux/vs_tag.h>
8180  
8181  /*
8182   * Bring the atime in the XFS inode uptodate.
8183 @@ -558,6 +559,7 @@ xfs_vn_getattr(
8184         stat->nlink = ip->i_d.di_nlink;
8185         stat->uid = ip->i_d.di_uid;
8186         stat->gid = ip->i_d.di_gid;
8187 +       stat->tag = ip->i_d.di_tag;
8188         stat->ino = ip->i_ino;
8189  #if XFS_BIG_INUMS
8190         stat->ino += mp->m_inoadd;
8191 @@ -597,6 +599,12 @@ xfs_vn_getattr(
8192  }
8193  
8194  STATIC int
8195 +xfs_vn_sync_xflags(struct inode *inode)
8196 +{
8197 +       return -xfs_sync_xflags(XFS_I(inode));
8198 +}
8199 +
8200 +STATIC int
8201  xfs_vn_setattr(
8202         struct dentry   *dentry,
8203         struct iattr    *iattr)
8204 @@ -671,6 +679,7 @@ static const struct inode_operations xfs
8205         .removexattr            = generic_removexattr,
8206         .listxattr              = xfs_vn_listxattr,
8207         .fallocate              = xfs_vn_fallocate,
8208 +       .sync_flags             = xfs_vn_sync_xflags,
8209  };
8210  
8211  static const struct inode_operations xfs_dir_inode_operations = {
8212 @@ -696,6 +705,7 @@ static const struct inode_operations xfs
8213         .getxattr               = generic_getxattr,
8214         .removexattr            = generic_removexattr,
8215         .listxattr              = xfs_vn_listxattr,
8216 +       .sync_flags             = xfs_vn_sync_xflags,
8217  };
8218  
8219  static const struct inode_operations xfs_dir_ci_inode_operations = {
8220 @@ -745,6 +755,10 @@ xfs_diflags_to_iflags(
8221                 inode->i_flags |= S_IMMUTABLE;
8222         else
8223                 inode->i_flags &= ~S_IMMUTABLE;
8224 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
8225 +               inode->i_flags |= S_IXUNLINK;
8226 +       else
8227 +               inode->i_flags &= ~S_IXUNLINK;
8228         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8229                 inode->i_flags |= S_APPEND;
8230         else
8231 @@ -757,6 +771,15 @@ xfs_diflags_to_iflags(
8232                 inode->i_flags |= S_NOATIME;
8233         else
8234                 inode->i_flags &= ~S_NOATIME;
8235 +
8236 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8237 +               inode->i_vflags |= V_BARRIER;
8238 +       else
8239 +               inode->i_vflags &= ~V_BARRIER;
8240 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8241 +               inode->i_vflags |= V_COW;
8242 +       else
8243 +               inode->i_vflags &= ~V_COW;
8244  }
8245  
8246  /*
8247 @@ -777,6 +800,7 @@ xfs_setup_inode(
8248         inode->i_nlink  = ip->i_d.di_nlink;
8249         inode->i_uid    = ip->i_d.di_uid;
8250         inode->i_gid    = ip->i_d.di_gid;
8251 +       inode->i_tag    = ip->i_d.di_tag;
8252  
8253         switch (inode->i_mode & S_IFMT) {
8254         case S_IFBLK:
8255 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_linux.h
8256 --- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_linux.h        2008-10-13 14:52:06.000000000 +0200
8257 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_linux.h   2008-10-13 15:35:26.000000000 +0200
8258 @@ -126,6 +126,7 @@
8259  
8260  #define current_cpu()          (raw_smp_processor_id())
8261  #define current_pid()          (current->pid)
8262 +#define current_fstag(cred,vp) (dx_current_fstag(vp->i_sb))
8263  #define current_test_flags(f)  (current->flags & (f))
8264  #define current_set_flags_nested(sp, f)                \
8265                 (*(sp) = current->flags, current->flags |= (f))
8266 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/linux-2.6/xfs_super.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_super.c
8267 --- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_super.c        2008-12-19 12:03:13.000000000 +0100
8268 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/linux-2.6/xfs_super.c   2008-11-12 18:41:59.000000000 +0100
8269 @@ -147,6 +147,9 @@ xfs_args_allocate(
8270  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8271  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8272  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8273 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8274 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8275 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8276  
8277  /*
8278   * Table driven mount option parser.
8279 @@ -155,10 +158,14 @@ xfs_args_allocate(
8280   * in the future, too.
8281   */
8282  enum {
8283 +       Opt_tag, Opt_notag,
8284         Opt_barrier, Opt_nobarrier, Opt_err
8285  };
8286  
8287  static match_table_t tokens = {
8288 +       {Opt_tag, "tagxid"},
8289 +       {Opt_tag, "tag"},
8290 +       {Opt_notag, "notag"},
8291         {Opt_barrier, "barrier"},
8292         {Opt_nobarrier, "nobarrier"},
8293         {Opt_err, NULL}
8294 @@ -383,6 +390,19 @@ xfs_parseargs(
8295                 } else if (!strcmp(this_char, "irixsgid")) {
8296                         cmn_err(CE_WARN,
8297         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8298 +#ifndef CONFIG_TAGGING_NONE
8299 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8300 +                       args->flags2 |= XFSMNT2_TAGGED;
8301 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8302 +                       args->flags2 &= ~XFSMNT2_TAGGED;
8303 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8304 +                       args->flags2 |= XFSMNT2_TAGGED;
8305 +#endif
8306 +#ifdef CONFIG_PROPAGATE
8307 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8308 +                       /* use value */
8309 +                       args->flags2 |= XFSMNT2_TAGGED;
8310 +#endif
8311                 } else {
8312                         cmn_err(CE_WARN,
8313                                 "XFS: unknown mount option [%s].", this_char);
8314 @@ -1301,6 +1321,16 @@ xfs_fs_remount(
8315                 case Opt_nobarrier:
8316                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8317                         break;
8318 +               case Opt_tag:
8319 +                       if (!(sb->s_flags & MS_TAGGED)) {
8320 +                               printk(KERN_INFO
8321 +                                       "XFS: %s: tagging not permitted on remount.\n",
8322 +                                       sb->s_id);
8323 +                               return -EINVAL;
8324 +                       }
8325 +                       break;
8326 +               case Opt_notag:
8327 +                       break;
8328                 default:
8329                         /*
8330                          * Logically we would return an error here to prevent
8331 @@ -1555,6 +1585,9 @@ xfs_start_flags(
8332  
8333         if (ap->flags & XFSMNT_DMAPI)
8334                 mp->m_flags |= XFS_MOUNT_DMAPI;
8335 +
8336 +       if (ap->flags2 & XFSMNT2_TAGGED)
8337 +               mp->m_flags |= XFS_MOUNT_TAGGED;
8338         return 0;
8339  
8340  
8341 @@ -1749,6 +1782,9 @@ xfs_fs_fill_super(
8342  
8343         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
8344  
8345 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8346 +               sb->s_flags |= MS_TAGGED;
8347 +
8348         sb->s_dirt = 1;
8349         sb->s_magic = XFS_SB_MAGIC;
8350         sb->s_blocksize = mp->m_sb.sb_blocksize;
8351 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/quota/xfs_qm_syscalls.c
8352 --- linux-2.6.27.10/fs/xfs/quota/xfs_qm_syscalls.c      2008-10-13 14:52:06.000000000 +0200
8353 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/quota/xfs_qm_syscalls.c 2008-10-24 03:47:08.000000000 +0200
8354 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8355         uint            accflags;
8356         __int64_t       sbflags;
8357  
8358 -       if (!capable(CAP_SYS_ADMIN))
8359 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8360                 return XFS_ERROR(EPERM);
8361  
8362         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8363 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_clnt.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_clnt.h
8364 --- linux-2.6.27.10/fs/xfs/xfs_clnt.h   2008-10-13 14:52:06.000000000 +0200
8365 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_clnt.h      2008-10-13 14:54:20.000000000 +0200
8366 @@ -101,5 +101,6 @@ struct xfs_mount_args {
8367                                                  * I/O size in stat(2) */
8368  #define XFSMNT2_FILESTREAMS    0x00000002      /* enable the filestreams
8369                                                  * allocator */
8370 +#define XFSMNT2_TAGGED         0x10000000      /* context tagging */
8371  
8372  #endif /* __XFS_CLNT_H__ */
8373 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_dinode.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_dinode.h
8374 --- linux-2.6.27.10/fs/xfs/xfs_dinode.h 2008-07-13 23:51:29.000000000 +0200
8375 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_dinode.h    2008-11-12 18:41:59.000000000 +0100
8376 @@ -53,7 +53,9 @@ typedef struct xfs_dinode_core {
8377         __be32          di_gid;         /* owner's group id */
8378         __be32          di_nlink;       /* number of links to file */
8379         __be16          di_projid;      /* owner's project id */
8380 -       __u8            di_pad[8];      /* unused, zeroed space */
8381 +       __be16          di_tag;         /* context tagging */
8382 +       __be16          di_vflags;      /* vserver specific flags */
8383 +       __u8            di_pad[4];      /* unused, zeroed space */
8384         __be16          di_flushiter;   /* incremented on flush */
8385         xfs_timestamp_t di_atime;       /* time last accessed */
8386         xfs_timestamp_t di_mtime;       /* time last modified */
8387 @@ -136,7 +138,9 @@ typedef struct xfs_dinode
8388  #define        XFS_DI_NEXT_UNLINKED    0x1000000
8389  #define        XFS_DI_U                0x2000000
8390  #define        XFS_DI_A                0x4000000
8391 -#define        XFS_DI_NUM_BITS         27
8392 +#define        XFS_DI_TAG              0x8000000
8393 +#define        XFS_DI_VFLAGS           0x10000000
8394 +#define        XFS_DI_NUM_BITS         29
8395  #define        XFS_DI_ALL_BITS         ((1 << XFS_DI_NUM_BITS) - 1)
8396  #define        XFS_DI_CORE_BITS        (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
8397  
8398 @@ -223,6 +227,8 @@ typedef enum xfs_dinode_fmt
8399  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8400  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8401  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8402 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8403 +
8404  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8405  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8406  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8407 @@ -238,6 +244,7 @@ typedef enum xfs_dinode_fmt
8408  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8409  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8410  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8411 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8412  
8413  #ifdef CONFIG_XFS_RT
8414  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8415 @@ -250,6 +257,10 @@ typedef enum xfs_dinode_fmt
8416          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8417          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8418          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8419 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8420 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8421 +        XFS_DIFLAG_IXUNLINK)
8422 +
8423 +#define XFS_DIVFLAG_BARRIER    0x01
8424 +#define XFS_DIVFLAG_COW                0x02
8425  
8426  #endif /* __XFS_DINODE_H__ */
8427 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_fs.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_fs.h
8428 --- linux-2.6.27.10/fs/xfs/xfs_fs.h     2008-10-13 14:52:06.000000000 +0200
8429 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_fs.h        2008-10-13 14:54:20.000000000 +0200
8430 @@ -67,6 +67,9 @@ struct fsxattr {
8431  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8432  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8433  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8434 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8435 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8436 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8437  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8438  
8439  /*
8440 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8441         __s32           bs_extents;     /* number of extents            */
8442         __u32           bs_gen;         /* generation count             */
8443         __u16           bs_projid;      /* project id                   */
8444 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8445 +       __u16           bs_tag;         /* context tagging              */
8446 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8447         __u32           bs_dmevmask;    /* DMIG event mask              */
8448         __u16           bs_dmstate;     /* DMIG state info              */
8449         __u16           bs_aextents;    /* attribute number of extents  */
8450 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_ialloc.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_ialloc.c
8451 --- linux-2.6.27.10/fs/xfs/xfs_ialloc.c 2008-07-13 23:51:29.000000000 +0200
8452 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_ialloc.c    2008-11-12 18:41:59.000000000 +0100
8453 @@ -84,6 +84,8 @@ xfs_ialloc_log_di(
8454                 offsetof(xfs_dinode_t, di_next_unlinked),
8455                 offsetof(xfs_dinode_t, di_u),
8456                 offsetof(xfs_dinode_t, di_a),
8457 +               offsetof(xfs_dinode_core_t, di_tag),
8458 +               offsetof(xfs_dinode_core_t, di_vflags),
8459                 sizeof(xfs_dinode_t)
8460         };
8461  
8462 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_inode.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_inode.c
8463 --- linux-2.6.27.10/fs/xfs/xfs_inode.c  2008-10-13 14:52:06.000000000 +0200
8464 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_inode.c     2008-11-12 18:42:00.000000000 +0100
8465 @@ -249,6 +249,7 @@ xfs_inotobp(
8466         return 0;
8467  }
8468  
8469 +#include <linux/vs_tag.h>
8470  
8471  /*
8472   * This routine is called to map an inode to the buffer containing
8473 @@ -660,15 +661,25 @@ xfs_iformat_btree(
8474  void
8475  xfs_dinode_from_disk(
8476         xfs_icdinode_t          *to,
8477 -       xfs_dinode_core_t       *from)
8478 +       xfs_dinode_core_t       *from,
8479 +       int tagged)
8480  {
8481 +       uint32_t uid, gid, tag;
8482 +
8483         to->di_magic = be16_to_cpu(from->di_magic);
8484         to->di_mode = be16_to_cpu(from->di_mode);
8485         to->di_version = from ->di_version;
8486         to->di_format = from->di_format;
8487         to->di_onlink = be16_to_cpu(from->di_onlink);
8488 -       to->di_uid = be32_to_cpu(from->di_uid);
8489 -       to->di_gid = be32_to_cpu(from->di_gid);
8490 +
8491 +       uid = be32_to_cpu(from->di_uid);
8492 +       gid = be32_to_cpu(from->di_gid);
8493 +       tag = be16_to_cpu(from->di_tag);
8494 +
8495 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8496 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8497 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8498 +
8499         to->di_nlink = be32_to_cpu(from->di_nlink);
8500         to->di_projid = be16_to_cpu(from->di_projid);
8501         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8502 @@ -689,21 +700,26 @@ xfs_dinode_from_disk(
8503         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8504         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8505         to->di_flags    = be16_to_cpu(from->di_flags);
8506 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8507         to->di_gen      = be32_to_cpu(from->di_gen);
8508  }
8509  
8510  void
8511  xfs_dinode_to_disk(
8512         xfs_dinode_core_t       *to,
8513 -       xfs_icdinode_t          *from)
8514 +       xfs_icdinode_t          *from,
8515 +       int tagged)
8516  {
8517         to->di_magic = cpu_to_be16(from->di_magic);
8518         to->di_mode = cpu_to_be16(from->di_mode);
8519         to->di_version = from ->di_version;
8520         to->di_format = from->di_format;
8521         to->di_onlink = cpu_to_be16(from->di_onlink);
8522 -       to->di_uid = cpu_to_be32(from->di_uid);
8523 -       to->di_gid = cpu_to_be32(from->di_gid);
8524 +
8525 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8526 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8527 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8528 +
8529         to->di_nlink = cpu_to_be32(from->di_nlink);
8530         to->di_projid = cpu_to_be16(from->di_projid);
8531         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8532 @@ -724,12 +740,14 @@ xfs_dinode_to_disk(
8533         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8534         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8535         to->di_flags = cpu_to_be16(from->di_flags);
8536 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8537         to->di_gen = cpu_to_be32(from->di_gen);
8538  }
8539  
8540  STATIC uint
8541  _xfs_dic2xflags(
8542 -       __uint16_t              di_flags)
8543 +       __uint16_t              di_flags,
8544 +       __uint16_t              di_vflags)
8545  {
8546         uint                    flags = 0;
8547  
8548 @@ -740,6 +758,8 @@ _xfs_dic2xflags(
8549                         flags |= XFS_XFLAG_PREALLOC;
8550                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8551                         flags |= XFS_XFLAG_IMMUTABLE;
8552 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8553 +                       flags |= XFS_XFLAG_IXUNLINK;
8554                 if (di_flags & XFS_DIFLAG_APPEND)
8555                         flags |= XFS_XFLAG_APPEND;
8556                 if (di_flags & XFS_DIFLAG_SYNC)
8557 @@ -764,6 +784,10 @@ _xfs_dic2xflags(
8558                         flags |= XFS_XFLAG_FILESTREAM;
8559         }
8560  
8561 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8562 +               flags |= FS_BARRIER_FL;
8563 +       if (di_vflags & XFS_DIVFLAG_COW)
8564 +               flags |= FS_COW_FL;
8565         return flags;
8566  }
8567  
8568 @@ -773,7 +797,7 @@ xfs_ip2xflags(
8569  {
8570         xfs_icdinode_t          *dic = &ip->i_d;
8571  
8572 -       return _xfs_dic2xflags(dic->di_flags) |
8573 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8574                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8575  }
8576  
8577 @@ -783,7 +807,8 @@ xfs_dic2xflags(
8578  {
8579         xfs_dinode_core_t       *dic = &dip->di_core;
8580  
8581 -       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
8582 +       return _xfs_dic2xflags(be16_to_cpu(dic->di_flags),
8583 +                               be16_to_cpu(dic->di_vflags)) |
8584                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8585  }
8586  
8587 @@ -878,7 +903,8 @@ xfs_iread(
8588          * Otherwise, just get the truly permanent information.
8589          */
8590         if (dip->di_core.di_mode) {
8591 -               xfs_dinode_from_disk(&ip->i_d, &dip->di_core);
8592 +               xfs_dinode_from_disk(&ip->i_d, &dip->di_core,
8593 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8594                 error = xfs_iformat(ip, dip);
8595                 if (error)  {
8596                         kmem_zone_free(xfs_inode_zone, ip);
8597 @@ -1083,6 +1109,7 @@ xfs_ialloc(
8598         ASSERT(ip->i_d.di_nlink == nlink);
8599         ip->i_d.di_uid = current_fsuid();
8600         ip->i_d.di_gid = current_fsgid();
8601 +       ip->i_d.di_tag = current_fstag(cr, ip->i_vnode);
8602         ip->i_d.di_projid = prid;
8603         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8604  
8605 @@ -1143,6 +1170,7 @@ xfs_ialloc(
8606         ip->i_d.di_dmevmask = 0;
8607         ip->i_d.di_dmstate = 0;
8608         ip->i_d.di_flags = 0;
8609 +       ip->i_d.di_vflags = 0;
8610         flags = XFS_ILOG_CORE;
8611         switch (mode & S_IFMT) {
8612         case S_IFIFO:
8613 @@ -2249,6 +2277,7 @@ xfs_ifree(
8614         }
8615         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8616         ip->i_d.di_flags = 0;
8617 +       ip->i_d.di_vflags = 0;
8618         ip->i_d.di_dmevmask = 0;
8619         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8620         ip->i_df.if_ext_max =
8621 @@ -3342,7 +3371,8 @@ xfs_iflush_int(
8622          * because if the inode is dirty at all the core must
8623          * be.
8624          */
8625 -       xfs_dinode_to_disk(&dip->di_core, &ip->i_d);
8626 +       xfs_dinode_to_disk(&dip->di_core, &ip->i_d,
8627 +               mp->m_flags & XFS_MOUNT_TAGGED);
8628  
8629         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8630         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8631 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_inode.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_inode.h
8632 --- linux-2.6.27.10/fs/xfs/xfs_inode.h  2008-10-13 14:52:06.000000000 +0200
8633 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_inode.h     2008-11-12 18:42:03.000000000 +0100
8634 @@ -173,7 +173,9 @@ typedef struct xfs_icdinode {
8635         __uint32_t      di_gid;         /* owner's group id */
8636         __uint32_t      di_nlink;       /* number of links to file */
8637         __uint16_t      di_projid;      /* owner's project id */
8638 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8639 +       __uint16_t      di_tag;         /* context tagging */
8640 +       __uint16_t      di_vflags;      /* vserver specific flags */
8641 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8642         __uint16_t      di_flushiter;   /* incremented on flush */
8643         xfs_ictimestamp_t di_atime;     /* time last accessed */
8644         xfs_ictimestamp_t di_mtime;     /* time last modified */
8645 @@ -500,9 +502,9 @@ int         xfs_ialloc(struct xfs_trans *, xfs_
8646                            xfs_nlink_t, xfs_dev_t, struct cred *, xfs_prid_t,
8647                            int, struct xfs_buf **, boolean_t *, xfs_inode_t **);
8648  void           xfs_dinode_from_disk(struct xfs_icdinode *,
8649 -                                    struct xfs_dinode_core *);
8650 +                                    struct xfs_dinode_core *, int tagged);
8651  void           xfs_dinode_to_disk(struct xfs_dinode_core *,
8652 -                                  struct xfs_icdinode *);
8653 +                                  struct xfs_icdinode *, int tagged);
8654  
8655  uint           xfs_ip2xflags(struct xfs_inode *);
8656  uint           xfs_dic2xflags(struct xfs_dinode *);
8657 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_itable.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_itable.c
8658 --- linux-2.6.27.10/fs/xfs/xfs_itable.c 2008-10-13 14:52:06.000000000 +0200
8659 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_itable.c    2008-11-12 18:42:03.000000000 +0100
8660 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
8661         buf->bs_mode = dic->di_mode;
8662         buf->bs_uid = dic->di_uid;
8663         buf->bs_gid = dic->di_gid;
8664 +       buf->bs_tag = dic->di_tag;
8665         buf->bs_size = dic->di_size;
8666         vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
8667         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
8668 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_log_recover.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_log_recover.c
8669 --- linux-2.6.27.10/fs/xfs/xfs_log_recover.c    2008-10-13 14:52:06.000000000 +0200
8670 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_log_recover.c       2008-11-12 18:42:03.000000000 +0100
8671 @@ -2417,7 +2417,8 @@ xlog_recover_do_inode_trans(
8672  
8673         /* The core is in in-core format */
8674         xfs_dinode_to_disk(&dip->di_core,
8675 -               (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8676 +               (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8677 +               mp->m_flags & XFS_MOUNT_TAGGED);
8678  
8679         /* the rest is in on-disk format */
8680         if (item->ri_buf[1].i_len > sizeof(xfs_dinode_core_t)) {
8681 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_mount.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_mount.h
8682 --- linux-2.6.27.10/fs/xfs/xfs_mount.h  2008-10-13 14:52:06.000000000 +0200
8683 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_mount.h     2008-10-13 14:54:20.000000000 +0200
8684 @@ -384,6 +384,7 @@ typedef struct xfs_mount {
8685                                                    allocator */
8686  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8687  
8688 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8689  
8690  /*
8691   * Default minimum read and write sizes.
8692 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_vnodeops.c linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_vnodeops.c
8693 --- linux-2.6.27.10/fs/xfs/xfs_vnodeops.c       2008-10-13 14:52:06.000000000 +0200
8694 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_vnodeops.c  2008-11-12 18:42:03.000000000 +0100
8695 @@ -75,6 +75,89 @@ xfs_open(
8696         return 0;
8697  }
8698  
8699 +STATIC void
8700 +xfs_get_inode_flags(
8701 +       xfs_inode_t     *ip)
8702 +{
8703 +       struct inode    *inode = VFS_I(ip);
8704 +       unsigned int    flags = inode->i_flags;
8705 +       unsigned int    vflags = inode->i_vflags;
8706 +
8707 +       if (flags & S_IMMUTABLE)
8708 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8709 +       else
8710 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8711 +       if (flags & S_IXUNLINK)
8712 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8713 +       else
8714 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8715 +
8716 +       if (vflags & V_BARRIER)
8717 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8718 +       else
8719 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8720 +       if (vflags & V_COW)
8721 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8722 +       else
8723 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8724 +}
8725 +
8726 +int
8727 +xfs_sync_xflags(
8728 +       xfs_inode_t             *ip)
8729 +{
8730 +       struct xfs_mount        *mp = ip->i_mount;
8731 +       struct xfs_trans        *tp;
8732 +       unsigned int            lock_flags = 0;
8733 +       int                     code;
8734 +
8735 +       xfs_itrace_entry(ip);
8736 +
8737 +       if (mp->m_flags & XFS_MOUNT_RDONLY)
8738 +               return XFS_ERROR(EROFS);
8739 +
8740 +       /*
8741 +        * we acquire the inode lock and do an error checking pass.
8742 +        */
8743 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8744 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8745 +       if (code)
8746 +               goto error_return;
8747 +
8748 +       lock_flags = XFS_ILOCK_EXCL;
8749 +       xfs_ilock(ip, lock_flags);
8750 +
8751 +       xfs_trans_ijoin(tp, ip, lock_flags);
8752 +       xfs_trans_ihold(tp, ip);
8753 +
8754 +       xfs_get_inode_flags(ip);
8755 +       // xfs_diflags_to_linux(ip);
8756 +
8757 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8758 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8759 +
8760 +       XFS_STATS_INC(xs_ig_attrchg);
8761 +
8762 +       /*
8763 +        * If this is a synchronous mount, make sure that the
8764 +        * transaction goes to disk before returning to the user.
8765 +        */
8766 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8767 +               xfs_trans_set_sync(tp);
8768 +       code = xfs_trans_commit(tp, 0);
8769 +       xfs_iunlock(ip, lock_flags);
8770 +
8771 +       if (code)
8772 +               return code;
8773 +       return 0;
8774 +
8775 + error_return:
8776 +       xfs_trans_cancel(tp, 0);
8777 +       if (lock_flags)
8778 +               xfs_iunlock(ip, lock_flags);
8779 +       return code;
8780 +}
8781 +
8782  int
8783  xfs_setattr(
8784         struct xfs_inode        *ip,
8785 @@ -91,6 +174,7 @@ xfs_setattr(
8786         uint                    commit_flags=0;
8787         uid_t                   uid=0, iuid=0;
8788         gid_t                   gid=0, igid=0;
8789 +       tag_t                   tag=0, itag=0;
8790         int                     timeflags = 0;
8791         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8792         int                     file_owner;
8793 @@ -238,7 +322,7 @@ xfs_setattr(
8794          * and can change the group id only to a group of which he
8795          * or she is a member.
8796          */
8797 -       if (mask & (ATTR_UID|ATTR_GID)) {
8798 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8799                 /*
8800                  * These IDs could have changed since we last looked at them.
8801                  * But, we're assured that if the ownership did change
8802 @@ -247,8 +331,10 @@ xfs_setattr(
8803                  */
8804                 iuid = ip->i_d.di_uid;
8805                 igid = ip->i_d.di_gid;
8806 +               itag = ip->i_d.di_tag;
8807                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8808                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8809 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8810  
8811                 /*
8812                  * CAP_CHOWN overrides the following restrictions:
8813 @@ -272,7 +358,9 @@ xfs_setattr(
8814                  * going to change.
8815                  */
8816                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8817 -                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
8818 +                   (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8819 +                   (XFS_IS_GQUOTA_ON(mp) && itag != tag)) {
8820 +                       /* TODO: handle tagging? */
8821                         ASSERT(tp);
8822                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
8823                                                 capable(CAP_FOWNER) ?
8824 @@ -461,7 +549,7 @@ xfs_setattr(
8825          * and can change the group id only to a group of which he
8826          * or she is a member.
8827          */
8828 -       if (mask & (ATTR_UID|ATTR_GID)) {
8829 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8830                 /*
8831                  * CAP_FSETID overrides the following restrictions:
8832                  *
8833 @@ -477,6 +565,10 @@ xfs_setattr(
8834                  * Change the ownerships and register quota modifications
8835                  * in the transaction.
8836                  */
8837 +               if (itag != tag) {
8838 +                       ip->i_d.di_tag = tag;
8839 +                       inode->i_tag = tag;
8840 +               }
8841                 if (iuid != uid) {
8842                         if (XFS_IS_UQUOTA_ON(mp)) {
8843                                 ASSERT(mask & ATTR_UID);
8844 diff -NurpP --minimal linux-2.6.27.10/fs/xfs/xfs_vnodeops.h linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_vnodeops.h
8845 --- linux-2.6.27.10/fs/xfs/xfs_vnodeops.h       2008-10-13 14:52:06.000000000 +0200
8846 +++ linux-2.6.27.10-vs2.3.0.36.4/fs/xfs/xfs_vnodeops.h  2008-11-12 18:42:03.000000000 +0100
8847 @@ -15,6 +15,7 @@ struct xfs_iomap;
8848  
8849  
8850  int xfs_open(struct xfs_inode *ip);
8851 +int xfs_sync_xflags(struct xfs_inode *ip);
8852  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags,
8853                 struct cred *credp);
8854  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8855 diff -NurpP --minimal linux-2.6.27.10/include/asm-generic/tlb.h linux-2.6.27.10-vs2.3.0.36.4/include/asm-generic/tlb.h
8856 --- linux-2.6.27.10/include/asm-generic/tlb.h   2008-07-13 23:51:29.000000000 +0200
8857 +++ linux-2.6.27.10-vs2.3.0.36.4/include/asm-generic/tlb.h      2008-10-13 14:54:20.000000000 +0200
8858 @@ -14,6 +14,7 @@
8859  #define _ASM_GENERIC__TLB_H
8860  
8861  #include <linux/swap.h>
8862 +#include <linux/vs_memory.h>
8863  #include <asm/pgalloc.h>
8864  #include <asm/tlbflush.h>
8865  
8866 diff -NurpP --minimal linux-2.6.27.10/include/asm-x86/unistd_64.h linux-2.6.27.10-vs2.3.0.36.4/include/asm-x86/unistd_64.h
8867 --- linux-2.6.27.10/include/asm-x86/unistd_64.h 2008-10-13 14:52:08.000000000 +0200
8868 +++ linux-2.6.27.10-vs2.3.0.36.4/include/asm-x86/unistd_64.h    2008-10-13 14:54:20.000000000 +0200
8869 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
8870  #define __NR_utimes                            235
8871  __SYSCALL(__NR_utimes, sys_utimes)
8872  #define __NR_vserver                           236
8873 -__SYSCALL(__NR_vserver, sys_ni_syscall)
8874 +__SYSCALL(__NR_vserver, sys_vserver)
8875  #define __NR_mbind                             237
8876  __SYSCALL(__NR_mbind, sys_mbind)
8877  #define __NR_set_mempolicy                     238
8878 diff -NurpP --minimal linux-2.6.27.10/include/linux/capability.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/capability.h
8879 --- linux-2.6.27.10/include/linux/capability.h  2008-10-13 14:52:09.000000000 +0200
8880 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/capability.h     2008-10-13 14:54:20.000000000 +0200
8881 @@ -274,6 +274,7 @@ typedef struct kernel_cap_struct {
8882     arbitrary SCSI commands */
8883  /* Allow setting encryption key on loopback filesystem */
8884  /* Allow setting zone reclaim policy */
8885 +/* Allow the selection of a security context */
8886  
8887  #define CAP_SYS_ADMIN        21
8888  
8889 @@ -346,7 +347,13 @@ typedef struct kernel_cap_struct {
8890  
8891  #define CAP_MAC_ADMIN        33
8892  
8893 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8894 +/* Allow context manipulations */
8895 +/* Allow changing context info on files */
8896 +
8897 +#define CAP_CONTEXT         34
8898 +
8899 +
8900 +#define CAP_LAST_CAP         CAP_CONTEXT
8901  
8902  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8903  
8904 diff -NurpP --minimal linux-2.6.27.10/include/linux/devpts_fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/devpts_fs.h
8905 --- linux-2.6.27.10/include/linux/devpts_fs.h   2008-07-13 23:51:29.000000000 +0200
8906 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/devpts_fs.h      2008-10-13 14:54:20.000000000 +0200
8907 @@ -34,5 +34,4 @@ static inline void devpts_pty_kill(int n
8908  
8909  #endif
8910  
8911 -
8912  #endif /* _LINUX_DEVPTS_FS_H */
8913 diff -NurpP --minimal linux-2.6.27.10/include/linux/ext2_fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/ext2_fs.h
8914 --- linux-2.6.27.10/include/linux/ext2_fs.h     2008-10-13 14:52:09.000000000 +0200
8915 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/ext2_fs.h        2008-10-13 14:54:20.000000000 +0200
8916 @@ -189,8 +189,12 @@ struct ext2_group_desc
8917  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8918  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8919  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8920 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8921  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8922  
8923 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8924 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8925 +
8926  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8927  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8928  
8929 @@ -247,7 +251,7 @@ struct ext2_inode {
8930                 struct {
8931                         __u8    l_i_frag;       /* Fragment number */
8932                         __u8    l_i_fsize;      /* Fragment size */
8933 -                       __u16   i_pad1;
8934 +                       __u16   l_i_tag;        /* Context Tag */
8935                         __le16  l_i_uid_high;   /* these 2 fields    */
8936                         __le16  l_i_gid_high;   /* were reserved2[0] */
8937                         __u32   l_i_reserved2;
8938 @@ -279,6 +283,7 @@ struct ext2_inode {
8939  #define i_gid_low      i_gid
8940  #define i_uid_high     osd2.linux2.l_i_uid_high
8941  #define i_gid_high     osd2.linux2.l_i_gid_high
8942 +#define i_raw_tag      osd2.linux2.l_i_tag
8943  #define i_reserved2    osd2.linux2.l_i_reserved2
8944  #endif
8945  
8946 @@ -323,6 +328,7 @@ struct ext2_inode {
8947  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8948  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8949  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8950 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8951  
8952  
8953  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8954 diff -NurpP --minimal linux-2.6.27.10/include/linux/ext3_fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/ext3_fs.h
8955 --- linux-2.6.27.10/include/linux/ext3_fs.h     2008-10-13 14:52:09.000000000 +0200
8956 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/ext3_fs.h        2008-10-31 18:15:18.000000000 +0100
8957 @@ -173,10 +173,14 @@ struct ext3_group_desc
8958  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8959  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8960  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8961 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8962  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8963  
8964 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8965 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8966 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8967 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8968 +
8969 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8970 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8971  
8972  /*
8973   * Inode dynamic state flags
8974 @@ -292,7 +296,7 @@ struct ext3_inode {
8975                 struct {
8976                         __u8    l_i_frag;       /* Fragment number */
8977                         __u8    l_i_fsize;      /* Fragment size */
8978 -                       __u16   i_pad1;
8979 +                       __u16   l_i_tag;        /* Context Tag */
8980                         __le16  l_i_uid_high;   /* these 2 fields    */
8981                         __le16  l_i_gid_high;   /* were reserved2[0] */
8982                         __u32   l_i_reserved2;
8983 @@ -326,6 +330,7 @@ struct ext3_inode {
8984  #define i_gid_low      i_gid
8985  #define i_uid_high     osd2.linux2.l_i_uid_high
8986  #define i_gid_high     osd2.linux2.l_i_gid_high
8987 +#define i_raw_tag      osd2.linux2.l_i_tag
8988  #define i_reserved2    osd2.linux2.l_i_reserved2
8989  
8990  #elif defined(__GNU__)
8991 @@ -380,6 +385,7 @@ struct ext3_inode {
8992  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
8993  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
8994  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8995 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8996  
8997  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8998  #ifndef _LINUX_EXT2_FS_H
8999 @@ -822,6 +828,7 @@ struct buffer_head * ext3_bread (handle_
9000  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
9001         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
9002         int create, int extend_disksize);
9003 +extern int ext3_sync_flags(struct inode *inode);
9004  
9005  extern struct inode *ext3_iget(struct super_block *, unsigned long);
9006  extern int  ext3_write_inode (struct inode *, int);
9007 diff -NurpP --minimal linux-2.6.27.10/include/linux/fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/fs.h
9008 --- linux-2.6.27.10/include/linux/fs.h  2008-10-13 14:52:09.000000000 +0200
9009 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/fs.h     2008-10-31 18:18:18.000000000 +0100
9010 @@ -128,6 +128,9 @@ extern int dir_notify_enable;
9011  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
9012  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
9013  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
9014 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
9015 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
9016 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
9017  #define MS_ACTIVE      (1<<30)
9018  #define MS_NOUSER      (1<<31)
9019  
9020 @@ -154,6 +157,14 @@ extern int dir_notify_enable;
9021  #define S_NOCMTIME     128     /* Do not update file c/mtime */
9022  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
9023  #define S_PRIVATE      512     /* Inode is fs-internal */
9024 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
9025 +
9026 +/* Linux-VServer related Inode flags */
9027 +
9028 +#define V_VALID                1
9029 +#define V_XATTR                2
9030 +#define V_BARRIER      4       /* Barrier for chroot() */
9031 +#define V_COW          8       /* Copy on Write */
9032  
9033  /*
9034   * Note that nosuid etc flags are inode-specific: setting some file-system
9035 @@ -176,12 +187,15 @@ extern int dir_notify_enable;
9036  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
9037                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
9038  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
9039 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9040 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
9041 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
9042 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
9043 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
9044  
9045  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
9046  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
9047  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
9048 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
9049 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
9050  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
9051  
9052  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
9053 @@ -189,6 +203,16 @@ extern int dir_notify_enable;
9054  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
9055  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
9056  
9057 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
9058 +
9059 +#ifdef CONFIG_VSERVER_COWBL
9060 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
9061 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
9062 +#else
9063 +#  define IS_COW(inode)                (0)
9064 +#  define IS_COW_LINK(inode)   (0)
9065 +#endif
9066 +
9067  /* the read-only stuff doesn't really belong here, but any other place is
9068     probably as bad and I don't want to create yet another include file. */
9069  
9070 @@ -262,11 +286,14 @@ extern int dir_notify_enable;
9071  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
9072  #define FS_EXTENT_FL                   0x00080000 /* Extents */
9073  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
9074 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
9075  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
9076  
9077 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
9078 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
9079 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
9080 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
9081  
9082 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
9083 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
9084  
9085  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
9086  #define SYNC_FILE_RANGE_WRITE          2
9087 @@ -337,6 +364,7 @@ typedef void (dio_iodone_t)(struct kiocb
9088  #define ATTR_KILL_PRIV (1 << 14)
9089  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
9090  #define ATTR_TIMES_SET (1 << 16)
9091 +#define ATTR_TAG       (1 << 17)
9092  
9093  /*
9094   * This is the Inode Attributes structure, used for notify_change().  It
9095 @@ -352,6 +380,7 @@ struct iattr {
9096         umode_t         ia_mode;
9097         uid_t           ia_uid;
9098         gid_t           ia_gid;
9099 +       tag_t           ia_tag;
9100         loff_t          ia_size;
9101         struct timespec ia_atime;
9102         struct timespec ia_mtime;
9103 @@ -365,6 +394,9 @@ struct iattr {
9104         struct file     *ia_file;
9105  };
9106  
9107 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
9108 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
9109 +
9110  /*
9111   * Includes for diskquotas.
9112   */
9113 @@ -626,7 +658,9 @@ struct inode {
9114         unsigned int            i_nlink;
9115         uid_t                   i_uid;
9116         gid_t                   i_gid;
9117 +       tag_t                   i_tag;
9118         dev_t                   i_rdev;
9119 +       dev_t                   i_mdev;
9120         u64                     i_version;
9121         loff_t                  i_size;
9122  #ifdef __NEED_I_SIZE_ORDERED
9123 @@ -674,7 +708,8 @@ struct inode {
9124         unsigned long           i_state;
9125         unsigned long           dirtied_when;   /* jiffies of first dirtying */
9126  
9127 -       unsigned int            i_flags;
9128 +       unsigned short          i_flags;
9129 +       unsigned short          i_vflags;
9130  
9131         atomic_t                i_writecount;
9132  #ifdef CONFIG_SECURITY
9133 @@ -761,12 +796,12 @@ static inline void i_size_write(struct i
9134  
9135  static inline unsigned iminor(const struct inode *inode)
9136  {
9137 -       return MINOR(inode->i_rdev);
9138 +       return MINOR(inode->i_mdev);
9139  }
9140  
9141  static inline unsigned imajor(const struct inode *inode)
9142  {
9143 -       return MAJOR(inode->i_rdev);
9144 +       return MAJOR(inode->i_mdev);
9145  }
9146  
9147  extern struct block_device *I_BDEV(struct inode *inode);
9148 @@ -824,6 +859,7 @@ struct file {
9149         loff_t                  f_pos;
9150         struct fown_struct      f_owner;
9151         unsigned int            f_uid, f_gid;
9152 +       xid_t                   f_xid;
9153         struct file_ra_state    f_ra;
9154  
9155         u64                     f_version;
9156 @@ -958,6 +994,7 @@ struct file_lock {
9157         struct file *fl_file;
9158         loff_t fl_start;
9159         loff_t fl_end;
9160 +       xid_t fl_xid;
9161  
9162         struct fasync_struct *  fl_fasync; /* for lease break notifications */
9163         unsigned long fl_break_time;    /* for nonblocking lease breaks */
9164 @@ -1287,6 +1324,7 @@ struct inode_operations {
9165         void (*truncate_range)(struct inode *, loff_t, loff_t);
9166         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
9167                           loff_t len);
9168 +       int (*sync_flags) (struct inode *);
9169  };
9170  
9171  struct seq_file;
9172 @@ -1302,6 +1340,7 @@ extern ssize_t vfs_readv(struct file *, 
9173                 unsigned long, loff_t *);
9174  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
9175                 unsigned long, loff_t *);
9176 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
9177  
9178  struct super_operations {
9179         struct inode *(*alloc_inode)(struct super_block *sb);
9180 @@ -1992,6 +2031,7 @@ extern int dcache_dir_open(struct inode 
9181  extern int dcache_dir_close(struct inode *, struct file *);
9182  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
9183  extern int dcache_readdir(struct file *, void *, filldir_t);
9184 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
9185  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
9186  extern int simple_statfs(struct dentry *, struct kstatfs *);
9187  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
9188 diff -NurpP --minimal linux-2.6.27.10/include/linux/if_tun.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/if_tun.h
9189 --- linux-2.6.27.10/include/linux/if_tun.h      2008-10-13 14:52:09.000000000 +0200
9190 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/if_tun.h 2008-10-13 14:54:20.000000000 +0200
9191 @@ -46,6 +46,7 @@
9192  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
9193  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
9194  #define TUNGETIFF      _IOR('T', 210, unsigned int)
9195 +#define TUNSETNID     _IOW('T', 215, int)
9196  
9197  /* TUNSETIFF ifr flags */
9198  #define IFF_TUN                0x0001
9199 diff -NurpP --minimal linux-2.6.27.10/include/linux/init_task.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/init_task.h
9200 --- linux-2.6.27.10/include/linux/init_task.h   2008-10-13 14:52:09.000000000 +0200
9201 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/init_task.h      2008-10-13 14:54:20.000000000 +0200
9202 @@ -179,6 +179,10 @@ extern struct group_info init_groups;
9203         INIT_IDS                                                        \
9204         INIT_TRACE_IRQFLAGS                                             \
9205         INIT_LOCKDEP                                                    \
9206 +       .xid            = 0,                                            \
9207 +       .vx_info        = NULL,                                         \
9208 +       .nid            = 0,                                            \
9209 +       .nx_info        = NULL,                                         \
9210  }
9211  
9212  
9213 diff -NurpP --minimal linux-2.6.27.10/include/linux/interrupt.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/interrupt.h
9214 --- linux-2.6.27.10/include/linux/interrupt.h   2008-10-13 14:52:09.000000000 +0200
9215 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/interrupt.h      2008-10-13 14:54:20.000000000 +0200
9216 @@ -8,8 +8,8 @@
9217  #include <linux/preempt.h>
9218  #include <linux/cpumask.h>
9219  #include <linux/irqreturn.h>
9220 -#include <linux/hardirq.h>
9221  #include <linux/sched.h>
9222 +#include <linux/hardirq.h>
9223  #include <linux/irqflags.h>
9224  #include <asm/atomic.h>
9225  #include <asm/ptrace.h>
9226 diff -NurpP --minimal linux-2.6.27.10/include/linux/ipc.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/ipc.h
9227 --- linux-2.6.27.10/include/linux/ipc.h 2008-07-13 23:51:29.000000000 +0200
9228 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/ipc.h    2008-10-13 14:54:20.000000000 +0200
9229 @@ -93,6 +93,7 @@ struct kern_ipc_perm
9230         key_t           key;
9231         uid_t           uid;
9232         gid_t           gid;
9233 +       xid_t           xid;
9234         uid_t           cuid;
9235         gid_t           cgid;
9236         mode_t          mode; 
9237 diff -NurpP --minimal linux-2.6.27.10/include/linux/Kbuild linux-2.6.27.10-vs2.3.0.36.4/include/linux/Kbuild
9238 --- linux-2.6.27.10/include/linux/Kbuild        2008-10-13 14:52:09.000000000 +0200
9239 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/Kbuild   2008-10-13 14:54:20.000000000 +0200
9240 @@ -369,3 +369,6 @@ unifdef-y += xattr.h
9241  unifdef-y += xfrm.h
9242  
9243  objhdr-y += version.h
9244 +
9245 +header-y += vserver/
9246 +
9247 diff -NurpP --minimal linux-2.6.27.10/include/linux/loop.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/loop.h
9248 --- linux-2.6.27.10/include/linux/loop.h        2008-07-13 23:51:29.000000000 +0200
9249 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/loop.h   2008-10-13 14:54:20.000000000 +0200
9250 @@ -45,6 +45,7 @@ struct loop_device {
9251         struct loop_func_table *lo_encryption;
9252         __u32           lo_init[2];
9253         uid_t           lo_key_owner;   /* Who set the key */
9254 +       xid_t           lo_xid;
9255         int             (*ioctl)(struct loop_device *, int cmd, 
9256                                  unsigned long arg); 
9257  
9258 diff -NurpP --minimal linux-2.6.27.10/include/linux/magic.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/magic.h
9259 --- linux-2.6.27.10/include/linux/magic.h       2008-07-13 23:51:29.000000000 +0200
9260 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/magic.h  2008-10-13 14:54:20.000000000 +0200
9261 @@ -3,7 +3,7 @@
9262  
9263  #define ADFS_SUPER_MAGIC       0xadf5
9264  #define AFFS_SUPER_MAGIC       0xadff
9265 -#define AFS_SUPER_MAGIC                0x5346414F
9266 +#define AFS_SUPER_MAGIC                0x5346414F
9267  #define AUTOFS_SUPER_MAGIC     0x0187
9268  #define CODA_SUPER_MAGIC       0x73757245
9269  #define EFS_SUPER_MAGIC                0x414A53
9270 @@ -26,6 +26,7 @@
9271  #define NFS_SUPER_MAGIC                0x6969
9272  #define OPENPROM_SUPER_MAGIC   0x9fa1
9273  #define PROC_SUPER_MAGIC       0x9fa0
9274 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9275  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9276  
9277  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9278 diff -NurpP --minimal linux-2.6.27.10/include/linux/major.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/major.h
9279 --- linux-2.6.27.10/include/linux/major.h       2008-10-13 14:52:09.000000000 +0200
9280 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/major.h  2008-10-13 14:54:20.000000000 +0200
9281 @@ -15,6 +15,7 @@
9282  #define HD_MAJOR               IDE0_MAJOR
9283  #define PTY_SLAVE_MAJOR                3
9284  #define TTY_MAJOR              4
9285 +#define VROOT_MAJOR            4
9286  #define TTYAUX_MAJOR           5
9287  #define LP_MAJOR               6
9288  #define VCS_MAJOR              7
9289 diff -NurpP --minimal linux-2.6.27.10/include/linux/mm_types.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/mm_types.h
9290 --- linux-2.6.27.10/include/linux/mm_types.h    2008-10-13 14:52:09.000000000 +0200
9291 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/mm_types.h       2008-10-13 14:54:20.000000000 +0200
9292 @@ -216,6 +216,7 @@ struct mm_struct {
9293  
9294         /* Architecture-specific MM context */
9295         mm_context_t context;
9296 +       struct vx_info *mm_vx_info;
9297  
9298         /* Swap token stuff */
9299         /*
9300 diff -NurpP --minimal linux-2.6.27.10/include/linux/mount.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/mount.h
9301 --- linux-2.6.27.10/include/linux/mount.h       2008-10-13 14:52:09.000000000 +0200
9302 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/mount.h  2008-10-24 03:34:52.000000000 +0200
9303 @@ -37,6 +37,9 @@ struct mnt_namespace;
9304  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
9305  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
9306  
9307 +#define MNT_TAGID      0x10000
9308 +#define MNT_NOTAG      0x20000
9309 +
9310  struct vfsmount {
9311         struct list_head mnt_hash;
9312         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9313 @@ -71,6 +74,7 @@ struct vfsmount {
9314          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
9315          */
9316         atomic_t __mnt_writers;
9317 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9318  };
9319  
9320  static inline struct vfsmount *mntget(struct vfsmount *mnt)
9321 diff -NurpP --minimal linux-2.6.27.10/include/linux/net.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/net.h
9322 --- linux-2.6.27.10/include/linux/net.h 2008-10-13 14:52:09.000000000 +0200
9323 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/net.h    2008-10-13 14:54:20.000000000 +0200
9324 @@ -68,6 +68,7 @@ struct net;
9325  #define SOCK_NOSPACE           2
9326  #define SOCK_PASSCRED          3
9327  #define SOCK_PASSSEC           4
9328 +#define SOCK_USER_SOCKET       5
9329  
9330  #ifndef ARCH_HAS_SOCKET_TYPES
9331  /**
9332 diff -NurpP --minimal linux-2.6.27.10/include/linux/nfs_mount.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/nfs_mount.h
9333 --- linux-2.6.27.10/include/linux/nfs_mount.h   2008-07-13 23:51:29.000000000 +0200
9334 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/nfs_mount.h      2008-10-13 14:54:20.000000000 +0200
9335 @@ -63,6 +63,7 @@ struct nfs_mount_data {
9336  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9337  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9338  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9339 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9340 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9341 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9342  
9343  #endif
9344 diff -NurpP --minimal linux-2.6.27.10/include/linux/nsproxy.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/nsproxy.h
9345 --- linux-2.6.27.10/include/linux/nsproxy.h     2008-10-13 14:52:09.000000000 +0200
9346 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/nsproxy.h        2008-10-13 14:54:20.000000000 +0200
9347 @@ -3,6 +3,7 @@
9348  
9349  #include <linux/spinlock.h>
9350  #include <linux/sched.h>
9351 +#include <linux/vserver/debug.h>
9352  
9353  struct mnt_namespace;
9354  struct uts_namespace;
9355 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9356  }
9357  
9358  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9359 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9360  void exit_task_namespaces(struct task_struct *tsk);
9361  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9362  void free_nsproxy(struct nsproxy *ns);
9363  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9364         struct fs_struct *);
9365  
9366 -static inline void put_nsproxy(struct nsproxy *ns)
9367 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9368 +
9369 +static inline void __get_nsproxy(struct nsproxy *ns,
9370 +       const char *_file, int _line)
9371  {
9372 -       if (atomic_dec_and_test(&ns->count)) {
9373 -               free_nsproxy(ns);
9374 -       }
9375 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9376 +               ns, atomic_read(&ns->count), _file, _line);
9377 +       atomic_inc(&ns->count);
9378  }
9379  
9380 -static inline void get_nsproxy(struct nsproxy *ns)
9381 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9382 +
9383 +static inline void __put_nsproxy(struct nsproxy *ns,
9384 +       const char *_file, int _line)
9385  {
9386 -       atomic_inc(&ns->count);
9387 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9388 +               ns, atomic_read(&ns->count), _file, _line);
9389 +       if (atomic_dec_and_test(&ns->count)) {
9390 +               free_nsproxy(ns);
9391 +       }
9392  }
9393  
9394  #ifdef CONFIG_CGROUP_NS
9395 diff -NurpP --minimal linux-2.6.27.10/include/linux/pid.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/pid.h
9396 --- linux-2.6.27.10/include/linux/pid.h 2008-10-13 14:52:09.000000000 +0200
9397 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/pid.h    2008-10-13 14:54:20.000000000 +0200
9398 @@ -8,7 +8,8 @@ enum pid_type
9399         PIDTYPE_PID,
9400         PIDTYPE_PGID,
9401         PIDTYPE_SID,
9402 -       PIDTYPE_MAX
9403 +       PIDTYPE_MAX,
9404 +       PIDTYPE_REALPID
9405  };
9406  
9407  /*
9408 @@ -142,6 +143,7 @@ static inline pid_t pid_nr(struct pid *p
9409  }
9410  
9411  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9412 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9413  pid_t pid_vnr(struct pid *pid);
9414  
9415  #define do_each_pid_task(pid, type, task)                              \
9416 diff -NurpP --minimal linux-2.6.27.10/include/linux/proc_fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/proc_fs.h
9417 --- linux-2.6.27.10/include/linux/proc_fs.h     2008-10-13 14:52:09.000000000 +0200
9418 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/proc_fs.h        2008-10-13 14:54:20.000000000 +0200
9419 @@ -59,6 +59,7 @@ struct proc_dir_entry {
9420         nlink_t nlink;
9421         uid_t uid;
9422         gid_t gid;
9423 +       int vx_flags;
9424         loff_t size;
9425         const struct inode_operations *proc_iops;
9426         /*
9427 @@ -274,12 +275,18 @@ static inline void kclist_add(struct kco
9428  extern void kclist_add(struct kcore_list *, void *, size_t);
9429  #endif
9430  
9431 +struct vx_info;
9432 +struct nx_info;
9433 +
9434  union proc_op {
9435         int (*proc_get_link)(struct inode *, struct path *);
9436         int (*proc_read)(struct task_struct *task, char *page);
9437         int (*proc_show)(struct seq_file *m,
9438                 struct pid_namespace *ns, struct pid *pid,
9439                 struct task_struct *task);
9440 +       int (*proc_vs_read)(char *page);
9441 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9442 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9443  };
9444  
9445  struct ctl_table_header;
9446 @@ -287,6 +294,7 @@ struct ctl_table;
9447  
9448  struct proc_inode {
9449         struct pid *pid;
9450 +       int vx_flags;
9451         int fd;
9452         union proc_op op;
9453         struct proc_dir_entry *pde;
9454 diff -NurpP --minimal linux-2.6.27.10/include/linux/reiserfs_fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/reiserfs_fs.h
9455 --- linux-2.6.27.10/include/linux/reiserfs_fs.h 2008-10-13 14:52:09.000000000 +0200
9456 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/reiserfs_fs.h    2008-10-13 14:54:20.000000000 +0200
9457 @@ -837,6 +837,11 @@ struct stat_data_v1 {
9458  #define REISERFS_COMPR_FL     FS_COMPR_FL
9459  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9460  
9461 +/* unfortunately reiserfs sdattr is only 16 bit */
9462 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9463 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9464 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9465 +
9466  /* persistent flags that file inherits from the parent directory */
9467  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9468                                 REISERFS_SYNC_FL |      \
9469 @@ -846,6 +851,9 @@ struct stat_data_v1 {
9470                                 REISERFS_COMPR_FL |     \
9471                                 REISERFS_NOTAIL_FL )
9472  
9473 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9474 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9475 +
9476  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9477     address blocks) */
9478  struct stat_data {
9479 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
9480  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9481  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9482  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9483 +int reiserfs_sync_flags(struct inode *inode);
9484  
9485  /* namei.c */
9486  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9487 diff -NurpP --minimal linux-2.6.27.10/include/linux/reiserfs_fs_sb.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/reiserfs_fs_sb.h
9488 --- linux-2.6.27.10/include/linux/reiserfs_fs_sb.h      2008-10-13 14:52:09.000000000 +0200
9489 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/reiserfs_fs_sb.h 2008-10-13 14:54:20.000000000 +0200
9490 @@ -455,6 +455,7 @@ enum reiserfs_mount_options {
9491         REISERFS_POSIXACL,
9492         REISERFS_BARRIER_NONE,
9493         REISERFS_BARRIER_FLUSH,
9494 +       REISERFS_TAGGED,
9495  
9496         /* Actions on error */
9497         REISERFS_ERROR_PANIC,
9498 diff -NurpP --minimal linux-2.6.27.10/include/linux/sched.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/sched.h
9499 --- linux-2.6.27.10/include/linux/sched.h       2008-12-19 12:03:14.000000000 +0100
9500 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/sched.h  2008-12-08 04:52:52.000000000 +0100
9501 @@ -71,7 +71,6 @@ struct sched_param {
9502  #include <linux/fs_struct.h>
9503  #include <linux/compiler.h>
9504  #include <linux/completion.h>
9505 -#include <linux/pid.h>
9506  #include <linux/percpu.h>
9507  #include <linux/topology.h>
9508  #include <linux/proportions.h>
9509 @@ -88,6 +87,7 @@ struct sched_param {
9510  #include <linux/kobject.h>
9511  #include <linux/latencytop.h>
9512  #include <linux/cred.h>
9513 +#include <linux/pid.h>
9514  
9515  #include <asm/processor.h>
9516  
9517 @@ -357,25 +357,27 @@ extern void arch_unmap_area_topdown(stru
9518   * The mm counters are not protected by its page_table_lock,
9519   * so must be incremented atomically.
9520   */
9521 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9522 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9523 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9524 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9525 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9526 -
9527 +#define __set_mm_counter(mm, member, value) \
9528 +       atomic_long_set(&(mm)->_##member, value)
9529 +#define get_mm_counter(mm, member) \
9530 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9531  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
9532  /*
9533   * The mm counters are protected by its page_table_lock,
9534   * so can be incremented directly.
9535   */
9536 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9537 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9538  #define get_mm_counter(mm, member) ((mm)->_##member)
9539 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9540 -#define inc_mm_counter(mm, member) (mm)->_##member++
9541 -#define dec_mm_counter(mm, member) (mm)->_##member--
9542  
9543  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
9544  
9545 +#define set_mm_counter(mm, member, value) \
9546 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9547 +#define add_mm_counter(mm, member, value) \
9548 +       vx_ ## member ## pages_add((mm), (value))
9549 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9550 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9551 +
9552  #define get_mm_rss(mm)                                 \
9553         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9554  #define update_hiwater_rss(mm) do {                    \
9555 @@ -1200,6 +1202,14 @@ struct task_struct {
9556  #endif
9557         seccomp_t seccomp;
9558  
9559 +/* vserver context data */
9560 +       struct vx_info *vx_info;
9561 +       struct nx_info *nx_info;
9562 +
9563 +       xid_t xid;
9564 +       nid_t nid;
9565 +       tag_t tag;
9566 +
9567  /* Thread group tracking */
9568         u32 parent_exec_id;
9569         u32 self_exec_id;
9570 @@ -1386,6 +1396,11 @@ struct pid_namespace;
9571   * see also pid_nr() etc in include/linux/pid.h
9572   */
9573  
9574 +#include <linux/vserver/base.h>
9575 +#include <linux/vserver/context.h>
9576 +#include <linux/vserver/debug.h>
9577 +#include <linux/vserver/pid.h>
9578 +
9579  static inline pid_t task_pid_nr(struct task_struct *tsk)
9580  {
9581         return tsk->pid;
9582 @@ -1395,7 +1410,7 @@ pid_t task_pid_nr_ns(struct task_struct 
9583  
9584  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9585  {
9586 -       return pid_vnr(task_pid(tsk));
9587 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
9588  }
9589  
9590  
9591 @@ -1408,7 +1423,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9592  
9593  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9594  {
9595 -       return pid_vnr(task_tgid(tsk));
9596 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9597  }
9598  
9599  
9600 diff -NurpP --minimal linux-2.6.27.10/include/linux/shmem_fs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/shmem_fs.h
9601 --- linux-2.6.27.10/include/linux/shmem_fs.h    2008-10-13 14:52:09.000000000 +0200
9602 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/shmem_fs.h       2008-10-13 14:54:20.000000000 +0200
9603 @@ -8,6 +8,9 @@
9604  
9605  #define SHMEM_NR_DIRECT 16
9606  
9607 +#define TMPFS_SUPER_MAGIC      0x01021994
9608 +
9609 +
9610  struct shmem_inode_info {
9611         spinlock_t              lock;
9612         unsigned long           flags;
9613 diff -NurpP --minimal linux-2.6.27.10/include/linux/stat.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/stat.h
9614 --- linux-2.6.27.10/include/linux/stat.h        2008-07-13 23:51:29.000000000 +0200
9615 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/stat.h   2008-10-13 14:54:20.000000000 +0200
9616 @@ -66,6 +66,7 @@ struct kstat {
9617         unsigned int    nlink;
9618         uid_t           uid;
9619         gid_t           gid;
9620 +       tag_t           tag;
9621         dev_t           rdev;
9622         loff_t          size;
9623         struct timespec  atime;
9624 diff -NurpP --minimal linux-2.6.27.10/include/linux/sunrpc/auth.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/sunrpc/auth.h
9625 --- linux-2.6.27.10/include/linux/sunrpc/auth.h 2008-07-13 23:51:29.000000000 +0200
9626 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/sunrpc/auth.h    2008-10-13 14:54:20.000000000 +0200
9627 @@ -25,6 +25,7 @@
9628  struct auth_cred {
9629         uid_t   uid;
9630         gid_t   gid;
9631 +       tag_t   tag;
9632         struct group_info *group_info;
9633         unsigned char machine_cred : 1;
9634  };
9635 diff -NurpP --minimal linux-2.6.27.10/include/linux/sunrpc/clnt.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/sunrpc/clnt.h
9636 --- linux-2.6.27.10/include/linux/sunrpc/clnt.h 2008-10-13 14:52:09.000000000 +0200
9637 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/sunrpc/clnt.h    2008-10-13 14:54:20.000000000 +0200
9638 @@ -43,7 +43,8 @@ struct rpc_clnt {
9639         unsigned int            cl_softrtry : 1,/* soft timeouts */
9640                                 cl_discrtry : 1,/* disconnect before retry */
9641                                 cl_autobind : 1,/* use getport() */
9642 -                               cl_chatty   : 1;/* be verbose */
9643 +                               cl_chatty   : 1,/* be verbose */
9644 +                               cl_tag      : 1;/* context tagging */
9645  
9646         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9647         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9648 diff -NurpP --minimal linux-2.6.27.10/include/linux/syscalls.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/syscalls.h
9649 --- linux-2.6.27.10/include/linux/syscalls.h    2008-10-13 14:52:09.000000000 +0200
9650 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/syscalls.h       2008-10-13 14:54:20.000000000 +0200
9651 @@ -295,6 +295,8 @@ asmlinkage long sys_symlink(const char _
9652  asmlinkage long sys_unlink(const char __user *pathname);
9653  asmlinkage long sys_rename(const char __user *oldname,
9654                                 const char __user *newname);
9655 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9656 +                               umode_t mode);
9657  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9658  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9659  
9660 diff -NurpP --minimal linux-2.6.27.10/include/linux/sysctl.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/sysctl.h
9661 --- linux-2.6.27.10/include/linux/sysctl.h      2008-10-13 14:52:09.000000000 +0200
9662 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/sysctl.h 2008-10-13 14:54:20.000000000 +0200
9663 @@ -70,6 +70,7 @@ enum
9664         CTL_ABI=9,              /* Binary emulation */
9665         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9666         CTL_ARLAN=254,          /* arlan wireless driver */
9667 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9668         CTL_S390DBF=5677,       /* s390 debug */
9669         CTL_SUNRPC=7249,        /* sunrpc debug */
9670         CTL_PM=9899,            /* frv power management */
9671 @@ -104,6 +105,7 @@ enum
9672  
9673         KERN_PANIC=15,          /* int: panic timeout */
9674         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9675 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9676  
9677         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9678         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9679 diff -NurpP --minimal linux-2.6.27.10/include/linux/sysfs.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/sysfs.h
9680 --- linux-2.6.27.10/include/linux/sysfs.h       2008-10-13 14:52:09.000000000 +0200
9681 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/sysfs.h  2008-10-13 14:54:20.000000000 +0200
9682 @@ -17,6 +17,8 @@
9683  #include <linux/list.h>
9684  #include <asm/atomic.h>
9685  
9686 +#define SYSFS_SUPER_MAGIC      0x62656572
9687 +
9688  struct kobject;
9689  struct module;
9690  
9691 diff -NurpP --minimal linux-2.6.27.10/include/linux/time.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/time.h
9692 --- linux-2.6.27.10/include/linux/time.h        2008-07-13 23:51:29.000000000 +0200
9693 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/time.h   2008-10-13 14:54:20.000000000 +0200
9694 @@ -179,6 +179,9 @@ static __always_inline void timespec_add
9695         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9696         a->tv_nsec = ns;
9697  }
9698 +
9699 +#include <linux/vs_time.h>
9700 +
9701  #endif /* __KERNEL__ */
9702  
9703  #define NFDBITS                        __NFDBITS
9704 diff -NurpP --minimal linux-2.6.27.10/include/linux/types.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/types.h
9705 --- linux-2.6.27.10/include/linux/types.h       2008-07-13 23:51:29.000000000 +0200
9706 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/types.h  2008-10-13 14:54:20.000000000 +0200
9707 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9708  typedef __kernel_gid32_t       gid_t;
9709  typedef __kernel_uid16_t        uid16_t;
9710  typedef __kernel_gid16_t        gid16_t;
9711 +typedef unsigned int           xid_t;
9712 +typedef unsigned int           nid_t;
9713 +typedef unsigned int           tag_t;
9714  
9715  typedef unsigned long          uintptr_t;
9716  
9717 diff -NurpP --minimal linux-2.6.27.10/include/linux/vroot.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vroot.h
9718 --- linux-2.6.27.10/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
9719 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vroot.h  2008-10-13 14:54:20.000000000 +0200
9720 @@ -0,0 +1,51 @@
9721 +
9722 +/*
9723 + * include/linux/vroot.h
9724 + *
9725 + * written by Herbert Pötzl, 9/11/2002
9726 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9727 + *
9728 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9729 + * Redistribution of this file is permitted under the
9730 + * GNU General Public License.
9731 + */
9732 +
9733 +#ifndef _LINUX_VROOT_H
9734 +#define _LINUX_VROOT_H
9735 +
9736 +
9737 +#ifdef __KERNEL__
9738 +
9739 +/* Possible states of device */
9740 +enum {
9741 +       Vr_unbound,
9742 +       Vr_bound,
9743 +};
9744 +
9745 +struct vroot_device {
9746 +       int             vr_number;
9747 +       int             vr_refcnt;
9748 +
9749 +       struct semaphore        vr_ctl_mutex;
9750 +       struct block_device    *vr_device;
9751 +       int                     vr_state;
9752 +};
9753 +
9754 +
9755 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9756 +
9757 +extern int register_vroot_grb(vroot_grb_func *);
9758 +extern int unregister_vroot_grb(vroot_grb_func *);
9759 +
9760 +#endif /* __KERNEL__ */
9761 +
9762 +#define MAX_VROOT_DEFAULT      8
9763 +
9764 +/*
9765 + * IOCTL commands --- we will commandeer 0x56 ('V')
9766 + */
9767 +
9768 +#define VROOT_SET_DEV          0x5600
9769 +#define VROOT_CLR_DEV          0x5601
9770 +
9771 +#endif /* _LINUX_VROOT_H */
9772 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_base.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_base.h
9773 --- linux-2.6.27.10/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
9774 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_base.h        2008-10-13 14:54:20.000000000 +0200
9775 @@ -0,0 +1,10 @@
9776 +#ifndef _VS_BASE_H
9777 +#define _VS_BASE_H
9778 +
9779 +#include "vserver/base.h"
9780 +#include "vserver/check.h"
9781 +#include "vserver/debug.h"
9782 +
9783 +#else
9784 +#warning duplicate inclusion
9785 +#endif
9786 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_context.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_context.h
9787 --- linux-2.6.27.10/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
9788 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_context.h     2008-10-13 14:54:20.000000000 +0200
9789 @@ -0,0 +1,227 @@
9790 +#ifndef _VS_CONTEXT_H
9791 +#define _VS_CONTEXT_H
9792 +
9793 +#include "vserver/base.h"
9794 +#include "vserver/check.h"
9795 +#include "vserver/context.h"
9796 +#include "vserver/history.h"
9797 +#include "vserver/debug.h"
9798 +
9799 +#include <linux/sched.h>
9800 +
9801 +
9802 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9803 +
9804 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9805 +       const char *_file, int _line, void *_here)
9806 +{
9807 +       if (!vxi)
9808 +               return NULL;
9809 +
9810 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9811 +               vxi, vxi ? vxi->vx_id : 0,
9812 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9813 +               _file, _line);
9814 +       __vxh_get_vx_info(vxi, _here);
9815 +
9816 +       atomic_inc(&vxi->vx_usecnt);
9817 +       return vxi;
9818 +}
9819 +
9820 +
9821 +extern void free_vx_info(struct vx_info *);
9822 +
9823 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9824 +
9825 +static inline void __put_vx_info(struct vx_info *vxi,
9826 +       const char *_file, int _line, void *_here)
9827 +{
9828 +       if (!vxi)
9829 +               return;
9830 +
9831 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9832 +               vxi, vxi ? vxi->vx_id : 0,
9833 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9834 +               _file, _line);
9835 +       __vxh_put_vx_info(vxi, _here);
9836 +
9837 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9838 +               free_vx_info(vxi);
9839 +}
9840 +
9841 +
9842 +#define init_vx_info(p, i) \
9843 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9844 +
9845 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9846 +       const char *_file, int _line, void *_here)
9847 +{
9848 +       if (vxi) {
9849 +               vxlprintk(VXD_CBIT(xid, 3),
9850 +                       "init_vx_info(%p[#%d.%d])",
9851 +                       vxi, vxi ? vxi->vx_id : 0,
9852 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9853 +                       _file, _line);
9854 +               __vxh_init_vx_info(vxi, vxp, _here);
9855 +
9856 +               atomic_inc(&vxi->vx_usecnt);
9857 +       }
9858 +       *vxp = vxi;
9859 +}
9860 +
9861 +
9862 +#define set_vx_info(p, i) \
9863 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9864 +
9865 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9866 +       const char *_file, int _line, void *_here)
9867 +{
9868 +       struct vx_info *vxo;
9869 +
9870 +       if (!vxi)
9871 +               return;
9872 +
9873 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9874 +               vxi, vxi ? vxi->vx_id : 0,
9875 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9876 +               _file, _line);
9877 +       __vxh_set_vx_info(vxi, vxp, _here);
9878 +
9879 +       atomic_inc(&vxi->vx_usecnt);
9880 +       vxo = xchg(vxp, vxi);
9881 +       BUG_ON(vxo);
9882 +}
9883 +
9884 +
9885 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9886 +
9887 +static inline void __clr_vx_info(struct vx_info **vxp,
9888 +       const char *_file, int _line, void *_here)
9889 +{
9890 +       struct vx_info *vxo;
9891 +
9892 +       vxo = xchg(vxp, NULL);
9893 +       if (!vxo)
9894 +               return;
9895 +
9896 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9897 +               vxo, vxo ? vxo->vx_id : 0,
9898 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9899 +               _file, _line);
9900 +       __vxh_clr_vx_info(vxo, vxp, _here);
9901 +
9902 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9903 +               free_vx_info(vxo);
9904 +}
9905 +
9906 +
9907 +#define claim_vx_info(v, p) \
9908 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9909 +
9910 +static inline void __claim_vx_info(struct vx_info *vxi,
9911 +       struct task_struct *task,
9912 +       const char *_file, int _line, void *_here)
9913 +{
9914 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9915 +               vxi, vxi ? vxi->vx_id : 0,
9916 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9917 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9918 +               task, _file, _line);
9919 +       __vxh_claim_vx_info(vxi, task, _here);
9920 +
9921 +       atomic_inc(&vxi->vx_tasks);
9922 +}
9923 +
9924 +
9925 +extern void unhash_vx_info(struct vx_info *);
9926 +
9927 +#define release_vx_info(v, p) \
9928 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9929 +
9930 +static inline void __release_vx_info(struct vx_info *vxi,
9931 +       struct task_struct *task,
9932 +       const char *_file, int _line, void *_here)
9933 +{
9934 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9935 +               vxi, vxi ? vxi->vx_id : 0,
9936 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9937 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9938 +               task, _file, _line);
9939 +       __vxh_release_vx_info(vxi, task, _here);
9940 +
9941 +       might_sleep();
9942 +
9943 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9944 +               unhash_vx_info(vxi);
9945 +}
9946 +
9947 +
9948 +#define task_get_vx_info(p) \
9949 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9950 +
9951 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9952 +       const char *_file, int _line, void *_here)
9953 +{
9954 +       struct vx_info *vxi;
9955 +
9956 +       task_lock(p);
9957 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9958 +               p, _file, _line);
9959 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9960 +       task_unlock(p);
9961 +       return vxi;
9962 +}
9963 +
9964 +
9965 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9966 +{
9967 +       if (waitqueue_active(&vxi->vx_wait))
9968 +               wake_up_interruptible(&vxi->vx_wait);
9969 +}
9970 +
9971 +
9972 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9973 +
9974 +static inline void __enter_vx_info(struct vx_info *vxi,
9975 +       struct vx_info_save *vxis, const char *_file, int _line)
9976 +{
9977 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9978 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9979 +               current->xid, current->vx_info, _file, _line);
9980 +       vxis->vxi = xchg(&current->vx_info, vxi);
9981 +       vxis->xid = current->xid;
9982 +       current->xid = vxi ? vxi->vx_id : 0;
9983 +}
9984 +
9985 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9986 +
9987 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9988 +       const char *_file, int _line)
9989 +{
9990 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9991 +               vxis, vxis->xid, vxis->vxi, current,
9992 +               current->xid, current->vx_info, _file, _line);
9993 +       (void)xchg(&current->vx_info, vxis->vxi);
9994 +       current->xid = vxis->xid;
9995 +}
9996 +
9997 +
9998 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9999 +{
10000 +       vxis->vxi = xchg(&current->vx_info, NULL);
10001 +       vxis->xid = xchg(&current->xid, (xid_t)0);
10002 +}
10003 +
10004 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
10005 +{
10006 +       (void)xchg(&current->xid, vxis->xid);
10007 +       (void)xchg(&current->vx_info, vxis->vxi);
10008 +}
10009 +
10010 +extern void exit_vx_info(struct task_struct *, int);
10011 +extern void exit_vx_info_early(struct task_struct *, int);
10012 +
10013 +
10014 +#else
10015 +#warning duplicate inclusion
10016 +#endif
10017 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_cowbl.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_cowbl.h
10018 --- linux-2.6.27.10/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
10019 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_cowbl.h       2008-10-13 14:54:20.000000000 +0200
10020 @@ -0,0 +1,47 @@
10021 +#ifndef _VS_COWBL_H
10022 +#define _VS_COWBL_H
10023 +
10024 +#include <linux/fs.h>
10025 +#include <linux/dcache.h>
10026 +#include <linux/namei.h>
10027 +
10028 +extern struct dentry *cow_break_link(const char *pathname);
10029 +
10030 +static inline int cow_check_and_break(struct path *path)
10031 +{
10032 +       struct inode *inode = path->dentry->d_inode;
10033 +       int error = 0;
10034 +
10035 +       /* do we need this check? */
10036 +       if (IS_RDONLY(inode))
10037 +               return -EROFS;
10038 +
10039 +       if (IS_COW(inode)) {
10040 +               if (IS_COW_LINK(inode)) {
10041 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
10042 +                       char *pp, *buf;
10043 +
10044 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
10045 +                       if (!buf) {
10046 +                               return -ENOMEM;
10047 +                       }
10048 +                       pp = d_path(path, buf, PATH_MAX);
10049 +                       new_dentry = cow_break_link(pp);
10050 +                       kfree(buf);
10051 +                       if (!IS_ERR(new_dentry)) {
10052 +                               path->dentry = new_dentry;
10053 +                               dput(old_dentry);
10054 +                       } else
10055 +                               error = PTR_ERR(new_dentry);
10056 +               } else {
10057 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
10058 +                       inode->i_ctime = CURRENT_TIME;
10059 +                       mark_inode_dirty(inode);
10060 +               }
10061 +       }
10062 +       return error;
10063 +}
10064 +
10065 +#else
10066 +#warning duplicate inclusion
10067 +#endif
10068 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_cvirt.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_cvirt.h
10069 --- linux-2.6.27.10/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
10070 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_cvirt.h       2008-10-13 14:54:20.000000000 +0200
10071 @@ -0,0 +1,50 @@
10072 +#ifndef _VS_CVIRT_H
10073 +#define _VS_CVIRT_H
10074 +
10075 +#include "vserver/cvirt.h"
10076 +#include "vserver/context.h"
10077 +#include "vserver/base.h"
10078 +#include "vserver/check.h"
10079 +#include "vserver/debug.h"
10080 +
10081 +
10082 +static inline void vx_activate_task(struct task_struct *p)
10083 +{
10084 +       struct vx_info *vxi;
10085 +
10086 +       if ((vxi = p->vx_info)) {
10087 +               vx_update_load(vxi);
10088 +               atomic_inc(&vxi->cvirt.nr_running);
10089 +       }
10090 +}
10091 +
10092 +static inline void vx_deactivate_task(struct task_struct *p)
10093 +{
10094 +       struct vx_info *vxi;
10095 +
10096 +       if ((vxi = p->vx_info)) {
10097 +               vx_update_load(vxi);
10098 +               atomic_dec(&vxi->cvirt.nr_running);
10099 +       }
10100 +}
10101 +
10102 +static inline void vx_uninterruptible_inc(struct task_struct *p)
10103 +{
10104 +       struct vx_info *vxi;
10105 +
10106 +       if ((vxi = p->vx_info))
10107 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
10108 +}
10109 +
10110 +static inline void vx_uninterruptible_dec(struct task_struct *p)
10111 +{
10112 +       struct vx_info *vxi;
10113 +
10114 +       if ((vxi = p->vx_info))
10115 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
10116 +}
10117 +
10118 +
10119 +#else
10120 +#warning duplicate inclusion
10121 +#endif
10122 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_device.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_device.h
10123 --- linux-2.6.27.10/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
10124 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_device.h      2008-10-13 14:54:20.000000000 +0200
10125 @@ -0,0 +1,45 @@
10126 +#ifndef _VS_DEVICE_H
10127 +#define _VS_DEVICE_H
10128 +
10129 +#include "vserver/base.h"
10130 +#include "vserver/device.h"
10131 +#include "vserver/debug.h"
10132 +
10133 +
10134 +#ifdef CONFIG_VSERVER_DEVICE
10135 +
10136 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
10137 +
10138 +#define vs_device_perm(v, d, m, p) \
10139 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
10140 +
10141 +#else
10142 +
10143 +static inline
10144 +int vs_map_device(struct vx_info *vxi,
10145 +       dev_t device, dev_t *target, umode_t mode)
10146 +{
10147 +       if (target)
10148 +               *target = device;
10149 +       return ~0;
10150 +}
10151 +
10152 +#define vs_device_perm(v, d, m, p) ((p) == (p))
10153 +
10154 +#endif
10155 +
10156 +
10157 +#define vs_map_chrdev(d, t, p) \
10158 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
10159 +#define vs_map_blkdev(d, t, p) \
10160 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
10161 +
10162 +#define vs_chrdev_perm(d, p) \
10163 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
10164 +#define vs_blkdev_perm(d, p) \
10165 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
10166 +
10167 +
10168 +#else
10169 +#warning duplicate inclusion
10170 +#endif
10171 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_dlimit.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_dlimit.h
10172 --- linux-2.6.27.10/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
10173 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_dlimit.h      2008-10-13 14:54:20.000000000 +0200
10174 @@ -0,0 +1,211 @@
10175 +#ifndef _VS_DLIMIT_H
10176 +#define _VS_DLIMIT_H
10177 +
10178 +#include <linux/fs.h>
10179 +
10180 +#include "vserver/dlimit.h"
10181 +#include "vserver/base.h"
10182 +#include "vserver/debug.h"
10183 +
10184 +
10185 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10186 +
10187 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10188 +       const char *_file, int _line)
10189 +{
10190 +       if (!dli)
10191 +               return NULL;
10192 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10193 +               dli, dli ? dli->dl_tag : 0,
10194 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10195 +               _file, _line);
10196 +       atomic_inc(&dli->dl_usecnt);
10197 +       return dli;
10198 +}
10199 +
10200 +
10201 +#define free_dl_info(i) \
10202 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10203 +
10204 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10205 +
10206 +static inline void __put_dl_info(struct dl_info *dli,
10207 +       const char *_file, int _line)
10208 +{
10209 +       if (!dli)
10210 +               return;
10211 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10212 +               dli, dli ? dli->dl_tag : 0,
10213 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10214 +               _file, _line);
10215 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10216 +               free_dl_info(dli);
10217 +}
10218 +
10219 +
10220 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10221 +
10222 +static inline int __dl_alloc_space(struct super_block *sb,
10223 +       tag_t tag, dlsize_t nr, const char *file, int line)
10224 +{
10225 +       struct dl_info *dli = NULL;
10226 +       int ret = 0;
10227 +
10228 +       if (nr == 0)
10229 +               goto out;
10230 +       dli = locate_dl_info(sb, tag);
10231 +       if (!dli)
10232 +               goto out;
10233 +
10234 +       spin_lock(&dli->dl_lock);
10235 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10236 +       if (!ret)
10237 +               dli->dl_space_used += nr;
10238 +       spin_unlock(&dli->dl_lock);
10239 +       put_dl_info(dli);
10240 +out:
10241 +       vxlprintk(VXD_CBIT(dlim, 1),
10242 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10243 +               sb, tag, __dlimit_char(dli), (long long)nr,
10244 +               ret, file, line);
10245 +       return ret;
10246 +}
10247 +
10248 +static inline void __dl_free_space(struct super_block *sb,
10249 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10250 +{
10251 +       struct dl_info *dli = NULL;
10252 +
10253 +       if (nr == 0)
10254 +               goto out;
10255 +       dli = locate_dl_info(sb, tag);
10256 +       if (!dli)
10257 +               goto out;
10258 +
10259 +       spin_lock(&dli->dl_lock);
10260 +       if (dli->dl_space_used > nr)
10261 +               dli->dl_space_used -= nr;
10262 +       else
10263 +               dli->dl_space_used = 0;
10264 +       spin_unlock(&dli->dl_lock);
10265 +       put_dl_info(dli);
10266 +out:
10267 +       vxlprintk(VXD_CBIT(dlim, 1),
10268 +               "FREE  (%p,#%d)%c %lld bytes",
10269 +               sb, tag, __dlimit_char(dli), (long long)nr,
10270 +               _file, _line);
10271 +}
10272 +
10273 +static inline int __dl_alloc_inode(struct super_block *sb,
10274 +       tag_t tag, const char *_file, int _line)
10275 +{
10276 +       struct dl_info *dli;
10277 +       int ret = 0;
10278 +
10279 +       dli = locate_dl_info(sb, tag);
10280 +       if (!dli)
10281 +               goto out;
10282 +
10283 +       spin_lock(&dli->dl_lock);
10284 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10285 +       if (!ret)
10286 +               dli->dl_inodes_used++;
10287 +       spin_unlock(&dli->dl_lock);
10288 +       put_dl_info(dli);
10289 +out:
10290 +       vxlprintk(VXD_CBIT(dlim, 0),
10291 +               "ALLOC (%p,#%d)%c inode (%d)",
10292 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10293 +       return ret;
10294 +}
10295 +
10296 +static inline void __dl_free_inode(struct super_block *sb,
10297 +       tag_t tag, const char *_file, int _line)
10298 +{
10299 +       struct dl_info *dli;
10300 +
10301 +       dli = locate_dl_info(sb, tag);
10302 +       if (!dli)
10303 +               goto out;
10304 +
10305 +       spin_lock(&dli->dl_lock);
10306 +       if (dli->dl_inodes_used > 1)
10307 +               dli->dl_inodes_used--;
10308 +       else
10309 +               dli->dl_inodes_used = 0;
10310 +       spin_unlock(&dli->dl_lock);
10311 +       put_dl_info(dli);
10312 +out:
10313 +       vxlprintk(VXD_CBIT(dlim, 0),
10314 +               "FREE  (%p,#%d)%c inode",
10315 +               sb, tag, __dlimit_char(dli), _file, _line);
10316 +}
10317 +
10318 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10319 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10320 +       const char *_file, int _line)
10321 +{
10322 +       struct dl_info *dli;
10323 +       uint64_t broot, bfree;
10324 +
10325 +       dli = locate_dl_info(sb, tag);
10326 +       if (!dli)
10327 +               return;
10328 +
10329 +       spin_lock(&dli->dl_lock);
10330 +       broot = (dli->dl_space_total -
10331 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10332 +               >> sb->s_blocksize_bits;
10333 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10334 +                       >> sb->s_blocksize_bits;
10335 +       spin_unlock(&dli->dl_lock);
10336 +
10337 +       vxlprintk(VXD_CBIT(dlim, 2),
10338 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10339 +               (long long)bfree, (long long)broot,
10340 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10341 +               _file, _line);
10342 +       if (free_blocks) {
10343 +               if (*free_blocks > bfree)
10344 +                       *free_blocks = bfree;
10345 +       }
10346 +       if (root_blocks) {
10347 +               if (*root_blocks > broot)
10348 +                       *root_blocks = broot;
10349 +       }
10350 +       put_dl_info(dli);
10351 +}
10352 +
10353 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
10354 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10355 +               __FILE__, __LINE__ )
10356 +
10357 +#define DLIMIT_FREE_SPACE(in, bytes) \
10358 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10359 +               __FILE__, __LINE__ )
10360 +
10361 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
10362 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
10363 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10364 +               __FILE__, __LINE__ )
10365 +
10366 +#define DLIMIT_FREE_BLOCK(in, nr) \
10367 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
10368 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10369 +               __FILE__, __LINE__ )
10370 +
10371 +
10372 +#define DLIMIT_ALLOC_INODE(in) \
10373 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10374 +
10375 +#define DLIMIT_FREE_INODE(in) \
10376 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10377 +
10378 +
10379 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
10380 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10381 +
10382 +
10383 +#else
10384 +#warning duplicate inclusion
10385 +#endif
10386 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/base.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/base.h
10387 --- linux-2.6.27.10/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
10388 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/base.h   2008-10-13 14:54:20.000000000 +0200
10389 @@ -0,0 +1,157 @@
10390 +#ifndef _VX_BASE_H
10391 +#define _VX_BASE_H
10392 +
10393 +
10394 +/* context state changes */
10395 +
10396 +enum {
10397 +       VSC_STARTUP = 1,
10398 +       VSC_SHUTDOWN,
10399 +
10400 +       VSC_NETUP,
10401 +       VSC_NETDOWN,
10402 +};
10403 +
10404 +
10405 +
10406 +#define vx_task_xid(t) ((t)->xid)
10407 +
10408 +#define vx_current_xid() vx_task_xid(current)
10409 +
10410 +#define current_vx_info() (current->vx_info)
10411 +
10412 +
10413 +#define nx_task_nid(t) ((t)->nid)
10414 +
10415 +#define nx_current_nid() nx_task_nid(current)
10416 +
10417 +#define current_nx_info() (current->nx_info)
10418 +
10419 +
10420 +/* generic flag merging */
10421 +
10422 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10423 +
10424 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10425 +
10426 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10427 +
10428 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10429 +
10430 +
10431 +/* context flags */
10432 +
10433 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10434 +
10435 +#define vx_current_flags()     __vx_flags(current->vx_info)
10436 +
10437 +#define vx_info_flags(v, m, f) \
10438 +       vs_check_flags(__vx_flags(v), m, f)
10439 +
10440 +#define task_vx_flags(t, m, f) \
10441 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10442 +
10443 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
10444 +
10445 +
10446 +/* context caps */
10447 +
10448 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10449 +
10450 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
10451 +
10452 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10453 +
10454 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
10455 +
10456 +
10457 +
10458 +/* network flags */
10459 +
10460 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10461 +
10462 +#define nx_current_flags()     __nx_flags(current->nx_info)
10463 +
10464 +#define nx_info_flags(n, m, f) \
10465 +       vs_check_flags(__nx_flags(n), m, f)
10466 +
10467 +#define task_nx_flags(t, m, f) \
10468 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10469 +
10470 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
10471 +
10472 +
10473 +/* network caps */
10474 +
10475 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10476 +
10477 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
10478 +
10479 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10480 +
10481 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
10482 +
10483 +
10484 +/* context mask capabilities */
10485 +
10486 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10487 +
10488 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10489 +
10490 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
10491 +
10492 +
10493 +/* context bcap mask */
10494 +
10495 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10496 +
10497 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
10498 +
10499 +
10500 +/* mask given bcaps */
10501 +
10502 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10503 +
10504 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
10505 +
10506 +
10507 +/* masked cap_bset */
10508 +
10509 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10510 +
10511 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
10512 +
10513 +#if 0
10514 +#define vx_info_mbcap(v, b) \
10515 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10516 +       vx_info_bcaps(v, b) : (b))
10517 +
10518 +#define task_vx_mbcap(t, b) \
10519 +       vx_info_mbcap((t)->vx_info, (t)->b)
10520 +
10521 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10522 +#endif
10523 +
10524 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10525 +
10526 +#define vx_capable(b, c) (capable(b) || \
10527 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
10528 +
10529 +#define nx_capable(b, c) (capable(b) || \
10530 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
10531 +
10532 +#define vx_current_initpid(n) \
10533 +       (current->vx_info && \
10534 +       (current->vx_info->vx_initpid == (n)))
10535 +
10536 +
10537 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10538 +
10539 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10540 +
10541 +
10542 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10543 +
10544 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10545 +
10546 +#endif
10547 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cacct_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct_cmd.h
10548 --- linux-2.6.27.10/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
10549 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct_cmd.h      2008-10-13 14:54:20.000000000 +0200
10550 @@ -0,0 +1,23 @@
10551 +#ifndef _VX_CACCT_CMD_H
10552 +#define _VX_CACCT_CMD_H
10553 +
10554 +
10555 +/* virtual host info name commands */
10556 +
10557 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10558 +
10559 +struct vcmd_sock_stat_v0 {
10560 +       uint32_t field;
10561 +       uint32_t count[3];
10562 +       uint64_t total[3];
10563 +};
10564 +
10565 +
10566 +#ifdef __KERNEL__
10567 +
10568 +#include <linux/compiler.h>
10569 +
10570 +extern int vc_sock_stat(struct vx_info *, void __user *);
10571 +
10572 +#endif /* __KERNEL__ */
10573 +#endif /* _VX_CACCT_CMD_H */
10574 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cacct_def.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct_def.h
10575 --- linux-2.6.27.10/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
10576 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct_def.h      2008-10-13 14:54:20.000000000 +0200
10577 @@ -0,0 +1,43 @@
10578 +#ifndef _VX_CACCT_DEF_H
10579 +#define _VX_CACCT_DEF_H
10580 +
10581 +#include <asm/atomic.h>
10582 +#include <linux/vserver/cacct.h>
10583 +
10584 +
10585 +struct _vx_sock_acc {
10586 +       atomic_long_t count;
10587 +       atomic_long_t total;
10588 +};
10589 +
10590 +/* context sub struct */
10591 +
10592 +struct _vx_cacct {
10593 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10594 +       atomic_t slab[8];
10595 +       atomic_t page[6][8];
10596 +};
10597 +
10598 +#ifdef CONFIG_VSERVER_DEBUG
10599 +
10600 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10601 +{
10602 +       int i, j;
10603 +
10604 +       printk("\t_vx_cacct:");
10605 +       for (i = 0; i < 6; i++) {
10606 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10607 +
10608 +               printk("\t [%d] =", i);
10609 +               for (j = 0; j < 3; j++) {
10610 +                       printk(" [%d] = %8lu, %8lu", j,
10611 +                               atomic_long_read(&ptr[j].count),
10612 +                               atomic_long_read(&ptr[j].total));
10613 +               }
10614 +               printk("\n");
10615 +       }
10616 +}
10617 +
10618 +#endif
10619 +
10620 +#endif /* _VX_CACCT_DEF_H */
10621 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cacct.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct.h
10622 --- linux-2.6.27.10/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
10623 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct.h  2008-10-13 14:54:20.000000000 +0200
10624 @@ -0,0 +1,15 @@
10625 +#ifndef _VX_CACCT_H
10626 +#define _VX_CACCT_H
10627 +
10628 +
10629 +enum sock_acc_field {
10630 +       VXA_SOCK_UNSPEC = 0,
10631 +       VXA_SOCK_UNIX,
10632 +       VXA_SOCK_INET,
10633 +       VXA_SOCK_INET6,
10634 +       VXA_SOCK_PACKET,
10635 +       VXA_SOCK_OTHER,
10636 +       VXA_SOCK_SIZE   /* array size */
10637 +};
10638 +
10639 +#endif /* _VX_CACCT_H */
10640 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cacct_int.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct_int.h
10641 --- linux-2.6.27.10/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
10642 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cacct_int.h      2008-10-13 14:54:20.000000000 +0200
10643 @@ -0,0 +1,21 @@
10644 +#ifndef _VX_CACCT_INT_H
10645 +#define _VX_CACCT_INT_H
10646 +
10647 +
10648 +#ifdef __KERNEL__
10649 +
10650 +static inline
10651 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10652 +{
10653 +       return atomic_long_read(&cacct->sock[type][pos].count);
10654 +}
10655 +
10656 +
10657 +static inline
10658 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10659 +{
10660 +       return atomic_long_read(&cacct->sock[type][pos].total);
10661 +}
10662 +
10663 +#endif /* __KERNEL__ */
10664 +#endif /* _VX_CACCT_INT_H */
10665 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/check.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/check.h
10666 --- linux-2.6.27.10/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
10667 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/check.h  2008-10-13 14:54:20.000000000 +0200
10668 @@ -0,0 +1,89 @@
10669 +#ifndef _VS_CHECK_H
10670 +#define _VS_CHECK_H
10671 +
10672 +
10673 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10674 +
10675 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10676 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10677 +#else
10678 +#define MIN_D_CONTEXT  65536
10679 +#endif
10680 +
10681 +/* check conditions */
10682 +
10683 +#define VS_ADMIN       0x0001
10684 +#define VS_WATCH       0x0002
10685 +#define VS_HIDE                0x0004
10686 +#define VS_HOSTID      0x0008
10687 +
10688 +#define VS_IDENT       0x0010
10689 +#define VS_EQUIV       0x0020
10690 +#define VS_PARENT      0x0040
10691 +#define VS_CHILD       0x0080
10692 +
10693 +#define VS_ARG_MASK    0x00F0
10694 +
10695 +#define VS_DYNAMIC     0x0100
10696 +#define VS_STATIC      0x0200
10697 +
10698 +#define VS_ATR_MASK    0x0F00
10699 +
10700 +#ifdef CONFIG_VSERVER_PRIVACY
10701 +#define VS_ADMIN_P     (0)
10702 +#define VS_WATCH_P     (0)
10703 +#else
10704 +#define VS_ADMIN_P     VS_ADMIN
10705 +#define VS_WATCH_P     VS_WATCH
10706 +#endif
10707 +
10708 +#define VS_HARDIRQ     0x1000
10709 +#define VS_SOFTIRQ     0x2000
10710 +#define VS_IRQ         0x4000
10711 +
10712 +#define VS_IRQ_MASK    0xF000
10713 +
10714 +#include <linux/hardirq.h>
10715 +
10716 +/*
10717 + * check current context for ADMIN/WATCH and
10718 + * optionally against supplied argument
10719 + */
10720 +static inline int __vs_check(int cid, int id, unsigned int mode)
10721 +{
10722 +       if (mode & VS_ARG_MASK) {
10723 +               if ((mode & VS_IDENT) && (id == cid))
10724 +                       return 1;
10725 +       }
10726 +       if (mode & VS_ATR_MASK) {
10727 +               if ((mode & VS_DYNAMIC) &&
10728 +                       (id >= MIN_D_CONTEXT) &&
10729 +                       (id <= MAX_S_CONTEXT))
10730 +                       return 1;
10731 +               if ((mode & VS_STATIC) &&
10732 +                       (id > 1) && (id < MIN_D_CONTEXT))
10733 +                       return 1;
10734 +       }
10735 +       if (mode & VS_IRQ_MASK) {
10736 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10737 +                       return 1;
10738 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10739 +                       return 1;
10740 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10741 +                       return 1;
10742 +       }
10743 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10744 +               ((mode & VS_WATCH) && (cid == 1)) ||
10745 +               ((mode & VS_HOSTID) && (id == 0)));
10746 +}
10747 +
10748 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10749 +
10750 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10751 +
10752 +
10753 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10754 +
10755 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10756 +
10757 +#endif
10758 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/context_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/context_cmd.h
10759 --- linux-2.6.27.10/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
10760 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/context_cmd.h    2008-10-13 14:54:20.000000000 +0200
10761 @@ -0,0 +1,128 @@
10762 +#ifndef _VX_CONTEXT_CMD_H
10763 +#define _VX_CONTEXT_CMD_H
10764 +
10765 +
10766 +/* vinfo commands */
10767 +
10768 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10769 +
10770 +#ifdef __KERNEL__
10771 +extern int vc_task_xid(uint32_t);
10772 +
10773 +#endif /* __KERNEL__ */
10774 +
10775 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10776 +
10777 +struct vcmd_vx_info_v0 {
10778 +       uint32_t xid;
10779 +       uint32_t initpid;
10780 +       /* more to come */
10781 +};
10782 +
10783 +#ifdef __KERNEL__
10784 +extern int vc_vx_info(struct vx_info *, void __user *);
10785 +
10786 +#endif /* __KERNEL__ */
10787 +
10788 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10789 +
10790 +struct vcmd_ctx_stat_v0 {
10791 +       uint32_t usecnt;
10792 +       uint32_t tasks;
10793 +       /* more to come */
10794 +};
10795 +
10796 +#ifdef __KERNEL__
10797 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10798 +
10799 +#endif /* __KERNEL__ */
10800 +
10801 +/* context commands */
10802 +
10803 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10804 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10805 +
10806 +struct vcmd_ctx_create {
10807 +       uint64_t flagword;
10808 +};
10809 +
10810 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10811 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10812 +
10813 +struct vcmd_ctx_migrate {
10814 +       uint64_t flagword;
10815 +};
10816 +
10817 +#ifdef __KERNEL__
10818 +extern int vc_ctx_create(uint32_t, void __user *);
10819 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10820 +
10821 +#endif /* __KERNEL__ */
10822 +
10823 +
10824 +/* flag commands */
10825 +
10826 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10827 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10828 +
10829 +struct vcmd_ctx_flags_v0 {
10830 +       uint64_t flagword;
10831 +       uint64_t mask;
10832 +};
10833 +
10834 +#ifdef __KERNEL__
10835 +extern int vc_get_cflags(struct vx_info *, void __user *);
10836 +extern int vc_set_cflags(struct vx_info *, void __user *);
10837 +
10838 +#endif /* __KERNEL__ */
10839 +
10840 +
10841 +/* context caps commands */
10842 +
10843 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10844 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10845 +
10846 +struct vcmd_ctx_caps_v1 {
10847 +       uint64_t ccaps;
10848 +       uint64_t cmask;
10849 +};
10850 +
10851 +#ifdef __KERNEL__
10852 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10853 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10854 +
10855 +#endif /* __KERNEL__ */
10856 +
10857 +
10858 +/* bcaps commands */
10859 +
10860 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10861 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10862 +
10863 +struct vcmd_bcaps {
10864 +       uint64_t bcaps;
10865 +       uint64_t bmask;
10866 +};
10867 +
10868 +#ifdef __KERNEL__
10869 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10870 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10871 +
10872 +#endif /* __KERNEL__ */
10873 +
10874 +
10875 +/* OOM badness */
10876 +
10877 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10878 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10879 +
10880 +struct vcmd_badness_v0 {
10881 +       int64_t bias;
10882 +};
10883 +
10884 +#ifdef __KERNEL__
10885 +extern int vc_get_badness(struct vx_info *, void __user *);
10886 +extern int vc_set_badness(struct vx_info *, void __user *);
10887 +
10888 +#endif /* __KERNEL__ */
10889 +#endif /* _VX_CONTEXT_CMD_H */
10890 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/context.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/context.h
10891 --- linux-2.6.27.10/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
10892 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/context.h        2008-10-31 18:15:28.000000000 +0100
10893 @@ -0,0 +1,178 @@
10894 +#ifndef _VX_CONTEXT_H
10895 +#define _VX_CONTEXT_H
10896 +
10897 +#include <linux/types.h>
10898 +#include <linux/capability.h>
10899 +
10900 +
10901 +/* context flags */
10902 +
10903 +#define VXF_INFO_SCHED         0x00000002
10904 +#define VXF_INFO_NPROC         0x00000004
10905 +#define VXF_INFO_PRIVATE       0x00000008
10906 +
10907 +#define VXF_INFO_INIT          0x00000010
10908 +#define VXF_INFO_HIDE          0x00000020
10909 +#define VXF_INFO_ULIMIT                0x00000040
10910 +#define VXF_INFO_NSPACE                0x00000080
10911 +
10912 +#define VXF_SCHED_HARD         0x00000100
10913 +#define VXF_SCHED_PRIO         0x00000200
10914 +#define VXF_SCHED_PAUSE                0x00000400
10915 +
10916 +#define VXF_VIRT_MEM           0x00010000
10917 +#define VXF_VIRT_UPTIME                0x00020000
10918 +#define VXF_VIRT_CPU           0x00040000
10919 +#define VXF_VIRT_LOAD          0x00080000
10920 +#define VXF_VIRT_TIME          0x00100000
10921 +
10922 +#define VXF_HIDE_MOUNT         0x01000000
10923 +/* was VXF_HIDE_NETIF          0x02000000 */
10924 +#define VXF_HIDE_VINFO         0x04000000
10925 +
10926 +#define VXF_STATE_SETUP                (1ULL << 32)
10927 +#define VXF_STATE_INIT         (1ULL << 33)
10928 +#define VXF_STATE_ADMIN                (1ULL << 34)
10929 +
10930 +#define VXF_SC_HELPER          (1ULL << 36)
10931 +#define VXF_REBOOT_KILL                (1ULL << 37)
10932 +#define VXF_PERSISTENT         (1ULL << 38)
10933 +
10934 +#define VXF_FORK_RSS           (1ULL << 48)
10935 +#define VXF_PROLIFIC           (1ULL << 49)
10936 +
10937 +#define VXF_IGNEG_NICE         (1ULL << 52)
10938 +
10939 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10940 +
10941 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10942 +
10943 +
10944 +/* context migration */
10945 +
10946 +#define VXM_SET_INIT           0x00000001
10947 +#define VXM_SET_REAPER         0x00000002
10948 +
10949 +/* context caps */
10950 +
10951 +#define VXC_CAP_MASK           0x00000000
10952 +
10953 +#define VXC_SET_UTSNAME                0x00000001
10954 +#define VXC_SET_RLIMIT         0x00000002
10955 +
10956 +/* was VXC_RAW_ICMP            0x00000100 */
10957 +#define VXC_SYSLOG             0x00001000
10958 +
10959 +#define VXC_SECURE_MOUNT       0x00010000
10960 +#define VXC_SECURE_REMOUNT     0x00020000
10961 +#define VXC_BINARY_MOUNT       0x00040000
10962 +
10963 +#define VXC_QUOTA_CTL          0x00100000
10964 +#define VXC_ADMIN_MAPPER       0x00200000
10965 +#define VXC_ADMIN_CLOOP                0x00400000
10966 +
10967 +#define VXC_KTHREAD            0x01000000
10968 +
10969 +
10970 +#ifdef __KERNEL__
10971 +
10972 +#include <linux/list.h>
10973 +#include <linux/spinlock.h>
10974 +#include <linux/rcupdate.h>
10975 +
10976 +#include "limit_def.h"
10977 +#include "sched_def.h"
10978 +#include "cvirt_def.h"
10979 +#include "cacct_def.h"
10980 +#include "device_def.h"
10981 +
10982 +#define VX_SPACES      2
10983 +
10984 +struct _vx_info_pc {
10985 +       struct _vx_sched_pc sched_pc;
10986 +       struct _vx_cvirt_pc cvirt_pc;
10987 +};
10988 +
10989 +struct vx_info {
10990 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10991 +       xid_t vx_id;                            /* context id */
10992 +       atomic_t vx_usecnt;                     /* usage count */
10993 +       atomic_t vx_tasks;                      /* tasks count */
10994 +       struct vx_info *vx_parent;              /* parent context */
10995 +       int vx_state;                           /* context state */
10996 +
10997 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10998 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10999 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
11000 +
11001 +       uint64_t vx_flags;                      /* context flags */
11002 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11003 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11004 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
11005 +
11006 +       struct task_struct *vx_reaper;          /* guest reaper process */
11007 +       pid_t vx_initpid;                       /* PID of guest init */
11008 +       int64_t vx_badness_bias;                /* OOM points bias */
11009 +
11010 +       struct _vx_limit limit;                 /* vserver limits */
11011 +       struct _vx_sched sched;                 /* vserver scheduler */
11012 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11013 +       struct _vx_cacct cacct;                 /* context accounting */
11014 +
11015 +       struct _vx_device dmap;                 /* default device map targets */
11016 +
11017 +#ifndef CONFIG_SMP
11018 +       struct _vx_info_pc info_pc;             /* per cpu data */
11019 +#else
11020 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11021 +#endif
11022 +
11023 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11024 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11025 +       int exit_code;                          /* last process exit code */
11026 +
11027 +       char vx_name[65];                       /* vserver name */
11028 +};
11029 +
11030 +#ifndef CONFIG_SMP
11031 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11032 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11033 +#else
11034 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11035 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11036 +#endif
11037 +
11038 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11039 +
11040 +
11041 +struct vx_info_save {
11042 +       struct vx_info *vxi;
11043 +       xid_t xid;
11044 +};
11045 +
11046 +
11047 +/* status flags */
11048 +
11049 +#define VXS_HASHED     0x0001
11050 +#define VXS_PAUSED     0x0010
11051 +#define VXS_SHUTDOWN   0x0100
11052 +#define VXS_HELPER     0x1000
11053 +#define VXS_RELEASED   0x8000
11054 +
11055 +
11056 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11057 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11058 +
11059 +extern struct vx_info *lookup_vx_info(int);
11060 +extern struct vx_info *lookup_or_create_vx_info(int);
11061 +
11062 +extern int get_xid_list(int, unsigned int *, int);
11063 +extern int xid_is_hashed(xid_t);
11064 +
11065 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11066 +
11067 +extern long vs_state_change(struct vx_info *, unsigned int);
11068 +
11069 +
11070 +#endif /* __KERNEL__ */
11071 +#endif /* _VX_CONTEXT_H */
11072 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cvirt_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cvirt_cmd.h
11073 --- linux-2.6.27.10/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
11074 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cvirt_cmd.h      2008-10-13 14:54:20.000000000 +0200
11075 @@ -0,0 +1,53 @@
11076 +#ifndef _VX_CVIRT_CMD_H
11077 +#define _VX_CVIRT_CMD_H
11078 +
11079 +
11080 +/* virtual host info name commands */
11081 +
11082 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11083 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11084 +
11085 +struct vcmd_vhi_name_v0 {
11086 +       uint32_t field;
11087 +       char name[65];
11088 +};
11089 +
11090 +
11091 +enum vhi_name_field {
11092 +       VHIN_CONTEXT = 0,
11093 +       VHIN_SYSNAME,
11094 +       VHIN_NODENAME,
11095 +       VHIN_RELEASE,
11096 +       VHIN_VERSION,
11097 +       VHIN_MACHINE,
11098 +       VHIN_DOMAINNAME,
11099 +};
11100 +
11101 +
11102 +#ifdef __KERNEL__
11103 +
11104 +#include <linux/compiler.h>
11105 +
11106 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11107 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11108 +
11109 +#endif /* __KERNEL__ */
11110 +
11111 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11112 +
11113 +struct vcmd_virt_stat_v0 {
11114 +       uint64_t offset;
11115 +       uint64_t uptime;
11116 +       uint32_t nr_threads;
11117 +       uint32_t nr_running;
11118 +       uint32_t nr_uninterruptible;
11119 +       uint32_t nr_onhold;
11120 +       uint32_t nr_forks;
11121 +       uint32_t load[3];
11122 +};
11123 +
11124 +#ifdef __KERNEL__
11125 +extern int vc_virt_stat(struct vx_info *, void __user *);
11126 +
11127 +#endif /* __KERNEL__ */
11128 +#endif /* _VX_CVIRT_CMD_H */
11129 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cvirt_def.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cvirt_def.h
11130 --- linux-2.6.27.10/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
11131 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cvirt_def.h      2008-10-13 14:54:20.000000000 +0200
11132 @@ -0,0 +1,80 @@
11133 +#ifndef _VX_CVIRT_DEF_H
11134 +#define _VX_CVIRT_DEF_H
11135 +
11136 +#include <linux/jiffies.h>
11137 +#include <linux/spinlock.h>
11138 +#include <linux/wait.h>
11139 +#include <linux/time.h>
11140 +#include <asm/atomic.h>
11141 +
11142 +
11143 +struct _vx_usage_stat {
11144 +       uint64_t user;
11145 +       uint64_t nice;
11146 +       uint64_t system;
11147 +       uint64_t softirq;
11148 +       uint64_t irq;
11149 +       uint64_t idle;
11150 +       uint64_t iowait;
11151 +};
11152 +
11153 +struct _vx_syslog {
11154 +       wait_queue_head_t log_wait;
11155 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11156 +
11157 +       unsigned long log_start;        /* next char to be read by syslog() */
11158 +       unsigned long con_start;        /* next char to be sent to consoles */
11159 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11160 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11161 +
11162 +       char log_buf[1024];
11163 +};
11164 +
11165 +
11166 +/* context sub struct */
11167 +
11168 +struct _vx_cvirt {
11169 +       atomic_t nr_threads;            /* number of current threads */
11170 +       atomic_t nr_running;            /* number of running threads */
11171 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11172 +
11173 +       atomic_t nr_onhold;             /* processes on hold */
11174 +       uint32_t onhold_last;           /* jiffies when put on hold */
11175 +
11176 +       struct timeval bias_tv;         /* time offset to the host */
11177 +       struct timespec bias_idle;
11178 +       struct timespec bias_uptime;    /* context creation point */
11179 +       uint64_t bias_clock;            /* offset in clock_t */
11180 +
11181 +       spinlock_t load_lock;           /* lock for the load averages */
11182 +       atomic_t load_updates;          /* nr of load updates done so far */
11183 +       uint32_t load_last;             /* last time load was calculated */
11184 +       uint32_t load[3];               /* load averages 1,5,15 */
11185 +
11186 +       atomic_t total_forks;           /* number of forks so far */
11187 +
11188 +       struct _vx_syslog syslog;
11189 +};
11190 +
11191 +struct _vx_cvirt_pc {
11192 +       struct _vx_usage_stat cpustat;
11193 +};
11194 +
11195 +
11196 +#ifdef CONFIG_VSERVER_DEBUG
11197 +
11198 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11199 +{
11200 +       printk("\t_vx_cvirt:\n");
11201 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11202 +               atomic_read(&cvirt->nr_threads),
11203 +               atomic_read(&cvirt->nr_running),
11204 +               atomic_read(&cvirt->nr_uninterruptible),
11205 +               atomic_read(&cvirt->nr_onhold));
11206 +       /* add rest here */
11207 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11208 +}
11209 +
11210 +#endif
11211 +
11212 +#endif /* _VX_CVIRT_DEF_H */
11213 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/cvirt.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cvirt.h
11214 --- linux-2.6.27.10/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
11215 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/cvirt.h  2008-10-13 14:54:20.000000000 +0200
11216 @@ -0,0 +1,20 @@
11217 +#ifndef _VX_CVIRT_H
11218 +#define _VX_CVIRT_H
11219 +
11220 +
11221 +#ifdef __KERNEL__
11222 +
11223 +struct timespec;
11224 +
11225 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11226 +
11227 +
11228 +struct vx_info;
11229 +
11230 +void vx_update_load(struct vx_info *);
11231 +
11232 +
11233 +int vx_do_syslog(int, char __user *, int);
11234 +
11235 +#endif /* __KERNEL__ */
11236 +#endif /* _VX_CVIRT_H */
11237 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/debug_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/debug_cmd.h
11238 --- linux-2.6.27.10/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
11239 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/debug_cmd.h      2008-10-13 14:54:20.000000000 +0200
11240 @@ -0,0 +1,58 @@
11241 +#ifndef _VX_DEBUG_CMD_H
11242 +#define _VX_DEBUG_CMD_H
11243 +
11244 +
11245 +/* debug commands */
11246 +
11247 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11248 +
11249 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11250 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11251 +
11252 +struct  vcmd_read_history_v0 {
11253 +       uint32_t index;
11254 +       uint32_t count;
11255 +       char __user *data;
11256 +};
11257 +
11258 +struct  vcmd_read_monitor_v0 {
11259 +       uint32_t index;
11260 +       uint32_t count;
11261 +       char __user *data;
11262 +};
11263 +
11264 +
11265 +#ifdef __KERNEL__
11266 +
11267 +#ifdef CONFIG_COMPAT
11268 +
11269 +#include <asm/compat.h>
11270 +
11271 +struct vcmd_read_history_v0_x32 {
11272 +       uint32_t index;
11273 +       uint32_t count;
11274 +       compat_uptr_t data_ptr;
11275 +};
11276 +
11277 +struct vcmd_read_monitor_v0_x32 {
11278 +       uint32_t index;
11279 +       uint32_t count;
11280 +       compat_uptr_t data_ptr;
11281 +};
11282 +
11283 +#endif  /* CONFIG_COMPAT */
11284 +
11285 +extern int vc_dump_history(uint32_t);
11286 +
11287 +extern int vc_read_history(uint32_t, void __user *);
11288 +extern int vc_read_monitor(uint32_t, void __user *);
11289 +
11290 +#ifdef CONFIG_COMPAT
11291 +
11292 +extern int vc_read_history_x32(uint32_t, void __user *);
11293 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11294 +
11295 +#endif  /* CONFIG_COMPAT */
11296 +
11297 +#endif /* __KERNEL__ */
11298 +#endif /* _VX_DEBUG_CMD_H */
11299 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/debug.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/debug.h
11300 --- linux-2.6.27.10/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
11301 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/debug.h  2008-10-13 14:54:20.000000000 +0200
11302 @@ -0,0 +1,127 @@
11303 +#ifndef _VX_DEBUG_H
11304 +#define _VX_DEBUG_H
11305 +
11306 +
11307 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11308 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11309 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11310 +
11311 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11312 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11313 +#define VXF_DEV                "%p[%lu,%d:%d]"
11314 +
11315 +
11316 +#define vxd_path(p)                                            \
11317 +       ({ static char _buffer[PATH_MAX];                       \
11318 +          d_path(p, _buffer, sizeof(_buffer)); })
11319 +
11320 +#define vxd_cond_path(n)                                       \
11321 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11322 +
11323 +
11324 +#ifdef CONFIG_VSERVER_DEBUG
11325 +
11326 +extern unsigned int vx_debug_switch;
11327 +extern unsigned int vx_debug_xid;
11328 +extern unsigned int vx_debug_nid;
11329 +extern unsigned int vx_debug_tag;
11330 +extern unsigned int vx_debug_net;
11331 +extern unsigned int vx_debug_limit;
11332 +extern unsigned int vx_debug_cres;
11333 +extern unsigned int vx_debug_dlim;
11334 +extern unsigned int vx_debug_quota;
11335 +extern unsigned int vx_debug_cvirt;
11336 +extern unsigned int vx_debug_space;
11337 +extern unsigned int vx_debug_misc;
11338 +
11339 +
11340 +#define VX_LOGLEVEL    "vxD: "
11341 +#define VX_PROC_FMT    "%p: "
11342 +#define VX_PROCESS     current
11343 +
11344 +#define vxdprintk(c, f, x...)                                  \
11345 +       do {                                                    \
11346 +               if (c)                                          \
11347 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11348 +                               VX_PROCESS , ##x);              \
11349 +       } while (0)
11350 +
11351 +#define vxlprintk(c, f, x...)                                  \
11352 +       do {                                                    \
11353 +               if (c)                                          \
11354 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11355 +       } while (0)
11356 +
11357 +#define vxfprintk(c, f, x...)                                  \
11358 +       do {                                                    \
11359 +               if (c)                                          \
11360 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11361 +       } while (0)
11362 +
11363 +
11364 +struct vx_info;
11365 +
11366 +void dump_vx_info(struct vx_info *, int);
11367 +void dump_vx_info_inactive(int);
11368 +
11369 +#else  /* CONFIG_VSERVER_DEBUG */
11370 +
11371 +#define vx_debug_switch 0
11372 +#define vx_debug_xid   0
11373 +#define vx_debug_nid   0
11374 +#define vx_debug_tag   0
11375 +#define vx_debug_net   0
11376 +#define vx_debug_limit 0
11377 +#define vx_debug_cres  0
11378 +#define vx_debug_dlim  0
11379 +#define vx_debug_cvirt 0
11380 +
11381 +#define vxdprintk(x...) do { } while (0)
11382 +#define vxlprintk(x...) do { } while (0)
11383 +#define vxfprintk(x...) do { } while (0)
11384 +
11385 +#endif /* CONFIG_VSERVER_DEBUG */
11386 +
11387 +
11388 +#ifdef CONFIG_VSERVER_WARN
11389 +
11390 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11391 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11392 +#define VX_WARN_XID    "[xid #%u] "
11393 +#define VX_WARN_NID    "[nid #%u] "
11394 +#define VX_WARN_TAG    "[tag #%u] "
11395 +
11396 +#define vxwprintk(c, f, x...)                                  \
11397 +       do {                                                    \
11398 +               if (c)                                          \
11399 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11400 +       } while (0)
11401 +
11402 +#else  /* CONFIG_VSERVER_WARN */
11403 +
11404 +#define vxwprintk(x...) do { } while (0)
11405 +
11406 +#endif /* CONFIG_VSERVER_WARN */
11407 +
11408 +#define vxwprintk_task(c, f, x...)                             \
11409 +       vxwprintk(c, VX_WARN_TASK f,                            \
11410 +               current->comm, current->pid,                    \
11411 +               current->xid, current->nid, current->tag, ##x)
11412 +#define vxwprintk_xid(c, f, x...)                              \
11413 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11414 +#define vxwprintk_nid(c, f, x...)                              \
11415 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11416 +#define vxwprintk_tag(c, f, x...)                              \
11417 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11418 +
11419 +#ifdef CONFIG_VSERVER_DEBUG
11420 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11421 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11422 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11423 +#else
11424 +#define vxd_assert_lock(l)     do { } while (0)
11425 +#define vxd_assert(c, f, x...) do { } while (0)
11426 +#endif
11427 +
11428 +
11429 +#endif /* _VX_DEBUG_H */
11430 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/device_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/device_cmd.h
11431 --- linux-2.6.27.10/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
11432 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/device_cmd.h     2008-10-13 14:54:20.000000000 +0200
11433 @@ -0,0 +1,44 @@
11434 +#ifndef _VX_DEVICE_CMD_H
11435 +#define _VX_DEVICE_CMD_H
11436 +
11437 +
11438 +/*  device vserver commands */
11439 +
11440 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11441 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11442 +
11443 +struct vcmd_set_mapping_v0 {
11444 +       const char __user *device;
11445 +       const char __user *target;
11446 +       uint32_t flags;
11447 +};
11448 +
11449 +
11450 +#ifdef __KERNEL__
11451 +
11452 +#ifdef CONFIG_COMPAT
11453 +
11454 +#include <asm/compat.h>
11455 +
11456 +struct vcmd_set_mapping_v0_x32 {
11457 +       compat_uptr_t device_ptr;
11458 +       compat_uptr_t target_ptr;
11459 +       uint32_t flags;
11460 +};
11461 +
11462 +#endif /* CONFIG_COMPAT */
11463 +
11464 +#include <linux/compiler.h>
11465 +
11466 +extern int vc_set_mapping(struct vx_info *, void __user *);
11467 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11468 +
11469 +#ifdef CONFIG_COMPAT
11470 +
11471 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11472 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11473 +
11474 +#endif /* CONFIG_COMPAT */
11475 +
11476 +#endif /* __KERNEL__ */
11477 +#endif /* _VX_DEVICE_CMD_H */
11478 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/device_def.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/device_def.h
11479 --- linux-2.6.27.10/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
11480 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/device_def.h     2008-10-13 14:54:20.000000000 +0200
11481 @@ -0,0 +1,17 @@
11482 +#ifndef _VX_DEVICE_DEF_H
11483 +#define _VX_DEVICE_DEF_H
11484 +
11485 +#include <linux/types.h>
11486 +
11487 +struct vx_dmap_target {
11488 +       dev_t target;
11489 +       uint32_t flags;
11490 +};
11491 +
11492 +struct _vx_device {
11493 +#ifdef CONFIG_VSERVER_DEVICE
11494 +       struct vx_dmap_target targets[2];
11495 +#endif
11496 +};
11497 +
11498 +#endif /* _VX_DEVICE_DEF_H */
11499 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/device.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/device.h
11500 --- linux-2.6.27.10/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
11501 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/device.h 2008-10-13 14:54:20.000000000 +0200
11502 @@ -0,0 +1,15 @@
11503 +#ifndef _VX_DEVICE_H
11504 +#define _VX_DEVICE_H
11505 +
11506 +
11507 +#define DATTR_CREATE   0x00000001
11508 +#define DATTR_OPEN     0x00000002
11509 +
11510 +#define DATTR_REMAP    0x00000010
11511 +
11512 +#define DATTR_MASK     0x00000013
11513 +
11514 +
11515 +#else  /* _VX_DEVICE_H */
11516 +#warning duplicate inclusion
11517 +#endif /* _VX_DEVICE_H */
11518 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/dlimit_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/dlimit_cmd.h
11519 --- linux-2.6.27.10/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
11520 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/dlimit_cmd.h     2008-10-13 14:54:20.000000000 +0200
11521 @@ -0,0 +1,74 @@
11522 +#ifndef _VX_DLIMIT_CMD_H
11523 +#define _VX_DLIMIT_CMD_H
11524 +
11525 +
11526 +/*  dlimit vserver commands */
11527 +
11528 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11529 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11530 +
11531 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11532 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11533 +
11534 +struct vcmd_ctx_dlimit_base_v0 {
11535 +       const char __user *name;
11536 +       uint32_t flags;
11537 +};
11538 +
11539 +struct vcmd_ctx_dlimit_v0 {
11540 +       const char __user *name;
11541 +       uint32_t space_used;                    /* used space in kbytes */
11542 +       uint32_t space_total;                   /* maximum space in kbytes */
11543 +       uint32_t inodes_used;                   /* used inodes */
11544 +       uint32_t inodes_total;                  /* maximum inodes */
11545 +       uint32_t reserved;                      /* reserved for root in % */
11546 +       uint32_t flags;
11547 +};
11548 +
11549 +#define CDLIM_UNSET            ((uint32_t)0UL)
11550 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11551 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11552 +
11553 +#ifdef __KERNEL__
11554 +
11555 +#ifdef CONFIG_COMPAT
11556 +
11557 +#include <asm/compat.h>
11558 +
11559 +struct vcmd_ctx_dlimit_base_v0_x32 {
11560 +       compat_uptr_t name_ptr;
11561 +       uint32_t flags;
11562 +};
11563 +
11564 +struct vcmd_ctx_dlimit_v0_x32 {
11565 +       compat_uptr_t name_ptr;
11566 +       uint32_t space_used;                    /* used space in kbytes */
11567 +       uint32_t space_total;                   /* maximum space in kbytes */
11568 +       uint32_t inodes_used;                   /* used inodes */
11569 +       uint32_t inodes_total;                  /* maximum inodes */
11570 +       uint32_t reserved;                      /* reserved for root in % */
11571 +       uint32_t flags;
11572 +};
11573 +
11574 +#endif /* CONFIG_COMPAT */
11575 +
11576 +#include <linux/compiler.h>
11577 +
11578 +extern int vc_add_dlimit(uint32_t, void __user *);
11579 +extern int vc_rem_dlimit(uint32_t, void __user *);
11580 +
11581 +extern int vc_set_dlimit(uint32_t, void __user *);
11582 +extern int vc_get_dlimit(uint32_t, void __user *);
11583 +
11584 +#ifdef CONFIG_COMPAT
11585 +
11586 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11587 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11588 +
11589 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11590 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11591 +
11592 +#endif /* CONFIG_COMPAT */
11593 +
11594 +#endif /* __KERNEL__ */
11595 +#endif /* _VX_DLIMIT_CMD_H */
11596 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/dlimit.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/dlimit.h
11597 --- linux-2.6.27.10/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
11598 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/dlimit.h 2008-10-13 14:54:20.000000000 +0200
11599 @@ -0,0 +1,54 @@
11600 +#ifndef _VX_DLIMIT_H
11601 +#define _VX_DLIMIT_H
11602 +
11603 +#include "switch.h"
11604 +
11605 +
11606 +#ifdef __KERNEL__
11607 +
11608 +/*      keep in sync with CDLIM_INFINITY       */
11609 +
11610 +#define DLIM_INFINITY          (~0ULL)
11611 +
11612 +#include <linux/spinlock.h>
11613 +#include <linux/rcupdate.h>
11614 +
11615 +struct super_block;
11616 +
11617 +struct dl_info {
11618 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11619 +       struct rcu_head dl_rcu;                 /* the rcu head */
11620 +       tag_t dl_tag;                           /* context tag */
11621 +       atomic_t dl_usecnt;                     /* usage count */
11622 +       atomic_t dl_refcnt;                     /* reference count */
11623 +
11624 +       struct super_block *dl_sb;              /* associated superblock */
11625 +
11626 +       spinlock_t dl_lock;                     /* protect the values */
11627 +
11628 +       unsigned long long dl_space_used;       /* used space in bytes */
11629 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11630 +       unsigned long dl_inodes_used;           /* used inodes */
11631 +       unsigned long dl_inodes_total;          /* maximum inodes */
11632 +
11633 +       unsigned int dl_nrlmult;                /* non root limit mult */
11634 +};
11635 +
11636 +struct rcu_head;
11637 +
11638 +extern void rcu_free_dl_info(struct rcu_head *);
11639 +extern void unhash_dl_info(struct dl_info *);
11640 +
11641 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11642 +
11643 +
11644 +struct kstatfs;
11645 +
11646 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11647 +
11648 +typedef uint64_t dlsize_t;
11649 +
11650 +#endif /* __KERNEL__ */
11651 +#else  /* _VX_DLIMIT_H */
11652 +#warning duplicate inclusion
11653 +#endif /* _VX_DLIMIT_H */
11654 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/global.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/global.h
11655 --- linux-2.6.27.10/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
11656 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/global.h 2008-10-13 14:54:20.000000000 +0200
11657 @@ -0,0 +1,20 @@
11658 +#ifndef _VX_GLOBAL_H
11659 +#define _VX_GLOBAL_H
11660 +
11661 +
11662 +extern atomic_t vx_global_ctotal;
11663 +extern atomic_t vx_global_cactive;
11664 +
11665 +extern atomic_t nx_global_ctotal;
11666 +extern atomic_t nx_global_cactive;
11667 +
11668 +extern atomic_t vs_global_nsproxy;
11669 +extern atomic_t vs_global_fs;
11670 +extern atomic_t vs_global_mnt_ns;
11671 +extern atomic_t vs_global_uts_ns;
11672 +extern atomic_t vs_global_ipc_ns;
11673 +extern atomic_t vs_global_user_ns;
11674 +extern atomic_t vs_global_pid_ns;
11675 +
11676 +
11677 +#endif /* _VX_GLOBAL_H */
11678 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/history.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/history.h
11679 --- linux-2.6.27.10/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
11680 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/history.h        2008-10-13 14:54:20.000000000 +0200
11681 @@ -0,0 +1,197 @@
11682 +#ifndef _VX_HISTORY_H
11683 +#define _VX_HISTORY_H
11684 +
11685 +
11686 +enum {
11687 +       VXH_UNUSED = 0,
11688 +       VXH_THROW_OOPS = 1,
11689 +
11690 +       VXH_GET_VX_INFO,
11691 +       VXH_PUT_VX_INFO,
11692 +       VXH_INIT_VX_INFO,
11693 +       VXH_SET_VX_INFO,
11694 +       VXH_CLR_VX_INFO,
11695 +       VXH_CLAIM_VX_INFO,
11696 +       VXH_RELEASE_VX_INFO,
11697 +       VXH_ALLOC_VX_INFO,
11698 +       VXH_DEALLOC_VX_INFO,
11699 +       VXH_HASH_VX_INFO,
11700 +       VXH_UNHASH_VX_INFO,
11701 +       VXH_LOC_VX_INFO,
11702 +       VXH_LOOKUP_VX_INFO,
11703 +       VXH_CREATE_VX_INFO,
11704 +};
11705 +
11706 +struct _vxhe_vxi {
11707 +       struct vx_info *ptr;
11708 +       unsigned xid;
11709 +       unsigned usecnt;
11710 +       unsigned tasks;
11711 +};
11712 +
11713 +struct _vxhe_set_clr {
11714 +       void *data;
11715 +};
11716 +
11717 +struct _vxhe_loc_lookup {
11718 +       unsigned arg;
11719 +};
11720 +
11721 +struct _vx_hist_entry {
11722 +       void *loc;
11723 +       unsigned short seq;
11724 +       unsigned short type;
11725 +       struct _vxhe_vxi vxi;
11726 +       union {
11727 +               struct _vxhe_set_clr sc;
11728 +               struct _vxhe_loc_lookup ll;
11729 +       };
11730 +};
11731 +
11732 +#ifdef CONFIG_VSERVER_HISTORY
11733 +
11734 +extern unsigned volatile int vxh_active;
11735 +
11736 +struct _vx_hist_entry *vxh_advance(void *loc);
11737 +
11738 +
11739 +static inline
11740 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11741 +{
11742 +       entry->vxi.ptr = vxi;
11743 +       if (vxi) {
11744 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11745 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11746 +               entry->vxi.xid = vxi->vx_id;
11747 +       }
11748 +}
11749 +
11750 +
11751 +#define        __HERE__ current_text_addr()
11752 +
11753 +#define __VXH_BODY(__type, __data, __here)     \
11754 +       struct _vx_hist_entry *entry;           \
11755 +                                               \
11756 +       preempt_disable();                      \
11757 +       entry = vxh_advance(__here);            \
11758 +       __data;                                 \
11759 +       entry->type = __type;                   \
11760 +       preempt_enable();
11761 +
11762 +
11763 +       /* pass vxi only */
11764 +
11765 +#define __VXH_SMPL                             \
11766 +       __vxh_copy_vxi(entry, vxi)
11767 +
11768 +static inline
11769 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11770 +{
11771 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11772 +}
11773 +
11774 +       /* pass vxi and data (void *) */
11775 +
11776 +#define __VXH_DATA                             \
11777 +       __vxh_copy_vxi(entry, vxi);             \
11778 +       entry->sc.data = data
11779 +
11780 +static inline
11781 +void   __vxh_data(struct vx_info *vxi, void *data,
11782 +                       int __type, void *__here)
11783 +{
11784 +       __VXH_BODY(__type, __VXH_DATA, __here)
11785 +}
11786 +
11787 +       /* pass vxi and arg (long) */
11788 +
11789 +#define __VXH_LONG                             \
11790 +       __vxh_copy_vxi(entry, vxi);             \
11791 +       entry->ll.arg = arg
11792 +
11793 +static inline
11794 +void   __vxh_long(struct vx_info *vxi, long arg,
11795 +                       int __type, void *__here)
11796 +{
11797 +       __VXH_BODY(__type, __VXH_LONG, __here)
11798 +}
11799 +
11800 +
11801 +static inline
11802 +void   __vxh_throw_oops(void *__here)
11803 +{
11804 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11805 +       /* prevent further acquisition */
11806 +       vxh_active = 0;
11807 +}
11808 +
11809 +
11810 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11811 +
11812 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11813 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11814 +
11815 +#define __vxh_init_vx_info(v, d, h) \
11816 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11817 +#define __vxh_set_vx_info(v, d, h) \
11818 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11819 +#define __vxh_clr_vx_info(v, d, h) \
11820 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11821 +
11822 +#define __vxh_claim_vx_info(v, d, h) \
11823 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11824 +#define __vxh_release_vx_info(v, d, h) \
11825 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11826 +
11827 +#define vxh_alloc_vx_info(v) \
11828 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11829 +#define vxh_dealloc_vx_info(v) \
11830 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11831 +
11832 +#define vxh_hash_vx_info(v) \
11833 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11834 +#define vxh_unhash_vx_info(v) \
11835 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11836 +
11837 +#define vxh_loc_vx_info(v, l) \
11838 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11839 +#define vxh_lookup_vx_info(v, l) \
11840 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11841 +#define vxh_create_vx_info(v, l) \
11842 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11843 +
11844 +extern void vxh_dump_history(void);
11845 +
11846 +
11847 +#else  /* CONFIG_VSERVER_HISTORY */
11848 +
11849 +#define        __HERE__        0
11850 +
11851 +#define vxh_throw_oops()               do { } while (0)
11852 +
11853 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11854 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11855 +
11856 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11857 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11858 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11859 +
11860 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11861 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11862 +
11863 +#define vxh_alloc_vx_info(v)           do { } while (0)
11864 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11865 +
11866 +#define vxh_hash_vx_info(v)            do { } while (0)
11867 +#define vxh_unhash_vx_info(v)          do { } while (0)
11868 +
11869 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11870 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11871 +#define vxh_create_vx_info(v, l)       do { } while (0)
11872 +
11873 +#define vxh_dump_history()             do { } while (0)
11874 +
11875 +
11876 +#endif /* CONFIG_VSERVER_HISTORY */
11877 +
11878 +#endif /* _VX_HISTORY_H */
11879 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/inode_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/inode_cmd.h
11880 --- linux-2.6.27.10/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
11881 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/inode_cmd.h      2008-10-13 14:54:20.000000000 +0200
11882 @@ -0,0 +1,59 @@
11883 +#ifndef _VX_INODE_CMD_H
11884 +#define _VX_INODE_CMD_H
11885 +
11886 +
11887 +/*  inode vserver commands */
11888 +
11889 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11890 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11891 +
11892 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11893 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11894 +
11895 +struct vcmd_ctx_iattr_v1 {
11896 +       const char __user *name;
11897 +       uint32_t tag;
11898 +       uint32_t flags;
11899 +       uint32_t mask;
11900 +};
11901 +
11902 +struct vcmd_ctx_fiattr_v0 {
11903 +       uint32_t tag;
11904 +       uint32_t flags;
11905 +       uint32_t mask;
11906 +};
11907 +
11908 +
11909 +#ifdef __KERNEL__
11910 +
11911 +
11912 +#ifdef CONFIG_COMPAT
11913 +
11914 +#include <asm/compat.h>
11915 +
11916 +struct vcmd_ctx_iattr_v1_x32 {
11917 +       compat_uptr_t name_ptr;
11918 +       uint32_t tag;
11919 +       uint32_t flags;
11920 +       uint32_t mask;
11921 +};
11922 +
11923 +#endif /* CONFIG_COMPAT */
11924 +
11925 +#include <linux/compiler.h>
11926 +
11927 +extern int vc_get_iattr(void __user *);
11928 +extern int vc_set_iattr(void __user *);
11929 +
11930 +extern int vc_fget_iattr(uint32_t, void __user *);
11931 +extern int vc_fset_iattr(uint32_t, void __user *);
11932 +
11933 +#ifdef CONFIG_COMPAT
11934 +
11935 +extern int vc_get_iattr_x32(void __user *);
11936 +extern int vc_set_iattr_x32(void __user *);
11937 +
11938 +#endif /* CONFIG_COMPAT */
11939 +
11940 +#endif /* __KERNEL__ */
11941 +#endif /* _VX_INODE_CMD_H */
11942 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/inode.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/inode.h
11943 --- linux-2.6.27.10/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
11944 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/inode.h  2008-10-13 14:54:20.000000000 +0200
11945 @@ -0,0 +1,38 @@
11946 +#ifndef _VX_INODE_H
11947 +#define _VX_INODE_H
11948 +
11949 +
11950 +#define IATTR_TAG      0x01000000
11951 +
11952 +#define IATTR_ADMIN    0x00000001
11953 +#define IATTR_WATCH    0x00000002
11954 +#define IATTR_HIDE     0x00000004
11955 +#define IATTR_FLAGS    0x00000007
11956 +
11957 +#define IATTR_BARRIER  0x00010000
11958 +#define IATTR_IXUNLINK 0x00020000
11959 +#define IATTR_IMMUTABLE 0x00040000
11960 +
11961 +#ifdef __KERNEL__
11962 +
11963 +
11964 +#ifdef CONFIG_VSERVER_PROC_SECURE
11965 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11966 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11967 +#else
11968 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11969 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11970 +#endif
11971 +
11972 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11973 +
11974 +#endif /* __KERNEL__ */
11975 +
11976 +/* inode ioctls */
11977 +
11978 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11979 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11980 +
11981 +#else  /* _VX_INODE_H */
11982 +#warning duplicate inclusion
11983 +#endif /* _VX_INODE_H */
11984 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/Kbuild linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/Kbuild
11985 --- linux-2.6.27.10/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
11986 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/Kbuild   2008-10-13 14:54:20.000000000 +0200
11987 @@ -0,0 +1,8 @@
11988 +
11989 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11990 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11991 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11992 +       debug_cmd.h device_cmd.h
11993 +
11994 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11995 +
11996 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/limit_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit_cmd.h
11997 --- linux-2.6.27.10/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11998 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit_cmd.h      2009-01-04 02:28:31.000000000 +0100
11999 @@ -0,0 +1,69 @@
12000 +#ifndef _VX_LIMIT_CMD_H
12001 +#define _VX_LIMIT_CMD_H
12002 +
12003 +
12004 +/*  rlimit vserver commands */
12005 +
12006 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12007 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12008 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12009 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12010 +
12011 +struct vcmd_ctx_rlimit_v0 {
12012 +       uint32_t id;
12013 +       uint64_t minimum;
12014 +       uint64_t softlimit;
12015 +       uint64_t maximum;
12016 +};
12017 +
12018 +struct vcmd_ctx_rlimit_mask_v0 {
12019 +       uint32_t minimum;
12020 +       uint32_t softlimit;
12021 +       uint32_t maximum;
12022 +};
12023 +
12024 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12025 +
12026 +struct vcmd_rlimit_stat_v0 {
12027 +       uint32_t id;
12028 +       uint32_t hits;
12029 +       uint64_t value;
12030 +       uint64_t minimum;
12031 +       uint64_t maximum;
12032 +};
12033 +
12034 +#define CRLIM_UNSET            (0ULL)
12035 +#define CRLIM_INFINITY         (~0ULL)
12036 +#define CRLIM_KEEP             (~1ULL)
12037 +
12038 +#ifdef __KERNEL__
12039 +
12040 +#ifdef CONFIG_IA32_EMULATION
12041 +
12042 +struct vcmd_ctx_rlimit_v0_x32 {
12043 +       uint32_t id;
12044 +       uint64_t minimum;
12045 +       uint64_t softlimit;
12046 +       uint64_t maximum;
12047 +} __attribute__ ((packed));
12048 +
12049 +#endif /* CONFIG_IA32_EMULATION */
12050 +
12051 +#include <linux/compiler.h>
12052 +
12053 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12054 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12055 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12056 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12057 +
12058 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12059 +
12060 +#ifdef CONFIG_IA32_EMULATION
12061 +
12062 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12063 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12064 +
12065 +#endif /* CONFIG_IA32_EMULATION */
12066 +
12067 +#endif /* __KERNEL__ */
12068 +#endif /* _VX_LIMIT_CMD_H */
12069 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/limit_def.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit_def.h
12070 --- linux-2.6.27.10/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
12071 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit_def.h      2008-10-13 14:54:20.000000000 +0200
12072 @@ -0,0 +1,47 @@
12073 +#ifndef _VX_LIMIT_DEF_H
12074 +#define _VX_LIMIT_DEF_H
12075 +
12076 +#include <asm/atomic.h>
12077 +#include <asm/resource.h>
12078 +
12079 +#include "limit.h"
12080 +
12081 +
12082 +struct _vx_res_limit {
12083 +       rlim_t soft;            /* Context soft limit */
12084 +       rlim_t hard;            /* Context hard limit */
12085 +
12086 +       rlim_atomic_t rcur;     /* Current value */
12087 +       rlim_t rmin;            /* Context minimum */
12088 +       rlim_t rmax;            /* Context maximum */
12089 +
12090 +       atomic_t lhit;          /* Limit hits */
12091 +};
12092 +
12093 +/* context sub struct */
12094 +
12095 +struct _vx_limit {
12096 +       struct _vx_res_limit res[NUM_LIMITS];
12097 +};
12098 +
12099 +#ifdef CONFIG_VSERVER_DEBUG
12100 +
12101 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12102 +{
12103 +       int i;
12104 +
12105 +       printk("\t_vx_limit:");
12106 +       for (i = 0; i < NUM_LIMITS; i++) {
12107 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12108 +                       i, (unsigned long)__rlim_get(limit, i),
12109 +                       (unsigned long)__rlim_rmin(limit, i),
12110 +                       (unsigned long)__rlim_rmax(limit, i),
12111 +                       (long)__rlim_soft(limit, i),
12112 +                       (long)__rlim_hard(limit, i),
12113 +                       atomic_read(&__rlim_lhit(limit, i)));
12114 +       }
12115 +}
12116 +
12117 +#endif
12118 +
12119 +#endif /* _VX_LIMIT_DEF_H */
12120 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/limit.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit.h
12121 --- linux-2.6.27.10/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
12122 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit.h  2008-10-13 14:54:20.000000000 +0200
12123 @@ -0,0 +1,70 @@
12124 +#ifndef _VX_LIMIT_H
12125 +#define _VX_LIMIT_H
12126 +
12127 +#define VLIMIT_NSOCK   16
12128 +#define VLIMIT_OPENFD  17
12129 +#define VLIMIT_ANON    18
12130 +#define VLIMIT_SHMEM   19
12131 +#define VLIMIT_SEMARY  20
12132 +#define VLIMIT_NSEMS   21
12133 +#define VLIMIT_DENTRY  22
12134 +#define VLIMIT_MAPPED  23
12135 +
12136 +
12137 +#ifdef __KERNEL__
12138 +
12139 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12140 +
12141 +/*     keep in sync with CRLIM_INFINITY */
12142 +
12143 +#define        VLIM_INFINITY   (~0ULL)
12144 +
12145 +#include <asm/atomic.h>
12146 +#include <asm/resource.h>
12147 +
12148 +#ifndef RLIM_INFINITY
12149 +#warning RLIM_INFINITY is undefined
12150 +#endif
12151 +
12152 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12153 +
12154 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12155 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12156 +
12157 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12158 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12159 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12160 +
12161 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12162 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12163 +
12164 +typedef atomic_long_t rlim_atomic_t;
12165 +typedef unsigned long rlim_t;
12166 +
12167 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12168 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12169 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12170 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12171 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12172 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12173 +
12174 +
12175 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12176 +#define        VX_VLIM(r) ((long long)(long)(r))
12177 +#define        VX_RLIM(v) ((rlim_t)(v))
12178 +#else
12179 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12180 +               ? VLIM_INFINITY : (long long)(r))
12181 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12182 +               ? RLIM_INFINITY : (rlim_t)(v))
12183 +#endif
12184 +
12185 +struct sysinfo;
12186 +
12187 +void vx_vsi_meminfo(struct sysinfo *);
12188 +void vx_vsi_swapinfo(struct sysinfo *);
12189 +
12190 +#define NUM_LIMITS     24
12191 +
12192 +#endif /* __KERNEL__ */
12193 +#endif /* _VX_LIMIT_H */
12194 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/limit_int.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit_int.h
12195 --- linux-2.6.27.10/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
12196 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/limit_int.h      2008-10-13 14:54:20.000000000 +0200
12197 @@ -0,0 +1,198 @@
12198 +#ifndef _VX_LIMIT_INT_H
12199 +#define _VX_LIMIT_INT_H
12200 +
12201 +#include "context.h"
12202 +
12203 +#ifdef __KERNEL__
12204 +
12205 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12206 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12207 +
12208 +extern const char *vlimit_name[NUM_LIMITS];
12209 +
12210 +static inline void __vx_acc_cres(struct vx_info *vxi,
12211 +       int res, int dir, void *_data, char *_file, int _line)
12212 +{
12213 +       if (VXD_RCRES_COND(res))
12214 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12215 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12216 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12217 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12218 +       if (!vxi)
12219 +               return;
12220 +
12221 +       if (dir > 0)
12222 +               __rlim_inc(&vxi->limit, res);
12223 +       else
12224 +               __rlim_dec(&vxi->limit, res);
12225 +}
12226 +
12227 +static inline void __vx_add_cres(struct vx_info *vxi,
12228 +       int res, int amount, void *_data, char *_file, int _line)
12229 +{
12230 +       if (VXD_RCRES_COND(res))
12231 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12232 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12233 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12234 +                       amount, _data, _file, _line);
12235 +       if (amount == 0)
12236 +               return;
12237 +       if (!vxi)
12238 +               return;
12239 +       __rlim_add(&vxi->limit, res, amount);
12240 +}
12241 +
12242 +static inline
12243 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12244 +{
12245 +       int cond = (value > __rlim_rmax(limit, res));
12246 +
12247 +       if (cond)
12248 +               __rlim_rmax(limit, res) = value;
12249 +       return cond;
12250 +}
12251 +
12252 +static inline
12253 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12254 +{
12255 +       int cond = (value < __rlim_rmin(limit, res));
12256 +
12257 +       if (cond)
12258 +               __rlim_rmin(limit, res) = value;
12259 +       return cond;
12260 +}
12261 +
12262 +static inline
12263 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12264 +{
12265 +       if (!__vx_cres_adjust_max(limit, res, value))
12266 +               __vx_cres_adjust_min(limit, res, value);
12267 +}
12268 +
12269 +
12270 +/*     return values:
12271 +        +1 ... no limit hit
12272 +        -1 ... over soft limit
12273 +         0 ... over hard limit         */
12274 +
12275 +static inline int __vx_cres_avail(struct vx_info *vxi,
12276 +       int res, int num, char *_file, int _line)
12277 +{
12278 +       struct _vx_limit *limit;
12279 +       rlim_t value;
12280 +
12281 +       if (VXD_RLIMIT_COND(res))
12282 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12283 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12284 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12285 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12286 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12287 +                       num, _file, _line);
12288 +       if (!vxi)
12289 +               return 1;
12290 +
12291 +       limit = &vxi->limit;
12292 +       value = __rlim_get(limit, res);
12293 +
12294 +       if (!__vx_cres_adjust_max(limit, res, value))
12295 +               __vx_cres_adjust_min(limit, res, value);
12296 +
12297 +       if (num == 0)
12298 +               return 1;
12299 +
12300 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12301 +               return -1;
12302 +       if (value + num <= __rlim_soft(limit, res))
12303 +               return -1;
12304 +
12305 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12306 +               return 1;
12307 +       if (value + num <= __rlim_hard(limit, res))
12308 +               return 1;
12309 +
12310 +       __rlim_hit(limit, res);
12311 +       return 0;
12312 +}
12313 +
12314 +
12315 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12316 +
12317 +static inline
12318 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12319 +{
12320 +       rlim_t value, sum = 0;
12321 +       int res;
12322 +
12323 +       while ((res = *array++)) {
12324 +               value = __rlim_get(limit, res);
12325 +               __vx_cres_fixup(limit, res, value);
12326 +               sum += value;
12327 +       }
12328 +       return sum;
12329 +}
12330 +
12331 +static inline
12332 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12333 +{
12334 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12335 +       int res = *array;
12336 +
12337 +       if (value == __rlim_get(limit, res))
12338 +               return value;
12339 +
12340 +       __rlim_set(limit, res, value);
12341 +       /* now adjust min/max */
12342 +       if (!__vx_cres_adjust_max(limit, res, value))
12343 +               __vx_cres_adjust_min(limit, res, value);
12344 +
12345 +       return value;
12346 +}
12347 +
12348 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12349 +       const int *array, int num, char *_file, int _line)
12350 +{
12351 +       struct _vx_limit *limit;
12352 +       rlim_t value = 0;
12353 +       int res;
12354 +
12355 +       if (num == 0)
12356 +               return 1;
12357 +       if (!vxi)
12358 +               return 1;
12359 +
12360 +       limit = &vxi->limit;
12361 +       res = *array;
12362 +       value = __vx_cres_array_sum(limit, array + 1);
12363 +
12364 +       __rlim_set(limit, res, value);
12365 +       __vx_cres_fixup(limit, res, value);
12366 +
12367 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12368 +}
12369 +
12370 +
12371 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12372 +{
12373 +       rlim_t value;
12374 +       int res;
12375 +
12376 +       /* complex resources first */
12377 +       if ((id < 0) || (id == RLIMIT_RSS))
12378 +               __vx_cres_array_fixup(limit, VLA_RSS);
12379 +
12380 +       for (res = 0; res < NUM_LIMITS; res++) {
12381 +               if ((id > 0) && (res != id))
12382 +                       continue;
12383 +
12384 +               value = __rlim_get(limit, res);
12385 +               __vx_cres_fixup(limit, res, value);
12386 +
12387 +               /* not supposed to happen, maybe warn? */
12388 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12389 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12390 +       }
12391 +}
12392 +
12393 +
12394 +#endif /* __KERNEL__ */
12395 +#endif /* _VX_LIMIT_INT_H */
12396 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/monitor.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/monitor.h
12397 --- linux-2.6.27.10/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
12398 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/monitor.h        2008-10-13 14:54:20.000000000 +0200
12399 @@ -0,0 +1,96 @@
12400 +#ifndef _VX_MONITOR_H
12401 +#define _VX_MONITOR_H
12402 +
12403 +#include <linux/types.h>
12404 +
12405 +enum {
12406 +       VXM_UNUSED = 0,
12407 +
12408 +       VXM_SYNC = 0x10,
12409 +
12410 +       VXM_UPDATE = 0x20,
12411 +       VXM_UPDATE_1,
12412 +       VXM_UPDATE_2,
12413 +
12414 +       VXM_RQINFO_1 = 0x24,
12415 +       VXM_RQINFO_2,
12416 +
12417 +       VXM_ACTIVATE = 0x40,
12418 +       VXM_DEACTIVATE,
12419 +       VXM_IDLE,
12420 +
12421 +       VXM_HOLD = 0x44,
12422 +       VXM_UNHOLD,
12423 +
12424 +       VXM_MIGRATE = 0x48,
12425 +       VXM_RESCHED,
12426 +
12427 +       /* all other bits are flags */
12428 +       VXM_SCHED = 0x80,
12429 +};
12430 +
12431 +struct _vxm_update_1 {
12432 +       uint32_t tokens_max;
12433 +       uint32_t fill_rate;
12434 +       uint32_t interval;
12435 +};
12436 +
12437 +struct _vxm_update_2 {
12438 +       uint32_t tokens_min;
12439 +       uint32_t fill_rate;
12440 +       uint32_t interval;
12441 +};
12442 +
12443 +struct _vxm_rqinfo_1 {
12444 +       uint16_t running;
12445 +       uint16_t onhold;
12446 +       uint16_t iowait;
12447 +       uint16_t uintr;
12448 +       uint32_t idle_tokens;
12449 +};
12450 +
12451 +struct _vxm_rqinfo_2 {
12452 +       uint32_t norm_time;
12453 +       uint32_t idle_time;
12454 +       uint32_t idle_skip;
12455 +};
12456 +
12457 +struct _vxm_sched {
12458 +       uint32_t tokens;
12459 +       uint32_t norm_time;
12460 +       uint32_t idle_time;
12461 +};
12462 +
12463 +struct _vxm_task {
12464 +       uint16_t pid;
12465 +       uint16_t state;
12466 +};
12467 +
12468 +struct _vxm_event {
12469 +       uint32_t jif;
12470 +       union {
12471 +               uint32_t seq;
12472 +               uint32_t sec;
12473 +       };
12474 +       union {
12475 +               uint32_t tokens;
12476 +               uint32_t nsec;
12477 +               struct _vxm_task tsk;
12478 +       };
12479 +};
12480 +
12481 +struct _vx_mon_entry {
12482 +       uint16_t type;
12483 +       uint16_t xid;
12484 +       union {
12485 +               struct _vxm_event ev;
12486 +               struct _vxm_sched sd;
12487 +               struct _vxm_update_1 u1;
12488 +               struct _vxm_update_2 u2;
12489 +               struct _vxm_rqinfo_1 q1;
12490 +               struct _vxm_rqinfo_2 q2;
12491 +       };
12492 +};
12493 +
12494 +
12495 +#endif /* _VX_MONITOR_H */
12496 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/network_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/network_cmd.h
12497 --- linux-2.6.27.10/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
12498 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/network_cmd.h    2008-10-13 14:54:20.000000000 +0200
12499 @@ -0,0 +1,150 @@
12500 +#ifndef _VX_NETWORK_CMD_H
12501 +#define _VX_NETWORK_CMD_H
12502 +
12503 +
12504 +/* vinfo commands */
12505 +
12506 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12507 +
12508 +#ifdef __KERNEL__
12509 +extern int vc_task_nid(uint32_t);
12510 +
12511 +#endif /* __KERNEL__ */
12512 +
12513 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12514 +
12515 +struct vcmd_nx_info_v0 {
12516 +       uint32_t nid;
12517 +       /* more to come */
12518 +};
12519 +
12520 +#ifdef __KERNEL__
12521 +extern int vc_nx_info(struct nx_info *, void __user *);
12522 +
12523 +#endif /* __KERNEL__ */
12524 +
12525 +#include <linux/in.h>
12526 +#include <linux/in6.h>
12527 +
12528 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12529 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12530 +
12531 +struct  vcmd_net_create {
12532 +       uint64_t flagword;
12533 +};
12534 +
12535 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12536 +
12537 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12538 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12539 +
12540 +struct vcmd_net_addr_v0 {
12541 +       uint16_t type;
12542 +       uint16_t count;
12543 +       struct in_addr ip[4];
12544 +       struct in_addr mask[4];
12545 +};
12546 +
12547 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12548 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12549 +
12550 +struct vcmd_net_addr_ipv4_v1 {
12551 +       uint16_t type;
12552 +       uint16_t flags;
12553 +       struct in_addr ip;
12554 +       struct in_addr mask;
12555 +};
12556 +
12557 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12558 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12559 +
12560 +struct vcmd_net_addr_ipv6_v1 {
12561 +       uint16_t type;
12562 +       uint16_t flags;
12563 +       uint32_t prefix;
12564 +       struct in6_addr ip;
12565 +       struct in6_addr mask;
12566 +};
12567 +
12568 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12569 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12570 +
12571 +struct vcmd_match_ipv4_v0 {
12572 +       uint16_t type;
12573 +       uint16_t flags;
12574 +       uint16_t parent;
12575 +       uint16_t prefix;
12576 +       struct in_addr ip;
12577 +       struct in_addr ip2;
12578 +       struct in_addr mask;
12579 +};
12580 +
12581 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12582 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12583 +
12584 +struct vcmd_match_ipv6_v0 {
12585 +       uint16_t type;
12586 +       uint16_t flags;
12587 +       uint16_t parent;
12588 +       uint16_t prefix;
12589 +       struct in6_addr ip;
12590 +       struct in6_addr ip2;
12591 +       struct in6_addr mask;
12592 +};
12593 +
12594 +
12595 +#ifdef __KERNEL__
12596 +extern int vc_net_create(uint32_t, void __user *);
12597 +extern int vc_net_migrate(struct nx_info *, void __user *);
12598 +
12599 +extern int vc_net_add(struct nx_info *, void __user *);
12600 +extern int vc_net_remove(struct nx_info *, void __user *);
12601 +
12602 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12603 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12604 +
12605 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12606 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12607 +
12608 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12609 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12610 +
12611 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12612 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12613 +
12614 +#endif /* __KERNEL__ */
12615 +
12616 +
12617 +/* flag commands */
12618 +
12619 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12620 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12621 +
12622 +struct vcmd_net_flags_v0 {
12623 +       uint64_t flagword;
12624 +       uint64_t mask;
12625 +};
12626 +
12627 +#ifdef __KERNEL__
12628 +extern int vc_get_nflags(struct nx_info *, void __user *);
12629 +extern int vc_set_nflags(struct nx_info *, void __user *);
12630 +
12631 +#endif /* __KERNEL__ */
12632 +
12633 +
12634 +/* network caps commands */
12635 +
12636 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12637 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12638 +
12639 +struct vcmd_net_caps_v0 {
12640 +       uint64_t ncaps;
12641 +       uint64_t cmask;
12642 +};
12643 +
12644 +#ifdef __KERNEL__
12645 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12646 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12647 +
12648 +#endif /* __KERNEL__ */
12649 +#endif /* _VX_CONTEXT_CMD_H */
12650 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/network.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/network.h
12651 --- linux-2.6.27.10/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
12652 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/network.h        2008-10-13 14:54:20.000000000 +0200
12653 @@ -0,0 +1,146 @@
12654 +#ifndef _VX_NETWORK_H
12655 +#define _VX_NETWORK_H
12656 +
12657 +#include <linux/types.h>
12658 +
12659 +
12660 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12661 +
12662 +
12663 +/* network flags */
12664 +
12665 +#define NXF_INFO_PRIVATE       0x00000008
12666 +
12667 +#define NXF_SINGLE_IP          0x00000100
12668 +#define NXF_LBACK_REMAP                0x00000200
12669 +#define NXF_LBACK_ALLOW                0x00000400
12670 +
12671 +#define NXF_HIDE_NETIF         0x02000000
12672 +#define NXF_HIDE_LBACK         0x04000000
12673 +
12674 +#define NXF_STATE_SETUP                (1ULL << 32)
12675 +#define NXF_STATE_ADMIN                (1ULL << 34)
12676 +
12677 +#define NXF_SC_HELPER          (1ULL << 36)
12678 +#define NXF_PERSISTENT         (1ULL << 38)
12679 +
12680 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12681 +
12682 +
12683 +#define        NXF_INIT_SET            (__nxf_init_set())
12684 +
12685 +static inline uint64_t __nxf_init_set(void) {
12686 +       return    NXF_STATE_ADMIN
12687 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12688 +               | NXF_LBACK_REMAP
12689 +               | NXF_HIDE_LBACK
12690 +#endif
12691 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12692 +               | NXF_SINGLE_IP
12693 +#endif
12694 +               | NXF_HIDE_NETIF;
12695 +}
12696 +
12697 +
12698 +/* network caps */
12699 +
12700 +#define NXC_TUN_CREATE         0x00000001
12701 +
12702 +#define NXC_RAW_ICMP           0x00000100
12703 +
12704 +
12705 +/* address types */
12706 +
12707 +#define NXA_TYPE_IPV4          0x0001
12708 +#define NXA_TYPE_IPV6          0x0002
12709 +
12710 +#define NXA_TYPE_NONE          0x0000
12711 +#define NXA_TYPE_ANY           0x00FF
12712 +
12713 +#define NXA_TYPE_ADDR          0x0010
12714 +#define NXA_TYPE_MASK          0x0020
12715 +#define NXA_TYPE_RANGE         0x0040
12716 +
12717 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12718 +
12719 +#define NXA_MOD_BCAST          0x0100
12720 +#define NXA_MOD_LBACK          0x0200
12721 +
12722 +#define NXA_LOOPBACK           0x1000
12723 +
12724 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12725 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12726 +
12727 +#ifdef __KERNEL__
12728 +
12729 +#include <linux/list.h>
12730 +#include <linux/spinlock.h>
12731 +#include <linux/rcupdate.h>
12732 +#include <linux/in.h>
12733 +#include <linux/in6.h>
12734 +#include <asm/atomic.h>
12735 +
12736 +struct nx_addr_v4 {
12737 +       struct nx_addr_v4 *next;
12738 +       struct in_addr ip[2];
12739 +       struct in_addr mask;
12740 +       uint16_t type;
12741 +       uint16_t flags;
12742 +};
12743 +
12744 +struct nx_addr_v6 {
12745 +       struct nx_addr_v6 *next;
12746 +       struct in6_addr ip;
12747 +       struct in6_addr mask;
12748 +       uint32_t prefix;
12749 +       uint16_t type;
12750 +       uint16_t flags;
12751 +};
12752 +
12753 +struct nx_info {
12754 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12755 +       nid_t nx_id;                    /* vnet id */
12756 +       atomic_t nx_usecnt;             /* usage count */
12757 +       atomic_t nx_tasks;              /* tasks count */
12758 +       int nx_state;                   /* context state */
12759 +
12760 +       uint64_t nx_flags;              /* network flag word */
12761 +       uint64_t nx_ncaps;              /* network capabilities */
12762 +
12763 +       struct in_addr v4_lback;        /* Loopback address */
12764 +       struct in_addr v4_bcast;        /* Broadcast address */
12765 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12766 +#ifdef CONFIG_IPV6
12767 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12768 +#endif
12769 +       char nx_name[65];               /* network context name */
12770 +};
12771 +
12772 +
12773 +/* status flags */
12774 +
12775 +#define NXS_HASHED      0x0001
12776 +#define NXS_SHUTDOWN    0x0100
12777 +#define NXS_RELEASED    0x8000
12778 +
12779 +extern struct nx_info *lookup_nx_info(int);
12780 +
12781 +extern int get_nid_list(int, unsigned int *, int);
12782 +extern int nid_is_hashed(nid_t);
12783 +
12784 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12785 +
12786 +extern long vs_net_change(struct nx_info *, unsigned int);
12787 +
12788 +struct sock;
12789 +
12790 +
12791 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12792 +#ifdef  CONFIG_IPV6
12793 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12794 +#else
12795 +#define NX_IPV6(n)     (0)
12796 +#endif
12797 +
12798 +#endif /* __KERNEL__ */
12799 +#endif /* _VX_NETWORK_H */
12800 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/percpu.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/percpu.h
12801 --- linux-2.6.27.10/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
12802 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/percpu.h 2008-10-13 14:54:20.000000000 +0200
12803 @@ -0,0 +1,14 @@
12804 +#ifndef _VX_PERCPU_H
12805 +#define _VX_PERCPU_H
12806 +
12807 +#include "cvirt_def.h"
12808 +#include "sched_def.h"
12809 +
12810 +struct _vx_percpu {
12811 +       struct _vx_cvirt_pc cvirt;
12812 +       struct _vx_sched_pc sched;
12813 +};
12814 +
12815 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12816 +
12817 +#endif /* _VX_PERCPU_H */
12818 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/pid.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/pid.h
12819 --- linux-2.6.27.10/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
12820 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/pid.h    2008-10-13 14:54:20.000000000 +0200
12821 @@ -0,0 +1,51 @@
12822 +#ifndef _VSERVER_PID_H
12823 +#define _VSERVER_PID_H
12824 +
12825 +/* pid faking stuff */
12826 +
12827 +#define vx_info_map_pid(v, p) \
12828 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12829 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12830 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12831 +#define vx_map_tgid(p) vx_map_pid(p)
12832 +
12833 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12834 +       const char *func, const char *file, int line)
12835 +{
12836 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12837 +               vxfprintk(VXD_CBIT(cvirt, 2),
12838 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12839 +                       vxi, (long long)vxi->vx_flags, pid,
12840 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12841 +                       func, file, line);
12842 +               if (pid == 0)
12843 +                       return 0;
12844 +               if (pid == vxi->vx_initpid)
12845 +                       return 1;
12846 +       }
12847 +       return pid;
12848 +}
12849 +
12850 +#define vx_info_rmap_pid(v, p) \
12851 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12852 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12853 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12854 +
12855 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12856 +       const char *func, const char *file, int line)
12857 +{
12858 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12859 +               vxfprintk(VXD_CBIT(cvirt, 2),
12860 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12861 +                       vxi, (long long)vxi->vx_flags, pid,
12862 +                       (pid == 1) ? vxi->vx_initpid : pid,
12863 +                       func, file, line);
12864 +               if ((pid == 1) && vxi->vx_initpid)
12865 +                       return vxi->vx_initpid;
12866 +               if (pid == vxi->vx_initpid)
12867 +                       return ~0U;
12868 +       }
12869 +       return pid;
12870 +}
12871 +
12872 +#endif
12873 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/sched_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/sched_cmd.h
12874 --- linux-2.6.27.10/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
12875 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/sched_cmd.h      2008-10-13 14:54:20.000000000 +0200
12876 @@ -0,0 +1,108 @@
12877 +#ifndef _VX_SCHED_CMD_H
12878 +#define _VX_SCHED_CMD_H
12879 +
12880 +
12881 +/*  sched vserver commands */
12882 +
12883 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12884 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12885 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12886 +
12887 +struct vcmd_set_sched_v2 {
12888 +       int32_t fill_rate;
12889 +       int32_t interval;
12890 +       int32_t tokens;
12891 +       int32_t tokens_min;
12892 +       int32_t tokens_max;
12893 +       uint64_t cpu_mask;
12894 +};
12895 +
12896 +struct vcmd_set_sched_v3 {
12897 +       uint32_t set_mask;
12898 +       int32_t fill_rate;
12899 +       int32_t interval;
12900 +       int32_t tokens;
12901 +       int32_t tokens_min;
12902 +       int32_t tokens_max;
12903 +       int32_t priority_bias;
12904 +};
12905 +
12906 +struct vcmd_set_sched_v4 {
12907 +       uint32_t set_mask;
12908 +       int32_t fill_rate;
12909 +       int32_t interval;
12910 +       int32_t tokens;
12911 +       int32_t tokens_min;
12912 +       int32_t tokens_max;
12913 +       int32_t prio_bias;
12914 +       int32_t cpu_id;
12915 +       int32_t bucket_id;
12916 +};
12917 +
12918 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12919 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12920 +
12921 +struct vcmd_sched_v5 {
12922 +       uint32_t mask;
12923 +       int32_t cpu_id;
12924 +       int32_t bucket_id;
12925 +       int32_t fill_rate[2];
12926 +       int32_t interval[2];
12927 +       int32_t tokens;
12928 +       int32_t tokens_min;
12929 +       int32_t tokens_max;
12930 +       int32_t prio_bias;
12931 +};
12932 +
12933 +#define VXSM_FILL_RATE         0x0001
12934 +#define VXSM_INTERVAL          0x0002
12935 +#define VXSM_FILL_RATE2                0x0004
12936 +#define VXSM_INTERVAL2         0x0008
12937 +#define VXSM_TOKENS            0x0010
12938 +#define VXSM_TOKENS_MIN                0x0020
12939 +#define VXSM_TOKENS_MAX                0x0040
12940 +#define VXSM_PRIO_BIAS         0x0100
12941 +
12942 +#define VXSM_IDLE_TIME         0x0200
12943 +#define VXSM_FORCE             0x0400
12944 +
12945 +#define        VXSM_V3_MASK            0x0173
12946 +#define        VXSM_SET_MASK           0x01FF
12947 +
12948 +#define VXSM_CPU_ID            0x1000
12949 +#define VXSM_BUCKET_ID         0x2000
12950 +
12951 +#define VXSM_MSEC              0x4000
12952 +
12953 +#define SCHED_KEEP             (-2)    /* only for v2 */
12954 +
12955 +#ifdef __KERNEL__
12956 +
12957 +#include <linux/compiler.h>
12958 +
12959 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12960 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12961 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12962 +extern int vc_set_sched(struct vx_info *, void __user *);
12963 +extern int vc_get_sched(struct vx_info *, void __user *);
12964 +
12965 +#endif /* __KERNEL__ */
12966 +
12967 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12968 +
12969 +struct vcmd_sched_info {
12970 +       int32_t cpu_id;
12971 +       int32_t bucket_id;
12972 +       uint64_t user_msec;
12973 +       uint64_t sys_msec;
12974 +       uint64_t hold_msec;
12975 +       uint32_t token_usec;
12976 +       int32_t vavavoom;
12977 +};
12978 +
12979 +#ifdef __KERNEL__
12980 +
12981 +extern int vc_sched_info(struct vx_info *, void __user *);
12982 +
12983 +#endif /* __KERNEL__ */
12984 +#endif /* _VX_SCHED_CMD_H */
12985 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/sched_def.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/sched_def.h
12986 --- linux-2.6.27.10/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
12987 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/sched_def.h      2008-10-13 14:54:20.000000000 +0200
12988 @@ -0,0 +1,68 @@
12989 +#ifndef _VX_SCHED_DEF_H
12990 +#define _VX_SCHED_DEF_H
12991 +
12992 +#include <linux/spinlock.h>
12993 +#include <linux/jiffies.h>
12994 +#include <linux/cpumask.h>
12995 +#include <asm/atomic.h>
12996 +#include <asm/param.h>
12997 +
12998 +
12999 +/* context sub struct */
13000 +
13001 +struct _vx_sched {
13002 +       spinlock_t tokens_lock;         /* lock for token bucket */
13003 +
13004 +       int tokens;                     /* number of CPU tokens */
13005 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13006 +       int interval[2];                /* Divisor:   per Y jiffies   */
13007 +       int tokens_min;                 /* Limit:     minimum for unhold */
13008 +       int tokens_max;                 /* Limit:     no more than N tokens */
13009 +
13010 +       int prio_bias;                  /* bias offset for priority */
13011 +
13012 +       unsigned update_mask;           /* which features should be updated */
13013 +       cpumask_t update;               /* CPUs which should update */
13014 +};
13015 +
13016 +struct _vx_sched_pc {
13017 +       int tokens;                     /* number of CPU tokens */
13018 +       int flags;                      /* bucket flags */
13019 +
13020 +       int fill_rate[2];               /* Fill rate: add X tokens... */
13021 +       int interval[2];                /* Divisor:   per Y jiffies   */
13022 +       int tokens_min;                 /* Limit:     minimum for unhold */
13023 +       int tokens_max;                 /* Limit:     no more than N tokens */
13024 +
13025 +       int prio_bias;                  /* bias offset for priority */
13026 +       int vavavoom;                   /* last calculated vavavoom */
13027 +
13028 +       unsigned long norm_time;        /* last time accounted */
13029 +       unsigned long idle_time;        /* non linear time for fair sched */
13030 +       unsigned long token_time;       /* token time for accounting */
13031 +       unsigned long onhold;           /* jiffies when put on hold */
13032 +
13033 +       uint64_t user_ticks;            /* token tick events */
13034 +       uint64_t sys_ticks;             /* token tick events */
13035 +       uint64_t hold_ticks;            /* token ticks paused */
13036 +};
13037 +
13038 +
13039 +#define VXSF_ONHOLD    0x0001
13040 +#define VXSF_IDLE_TIME 0x0100
13041 +
13042 +#ifdef CONFIG_VSERVER_DEBUG
13043 +
13044 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13045 +{
13046 +       printk("\t_vx_sched:\n");
13047 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
13048 +               sched->fill_rate[0], sched->interval[0],
13049 +               sched->fill_rate[1], sched->interval[1],
13050 +               sched->tokens_min, sched->tokens_max);
13051 +       printk("\t priority = %4d\n", sched->prio_bias);
13052 +}
13053 +
13054 +#endif
13055 +
13056 +#endif /* _VX_SCHED_DEF_H */
13057 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/sched.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/sched.h
13058 --- linux-2.6.27.10/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
13059 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/sched.h  2008-10-13 14:54:20.000000000 +0200
13060 @@ -0,0 +1,26 @@
13061 +#ifndef _VX_SCHED_H
13062 +#define _VX_SCHED_H
13063 +
13064 +
13065 +#ifdef __KERNEL__
13066 +
13067 +struct timespec;
13068 +
13069 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13070 +
13071 +
13072 +struct vx_info;
13073 +
13074 +void vx_update_load(struct vx_info *);
13075 +
13076 +
13077 +int vx_tokens_recalc(struct _vx_sched_pc *,
13078 +       unsigned long *, unsigned long *, int [2]);
13079 +
13080 +void vx_update_sched_param(struct _vx_sched *sched,
13081 +       struct _vx_sched_pc *sched_pc);
13082 +
13083 +#endif /* __KERNEL__ */
13084 +#else  /* _VX_SCHED_H */
13085 +#warning duplicate inclusion
13086 +#endif /* _VX_SCHED_H */
13087 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/signal_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/signal_cmd.h
13088 --- linux-2.6.27.10/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
13089 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/signal_cmd.h     2008-10-13 14:54:20.000000000 +0200
13090 @@ -0,0 +1,43 @@
13091 +#ifndef _VX_SIGNAL_CMD_H
13092 +#define _VX_SIGNAL_CMD_H
13093 +
13094 +
13095 +/*  signalling vserver commands */
13096 +
13097 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13098 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13099 +
13100 +struct vcmd_ctx_kill_v0 {
13101 +       int32_t pid;
13102 +       int32_t sig;
13103 +};
13104 +
13105 +struct vcmd_wait_exit_v0 {
13106 +       int32_t reboot_cmd;
13107 +       int32_t exit_code;
13108 +};
13109 +
13110 +#ifdef __KERNEL__
13111 +
13112 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13113 +extern int vc_wait_exit(struct vx_info *, void __user *);
13114 +
13115 +#endif /* __KERNEL__ */
13116 +
13117 +/*  process alteration commands */
13118 +
13119 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13120 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13121 +
13122 +struct vcmd_pflags_v0 {
13123 +       uint32_t flagword;
13124 +       uint32_t mask;
13125 +};
13126 +
13127 +#ifdef __KERNEL__
13128 +
13129 +extern int vc_get_pflags(uint32_t pid, void __user *);
13130 +extern int vc_set_pflags(uint32_t pid, void __user *);
13131 +
13132 +#endif /* __KERNEL__ */
13133 +#endif /* _VX_SIGNAL_CMD_H */
13134 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/signal.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/signal.h
13135 --- linux-2.6.27.10/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
13136 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/signal.h 2008-10-13 14:54:20.000000000 +0200
13137 @@ -0,0 +1,14 @@
13138 +#ifndef _VX_SIGNAL_H
13139 +#define _VX_SIGNAL_H
13140 +
13141 +
13142 +#ifdef __KERNEL__
13143 +
13144 +struct vx_info;
13145 +
13146 +int vx_info_kill(struct vx_info *, int, int);
13147 +
13148 +#endif /* __KERNEL__ */
13149 +#else  /* _VX_SIGNAL_H */
13150 +#warning duplicate inclusion
13151 +#endif /* _VX_SIGNAL_H */
13152 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/space_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/space_cmd.h
13153 --- linux-2.6.27.10/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
13154 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/space_cmd.h      2008-10-31 03:49:36.000000000 +0100
13155 @@ -0,0 +1,38 @@
13156 +#ifndef _VX_SPACE_CMD_H
13157 +#define _VX_SPACE_CMD_H
13158 +
13159 +
13160 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13161 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13162 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13163 +
13164 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13165 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13166 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13167 +
13168 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13169 +
13170 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13171 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13172 +
13173 +
13174 +struct vcmd_space_mask_v1 {
13175 +       uint64_t mask;
13176 +};
13177 +
13178 +struct vcmd_space_mask_v2 {
13179 +       uint64_t mask;
13180 +       uint32_t index;
13181 +};
13182 +
13183 +
13184 +#ifdef __KERNEL__
13185 +
13186 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13187 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13188 +extern int vc_enter_space(struct vx_info *, void __user *);
13189 +extern int vc_set_space(struct vx_info *, void __user *);
13190 +extern int vc_get_space_mask(void __user *, int);
13191 +
13192 +#endif /* __KERNEL__ */
13193 +#endif /* _VX_SPACE_CMD_H */
13194 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/space.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/space.h
13195 --- linux-2.6.27.10/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
13196 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/space.h  2008-10-31 04:02:02.000000000 +0100
13197 @@ -0,0 +1,12 @@
13198 +#ifndef _VX_SPACE_H
13199 +#define _VX_SPACE_H
13200 +
13201 +#include <linux/types.h>
13202 +
13203 +struct vx_info;
13204 +
13205 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13206 +
13207 +#else  /* _VX_SPACE_H */
13208 +#warning duplicate inclusion
13209 +#endif /* _VX_SPACE_H */
13210 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/switch.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/switch.h
13211 --- linux-2.6.27.10/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
13212 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/switch.h 2008-11-22 20:32:00.000000000 +0100
13213 @@ -0,0 +1,98 @@
13214 +#ifndef _VX_SWITCH_H
13215 +#define _VX_SWITCH_H
13216 +
13217 +#include <linux/types.h>
13218 +
13219 +
13220 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13221 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13222 +#define VC_VERSION(c)          ((c) & 0xFFF)
13223 +
13224 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13225 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13226 +
13227 +/*
13228 +
13229 +  Syscall Matrix V2.8
13230 +
13231 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13232 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13233 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13234 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13235 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13236 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13237 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13238 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13239 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13240 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13241 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13242 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13243 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13244 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13245 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13246 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13247 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13248 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13249 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13250 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13251 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13252 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13253 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13254 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13255 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13256 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13257 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13258 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13259 +
13260 +*/
13261 +
13262 +#define VC_CAT_VERSION         0
13263 +
13264 +#define VC_CAT_VSETUP          1
13265 +#define VC_CAT_VHOST           2
13266 +
13267 +#define VC_CAT_DEVICE          6
13268 +
13269 +#define VC_CAT_VPROC           9
13270 +#define VC_CAT_PROCALT         10
13271 +#define VC_CAT_PROCMIG         11
13272 +#define VC_CAT_PROCTRL         12
13273 +
13274 +#define VC_CAT_SCHED           14
13275 +#define VC_CAT_MEMCTRL         20
13276 +
13277 +#define VC_CAT_VNET            25
13278 +#define VC_CAT_NETALT          26
13279 +#define VC_CAT_NETMIG          27
13280 +#define VC_CAT_NETCTRL         28
13281 +
13282 +#define VC_CAT_TAGMIG          35
13283 +#define VC_CAT_DLIMIT          36
13284 +#define VC_CAT_INODE           38
13285 +
13286 +#define VC_CAT_VSTAT           40
13287 +#define VC_CAT_VINFO           46
13288 +#define VC_CAT_EVENT           48
13289 +
13290 +#define VC_CAT_FLAGS           52
13291 +#define VC_CAT_VSPACE          54
13292 +#define VC_CAT_DEBUG           56
13293 +#define VC_CAT_RLIMIT          60
13294 +
13295 +#define VC_CAT_SYSTEST         61
13296 +#define VC_CAT_COMPAT          63
13297 +
13298 +/*  query version */
13299 +
13300 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13301 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13302 +
13303 +
13304 +#ifdef __KERNEL__
13305 +
13306 +#include <linux/errno.h>
13307 +
13308 +#endif /* __KERNEL__ */
13309 +
13310 +#endif /* _VX_SWITCH_H */
13311 +
13312 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/tag_cmd.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/tag_cmd.h
13313 --- linux-2.6.27.10/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
13314 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/tag_cmd.h        2008-10-13 14:54:20.000000000 +0200
13315 @@ -0,0 +1,22 @@
13316 +#ifndef _VX_TAG_CMD_H
13317 +#define _VX_TAG_CMD_H
13318 +
13319 +
13320 +/* vinfo commands */
13321 +
13322 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13323 +
13324 +#ifdef __KERNEL__
13325 +extern int vc_task_tag(uint32_t);
13326 +
13327 +#endif /* __KERNEL__ */
13328 +
13329 +/* context commands */
13330 +
13331 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13332 +
13333 +#ifdef __KERNEL__
13334 +extern int vc_tag_migrate(uint32_t);
13335 +
13336 +#endif /* __KERNEL__ */
13337 +#endif /* _VX_TAG_CMD_H */
13338 diff -NurpP --minimal linux-2.6.27.10/include/linux/vserver/tag.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/tag.h
13339 --- linux-2.6.27.10/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
13340 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vserver/tag.h    2008-10-24 03:34:52.000000000 +0200
13341 @@ -0,0 +1,143 @@
13342 +#ifndef _DX_TAG_H
13343 +#define _DX_TAG_H
13344 +
13345 +#include <linux/types.h>
13346 +
13347 +
13348 +#define DX_TAG(in)     (IS_TAGGED(in))
13349 +
13350 +
13351 +#ifdef CONFIG_TAG_NFSD
13352 +#define DX_TAG_NFSD    1
13353 +#else
13354 +#define DX_TAG_NFSD    0
13355 +#endif
13356 +
13357 +
13358 +#ifdef CONFIG_TAGGING_NONE
13359 +
13360 +#define MAX_UID                0xFFFFFFFF
13361 +#define MAX_GID                0xFFFFFFFF
13362 +
13363 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13364 +
13365 +#define TAGINO_UID(cond, uid, tag)     (uid)
13366 +#define TAGINO_GID(cond, gid, tag)     (gid)
13367 +
13368 +#endif
13369 +
13370 +
13371 +#ifdef CONFIG_TAGGING_GID16
13372 +
13373 +#define MAX_UID                0xFFFFFFFF
13374 +#define MAX_GID                0x0000FFFF
13375 +
13376 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13377 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13378 +
13379 +#define TAGINO_UID(cond, uid, tag)     (uid)
13380 +#define TAGINO_GID(cond, gid, tag)     \
13381 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13382 +
13383 +#endif
13384 +
13385 +
13386 +#ifdef CONFIG_TAGGING_ID24
13387 +
13388 +#define MAX_UID                0x00FFFFFF
13389 +#define MAX_GID                0x00FFFFFF
13390 +
13391 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13392 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13393 +
13394 +#define TAGINO_UID(cond, uid, tag)     \
13395 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13396 +#define TAGINO_GID(cond, gid, tag)     \
13397 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13398 +
13399 +#endif
13400 +
13401 +
13402 +#ifdef CONFIG_TAGGING_UID16
13403 +
13404 +#define MAX_UID                0x0000FFFF
13405 +#define MAX_GID                0xFFFFFFFF
13406 +
13407 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13408 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13409 +
13410 +#define TAGINO_UID(cond, uid, tag)     \
13411 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13412 +#define TAGINO_GID(cond, gid, tag)     (gid)
13413 +
13414 +#endif
13415 +
13416 +
13417 +#ifdef CONFIG_TAGGING_INTERN
13418 +
13419 +#define MAX_UID                0xFFFFFFFF
13420 +#define MAX_GID                0xFFFFFFFF
13421 +
13422 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13423 +       ((cond) ? (tag) : 0)
13424 +
13425 +#define TAGINO_UID(cond, uid, tag)     (uid)
13426 +#define TAGINO_GID(cond, gid, tag)     (gid)
13427 +
13428 +#endif
13429 +
13430 +
13431 +#ifndef CONFIG_TAGGING_NONE
13432 +#define dx_current_fstag(sb)   \
13433 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13434 +#else
13435 +#define dx_current_fstag(sb)   (0)
13436 +#endif
13437 +
13438 +#ifndef CONFIG_TAGGING_INTERN
13439 +#define TAGINO_TAG(cond, tag)  (0)
13440 +#else
13441 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13442 +#endif
13443 +
13444 +#define INOTAG_UID(cond, uid, gid)     \
13445 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13446 +#define INOTAG_GID(cond, uid, gid)     \
13447 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13448 +
13449 +
13450 +static inline uid_t dx_map_uid(uid_t uid)
13451 +{
13452 +       if ((uid > MAX_UID) && (uid != -1))
13453 +               uid = -2;
13454 +       return (uid & MAX_UID);
13455 +}
13456 +
13457 +static inline gid_t dx_map_gid(gid_t gid)
13458 +{
13459 +       if ((gid > MAX_GID) && (gid != -1))
13460 +               gid = -2;
13461 +       return (gid & MAX_GID);
13462 +}
13463 +
13464 +struct peer_tag {
13465 +       int32_t xid;
13466 +       int32_t nid;
13467 +};
13468 +
13469 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13470 +
13471 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13472 +                unsigned long *flags);
13473 +
13474 +#ifdef CONFIG_PROPAGATE
13475 +
13476 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13477 +
13478 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13479 +
13480 +#else
13481 +#define dx_propagate_tag(n, i) do { } while (0)
13482 +#endif
13483 +
13484 +#endif /* _DX_TAG_H */
13485 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_inet6.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_inet6.h
13486 --- linux-2.6.27.10/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
13487 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_inet6.h       2008-11-16 17:35:20.000000000 +0100
13488 @@ -0,0 +1,246 @@
13489 +#ifndef _VS_INET6_H
13490 +#define _VS_INET6_H
13491 +
13492 +#include "vserver/base.h"
13493 +#include "vserver/network.h"
13494 +#include "vserver/debug.h"
13495 +
13496 +#include <net/ipv6.h>
13497 +
13498 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
13499 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
13500 +
13501 +
13502 +#ifdef CONFIG_IPV6
13503 +
13504 +static inline
13505 +int v6_addr_match(struct nx_addr_v6 *nxa,
13506 +       const struct in6_addr *addr, uint16_t mask)
13507 +{
13508 +       int ret = 0;
13509 +
13510 +       switch (nxa->type & mask) {
13511 +       case NXA_TYPE_MASK:
13512 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13513 +               break;
13514 +       case NXA_TYPE_ADDR:
13515 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13516 +               break;
13517 +       case NXA_TYPE_ANY:
13518 +               ret = 1;
13519 +               break;
13520 +       }
13521 +       vxdprintk(VXD_CBIT(net, 0),
13522 +               "v6_addr_match(%p" NXAV6_FMT ", " NIP6_FMT ", %04x) = %d",
13523 +               nxa, NXAV6(nxa), NIP6(*addr), mask, ret);
13524 +       return ret;
13525 +}
13526 +
13527 +static inline
13528 +int v6_addr_in_nx_info(struct nx_info *nxi,
13529 +       const struct in6_addr *addr, uint16_t mask)
13530 +{
13531 +       struct nx_addr_v6 *nxa;
13532 +       int ret = 1;
13533 +
13534 +       if (!nxi)
13535 +               goto out;
13536 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13537 +               if (v6_addr_match(nxa, addr, mask))
13538 +                       goto out;
13539 +       ret = 0;
13540 +out:
13541 +       vxdprintk(VXD_CBIT(net, 0),
13542 +               "v6_addr_in_nx_info(%p[#%u]," NIP6_FMT ",%04x) = %d",
13543 +               nxi, nxi ? nxi->nx_id : 0, NIP6(*addr), mask, ret);
13544 +       return ret;
13545 +}
13546 +
13547 +static inline
13548 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13549 +{
13550 +       /* FIXME: needs full range checks */
13551 +       return v6_addr_match(nxa, &addr->ip, mask);
13552 +}
13553 +
13554 +static inline
13555 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13556 +{
13557 +       struct nx_addr_v6 *ptr;
13558 +
13559 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13560 +               if (v6_nx_addr_match(ptr, nxa, mask))
13561 +                       return 1;
13562 +       return 0;
13563 +}
13564 +
13565 +
13566 +/*
13567 + *     Check if a given address matches for a socket
13568 + *
13569 + *     nxi:            the socket's nx_info if any
13570 + *     addr:           to be verified address
13571 + */
13572 +static inline
13573 +int v6_sock_addr_match (
13574 +       struct nx_info *nxi,
13575 +       struct inet_sock *inet,
13576 +       struct in6_addr *addr)
13577 +{
13578 +       struct sock *sk = &inet->sk;
13579 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13580 +
13581 +       if (!ipv6_addr_any(addr) &&
13582 +               ipv6_addr_equal(saddr, addr))
13583 +               return 1;
13584 +       if (ipv6_addr_any(saddr))
13585 +               return v6_addr_in_nx_info(nxi, addr, -1);
13586 +       return 0;
13587 +}
13588 +
13589 +/*
13590 + *     check if address is covered by socket
13591 + *
13592 + *     sk:     the socket to check against
13593 + *     addr:   the address in question (must be != 0)
13594 + */
13595 +
13596 +static inline
13597 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13598 +{
13599 +       struct nx_info *nxi = sk->sk_nx_info;
13600 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13601 +
13602 +       vxdprintk(VXD_CBIT(net, 5),
13603 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
13604 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
13605 +               (sk->sk_socket?sk->sk_socket->flags:0));
13606 +
13607 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13608 +               return v6_addr_match(nxa, saddr, -1);
13609 +       } else if (nxi) {               /* match against nx_info */
13610 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13611 +       } else {                        /* unrestricted any socket */
13612 +               return 1;
13613 +       }
13614 +}
13615 +
13616 +
13617 +/* inet related checks and helpers */
13618 +
13619 +
13620 +struct in_ifaddr;
13621 +struct net_device;
13622 +struct sock;
13623 +
13624 +
13625 +#include <linux/netdevice.h>
13626 +#include <linux/inetdevice.h>
13627 +#include <net/inet_timewait_sock.h>
13628 +
13629 +
13630 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13631 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13632 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13633 +
13634 +
13635 +
13636 +static inline
13637 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13638 +{
13639 +       if (!nxi)
13640 +               return 1;
13641 +       if (!ifa)
13642 +               return 0;
13643 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13644 +}
13645 +
13646 +static inline
13647 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13648 +{
13649 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13650 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13651 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13652 +
13653 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13654 +               return 1;
13655 +       if (v6_ifa_in_nx_info(ifa, nxi))
13656 +               return 1;
13657 +       return 0;
13658 +}
13659 +
13660 +
13661 +struct nx_v6_sock_addr {
13662 +       struct in6_addr saddr;  /* Address used for validation */
13663 +       struct in6_addr baddr;  /* Address used for socket bind */
13664 +};
13665 +
13666 +static inline
13667 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13668 +       struct nx_v6_sock_addr *nsa)
13669 +{
13670 +       // struct sock *sk = &inet->sk;
13671 +       // struct nx_info *nxi = sk->sk_nx_info;
13672 +       struct in6_addr saddr = addr->sin6_addr;
13673 +       struct in6_addr baddr = saddr;
13674 +
13675 +       nsa->saddr = saddr;
13676 +       nsa->baddr = baddr;
13677 +       return 0;
13678 +}
13679 +
13680 +static inline
13681 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13682 +{
13683 +       // struct sock *sk = &inet->sk;
13684 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13685 +
13686 +       // *saddr = nsa->baddr;
13687 +       // inet->saddr = nsa->baddr;
13688 +}
13689 +
13690 +static inline
13691 +int nx_info_has_v6(struct nx_info *nxi)
13692 +{
13693 +       if (!nxi)
13694 +               return 1;
13695 +       if (NX_IPV6(nxi))
13696 +               return 1;
13697 +       return 0;
13698 +}
13699 +
13700 +#else /* CONFIG_IPV6 */
13701 +
13702 +static inline
13703 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13704 +{
13705 +       return 1;
13706 +}
13707 +
13708 +
13709 +static inline
13710 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13711 +{
13712 +       return 1;
13713 +}
13714 +
13715 +static inline
13716 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13717 +{
13718 +       return 1;
13719 +}
13720 +
13721 +static inline
13722 +int nx_info_has_v6(struct nx_info *nxi)
13723 +{
13724 +       return 0;
13725 +}
13726 +
13727 +#endif /* CONFIG_IPV6 */
13728 +
13729 +#define current_nx_info_has_v6() \
13730 +       nx_info_has_v6(current_nx_info())
13731 +
13732 +#else
13733 +#warning duplicate inclusion
13734 +#endif
13735 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_inet.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_inet.h
13736 --- linux-2.6.27.10/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
13737 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_inet.h        2008-10-13 14:54:20.000000000 +0200
13738 @@ -0,0 +1,342 @@
13739 +#ifndef _VS_INET_H
13740 +#define _VS_INET_H
13741 +
13742 +#include "vserver/base.h"
13743 +#include "vserver/network.h"
13744 +#include "vserver/debug.h"
13745 +
13746 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13747 +
13748 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13749 +                       NIPQUAD((a)->mask), (a)->type
13750 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13751 +
13752 +
13753 +static inline
13754 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13755 +{
13756 +       __be32 ip = nxa->ip[0].s_addr;
13757 +       __be32 mask = nxa->mask.s_addr;
13758 +       __be32 bcast = ip | ~mask;
13759 +       int ret = 0;
13760 +
13761 +       switch (nxa->type & tmask) {
13762 +       case NXA_TYPE_MASK:
13763 +               ret = (ip == (addr & mask));
13764 +               break;
13765 +       case NXA_TYPE_ADDR:
13766 +               ret = 3;
13767 +               if (addr == ip)
13768 +                       break;
13769 +               /* fall through to broadcast */
13770 +       case NXA_MOD_BCAST:
13771 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13772 +               break;
13773 +       case NXA_TYPE_RANGE:
13774 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13775 +                       (nxa->ip[1].s_addr > addr));
13776 +               break;
13777 +       case NXA_TYPE_ANY:
13778 +               ret = 2;
13779 +               break;
13780 +       }
13781 +
13782 +       vxdprintk(VXD_CBIT(net, 0),
13783 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13784 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13785 +       return ret;
13786 +}
13787 +
13788 +static inline
13789 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13790 +{
13791 +       struct nx_addr_v4 *nxa;
13792 +       int ret = 1;
13793 +
13794 +       if (!nxi)
13795 +               goto out;
13796 +
13797 +       ret = 2;
13798 +       /* allow 127.0.0.1 when remapping lback */
13799 +       if ((tmask & NXA_LOOPBACK) &&
13800 +               (addr == IPI_LOOPBACK) &&
13801 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13802 +               goto out;
13803 +       ret = 3;
13804 +       /* check for lback address */
13805 +       if ((tmask & NXA_MOD_LBACK) &&
13806 +               (nxi->v4_lback.s_addr == addr))
13807 +               goto out;
13808 +       ret = 4;
13809 +       /* check for broadcast address */
13810 +       if ((tmask & NXA_MOD_BCAST) &&
13811 +               (nxi->v4_bcast.s_addr == addr))
13812 +               goto out;
13813 +       ret = 5;
13814 +       /* check for v4 addresses */
13815 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13816 +               if (v4_addr_match(nxa, addr, tmask))
13817 +                       goto out;
13818 +       ret = 0;
13819 +out:
13820 +       vxdprintk(VXD_CBIT(net, 0),
13821 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13822 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13823 +       return ret;
13824 +}
13825 +
13826 +static inline
13827 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13828 +{
13829 +       /* FIXME: needs full range checks */
13830 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13831 +}
13832 +
13833 +static inline
13834 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13835 +{
13836 +       struct nx_addr_v4 *ptr;
13837 +
13838 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13839 +               if (v4_nx_addr_match(ptr, nxa, mask))
13840 +                       return 1;
13841 +       return 0;
13842 +}
13843 +
13844 +#include <net/inet_sock.h>
13845 +
13846 +/*
13847 + *     Check if a given address matches for a socket
13848 + *
13849 + *     nxi:            the socket's nx_info if any
13850 + *     addr:           to be verified address
13851 + */
13852 +static inline
13853 +int v4_sock_addr_match (
13854 +       struct nx_info *nxi,
13855 +       struct inet_sock *inet,
13856 +       __be32 addr)
13857 +{
13858 +       __be32 saddr = inet->rcv_saddr;
13859 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13860 +
13861 +       if (addr && (saddr == addr || bcast == addr))
13862 +               return 1;
13863 +       if (!saddr)
13864 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13865 +       return 0;
13866 +}
13867 +
13868 +
13869 +/* inet related checks and helpers */
13870 +
13871 +
13872 +struct in_ifaddr;
13873 +struct net_device;
13874 +struct sock;
13875 +
13876 +#ifdef CONFIG_INET
13877 +
13878 +#include <linux/netdevice.h>
13879 +#include <linux/inetdevice.h>
13880 +#include <net/inet_sock.h>
13881 +#include <net/inet_timewait_sock.h>
13882 +
13883 +
13884 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13885 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13886 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13887 +
13888 +
13889 +/*
13890 + *     check if address is covered by socket
13891 + *
13892 + *     sk:     the socket to check against
13893 + *     addr:   the address in question (must be != 0)
13894 + */
13895 +
13896 +static inline
13897 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13898 +{
13899 +       struct nx_info *nxi = sk->sk_nx_info;
13900 +       __be32 saddr = inet_rcv_saddr(sk);
13901 +
13902 +       vxdprintk(VXD_CBIT(net, 5),
13903 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13904 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13905 +               (sk->sk_socket?sk->sk_socket->flags:0));
13906 +
13907 +       if (saddr) {            /* direct address match */
13908 +               return v4_addr_match(nxa, saddr, -1);
13909 +       } else if (nxi) {       /* match against nx_info */
13910 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13911 +       } else {                /* unrestricted any socket */
13912 +               return 1;
13913 +       }
13914 +}
13915 +
13916 +
13917 +
13918 +static inline
13919 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13920 +{
13921 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13922 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13923 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13924 +
13925 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13926 +               return 1;
13927 +       if (dev_in_nx_info(dev, nxi))
13928 +               return 1;
13929 +       return 0;
13930 +}
13931 +
13932 +
13933 +static inline
13934 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13935 +{
13936 +       if (!nxi)
13937 +               return 1;
13938 +       if (!ifa)
13939 +               return 0;
13940 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13941 +}
13942 +
13943 +static inline
13944 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13945 +{
13946 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13947 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13948 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13949 +
13950 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13951 +               return 1;
13952 +       if (v4_ifa_in_nx_info(ifa, nxi))
13953 +               return 1;
13954 +       return 0;
13955 +}
13956 +
13957 +
13958 +struct nx_v4_sock_addr {
13959 +       __be32 saddr;   /* Address used for validation */
13960 +       __be32 baddr;   /* Address used for socket bind */
13961 +};
13962 +
13963 +static inline
13964 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13965 +       struct nx_v4_sock_addr *nsa)
13966 +{
13967 +       struct sock *sk = &inet->sk;
13968 +       struct nx_info *nxi = sk->sk_nx_info;
13969 +       __be32 saddr = addr->sin_addr.s_addr;
13970 +       __be32 baddr = saddr;
13971 +
13972 +       vxdprintk(VXD_CBIT(net, 3),
13973 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13974 +               sk, sk->sk_nx_info, sk->sk_socket,
13975 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13976 +               NIPQUAD(saddr));
13977 +
13978 +       if (nxi) {
13979 +               if (saddr == INADDR_ANY) {
13980 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13981 +                               baddr = nxi->v4.ip[0].s_addr;
13982 +               } else if (saddr == IPI_LOOPBACK) {
13983 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13984 +                               baddr = nxi->v4_lback.s_addr;
13985 +               } else {        /* normal address bind */
13986 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13987 +                               return -EADDRNOTAVAIL;
13988 +               }
13989 +       }
13990 +
13991 +       vxdprintk(VXD_CBIT(net, 3),
13992 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13993 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13994 +
13995 +       nsa->saddr = saddr;
13996 +       nsa->baddr = baddr;
13997 +       return 0;
13998 +}
13999 +
14000 +static inline
14001 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
14002 +{
14003 +       inet->saddr = nsa->baddr;
14004 +       inet->rcv_saddr = nsa->baddr;
14005 +}
14006 +
14007 +
14008 +/*
14009 + *      helper to simplify inet_lookup_listener
14010 + *
14011 + *      nxi:   the socket's nx_info if any
14012 + *      addr:  to be verified address
14013 + *      saddr: socket address
14014 + */
14015 +static inline int v4_inet_addr_match (
14016 +       struct nx_info *nxi,
14017 +       __be32 addr,
14018 +       __be32 saddr)
14019 +{
14020 +       if (addr && (saddr == addr))
14021 +               return 1;
14022 +       if (!saddr)
14023 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
14024 +       return 0;
14025 +}
14026 +
14027 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
14028 +{
14029 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
14030 +               (addr == nxi->v4_lback.s_addr))
14031 +               return IPI_LOOPBACK;
14032 +       return addr;
14033 +}
14034 +
14035 +static inline
14036 +int nx_info_has_v4(struct nx_info *nxi)
14037 +{
14038 +       if (!nxi)
14039 +               return 1;
14040 +       if (NX_IPV4(nxi))
14041 +               return 1;
14042 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
14043 +               return 1;
14044 +       return 0;
14045 +}
14046 +
14047 +#else /* CONFIG_INET */
14048 +
14049 +static inline
14050 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
14051 +{
14052 +       return 1;
14053 +}
14054 +
14055 +static inline
14056 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14057 +{
14058 +       return 1;
14059 +}
14060 +
14061 +static inline
14062 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14063 +{
14064 +       return 1;
14065 +}
14066 +
14067 +static inline
14068 +int nx_info_has_v4(struct nx_info *nxi)
14069 +{
14070 +       return 0;
14071 +}
14072 +
14073 +#endif /* CONFIG_INET */
14074 +
14075 +#define current_nx_info_has_v4() \
14076 +       nx_info_has_v4(current_nx_info())
14077 +
14078 +#else
14079 +// #warning duplicate inclusion
14080 +#endif
14081 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_limit.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_limit.h
14082 --- linux-2.6.27.10/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
14083 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_limit.h       2008-10-13 14:54:20.000000000 +0200
14084 @@ -0,0 +1,140 @@
14085 +#ifndef _VS_LIMIT_H
14086 +#define _VS_LIMIT_H
14087 +
14088 +#include "vserver/limit.h"
14089 +#include "vserver/base.h"
14090 +#include "vserver/context.h"
14091 +#include "vserver/debug.h"
14092 +#include "vserver/context.h"
14093 +#include "vserver/limit_int.h"
14094 +
14095 +
14096 +#define vx_acc_cres(v, d, p, r) \
14097 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14098 +
14099 +#define vx_acc_cres_cond(x, d, p, r) \
14100 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14101 +       r, d, p, __FILE__, __LINE__)
14102 +
14103 +
14104 +#define vx_add_cres(v, a, p, r) \
14105 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
14106 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
14107 +
14108 +#define vx_add_cres_cond(x, a, p, r) \
14109 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14110 +       r, a, p, __FILE__, __LINE__)
14111 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
14112 +
14113 +
14114 +/* process and file limits */
14115 +
14116 +#define vx_nproc_inc(p) \
14117 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
14118 +
14119 +#define vx_nproc_dec(p) \
14120 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
14121 +
14122 +#define vx_files_inc(f) \
14123 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
14124 +
14125 +#define vx_files_dec(f) \
14126 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
14127 +
14128 +#define vx_locks_inc(l) \
14129 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
14130 +
14131 +#define vx_locks_dec(l) \
14132 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
14133 +
14134 +#define vx_openfd_inc(f) \
14135 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
14136 +
14137 +#define vx_openfd_dec(f) \
14138 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
14139 +
14140 +
14141 +#define vx_cres_avail(v, n, r) \
14142 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
14143 +
14144 +
14145 +#define vx_nproc_avail(n) \
14146 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
14147 +
14148 +#define vx_files_avail(n) \
14149 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
14150 +
14151 +#define vx_locks_avail(n) \
14152 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
14153 +
14154 +#define vx_openfd_avail(n) \
14155 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
14156 +
14157 +
14158 +/* dentry limits */
14159 +
14160 +#define vx_dentry_inc(d) do {                                          \
14161 +       if (atomic_read(&d->d_count) == 1)                              \
14162 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
14163 +       } while (0)
14164 +
14165 +#define vx_dentry_dec(d) do {                                          \
14166 +       if (atomic_read(&d->d_count) == 0)                              \
14167 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
14168 +       } while (0)
14169 +
14170 +#define vx_dentry_avail(n) \
14171 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
14172 +
14173 +
14174 +/* socket limits */
14175 +
14176 +#define vx_sock_inc(s) \
14177 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14178 +
14179 +#define vx_sock_dec(s) \
14180 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14181 +
14182 +#define vx_sock_avail(n) \
14183 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
14184 +
14185 +
14186 +/* ipc resource limits */
14187 +
14188 +#define vx_ipcmsg_add(v, u, a) \
14189 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14190 +
14191 +#define vx_ipcmsg_sub(v, u, a) \
14192 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14193 +
14194 +#define vx_ipcmsg_avail(v, a) \
14195 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14196 +
14197 +
14198 +#define vx_ipcshm_add(v, k, a) \
14199 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14200 +
14201 +#define vx_ipcshm_sub(v, k, a) \
14202 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14203 +
14204 +#define vx_ipcshm_avail(v, a) \
14205 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14206 +
14207 +
14208 +#define vx_semary_inc(a) \
14209 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
14210 +
14211 +#define vx_semary_dec(a) \
14212 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
14213 +
14214 +
14215 +#define vx_nsems_add(a,n) \
14216 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14217 +
14218 +#define vx_nsems_sub(a,n) \
14219 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14220 +
14221 +
14222 +#else
14223 +#warning duplicate inclusion
14224 +#endif
14225 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_memory.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_memory.h
14226 --- linux-2.6.27.10/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
14227 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_memory.h      2008-10-13 14:54:20.000000000 +0200
14228 @@ -0,0 +1,159 @@
14229 +#ifndef _VS_MEMORY_H
14230 +#define _VS_MEMORY_H
14231 +
14232 +#include "vserver/limit.h"
14233 +#include "vserver/base.h"
14234 +#include "vserver/context.h"
14235 +#include "vserver/debug.h"
14236 +#include "vserver/context.h"
14237 +#include "vserver/limit_int.h"
14238 +
14239 +
14240 +#define __acc_add_long(a, v)   (*(v) += (a))
14241 +#define __acc_inc_long(v)      (++*(v))
14242 +#define __acc_dec_long(v)      (--*(v))
14243 +
14244 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14245 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14246 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14247 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14248 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14249 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14250 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14251 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14252 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14253 +
14254 +
14255 +#define vx_acc_page(m, d, v, r) do {                                   \
14256 +       if ((d) > 0)                                                    \
14257 +               __acc_inc_long(&(m)->v);                                \
14258 +       else                                                            \
14259 +               __acc_dec_long(&(m)->v);                                \
14260 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14261 +} while (0)
14262 +
14263 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14264 +       if ((d) > 0)                                                    \
14265 +               __acc_inc_atomic(&(m)->v);                              \
14266 +       else                                                            \
14267 +               __acc_dec_atomic(&(m)->v);                              \
14268 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14269 +} while (0)
14270 +
14271 +
14272 +#define vx_acc_pages(m, p, v, r) do {                                  \
14273 +       unsigned long __p = (p);                                        \
14274 +       __acc_add_long(__p, &(m)->v);                                   \
14275 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14276 +} while (0)
14277 +
14278 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14279 +       unsigned long __p = (p);                                        \
14280 +       __acc_add_atomic(__p, &(m)->v);                                 \
14281 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14282 +} while (0)
14283 +
14284 +
14285 +
14286 +#define vx_acc_vmpage(m, d) \
14287 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14288 +#define vx_acc_vmlpage(m, d) \
14289 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14290 +#define vx_acc_file_rsspage(m, d) \
14291 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14292 +#define vx_acc_anon_rsspage(m, d) \
14293 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14294 +
14295 +#define vx_acc_vmpages(m, p) \
14296 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14297 +#define vx_acc_vmlpages(m, p) \
14298 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14299 +#define vx_acc_file_rsspages(m, p) \
14300 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14301 +#define vx_acc_anon_rsspages(m, p) \
14302 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14303 +
14304 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14305 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14306 +
14307 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14308 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14309 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14310 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14311 +
14312 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14313 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14314 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14315 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14316 +
14317 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14318 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14319 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14320 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14321 +
14322 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14323 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14324 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14325 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14326 +
14327 +
14328 +#define vx_pages_avail(m, p, r) \
14329 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14330 +
14331 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14332 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14333 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14334 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14335 +
14336 +#define vx_rss_avail(m, p) \
14337 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14338 +
14339 +
14340 +enum {
14341 +       VXPT_UNKNOWN = 0,
14342 +       VXPT_ANON,
14343 +       VXPT_NONE,
14344 +       VXPT_FILE,
14345 +       VXPT_SWAP,
14346 +       VXPT_WRITE
14347 +};
14348 +
14349 +#if 0
14350 +#define        vx_page_fault(mm, vma, type, ret)
14351 +#else
14352 +
14353 +static inline
14354 +void __vx_page_fault(struct mm_struct *mm,
14355 +       struct vm_area_struct *vma, int type, int ret)
14356 +{
14357 +       struct vx_info *vxi = mm->mm_vx_info;
14358 +       int what;
14359 +/*
14360 +       static char *page_type[6] =
14361 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14362 +       static char *page_what[4] =
14363 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14364 +*/
14365 +
14366 +       if (!vxi)
14367 +               return;
14368 +
14369 +       what = (ret & 0x3);
14370 +
14371 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14372 +               type, what, ret, page_type[type], page_what[what]);
14373 +*/
14374 +       if (ret & VM_FAULT_WRITE)
14375 +               what |= 0x4;
14376 +       atomic_inc(&vxi->cacct.page[type][what]);
14377 +}
14378 +
14379 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14380 +#endif
14381 +
14382 +
14383 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14384 +
14385 +#else
14386 +#warning duplicate inclusion
14387 +#endif
14388 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_network.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_network.h
14389 --- linux-2.6.27.10/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
14390 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_network.h     2008-10-13 14:54:20.000000000 +0200
14391 @@ -0,0 +1,169 @@
14392 +#ifndef _NX_VS_NETWORK_H
14393 +#define _NX_VS_NETWORK_H
14394 +
14395 +#include "vserver/context.h"
14396 +#include "vserver/network.h"
14397 +#include "vserver/base.h"
14398 +#include "vserver/check.h"
14399 +#include "vserver/debug.h"
14400 +
14401 +#include <linux/sched.h>
14402 +
14403 +
14404 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14405 +
14406 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14407 +       const char *_file, int _line)
14408 +{
14409 +       if (!nxi)
14410 +               return NULL;
14411 +
14412 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14413 +               nxi, nxi ? nxi->nx_id : 0,
14414 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14415 +               _file, _line);
14416 +
14417 +       atomic_inc(&nxi->nx_usecnt);
14418 +       return nxi;
14419 +}
14420 +
14421 +
14422 +extern void free_nx_info(struct nx_info *);
14423 +
14424 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14425 +
14426 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14427 +{
14428 +       if (!nxi)
14429 +               return;
14430 +
14431 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14432 +               nxi, nxi ? nxi->nx_id : 0,
14433 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14434 +               _file, _line);
14435 +
14436 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14437 +               free_nx_info(nxi);
14438 +}
14439 +
14440 +
14441 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14442 +
14443 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14444 +               const char *_file, int _line)
14445 +{
14446 +       if (nxi) {
14447 +               vxlprintk(VXD_CBIT(nid, 3),
14448 +                       "init_nx_info(%p[#%d.%d])",
14449 +                       nxi, nxi ? nxi->nx_id : 0,
14450 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14451 +                       _file, _line);
14452 +
14453 +               atomic_inc(&nxi->nx_usecnt);
14454 +       }
14455 +       *nxp = nxi;
14456 +}
14457 +
14458 +
14459 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14460 +
14461 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14462 +       const char *_file, int _line)
14463 +{
14464 +       struct nx_info *nxo;
14465 +
14466 +       if (!nxi)
14467 +               return;
14468 +
14469 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14470 +               nxi, nxi ? nxi->nx_id : 0,
14471 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14472 +               _file, _line);
14473 +
14474 +       atomic_inc(&nxi->nx_usecnt);
14475 +       nxo = xchg(nxp, nxi);
14476 +       BUG_ON(nxo);
14477 +}
14478 +
14479 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14480 +
14481 +static inline void __clr_nx_info(struct nx_info **nxp,
14482 +       const char *_file, int _line)
14483 +{
14484 +       struct nx_info *nxo;
14485 +
14486 +       nxo = xchg(nxp, NULL);
14487 +       if (!nxo)
14488 +               return;
14489 +
14490 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14491 +               nxo, nxo ? nxo->nx_id : 0,
14492 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14493 +               _file, _line);
14494 +
14495 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14496 +               free_nx_info(nxo);
14497 +}
14498 +
14499 +
14500 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14501 +
14502 +static inline void __claim_nx_info(struct nx_info *nxi,
14503 +       struct task_struct *task, const char *_file, int _line)
14504 +{
14505 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14506 +               nxi, nxi ? nxi->nx_id : 0,
14507 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14508 +               nxi?atomic_read(&nxi->nx_tasks):0,
14509 +               task, _file, _line);
14510 +
14511 +       atomic_inc(&nxi->nx_tasks);
14512 +}
14513 +
14514 +
14515 +extern void unhash_nx_info(struct nx_info *);
14516 +
14517 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14518 +
14519 +static inline void __release_nx_info(struct nx_info *nxi,
14520 +       struct task_struct *task, const char *_file, int _line)
14521 +{
14522 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14523 +               nxi, nxi ? nxi->nx_id : 0,
14524 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14525 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14526 +               task, _file, _line);
14527 +
14528 +       might_sleep();
14529 +
14530 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14531 +               unhash_nx_info(nxi);
14532 +}
14533 +
14534 +
14535 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14536 +
14537 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14538 +       const char *_file, int _line)
14539 +{
14540 +       struct nx_info *nxi;
14541 +
14542 +       task_lock(p);
14543 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14544 +               p, _file, _line);
14545 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14546 +       task_unlock(p);
14547 +       return nxi;
14548 +}
14549 +
14550 +
14551 +static inline void exit_nx_info(struct task_struct *p)
14552 +{
14553 +       if (p->nx_info)
14554 +               release_nx_info(p->nx_info, p);
14555 +}
14556 +
14557 +
14558 +#else
14559 +#warning duplicate inclusion
14560 +#endif
14561 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_pid.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_pid.h
14562 --- linux-2.6.27.10/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
14563 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_pid.h 2008-10-13 14:54:20.000000000 +0200
14564 @@ -0,0 +1,95 @@
14565 +#ifndef _VS_PID_H
14566 +#define _VS_PID_H
14567 +
14568 +#include "vserver/base.h"
14569 +#include "vserver/check.h"
14570 +#include "vserver/context.h"
14571 +#include "vserver/debug.h"
14572 +#include "vserver/pid.h"
14573 +#include <linux/pid_namespace.h>
14574 +
14575 +
14576 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14577 +
14578 +static inline
14579 +int vx_proc_task_visible(struct task_struct *task)
14580 +{
14581 +       if ((task->pid == 1) &&
14582 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14583 +               /* show a blend through init */
14584 +               goto visible;
14585 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14586 +               goto visible;
14587 +       return 0;
14588 +visible:
14589 +       return 1;
14590 +}
14591 +
14592 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14593 +
14594 +#if 0
14595 +
14596 +static inline
14597 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14598 +{
14599 +       struct task_struct *task = find_task_by_real_pid(pid);
14600 +
14601 +       if (task && !vx_proc_task_visible(task)) {
14602 +               vxdprintk(VXD_CBIT(misc, 6),
14603 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14604 +                       task, task->xid, task->pid,
14605 +                       current, current->xid, current->pid);
14606 +               task = NULL;
14607 +       }
14608 +       return task;
14609 +}
14610 +
14611 +#endif
14612 +
14613 +static inline
14614 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14615 +{
14616 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14617 +
14618 +       if (task && !vx_proc_task_visible(task)) {
14619 +               vxdprintk(VXD_CBIT(misc, 6),
14620 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14621 +                       task, task->xid, task->pid,
14622 +                       current, current->xid, current->pid);
14623 +               put_task_struct(task);
14624 +               task = NULL;
14625 +       }
14626 +       return task;
14627 +}
14628 +
14629 +#if 0
14630 +
14631 +static inline
14632 +struct task_struct *vx_child_reaper(struct task_struct *p)
14633 +{
14634 +       struct vx_info *vxi = p->vx_info;
14635 +       struct task_struct *reaper = child_reaper(p);
14636 +
14637 +       if (!vxi)
14638 +               goto out;
14639 +
14640 +       BUG_ON(!p->vx_info->vx_reaper);
14641 +
14642 +       /* child reaper for the guest reaper */
14643 +       if (vxi->vx_reaper == p)
14644 +               goto out;
14645 +
14646 +       reaper = vxi->vx_reaper;
14647 +out:
14648 +       vxdprintk(VXD_CBIT(xid, 7),
14649 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14650 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14651 +       return reaper;
14652 +}
14653 +
14654 +#endif
14655 +
14656 +
14657 +#else
14658 +#warning duplicate inclusion
14659 +#endif
14660 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_sched.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_sched.h
14661 --- linux-2.6.27.10/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
14662 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_sched.h       2008-10-13 14:54:20.000000000 +0200
14663 @@ -0,0 +1,110 @@
14664 +#ifndef _VS_SCHED_H
14665 +#define _VS_SCHED_H
14666 +
14667 +#include "vserver/base.h"
14668 +#include "vserver/context.h"
14669 +#include "vserver/sched.h"
14670 +
14671 +
14672 +#define VAVAVOOM_RATIO          50
14673 +
14674 +#define MAX_PRIO_BIAS           20
14675 +#define MIN_PRIO_BIAS          -20
14676 +
14677 +
14678 +#ifdef CONFIG_VSERVER_HARDCPU
14679 +
14680 +/*
14681 + * effective_prio - return the priority that is based on the static
14682 + * priority but is modified by bonuses/penalties.
14683 + *
14684 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14685 + * into a -4 ... 0 ... +4 bonus/penalty range.
14686 + *
14687 + * Additionally, we scale another amount based on the number of
14688 + * CPU tokens currently held by the context, if the process is
14689 + * part of a context (and the appropriate SCHED flag is set).
14690 + * This ranges from -5 ... 0 ... +15, quadratically.
14691 + *
14692 + * So, the total bonus is -9 .. 0 .. +19
14693 + * We use ~50% of the full 0...39 priority range so that:
14694 + *
14695 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14696 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14697 + *    unless that context is far exceeding its CPU allocation.
14698 + *
14699 + * Both properties are important to certain workloads.
14700 + */
14701 +static inline
14702 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14703 +{
14704 +       int vavavoom, max;
14705 +
14706 +       /* lots of tokens = lots of vavavoom
14707 +        *      no tokens = no vavavoom      */
14708 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14709 +               max = sched_pc->tokens_max;
14710 +               vavavoom = max - vavavoom;
14711 +               max = max * max;
14712 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14713 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14714 +               return vavavoom;
14715 +       }
14716 +       return 0;
14717 +}
14718 +
14719 +
14720 +static inline
14721 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14722 +{
14723 +       struct vx_info *vxi = p->vx_info;
14724 +       struct _vx_sched_pc *sched_pc;
14725 +
14726 +       if (!vxi)
14727 +               return prio;
14728 +
14729 +       sched_pc = &vx_cpu(vxi, sched_pc);
14730 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14731 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14732 +
14733 +               sched_pc->vavavoom = vavavoom;
14734 +               prio += vavavoom;
14735 +       }
14736 +       prio += sched_pc->prio_bias;
14737 +       return prio;
14738 +}
14739 +
14740 +#else /* !CONFIG_VSERVER_HARDCPU */
14741 +
14742 +static inline
14743 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14744 +{
14745 +       struct vx_info *vxi = p->vx_info;
14746 +
14747 +       if (vxi)
14748 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14749 +       return prio;
14750 +}
14751 +
14752 +#endif /* CONFIG_VSERVER_HARDCPU */
14753 +
14754 +
14755 +static inline void vx_account_user(struct vx_info *vxi,
14756 +       cputime_t cputime, int nice)
14757 +{
14758 +       if (!vxi)
14759 +               return;
14760 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14761 +}
14762 +
14763 +static inline void vx_account_system(struct vx_info *vxi,
14764 +       cputime_t cputime, int idle)
14765 +{
14766 +       if (!vxi)
14767 +               return;
14768 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14769 +}
14770 +
14771 +#else
14772 +#warning duplicate inclusion
14773 +#endif
14774 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_socket.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_socket.h
14775 --- linux-2.6.27.10/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
14776 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_socket.h      2008-10-13 14:54:20.000000000 +0200
14777 @@ -0,0 +1,67 @@
14778 +#ifndef _VS_SOCKET_H
14779 +#define _VS_SOCKET_H
14780 +
14781 +#include "vserver/debug.h"
14782 +#include "vserver/base.h"
14783 +#include "vserver/cacct.h"
14784 +#include "vserver/context.h"
14785 +#include "vserver/tag.h"
14786 +
14787 +
14788 +/* socket accounting */
14789 +
14790 +#include <linux/socket.h>
14791 +
14792 +static inline int vx_sock_type(int family)
14793 +{
14794 +       switch (family) {
14795 +       case PF_UNSPEC:
14796 +               return VXA_SOCK_UNSPEC;
14797 +       case PF_UNIX:
14798 +               return VXA_SOCK_UNIX;
14799 +       case PF_INET:
14800 +               return VXA_SOCK_INET;
14801 +       case PF_INET6:
14802 +               return VXA_SOCK_INET6;
14803 +       case PF_PACKET:
14804 +               return VXA_SOCK_PACKET;
14805 +       default:
14806 +               return VXA_SOCK_OTHER;
14807 +       }
14808 +}
14809 +
14810 +#define vx_acc_sock(v, f, p, s) \
14811 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14812 +
14813 +static inline void __vx_acc_sock(struct vx_info *vxi,
14814 +       int family, int pos, int size, char *file, int line)
14815 +{
14816 +       if (vxi) {
14817 +               int type = vx_sock_type(family);
14818 +
14819 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14820 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14821 +       }
14822 +}
14823 +
14824 +#define vx_sock_recv(sk, s) \
14825 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14826 +#define vx_sock_send(sk, s) \
14827 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14828 +#define vx_sock_fail(sk, s) \
14829 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14830 +
14831 +
14832 +#define sock_vx_init(s) do {           \
14833 +       (s)->sk_xid = 0;                \
14834 +       (s)->sk_vx_info = NULL;         \
14835 +       } while (0)
14836 +
14837 +#define sock_nx_init(s) do {           \
14838 +       (s)->sk_nid = 0;                \
14839 +       (s)->sk_nx_info = NULL;         \
14840 +       } while (0)
14841 +
14842 +#else
14843 +#warning duplicate inclusion
14844 +#endif
14845 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_tag.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_tag.h
14846 --- linux-2.6.27.10/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
14847 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_tag.h 2008-10-24 03:34:52.000000000 +0200
14848 @@ -0,0 +1,47 @@
14849 +#ifndef _VS_TAG_H
14850 +#define _VS_TAG_H
14851 +
14852 +#include <linux/vserver/tag.h>
14853 +
14854 +/* check conditions */
14855 +
14856 +#define DX_ADMIN       0x0001
14857 +#define DX_WATCH       0x0002
14858 +#define DX_HOSTID      0x0008
14859 +
14860 +#define DX_IDENT       0x0010
14861 +
14862 +#define DX_ARG_MASK    0x0010
14863 +
14864 +
14865 +#define dx_task_tag(t) ((t)->tag)
14866 +
14867 +#define dx_current_tag() dx_task_tag(current)
14868 +
14869 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14870 +
14871 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14872 +
14873 +
14874 +/*
14875 + * check current context for ADMIN/WATCH and
14876 + * optionally against supplied argument
14877 + */
14878 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14879 +{
14880 +       if (mode & DX_ARG_MASK) {
14881 +               if ((mode & DX_IDENT) && (id == cid))
14882 +                       return 1;
14883 +       }
14884 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14885 +               ((mode & DX_WATCH) && (cid == 1)) ||
14886 +               ((mode & DX_HOSTID) && (id == 0)));
14887 +}
14888 +
14889 +struct inode;
14890 +int dx_permission(struct inode *inode, int mask);
14891 +
14892 +
14893 +#else
14894 +#warning duplicate inclusion
14895 +#endif
14896 diff -NurpP --minimal linux-2.6.27.10/include/linux/vs_time.h linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_time.h
14897 --- linux-2.6.27.10/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
14898 +++ linux-2.6.27.10-vs2.3.0.36.4/include/linux/vs_time.h        2008-10-13 14:54:20.000000000 +0200
14899 @@ -0,0 +1,19 @@
14900 +#ifndef _VS_TIME_H
14901 +#define _VS_TIME_H
14902 +
14903 +
14904 +/* time faking stuff */
14905 +
14906 +#ifdef CONFIG_VSERVER_VTIME
14907 +
14908 +extern void vx_gettimeofday(struct timeval *tv);
14909 +extern int vx_settimeofday(struct timespec *ts);
14910 +
14911 +#else
14912 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14913 +#define        vx_settimeofday(t)      do_settimeofday(t)
14914 +#endif
14915 +
14916 +#else
14917 +#warning duplicate inclusion
14918 +#endif
14919 diff -NurpP --minimal linux-2.6.27.10/include/net/addrconf.h linux-2.6.27.10-vs2.3.0.36.4/include/net/addrconf.h
14920 --- linux-2.6.27.10/include/net/addrconf.h      2008-10-13 14:52:09.000000000 +0200
14921 +++ linux-2.6.27.10-vs2.3.0.36.4/include/net/addrconf.h 2008-10-13 14:54:20.000000000 +0200
14922 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14923                                                struct net_device *dev,
14924                                                const struct in6_addr *daddr,
14925                                                unsigned int srcprefs,
14926 -                                              struct in6_addr *saddr);
14927 +                                              struct in6_addr *saddr,
14928 +                                              struct nx_info *nxi);
14929  extern int                     ipv6_get_lladdr(struct net_device *dev,
14930                                                 struct in6_addr *addr,
14931                                                 unsigned char banned_flags);
14932 diff -NurpP --minimal linux-2.6.27.10/include/net/af_unix.h linux-2.6.27.10-vs2.3.0.36.4/include/net/af_unix.h
14933 --- linux-2.6.27.10/include/net/af_unix.h       2008-12-19 12:03:14.000000000 +0100
14934 +++ linux-2.6.27.10-vs2.3.0.36.4/include/net/af_unix.h  2008-12-08 04:52:52.000000000 +0100
14935 @@ -4,6 +4,7 @@
14936  #include <linux/socket.h>
14937  #include <linux/un.h>
14938  #include <linux/mutex.h>
14939 +#include <linux/vs_base.h>
14940  #include <net/sock.h>
14941  
14942  extern void unix_inflight(struct file *fp);
14943 diff -NurpP --minimal linux-2.6.27.10/include/net/inet_sock.h linux-2.6.27.10-vs2.3.0.36.4/include/net/inet_sock.h
14944 --- linux-2.6.27.10/include/net/inet_sock.h     2008-10-13 14:52:09.000000000 +0200
14945 +++ linux-2.6.27.10-vs2.3.0.36.4/include/net/inet_sock.h        2008-10-13 14:54:20.000000000 +0200
14946 @@ -24,7 +24,7 @@
14947  #include <net/flow.h>
14948  #include <net/sock.h>
14949  #include <net/request_sock.h>
14950 -#include <net/route.h>
14951 +// #include <net/route.h>
14952  #include <net/netns/hash.h>
14953  
14954  /** struct ip_options - IP Options
14955 @@ -195,11 +195,6 @@ static inline int inet_sk_ehashfn(const 
14956  }
14957  
14958  
14959 -static inline int inet_iif(const struct sk_buff *skb)
14960 -{
14961 -       return skb->rtable->rt_iif;
14962 -}
14963 -
14964  static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
14965  {
14966         struct request_sock *req = reqsk_alloc(ops);
14967 diff -NurpP --minimal linux-2.6.27.10/include/net/inet_timewait_sock.h linux-2.6.27.10-vs2.3.0.36.4/include/net/inet_timewait_sock.h
14968 --- linux-2.6.27.10/include/net/inet_timewait_sock.h    2008-10-13 14:52:09.000000000 +0200
14969 +++ linux-2.6.27.10-vs2.3.0.36.4/include/net/inet_timewait_sock.h       2008-10-13 14:54:20.000000000 +0200
14970 @@ -15,15 +15,14 @@
14971  #ifndef _INET_TIMEWAIT_SOCK_
14972  #define _INET_TIMEWAIT_SOCK_
14973  
14974 +// #include <net/inet_sock.h>
14975 +#include <net/sock.h>
14976  
14977  #include <linux/list.h>
14978  #include <linux/module.h>
14979  #include <linux/timer.h>
14980  #include <linux/types.h>
14981  #include <linux/workqueue.h>
14982 -
14983 -#include <net/inet_sock.h>
14984 -#include <net/sock.h>
14985  #include <net/tcp_states.h>
14986  #include <net/timewait_sock.h>
14987  
14988 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14989  #define tw_hash                        __tw_common.skc_hash
14990  #define tw_prot                        __tw_common.skc_prot
14991  #define tw_net                 __tw_common.skc_net
14992 +#define tw_xid                 __tw_common.skc_xid
14993 +#define tw_vx_info             __tw_common.skc_vx_info
14994 +#define tw_nid                 __tw_common.skc_nid
14995 +#define tw_nx_info             __tw_common.skc_nx_info
14996         int                     tw_timeout;
14997         volatile unsigned char  tw_substate;
14998         /* 3 bits hole, try to pack */
14999 diff -NurpP --minimal linux-2.6.27.10/include/net/route.h linux-2.6.27.10-vs2.3.0.36.4/include/net/route.h
15000 --- linux-2.6.27.10/include/net/route.h 2008-10-13 14:52:09.000000000 +0200
15001 +++ linux-2.6.27.10-vs2.3.0.36.4/include/net/route.h    2008-10-13 14:54:20.000000000 +0200
15002 @@ -28,6 +28,7 @@
15003  #include <net/inetpeer.h>
15004  #include <net/flow.h>
15005  #include <net/sock.h>
15006 +// #include <linux/in.h>
15007  #include <linux/in_route.h>
15008  #include <linux/rtnetlink.h>
15009  #include <linux/route.h>
15010 @@ -85,6 +86,11 @@ struct ip_rt_acct
15011         __u32   i_packets;
15012  };
15013  
15014 +static inline int inet_iif(const struct sk_buff *skb)
15015 +{
15016 +       return skb->rtable->rt_iif;
15017 +}
15018 +
15019  struct rt_cache_stat 
15020  {
15021          unsigned int in_hit;
15022 @@ -135,6 +141,9 @@ static inline void ip_rt_put(struct rtab
15023                 dst_release(&rt->u.dst);
15024  }
15025  
15026 +#include <linux/vs_base.h>
15027 +#include <linux/vs_inet.h>
15028 +
15029  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
15030  
15031  extern const __u8 ip_tos2prio[16];
15032 @@ -144,6 +153,9 @@ static inline char rt_tos2priority(u8 to
15033         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15034  }
15035  
15036 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
15037 +       struct rtable **, struct flowi *);
15038 +
15039  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15040                                    __be32 src, u32 tos, int oif, u8 protocol,
15041                                    __be16 sport, __be16 dport, struct sock *sk,
15042 @@ -161,7 +173,21 @@ static inline int ip_route_connect(struc
15043  
15044         int err;
15045         struct net *net = sock_net(sk);
15046 -       if (!dst || !src) {
15047 +       struct nx_info *nx_info = current->nx_info;
15048 +
15049 +       if (sk)
15050 +               nx_info = sk->sk_nx_info;
15051 +
15052 +       vxdprintk(VXD_CBIT(net, 4),
15053 +               "ip_route_connect(%p) %p,%p;%lx",
15054 +               sk, nx_info, sk->sk_socket,
15055 +               (sk->sk_socket?sk->sk_socket->flags:0));
15056 +
15057 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
15058 +       if (err)
15059 +               return err;
15060 +
15061 +       if (!fl.fl4_dst || !fl.fl4_src) {
15062                 err = __ip_route_output_key(net, rp, &fl);
15063                 if (err)
15064                         return err;
15065 diff -NurpP --minimal linux-2.6.27.10/include/net/sock.h linux-2.6.27.10-vs2.3.0.36.4/include/net/sock.h
15066 --- linux-2.6.27.10/include/net/sock.h  2008-10-13 14:52:09.000000000 +0200
15067 +++ linux-2.6.27.10-vs2.3.0.36.4/include/net/sock.h     2008-10-13 14:54:20.000000000 +0200
15068 @@ -128,6 +128,10 @@ struct sock_common {
15069  #ifdef CONFIG_NET_NS
15070         struct net              *skc_net;
15071  #endif
15072 +       xid_t                   skc_xid;
15073 +       struct vx_info          *skc_vx_info;
15074 +       nid_t                   skc_nid;
15075 +       struct nx_info          *skc_nx_info;
15076  };
15077  
15078  /**
15079 @@ -211,6 +215,10 @@ struct sock {
15080  #define sk_hash                        __sk_common.skc_hash
15081  #define sk_prot                        __sk_common.skc_prot
15082  #define sk_net                 __sk_common.skc_net
15083 +#define sk_xid                 __sk_common.skc_xid
15084 +#define sk_vx_info             __sk_common.skc_vx_info
15085 +#define sk_nid                 __sk_common.skc_nid
15086 +#define sk_nx_info             __sk_common.skc_nx_info
15087         unsigned char           sk_shutdown : 2,
15088                                 sk_no_check : 2,
15089                                 sk_userlocks : 4;
15090 diff -NurpP --minimal linux-2.6.27.10/init/main.c linux-2.6.27.10-vs2.3.0.36.4/init/main.c
15091 --- linux-2.6.27.10/init/main.c 2008-10-13 14:52:09.000000000 +0200
15092 +++ linux-2.6.27.10-vs2.3.0.36.4/init/main.c    2008-10-13 14:54:20.000000000 +0200
15093 @@ -60,6 +60,7 @@
15094  #include <linux/sched.h>
15095  #include <linux/signal.h>
15096  #include <linux/idr.h>
15097 +#include <linux/vserver/percpu.h>
15098  
15099  #include <asm/io.h>
15100  #include <asm/bugs.h>
15101 @@ -391,12 +392,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15102  
15103  static void __init setup_per_cpu_areas(void)
15104  {
15105 -       unsigned long size, i;
15106 +       unsigned long size, vspc, i;
15107         char *ptr;
15108         unsigned long nr_possible_cpus = num_possible_cpus();
15109  
15110 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15111 +
15112         /* Copy section for each CPU (we discard the original) */
15113 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15114 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15115         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15116  
15117         for_each_possible_cpu(i) {
15118 diff -NurpP --minimal linux-2.6.27.10/ipc/mqueue.c linux-2.6.27.10-vs2.3.0.36.4/ipc/mqueue.c
15119 --- linux-2.6.27.10/ipc/mqueue.c        2008-10-13 14:52:09.000000000 +0200
15120 +++ linux-2.6.27.10-vs2.3.0.36.4/ipc/mqueue.c   2008-10-13 14:54:20.000000000 +0200
15121 @@ -31,6 +31,8 @@
15122  #include <linux/mutex.h>
15123  #include <linux/nsproxy.h>
15124  #include <linux/pid.h>
15125 +#include <linux/vs_context.h>
15126 +#include <linux/vs_limit.h>
15127  
15128  #include <net/sock.h>
15129  #include "util.h"
15130 @@ -71,6 +73,7 @@ struct mqueue_inode_info {
15131         struct sigevent notify;
15132         struct pid* notify_owner;
15133         struct user_struct *user;       /* user who created, for accounting */
15134 +       struct vx_info *vxi;
15135         struct sock *notify_sock;
15136         struct sk_buff *notify_cookie;
15137  
15138 @@ -119,6 +122,7 @@ static struct inode *mqueue_get_inode(st
15139                         struct mqueue_inode_info *info;
15140                         struct task_struct *p = current;
15141                         struct user_struct *u = p->user;
15142 +                       struct vx_info *vxi = p->vx_info;
15143                         unsigned long mq_bytes, mq_msg_tblsz;
15144  
15145                         inode->i_fop = &mqueue_file_operations;
15146 @@ -133,6 +137,7 @@ static struct inode *mqueue_get_inode(st
15147                         info->notify_owner = NULL;
15148                         info->qsize = 0;
15149                         info->user = NULL;      /* set when all is ok */
15150 +                       info->vxi = NULL;
15151                         memset(&info->attr, 0, sizeof(info->attr));
15152                         info->attr.mq_maxmsg = DFLT_MSGMAX;
15153                         info->attr.mq_msgsize = DFLT_MSGSIZEMAX;
15154 @@ -147,22 +152,26 @@ static struct inode *mqueue_get_inode(st
15155                         spin_lock(&mq_lock);
15156                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15157                             u->mq_bytes + mq_bytes >
15158 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15159 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15160 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
15161                                 spin_unlock(&mq_lock);
15162                                 goto out_inode;
15163                         }
15164                         u->mq_bytes += mq_bytes;
15165 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
15166                         spin_unlock(&mq_lock);
15167  
15168                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15169                         if (!info->messages) {
15170                                 spin_lock(&mq_lock);
15171                                 u->mq_bytes -= mq_bytes;
15172 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
15173                                 spin_unlock(&mq_lock);
15174                                 goto out_inode;
15175                         }
15176                         /* all is ok */
15177                         info->user = get_uid(u);
15178 +                       info->vxi = get_vx_info(vxi);
15179                 } else if (S_ISDIR(mode)) {
15180                         inc_nlink(inode);
15181                         /* Some things misbehave if size == 0 on a directory */
15182 @@ -253,10 +262,14 @@ static void mqueue_delete_inode(struct i
15183                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15184         user = info->user;
15185         if (user) {
15186 +               struct vx_info *vxi = info->vxi;
15187 +
15188                 spin_lock(&mq_lock);
15189                 user->mq_bytes -= mq_bytes;
15190 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15191                 queues_count--;
15192                 spin_unlock(&mq_lock);
15193 +               put_vx_info(vxi);
15194                 free_uid(user);
15195         }
15196  }
15197 diff -NurpP --minimal linux-2.6.27.10/ipc/msg.c linux-2.6.27.10-vs2.3.0.36.4/ipc/msg.c
15198 --- linux-2.6.27.10/ipc/msg.c   2008-07-13 23:51:29.000000000 +0200
15199 +++ linux-2.6.27.10-vs2.3.0.36.4/ipc/msg.c      2008-10-13 14:54:20.000000000 +0200
15200 @@ -38,6 +38,7 @@
15201  #include <linux/rwsem.h>
15202  #include <linux/nsproxy.h>
15203  #include <linux/ipc_namespace.h>
15204 +#include <linux/vs_base.h>
15205  
15206  #include <asm/current.h>
15207  #include <asm/uaccess.h>
15208 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
15209  
15210         msq->q_perm.mode = msgflg & S_IRWXUGO;
15211         msq->q_perm.key = key;
15212 +       msq->q_perm.xid = vx_current_xid();
15213  
15214         msq->q_perm.security = NULL;
15215         retval = security_msg_queue_alloc(msq);
15216 diff -NurpP --minimal linux-2.6.27.10/ipc/namespace.c linux-2.6.27.10-vs2.3.0.36.4/ipc/namespace.c
15217 --- linux-2.6.27.10/ipc/namespace.c     2008-07-13 23:51:29.000000000 +0200
15218 +++ linux-2.6.27.10-vs2.3.0.36.4/ipc/namespace.c        2008-10-13 14:54:20.000000000 +0200
15219 @@ -9,6 +9,8 @@
15220  #include <linux/rcupdate.h>
15221  #include <linux/nsproxy.h>
15222  #include <linux/slab.h>
15223 +#include <linux/vs_base.h>
15224 +#include <linux/vserver/global.h>
15225  
15226  #include "util.h"
15227  
15228 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
15229         register_ipcns_notifier(ns);
15230  
15231         kref_init(&ns->kref);
15232 +       atomic_inc(&vs_global_ipc_ns);
15233         return ns;
15234  }
15235  
15236 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
15237         sem_exit_ns(ns);
15238         msg_exit_ns(ns);
15239         shm_exit_ns(ns);
15240 +       atomic_dec(&vs_global_ipc_ns);
15241         kfree(ns);
15242         atomic_dec(&nr_ipc_ns);
15243  
15244 diff -NurpP --minimal linux-2.6.27.10/ipc/sem.c linux-2.6.27.10-vs2.3.0.36.4/ipc/sem.c
15245 --- linux-2.6.27.10/ipc/sem.c   2008-10-13 14:52:09.000000000 +0200
15246 +++ linux-2.6.27.10-vs2.3.0.36.4/ipc/sem.c      2008-10-13 14:54:20.000000000 +0200
15247 @@ -83,6 +83,8 @@
15248  #include <linux/rwsem.h>
15249  #include <linux/nsproxy.h>
15250  #include <linux/ipc_namespace.h>
15251 +#include <linux/vs_base.h>
15252 +#include <linux/vs_limit.h>
15253  
15254  #include <asm/uaccess.h>
15255  #include "util.h"
15256 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
15257  
15258         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15259         sma->sem_perm.key = key;
15260 +       sma->sem_perm.xid = vx_current_xid();
15261  
15262         sma->sem_perm.security = NULL;
15263         retval = security_sem_alloc(sma);
15264 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
15265                 return id;
15266         }
15267         ns->used_sems += nsems;
15268 +       /* FIXME: obsoleted? */
15269 +       vx_semary_inc(sma);
15270 +       vx_nsems_add(sma, nsems);
15271  
15272         sma->sem_base = (struct sem *) &sma[1];
15273         INIT_LIST_HEAD(&sma->sem_pending);
15274 diff -NurpP --minimal linux-2.6.27.10/ipc/shm.c linux-2.6.27.10-vs2.3.0.36.4/ipc/shm.c
15275 --- linux-2.6.27.10/ipc/shm.c   2008-10-13 14:52:09.000000000 +0200
15276 +++ linux-2.6.27.10-vs2.3.0.36.4/ipc/shm.c      2008-10-13 14:54:20.000000000 +0200
15277 @@ -39,6 +39,8 @@
15278  #include <linux/nsproxy.h>
15279  #include <linux/mount.h>
15280  #include <linux/ipc_namespace.h>
15281 +#include <linux/vs_context.h>
15282 +#include <linux/vs_limit.h>
15283  
15284  #include <asm/uaccess.h>
15285  
15286 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
15287   */
15288  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15289  {
15290 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15291 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15292 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15293 +
15294 +       vx_ipcshm_sub(vxi, shp, numpages);
15295 +       ns->shm_tot -= numpages;
15296 +
15297         shm_rmid(ns, shp);
15298         shm_unlock(shp);
15299         if (!is_file_hugepages(shp->shm_file))
15300 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
15301                                                 shp->mlock_user);
15302         fput (shp->shm_file);
15303         security_shm_free(shp);
15304 +       put_vx_info(vxi);
15305         ipc_rcu_putref(shp);
15306  }
15307  
15308 @@ -347,11 +355,15 @@ static int newseg(struct ipc_namespace *
15309         if (ns->shm_tot + numpages > ns->shm_ctlall)
15310                 return -ENOSPC;
15311  
15312 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15313 +               return -ENOSPC;
15314 +
15315         shp = ipc_rcu_alloc(sizeof(*shp));
15316         if (!shp)
15317                 return -ENOMEM;
15318  
15319         shp->shm_perm.key = key;
15320 +       shp->shm_perm.xid = vx_current_xid();
15321         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15322         shp->mlock_user = NULL;
15323  
15324 @@ -404,6 +416,7 @@ static int newseg(struct ipc_namespace *
15325         ns->shm_tot += numpages;
15326         error = shp->shm_perm.id;
15327         shm_unlock(shp);
15328 +       vx_ipcshm_add(current->vx_info, key, numpages);
15329         return error;
15330  
15331  no_id:
15332 diff -NurpP --minimal linux-2.6.27.10/kernel/capability.c linux-2.6.27.10-vs2.3.0.36.4/kernel/capability.c
15333 --- linux-2.6.27.10/kernel/capability.c 2008-10-13 14:52:09.000000000 +0200
15334 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/capability.c    2008-10-13 14:54:20.000000000 +0200
15335 @@ -13,6 +13,7 @@
15336  #include <linux/security.h>
15337  #include <linux/syscalls.h>
15338  #include <linux/pid_namespace.h>
15339 +#include <linux/vs_context.h>
15340  #include <asm/uaccess.h>
15341  
15342  /*
15343 @@ -166,6 +167,8 @@ static inline int cap_set_pg(int pgrp_nr
15344  
15345         pgrp = find_vpid(pgrp_nr);
15346         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
15347 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
15348 +                       continue;
15349                 target = g;
15350                 while_each_thread(g, target) {
15351                         if (!security_capset_check(target, effective,
15352 @@ -486,6 +489,8 @@ asmlinkage long sys_capset(cap_user_head
15353         return ret;
15354  }
15355  
15356 +#include <linux/vserver/base.h>
15357 +
15358  /**
15359   * capable - Determine if the current task has a superior capability in effect
15360   * @cap: The capability to be tested for
15361 @@ -498,6 +503,9 @@ asmlinkage long sys_capset(cap_user_head
15362   */
15363  int capable(int cap)
15364  {
15365 +       /* here for now so we don't require task locking */
15366 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15367 +               return 0;
15368         if (has_capability(current, cap)) {
15369                 current->flags |= PF_SUPERPRIV;
15370                 return 1;
15371 diff -NurpP --minimal linux-2.6.27.10/kernel/compat.c linux-2.6.27.10-vs2.3.0.36.4/kernel/compat.c
15372 --- linux-2.6.27.10/kernel/compat.c     2008-07-13 23:51:29.000000000 +0200
15373 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/compat.c        2008-10-13 14:54:20.000000000 +0200
15374 @@ -845,7 +845,7 @@ asmlinkage long compat_sys_time(compat_t
15375         compat_time_t i;
15376         struct timeval tv;
15377  
15378 -       do_gettimeofday(&tv);
15379 +       vx_gettimeofday(&tv);
15380         i = tv.tv_sec;
15381  
15382         if (tloc) {
15383 @@ -869,7 +869,7 @@ asmlinkage long compat_sys_stime(compat_
15384         if (err)
15385                 return err;
15386  
15387 -       do_settimeofday(&tv);
15388 +       vx_settimeofday(&tv);
15389         return 0;
15390  }
15391  
15392 diff -NurpP --minimal linux-2.6.27.10/kernel/exit.c linux-2.6.27.10-vs2.3.0.36.4/kernel/exit.c
15393 --- linux-2.6.27.10/kernel/exit.c       2008-10-13 14:52:09.000000000 +0200
15394 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/exit.c  2008-10-13 14:54:20.000000000 +0200
15395 @@ -47,6 +47,11 @@
15396  #include <linux/blkdev.h>
15397  #include <linux/task_io_accounting_ops.h>
15398  #include <linux/tracehook.h>
15399 +#include <linux/vs_limit.h>
15400 +#include <linux/vs_context.h>
15401 +#include <linux/vs_network.h>
15402 +#include <linux/vs_pid.h>
15403 +#include <linux/vserver/global.h>
15404  
15405  #include <asm/uaccess.h>
15406  #include <asm/unistd.h>
15407 @@ -485,9 +490,11 @@ static void close_files(struct files_str
15408                                         filp_close(file, files);
15409                                         cond_resched();
15410                                 }
15411 +                               vx_openfd_dec(i);
15412                         }
15413                         i++;
15414                         set >>= 1;
15415 +                       cond_resched();
15416                 }
15417         }
15418  }
15419 @@ -554,6 +561,7 @@ void put_fs_struct(struct fs_struct *fs)
15420         if (atomic_dec_and_test(&fs->count)) {
15421                 path_put(&fs->root);
15422                 path_put(&fs->pwd);
15423 +               atomic_dec(&vs_global_fs);
15424                 kmem_cache_free(fs_cachep, fs);
15425         }
15426  }
15427 @@ -1122,6 +1130,10 @@ NORET_TYPE void do_exit(long code)
15428         if (tsk->splice_pipe)
15429                 __free_pipe_info(tsk->splice_pipe);
15430  
15431 +       /* needs to stay after exit_notify() */
15432 +       exit_vx_info(tsk, code);
15433 +       exit_nx_info(tsk);
15434 +
15435         preempt_disable();
15436         /* causes final put_task_struct in finish_task_switch(). */
15437         tsk->state = TASK_DEAD;
15438 diff -NurpP --minimal linux-2.6.27.10/kernel/fork.c linux-2.6.27.10-vs2.3.0.36.4/kernel/fork.c
15439 --- linux-2.6.27.10/kernel/fork.c       2008-12-19 12:03:14.000000000 +0100
15440 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/fork.c  2008-12-19 12:09:13.000000000 +0100
15441 @@ -58,6 +58,11 @@
15442  #include <linux/tty.h>
15443  #include <linux/proc_fs.h>
15444  #include <linux/blkdev.h>
15445 +#include <linux/vs_context.h>
15446 +#include <linux/vs_network.h>
15447 +#include <linux/vs_limit.h>
15448 +#include <linux/vs_memory.h>
15449 +#include <linux/vserver/global.h>
15450  
15451  #include <asm/pgtable.h>
15452  #include <asm/pgalloc.h>
15453 @@ -135,6 +140,8 @@ void free_task(struct task_struct *tsk)
15454         prop_local_destroy_single(&tsk->dirties);
15455         free_thread_info(tsk->stack);
15456         rt_mutex_debug_task_free(tsk);
15457 +       clr_vx_info(&tsk->vx_info);
15458 +       clr_nx_info(&tsk->nx_info);
15459         free_task_struct(tsk);
15460  }
15461  EXPORT_SYMBOL(free_task);
15462 @@ -274,6 +281,8 @@ static int dup_mmap(struct mm_struct *mm
15463         mm->free_area_cache = oldmm->mmap_base;
15464         mm->cached_hole_size = ~0UL;
15465         mm->map_count = 0;
15466 +       __set_mm_counter(mm, file_rss, 0);
15467 +       __set_mm_counter(mm, anon_rss, 0);
15468         cpus_clear(mm->cpu_vm_mask);
15469         mm->mm_rb = RB_ROOT;
15470         rb_link = &mm->mm_rb.rb_node;
15471 @@ -285,7 +294,7 @@ static int dup_mmap(struct mm_struct *mm
15472  
15473                 if (mpnt->vm_flags & VM_DONTCOPY) {
15474                         long pages = vma_pages(mpnt);
15475 -                       mm->total_vm -= pages;
15476 +                       vx_vmpages_sub(mm, pages);
15477                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15478                                                                 -pages);
15479                         continue;
15480 @@ -407,8 +416,8 @@ static struct mm_struct * mm_init(struct
15481                                   : MMF_DUMP_FILTER_DEFAULT;
15482         mm->core_state = NULL;
15483         mm->nr_ptes = 0;
15484 -       set_mm_counter(mm, file_rss, 0);
15485 -       set_mm_counter(mm, anon_rss, 0);
15486 +       __set_mm_counter(mm, file_rss, 0);
15487 +       __set_mm_counter(mm, anon_rss, 0);
15488         spin_lock_init(&mm->page_table_lock);
15489         rwlock_init(&mm->ioctx_list_lock);
15490         mm->ioctx_list = NULL;
15491 @@ -419,6 +428,7 @@ static struct mm_struct * mm_init(struct
15492         if (likely(!mm_alloc_pgd(mm))) {
15493                 mm->def_flags = 0;
15494                 mmu_notifier_mm_init(mm);
15495 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15496                 return mm;
15497         }
15498  
15499 @@ -452,6 +462,7 @@ void __mmdrop(struct mm_struct *mm)
15500         mm_free_pgd(mm);
15501         destroy_context(mm);
15502         mmu_notifier_mm_destroy(mm);
15503 +       clr_vx_info(&mm->mm_vx_info);
15504         free_mm(mm);
15505  }
15506  EXPORT_SYMBOL_GPL(__mmdrop);
15507 @@ -568,6 +579,7 @@ struct mm_struct *dup_mm(struct task_str
15508                 goto fail_nomem;
15509  
15510         memcpy(mm, oldmm, sizeof(*mm));
15511 +       mm->mm_vx_info = NULL;
15512  
15513         /* Initializing for Swap token stuff */
15514         mm->token_priority = 0;
15515 @@ -601,6 +613,7 @@ fail_nocontext:
15516          * If init_new_context() failed, we cannot use mmput() to free the mm
15517          * because it calls destroy_context()
15518          */
15519 +       clr_vx_info(&mm->mm_vx_info);
15520         mm_free_pgd(mm);
15521         free_mm(mm);
15522         return NULL;
15523 @@ -664,6 +677,7 @@ static struct fs_struct *__copy_fs_struc
15524                 fs->pwd = old->pwd;
15525                 path_get(&old->pwd);
15526                 read_unlock(&old->lock);
15527 +               atomic_inc(&vs_global_fs);
15528         }
15529         return fs;
15530  }
15531 @@ -907,6 +921,8 @@ static struct task_struct *copy_process(
15532         int retval;
15533         struct task_struct *p;
15534         int cgroup_callbacks_done = 0;
15535 +       struct vx_info *vxi;
15536 +       struct nx_info *nxi;
15537  
15538         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15539                 return ERR_PTR(-EINVAL);
15540 @@ -941,12 +957,28 @@ static struct task_struct *copy_process(
15541         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15542         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15543  #endif
15544 +       init_vx_info(&p->vx_info, current->vx_info);
15545 +       init_nx_info(&p->nx_info, current->nx_info);
15546 +
15547 +       /* check vserver memory */
15548 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15549 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15550 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15551 +               else
15552 +                       goto bad_fork_free;
15553 +       }
15554 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15555 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15556 +                       goto bad_fork_cleanup_vm;
15557 +       }
15558         retval = -EAGAIN;
15559 +       if (!vx_nproc_avail(1))
15560 +               goto bad_fork_cleanup_vm;
15561         if (atomic_read(&p->user->processes) >=
15562                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15563                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15564                     p->user != current->nsproxy->user_ns->root_user)
15565 -                       goto bad_fork_free;
15566 +                       goto bad_fork_cleanup_vm;
15567         }
15568  
15569         atomic_inc(&p->user->__count);
15570 @@ -1244,6 +1276,18 @@ static struct task_struct *copy_process(
15571  
15572         total_forks++;
15573         spin_unlock(&current->sighand->siglock);
15574 +
15575 +       /* p is copy of current */
15576 +       vxi = p->vx_info;
15577 +       if (vxi) {
15578 +               claim_vx_info(vxi, p);
15579 +               atomic_inc(&vxi->cvirt.nr_threads);
15580 +               atomic_inc(&vxi->cvirt.total_forks);
15581 +               vx_nproc_inc(p);
15582 +       }
15583 +       nxi = p->nx_info;
15584 +       if (nxi)
15585 +               claim_nx_info(nxi, p);
15586         write_unlock_irq(&tasklist_lock);
15587         proc_fork_connector(p);
15588         cgroup_post_fork(p);
15589 @@ -1290,6 +1334,9 @@ bad_fork_cleanup_count:
15590         put_group_info(p->group_info);
15591         atomic_dec(&p->user->processes);
15592         free_uid(p->user);
15593 +bad_fork_cleanup_vm:
15594 +       if (p->mm && !(clone_flags & CLONE_VM))
15595 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15596  bad_fork_free:
15597         free_task(p);
15598  fork_out:
15599 diff -NurpP --minimal linux-2.6.27.10/kernel/kthread.c linux-2.6.27.10-vs2.3.0.36.4/kernel/kthread.c
15600 --- linux-2.6.27.10/kernel/kthread.c    2008-10-13 14:52:09.000000000 +0200
15601 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/kthread.c       2008-10-13 14:54:20.000000000 +0200
15602 @@ -13,6 +13,7 @@
15603  #include <linux/file.h>
15604  #include <linux/module.h>
15605  #include <linux/mutex.h>
15606 +#include <linux/vs_pid.h>
15607  
15608  #define KTHREAD_NICE_LEVEL (-5)
15609  
15610 @@ -98,7 +99,7 @@ static void create_kthread(struct kthrea
15611                 struct sched_param param = { .sched_priority = 0 };
15612                 wait_for_completion(&create->started);
15613                 read_lock(&tasklist_lock);
15614 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15615 +               create->result = find_task_by_real_pid(pid);
15616                 read_unlock(&tasklist_lock);
15617                 /*
15618                  * root may have changed our (kthreadd's) priority or CPU mask.
15619 diff -NurpP --minimal linux-2.6.27.10/kernel/Makefile linux-2.6.27.10-vs2.3.0.36.4/kernel/Makefile
15620 --- linux-2.6.27.10/kernel/Makefile     2008-12-19 12:03:14.000000000 +0100
15621 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/Makefile        2008-12-08 04:52:52.000000000 +0100
15622 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15623  CFLAGS_REMOVE_sched.o = -pg
15624  endif
15625  
15626 +obj-y += vserver/
15627  obj-$(CONFIG_PROFILING) += profile.o
15628  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15629  obj-$(CONFIG_STACKTRACE) += stacktrace.o
15630 diff -NurpP --minimal linux-2.6.27.10/kernel/nsproxy.c linux-2.6.27.10-vs2.3.0.36.4/kernel/nsproxy.c
15631 --- linux-2.6.27.10/kernel/nsproxy.c    2008-10-13 14:52:09.000000000 +0200
15632 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/nsproxy.c       2008-10-13 14:54:20.000000000 +0200
15633 @@ -19,6 +19,8 @@
15634  #include <linux/mnt_namespace.h>
15635  #include <linux/utsname.h>
15636  #include <linux/pid_namespace.h>
15637 +#include <linux/vserver/global.h>
15638 +#include <linux/vserver/debug.h>
15639  #include <net/net_namespace.h>
15640  #include <linux/ipc_namespace.h>
15641  
15642 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15643         if (ns) {
15644                 memcpy(ns, orig, sizeof(struct nsproxy));
15645                 atomic_set(&ns->count, 1);
15646 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15647 +                       orig, atomic_read(&orig->count), ns);
15648 +               atomic_inc(&vs_global_nsproxy);
15649         }
15650         return ns;
15651  }
15652 @@ -46,47 +51,51 @@ static inline struct nsproxy *clone_nspr
15653   * Return the newly created nsproxy.  Do not attach this to the task,
15654   * leave it to the caller to do proper locking and attach it to task.
15655   */
15656 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15657 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15658 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15659 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15660  {
15661         struct nsproxy *new_nsp;
15662         int err;
15663  
15664 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15665 +       vxdprintk(VXD_CBIT(space, 4),
15666 +               "unshare_namespaces(0x%08lx,%p,%p)",
15667 +               flags, orig, new_fs);
15668 +
15669 +       new_nsp = clone_nsproxy(orig);
15670         if (!new_nsp)
15671                 return ERR_PTR(-ENOMEM);
15672  
15673 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15674 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15675         if (IS_ERR(new_nsp->mnt_ns)) {
15676                 err = PTR_ERR(new_nsp->mnt_ns);
15677                 goto out_ns;
15678         }
15679  
15680 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15681 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15682         if (IS_ERR(new_nsp->uts_ns)) {
15683                 err = PTR_ERR(new_nsp->uts_ns);
15684                 goto out_uts;
15685         }
15686  
15687 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15688 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15689         if (IS_ERR(new_nsp->ipc_ns)) {
15690                 err = PTR_ERR(new_nsp->ipc_ns);
15691                 goto out_ipc;
15692         }
15693  
15694 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15695 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15696         if (IS_ERR(new_nsp->pid_ns)) {
15697                 err = PTR_ERR(new_nsp->pid_ns);
15698                 goto out_pid;
15699         }
15700  
15701 -       new_nsp->user_ns = copy_user_ns(flags, tsk->nsproxy->user_ns);
15702 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15703         if (IS_ERR(new_nsp->user_ns)) {
15704                 err = PTR_ERR(new_nsp->user_ns);
15705                 goto out_user;
15706         }
15707  
15708 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15709 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15710         if (IS_ERR(new_nsp->net_ns)) {
15711                 err = PTR_ERR(new_nsp->net_ns);
15712                 goto out_net;
15713 @@ -114,6 +123,37 @@ out_ns:
15714         return ERR_PTR(err);
15715  }
15716  
15717 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15718 +                       struct fs_struct *new_fs)
15719 +{
15720 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15721 +}
15722 +
15723 +/*
15724 + * copies the nsproxy, setting refcount to 1, and grabbing a
15725 + * reference to all contained namespaces.
15726 + */
15727 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15728 +{
15729 +       struct nsproxy *ns = clone_nsproxy(orig);
15730 +
15731 +       if (ns) {
15732 +               if (ns->mnt_ns)
15733 +                       get_mnt_ns(ns->mnt_ns);
15734 +               if (ns->uts_ns)
15735 +                       get_uts_ns(ns->uts_ns);
15736 +               if (ns->ipc_ns)
15737 +                       get_ipc_ns(ns->ipc_ns);
15738 +               if (ns->pid_ns)
15739 +                       get_pid_ns(ns->pid_ns);
15740 +               if (ns->user_ns)
15741 +                       get_user_ns(ns->user_ns);
15742 +               if (ns->net_ns)
15743 +                       get_net(ns->net_ns);
15744 +       }
15745 +       return ns;
15746 +}
15747 +
15748  /*
15749   * called from clone.  This now handles copy for nsproxy and all
15750   * namespaces therein.
15751 @@ -121,9 +161,12 @@ out_ns:
15752  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15753  {
15754         struct nsproxy *old_ns = tsk->nsproxy;
15755 -       struct nsproxy *new_ns;
15756 +       struct nsproxy *new_ns = NULL;
15757         int err = 0;
15758  
15759 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15760 +               flags, tsk, old_ns);
15761 +
15762         if (!old_ns)
15763                 return 0;
15764  
15765 @@ -160,6 +203,9 @@ int copy_namespaces(unsigned long flags,
15766  
15767  out:
15768         put_nsproxy(old_ns);
15769 +       vxdprintk(VXD_CBIT(space, 3),
15770 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15771 +               flags, tsk, old_ns, err, new_ns);
15772         return err;
15773  }
15774  
15775 @@ -175,7 +221,9 @@ void free_nsproxy(struct nsproxy *ns)
15776                 put_pid_ns(ns->pid_ns);
15777         if (ns->user_ns)
15778                 put_user_ns(ns->user_ns);
15779 -       put_net(ns->net_ns);
15780 +       if (ns->net_ns)
15781 +               put_net(ns->net_ns);
15782 +       atomic_dec(&vs_global_nsproxy);
15783         kmem_cache_free(nsproxy_cachep, ns);
15784  }
15785  
15786 @@ -188,6 +236,10 @@ int unshare_nsproxy_namespaces(unsigned 
15787  {
15788         int err = 0;
15789  
15790 +       vxdprintk(VXD_CBIT(space, 4),
15791 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15792 +               unshare_flags, current->nsproxy);
15793 +
15794         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15795                                CLONE_NEWUSER | CLONE_NEWNET)))
15796                 return 0;
15797 diff -NurpP --minimal linux-2.6.27.10/kernel/pid.c linux-2.6.27.10-vs2.3.0.36.4/kernel/pid.c
15798 --- linux-2.6.27.10/kernel/pid.c        2008-10-13 14:52:09.000000000 +0200
15799 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/pid.c   2008-10-13 14:54:20.000000000 +0200
15800 @@ -36,6 +36,8 @@
15801  #include <linux/pid_namespace.h>
15802  #include <linux/init_task.h>
15803  #include <linux/syscalls.h>
15804 +#include <linux/vs_pid.h>
15805 +#include <linux/vserver/global.h>
15806  
15807  #define pid_hashfn(nr, ns)     \
15808         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15809 @@ -305,7 +307,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15810  
15811  struct pid *find_vpid(int nr)
15812  {
15813 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15814 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15815  }
15816  EXPORT_SYMBOL_GPL(find_vpid);
15817  
15818 @@ -365,6 +367,9 @@ void transfer_pid(struct task_struct *ol
15819  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15820  {
15821         struct task_struct *result = NULL;
15822 +
15823 +       if (type == PIDTYPE_REALPID)
15824 +               type = PIDTYPE_PID;
15825         if (pid) {
15826                 struct hlist_node *first;
15827                 first = rcu_dereference(pid->tasks[type].first);
15828 @@ -388,14 +393,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15829  
15830  struct task_struct *find_task_by_vpid(pid_t vnr)
15831  {
15832 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15833 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15834                         current->nsproxy->pid_ns);
15835  }
15836  EXPORT_SYMBOL(find_task_by_vpid);
15837  
15838  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15839  {
15840 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15841 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15842  }
15843  EXPORT_SYMBOL(find_task_by_pid_ns);
15844  
15845 @@ -431,7 +436,7 @@ struct pid *find_get_pid(pid_t nr)
15846  }
15847  EXPORT_SYMBOL_GPL(find_get_pid);
15848  
15849 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15850 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15851  {
15852         struct upid *upid;
15853         pid_t nr = 0;
15854 @@ -444,6 +449,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15855         return nr;
15856  }
15857  
15858 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15859 +{
15860 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15861 +}
15862 +
15863  pid_t pid_vnr(struct pid *pid)
15864  {
15865         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15866 diff -NurpP --minimal linux-2.6.27.10/kernel/pid_namespace.c linux-2.6.27.10-vs2.3.0.36.4/kernel/pid_namespace.c
15867 --- linux-2.6.27.10/kernel/pid_namespace.c      2008-10-13 14:52:09.000000000 +0200
15868 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/pid_namespace.c 2008-10-13 14:54:20.000000000 +0200
15869 @@ -13,6 +13,7 @@
15870  #include <linux/syscalls.h>
15871  #include <linux/err.h>
15872  #include <linux/acct.h>
15873 +#include <linux/vserver/global.h>
15874  
15875  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15876  
15877 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15878                 goto out_free_map;
15879  
15880         kref_init(&ns->kref);
15881 +       atomic_inc(&vs_global_pid_ns);
15882         ns->level = level;
15883  
15884         set_bit(0, ns->pidmap[0].page);
15885 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15886  
15887         for (i = 0; i < PIDMAP_ENTRIES; i++)
15888                 kfree(ns->pidmap[i].page);
15889 +       atomic_dec(&vs_global_pid_ns);
15890         kmem_cache_free(pid_ns_cachep, ns);
15891  }
15892  
15893 diff -NurpP --minimal linux-2.6.27.10/kernel/posix-timers.c linux-2.6.27.10-vs2.3.0.36.4/kernel/posix-timers.c
15894 --- linux-2.6.27.10/kernel/posix-timers.c       2008-10-13 14:52:09.000000000 +0200
15895 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/posix-timers.c  2008-10-13 14:54:20.000000000 +0200
15896 @@ -46,6 +46,7 @@
15897  #include <linux/wait.h>
15898  #include <linux/workqueue.h>
15899  #include <linux/module.h>
15900 +#include <linux/vs_context.h>
15901  
15902  /*
15903   * Management arrays for POSIX timers.  Timers are kept in slab memory
15904 @@ -298,6 +299,12 @@ void do_schedule_next_timer(struct sigin
15905  
15906  int posix_timer_event(struct k_itimer *timr, int si_private)
15907  {
15908 +       struct vx_info_save vxis;
15909 +       struct vx_info *vxi;
15910 +       int ret;
15911 +
15912 +       vxi = task_get_vx_info(timr->it_process);
15913 +       enter_vx_info(vxi, &vxis);
15914         /*
15915          * FIXME: if ->sigq is queued we can race with
15916          * dequeue_signal()->do_schedule_next_timer().
15917 @@ -318,10 +325,11 @@ int posix_timer_event(struct k_itimer *t
15918  
15919         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
15920                 struct task_struct *leader;
15921 -               int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15922 +
15923 +               ret = send_sigqueue(timr->sigq, timr->it_process, 0);
15924  
15925                 if (likely(ret >= 0))
15926 -                       return ret;
15927 +                       goto out;
15928  
15929                 timr->it_sigev_notify = SIGEV_SIGNAL;
15930                 leader = timr->it_process->group_leader;
15931 @@ -329,7 +337,11 @@ int posix_timer_event(struct k_itimer *t
15932                 timr->it_process = leader;
15933         }
15934  
15935 -       return send_sigqueue(timr->sigq, timr->it_process, 1);
15936 +       ret = send_sigqueue(timr->sigq, timr->it_process, 1);
15937 +out:
15938 +       leave_vx_info(&vxis);
15939 +       put_vx_info(vxi);
15940 +       return ret;
15941  }
15942  EXPORT_SYMBOL_GPL(posix_timer_event);
15943  
15944 diff -NurpP --minimal linux-2.6.27.10/kernel/printk.c linux-2.6.27.10-vs2.3.0.36.4/kernel/printk.c
15945 --- linux-2.6.27.10/kernel/printk.c     2008-10-13 14:52:09.000000000 +0200
15946 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/printk.c        2008-10-13 14:54:20.000000000 +0200
15947 @@ -32,6 +32,7 @@
15948  #include <linux/security.h>
15949  #include <linux/bootmem.h>
15950  #include <linux/syscalls.h>
15951 +#include <linux/vs_cvirt.h>
15952  
15953  #include <asm/uaccess.h>
15954  
15955 @@ -291,18 +292,13 @@ int do_syslog(int type, char __user *buf
15956         unsigned i, j, limit, count;
15957         int do_clear = 0;
15958         char c;
15959 -       int error = 0;
15960 +       int error;
15961  
15962         error = security_syslog(type);
15963         if (error)
15964                 return error;
15965  
15966 -       switch (type) {
15967 -       case 0:         /* Close log */
15968 -               break;
15969 -       case 1:         /* Open log */
15970 -               break;
15971 -       case 2:         /* Read from log */
15972 +       if ((type >= 2) && (type <= 4)) {
15973                 error = -EINVAL;
15974                 if (!buf || len < 0)
15975                         goto out;
15976 @@ -313,6 +309,16 @@ int do_syslog(int type, char __user *buf
15977                         error = -EFAULT;
15978                         goto out;
15979                 }
15980 +       }
15981 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15982 +               return vx_do_syslog(type, buf, len);
15983 +
15984 +       switch (type) {
15985 +       case 0:         /* Close log */
15986 +               break;
15987 +       case 1:         /* Open log */
15988 +               break;
15989 +       case 2:         /* Read from log */
15990                 error = wait_event_interruptible(log_wait,
15991                                                         (log_start - log_end));
15992                 if (error)
15993 @@ -337,16 +343,6 @@ int do_syslog(int type, char __user *buf
15994                 do_clear = 1;
15995                 /* FALL THRU */
15996         case 3:         /* Read last kernel messages */
15997 -               error = -EINVAL;
15998 -               if (!buf || len < 0)
15999 -                       goto out;
16000 -               error = 0;
16001 -               if (!len)
16002 -                       goto out;
16003 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16004 -                       error = -EFAULT;
16005 -                       goto out;
16006 -               }
16007                 count = len;
16008                 if (count > log_buf_len)
16009                         count = log_buf_len;
16010 diff -NurpP --minimal linux-2.6.27.10/kernel/ptrace.c linux-2.6.27.10-vs2.3.0.36.4/kernel/ptrace.c
16011 --- linux-2.6.27.10/kernel/ptrace.c     2008-10-13 14:52:09.000000000 +0200
16012 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/ptrace.c        2008-10-13 14:54:20.000000000 +0200
16013 @@ -21,6 +21,7 @@
16014  #include <linux/audit.h>
16015  #include <linux/pid_namespace.h>
16016  #include <linux/syscalls.h>
16017 +#include <linux/vs_context.h>
16018  
16019  #include <asm/pgtable.h>
16020  #include <asm/uaccess.h>
16021 @@ -139,6 +140,11 @@ int __ptrace_may_access(struct task_stru
16022                 dumpable = get_dumpable(task->mm);
16023         if (!dumpable && !capable(CAP_SYS_PTRACE))
16024                 return -EPERM;
16025 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16026 +               return -EPERM;
16027 +       if (!vx_check(task->xid, VS_IDENT) &&
16028 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16029 +               return -EACCES;
16030  
16031         return security_ptrace_may_access(task, mode);
16032  }
16033 @@ -567,6 +573,10 @@ asmlinkage long sys_ptrace(long request,
16034                 goto out;
16035         }
16036  
16037 +       ret = -EPERM;
16038 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16039 +               goto out_put_task_struct;
16040 +
16041         if (request == PTRACE_ATTACH) {
16042                 ret = ptrace_attach(child);
16043                 /*
16044 diff -NurpP --minimal linux-2.6.27.10/kernel/sched.c linux-2.6.27.10-vs2.3.0.36.4/kernel/sched.c
16045 --- linux-2.6.27.10/kernel/sched.c      2008-12-19 12:03:14.000000000 +0100
16046 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sched.c 2008-12-19 12:09:14.000000000 +0100
16047 @@ -71,6 +71,8 @@
16048  #include <linux/debugfs.h>
16049  #include <linux/ctype.h>
16050  #include <linux/ftrace.h>
16051 +#include <linux/vs_sched.h>
16052 +#include <linux/vs_cvirt.h>
16053  
16054  #include <asm/tlb.h>
16055  #include <asm/irq_regs.h>
16056 @@ -497,6 +499,16 @@ struct root_domain {
16057  static struct root_domain def_root_domain;
16058  
16059  #endif
16060 +       unsigned long norm_time;
16061 +       unsigned long idle_time;
16062 +#ifdef CONFIG_VSERVER_IDLETIME
16063 +       int idle_skip;
16064 +#endif
16065 +#ifdef CONFIG_VSERVER_HARDCPU
16066 +       struct list_head hold_queue;
16067 +       unsigned long nr_onhold;
16068 +       int idle_tokens;
16069 +#endif
16070  
16071  /*
16072   * This is the main, per-CPU runqueue data structure.
16073 @@ -1640,6 +1652,7 @@ static void update_avg(u64 *avg, u64 sam
16074  
16075  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
16076  {
16077 +       // BUG_ON(p->state & TASK_ONHOLD);
16078         sched_info_queued(p);
16079         p->sched_class->enqueue_task(rq, p, wakeup);
16080         p->se.on_rq = 1;
16081 @@ -1837,6 +1850,9 @@ struct migration_req {
16082         struct completion done;
16083  };
16084  
16085 +#include "sched_mon.h"
16086 +
16087 +
16088  /*
16089   * The task's runqueue lock must be held.
16090   * Returns true if you have to wait for migration thread.
16091 @@ -1846,6 +1862,7 @@ migrate_task(struct task_struct *p, int 
16092  {
16093         struct rq *rq = task_rq(p);
16094  
16095 +       vxm_migrate_task(p, rq, dest_cpu);
16096         /*
16097          * If the task is not on a runqueue (and not running), then
16098          * it is sufficient to simply update the task's cpu field.
16099 @@ -2242,6 +2259,12 @@ static int try_to_wake_up(struct task_st
16100                 /* might preempt at this point */
16101                 rq = task_rq_lock(p, &flags);
16102                 old_state = p->state;
16103 +
16104 +       /* we need to unhold suspended tasks
16105 +       if (old_state & TASK_ONHOLD) {
16106 +               vx_unhold_task(p, rq);
16107 +               old_state = p->state;
16108 +       } */
16109                 if (!(old_state & state))
16110                         goto out;
16111                 if (p->se.on_rq)
16112 @@ -4067,13 +4090,16 @@ unsigned long long task_sched_runtime(st
16113  void account_user_time(struct task_struct *p, cputime_t cputime)
16114  {
16115         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16116 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16117         cputime64_t tmp;
16118 +       int nice = (TASK_NICE(p) > 0);
16119  
16120         p->utime = cputime_add(p->utime, cputime);
16121 +       vx_account_user(vxi, cputime, nice);
16122  
16123         /* Add user time to cpustat. */
16124         tmp = cputime_to_cputime64(cputime);
16125 -       if (TASK_NICE(p) > 0)
16126 +       if (nice)
16127                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16128         else
16129                 cpustat->user = cputime64_add(cpustat->user, tmp);
16130 @@ -4120,6 +4146,7 @@ void account_system_time(struct task_str
16131                          cputime_t cputime)
16132  {
16133         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16134 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16135         struct rq *rq = this_rq();
16136         cputime64_t tmp;
16137  
16138 @@ -4129,6 +4156,7 @@ void account_system_time(struct task_str
16139         }
16140  
16141         p->stime = cputime_add(p->stime, cputime);
16142 +       vx_account_system(vxi, cputime, (p == rq->idle));
16143  
16144         /* Add system time to cpustat. */
16145         tmp = cputime_to_cputime64(cputime);
16146 @@ -4963,7 +4991,7 @@ asmlinkage long sys_nice(int increment)
16147                 nice = 19;
16148  
16149         if (increment < 0 && !can_nice(current, nice))
16150 -               return -EPERM;
16151 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16152  
16153         retval = security_task_setnice(current, nice);
16154         if (retval)
16155 diff -NurpP --minimal linux-2.6.27.10/kernel/sched_fair.c linux-2.6.27.10-vs2.3.0.36.4/kernel/sched_fair.c
16156 --- linux-2.6.27.10/kernel/sched_fair.c 2008-10-13 14:52:09.000000000 +0200
16157 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sched_fair.c    2008-10-13 14:54:20.000000000 +0200
16158 @@ -724,6 +724,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16159         check_spread(cfs_rq, se);
16160         if (se != cfs_rq->curr)
16161                 __enqueue_entity(cfs_rq, se);
16162 +
16163 +       if (entity_is_task(se))
16164 +               vx_activate_task(task_of(se));
16165  }
16166  
16167  static void
16168 @@ -750,6 +753,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16169  
16170         if (se != cfs_rq->curr)
16171                 __dequeue_entity(cfs_rq, se);
16172 +       if (entity_is_task(se))
16173 +               vx_deactivate_task(task_of(se));
16174         account_entity_dequeue(cfs_rq, se);
16175  }
16176  
16177 diff -NurpP --minimal linux-2.6.27.10/kernel/sched_hard.h linux-2.6.27.10-vs2.3.0.36.4/kernel/sched_hard.h
16178 --- linux-2.6.27.10/kernel/sched_hard.h 1970-01-01 01:00:00.000000000 +0100
16179 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sched_hard.h    2008-10-13 14:54:20.000000000 +0200
16180 @@ -0,0 +1,324 @@
16181 +
16182 +#ifdef CONFIG_VSERVER_IDLELIMIT
16183 +
16184 +/*
16185 + * vx_idle_resched - reschedule after maxidle
16186 + */
16187 +static inline
16188 +void vx_idle_resched(struct rq *rq)
16189 +{
16190 +       /* maybe have a better criterion for paused */
16191 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16192 +               set_need_resched();
16193 +}
16194 +
16195 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16196 +
16197 +#define vx_idle_resched(rq)
16198 +
16199 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16200 +
16201 +
16202 +
16203 +#ifdef CONFIG_VSERVER_IDLETIME
16204 +
16205 +#define vx_set_rq_min_skip(rq, min)            \
16206 +       (rq)->idle_skip = (min)
16207 +
16208 +#define vx_save_min_skip(ret, min, val)                \
16209 +       __vx_save_min_skip(ret, min, val)
16210 +
16211 +static inline
16212 +void __vx_save_min_skip(int ret, int *min, int val)
16213 +{
16214 +       if (ret > -2)
16215 +               return;
16216 +       if ((*min > val) || !*min)
16217 +               *min = val;
16218 +}
16219 +
16220 +static inline
16221 +int vx_try_skip(struct rq *rq, int cpu)
16222 +{
16223 +       /* artificially advance time */
16224 +       if (rq->idle_skip > 0) {
16225 +               vxdprintk(list_empty(&rq->hold_queue),
16226 +                       "hold queue empty on cpu %d", cpu);
16227 +               rq->idle_time += rq->idle_skip;
16228 +               vxm_idle_skip(rq, cpu);
16229 +               return 1;
16230 +       }
16231 +       return 0;
16232 +}
16233 +
16234 +#else /* !CONFIG_VSERVER_IDLETIME */
16235 +
16236 +#define vx_set_rq_min_skip(rq, min)            \
16237 +       ({ int dummy = (min); dummy; })
16238 +
16239 +#define vx_save_min_skip(ret, min, val)
16240 +
16241 +static inline
16242 +int vx_try_skip(struct rq *rq, int cpu)
16243 +{
16244 +       return 0;
16245 +}
16246 +
16247 +#endif /* CONFIG_VSERVER_IDLETIME */
16248 +
16249 +
16250 +
16251 +#ifdef CONFIG_VSERVER_HARDCPU
16252 +
16253 +#define vx_set_rq_max_idle(rq, max)            \
16254 +       (rq)->idle_tokens = (max)
16255 +
16256 +#define vx_save_max_idle(ret, min, val)                \
16257 +       __vx_save_max_idle(ret, min, val)
16258 +
16259 +static inline
16260 +void __vx_save_max_idle(int ret, int *min, int val)
16261 +{
16262 +       if (*min > val)
16263 +               *min = val;
16264 +}
16265 +
16266 +
16267 +/*
16268 + * vx_hold_task - put a task on the hold queue
16269 + */
16270 +static inline
16271 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16272 +{
16273 +       __deactivate_task(p, rq);
16274 +       p->state |= TASK_ONHOLD;
16275 +       /* a new one on hold */
16276 +       rq->nr_onhold++;
16277 +       vxm_hold_task(p, rq);
16278 +       list_add_tail(&p->run_list, &rq->hold_queue);
16279 +}
16280 +
16281 +/*
16282 + * vx_unhold_task - put a task back to the runqueue
16283 + */
16284 +static inline
16285 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16286 +{
16287 +       list_del(&p->run_list);
16288 +       /* one less waiting */
16289 +       rq->nr_onhold--;
16290 +       p->state &= ~TASK_ONHOLD;
16291 +       enqueue_task(p, rq->expired);
16292 +       inc_nr_running(p, rq);
16293 +       vxm_unhold_task(p, rq);
16294 +
16295 +       if (p->static_prio < rq->best_expired_prio)
16296 +               rq->best_expired_prio = p->static_prio;
16297 +}
16298 +
16299 +unsigned long nr_onhold(void)
16300 +{
16301 +       unsigned long i, sum = 0;
16302 +
16303 +       for_each_online_cpu(i)
16304 +               sum += cpu_rq(i)->nr_onhold;
16305 +
16306 +       return sum;
16307 +}
16308 +
16309 +
16310 +
16311 +static inline
16312 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16313 +{
16314 +       return sched_pc->tokens;
16315 +}
16316 +
16317 +static inline
16318 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16319 +{
16320 +       sched_pc->tokens--;
16321 +}
16322 +
16323 +static inline
16324 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16325 +{
16326 +       struct vx_info *vxi = p->vx_info;
16327 +
16328 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16329 +               struct _vx_sched_pc *sched_pc =
16330 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16331 +               int tokens;
16332 +
16333 +               /* maybe we can simplify that to decrement
16334 +                  the token counter unconditional? */
16335 +
16336 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16337 +                       __vx_consume_token(sched_pc);
16338 +
16339 +               /* for tokens > 0, one token was consumed */
16340 +               if (tokens < 2)
16341 +                       slice = 0;
16342 +       }
16343 +       vxm_need_resched(p, slice, cpu);
16344 +       return (slice == 0);
16345 +}
16346 +
16347 +
16348 +#define vx_set_rq_time(rq, time) do {  \
16349 +       rq->norm_time = time;           \
16350 +} while (0)
16351 +
16352 +
16353 +static inline
16354 +void vx_try_unhold(struct rq *rq, int cpu)
16355 +{
16356 +       struct vx_info *vxi = NULL;
16357 +       struct list_head *l, *n;
16358 +       int maxidle = HZ;
16359 +       int minskip = 0;
16360 +
16361 +       /* nothing to do? what about pause? */
16362 +       if (list_empty(&rq->hold_queue))
16363 +               return;
16364 +
16365 +       list_for_each_safe(l, n, &rq->hold_queue) {
16366 +               int ret, delta_min[2];
16367 +               struct _vx_sched_pc *sched_pc;
16368 +               struct task_struct *p;
16369 +
16370 +               p = list_entry(l, struct task_struct, run_list);
16371 +               /* don't bother with same context */
16372 +               if (vxi == p->vx_info)
16373 +                       continue;
16374 +
16375 +               vxi = p->vx_info;
16376 +               /* ignore paused contexts */
16377 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16378 +                       continue;
16379 +
16380 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16381 +
16382 +               /* recalc tokens */
16383 +               vxm_sched_info(sched_pc, vxi, cpu);
16384 +               ret = vx_tokens_recalc(sched_pc,
16385 +                       &rq->norm_time, &rq->idle_time, delta_min);
16386 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16387 +
16388 +               if (ret > 0) {
16389 +                       /* we found a runable context */
16390 +                       vx_unhold_task(p, rq);
16391 +                       break;
16392 +               }
16393 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16394 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16395 +       }
16396 +       vx_set_rq_max_idle(rq, maxidle);
16397 +       vx_set_rq_min_skip(rq, minskip);
16398 +       vxm_rq_max_min(rq, cpu);
16399 +}
16400 +
16401 +
16402 +static inline
16403 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16404 +{
16405 +       struct vx_info *vxi = next->vx_info;
16406 +       struct _vx_sched_pc *sched_pc;
16407 +       int delta_min[2];
16408 +       int flags, ret;
16409 +
16410 +       if (!vxi)
16411 +               return 1;
16412 +
16413 +       flags = vxi->vx_flags;
16414 +
16415 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16416 +               goto put_on_hold;
16417 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16418 +               return 1;
16419 +
16420 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16421 +#ifdef CONFIG_SMP
16422 +       /* update scheduler params */
16423 +       if (cpu_isset(cpu, vxi->sched.update)) {
16424 +               vx_update_sched_param(&vxi->sched, sched_pc);
16425 +               vxm_update_sched(sched_pc, vxi, cpu);
16426 +               cpu_clear(cpu, vxi->sched.update);
16427 +       }
16428 +#endif
16429 +       vxm_sched_info(sched_pc, vxi, cpu);
16430 +       ret  = vx_tokens_recalc(sched_pc,
16431 +               &rq->norm_time, &rq->idle_time, delta_min);
16432 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16433 +
16434 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16435 +               return 1;
16436 +
16437 +       if (unlikely(ret < 0)) {
16438 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16439 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16440 +               vxm_rq_max_min(rq, cpu);
16441 +       put_on_hold:
16442 +               vx_hold_task(next, rq);
16443 +               return 0;
16444 +       }
16445 +       return 1;
16446 +}
16447 +
16448 +
16449 +#else /* CONFIG_VSERVER_HARDCPU */
16450 +
16451 +static inline
16452 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16453 +{
16454 +       return;
16455 +}
16456 +
16457 +static inline
16458 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16459 +{
16460 +       return;
16461 +}
16462 +
16463 +unsigned long nr_onhold(void)
16464 +{
16465 +       return 0;
16466 +}
16467 +
16468 +
16469 +static inline
16470 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16471 +{
16472 +       return (slice == 0);
16473 +}
16474 +
16475 +
16476 +#define vx_set_rq_time(rq, time)
16477 +
16478 +static inline
16479 +void vx_try_unhold(struct rq *rq, int cpu)
16480 +{
16481 +       return;
16482 +}
16483 +
16484 +static inline
16485 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16486 +{
16487 +       struct vx_info *vxi = next->vx_info;
16488 +       struct _vx_sched_pc *sched_pc;
16489 +       int delta_min[2];
16490 +       int ret;
16491 +
16492 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16493 +               return 1;
16494 +
16495 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16496 +       vxm_sched_info(sched_pc, vxi, cpu);
16497 +       ret  = vx_tokens_recalc(sched_pc,
16498 +               &rq->norm_time, &rq->idle_time, delta_min);
16499 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16500 +       return 1;
16501 +}
16502 +
16503 +#endif /* CONFIG_VSERVER_HARDCPU */
16504 +
16505 diff -NurpP --minimal linux-2.6.27.10/kernel/sched_mon.h linux-2.6.27.10-vs2.3.0.36.4/kernel/sched_mon.h
16506 --- linux-2.6.27.10/kernel/sched_mon.h  1970-01-01 01:00:00.000000000 +0100
16507 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sched_mon.h     2008-10-13 14:54:20.000000000 +0200
16508 @@ -0,0 +1,200 @@
16509 +
16510 +#include <linux/vserver/monitor.h>
16511 +
16512 +#ifdef  CONFIG_VSERVER_MONITOR
16513 +
16514 +#ifdef CONFIG_VSERVER_HARDCPU
16515 +#define HARDCPU(x) (x)
16516 +#else
16517 +#define HARDCPU(x) (0)
16518 +#endif
16519 +
16520 +#ifdef CONFIG_VSERVER_IDLETIME
16521 +#define IDLETIME(x) (x)
16522 +#else
16523 +#define IDLETIME(x) (0)
16524 +#endif
16525 +
16526 +struct _vx_mon_entry *vxm_advance(int cpu);
16527 +
16528 +
16529 +static inline
16530 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16531 +{
16532 +       entry->type = type;
16533 +       entry->xid = xid;
16534 +}
16535 +
16536 +static inline
16537 +void   __vxm_sync(int cpu)
16538 +{
16539 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16540 +
16541 +       __vxm_basic(entry, 0, VXM_SYNC);
16542 +       entry->ev.sec = xtime.tv_sec;
16543 +       entry->ev.nsec = xtime.tv_nsec;
16544 +}
16545 +
16546 +static inline
16547 +void   __vxm_task(struct task_struct *p, int type)
16548 +{
16549 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16550 +
16551 +       __vxm_basic(entry, p->xid, type);
16552 +       entry->ev.tsk.pid = p->pid;
16553 +       entry->ev.tsk.state = p->state;
16554 +}
16555 +
16556 +static inline
16557 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16558 +{
16559 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16560 +
16561 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16562 +       entry->sd.tokens = s->tokens;
16563 +       entry->sd.norm_time = s->norm_time;
16564 +       entry->sd.idle_time = s->idle_time;
16565 +}
16566 +
16567 +static inline
16568 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16569 +{
16570 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16571 +
16572 +       entry->type = VXM_RQINFO_1;
16573 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16574 +       entry->q1.running = q->nr_running;
16575 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16576 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16577 +       entry->q1.uintr = q->nr_uninterruptible;
16578 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16579 +}
16580 +
16581 +static inline
16582 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16583 +{
16584 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16585 +
16586 +       entry->type = VXM_RQINFO_2;
16587 +       entry->xid = (unsigned long)q & 0xffff;
16588 +       entry->q2.norm_time = q->norm_time;
16589 +       entry->q2.idle_time = q->idle_time;
16590 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16591 +}
16592 +
16593 +static inline
16594 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16595 +{
16596 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16597 +
16598 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16599 +       entry->ev.tokens = s->tokens;
16600 +}
16601 +
16602 +static inline
16603 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16604 +{
16605 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16606 +
16607 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16608 +       entry->u1.tokens_max = s->tokens_max;
16609 +       entry->u1.fill_rate = s->fill_rate[0];
16610 +       entry->u1.interval = s->interval[0];
16611 +}
16612 +
16613 +static inline
16614 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16615 +{
16616 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16617 +
16618 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16619 +       entry->u2.tokens_min = s->tokens_min;
16620 +       entry->u2.fill_rate = s->fill_rate[1];
16621 +       entry->u2.interval = s->interval[1];
16622 +}
16623 +
16624 +
16625 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16626 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16627 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16628 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16629 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16630 +
16631 +static inline
16632 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16633 +{
16634 +       __vxm_task(p, VXM_MIGRATE);
16635 +       __vxm_rqinfo1(rq, task_cpu(p));
16636 +       __vxm_rqinfo2(rq, task_cpu(p));
16637 +}
16638 +
16639 +static inline
16640 +void   vxm_idle_skip(struct rq *rq, int cpu)
16641 +{
16642 +       __vxm_rqinfo1(rq, cpu);
16643 +       __vxm_rqinfo2(rq, cpu);
16644 +}
16645 +
16646 +static inline
16647 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16648 +{
16649 +       if (slice)
16650 +               return;
16651 +
16652 +       __vxm_task(p, VXM_RESCHED);
16653 +}
16654 +
16655 +static inline
16656 +void   vxm_sync(unsigned long now, int cpu)
16657 +{
16658 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16659 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16660 +               return;
16661 +
16662 +       __vxm_sync(cpu);
16663 +}
16664 +
16665 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16666 +
16667 +static inline
16668 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16669 +       struct vx_info *vxi, int cpu)
16670 +{
16671 +       __vxm_sched(s, vxi, cpu);
16672 +       __vxm_rqinfo2(rq, cpu);
16673 +}
16674 +
16675 +static inline
16676 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16677 +{
16678 +       __vxm_sched(s, vxi, cpu);
16679 +       __vxm_update(s, vxi, cpu);
16680 +       __vxm_update1(s, vxi, cpu);
16681 +       __vxm_update2(s, vxi, cpu);
16682 +}
16683 +
16684 +static inline
16685 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16686 +{
16687 +       __vxm_rqinfo1(rq, cpu);
16688 +       __vxm_rqinfo2(rq, cpu);
16689 +}
16690 +
16691 +#else  /* CONFIG_VSERVER_MONITOR */
16692 +
16693 +#define        vxm_activate_task(t,q)          do { } while (0)
16694 +#define        vxm_activate_idle(t,q)          do { } while (0)
16695 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16696 +#define        vxm_hold_task(t,q)              do { } while (0)
16697 +#define        vxm_unhold_task(t,q)            do { } while (0)
16698 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16699 +#define        vxm_idle_skip(q,c)              do { } while (0)
16700 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16701 +#define        vxm_sync(s,c)                   do { } while (0)
16702 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16703 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16704 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16705 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16706 +
16707 +#endif /* CONFIG_VSERVER_MONITOR */
16708 +
16709 diff -NurpP --minimal linux-2.6.27.10/kernel/signal.c linux-2.6.27.10-vs2.3.0.36.4/kernel/signal.c
16710 --- linux-2.6.27.10/kernel/signal.c     2008-10-13 14:52:09.000000000 +0200
16711 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/signal.c        2008-11-22 11:37:23.000000000 +0100
16712 @@ -27,6 +27,8 @@
16713  #include <linux/freezer.h>
16714  #include <linux/pid_namespace.h>
16715  #include <linux/nsproxy.h>
16716 +#include <linux/vs_context.h>
16717 +#include <linux/vs_pid.h>
16718  
16719  #include <asm/param.h>
16720  #include <asm/uaccess.h>
16721 @@ -571,6 +573,14 @@ static int check_kill_permission(int sig
16722         if (!valid_signal(sig))
16723                 return -EINVAL;
16724  
16725 +       if ((info != SEND_SIG_NOINFO) &&
16726 +               (is_si_special(info) || !SI_FROMUSER(info)))
16727 +               goto skip;
16728 +
16729 +       vxdprintk(VXD_CBIT(misc, 7),
16730 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16731 +               sig, info, t, vx_task_xid(t), t->pid);
16732 +
16733         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16734                 return 0;
16735  
16736 @@ -595,6 +605,18 @@ static int check_kill_permission(int sig
16737                 }
16738         }
16739  
16740 +       error = -EPERM;
16741 +       if (t->pid == 1 && current->xid)
16742 +               return error;
16743 +
16744 +       error = -ESRCH;
16745 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16746 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16747 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16748 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16749 +               return error;
16750 +       }
16751 +skip:
16752         return security_task_kill(t, info, sig, 0);
16753  }
16754  
16755 @@ -1051,7 +1073,7 @@ int kill_pid_info(int sig, struct siginf
16756         rcu_read_lock();
16757  retry:
16758         p = pid_task(pid, PIDTYPE_PID);
16759 -       if (p) {
16760 +       if (p && vx_check(vx_task_xid(p), VS_ADMIN | VS_IDENT)) {
16761                 error = group_send_sig_info(sig, info, p);
16762                 if (unlikely(error == -ESRCH))
16763                         /*
16764 @@ -1089,7 +1111,7 @@ int kill_pid_info_as_uid(int sig, struct
16765  
16766         read_lock(&tasklist_lock);
16767         p = pid_task(pid, PIDTYPE_PID);
16768 -       if (!p) {
16769 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16770                 ret = -ESRCH;
16771                 goto out_unlock;
16772         }
16773 @@ -1141,7 +1163,10 @@ static int kill_something_info(int sig, 
16774                 struct task_struct * p;
16775  
16776                 for_each_process(p) {
16777 -                       if (p->pid > 1 && !same_thread_group(p, current)) {
16778 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16779 +                               task_pid_vnr(p) > 1 &&
16780 +                               !same_thread_group(p, current) &&
16781 +                               !vx_current_initpid(p->pid)) {
16782                                 int err = group_send_sig_info(sig, info, p);
16783                                 ++count;
16784                                 if (err != -EPERM)
16785 @@ -1814,6 +1839,11 @@ relock:
16786                     !signal_group_exit(signal))
16787                         continue;
16788  
16789 +               /* virtual init is protected against user signals */
16790 +               if ((info->si_code == SI_USER) &&
16791 +                       vx_current_initpid(current->pid))
16792 +                       continue;
16793 +
16794                 if (sig_kernel_stop(signr)) {
16795                         /*
16796                          * The default action is to stop all threads in
16797 diff -NurpP --minimal linux-2.6.27.10/kernel/softirq.c linux-2.6.27.10-vs2.3.0.36.4/kernel/softirq.c
16798 --- linux-2.6.27.10/kernel/softirq.c    2008-10-13 14:52:09.000000000 +0200
16799 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/softirq.c       2008-10-13 14:54:20.000000000 +0200
16800 @@ -21,6 +21,7 @@
16801  #include <linux/rcupdate.h>
16802  #include <linux/smp.h>
16803  #include <linux/tick.h>
16804 +#include <linux/vs_context.h>
16805  
16806  #include <asm/irq.h>
16807  /*
16808 diff -NurpP --minimal linux-2.6.27.10/kernel/sys.c linux-2.6.27.10-vs2.3.0.36.4/kernel/sys.c
16809 --- linux-2.6.27.10/kernel/sys.c        2008-10-13 14:52:09.000000000 +0200
16810 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sys.c   2008-10-13 14:54:20.000000000 +0200
16811 @@ -38,6 +38,7 @@
16812  #include <linux/syscalls.h>
16813  #include <linux/kprobes.h>
16814  #include <linux/user_namespace.h>
16815 +#include <linux/vs_pid.h>
16816  
16817  #include <asm/uaccess.h>
16818  #include <asm/io.h>
16819 @@ -122,7 +123,10 @@ static int set_one_prio(struct task_stru
16820                 goto out;
16821         }
16822         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16823 -               error = -EACCES;
16824 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16825 +                       error = 0;
16826 +               else
16827 +                       error = -EACCES;
16828                 goto out;
16829         }
16830         no_nice = security_task_setnice(p, niceval);
16831 @@ -170,6 +174,8 @@ asmlinkage long sys_setpriority(int whic
16832                         else
16833                                 pgrp = task_pgrp(current);
16834                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16835 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16836 +                                       continue;
16837                                 error = set_one_prio(p, niceval, error);
16838                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16839                         break;
16840 @@ -230,6 +236,8 @@ asmlinkage long sys_getpriority(int whic
16841                         else
16842                                 pgrp = task_pgrp(current);
16843                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16844 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16845 +                                       continue;
16846                                 niceval = 20 - task_nice(p);
16847                                 if (niceval > retval)
16848                                         retval = niceval;
16849 @@ -339,6 +347,9 @@ void kernel_power_off(void)
16850         machine_power_off();
16851  }
16852  EXPORT_SYMBOL_GPL(kernel_power_off);
16853 +
16854 +long vs_reboot(unsigned int, void __user *);
16855 +
16856  /*
16857   * Reboot system call: for obvious reasons only root may call it,
16858   * and even root needs to set up some magic numbers in the registers
16859 @@ -369,6 +380,9 @@ asmlinkage long sys_reboot(int magic1, i
16860         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16861                 cmd = LINUX_REBOOT_CMD_HALT;
16862  
16863 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16864 +               return vs_reboot(cmd, arg);
16865 +
16866         lock_kernel();
16867         switch (cmd) {
16868         case LINUX_REBOOT_CMD_RESTART:
16869 @@ -1344,7 +1358,7 @@ asmlinkage long sys_sethostname(char __u
16870         int errno;
16871         char tmp[__NEW_UTS_LEN];
16872  
16873 -       if (!capable(CAP_SYS_ADMIN))
16874 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16875                 return -EPERM;
16876         if (len < 0 || len > __NEW_UTS_LEN)
16877                 return -EINVAL;
16878 @@ -1389,7 +1403,7 @@ asmlinkage long sys_setdomainname(char _
16879         int errno;
16880         char tmp[__NEW_UTS_LEN];
16881  
16882 -       if (!capable(CAP_SYS_ADMIN))
16883 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16884                 return -EPERM;
16885         if (len < 0 || len > __NEW_UTS_LEN)
16886                 return -EINVAL;
16887 @@ -1456,7 +1470,7 @@ asmlinkage long sys_setrlimit(unsigned i
16888                 return -EINVAL;
16889         old_rlim = current->signal->rlim + resource;
16890         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16891 -           !capable(CAP_SYS_RESOURCE))
16892 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16893                 return -EPERM;
16894         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16895                 return -EPERM;
16896 diff -NurpP --minimal linux-2.6.27.10/kernel/sysctl.c linux-2.6.27.10-vs2.3.0.36.4/kernel/sysctl.c
16897 --- linux-2.6.27.10/kernel/sysctl.c     2008-12-19 12:03:14.000000000 +0100
16898 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sysctl.c        2008-12-08 04:52:52.000000000 +0100
16899 @@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
16900  #ifdef CONFIG_MODULES
16901  extern char modprobe_path[];
16902  #endif
16903 +extern char vshelper_path[];
16904  #ifdef CONFIG_CHR_DEV_SG
16905  extern int sg_big_buff;
16906  #endif
16907 @@ -503,6 +504,15 @@ static struct ctl_table kern_table[] = {
16908                 .strategy       = &sysctl_string,
16909         },
16910  #endif
16911 +       {
16912 +               .ctl_name       = KERN_VSHELPER,
16913 +               .procname       = "vshelper",
16914 +               .data           = &vshelper_path,
16915 +               .maxlen         = 256,
16916 +               .mode           = 0644,
16917 +               .proc_handler   = &proc_dostring,
16918 +               .strategy       = &sysctl_string,
16919 +       },
16920  #ifdef CONFIG_CHR_DEV_SG
16921         {
16922                 .ctl_name       = KERN_SG_BIG_BUFF,
16923 diff -NurpP --minimal linux-2.6.27.10/kernel/sysctl_check.c linux-2.6.27.10-vs2.3.0.36.4/kernel/sysctl_check.c
16924 --- linux-2.6.27.10/kernel/sysctl_check.c       2008-10-13 14:52:09.000000000 +0200
16925 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/sysctl_check.c  2008-10-13 14:54:20.000000000 +0200
16926 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16927  
16928         { KERN_PANIC,                   "panic" },
16929         { KERN_REALROOTDEV,             "real-root-dev" },
16930 +       { KERN_VSHELPER,                "vshelper", },
16931  
16932         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16933         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16934 @@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
16935         {}
16936  };
16937  
16938 +static struct trans_ctl_table trans_vserver_table[] = {
16939 +       { 1,    "debug_switch" },
16940 +       { 2,    "debug_xid" },
16941 +       { 3,    "debug_nid" },
16942 +       { 4,    "debug_tag" },
16943 +       { 5,    "debug_net" },
16944 +       { 6,    "debug_limit" },
16945 +       { 7,    "debug_cres" },
16946 +       { 8,    "debug_dlim" },
16947 +       { 9,    "debug_quota" },
16948 +       { 10,   "debug_cvirt" },
16949 +       { 11,   "debug_space" },
16950 +       { 12,   "debug_misc" },
16951 +       {}
16952 +};
16953 +
16954  static const struct trans_ctl_table trans_root_table[] = {
16955         { CTL_KERN,     "kernel",       trans_kern_table },
16956         { CTL_VM,       "vm",           trans_vm_table },
16957 @@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
16958         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16959         { CTL_PM,       "pm",           trans_pm_table },
16960         { CTL_FRV,      "frv",          trans_frv_table },
16961 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16962         {}
16963  };
16964  
16965 diff -NurpP --minimal linux-2.6.27.10/kernel/time.c linux-2.6.27.10-vs2.3.0.36.4/kernel/time.c
16966 --- linux-2.6.27.10/kernel/time.c       2008-07-13 23:51:29.000000000 +0200
16967 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/time.c  2008-10-13 14:54:20.000000000 +0200
16968 @@ -62,6 +62,7 @@ EXPORT_SYMBOL(sys_tz);
16969  asmlinkage long sys_time(time_t __user * tloc)
16970  {
16971         time_t i = get_seconds();
16972 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16973  
16974         if (tloc) {
16975                 if (put_user(i,tloc))
16976 @@ -91,7 +92,7 @@ asmlinkage long sys_stime(time_t __user 
16977         if (err)
16978                 return err;
16979  
16980 -       do_settimeofday(&tv);
16981 +       vx_settimeofday(&tv);
16982         return 0;
16983  }
16984  
16985 @@ -102,7 +103,7 @@ asmlinkage long sys_gettimeofday(struct 
16986  {
16987         if (likely(tv != NULL)) {
16988                 struct timeval ktv;
16989 -               do_gettimeofday(&ktv);
16990 +               vx_gettimeofday(&ktv);
16991                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16992                         return -EFAULT;
16993         }
16994 @@ -177,7 +178,7 @@ int do_sys_settimeofday(struct timespec 
16995                 /* SMP safe, again the code in arch/foo/time.c should
16996                  * globally block out interrupts when it runs.
16997                  */
16998 -               return do_settimeofday(tv);
16999 +               return vx_settimeofday(tv);
17000         }
17001         return 0;
17002  }
17003 @@ -309,7 +310,7 @@ void getnstimeofday(struct timespec *tv)
17004  {
17005         struct timeval x;
17006  
17007 -       do_gettimeofday(&x);
17008 +       vx_gettimeofday(&x);
17009         tv->tv_sec = x.tv_sec;
17010         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17011  }
17012 diff -NurpP --minimal linux-2.6.27.10/kernel/timer.c linux-2.6.27.10-vs2.3.0.36.4/kernel/timer.c
17013 --- linux-2.6.27.10/kernel/timer.c      2008-10-13 14:52:09.000000000 +0200
17014 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/timer.c 2008-10-13 14:54:20.000000000 +0200
17015 @@ -37,6 +37,10 @@
17016  #include <linux/delay.h>
17017  #include <linux/tick.h>
17018  #include <linux/kallsyms.h>
17019 +#include <linux/vs_base.h>
17020 +#include <linux/vs_cvirt.h>
17021 +#include <linux/vs_pid.h>
17022 +#include <linux/vserver/sched.h>
17023  
17024  #include <asm/uaccess.h>
17025  #include <asm/unistd.h>
17026 @@ -1081,12 +1085,6 @@ asmlinkage unsigned long sys_alarm(unsig
17027  
17028  #endif
17029  
17030 -#ifndef __alpha__
17031 -
17032 -/*
17033 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17034 - * should be moved into arch/i386 instead?
17035 - */
17036  
17037  /**
17038   * sys_getpid - return the thread group id of the current process
17039 @@ -1115,10 +1113,23 @@ asmlinkage long sys_getppid(void)
17040         rcu_read_lock();
17041         pid = task_tgid_vnr(current->real_parent);
17042         rcu_read_unlock();
17043 +       return vx_map_pid(pid);
17044 +}
17045  
17046 -       return pid;
17047 +#ifdef __alpha__
17048 +
17049 +/*
17050 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17051 + */
17052 +
17053 +asmlinkage long do_getxpid(long *ppid)
17054 +{
17055 +       *ppid = sys_getppid();
17056 +       return sys_getpid();
17057  }
17058  
17059 +#else /* _alpha_ */
17060 +
17061  asmlinkage long sys_getuid(void)
17062  {
17063         /* Only we change this so SMP safe */
17064 @@ -1289,6 +1300,8 @@ int do_sysinfo(struct sysinfo *info)
17065                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17066                         tp.tv_sec++;
17067                 }
17068 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17069 +                       vx_vsi_uptime(&tp, NULL);
17070                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17071  
17072                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17073 diff -NurpP --minimal linux-2.6.27.10/kernel/user.c linux-2.6.27.10-vs2.3.0.36.4/kernel/user.c
17074 --- linux-2.6.27.10/kernel/user.c       2008-07-13 23:51:29.000000000 +0200
17075 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/user.c  2008-10-13 14:54:20.000000000 +0200
17076 @@ -243,12 +243,15 @@ static struct kobj_type uids_ktype = {
17077  };
17078  
17079  /* create /sys/kernel/uids/<uid>/cpu_share file for this user */
17080 -static int uids_user_create(struct user_struct *up)
17081 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
17082  {
17083         struct kobject *kobj = &up->kobj;
17084 -       int error;
17085 +       int error = 0;
17086  
17087         memset(kobj, 0, sizeof(struct kobject));
17088 +       if (ns != &init_user_ns)
17089 +               goto done;
17090 +
17091         kobj->kset = uids_kset;
17092         error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
17093         if (error) {
17094 @@ -272,7 +275,7 @@ int __init uids_sysfs_init(void)
17095         if (!uids_kset)
17096                 return -ENOMEM;
17097  
17098 -       return uids_user_create(&root_user);
17099 +       return uids_user_create(NULL, &root_user);
17100  }
17101  
17102  /* work function to remove sysfs directory for a user and free up
17103 @@ -302,9 +305,11 @@ static void remove_user_sysfs_dir(struct
17104         if (!remove_user)
17105                 goto done;
17106  
17107 -       kobject_uevent(&up->kobj, KOBJ_REMOVE);
17108 -       kobject_del(&up->kobj);
17109 -       kobject_put(&up->kobj);
17110 +       if (up->kobj.name) {
17111 +               kobject_uevent(&up->kobj, KOBJ_REMOVE);
17112 +               kobject_del(&up->kobj);
17113 +               kobject_put(&up->kobj);
17114 +       }
17115  
17116         sched_destroy_user(up);
17117         key_put(up->uid_keyring);
17118 @@ -332,7 +337,8 @@ static inline void free_user(struct user
17119  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
17120  
17121  int uids_sysfs_init(void) { return 0; }
17122 -static inline int uids_user_create(struct user_struct *up) { return 0; }
17123 +static inline int uids_user_create(struct user_namespace *ns,
17124 +       struct user_struct *up) { return 0; }
17125  static inline void uids_mutex_lock(void) { }
17126  static inline void uids_mutex_unlock(void) { }
17127  
17128 @@ -409,7 +415,7 @@ struct user_struct *alloc_uid(struct use
17129                 if (sched_create_user(new) < 0)
17130                         goto out_free_user;
17131  
17132 -               if (uids_user_create(new))
17133 +               if (uids_user_create(ns, new))
17134                         goto out_destoy_sched;
17135  
17136                 /*
17137 diff -NurpP --minimal linux-2.6.27.10/kernel/user_namespace.c linux-2.6.27.10-vs2.3.0.36.4/kernel/user_namespace.c
17138 --- linux-2.6.27.10/kernel/user_namespace.c     2008-10-13 14:52:09.000000000 +0200
17139 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/user_namespace.c        2008-10-13 14:54:20.000000000 +0200
17140 @@ -9,6 +9,7 @@
17141  #include <linux/nsproxy.h>
17142  #include <linux/slab.h>
17143  #include <linux/user_namespace.h>
17144 +#include <linux/vserver/global.h>
17145  
17146  /*
17147   * Clone a new ns copying an original user ns, setting refcount to 1
17148 @@ -26,6 +27,7 @@ static struct user_namespace *clone_user
17149                 return ERR_PTR(-ENOMEM);
17150  
17151         kref_init(&ns->kref);
17152 +       atomic_inc(&vs_global_user_ns);
17153  
17154         for (n = 0; n < UIDHASH_SZ; ++n)
17155                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17156 @@ -71,6 +73,7 @@ void free_user_ns(struct kref *kref)
17157  
17158         ns = container_of(kref, struct user_namespace, kref);
17159         release_uids(ns);
17160 +       atomic_dec(&vs_global_user_ns);
17161         kfree(ns);
17162  }
17163  EXPORT_SYMBOL(free_user_ns);
17164 diff -NurpP --minimal linux-2.6.27.10/kernel/utsname.c linux-2.6.27.10-vs2.3.0.36.4/kernel/utsname.c
17165 --- linux-2.6.27.10/kernel/utsname.c    2008-10-13 14:52:09.000000000 +0200
17166 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/utsname.c       2008-10-13 14:54:20.000000000 +0200
17167 @@ -14,6 +14,7 @@
17168  #include <linux/utsname.h>
17169  #include <linux/err.h>
17170  #include <linux/slab.h>
17171 +#include <linux/vserver/global.h>
17172  
17173  /*
17174   * Clone a new ns copying an original utsname, setting refcount to 1
17175 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17176         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17177         up_read(&uts_sem);
17178         kref_init(&ns->kref);
17179 +       atomic_inc(&vs_global_uts_ns);
17180         return ns;
17181  }
17182  
17183 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17184         struct uts_namespace *ns;
17185  
17186         ns = container_of(kref, struct uts_namespace, kref);
17187 +       atomic_dec(&vs_global_uts_ns);
17188         kfree(ns);
17189  }
17190 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/cacct.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cacct.c
17191 --- linux-2.6.27.10/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
17192 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cacct.c 2008-10-13 14:54:20.000000000 +0200
17193 @@ -0,0 +1,42 @@
17194 +/*
17195 + *  linux/kernel/vserver/cacct.c
17196 + *
17197 + *  Virtual Server: Context Accounting
17198 + *
17199 + *  Copyright (C) 2006-2007 Herbert Pötzl
17200 + *
17201 + *  V0.01  added accounting stats
17202 + *
17203 + */
17204 +
17205 +#include <linux/types.h>
17206 +#include <linux/vs_context.h>
17207 +#include <linux/vserver/cacct_cmd.h>
17208 +#include <linux/vserver/cacct_int.h>
17209 +
17210 +#include <asm/errno.h>
17211 +#include <asm/uaccess.h>
17212 +
17213 +
17214 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17215 +{
17216 +       struct vcmd_sock_stat_v0 vc_data;
17217 +       int j, field;
17218 +
17219 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17220 +               return -EFAULT;
17221 +
17222 +       field = vc_data.field;
17223 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17224 +               return -EINVAL;
17225 +
17226 +       for (j = 0; j < 3; j++) {
17227 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17228 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17229 +       }
17230 +
17231 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17232 +               return -EFAULT;
17233 +       return 0;
17234 +}
17235 +
17236 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/cacct_init.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cacct_init.h
17237 --- linux-2.6.27.10/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
17238 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cacct_init.h    2008-10-13 14:54:20.000000000 +0200
17239 @@ -0,0 +1,25 @@
17240 +
17241 +
17242 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17243 +{
17244 +       int i, j;
17245 +
17246 +
17247 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17248 +               for (j = 0; j < 3; j++) {
17249 +                       atomic_set(&cacct->sock[i][j].count, 0);
17250 +                       atomic_set(&cacct->sock[i][j].total, 0);
17251 +               }
17252 +       }
17253 +       for (i = 0; i < 8; i++)
17254 +               atomic_set(&cacct->slab[i], 0);
17255 +       for (i = 0; i < 5; i++)
17256 +               for (j = 0; j < 4; j++)
17257 +                       atomic_set(&cacct->page[i][j], 0);
17258 +}
17259 +
17260 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17261 +{
17262 +       return;
17263 +}
17264 +
17265 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/cacct_proc.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cacct_proc.h
17266 --- linux-2.6.27.10/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
17267 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cacct_proc.h    2008-10-13 14:54:20.000000000 +0200
17268 @@ -0,0 +1,53 @@
17269 +#ifndef _VX_CACCT_PROC_H
17270 +#define _VX_CACCT_PROC_H
17271 +
17272 +#include <linux/vserver/cacct_int.h>
17273 +
17274 +
17275 +#define VX_SOCKA_TOP   \
17276 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17277 +
17278 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17279 +{
17280 +       int i, j, length = 0;
17281 +       static char *type[VXA_SOCK_SIZE] = {
17282 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17283 +       };
17284 +
17285 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17286 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17287 +               length += sprintf(buffer + length, "%s:", type[i]);
17288 +               for (j = 0; j < 3; j++) {
17289 +                       length += sprintf(buffer + length,
17290 +                               "\t%10lu/%-10lu",
17291 +                               vx_sock_count(cacct, i, j),
17292 +                               vx_sock_total(cacct, i, j));
17293 +               }
17294 +               buffer[length++] = '\n';
17295 +       }
17296 +
17297 +       length += sprintf(buffer + length, "\n");
17298 +       length += sprintf(buffer + length,
17299 +               "slab:\t %8u %8u %8u %8u\n",
17300 +               atomic_read(&cacct->slab[1]),
17301 +               atomic_read(&cacct->slab[4]),
17302 +               atomic_read(&cacct->slab[0]),
17303 +               atomic_read(&cacct->slab[2]));
17304 +
17305 +       length += sprintf(buffer + length, "\n");
17306 +       for (i = 0; i < 5; i++) {
17307 +               length += sprintf(buffer + length,
17308 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17309 +                       atomic_read(&cacct->page[i][0]),
17310 +                       atomic_read(&cacct->page[i][1]),
17311 +                       atomic_read(&cacct->page[i][2]),
17312 +                       atomic_read(&cacct->page[i][3]),
17313 +                       atomic_read(&cacct->page[i][4]),
17314 +                       atomic_read(&cacct->page[i][5]),
17315 +                       atomic_read(&cacct->page[i][6]),
17316 +                       atomic_read(&cacct->page[i][7]));
17317 +       }
17318 +       return length;
17319 +}
17320 +
17321 +#endif /* _VX_CACCT_PROC_H */
17322 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/context.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/context.c
17323 --- linux-2.6.27.10/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
17324 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/context.c       2008-10-31 03:56:55.000000000 +0100
17325 @@ -0,0 +1,1018 @@
17326 +/*
17327 + *  linux/kernel/vserver/context.c
17328 + *
17329 + *  Virtual Server: Context Support
17330 + *
17331 + *  Copyright (C) 2003-2007  Herbert Pötzl
17332 + *
17333 + *  V0.01  context helper
17334 + *  V0.02  vx_ctx_kill syscall command
17335 + *  V0.03  replaced context_info calls
17336 + *  V0.04  redesign of struct (de)alloc
17337 + *  V0.05  rlimit basic implementation
17338 + *  V0.06  task_xid and info commands
17339 + *  V0.07  context flags and caps
17340 + *  V0.08  switch to RCU based hash
17341 + *  V0.09  revert to non RCU for now
17342 + *  V0.10  and back to working RCU hash
17343 + *  V0.11  and back to locking again
17344 + *  V0.12  referenced context store
17345 + *  V0.13  separate per cpu data
17346 + *  V0.14  changed vcmds to vxi arg
17347 + *  V0.15  added context stat
17348 + *  V0.16  have __create claim() the vxi
17349 + *  V0.17  removed older and legacy stuff
17350 + *
17351 + */
17352 +
17353 +#include <linux/slab.h>
17354 +#include <linux/types.h>
17355 +#include <linux/security.h>
17356 +#include <linux/pid_namespace.h>
17357 +
17358 +#include <linux/vserver/context.h>
17359 +#include <linux/vserver/network.h>
17360 +#include <linux/vserver/debug.h>
17361 +#include <linux/vserver/limit.h>
17362 +#include <linux/vserver/limit_int.h>
17363 +#include <linux/vserver/space.h>
17364 +
17365 +#include <linux/vs_context.h>
17366 +#include <linux/vs_limit.h>
17367 +#include <linux/vs_pid.h>
17368 +#include <linux/vserver/context_cmd.h>
17369 +
17370 +#include "cvirt_init.h"
17371 +#include "cacct_init.h"
17372 +#include "limit_init.h"
17373 +#include "sched_init.h"
17374 +
17375 +
17376 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17377 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17378 +
17379 +
17380 +/*     now inactive context structures */
17381 +
17382 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17383 +
17384 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17385 +
17386 +
17387 +/*     __alloc_vx_info()
17388 +
17389 +       * allocate an initialized vx_info struct
17390 +       * doesn't make it visible (hash)                        */
17391 +
17392 +static struct vx_info *__alloc_vx_info(xid_t xid)
17393 +{
17394 +       struct vx_info *new = NULL;
17395 +       int cpu;
17396 +
17397 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17398 +
17399 +       /* would this benefit from a slab cache? */
17400 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17401 +       if (!new)
17402 +               return 0;
17403 +
17404 +       memset(new, 0, sizeof(struct vx_info));
17405 +#ifdef CONFIG_SMP
17406 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17407 +       if (!new->ptr_pc)
17408 +               goto error;
17409 +#endif
17410 +       new->vx_id = xid;
17411 +       INIT_HLIST_NODE(&new->vx_hlist);
17412 +       atomic_set(&new->vx_usecnt, 0);
17413 +       atomic_set(&new->vx_tasks, 0);
17414 +       new->vx_parent = NULL;
17415 +       new->vx_state = 0;
17416 +       init_waitqueue_head(&new->vx_wait);
17417 +
17418 +       /* prepare reaper */
17419 +       get_task_struct(init_pid_ns.child_reaper);
17420 +       new->vx_reaper = init_pid_ns.child_reaper;
17421 +       new->vx_badness_bias = 0;
17422 +
17423 +       /* rest of init goes here */
17424 +       vx_info_init_limit(&new->limit);
17425 +       vx_info_init_sched(&new->sched);
17426 +       vx_info_init_cvirt(&new->cvirt);
17427 +       vx_info_init_cacct(&new->cacct);
17428 +
17429 +       /* per cpu data structures */
17430 +       for_each_possible_cpu(cpu) {
17431 +               vx_info_init_sched_pc(
17432 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17433 +               vx_info_init_cvirt_pc(
17434 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17435 +       }
17436 +
17437 +       new->vx_flags = VXF_INIT_SET;
17438 +       cap_set_init_eff(new->vx_bcaps);
17439 +       new->vx_ccaps = 0;
17440 +       // new->vx_cap_bset = current->cap_bset;
17441 +
17442 +       new->reboot_cmd = 0;
17443 +       new->exit_code = 0;
17444 +
17445 +       vxdprintk(VXD_CBIT(xid, 0),
17446 +               "alloc_vx_info(%d) = %p", xid, new);
17447 +       vxh_alloc_vx_info(new);
17448 +       atomic_inc(&vx_global_ctotal);
17449 +       return new;
17450 +#ifdef CONFIG_SMP
17451 +error:
17452 +       kfree(new);
17453 +       return 0;
17454 +#endif
17455 +}
17456 +
17457 +/*     __dealloc_vx_info()
17458 +
17459 +       * final disposal of vx_info                             */
17460 +
17461 +static void __dealloc_vx_info(struct vx_info *vxi)
17462 +{
17463 +       struct vx_info_save vxis;
17464 +       int cpu;
17465 +
17466 +       vxdprintk(VXD_CBIT(xid, 0),
17467 +               "dealloc_vx_info(%p)", vxi);
17468 +       vxh_dealloc_vx_info(vxi);
17469 +
17470 +#ifdef CONFIG_VSERVER_WARN
17471 +       enter_vx_info(vxi, &vxis);
17472 +       vx_info_exit_limit(&vxi->limit);
17473 +       vx_info_exit_sched(&vxi->sched);
17474 +       vx_info_exit_cvirt(&vxi->cvirt);
17475 +       vx_info_exit_cacct(&vxi->cacct);
17476 +
17477 +       for_each_possible_cpu(cpu) {
17478 +               vx_info_exit_sched_pc(
17479 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17480 +               vx_info_exit_cvirt_pc(
17481 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17482 +       }
17483 +       leave_vx_info(&vxis);
17484 +#endif
17485 +
17486 +       vxi->vx_id = -1;
17487 +       vxi->vx_state |= VXS_RELEASED;
17488 +
17489 +#ifdef CONFIG_SMP
17490 +       free_percpu(vxi->ptr_pc);
17491 +#endif
17492 +       kfree(vxi);
17493 +       atomic_dec(&vx_global_ctotal);
17494 +}
17495 +
17496 +static void __shutdown_vx_info(struct vx_info *vxi)
17497 +{
17498 +       struct nsproxy *nsproxy;
17499 +       struct fs_struct *fs;
17500 +       int index;
17501 +
17502 +       might_sleep();
17503 +
17504 +       vxi->vx_state |= VXS_SHUTDOWN;
17505 +       vs_state_change(vxi, VSC_SHUTDOWN);
17506 +
17507 +       for (index = 0; index < VX_SPACES; index++) {
17508 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17509 +               if (nsproxy)
17510 +                       put_nsproxy(nsproxy);
17511 +
17512 +               fs = xchg(&vxi->vx_fs[index], NULL);
17513 +               if (fs)
17514 +                       put_fs_struct(fs);
17515 +       }
17516 +}
17517 +
17518 +/* exported stuff */
17519 +
17520 +void free_vx_info(struct vx_info *vxi)
17521 +{
17522 +       unsigned long flags;
17523 +       unsigned index;
17524 +
17525 +       /* check for reference counts first */
17526 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17527 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17528 +
17529 +       /* context must not be hashed */
17530 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17531 +
17532 +       /* context shutdown is mandatory */
17533 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17534 +
17535 +       /* nsproxy and fs check */
17536 +       for (index = 0; index < VX_SPACES; index++) {
17537 +               BUG_ON(vxi->vx_nsproxy[index]);
17538 +               BUG_ON(vxi->vx_fs[index]);
17539 +       }
17540 +
17541 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17542 +       hlist_del(&vxi->vx_hlist);
17543 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17544 +
17545 +       __dealloc_vx_info(vxi);
17546 +}
17547 +
17548 +
17549 +/*     hash table for vx_info hash */
17550 +
17551 +#define VX_HASH_SIZE   13
17552 +
17553 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17554 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17555 +
17556 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17557 +
17558 +
17559 +static inline unsigned int __hashval(xid_t xid)
17560 +{
17561 +       return (xid % VX_HASH_SIZE);
17562 +}
17563 +
17564 +
17565 +
17566 +/*     __hash_vx_info()
17567 +
17568 +       * add the vxi to the global hash table
17569 +       * requires the hash_lock to be held                     */
17570 +
17571 +static inline void __hash_vx_info(struct vx_info *vxi)
17572 +{
17573 +       struct hlist_head *head;
17574 +
17575 +       vxd_assert_lock(&vx_info_hash_lock);
17576 +       vxdprintk(VXD_CBIT(xid, 4),
17577 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17578 +       vxh_hash_vx_info(vxi);
17579 +
17580 +       /* context must not be hashed */
17581 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17582 +
17583 +       vxi->vx_state |= VXS_HASHED;
17584 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17585 +       hlist_add_head(&vxi->vx_hlist, head);
17586 +       atomic_inc(&vx_global_cactive);
17587 +}
17588 +
17589 +/*     __unhash_vx_info()
17590 +
17591 +       * remove the vxi from the global hash table
17592 +       * requires the hash_lock to be held                     */
17593 +
17594 +static inline void __unhash_vx_info(struct vx_info *vxi)
17595 +{
17596 +       unsigned long flags;
17597 +
17598 +       vxd_assert_lock(&vx_info_hash_lock);
17599 +       vxdprintk(VXD_CBIT(xid, 4),
17600 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17601 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17602 +       vxh_unhash_vx_info(vxi);
17603 +
17604 +       /* context must be hashed */
17605 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17606 +       /* but without tasks */
17607 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17608 +
17609 +       vxi->vx_state &= ~VXS_HASHED;
17610 +       hlist_del_init(&vxi->vx_hlist);
17611 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17612 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17613 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17614 +       atomic_dec(&vx_global_cactive);
17615 +}
17616 +
17617 +
17618 +/*     __lookup_vx_info()
17619 +
17620 +       * requires the hash_lock to be held
17621 +       * doesn't increment the vx_refcnt                       */
17622 +
17623 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17624 +{
17625 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17626 +       struct hlist_node *pos;
17627 +       struct vx_info *vxi;
17628 +
17629 +       vxd_assert_lock(&vx_info_hash_lock);
17630 +       hlist_for_each(pos, head) {
17631 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17632 +
17633 +               if (vxi->vx_id == xid)
17634 +                       goto found;
17635 +       }
17636 +       vxi = NULL;
17637 +found:
17638 +       vxdprintk(VXD_CBIT(xid, 0),
17639 +               "__lookup_vx_info(#%u): %p[#%u]",
17640 +               xid, vxi, vxi ? vxi->vx_id : 0);
17641 +       vxh_lookup_vx_info(vxi, xid);
17642 +       return vxi;
17643 +}
17644 +
17645 +
17646 +/*     __create_vx_info()
17647 +
17648 +       * create the requested context
17649 +       * get(), claim() and hash it                            */
17650 +
17651 +static struct vx_info *__create_vx_info(int id)
17652 +{
17653 +       struct vx_info *new, *vxi = NULL;
17654 +
17655 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17656 +
17657 +       if (!(new = __alloc_vx_info(id)))
17658 +               return ERR_PTR(-ENOMEM);
17659 +
17660 +       /* required to make dynamic xids unique */
17661 +       spin_lock(&vx_info_hash_lock);
17662 +
17663 +       /* static context requested */
17664 +       if ((vxi = __lookup_vx_info(id))) {
17665 +               vxdprintk(VXD_CBIT(xid, 0),
17666 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17667 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17668 +                       vxi = ERR_PTR(-EBUSY);
17669 +               else
17670 +                       vxi = ERR_PTR(-EEXIST);
17671 +               goto out_unlock;
17672 +       }
17673 +       /* new context */
17674 +       vxdprintk(VXD_CBIT(xid, 0),
17675 +               "create_vx_info(%d) = %p (new)", id, new);
17676 +       claim_vx_info(new, NULL);
17677 +       __hash_vx_info(get_vx_info(new));
17678 +       vxi = new, new = NULL;
17679 +
17680 +out_unlock:
17681 +       spin_unlock(&vx_info_hash_lock);
17682 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17683 +       if (new)
17684 +               __dealloc_vx_info(new);
17685 +       return vxi;
17686 +}
17687 +
17688 +
17689 +/*     exported stuff                                          */
17690 +
17691 +
17692 +void unhash_vx_info(struct vx_info *vxi)
17693 +{
17694 +       __shutdown_vx_info(vxi);
17695 +       spin_lock(&vx_info_hash_lock);
17696 +       __unhash_vx_info(vxi);
17697 +       spin_unlock(&vx_info_hash_lock);
17698 +       __wakeup_vx_info(vxi);
17699 +}
17700 +
17701 +
17702 +/*     lookup_vx_info()
17703 +
17704 +       * search for a vx_info and get() it
17705 +       * negative id means current                             */
17706 +
17707 +struct vx_info *lookup_vx_info(int id)
17708 +{
17709 +       struct vx_info *vxi = NULL;
17710 +
17711 +       if (id < 0) {
17712 +               vxi = get_vx_info(current->vx_info);
17713 +       } else if (id > 1) {
17714 +               spin_lock(&vx_info_hash_lock);
17715 +               vxi = get_vx_info(__lookup_vx_info(id));
17716 +               spin_unlock(&vx_info_hash_lock);
17717 +       }
17718 +       return vxi;
17719 +}
17720 +
17721 +/*     xid_is_hashed()
17722 +
17723 +       * verify that xid is still hashed                       */
17724 +
17725 +int xid_is_hashed(xid_t xid)
17726 +{
17727 +       int hashed;
17728 +
17729 +       spin_lock(&vx_info_hash_lock);
17730 +       hashed = (__lookup_vx_info(xid) != NULL);
17731 +       spin_unlock(&vx_info_hash_lock);
17732 +       return hashed;
17733 +}
17734 +
17735 +#ifdef CONFIG_PROC_FS
17736 +
17737 +/*     get_xid_list()
17738 +
17739 +       * get a subset of hashed xids for proc
17740 +       * assumes size is at least one                          */
17741 +
17742 +int get_xid_list(int index, unsigned int *xids, int size)
17743 +{
17744 +       int hindex, nr_xids = 0;
17745 +
17746 +       /* only show current and children */
17747 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17748 +               if (index > 0)
17749 +                       return 0;
17750 +               xids[nr_xids] = vx_current_xid();
17751 +               return 1;
17752 +       }
17753 +
17754 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17755 +               struct hlist_head *head = &vx_info_hash[hindex];
17756 +               struct hlist_node *pos;
17757 +
17758 +               spin_lock(&vx_info_hash_lock);
17759 +               hlist_for_each(pos, head) {
17760 +                       struct vx_info *vxi;
17761 +
17762 +                       if (--index > 0)
17763 +                               continue;
17764 +
17765 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17766 +                       xids[nr_xids] = vxi->vx_id;
17767 +                       if (++nr_xids >= size) {
17768 +                               spin_unlock(&vx_info_hash_lock);
17769 +                               goto out;
17770 +                       }
17771 +               }
17772 +               /* keep the lock time short */
17773 +               spin_unlock(&vx_info_hash_lock);
17774 +       }
17775 +out:
17776 +       return nr_xids;
17777 +}
17778 +#endif
17779 +
17780 +#ifdef CONFIG_VSERVER_DEBUG
17781 +
17782 +void   dump_vx_info_inactive(int level)
17783 +{
17784 +       struct hlist_node *entry, *next;
17785 +
17786 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17787 +               struct vx_info *vxi =
17788 +                       list_entry(entry, struct vx_info, vx_hlist);
17789 +
17790 +               dump_vx_info(vxi, level);
17791 +       }
17792 +}
17793 +
17794 +#endif
17795 +
17796 +#if 0
17797 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17798 +{
17799 +       struct user_struct *new_user, *old_user;
17800 +
17801 +       if (!p || !vxi)
17802 +               BUG();
17803 +
17804 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17805 +               return -EACCES;
17806 +
17807 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17808 +       if (!new_user)
17809 +               return -ENOMEM;
17810 +
17811 +       old_user = p->user;
17812 +       if (new_user != old_user) {
17813 +               atomic_inc(&new_user->processes);
17814 +               atomic_dec(&old_user->processes);
17815 +               p->user = new_user;
17816 +       }
17817 +       free_uid(old_user);
17818 +       return 0;
17819 +}
17820 +#endif
17821 +
17822 +#if 0
17823 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17824 +{
17825 +       // p->cap_effective &= vxi->vx_cap_bset;
17826 +       p->cap_effective =
17827 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17828 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17829 +       p->cap_inheritable =
17830 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17831 +       // p->cap_permitted &= vxi->vx_cap_bset;
17832 +       p->cap_permitted =
17833 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17834 +}
17835 +#endif
17836 +
17837 +
17838 +#include <linux/file.h>
17839 +#include <linux/fdtable.h>
17840 +
17841 +static int vx_openfd_task(struct task_struct *tsk)
17842 +{
17843 +       struct files_struct *files = tsk->files;
17844 +       struct fdtable *fdt;
17845 +       const unsigned long *bptr;
17846 +       int count, total;
17847 +
17848 +       /* no rcu_read_lock() because of spin_lock() */
17849 +       spin_lock(&files->file_lock);
17850 +       fdt = files_fdtable(files);
17851 +       bptr = fdt->open_fds->fds_bits;
17852 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17853 +       for (total = 0; count > 0; count--) {
17854 +               if (*bptr)
17855 +                       total += hweight_long(*bptr);
17856 +               bptr++;
17857 +       }
17858 +       spin_unlock(&files->file_lock);
17859 +       return total;
17860 +}
17861 +
17862 +
17863 +/*     for *space compatibility */
17864 +
17865 +asmlinkage long sys_unshare(unsigned long);
17866 +
17867 +/*
17868 + *     migrate task to new context
17869 + *     gets vxi, puts old_vxi on change
17870 + *     optionally unshares namespaces (hack)
17871 + */
17872 +
17873 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17874 +{
17875 +       struct vx_info *old_vxi;
17876 +       int ret = 0;
17877 +
17878 +       if (!p || !vxi)
17879 +               BUG();
17880 +
17881 +       vxdprintk(VXD_CBIT(xid, 5),
17882 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17883 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17884 +
17885 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17886 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17887 +               return -EACCES;
17888 +
17889 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17890 +               return -EFAULT;
17891 +
17892 +       old_vxi = task_get_vx_info(p);
17893 +       if (old_vxi == vxi)
17894 +               goto out;
17895 +
17896 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17897 +       {
17898 +               int openfd;
17899 +
17900 +               task_lock(p);
17901 +               openfd = vx_openfd_task(p);
17902 +
17903 +               if (old_vxi) {
17904 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17905 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17906 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17907 +                       /* FIXME: what about the struct files here? */
17908 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17909 +                       /* account for the executable */
17910 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17911 +               }
17912 +               atomic_inc(&vxi->cvirt.nr_threads);
17913 +               atomic_inc(&vxi->cvirt.nr_running);
17914 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17915 +               /* FIXME: what about the struct files here? */
17916 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17917 +               /* account for the executable */
17918 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17919 +
17920 +               if (old_vxi) {
17921 +                       release_vx_info(old_vxi, p);
17922 +                       clr_vx_info(&p->vx_info);
17923 +               }
17924 +               claim_vx_info(vxi, p);
17925 +               set_vx_info(&p->vx_info, vxi);
17926 +               p->xid = vxi->vx_id;
17927 +
17928 +               vxdprintk(VXD_CBIT(xid, 5),
17929 +                       "moved task %p into vxi:%p[#%d]",
17930 +                       p, vxi, vxi->vx_id);
17931 +
17932 +               // vx_mask_cap_bset(vxi, p);
17933 +               task_unlock(p);
17934 +
17935 +               /* hack for *spaces to provide compatibility */
17936 +               if (unshare) {
17937 +                       struct nsproxy *old_nsp, *new_nsp;
17938 +
17939 +                       ret = unshare_nsproxy_namespaces(
17940 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17941 +                               &new_nsp, NULL);
17942 +                       if (ret)
17943 +                               goto out;
17944 +
17945 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17946 +                       vx_set_space(vxi,
17947 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17948 +                       put_nsproxy(old_nsp);
17949 +               }
17950 +       }
17951 +out:
17952 +       put_vx_info(old_vxi);
17953 +       return ret;
17954 +}
17955 +
17956 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17957 +{
17958 +       struct task_struct *old_reaper;
17959 +
17960 +       if (!vxi)
17961 +               return -EINVAL;
17962 +
17963 +       vxdprintk(VXD_CBIT(xid, 6),
17964 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17965 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17966 +
17967 +       old_reaper = vxi->vx_reaper;
17968 +       if (old_reaper == p)
17969 +               return 0;
17970 +
17971 +       /* set new child reaper */
17972 +       get_task_struct(p);
17973 +       vxi->vx_reaper = p;
17974 +       put_task_struct(old_reaper);
17975 +       return 0;
17976 +}
17977 +
17978 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17979 +{
17980 +       if (!vxi)
17981 +               return -EINVAL;
17982 +
17983 +       vxdprintk(VXD_CBIT(xid, 6),
17984 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17985 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17986 +
17987 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17988 +       vxi->vx_initpid = p->tgid;
17989 +       return 0;
17990 +}
17991 +
17992 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17993 +{
17994 +       vxdprintk(VXD_CBIT(xid, 6),
17995 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17996 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17997 +
17998 +       vxi->exit_code = code;
17999 +       vxi->vx_initpid = 0;
18000 +}
18001 +
18002 +
18003 +void vx_set_persistent(struct vx_info *vxi)
18004 +{
18005 +       vxdprintk(VXD_CBIT(xid, 6),
18006 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18007 +
18008 +       get_vx_info(vxi);
18009 +       claim_vx_info(vxi, NULL);
18010 +}
18011 +
18012 +void vx_clear_persistent(struct vx_info *vxi)
18013 +{
18014 +       vxdprintk(VXD_CBIT(xid, 6),
18015 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18016 +
18017 +       release_vx_info(vxi, NULL);
18018 +       put_vx_info(vxi);
18019 +}
18020 +
18021 +void vx_update_persistent(struct vx_info *vxi)
18022 +{
18023 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18024 +               vx_set_persistent(vxi);
18025 +       else
18026 +               vx_clear_persistent(vxi);
18027 +}
18028 +
18029 +
18030 +/*     task must be current or locked          */
18031 +
18032 +void   exit_vx_info(struct task_struct *p, int code)
18033 +{
18034 +       struct vx_info *vxi = p->vx_info;
18035 +
18036 +       if (vxi) {
18037 +               atomic_dec(&vxi->cvirt.nr_threads);
18038 +               vx_nproc_dec(p);
18039 +
18040 +               vxi->exit_code = code;
18041 +               release_vx_info(vxi, p);
18042 +       }
18043 +}
18044 +
18045 +void   exit_vx_info_early(struct task_struct *p, int code)
18046 +{
18047 +       struct vx_info *vxi = p->vx_info;
18048 +
18049 +       if (vxi) {
18050 +               if (vxi->vx_initpid == p->tgid)
18051 +                       vx_exit_init(vxi, p, code);
18052 +               if (vxi->vx_reaper == p)
18053 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18054 +       }
18055 +}
18056 +
18057 +
18058 +/* vserver syscall commands below here */
18059 +
18060 +/* taks xid and vx_info functions */
18061 +
18062 +#include <asm/uaccess.h>
18063 +
18064 +
18065 +int vc_task_xid(uint32_t id)
18066 +{
18067 +       xid_t xid;
18068 +
18069 +       if (id) {
18070 +               struct task_struct *tsk;
18071 +
18072 +               read_lock(&tasklist_lock);
18073 +               tsk = find_task_by_real_pid(id);
18074 +               xid = (tsk) ? tsk->xid : -ESRCH;
18075 +               read_unlock(&tasklist_lock);
18076 +       } else
18077 +               xid = vx_current_xid();
18078 +       return xid;
18079 +}
18080 +
18081 +
18082 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18083 +{
18084 +       struct vcmd_vx_info_v0 vc_data;
18085 +
18086 +       vc_data.xid = vxi->vx_id;
18087 +       vc_data.initpid = vxi->vx_initpid;
18088 +
18089 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18090 +               return -EFAULT;
18091 +       return 0;
18092 +}
18093 +
18094 +
18095 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18096 +{
18097 +       struct vcmd_ctx_stat_v0 vc_data;
18098 +
18099 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18100 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18101 +
18102 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18103 +               return -EFAULT;
18104 +       return 0;
18105 +}
18106 +
18107 +
18108 +/* context functions */
18109 +
18110 +int vc_ctx_create(uint32_t xid, void __user *data)
18111 +{
18112 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18113 +       struct vx_info *new_vxi;
18114 +       int ret;
18115 +
18116 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18117 +               return -EFAULT;
18118 +
18119 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18120 +               return -EINVAL;
18121 +
18122 +       new_vxi = __create_vx_info(xid);
18123 +       if (IS_ERR(new_vxi))
18124 +               return PTR_ERR(new_vxi);
18125 +
18126 +       /* initial flags */
18127 +       new_vxi->vx_flags = vc_data.flagword;
18128 +
18129 +       ret = -ENOEXEC;
18130 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18131 +               goto out;
18132 +
18133 +       ret = vx_migrate_task(current, new_vxi, (!data));
18134 +       if (ret)
18135 +               goto out;
18136 +
18137 +       /* return context id on success */
18138 +       ret = new_vxi->vx_id;
18139 +
18140 +       /* get a reference for persistent contexts */
18141 +       if ((vc_data.flagword & VXF_PERSISTENT))
18142 +               vx_set_persistent(new_vxi);
18143 +out:
18144 +       release_vx_info(new_vxi, NULL);
18145 +       put_vx_info(new_vxi);
18146 +       return ret;
18147 +}
18148 +
18149 +
18150 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18151 +{
18152 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18153 +       int ret;
18154 +
18155 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18156 +               return -EFAULT;
18157 +
18158 +       ret = vx_migrate_task(current, vxi, 0);
18159 +       if (ret)
18160 +               return ret;
18161 +       if (vc_data.flagword & VXM_SET_INIT)
18162 +               ret = vx_set_init(vxi, current);
18163 +       if (ret)
18164 +               return ret;
18165 +       if (vc_data.flagword & VXM_SET_REAPER)
18166 +               ret = vx_set_reaper(vxi, current);
18167 +       return ret;
18168 +}
18169 +
18170 +
18171 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18172 +{
18173 +       struct vcmd_ctx_flags_v0 vc_data;
18174 +
18175 +       vc_data.flagword = vxi->vx_flags;
18176 +
18177 +       /* special STATE flag handling */
18178 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18179 +
18180 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18181 +               return -EFAULT;
18182 +       return 0;
18183 +}
18184 +
18185 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18186 +{
18187 +       struct vcmd_ctx_flags_v0 vc_data;
18188 +       uint64_t mask, trigger;
18189 +
18190 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18191 +               return -EFAULT;
18192 +
18193 +       /* special STATE flag handling */
18194 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18195 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18196 +
18197 +       if (vxi == current->vx_info) {
18198 +               /* if (trigger & VXF_STATE_SETUP)
18199 +                       vx_mask_cap_bset(vxi, current); */
18200 +               if (trigger & VXF_STATE_INIT) {
18201 +                       int ret;
18202 +
18203 +                       ret = vx_set_init(vxi, current);
18204 +                       if (ret)
18205 +                               return ret;
18206 +                       ret = vx_set_reaper(vxi, current);
18207 +                       if (ret)
18208 +                               return ret;
18209 +               }
18210 +       }
18211 +
18212 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18213 +               vc_data.flagword, mask);
18214 +       if (trigger & VXF_PERSISTENT)
18215 +               vx_update_persistent(vxi);
18216 +
18217 +       return 0;
18218 +}
18219 +
18220 +
18221 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18222 +{
18223 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18224 +
18225 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18226 +       return v;
18227 +}
18228 +
18229 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18230 +{
18231 +       kernel_cap_t c = __cap_empty_set;
18232 +
18233 +       c.cap[0] = v & 0xFFFFFFFF;
18234 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18235 +
18236 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18237 +       return c;
18238 +}
18239 +
18240 +
18241 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18242 +{
18243 +       if (bcaps)
18244 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18245 +       if (ccaps)
18246 +               *ccaps = vxi->vx_ccaps;
18247 +
18248 +       return 0;
18249 +}
18250 +
18251 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18252 +{
18253 +       struct vcmd_ctx_caps_v1 vc_data;
18254 +       int ret;
18255 +
18256 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18257 +       if (ret)
18258 +               return ret;
18259 +       vc_data.cmask = ~0ULL;
18260 +
18261 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18262 +               return -EFAULT;
18263 +       return 0;
18264 +}
18265 +
18266 +static int do_set_caps(struct vx_info *vxi,
18267 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18268 +{
18269 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18270 +
18271 +#if 0
18272 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18273 +               bcaps, bmask, ccaps, cmask);
18274 +#endif
18275 +       vxi->vx_bcaps = cap_t_from_caps(
18276 +               vs_mask_flags(bcold, bcaps, bmask));
18277 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18278 +
18279 +       return 0;
18280 +}
18281 +
18282 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18283 +{
18284 +       struct vcmd_ctx_caps_v1 vc_data;
18285 +
18286 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18287 +               return -EFAULT;
18288 +
18289 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18290 +}
18291 +
18292 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18293 +{
18294 +       struct vcmd_bcaps vc_data;
18295 +       int ret;
18296 +
18297 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18298 +       if (ret)
18299 +               return ret;
18300 +       vc_data.bmask = ~0ULL;
18301 +
18302 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18303 +               return -EFAULT;
18304 +       return 0;
18305 +}
18306 +
18307 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18308 +{
18309 +       struct vcmd_bcaps vc_data;
18310 +
18311 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18312 +               return -EFAULT;
18313 +
18314 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18315 +}
18316 +
18317 +
18318 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18319 +{
18320 +       struct vcmd_badness_v0 vc_data;
18321 +
18322 +       vc_data.bias = vxi->vx_badness_bias;
18323 +
18324 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18325 +               return -EFAULT;
18326 +       return 0;
18327 +}
18328 +
18329 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18330 +{
18331 +       struct vcmd_badness_v0 vc_data;
18332 +
18333 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18334 +               return -EFAULT;
18335 +
18336 +       vxi->vx_badness_bias = vc_data.bias;
18337 +       return 0;
18338 +}
18339 +
18340 +#include <linux/module.h>
18341 +
18342 +EXPORT_SYMBOL_GPL(free_vx_info);
18343 +
18344 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/cvirt.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cvirt.c
18345 --- linux-2.6.27.10/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
18346 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cvirt.c 2008-10-31 03:49:36.000000000 +0100
18347 @@ -0,0 +1,300 @@
18348 +/*
18349 + *  linux/kernel/vserver/cvirt.c
18350 + *
18351 + *  Virtual Server: Context Virtualization
18352 + *
18353 + *  Copyright (C) 2004-2007  Herbert Pötzl
18354 + *
18355 + *  V0.01  broken out from limit.c
18356 + *  V0.02  added utsname stuff
18357 + *  V0.03  changed vcmds to vxi arg
18358 + *
18359 + */
18360 +
18361 +#include <linux/types.h>
18362 +#include <linux/utsname.h>
18363 +#include <linux/vs_cvirt.h>
18364 +#include <linux/vserver/switch.h>
18365 +#include <linux/vserver/cvirt_cmd.h>
18366 +
18367 +#include <asm/uaccess.h>
18368 +
18369 +
18370 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18371 +{
18372 +       struct vx_info *vxi = current->vx_info;
18373 +
18374 +       set_normalized_timespec(uptime,
18375 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18376 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18377 +       if (!idle)
18378 +               return;
18379 +       set_normalized_timespec(idle,
18380 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18381 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18382 +       return;
18383 +}
18384 +
18385 +uint64_t vx_idle_jiffies(void)
18386 +{
18387 +       return init_task.utime + init_task.stime;
18388 +}
18389 +
18390 +
18391 +
18392 +static inline uint32_t __update_loadavg(uint32_t load,
18393 +       int wsize, int delta, int n)
18394 +{
18395 +       unsigned long long calc, prev;
18396 +
18397 +       /* just set it to n */
18398 +       if (unlikely(delta >= wsize))
18399 +               return (n << FSHIFT);
18400 +
18401 +       calc = delta * n;
18402 +       calc <<= FSHIFT;
18403 +       prev = (wsize - delta);
18404 +       prev *= load;
18405 +       calc += prev;
18406 +       do_div(calc, wsize);
18407 +       return calc;
18408 +}
18409 +
18410 +
18411 +void vx_update_load(struct vx_info *vxi)
18412 +{
18413 +       uint32_t now, last, delta;
18414 +       unsigned int nr_running, nr_uninterruptible;
18415 +       unsigned int total;
18416 +       unsigned long flags;
18417 +
18418 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18419 +
18420 +       now = jiffies;
18421 +       last = vxi->cvirt.load_last;
18422 +       delta = now - last;
18423 +
18424 +       if (delta < 5*HZ)
18425 +               goto out;
18426 +
18427 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18428 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18429 +       total = nr_running + nr_uninterruptible;
18430 +
18431 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18432 +               60*HZ, delta, total);
18433 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18434 +               5*60*HZ, delta, total);
18435 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18436 +               15*60*HZ, delta, total);
18437 +
18438 +       vxi->cvirt.load_last = now;
18439 +out:
18440 +       atomic_inc(&vxi->cvirt.load_updates);
18441 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18442 +}
18443 +
18444 +
18445 +/*
18446 + * Commands to do_syslog:
18447 + *
18448 + *      0 -- Close the log.  Currently a NOP.
18449 + *      1 -- Open the log. Currently a NOP.
18450 + *      2 -- Read from the log.
18451 + *      3 -- Read all messages remaining in the ring buffer.
18452 + *      4 -- Read and clear all messages remaining in the ring buffer
18453 + *      5 -- Clear ring buffer.
18454 + *      6 -- Disable printk's to console
18455 + *      7 -- Enable printk's to console
18456 + *      8 -- Set level of messages printed to console
18457 + *      9 -- Return number of unread characters in the log buffer
18458 + *     10 -- Return size of the log buffer
18459 + */
18460 +int vx_do_syslog(int type, char __user *buf, int len)
18461 +{
18462 +       int error = 0;
18463 +       int do_clear = 0;
18464 +       struct vx_info *vxi = current->vx_info;
18465 +       struct _vx_syslog *log;
18466 +
18467 +       if (!vxi)
18468 +               return -EINVAL;
18469 +       log = &vxi->cvirt.syslog;
18470 +
18471 +       switch (type) {
18472 +       case 0:         /* Close log */
18473 +       case 1:         /* Open log */
18474 +               break;
18475 +       case 2:         /* Read from log */
18476 +               error = wait_event_interruptible(log->log_wait,
18477 +                       (log->log_start - log->log_end));
18478 +               if (error)
18479 +                       break;
18480 +               spin_lock_irq(&log->logbuf_lock);
18481 +               spin_unlock_irq(&log->logbuf_lock);
18482 +               break;
18483 +       case 4:         /* Read/clear last kernel messages */
18484 +               do_clear = 1;
18485 +               /* fall through */
18486 +       case 3:         /* Read last kernel messages */
18487 +               return 0;
18488 +
18489 +       case 5:         /* Clear ring buffer */
18490 +               return 0;
18491 +
18492 +       case 6:         /* Disable logging to console */
18493 +       case 7:         /* Enable logging to console */
18494 +       case 8:         /* Set level of messages printed to console */
18495 +               break;
18496 +
18497 +       case 9:         /* Number of chars in the log buffer */
18498 +               return 0;
18499 +       case 10:        /* Size of the log buffer */
18500 +               return 0;
18501 +       default:
18502 +               error = -EINVAL;
18503 +               break;
18504 +       }
18505 +       return error;
18506 +}
18507 +
18508 +
18509 +/* virtual host info names */
18510 +
18511 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18512 +{
18513 +       struct nsproxy *nsproxy;
18514 +       struct uts_namespace *uts;
18515 +
18516 +       if (id == VHIN_CONTEXT)
18517 +               return vxi->vx_name;
18518 +
18519 +       nsproxy = vxi->vx_nsproxy[0];
18520 +       if (!nsproxy)
18521 +               return NULL;
18522 +
18523 +       uts = nsproxy->uts_ns;
18524 +       if (!uts)
18525 +               return NULL;
18526 +
18527 +       switch (id) {
18528 +       case VHIN_SYSNAME:
18529 +               return uts->name.sysname;
18530 +       case VHIN_NODENAME:
18531 +               return uts->name.nodename;
18532 +       case VHIN_RELEASE:
18533 +               return uts->name.release;
18534 +       case VHIN_VERSION:
18535 +               return uts->name.version;
18536 +       case VHIN_MACHINE:
18537 +               return uts->name.machine;
18538 +       case VHIN_DOMAINNAME:
18539 +               return uts->name.domainname;
18540 +       default:
18541 +               return NULL;
18542 +       }
18543 +       return NULL;
18544 +}
18545 +
18546 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18547 +{
18548 +       struct vcmd_vhi_name_v0 vc_data;
18549 +       char *name;
18550 +
18551 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18552 +               return -EFAULT;
18553 +
18554 +       name = vx_vhi_name(vxi, vc_data.field);
18555 +       if (!name)
18556 +               return -EINVAL;
18557 +
18558 +       memcpy(name, vc_data.name, 65);
18559 +       return 0;
18560 +}
18561 +
18562 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18563 +{
18564 +       struct vcmd_vhi_name_v0 vc_data;
18565 +       char *name;
18566 +
18567 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18568 +               return -EFAULT;
18569 +
18570 +       name = vx_vhi_name(vxi, vc_data.field);
18571 +       if (!name)
18572 +               return -EINVAL;
18573 +
18574 +       memcpy(vc_data.name, name, 65);
18575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18576 +               return -EFAULT;
18577 +       return 0;
18578 +}
18579 +
18580 +
18581 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18582 +{
18583 +       struct vcmd_virt_stat_v0 vc_data;
18584 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18585 +       struct timespec uptime;
18586 +
18587 +       do_posix_clock_monotonic_gettime(&uptime);
18588 +       set_normalized_timespec(&uptime,
18589 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18590 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18591 +
18592 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18593 +       vc_data.uptime = timespec_to_ns(&uptime);
18594 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18595 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18596 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18597 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18598 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18599 +       vc_data.load[0] = cvirt->load[0];
18600 +       vc_data.load[1] = cvirt->load[1];
18601 +       vc_data.load[2] = cvirt->load[2];
18602 +
18603 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18604 +               return -EFAULT;
18605 +       return 0;
18606 +}
18607 +
18608 +
18609 +#ifdef CONFIG_VSERVER_VTIME
18610 +
18611 +/* virtualized time base */
18612 +
18613 +void vx_gettimeofday(struct timeval *tv)
18614 +{
18615 +       do_gettimeofday(tv);
18616 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18617 +               return;
18618 +
18619 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18620 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18621 +
18622 +       if (tv->tv_usec >= USEC_PER_SEC) {
18623 +               tv->tv_sec++;
18624 +               tv->tv_usec -= USEC_PER_SEC;
18625 +       } else if (tv->tv_usec < 0) {
18626 +               tv->tv_sec--;
18627 +               tv->tv_usec += USEC_PER_SEC;
18628 +       }
18629 +}
18630 +
18631 +int vx_settimeofday(struct timespec *ts)
18632 +{
18633 +       struct timeval tv;
18634 +
18635 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18636 +               return do_settimeofday(ts);
18637 +
18638 +       do_gettimeofday(&tv);
18639 +       current->vx_info->cvirt.bias_tv.tv_sec =
18640 +               ts->tv_sec - tv.tv_sec;
18641 +       current->vx_info->cvirt.bias_tv.tv_usec =
18642 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18643 +       return 0;
18644 +}
18645 +
18646 +#endif
18647 +
18648 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/cvirt_init.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cvirt_init.h
18649 --- linux-2.6.27.10/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
18650 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cvirt_init.h    2008-10-13 14:54:20.000000000 +0200
18651 @@ -0,0 +1,69 @@
18652 +
18653 +
18654 +extern uint64_t vx_idle_jiffies(void);
18655 +
18656 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18657 +{
18658 +       uint64_t idle_jiffies = vx_idle_jiffies();
18659 +       uint64_t nsuptime;
18660 +
18661 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18662 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18663 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18664 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18665 +       cvirt->bias_tv.tv_sec = 0;
18666 +       cvirt->bias_tv.tv_usec = 0;
18667 +
18668 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18669 +       atomic_set(&cvirt->nr_threads, 0);
18670 +       atomic_set(&cvirt->nr_running, 0);
18671 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18672 +       atomic_set(&cvirt->nr_onhold, 0);
18673 +
18674 +       spin_lock_init(&cvirt->load_lock);
18675 +       cvirt->load_last = jiffies;
18676 +       atomic_set(&cvirt->load_updates, 0);
18677 +       cvirt->load[0] = 0;
18678 +       cvirt->load[1] = 0;
18679 +       cvirt->load[2] = 0;
18680 +       atomic_set(&cvirt->total_forks, 0);
18681 +
18682 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18683 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18684 +       cvirt->syslog.log_start = 0;
18685 +       cvirt->syslog.log_end = 0;
18686 +       cvirt->syslog.con_start = 0;
18687 +       cvirt->syslog.logged_chars = 0;
18688 +}
18689 +
18690 +static inline
18691 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18692 +{
18693 +       // cvirt_pc->cpustat = { 0 };
18694 +}
18695 +
18696 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18697 +{
18698 +       int value;
18699 +
18700 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18701 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18702 +               cvirt, value);
18703 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18704 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18705 +               cvirt, value);
18706 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18707 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18708 +               cvirt, value);
18709 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18710 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18711 +               cvirt, value);
18712 +       return;
18713 +}
18714 +
18715 +static inline
18716 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18717 +{
18718 +       return;
18719 +}
18720 +
18721 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/cvirt_proc.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cvirt_proc.h
18722 --- linux-2.6.27.10/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
18723 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/cvirt_proc.h    2008-10-13 14:54:20.000000000 +0200
18724 @@ -0,0 +1,135 @@
18725 +#ifndef _VX_CVIRT_PROC_H
18726 +#define _VX_CVIRT_PROC_H
18727 +
18728 +#include <linux/nsproxy.h>
18729 +#include <linux/mnt_namespace.h>
18730 +#include <linux/ipc_namespace.h>
18731 +#include <linux/utsname.h>
18732 +#include <linux/ipc.h>
18733 +
18734 +
18735 +static inline
18736 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18737 +{
18738 +       struct mnt_namespace *ns;
18739 +       struct uts_namespace *uts;
18740 +       struct ipc_namespace *ipc;
18741 +       struct path path;
18742 +       char *pstr, *root;
18743 +       int length = 0;
18744 +
18745 +       if (!nsproxy)
18746 +               goto out;
18747 +
18748 +       length += sprintf(buffer + length,
18749 +               "NSProxy:\t%p [%p,%p,%p]\n",
18750 +               nsproxy, nsproxy->mnt_ns,
18751 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18752 +
18753 +       ns = nsproxy->mnt_ns;
18754 +       if (!ns)
18755 +               goto skip_ns;
18756 +
18757 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18758 +       if (!pstr)
18759 +               goto skip_ns;
18760 +
18761 +       path.mnt = ns->root;
18762 +       path.dentry = ns->root->mnt_root;
18763 +       root = d_path(&path, pstr, PATH_MAX - 2);
18764 +       length += sprintf(buffer + length,
18765 +               "Namespace:\t%p [#%u]\n"
18766 +               "RootPath:\t%s\n",
18767 +               ns, atomic_read(&ns->count),
18768 +               root);
18769 +       kfree(pstr);
18770 +skip_ns:
18771 +
18772 +       uts = nsproxy->uts_ns;
18773 +       if (!uts)
18774 +               goto skip_uts;
18775 +
18776 +       length += sprintf(buffer + length,
18777 +               "SysName:\t%.*s\n"
18778 +               "NodeName:\t%.*s\n"
18779 +               "Release:\t%.*s\n"
18780 +               "Version:\t%.*s\n"
18781 +               "Machine:\t%.*s\n"
18782 +               "DomainName:\t%.*s\n",
18783 +               __NEW_UTS_LEN, uts->name.sysname,
18784 +               __NEW_UTS_LEN, uts->name.nodename,
18785 +               __NEW_UTS_LEN, uts->name.release,
18786 +               __NEW_UTS_LEN, uts->name.version,
18787 +               __NEW_UTS_LEN, uts->name.machine,
18788 +               __NEW_UTS_LEN, uts->name.domainname);
18789 +skip_uts:
18790 +
18791 +       ipc = nsproxy->ipc_ns;
18792 +       if (!ipc)
18793 +               goto skip_ipc;
18794 +
18795 +       length += sprintf(buffer + length,
18796 +               "SEMS:\t\t%d %d %d %d  %d\n"
18797 +               "MSG:\t\t%d %d %d\n"
18798 +               "SHM:\t\t%lu %lu  %d %d\n",
18799 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18800 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18801 +               ipc->used_sems,
18802 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18803 +               (unsigned long)ipc->shm_ctlmax,
18804 +               (unsigned long)ipc->shm_ctlall,
18805 +               ipc->shm_ctlmni, ipc->shm_tot);
18806 +skip_ipc:
18807 +out:
18808 +       return length;
18809 +}
18810 +
18811 +
18812 +#include <linux/sched.h>
18813 +
18814 +#define LOAD_INT(x) ((x) >> FSHIFT)
18815 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18816 +
18817 +static inline
18818 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18819 +{
18820 +       int length = 0;
18821 +       int a, b, c;
18822 +
18823 +       length += sprintf(buffer + length,
18824 +               "BiasUptime:\t%lu.%02lu\n",
18825 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18826 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18827 +
18828 +       a = cvirt->load[0] + (FIXED_1 / 200);
18829 +       b = cvirt->load[1] + (FIXED_1 / 200);
18830 +       c = cvirt->load[2] + (FIXED_1 / 200);
18831 +       length += sprintf(buffer + length,
18832 +               "nr_threads:\t%d\n"
18833 +               "nr_running:\t%d\n"
18834 +               "nr_unintr:\t%d\n"
18835 +               "nr_onhold:\t%d\n"
18836 +               "load_updates:\t%d\n"
18837 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18838 +               "total_forks:\t%d\n",
18839 +               atomic_read(&cvirt->nr_threads),
18840 +               atomic_read(&cvirt->nr_running),
18841 +               atomic_read(&cvirt->nr_uninterruptible),
18842 +               atomic_read(&cvirt->nr_onhold),
18843 +               atomic_read(&cvirt->load_updates),
18844 +               LOAD_INT(a), LOAD_FRAC(a),
18845 +               LOAD_INT(b), LOAD_FRAC(b),
18846 +               LOAD_INT(c), LOAD_FRAC(c),
18847 +               atomic_read(&cvirt->total_forks));
18848 +       return length;
18849 +}
18850 +
18851 +static inline
18852 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18853 +       char *buffer, int cpu)
18854 +{
18855 +       int length = 0;
18856 +       return length;
18857 +}
18858 +
18859 +#endif /* _VX_CVIRT_PROC_H */
18860 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/debug.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/debug.c
18861 --- linux-2.6.27.10/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
18862 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/debug.c 2008-10-13 14:54:20.000000000 +0200
18863 @@ -0,0 +1,32 @@
18864 +/*
18865 + *  kernel/vserver/debug.c
18866 + *
18867 + *  Copyright (C) 2005-2007 Herbert Pötzl
18868 + *
18869 + *  V0.01  vx_info dump support
18870 + *
18871 + */
18872 +
18873 +#include <linux/module.h>
18874 +
18875 +#include <linux/vserver/context.h>
18876 +
18877 +
18878 +void   dump_vx_info(struct vx_info *vxi, int level)
18879 +{
18880 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18881 +               atomic_read(&vxi->vx_usecnt),
18882 +               atomic_read(&vxi->vx_tasks),
18883 +               vxi->vx_state);
18884 +       if (level > 0) {
18885 +               __dump_vx_limit(&vxi->limit);
18886 +               __dump_vx_sched(&vxi->sched);
18887 +               __dump_vx_cvirt(&vxi->cvirt);
18888 +               __dump_vx_cacct(&vxi->cacct);
18889 +       }
18890 +       printk("---\n");
18891 +}
18892 +
18893 +
18894 +EXPORT_SYMBOL_GPL(dump_vx_info);
18895 +
18896 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/device.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/device.c
18897 --- linux-2.6.27.10/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
18898 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/device.c        2008-10-13 14:54:20.000000000 +0200
18899 @@ -0,0 +1,443 @@
18900 +/*
18901 + *  linux/kernel/vserver/device.c
18902 + *
18903 + *  Linux-VServer: Device Support
18904 + *
18905 + *  Copyright (C) 2006  Herbert Pötzl
18906 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18907 + *
18908 + *  V0.01  device mapping basics
18909 + *  V0.02  added defaults
18910 + *
18911 + */
18912 +
18913 +#include <linux/slab.h>
18914 +#include <linux/rcupdate.h>
18915 +#include <linux/fs.h>
18916 +#include <linux/namei.h>
18917 +#include <linux/hash.h>
18918 +
18919 +#include <asm/errno.h>
18920 +#include <asm/uaccess.h>
18921 +#include <linux/vserver/base.h>
18922 +#include <linux/vserver/debug.h>
18923 +#include <linux/vserver/context.h>
18924 +#include <linux/vserver/device.h>
18925 +#include <linux/vserver/device_cmd.h>
18926 +
18927 +
18928 +#define DMAP_HASH_BITS 4
18929 +
18930 +
18931 +struct vs_mapping {
18932 +       union {
18933 +               struct hlist_node hlist;
18934 +               struct list_head list;
18935 +       } u;
18936 +#define dm_hlist       u.hlist
18937 +#define dm_list                u.list
18938 +       xid_t xid;
18939 +       dev_t device;
18940 +       struct vx_dmap_target target;
18941 +};
18942 +
18943 +
18944 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18945 +
18946 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18947 +
18948 +static struct vx_dmap_target dmap_defaults[2] = {
18949 +       { .flags = DATTR_OPEN },
18950 +       { .flags = DATTR_OPEN },
18951 +};
18952 +
18953 +
18954 +struct kmem_cache *dmap_cachep __read_mostly;
18955 +
18956 +int __init dmap_cache_init(void)
18957 +{
18958 +       dmap_cachep = kmem_cache_create("dmap_cache",
18959 +               sizeof(struct vs_mapping), 0,
18960 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18961 +       return 0;
18962 +}
18963 +
18964 +__initcall(dmap_cache_init);
18965 +
18966 +
18967 +static inline unsigned int __hashval(dev_t dev, int bits)
18968 +{
18969 +       return hash_long((unsigned long)dev, bits);
18970 +}
18971 +
18972 +
18973 +/*     __hash_mapping()
18974 + *     add the mapping to the hash table
18975 + */
18976 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18977 +{
18978 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18979 +       struct hlist_head *head, *hash = dmap_main_hash;
18980 +       int device = vdm->device;
18981 +
18982 +       spin_lock(hash_lock);
18983 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18984 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18985 +
18986 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18987 +       hlist_add_head(&vdm->dm_hlist, head);
18988 +       spin_unlock(hash_lock);
18989 +}
18990 +
18991 +
18992 +static inline int __mode_to_default(umode_t mode)
18993 +{
18994 +       switch (mode) {
18995 +       case S_IFBLK:
18996 +               return 0;
18997 +       case S_IFCHR:
18998 +               return 1;
18999 +       default:
19000 +               BUG();
19001 +       }
19002 +}
19003 +
19004 +
19005 +/*     __set_default()
19006 + *     set a default
19007 + */
19008 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19009 +       struct vx_dmap_target *vdmt)
19010 +{
19011 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19012 +       spin_lock(hash_lock);
19013 +
19014 +       if (vxi)
19015 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19016 +       else
19017 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19018 +
19019 +
19020 +       spin_unlock(hash_lock);
19021 +
19022 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19023 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19024 +}
19025 +
19026 +
19027 +/*     __remove_default()
19028 + *     remove a default
19029 + */
19030 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19031 +{
19032 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19033 +       spin_lock(hash_lock);
19034 +
19035 +       if (vxi)
19036 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19037 +       else    /* remove == reset */
19038 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19039 +
19040 +       spin_unlock(hash_lock);
19041 +       return 0;
19042 +}
19043 +
19044 +
19045 +/*     __find_mapping()
19046 + *     find a mapping in the hash table
19047 + *
19048 + *     caller must hold hash_lock
19049 + */
19050 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19051 +       struct vs_mapping **local, struct vs_mapping **global)
19052 +{
19053 +       struct hlist_head *hash = dmap_main_hash;
19054 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19055 +       struct hlist_node *pos;
19056 +       struct vs_mapping *vdm;
19057 +
19058 +       *local = NULL;
19059 +       if (global)
19060 +               *global = NULL;
19061 +
19062 +       hlist_for_each(pos, head) {
19063 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19064 +
19065 +               if ((vdm->device == device) &&
19066 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19067 +                       if (vdm->xid == xid) {
19068 +                               *local = vdm;
19069 +                               return 1;
19070 +                       } else if (global && vdm->xid == 0)
19071 +                               *global = vdm;
19072 +               }
19073 +       }
19074 +
19075 +       if (global && *global)
19076 +               return 0;
19077 +       else
19078 +               return -ENOENT;
19079 +}
19080 +
19081 +
19082 +/*     __lookup_mapping()
19083 + *     find a mapping and store the result in target and flags
19084 + */
19085 +static inline int __lookup_mapping(struct vx_info *vxi,
19086 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19087 +{
19088 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19089 +       struct vs_mapping *vdm, *global;
19090 +       struct vx_dmap_target *vdmt;
19091 +       int ret = 0;
19092 +       xid_t xid = vxi->vx_id;
19093 +       int index;
19094 +
19095 +       spin_lock(hash_lock);
19096 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19097 +               ret = 1;
19098 +               vdmt = &vdm->target;
19099 +               goto found;
19100 +       }
19101 +
19102 +       index = __mode_to_default(mode);
19103 +       if (vxi && vxi->dmap.targets[index].flags) {
19104 +               ret = 2;
19105 +               vdmt = &vxi->dmap.targets[index];
19106 +       } else if (global) {
19107 +               ret = 3;
19108 +               vdmt = &global->target;
19109 +               goto found;
19110 +       } else {
19111 +               ret = 4;
19112 +               vdmt = &dmap_defaults[index];
19113 +       }
19114 +
19115 +found:
19116 +       if (target && (vdmt->flags & DATTR_REMAP))
19117 +               *target = vdmt->target;
19118 +       else if (target)
19119 +               *target = device;
19120 +       if (flags)
19121 +               *flags = vdmt->flags;
19122 +
19123 +       spin_unlock(hash_lock);
19124 +
19125 +       return ret;
19126 +}
19127 +
19128 +
19129 +/*     __remove_mapping()
19130 + *     remove a mapping from the hash table
19131 + */
19132 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19133 +       umode_t mode)
19134 +{
19135 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19136 +       struct vs_mapping *vdm = NULL;
19137 +       int ret = 0;
19138 +
19139 +       spin_lock(hash_lock);
19140 +
19141 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19142 +               NULL);
19143 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19144 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19145 +       if (ret < 0)
19146 +               goto out;
19147 +       hlist_del(&vdm->dm_hlist);
19148 +
19149 +out:
19150 +       spin_unlock(hash_lock);
19151 +       if (vdm)
19152 +               kmem_cache_free(dmap_cachep, vdm);
19153 +       return ret;
19154 +}
19155 +
19156 +
19157 +
19158 +int vs_map_device(struct vx_info *vxi,
19159 +       dev_t device, dev_t *target, umode_t mode)
19160 +{
19161 +       int ret, flags = DATTR_MASK;
19162 +
19163 +       if (!vxi) {
19164 +               if (target)
19165 +                       *target = device;
19166 +               goto out;
19167 +       }
19168 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19169 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19170 +               device, target ? *target : 0, flags, mode, ret);
19171 +out:
19172 +       return (flags & DATTR_MASK);
19173 +}
19174 +
19175 +
19176 +
19177 +static int do_set_mapping(struct vx_info *vxi,
19178 +       dev_t device, dev_t target, int flags, umode_t mode)
19179 +{
19180 +       if (device) {
19181 +               struct vs_mapping *new;
19182 +
19183 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19184 +               if (!new)
19185 +                       return -ENOMEM;
19186 +
19187 +               INIT_HLIST_NODE(&new->dm_hlist);
19188 +               new->device = device;
19189 +               new->target.target = target;
19190 +               new->target.flags = flags | mode;
19191 +               new->xid = (vxi ? vxi->vx_id : 0);
19192 +
19193 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19194 +               __hash_mapping(vxi, new);
19195 +       } else {
19196 +               struct vx_dmap_target new = {
19197 +                       .target = target,
19198 +                       .flags = flags | mode,
19199 +               };
19200 +               __set_default(vxi, mode, &new);
19201 +       }
19202 +       return 0;
19203 +}
19204 +
19205 +
19206 +static int do_unset_mapping(struct vx_info *vxi,
19207 +       dev_t device, dev_t target, int flags, umode_t mode)
19208 +{
19209 +       int ret = -EINVAL;
19210 +
19211 +       if (device) {
19212 +               ret = __remove_mapping(vxi, device, mode);
19213 +               if (ret < 0)
19214 +                       goto out;
19215 +       } else {
19216 +               ret = __remove_default(vxi, mode);
19217 +               if (ret < 0)
19218 +                       goto out;
19219 +       }
19220 +
19221 +out:
19222 +       return ret;
19223 +}
19224 +
19225 +
19226 +static inline int __user_device(const char __user *name, dev_t *dev,
19227 +       umode_t *mode)
19228 +{
19229 +       struct nameidata nd;
19230 +       int ret;
19231 +
19232 +       if (!name) {
19233 +               *dev = 0;
19234 +               return 0;
19235 +       }
19236 +       ret = user_lpath(name, &nd.path);
19237 +       if (ret)
19238 +               return ret;
19239 +       if (nd.path.dentry->d_inode) {
19240 +               *dev = nd.path.dentry->d_inode->i_rdev;
19241 +               *mode = nd.path.dentry->d_inode->i_mode;
19242 +       }
19243 +       path_put(&nd.path);
19244 +       return 0;
19245 +}
19246 +
19247 +static inline int __mapping_mode(dev_t device, dev_t target,
19248 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19249 +{
19250 +       if (device)
19251 +               *mode = device_mode & S_IFMT;
19252 +       else if (target)
19253 +               *mode = target_mode & S_IFMT;
19254 +       else
19255 +               return -EINVAL;
19256 +
19257 +       /* if both given, device and target mode have to match */
19258 +       if (device && target &&
19259 +               ((device_mode ^ target_mode) & S_IFMT))
19260 +               return -EINVAL;
19261 +       return 0;
19262 +}
19263 +
19264 +
19265 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19266 +       const char __user *target_path, int flags, int set)
19267 +{
19268 +       dev_t device = ~0, target = ~0;
19269 +       umode_t device_mode = 0, target_mode = 0, mode;
19270 +       int ret;
19271 +
19272 +       ret = __user_device(device_path, &device, &device_mode);
19273 +       if (ret)
19274 +               return ret;
19275 +       ret = __user_device(target_path, &target, &target_mode);
19276 +       if (ret)
19277 +               return ret;
19278 +
19279 +       ret = __mapping_mode(device, target,
19280 +               device_mode, target_mode, &mode);
19281 +       if (ret)
19282 +               return ret;
19283 +
19284 +       if (set)
19285 +               return do_set_mapping(vxi, device, target,
19286 +                       flags, mode);
19287 +       else
19288 +               return do_unset_mapping(vxi, device, target,
19289 +                       flags, mode);
19290 +}
19291 +
19292 +
19293 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19294 +{
19295 +       struct vcmd_set_mapping_v0 vc_data;
19296 +
19297 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19298 +               return -EFAULT;
19299 +
19300 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19301 +               vc_data.flags, 1);
19302 +}
19303 +
19304 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19305 +{
19306 +       struct vcmd_set_mapping_v0 vc_data;
19307 +
19308 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19309 +               return -EFAULT;
19310 +
19311 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19312 +               vc_data.flags, 0);
19313 +}
19314 +
19315 +
19316 +#ifdef CONFIG_COMPAT
19317 +
19318 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19319 +{
19320 +       struct vcmd_set_mapping_v0_x32 vc_data;
19321 +
19322 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19323 +               return -EFAULT;
19324 +
19325 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19326 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19327 +}
19328 +
19329 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19330 +{
19331 +       struct vcmd_set_mapping_v0_x32 vc_data;
19332 +
19333 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19334 +               return -EFAULT;
19335 +
19336 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19337 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19338 +}
19339 +
19340 +#endif /* CONFIG_COMPAT */
19341 +
19342 +
19343 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/dlimit.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/dlimit.c
19344 --- linux-2.6.27.10/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
19345 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/dlimit.c        2008-10-13 14:54:20.000000000 +0200
19346 @@ -0,0 +1,522 @@
19347 +/*
19348 + *  linux/kernel/vserver/dlimit.c
19349 + *
19350 + *  Virtual Server: Context Disk Limits
19351 + *
19352 + *  Copyright (C) 2004-2007  Herbert Pötzl
19353 + *
19354 + *  V0.01  initial version
19355 + *  V0.02  compat32 splitup
19356 + *
19357 + */
19358 +
19359 +#include <linux/statfs.h>
19360 +#include <linux/sched.h>
19361 +#include <linux/namei.h>
19362 +#include <linux/vs_tag.h>
19363 +#include <linux/vs_dlimit.h>
19364 +#include <linux/vserver/dlimit_cmd.h>
19365 +
19366 +#include <asm/uaccess.h>
19367 +
19368 +/*     __alloc_dl_info()
19369 +
19370 +       * allocate an initialized dl_info struct
19371 +       * doesn't make it visible (hash)                        */
19372 +
19373 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19374 +{
19375 +       struct dl_info *new = NULL;
19376 +
19377 +       vxdprintk(VXD_CBIT(dlim, 5),
19378 +               "alloc_dl_info(%p,%d)*", sb, tag);
19379 +
19380 +       /* would this benefit from a slab cache? */
19381 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19382 +       if (!new)
19383 +               return 0;
19384 +
19385 +       memset(new, 0, sizeof(struct dl_info));
19386 +       new->dl_tag = tag;
19387 +       new->dl_sb = sb;
19388 +       INIT_RCU_HEAD(&new->dl_rcu);
19389 +       INIT_HLIST_NODE(&new->dl_hlist);
19390 +       spin_lock_init(&new->dl_lock);
19391 +       atomic_set(&new->dl_refcnt, 0);
19392 +       atomic_set(&new->dl_usecnt, 0);
19393 +
19394 +       /* rest of init goes here */
19395 +
19396 +       vxdprintk(VXD_CBIT(dlim, 4),
19397 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19398 +       return new;
19399 +}
19400 +
19401 +/*     __dealloc_dl_info()
19402 +
19403 +       * final disposal of dl_info                             */
19404 +
19405 +static void __dealloc_dl_info(struct dl_info *dli)
19406 +{
19407 +       vxdprintk(VXD_CBIT(dlim, 4),
19408 +               "dealloc_dl_info(%p)", dli);
19409 +
19410 +       dli->dl_hlist.next = LIST_POISON1;
19411 +       dli->dl_tag = -1;
19412 +       dli->dl_sb = 0;
19413 +
19414 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19415 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19416 +
19417 +       kfree(dli);
19418 +}
19419 +
19420 +
19421 +/*     hash table for dl_info hash */
19422 +
19423 +#define DL_HASH_SIZE   13
19424 +
19425 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19426 +
19427 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19428 +
19429 +
19430 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19431 +{
19432 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19433 +}
19434 +
19435 +
19436 +
19437 +/*     __hash_dl_info()
19438 +
19439 +       * add the dli to the global hash table
19440 +       * requires the hash_lock to be held                     */
19441 +
19442 +static inline void __hash_dl_info(struct dl_info *dli)
19443 +{
19444 +       struct hlist_head *head;
19445 +
19446 +       vxdprintk(VXD_CBIT(dlim, 6),
19447 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19448 +       get_dl_info(dli);
19449 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19450 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19451 +}
19452 +
19453 +/*     __unhash_dl_info()
19454 +
19455 +       * remove the dli from the global hash table
19456 +       * requires the hash_lock to be held                     */
19457 +
19458 +static inline void __unhash_dl_info(struct dl_info *dli)
19459 +{
19460 +       vxdprintk(VXD_CBIT(dlim, 6),
19461 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19462 +       hlist_del_rcu(&dli->dl_hlist);
19463 +       put_dl_info(dli);
19464 +}
19465 +
19466 +
19467 +/*     __lookup_dl_info()
19468 +
19469 +       * requires the rcu_read_lock()
19470 +       * doesn't increment the dl_refcnt                       */
19471 +
19472 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19473 +{
19474 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19475 +       struct hlist_node *pos;
19476 +       struct dl_info *dli;
19477 +
19478 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19479 +
19480 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19481 +                       return dli;
19482 +               }
19483 +       }
19484 +       return NULL;
19485 +}
19486 +
19487 +
19488 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19489 +{
19490 +       struct dl_info *dli;
19491 +
19492 +       rcu_read_lock();
19493 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19494 +       vxdprintk(VXD_CBIT(dlim, 7),
19495 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19496 +       rcu_read_unlock();
19497 +       return dli;
19498 +}
19499 +
19500 +void rcu_free_dl_info(struct rcu_head *head)
19501 +{
19502 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19503 +       int usecnt, refcnt;
19504 +
19505 +       BUG_ON(!dli || !head);
19506 +
19507 +       usecnt = atomic_read(&dli->dl_usecnt);
19508 +       BUG_ON(usecnt < 0);
19509 +
19510 +       refcnt = atomic_read(&dli->dl_refcnt);
19511 +       BUG_ON(refcnt < 0);
19512 +
19513 +       vxdprintk(VXD_CBIT(dlim, 3),
19514 +               "rcu_free_dl_info(%p)", dli);
19515 +       if (!usecnt)
19516 +               __dealloc_dl_info(dli);
19517 +       else
19518 +               printk("!!! rcu didn't free\n");
19519 +}
19520 +
19521 +
19522 +
19523 +
19524 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19525 +       uint32_t flags, int add)
19526 +{
19527 +       struct path path;
19528 +       int ret;
19529 +
19530 +       ret = user_lpath(name, &path);
19531 +       if (!ret) {
19532 +               struct super_block *sb;
19533 +               struct dl_info *dli;
19534 +
19535 +               ret = -EINVAL;
19536 +               if (!path.dentry->d_inode)
19537 +                       goto out_release;
19538 +               if (!(sb = path.dentry->d_inode->i_sb))
19539 +                       goto out_release;
19540 +
19541 +               if (add) {
19542 +                       dli = __alloc_dl_info(sb, id);
19543 +                       spin_lock(&dl_info_hash_lock);
19544 +
19545 +                       ret = -EEXIST;
19546 +                       if (__lookup_dl_info(sb, id))
19547 +                               goto out_unlock;
19548 +                       __hash_dl_info(dli);
19549 +                       dli = NULL;
19550 +               } else {
19551 +                       spin_lock(&dl_info_hash_lock);
19552 +                       dli = __lookup_dl_info(sb, id);
19553 +
19554 +                       ret = -ESRCH;
19555 +                       if (!dli)
19556 +                               goto out_unlock;
19557 +                       __unhash_dl_info(dli);
19558 +               }
19559 +               ret = 0;
19560 +       out_unlock:
19561 +               spin_unlock(&dl_info_hash_lock);
19562 +               if (add && dli)
19563 +                       __dealloc_dl_info(dli);
19564 +       out_release:
19565 +               path_put(&path);
19566 +       }
19567 +       return ret;
19568 +}
19569 +
19570 +int vc_add_dlimit(uint32_t id, void __user *data)
19571 +{
19572 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19573 +
19574 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19575 +               return -EFAULT;
19576 +
19577 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19578 +}
19579 +
19580 +int vc_rem_dlimit(uint32_t id, void __user *data)
19581 +{
19582 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19583 +
19584 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19585 +               return -EFAULT;
19586 +
19587 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19588 +}
19589 +
19590 +#ifdef CONFIG_COMPAT
19591 +
19592 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19593 +{
19594 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19595 +
19596 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19597 +               return -EFAULT;
19598 +
19599 +       return do_addrem_dlimit(id,
19600 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19601 +}
19602 +
19603 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19604 +{
19605 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19606 +
19607 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19608 +               return -EFAULT;
19609 +
19610 +       return do_addrem_dlimit(id,
19611 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19612 +}
19613 +
19614 +#endif /* CONFIG_COMPAT */
19615 +
19616 +
19617 +static inline
19618 +int do_set_dlimit(uint32_t id, const char __user *name,
19619 +       uint32_t space_used, uint32_t space_total,
19620 +       uint32_t inodes_used, uint32_t inodes_total,
19621 +       uint32_t reserved, uint32_t flags)
19622 +{
19623 +       struct path path;
19624 +       int ret;
19625 +
19626 +       ret = user_lpath(name, &path);
19627 +       if (!ret) {
19628 +               struct super_block *sb;
19629 +               struct dl_info *dli;
19630 +
19631 +               ret = -EINVAL;
19632 +               if (!path.dentry->d_inode)
19633 +                       goto out_release;
19634 +               if (!(sb = path.dentry->d_inode->i_sb))
19635 +                       goto out_release;
19636 +               if ((reserved != CDLIM_KEEP &&
19637 +                       reserved > 100) ||
19638 +                       (inodes_used != CDLIM_KEEP &&
19639 +                       inodes_used > inodes_total) ||
19640 +                       (space_used != CDLIM_KEEP &&
19641 +                       space_used > space_total))
19642 +                       goto out_release;
19643 +
19644 +               ret = -ESRCH;
19645 +               dli = locate_dl_info(sb, id);
19646 +               if (!dli)
19647 +                       goto out_release;
19648 +
19649 +               spin_lock(&dli->dl_lock);
19650 +
19651 +               if (inodes_used != CDLIM_KEEP)
19652 +                       dli->dl_inodes_used = inodes_used;
19653 +               if (inodes_total != CDLIM_KEEP)
19654 +                       dli->dl_inodes_total = inodes_total;
19655 +               if (space_used != CDLIM_KEEP) {
19656 +                       dli->dl_space_used = space_used;
19657 +                       dli->dl_space_used <<= 10;
19658 +               }
19659 +               if (space_total == CDLIM_INFINITY)
19660 +                       dli->dl_space_total = DLIM_INFINITY;
19661 +               else if (space_total != CDLIM_KEEP) {
19662 +                       dli->dl_space_total = space_total;
19663 +                       dli->dl_space_total <<= 10;
19664 +               }
19665 +               if (reserved != CDLIM_KEEP)
19666 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19667 +
19668 +               spin_unlock(&dli->dl_lock);
19669 +
19670 +               put_dl_info(dli);
19671 +               ret = 0;
19672 +
19673 +       out_release:
19674 +               path_put(&path);
19675 +       }
19676 +       return ret;
19677 +}
19678 +
19679 +int vc_set_dlimit(uint32_t id, void __user *data)
19680 +{
19681 +       struct vcmd_ctx_dlimit_v0 vc_data;
19682 +
19683 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19684 +               return -EFAULT;
19685 +
19686 +       return do_set_dlimit(id, vc_data.name,
19687 +               vc_data.space_used, vc_data.space_total,
19688 +               vc_data.inodes_used, vc_data.inodes_total,
19689 +               vc_data.reserved, vc_data.flags);
19690 +}
19691 +
19692 +#ifdef CONFIG_COMPAT
19693 +
19694 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19695 +{
19696 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19697 +
19698 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19699 +               return -EFAULT;
19700 +
19701 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19702 +               vc_data.space_used, vc_data.space_total,
19703 +               vc_data.inodes_used, vc_data.inodes_total,
19704 +               vc_data.reserved, vc_data.flags);
19705 +}
19706 +
19707 +#endif /* CONFIG_COMPAT */
19708 +
19709 +
19710 +static inline
19711 +int do_get_dlimit(uint32_t id, const char __user *name,
19712 +       uint32_t *space_used, uint32_t *space_total,
19713 +       uint32_t *inodes_used, uint32_t *inodes_total,
19714 +       uint32_t *reserved, uint32_t *flags)
19715 +{
19716 +       struct path path;
19717 +       int ret;
19718 +
19719 +       ret = user_lpath(name, &path);
19720 +       if (!ret) {
19721 +               struct super_block *sb;
19722 +               struct dl_info *dli;
19723 +
19724 +               ret = -EINVAL;
19725 +               if (!path.dentry->d_inode)
19726 +                       goto out_release;
19727 +               if (!(sb = path.dentry->d_inode->i_sb))
19728 +                       goto out_release;
19729 +
19730 +               ret = -ESRCH;
19731 +               dli = locate_dl_info(sb, id);
19732 +               if (!dli)
19733 +                       goto out_release;
19734 +
19735 +               spin_lock(&dli->dl_lock);
19736 +               *inodes_used = dli->dl_inodes_used;
19737 +               *inodes_total = dli->dl_inodes_total;
19738 +               *space_used = dli->dl_space_used >> 10;
19739 +               if (dli->dl_space_total == DLIM_INFINITY)
19740 +                       *space_total = CDLIM_INFINITY;
19741 +               else
19742 +                       *space_total = dli->dl_space_total >> 10;
19743 +
19744 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19745 +               spin_unlock(&dli->dl_lock);
19746 +
19747 +               put_dl_info(dli);
19748 +               ret = -EFAULT;
19749 +
19750 +               ret = 0;
19751 +       out_release:
19752 +               path_put(&path);
19753 +       }
19754 +       return ret;
19755 +}
19756 +
19757 +
19758 +int vc_get_dlimit(uint32_t id, void __user *data)
19759 +{
19760 +       struct vcmd_ctx_dlimit_v0 vc_data;
19761 +       int ret;
19762 +
19763 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19764 +               return -EFAULT;
19765 +
19766 +       ret = do_get_dlimit(id, vc_data.name,
19767 +               &vc_data.space_used, &vc_data.space_total,
19768 +               &vc_data.inodes_used, &vc_data.inodes_total,
19769 +               &vc_data.reserved, &vc_data.flags);
19770 +       if (ret)
19771 +               return ret;
19772 +
19773 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19774 +               return -EFAULT;
19775 +       return 0;
19776 +}
19777 +
19778 +#ifdef CONFIG_COMPAT
19779 +
19780 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19781 +{
19782 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19783 +       int ret;
19784 +
19785 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19786 +               return -EFAULT;
19787 +
19788 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19789 +               &vc_data.space_used, &vc_data.space_total,
19790 +               &vc_data.inodes_used, &vc_data.inodes_total,
19791 +               &vc_data.reserved, &vc_data.flags);
19792 +       if (ret)
19793 +               return ret;
19794 +
19795 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19796 +               return -EFAULT;
19797 +       return 0;
19798 +}
19799 +
19800 +#endif /* CONFIG_COMPAT */
19801 +
19802 +
19803 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19804 +{
19805 +       struct dl_info *dli;
19806 +       __u64 blimit, bfree, bavail;
19807 +       __u32 ifree;
19808 +
19809 +       dli = locate_dl_info(sb, dx_current_tag());
19810 +       if (!dli)
19811 +               return;
19812 +
19813 +       spin_lock(&dli->dl_lock);
19814 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19815 +               goto no_ilim;
19816 +
19817 +       /* reduce max inodes available to limit */
19818 +       if (buf->f_files > dli->dl_inodes_total)
19819 +               buf->f_files = dli->dl_inodes_total;
19820 +
19821 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19822 +       /* reduce free inodes to min */
19823 +       if (ifree < buf->f_ffree)
19824 +               buf->f_ffree = ifree;
19825 +
19826 +no_ilim:
19827 +       if (dli->dl_space_total == DLIM_INFINITY)
19828 +               goto no_blim;
19829 +
19830 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19831 +
19832 +       if (dli->dl_space_total < dli->dl_space_used)
19833 +               bfree = 0;
19834 +       else
19835 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19836 +                       >> sb->s_blocksize_bits;
19837 +
19838 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19839 +       if (bavail < dli->dl_space_used)
19840 +               bavail = 0;
19841 +       else
19842 +               bavail = (bavail - dli->dl_space_used)
19843 +                       >> sb->s_blocksize_bits;
19844 +
19845 +       /* reduce max space available to limit */
19846 +       if (buf->f_blocks > blimit)
19847 +               buf->f_blocks = blimit;
19848 +
19849 +       /* reduce free space to min */
19850 +       if (bfree < buf->f_bfree)
19851 +               buf->f_bfree = bfree;
19852 +
19853 +       /* reduce avail space to min */
19854 +       if (bavail < buf->f_bavail)
19855 +               buf->f_bavail = bavail;
19856 +
19857 +no_blim:
19858 +       spin_unlock(&dli->dl_lock);
19859 +       put_dl_info(dli);
19860 +
19861 +       return;
19862 +}
19863 +
19864 +#include <linux/module.h>
19865 +
19866 +EXPORT_SYMBOL_GPL(locate_dl_info);
19867 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19868 +
19869 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/helper.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/helper.c
19870 --- linux-2.6.27.10/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
19871 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/helper.c        2008-10-13 14:54:20.000000000 +0200
19872 @@ -0,0 +1,199 @@
19873 +/*
19874 + *  linux/kernel/vserver/helper.c
19875 + *
19876 + *  Virtual Context Support
19877 + *
19878 + *  Copyright (C) 2004-2007  Herbert Pötzl
19879 + *
19880 + *  V0.01  basic helper
19881 + *
19882 + */
19883 +
19884 +#include <linux/kmod.h>
19885 +#include <linux/reboot.h>
19886 +#include <linux/vs_context.h>
19887 +#include <linux/vs_network.h>
19888 +#include <linux/vserver/signal.h>
19889 +
19890 +
19891 +char vshelper_path[255] = "/sbin/vshelper";
19892 +
19893 +
19894 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19895 +{
19896 +       int ret;
19897 +
19898 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19899 +               printk( KERN_WARNING
19900 +                       "%s: (%s %s) returned %s with %d\n",
19901 +                       name, argv[1], argv[2],
19902 +                       sync ? "sync" : "async", ret);
19903 +       }
19904 +       vxdprintk(VXD_CBIT(switch, 4),
19905 +               "%s: (%s %s) returned %s with %d",
19906 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19907 +       return ret;
19908 +}
19909 +
19910 +/*
19911 + *      vshelper path is set via /proc/sys
19912 + *      invoked by vserver sys_reboot(), with
19913 + *      the following arguments
19914 + *
19915 + *      argv [0] = vshelper_path;
19916 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19917 + *      argv [2] = context identifier
19918 + *
19919 + *      envp [*] = type-specific parameters
19920 + */
19921 +
19922 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19923 +{
19924 +       char id_buf[8], cmd_buf[16];
19925 +       char uid_buf[16], pid_buf[16];
19926 +       int ret;
19927 +
19928 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19929 +       char *envp[] = {"HOME=/", "TERM=linux",
19930 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19931 +                       uid_buf, pid_buf, cmd_buf, 0};
19932 +
19933 +       if (vx_info_state(vxi, VXS_HELPER))
19934 +               return -EAGAIN;
19935 +       vxi->vx_state |= VXS_HELPER;
19936 +
19937 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19938 +
19939 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19940 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
19941 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19942 +
19943 +       switch (cmd) {
19944 +       case LINUX_REBOOT_CMD_RESTART:
19945 +               argv[1] = "restart";
19946 +               break;
19947 +
19948 +       case LINUX_REBOOT_CMD_HALT:
19949 +               argv[1] = "halt";
19950 +               break;
19951 +
19952 +       case LINUX_REBOOT_CMD_POWER_OFF:
19953 +               argv[1] = "poweroff";
19954 +               break;
19955 +
19956 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19957 +               argv[1] = "swsusp";
19958 +               break;
19959 +
19960 +       default:
19961 +               vxi->vx_state &= ~VXS_HELPER;
19962 +               return 0;
19963 +       }
19964 +
19965 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19966 +       vxi->vx_state &= ~VXS_HELPER;
19967 +       __wakeup_vx_info(vxi);
19968 +       return (ret) ? -EPERM : 0;
19969 +}
19970 +
19971 +
19972 +long vs_reboot(unsigned int cmd, void __user *arg)
19973 +{
19974 +       struct vx_info *vxi = current->vx_info;
19975 +       long ret = 0;
19976 +
19977 +       vxdprintk(VXD_CBIT(misc, 5),
19978 +               "vs_reboot(%p[#%d],%d)",
19979 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19980 +
19981 +       ret = vs_reboot_helper(vxi, cmd, arg);
19982 +       if (ret)
19983 +               return ret;
19984 +
19985 +       vxi->reboot_cmd = cmd;
19986 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19987 +               switch (cmd) {
19988 +               case LINUX_REBOOT_CMD_RESTART:
19989 +               case LINUX_REBOOT_CMD_HALT:
19990 +               case LINUX_REBOOT_CMD_POWER_OFF:
19991 +                       vx_info_kill(vxi, 0, SIGKILL);
19992 +                       vx_info_kill(vxi, 1, SIGKILL);
19993 +               default:
19994 +                       break;
19995 +               }
19996 +       }
19997 +       return 0;
19998 +}
19999 +
20000 +
20001 +/*
20002 + *      argv [0] = vshelper_path;
20003 + *      argv [1] = action: "startup", "shutdown"
20004 + *      argv [2] = context identifier
20005 + *
20006 + *      envp [*] = type-specific parameters
20007 + */
20008 +
20009 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20010 +{
20011 +       char id_buf[8], cmd_buf[16];
20012 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20013 +       char *envp[] = {"HOME=/", "TERM=linux",
20014 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20015 +
20016 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20017 +               return 0;
20018 +
20019 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20020 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20021 +
20022 +       switch (cmd) {
20023 +       case VSC_STARTUP:
20024 +               argv[1] = "startup";
20025 +               break;
20026 +       case VSC_SHUTDOWN:
20027 +               argv[1] = "shutdown";
20028 +               break;
20029 +       default:
20030 +               return 0;
20031 +       }
20032 +
20033 +       return do_vshelper(vshelper_path, argv, envp, 1);
20034 +}
20035 +
20036 +
20037 +/*
20038 + *      argv [0] = vshelper_path;
20039 + *      argv [1] = action: "netup", "netdown"
20040 + *      argv [2] = context identifier
20041 + *
20042 + *      envp [*] = type-specific parameters
20043 + */
20044 +
20045 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20046 +{
20047 +       char id_buf[8], cmd_buf[16];
20048 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20049 +       char *envp[] = {"HOME=/", "TERM=linux",
20050 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20051 +
20052 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20053 +               return 0;
20054 +
20055 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20056 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20057 +
20058 +       switch (cmd) {
20059 +       case VSC_NETUP:
20060 +               argv[1] = "netup";
20061 +               break;
20062 +       case VSC_NETDOWN:
20063 +               argv[1] = "netdown";
20064 +               break;
20065 +       default:
20066 +               return 0;
20067 +       }
20068 +
20069 +       return do_vshelper(vshelper_path, argv, envp, 1);
20070 +}
20071 +
20072 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/history.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/history.c
20073 --- linux-2.6.27.10/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
20074 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/history.c       2008-10-13 14:54:20.000000000 +0200
20075 @@ -0,0 +1,258 @@
20076 +/*
20077 + *  kernel/vserver/history.c
20078 + *
20079 + *  Virtual Context History Backtrace
20080 + *
20081 + *  Copyright (C) 2004-2007  Herbert Pötzl
20082 + *
20083 + *  V0.01  basic structure
20084 + *  V0.02  hash/unhash and trace
20085 + *  V0.03  preemption fixes
20086 + *
20087 + */
20088 +
20089 +#include <linux/module.h>
20090 +#include <asm/uaccess.h>
20091 +
20092 +#include <linux/vserver/context.h>
20093 +#include <linux/vserver/debug.h>
20094 +#include <linux/vserver/debug_cmd.h>
20095 +#include <linux/vserver/history.h>
20096 +
20097 +
20098 +#ifdef CONFIG_VSERVER_HISTORY
20099 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20100 +#else
20101 +#define VXH_SIZE       64
20102 +#endif
20103 +
20104 +struct _vx_history {
20105 +       unsigned int counter;
20106 +
20107 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20108 +};
20109 +
20110 +
20111 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20112 +
20113 +unsigned volatile int vxh_active = 1;
20114 +
20115 +static atomic_t sequence = ATOMIC_INIT(0);
20116 +
20117 +
20118 +/*     vxh_advance()
20119 +
20120 +       * requires disabled preemption                          */
20121 +
20122 +struct _vx_hist_entry *vxh_advance(void *loc)
20123 +{
20124 +       unsigned int cpu = smp_processor_id();
20125 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20126 +       struct _vx_hist_entry *entry;
20127 +       unsigned int index;
20128 +
20129 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20130 +       entry = &hist->entry[index];
20131 +
20132 +       entry->seq = atomic_inc_return(&sequence);
20133 +       entry->loc = loc;
20134 +       return entry;
20135 +}
20136 +
20137 +EXPORT_SYMBOL_GPL(vxh_advance);
20138 +
20139 +
20140 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20141 +
20142 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20143 +
20144 +
20145 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20146 +
20147 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20148 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20149 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20150 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20151 +
20152 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20153 +{
20154 +       switch (e->type) {
20155 +       case VXH_THROW_OOPS:
20156 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20157 +               break;
20158 +
20159 +       case VXH_GET_VX_INFO:
20160 +       case VXH_PUT_VX_INFO:
20161 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20162 +                       VXH_LOC_ARGS(e),
20163 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20164 +                       VXH_VXI_ARGS(e));
20165 +               break;
20166 +
20167 +       case VXH_INIT_VX_INFO:
20168 +       case VXH_SET_VX_INFO:
20169 +       case VXH_CLR_VX_INFO:
20170 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20171 +                       VXH_LOC_ARGS(e),
20172 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20173 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20174 +                       VXH_VXI_ARGS(e), e->sc.data);
20175 +               break;
20176 +
20177 +       case VXH_CLAIM_VX_INFO:
20178 +       case VXH_RELEASE_VX_INFO:
20179 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20180 +                       VXH_LOC_ARGS(e),
20181 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20182 +                       VXH_VXI_ARGS(e), e->sc.data);
20183 +               break;
20184 +
20185 +       case VXH_ALLOC_VX_INFO:
20186 +       case VXH_DEALLOC_VX_INFO:
20187 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20188 +                       VXH_LOC_ARGS(e),
20189 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20190 +                       VXH_VXI_ARGS(e));
20191 +               break;
20192 +
20193 +       case VXH_HASH_VX_INFO:
20194 +       case VXH_UNHASH_VX_INFO:
20195 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20196 +                       VXH_LOC_ARGS(e),
20197 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20198 +                       VXH_VXI_ARGS(e));
20199 +               break;
20200 +
20201 +       case VXH_LOC_VX_INFO:
20202 +       case VXH_LOOKUP_VX_INFO:
20203 +       case VXH_CREATE_VX_INFO:
20204 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20205 +                       VXH_LOC_ARGS(e),
20206 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20207 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20208 +                       e->ll.arg, VXH_VXI_ARGS(e));
20209 +               break;
20210 +       }
20211 +}
20212 +
20213 +static void __vxh_dump_history(void)
20214 +{
20215 +       unsigned int i, cpu;
20216 +
20217 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20218 +               atomic_read(&sequence), NR_CPUS);
20219 +
20220 +       for (i = 0; i < VXH_SIZE; i++) {
20221 +               for_each_online_cpu(cpu) {
20222 +                       struct _vx_history *hist =
20223 +                               &per_cpu(vx_history_buffer, cpu);
20224 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20225 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20226 +
20227 +                       vxh_dump_entry(entry, cpu);
20228 +               }
20229 +       }
20230 +}
20231 +
20232 +void   vxh_dump_history(void)
20233 +{
20234 +       vxh_active = 0;
20235 +#ifdef CONFIG_SMP
20236 +       local_irq_enable();
20237 +       smp_send_stop();
20238 +       local_irq_disable();
20239 +#endif
20240 +       __vxh_dump_history();
20241 +}
20242 +
20243 +
20244 +/* vserver syscall commands below here */
20245 +
20246 +
20247 +int vc_dump_history(uint32_t id)
20248 +{
20249 +       vxh_active = 0;
20250 +       __vxh_dump_history();
20251 +       vxh_active = 1;
20252 +
20253 +       return 0;
20254 +}
20255 +
20256 +
20257 +int do_read_history(struct __user _vx_hist_entry *data,
20258 +       int cpu, uint32_t *index, uint32_t *count)
20259 +{
20260 +       int pos, ret = 0;
20261 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20262 +       int end = hist->counter;
20263 +       int start = end - VXH_SIZE + 2;
20264 +       int idx = *index;
20265 +
20266 +       /* special case: get current pos */
20267 +       if (!*count) {
20268 +               *index = end;
20269 +               return 0;
20270 +       }
20271 +
20272 +       /* have we lost some data? */
20273 +       if (idx < start)
20274 +               idx = start;
20275 +
20276 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20277 +               struct _vx_hist_entry *entry =
20278 +                       &hist->entry[idx % VXH_SIZE];
20279 +
20280 +               /* send entry to userspace */
20281 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20282 +               if (ret)
20283 +                       break;
20284 +       }
20285 +       /* save new index and count */
20286 +       *index = idx;
20287 +       *count = pos;
20288 +       return ret ? ret : (*index < end);
20289 +}
20290 +
20291 +int vc_read_history(uint32_t id, void __user *data)
20292 +{
20293 +       struct vcmd_read_history_v0 vc_data;
20294 +       int ret;
20295 +
20296 +       if (id >= NR_CPUS)
20297 +               return -EINVAL;
20298 +
20299 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20300 +               return -EFAULT;
20301 +
20302 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20303 +               id, &vc_data.index, &vc_data.count);
20304 +
20305 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20306 +               return -EFAULT;
20307 +       return ret;
20308 +}
20309 +
20310 +#ifdef CONFIG_COMPAT
20311 +
20312 +int vc_read_history_x32(uint32_t id, void __user *data)
20313 +{
20314 +       struct vcmd_read_history_v0_x32 vc_data;
20315 +       int ret;
20316 +
20317 +       if (id >= NR_CPUS)
20318 +               return -EINVAL;
20319 +
20320 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20321 +               return -EFAULT;
20322 +
20323 +       ret = do_read_history((struct __user _vx_hist_entry *)
20324 +               compat_ptr(vc_data.data_ptr),
20325 +               id, &vc_data.index, &vc_data.count);
20326 +
20327 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20328 +               return -EFAULT;
20329 +       return ret;
20330 +}
20331 +
20332 +#endif /* CONFIG_COMPAT */
20333 +
20334 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/inet.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/inet.c
20335 --- linux-2.6.27.10/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
20336 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/inet.c  2008-10-13 14:54:20.000000000 +0200
20337 @@ -0,0 +1,225 @@
20338 +
20339 +#include <linux/in.h>
20340 +#include <linux/inetdevice.h>
20341 +#include <linux/vs_inet.h>
20342 +#include <linux/vs_inet6.h>
20343 +#include <linux/vserver/debug.h>
20344 +#include <net/route.h>
20345 +#include <net/addrconf.h>
20346 +
20347 +
20348 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20349 +{
20350 +       int ret = 0;
20351 +
20352 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20353 +               ret = 1;
20354 +       else {
20355 +               struct nx_addr_v4 *ptr;
20356 +
20357 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20358 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20359 +                               ret = 1;
20360 +                               break;
20361 +                       }
20362 +               }
20363 +       }
20364 +
20365 +       vxdprintk(VXD_CBIT(net, 2),
20366 +               "nx_v4_addr_conflict(%p,%p): %d",
20367 +               nxi1, nxi2, ret);
20368 +
20369 +       return ret;
20370 +}
20371 +
20372 +
20373 +#ifdef CONFIG_IPV6
20374 +
20375 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20376 +{
20377 +       int ret = 0;
20378 +
20379 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20380 +               ret = 1;
20381 +       else {
20382 +               struct nx_addr_v6 *ptr;
20383 +
20384 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20385 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20386 +                               ret = 1;
20387 +                               break;
20388 +                       }
20389 +               }
20390 +       }
20391 +
20392 +       vxdprintk(VXD_CBIT(net, 2),
20393 +               "nx_v6_addr_conflict(%p,%p): %d",
20394 +               nxi1, nxi2, ret);
20395 +
20396 +       return ret;
20397 +}
20398 +
20399 +#endif
20400 +
20401 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20402 +{
20403 +       struct in_device *in_dev;
20404 +       struct in_ifaddr **ifap;
20405 +       struct in_ifaddr *ifa;
20406 +       int ret = 0;
20407 +
20408 +       if (!dev)
20409 +               goto out;
20410 +       in_dev = in_dev_get(dev);
20411 +       if (!in_dev)
20412 +               goto out;
20413 +
20414 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20415 +               ifap = &ifa->ifa_next) {
20416 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20417 +                       ret = 1;
20418 +                       break;
20419 +               }
20420 +       }
20421 +       in_dev_put(in_dev);
20422 +out:
20423 +       return ret;
20424 +}
20425 +
20426 +
20427 +#ifdef CONFIG_IPV6
20428 +
20429 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20430 +{
20431 +       struct inet6_dev *in_dev;
20432 +       struct inet6_ifaddr **ifap;
20433 +       struct inet6_ifaddr *ifa;
20434 +       int ret = 0;
20435 +
20436 +       if (!dev)
20437 +               goto out;
20438 +       in_dev = in6_dev_get(dev);
20439 +       if (!in_dev)
20440 +               goto out;
20441 +
20442 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20443 +               ifap = &ifa->if_next) {
20444 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20445 +                       ret = 1;
20446 +                       break;
20447 +               }
20448 +       }
20449 +       in6_dev_put(in_dev);
20450 +out:
20451 +       return ret;
20452 +}
20453 +
20454 +#endif
20455 +
20456 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20457 +{
20458 +       int ret = 1;
20459 +
20460 +       if (!nxi)
20461 +               goto out;
20462 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20463 +               goto out;
20464 +#ifdef CONFIG_IPV6
20465 +       ret = 2;
20466 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20467 +               goto out;
20468 +#endif
20469 +       ret = 0;
20470 +out:
20471 +       vxdprintk(VXD_CBIT(net, 3),
20472 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20473 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20474 +       return ret;
20475 +}
20476 +
20477 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20478 +       struct rtable **rp, struct flowi *fl)
20479 +{
20480 +       if (!nxi)
20481 +               return 0;
20482 +
20483 +       /* FIXME: handle lback only case */
20484 +       if (!NX_IPV4(nxi))
20485 +               return -EPERM;
20486 +
20487 +       vxdprintk(VXD_CBIT(net, 4),
20488 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20489 +               nxi, nxi ? nxi->nx_id : 0,
20490 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20491 +
20492 +       /* single IP is unconditional */
20493 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20494 +               (fl->fl4_src == INADDR_ANY))
20495 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20496 +
20497 +       if (fl->fl4_src == INADDR_ANY) {
20498 +               struct nx_addr_v4 *ptr;
20499 +               __be32 found = 0;
20500 +               int err;
20501 +
20502 +               err = __ip_route_output_key(net, rp, fl);
20503 +               if (!err) {
20504 +                       found = (*rp)->rt_src;
20505 +                       ip_rt_put(*rp);
20506 +                       vxdprintk(VXD_CBIT(net, 4),
20507 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20508 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20509 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20510 +                               goto found;
20511 +               }
20512 +
20513 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20514 +                       __be32 primary = ptr->ip[0].s_addr;
20515 +                       __be32 mask = ptr->mask.s_addr;
20516 +                       __be32 neta = primary & mask;
20517 +
20518 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20519 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20520 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20521 +                               NIPQUAD(mask), NIPQUAD(neta));
20522 +                       if ((found & mask) != neta)
20523 +                               continue;
20524 +
20525 +                       fl->fl4_src = primary;
20526 +                       err = __ip_route_output_key(net, rp, fl);
20527 +                       vxdprintk(VXD_CBIT(net, 4),
20528 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20529 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20530 +                       if (!err) {
20531 +                               found = (*rp)->rt_src;
20532 +                               ip_rt_put(*rp);
20533 +                               if (found == primary)
20534 +                                       goto found;
20535 +                       }
20536 +               }
20537 +               /* still no source ip? */
20538 +               found = ipv4_is_loopback(fl->fl4_dst)
20539 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20540 +       found:
20541 +               /* assign src ip to flow */
20542 +               fl->fl4_src = found;
20543 +
20544 +       } else {
20545 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20546 +                       return -EPERM;
20547 +       }
20548 +
20549 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20550 +               if (ipv4_is_loopback(fl->fl4_dst))
20551 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20552 +               if (ipv4_is_loopback(fl->fl4_src))
20553 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20554 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20555 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20556 +               return -EPERM;
20557 +
20558 +       return 0;
20559 +}
20560 +
20561 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20562 +
20563 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/init.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/init.c
20564 --- linux-2.6.27.10/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
20565 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/init.c  2008-10-13 14:54:20.000000000 +0200
20566 @@ -0,0 +1,45 @@
20567 +/*
20568 + *  linux/kernel/init.c
20569 + *
20570 + *  Virtual Server Init
20571 + *
20572 + *  Copyright (C) 2004-2007  Herbert Pötzl
20573 + *
20574 + *  V0.01  basic structure
20575 + *
20576 + */
20577 +
20578 +#include <linux/init.h>
20579 +
20580 +int    vserver_register_sysctl(void);
20581 +void   vserver_unregister_sysctl(void);
20582 +
20583 +
20584 +static int __init init_vserver(void)
20585 +{
20586 +       int ret = 0;
20587 +
20588 +#ifdef CONFIG_VSERVER_DEBUG
20589 +       vserver_register_sysctl();
20590 +#endif
20591 +       return ret;
20592 +}
20593 +
20594 +
20595 +static void __exit exit_vserver(void)
20596 +{
20597 +
20598 +#ifdef CONFIG_VSERVER_DEBUG
20599 +       vserver_unregister_sysctl();
20600 +#endif
20601 +       return;
20602 +}
20603 +
20604 +/* FIXME: GFP_ZONETYPES gone
20605 +long vx_slab[GFP_ZONETYPES]; */
20606 +long vx_area;
20607 +
20608 +
20609 +module_init(init_vserver);
20610 +module_exit(exit_vserver);
20611 +
20612 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/inode.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/inode.c
20613 --- linux-2.6.27.10/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
20614 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/inode.c 2008-10-24 03:34:52.000000000 +0200
20615 @@ -0,0 +1,422 @@
20616 +/*
20617 + *  linux/kernel/vserver/inode.c
20618 + *
20619 + *  Virtual Server: File System Support
20620 + *
20621 + *  Copyright (C) 2004-2007  Herbert Pötzl
20622 + *
20623 + *  V0.01  separated from vcontext V0.05
20624 + *  V0.02  moved to tag (instead of xid)
20625 + *
20626 + */
20627 +
20628 +#include <linux/tty.h>
20629 +#include <linux/proc_fs.h>
20630 +#include <linux/devpts_fs.h>
20631 +#include <linux/fs.h>
20632 +#include <linux/file.h>
20633 +#include <linux/mount.h>
20634 +#include <linux/parser.h>
20635 +#include <linux/namei.h>
20636 +#include <linux/vserver/inode.h>
20637 +#include <linux/vserver/inode_cmd.h>
20638 +#include <linux/vs_base.h>
20639 +#include <linux/vs_tag.h>
20640 +
20641 +#include <asm/uaccess.h>
20642 +
20643 +
20644 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20645 +{
20646 +       struct proc_dir_entry *entry;
20647 +
20648 +       if (!in || !in->i_sb)
20649 +               return -ESRCH;
20650 +
20651 +       *flags = IATTR_TAG
20652 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20653 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20654 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20655 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20656 +
20657 +       if (S_ISDIR(in->i_mode))
20658 +               *mask |= IATTR_BARRIER;
20659 +
20660 +       if (IS_TAGGED(in)) {
20661 +               *tag = in->i_tag;
20662 +               *mask |= IATTR_TAG;
20663 +       }
20664 +
20665 +       switch (in->i_sb->s_magic) {
20666 +       case PROC_SUPER_MAGIC:
20667 +               entry = PROC_I(in)->pde;
20668 +
20669 +               /* check for specific inodes? */
20670 +               if (entry)
20671 +                       *mask |= IATTR_FLAGS;
20672 +               if (entry)
20673 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20674 +               else
20675 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20676 +               break;
20677 +
20678 +       case DEVPTS_SUPER_MAGIC:
20679 +               *tag = in->i_tag;
20680 +               *mask |= IATTR_TAG;
20681 +               break;
20682 +
20683 +       default:
20684 +               break;
20685 +       }
20686 +       return 0;
20687 +}
20688 +
20689 +int vc_get_iattr(void __user *data)
20690 +{
20691 +       struct path path;
20692 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20693 +       int ret;
20694 +
20695 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20696 +               return -EFAULT;
20697 +
20698 +       ret = user_lpath(vc_data.name, &path);
20699 +       if (!ret) {
20700 +               ret = __vc_get_iattr(path.dentry->d_inode,
20701 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20702 +               path_put(&path);
20703 +       }
20704 +       if (ret)
20705 +               return ret;
20706 +
20707 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20708 +               ret = -EFAULT;
20709 +       return ret;
20710 +}
20711 +
20712 +#ifdef CONFIG_COMPAT
20713 +
20714 +int vc_get_iattr_x32(void __user *data)
20715 +{
20716 +       struct path path;
20717 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20718 +       int ret;
20719 +
20720 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20721 +               return -EFAULT;
20722 +
20723 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20724 +       if (!ret) {
20725 +               ret = __vc_get_iattr(path.dentry->d_inode,
20726 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20727 +               path_put(&path);
20728 +       }
20729 +       if (ret)
20730 +               return ret;
20731 +
20732 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20733 +               ret = -EFAULT;
20734 +       return ret;
20735 +}
20736 +
20737 +#endif /* CONFIG_COMPAT */
20738 +
20739 +
20740 +int vc_fget_iattr(uint32_t fd, void __user *data)
20741 +{
20742 +       struct file *filp;
20743 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20744 +       int ret;
20745 +
20746 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20747 +               return -EFAULT;
20748 +
20749 +       filp = fget(fd);
20750 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20751 +               return -EBADF;
20752 +
20753 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20754 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20755 +
20756 +       fput(filp);
20757 +
20758 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20759 +               ret = -EFAULT;
20760 +       return ret;
20761 +}
20762 +
20763 +
20764 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20765 +{
20766 +       struct inode *in = de->d_inode;
20767 +       int error = 0, is_proc = 0, has_tag = 0;
20768 +       struct iattr attr = { 0 };
20769 +
20770 +       if (!in || !in->i_sb)
20771 +               return -ESRCH;
20772 +
20773 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20774 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20775 +               return -EINVAL;
20776 +
20777 +       has_tag = IS_TAGGED(in) ||
20778 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20779 +       if ((*mask & IATTR_TAG) && !has_tag)
20780 +               return -EINVAL;
20781 +
20782 +       mutex_lock(&in->i_mutex);
20783 +       if (*mask & IATTR_TAG) {
20784 +               attr.ia_tag = *tag;
20785 +               attr.ia_valid |= ATTR_TAG;
20786 +       }
20787 +
20788 +       if (*mask & IATTR_FLAGS) {
20789 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20790 +               unsigned int iflags = PROC_I(in)->vx_flags;
20791 +
20792 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20793 +                       | (*flags & IATTR_FLAGS);
20794 +               PROC_I(in)->vx_flags = iflags;
20795 +               if (entry)
20796 +                       entry->vx_flags = iflags;
20797 +       }
20798 +
20799 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20800 +               if (*mask & IATTR_IMMUTABLE) {
20801 +                       if (*flags & IATTR_IMMUTABLE)
20802 +                               in->i_flags |= S_IMMUTABLE;
20803 +                       else
20804 +                               in->i_flags &= ~S_IMMUTABLE;
20805 +               }
20806 +               if (*mask & IATTR_IXUNLINK) {
20807 +                       if (*flags & IATTR_IXUNLINK)
20808 +                               in->i_flags |= S_IXUNLINK;
20809 +                       else
20810 +                               in->i_flags &= ~S_IXUNLINK;
20811 +               }
20812 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20813 +                       if (*flags & IATTR_BARRIER)
20814 +                               in->i_vflags |= V_BARRIER;
20815 +                       else
20816 +                               in->i_vflags &= ~V_BARRIER;
20817 +               }
20818 +               if (in->i_op && in->i_op->sync_flags) {
20819 +                       error = in->i_op->sync_flags(in);
20820 +                       if (error)
20821 +                               goto out;
20822 +               }
20823 +       }
20824 +
20825 +       if (attr.ia_valid) {
20826 +               if (in->i_op && in->i_op->setattr)
20827 +                       error = in->i_op->setattr(de, &attr);
20828 +               else {
20829 +                       error = inode_change_ok(in, &attr);
20830 +                       if (!error)
20831 +                               error = inode_setattr(in, &attr);
20832 +               }
20833 +       }
20834 +
20835 +out:
20836 +       mutex_unlock(&in->i_mutex);
20837 +       return error;
20838 +}
20839 +
20840 +int vc_set_iattr(void __user *data)
20841 +{
20842 +       struct path path;
20843 +       struct vcmd_ctx_iattr_v1 vc_data;
20844 +       int ret;
20845 +
20846 +       if (!capable(CAP_LINUX_IMMUTABLE))
20847 +               return -EPERM;
20848 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20849 +               return -EFAULT;
20850 +
20851 +       ret = user_lpath(vc_data.name, &path);
20852 +       if (!ret) {
20853 +               ret = __vc_set_iattr(path.dentry,
20854 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20855 +               path_put(&path);
20856 +       }
20857 +
20858 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20859 +               ret = -EFAULT;
20860 +       return ret;
20861 +}
20862 +
20863 +#ifdef CONFIG_COMPAT
20864 +
20865 +int vc_set_iattr_x32(void __user *data)
20866 +{
20867 +       struct path path;
20868 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20869 +       int ret;
20870 +
20871 +       if (!capable(CAP_LINUX_IMMUTABLE))
20872 +               return -EPERM;
20873 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20874 +               return -EFAULT;
20875 +
20876 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20877 +       if (!ret) {
20878 +               ret = __vc_set_iattr(path.dentry,
20879 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20880 +               path_put(&path);
20881 +       }
20882 +
20883 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20884 +               ret = -EFAULT;
20885 +       return ret;
20886 +}
20887 +
20888 +#endif /* CONFIG_COMPAT */
20889 +
20890 +int vc_fset_iattr(uint32_t fd, void __user *data)
20891 +{
20892 +       struct file *filp;
20893 +       struct vcmd_ctx_fiattr_v0 vc_data;
20894 +       int ret;
20895 +
20896 +       if (!capable(CAP_LINUX_IMMUTABLE))
20897 +               return -EPERM;
20898 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20899 +               return -EFAULT;
20900 +
20901 +       filp = fget(fd);
20902 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20903 +               return -EBADF;
20904 +
20905 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20906 +               &vc_data.flags, &vc_data.mask);
20907 +
20908 +       fput(filp);
20909 +
20910 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20911 +               return -EFAULT;
20912 +       return ret;
20913 +}
20914 +
20915 +
20916 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20917 +
20918 +static match_table_t tokens = {
20919 +       {Opt_notagcheck, "notagcheck"},
20920 +#ifdef CONFIG_PROPAGATE
20921 +       {Opt_notag, "notag"},
20922 +       {Opt_tag, "tag"},
20923 +       {Opt_tagid, "tagid=%u"},
20924 +#endif
20925 +       {Opt_err, NULL}
20926 +};
20927 +
20928 +
20929 +static void __dx_parse_remove(char *string, char *opt)
20930 +{
20931 +       char *p = strstr(string, opt);
20932 +       char *q = p;
20933 +
20934 +       if (p) {
20935 +               while (*q != '\0' && *q != ',')
20936 +                       q++;
20937 +               while (*q)
20938 +                       *p++ = *q++;
20939 +               while (*p)
20940 +                       *p++ = '\0';
20941 +       }
20942 +}
20943 +
20944 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20945 +                unsigned long *flags)
20946 +{
20947 +       int set = 0;
20948 +       substring_t args[MAX_OPT_ARGS];
20949 +       int token, option = 0;
20950 +       char *s, *p, *opts;
20951 +
20952 +       if (!string)
20953 +               return 0;
20954 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20955 +       if (!s)
20956 +               return 0;
20957 +
20958 +       opts = s;
20959 +       while ((p = strsep(&opts, ",")) != NULL) {
20960 +               token = match_token(p, tokens, args);
20961 +
20962 +               vxdprintk(VXD_CBIT(tag, 7),
20963 +                       "dx_parse_tag(»%s«): %d:#%d",
20964 +                       p, token, option);
20965 +
20966 +               switch (token) {
20967 +#ifdef CONFIG_PROPAGATE
20968 +               case Opt_tag:
20969 +                       if (tag)
20970 +                               *tag = 0;
20971 +                       if (remove)
20972 +                               __dx_parse_remove(s, "tag");
20973 +                       *mnt_flags |= MNT_TAGID;
20974 +                       set |= MNT_TAGID;
20975 +                       break;
20976 +               case Opt_notag:
20977 +                       if (remove)
20978 +                               __dx_parse_remove(s, "notag");
20979 +                       *mnt_flags |= MNT_NOTAG;
20980 +                       set |= MNT_NOTAG;
20981 +                       break;
20982 +               case Opt_tagid:
20983 +                       if (tag && !match_int(args, &option))
20984 +                               *tag = option;
20985 +                       if (remove)
20986 +                               __dx_parse_remove(s, "tagid");
20987 +                       *mnt_flags |= MNT_TAGID;
20988 +                       set |= MNT_TAGID;
20989 +                       break;
20990 +#endif
20991 +               case Opt_notagcheck:
20992 +                       if (remove)
20993 +                               __dx_parse_remove(s, "notagcheck");
20994 +                       *flags |= MS_NOTAGCHECK;
20995 +                       set |= MS_NOTAGCHECK;
20996 +                       break;
20997 +               }
20998 +       }
20999 +       if (set)
21000 +               strcpy(string, s);
21001 +       kfree(s);
21002 +       return set;
21003 +}
21004 +
21005 +#ifdef CONFIG_PROPAGATE
21006 +
21007 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21008 +{
21009 +       tag_t new_tag = 0;
21010 +       struct vfsmount *mnt;
21011 +       int propagate;
21012 +
21013 +       if (!nd)
21014 +               return;
21015 +       mnt = nd->path.mnt;
21016 +       if (!mnt)
21017 +               return;
21018 +
21019 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21020 +       if (propagate)
21021 +               new_tag = mnt->mnt_tag;
21022 +
21023 +       vxdprintk(VXD_CBIT(tag, 7),
21024 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21025 +               inode, inode->i_ino, inode->i_tag,
21026 +               new_tag, (propagate) ? 1 : 0);
21027 +
21028 +       if (propagate)
21029 +               inode->i_tag = new_tag;
21030 +}
21031 +
21032 +#include <linux/module.h>
21033 +
21034 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21035 +
21036 +#endif /* CONFIG_PROPAGATE */
21037 +
21038 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/Kconfig linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/Kconfig
21039 --- linux-2.6.27.10/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
21040 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/Kconfig 2008-10-13 14:54:20.000000000 +0200
21041 @@ -0,0 +1,251 @@
21042 +#
21043 +# Linux VServer configuration
21044 +#
21045 +
21046 +menu "Linux VServer"
21047 +
21048 +config VSERVER_AUTO_LBACK
21049 +       bool    "Automatically Assign Loopback IP"
21050 +       default y
21051 +       help
21052 +         Automatically assign a guest specific loopback
21053 +         IP and add it to the kernel network stack on
21054 +         startup.
21055 +
21056 +config VSERVER_AUTO_SINGLE
21057 +       bool    "Automatic Single IP Special Casing"
21058 +       depends on EXPERIMENTAL
21059 +       default y
21060 +       help
21061 +         This allows network contexts with a single IP to
21062 +         automatically remap 0.0.0.0 bindings to that IP,
21063 +         avoiding further network checks and improving
21064 +         performance.
21065 +
21066 +         (note: such guests do not allow to change the ip
21067 +          on the fly and do not show loopback addresses)
21068 +
21069 +config VSERVER_COWBL
21070 +       bool    "Enable COW Immutable Link Breaking"
21071 +       default y
21072 +       help
21073 +         This enables the COW (Copy-On-Write) link break code.
21074 +         It allows you to treat unified files like normal files
21075 +         when writing to them (which will implicitely break the
21076 +         link and create a copy of the unified file)
21077 +
21078 +config VSERVER_VTIME
21079 +       bool    "Enable Virtualized Guest Time"
21080 +       depends on EXPERIMENTAL
21081 +       default n
21082 +       help
21083 +         This enables per guest time offsets to allow for
21084 +         adjusting the system clock individually per guest.
21085 +         this adds some overhead to the time functions and
21086 +         therefore should not be enabled without good reason.
21087 +
21088 +config VSERVER_DEVICE
21089 +       bool    "Enable Guest Device Mapping"
21090 +       depends on EXPERIMENTAL
21091 +       default n
21092 +       help
21093 +         This enables generic device remapping.
21094 +
21095 +config VSERVER_PROC_SECURE
21096 +       bool    "Enable Proc Security"
21097 +       depends on PROC_FS
21098 +       default y
21099 +       help
21100 +         This configures ProcFS security to initially hide
21101 +         non-process entries for all contexts except the main and
21102 +         spectator context (i.e. for all guests), which is a secure
21103 +         default.
21104 +
21105 +         (note: on 1.2x the entries were visible by default)
21106 +
21107 +config VSERVER_HARDCPU
21108 +       bool    "Enable Hard CPU Limits"
21109 +       default y
21110 +       help
21111 +         Activate the Hard CPU Limits
21112 +
21113 +         This will compile in code that allows the Token Bucket
21114 +         Scheduler to put processes on hold when a context's
21115 +         tokens are depleted (provided that its per-context
21116 +         sched_hard flag is set).
21117 +
21118 +         Processes belonging to that context will not be able
21119 +         to consume CPU resources again until a per-context
21120 +         configured minimum of tokens has been reached.
21121 +
21122 +config VSERVER_IDLETIME
21123 +       bool    "Avoid idle CPUs by skipping Time"
21124 +       depends on VSERVER_HARDCPU
21125 +       default y
21126 +       help
21127 +         This option allows the scheduler to artificially
21128 +         advance time (per cpu) when otherwise the idle
21129 +         task would be scheduled, thus keeping the cpu
21130 +         busy and sharing the available resources among
21131 +         certain contexts.
21132 +
21133 +config VSERVER_IDLELIMIT
21134 +       bool    "Limit the IDLE task"
21135 +       depends on VSERVER_HARDCPU
21136 +       default n
21137 +       help
21138 +         Limit the idle slices, so the the next context
21139 +         will be scheduled as soon as possible.
21140 +
21141 +         This might improve interactivity and latency, but
21142 +         will also marginally increase scheduling overhead.
21143 +
21144 +choice
21145 +       prompt  "Persistent Inode Tagging"
21146 +       default TAGGING_ID24
21147 +       help
21148 +         This adds persistent context information to filesystems
21149 +         mounted with the tagxid option. Tagging is a requirement
21150 +         for per-context disk limits and per-context quota.
21151 +
21152 +
21153 +config TAGGING_NONE
21154 +       bool    "Disabled"
21155 +       help
21156 +         do not store per-context information in inodes.
21157 +
21158 +config TAGGING_UID16
21159 +       bool    "UID16/GID32"
21160 +       help
21161 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21162 +
21163 +config TAGGING_GID16
21164 +       bool    "UID32/GID16"
21165 +       help
21166 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21167 +
21168 +config TAGGING_ID24
21169 +       bool    "UID24/GID24"
21170 +       help
21171 +         uses the upper 8bit from UID and GID for XID tagging
21172 +         which leaves 24bit for UID/GID each, which should be
21173 +         more than sufficient for normal use.
21174 +
21175 +config TAGGING_INTERN
21176 +       bool    "UID32/GID32"
21177 +       help
21178 +         this uses otherwise reserved inode fields in the on
21179 +         disk representation, which limits the use to a few
21180 +         filesystems (currently ext2 and ext3)
21181 +
21182 +endchoice
21183 +
21184 +config TAG_NFSD
21185 +       bool    "Tag NFSD User Auth and Files"
21186 +       default n
21187 +       help
21188 +         Enable this if you do want the in-kernel NFS
21189 +         Server to use the tagging specified above.
21190 +         (will require patched clients too)
21191 +
21192 +config VSERVER_PRIVACY
21193 +       bool    "Honor Privacy Aspects of Guests"
21194 +       default n
21195 +       help
21196 +         When enabled, most context checks will disallow
21197 +         access to structures assigned to a specific context,
21198 +         like ptys or loop devices.
21199 +
21200 +config VSERVER_CONTEXTS
21201 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21202 +       range 1 65533
21203 +       default "768"   if 64BIT
21204 +       default "256"
21205 +       help
21206 +         This setting will optimize certain data structures
21207 +         and memory allocations according to the expected
21208 +         maximum.
21209 +
21210 +         note: this is not a strict upper limit.
21211 +
21212 +config VSERVER_WARN
21213 +       bool    "VServer Warnings"
21214 +       default y
21215 +       help
21216 +         This enables various runtime warnings, which will
21217 +         notify about potential manipulation attempts or
21218 +         resource shortage. It is generally considered to
21219 +         be a good idea to have that enabled.
21220 +
21221 +config VSERVER_DEBUG
21222 +       bool    "VServer Debugging Code"
21223 +       default n
21224 +       help
21225 +         Set this to yes if you want to be able to activate
21226 +         debugging output at runtime. It adds a very small
21227 +         overhead to all vserver related functions and
21228 +         increases the kernel size by about 20k.
21229 +
21230 +config VSERVER_HISTORY
21231 +       bool    "VServer History Tracing"
21232 +       depends on VSERVER_DEBUG
21233 +       default n
21234 +       help
21235 +         Set this to yes if you want to record the history of
21236 +         linux-vserver activities, so they can be replayed in
21237 +         the event of a kernel panic or oops.
21238 +
21239 +config VSERVER_HISTORY_SIZE
21240 +       int     "Per-CPU History Size (32-65536)"
21241 +       depends on VSERVER_HISTORY
21242 +       range 32 65536
21243 +       default 64
21244 +       help
21245 +         This allows you to specify the number of entries in
21246 +         the per-CPU history buffer.
21247 +
21248 +config VSERVER_MONITOR
21249 +       bool    "VServer Scheduling Monitor"
21250 +       depends on VSERVER_DISABLED
21251 +       default n
21252 +       help
21253 +         Set this to yes if you want to record the scheduling
21254 +         decisions, so that they can be relayed to userspace
21255 +         for detailed analysis.
21256 +
21257 +config VSERVER_MONITOR_SIZE
21258 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21259 +       depends on VSERVER_MONITOR
21260 +       range 32 65536
21261 +       default 1024
21262 +       help
21263 +         This allows you to specify the number of entries in
21264 +         the per-CPU scheduling monitor buffer.
21265 +
21266 +config VSERVER_MONITOR_SYNC
21267 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21268 +       depends on VSERVER_MONITOR
21269 +       range 0 65536
21270 +       default 256
21271 +       help
21272 +         This allows you to specify the interval in ticks
21273 +         when a time sync entry is inserted.
21274 +
21275 +endmenu
21276 +
21277 +
21278 +config VSERVER
21279 +       bool
21280 +       default y
21281 +       select NAMESPACES
21282 +       select UTS_NS
21283 +       select IPC_NS
21284 +       select USER_NS
21285 +       select SYSVIPC
21286 +
21287 +config VSERVER_SECURITY
21288 +       bool
21289 +       depends on SECURITY
21290 +       default y
21291 +       select SECURITY_CAPABILITIES
21292 +
21293 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/limit.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/limit.c
21294 --- linux-2.6.27.10/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
21295 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/limit.c 2008-10-13 14:54:20.000000000 +0200
21296 @@ -0,0 +1,319 @@
21297 +/*
21298 + *  linux/kernel/vserver/limit.c
21299 + *
21300 + *  Virtual Server: Context Limits
21301 + *
21302 + *  Copyright (C) 2004-2007  Herbert Pötzl
21303 + *
21304 + *  V0.01  broken out from vcontext V0.05
21305 + *  V0.02  changed vcmds to vxi arg
21306 + *
21307 + */
21308 +
21309 +#include <linux/sched.h>
21310 +#include <linux/module.h>
21311 +#include <linux/vs_limit.h>
21312 +#include <linux/vserver/limit.h>
21313 +#include <linux/vserver/limit_cmd.h>
21314 +
21315 +#include <asm/uaccess.h>
21316 +
21317 +
21318 +const char *vlimit_name[NUM_LIMITS] = {
21319 +       [RLIMIT_CPU]            = "CPU",
21320 +       [RLIMIT_RSS]            = "RSS",
21321 +       [RLIMIT_NPROC]          = "NPROC",
21322 +       [RLIMIT_NOFILE]         = "NOFILE",
21323 +       [RLIMIT_MEMLOCK]        = "VML",
21324 +       [RLIMIT_AS]             = "VM",
21325 +       [RLIMIT_LOCKS]          = "LOCKS",
21326 +       [RLIMIT_SIGPENDING]     = "SIGP",
21327 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21328 +
21329 +       [VLIMIT_NSOCK]          = "NSOCK",
21330 +       [VLIMIT_OPENFD]         = "OPENFD",
21331 +       [VLIMIT_ANON]           = "ANON",
21332 +       [VLIMIT_SHMEM]          = "SHMEM",
21333 +       [VLIMIT_DENTRY]         = "DENTRY",
21334 +};
21335 +
21336 +EXPORT_SYMBOL_GPL(vlimit_name);
21337 +
21338 +#define MASK_ENTRY(x)  (1 << (x))
21339 +
21340 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21341 +               /* minimum */
21342 +       0
21343 +       ,       /* softlimit */
21344 +       MASK_ENTRY( RLIMIT_RSS          ) |
21345 +       MASK_ENTRY( VLIMIT_ANON         ) |
21346 +       0
21347 +       ,       /* maximum */
21348 +       MASK_ENTRY( RLIMIT_RSS          ) |
21349 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21350 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21351 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21352 +       MASK_ENTRY( RLIMIT_AS           ) |
21353 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21354 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21355 +
21356 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21357 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21358 +       MASK_ENTRY( VLIMIT_ANON         ) |
21359 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21360 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21361 +       0
21362 +};
21363 +               /* accounting only */
21364 +uint32_t account_mask =
21365 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21366 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21367 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21368 +       0;
21369 +
21370 +
21371 +static int is_valid_vlimit(int id)
21372 +{
21373 +       uint32_t mask = vlimit_mask.minimum |
21374 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21375 +       return mask & (1 << id);
21376 +}
21377 +
21378 +static int is_accounted_vlimit(int id)
21379 +{
21380 +       if (is_valid_vlimit(id))
21381 +               return 1;
21382 +       return account_mask & (1 << id);
21383 +}
21384 +
21385 +
21386 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21387 +{
21388 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21389 +       return VX_VLIM(limit);
21390 +}
21391 +
21392 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21393 +{
21394 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21395 +       return VX_VLIM(limit);
21396 +}
21397 +
21398 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21399 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21400 +{
21401 +       if (!is_valid_vlimit(id))
21402 +               return -EINVAL;
21403 +
21404 +       if (minimum)
21405 +               *minimum = CRLIM_UNSET;
21406 +       if (softlimit)
21407 +               *softlimit = vc_get_soft(vxi, id);
21408 +       if (maximum)
21409 +               *maximum = vc_get_hard(vxi, id);
21410 +       return 0;
21411 +}
21412 +
21413 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21414 +{
21415 +       struct vcmd_ctx_rlimit_v0 vc_data;
21416 +       int ret;
21417 +
21418 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21419 +               return -EFAULT;
21420 +
21421 +       ret = do_get_rlimit(vxi, vc_data.id,
21422 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21423 +       if (ret)
21424 +               return ret;
21425 +
21426 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21427 +               return -EFAULT;
21428 +       return 0;
21429 +}
21430 +
21431 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21432 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21433 +{
21434 +       if (!is_valid_vlimit(id))
21435 +               return -EINVAL;
21436 +
21437 +       if (maximum != CRLIM_KEEP)
21438 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21439 +       if (softlimit != CRLIM_KEEP)
21440 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21441 +
21442 +       /* clamp soft limit */
21443 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21444 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21445 +
21446 +       return 0;
21447 +}
21448 +
21449 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21450 +{
21451 +       struct vcmd_ctx_rlimit_v0 vc_data;
21452 +
21453 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21454 +               return -EFAULT;
21455 +
21456 +       return do_set_rlimit(vxi, vc_data.id,
21457 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21458 +}
21459 +
21460 +#ifdef CONFIG_IA32_EMULATION
21461 +
21462 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21463 +{
21464 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21465 +
21466 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21467 +               return -EFAULT;
21468 +
21469 +       return do_set_rlimit(vxi, vc_data.id,
21470 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21471 +}
21472 +
21473 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21474 +{
21475 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21476 +       int ret;
21477 +
21478 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21479 +               return -EFAULT;
21480 +
21481 +       ret = do_get_rlimit(vxi, vc_data.id,
21482 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21483 +       if (ret)
21484 +               return ret;
21485 +
21486 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21487 +               return -EFAULT;
21488 +       return 0;
21489 +}
21490 +
21491 +#endif /* CONFIG_IA32_EMULATION */
21492 +
21493 +
21494 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21495 +{
21496 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21497 +               return -EFAULT;
21498 +       return 0;
21499 +}
21500 +
21501 +
21502 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21503 +{
21504 +       rlim_t value;
21505 +       int lim;
21506 +
21507 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21508 +               value = __rlim_get(limit, lim);
21509 +               __rlim_rmax(limit, lim) = value;
21510 +               __rlim_rmin(limit, lim) = value;
21511 +       }
21512 +}
21513 +
21514 +
21515 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21516 +{
21517 +       vx_reset_minmax(&vxi->limit);
21518 +       return 0;
21519 +}
21520 +
21521 +
21522 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21523 +{
21524 +       struct vcmd_rlimit_stat_v0 vc_data;
21525 +       struct _vx_limit *limit = &vxi->limit;
21526 +       int id;
21527 +
21528 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21529 +               return -EFAULT;
21530 +
21531 +       id = vc_data.id;
21532 +       if (!is_accounted_vlimit(id))
21533 +               return -EINVAL;
21534 +
21535 +       vx_limit_fixup(limit, id);
21536 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21537 +       vc_data.value = __rlim_get(limit, id);
21538 +       vc_data.minimum = __rlim_rmin(limit, id);
21539 +       vc_data.maximum = __rlim_rmax(limit, id);
21540 +
21541 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21542 +               return -EFAULT;
21543 +       return 0;
21544 +}
21545 +
21546 +
21547 +void vx_vsi_meminfo(struct sysinfo *val)
21548 +{
21549 +       struct vx_info *vxi = current->vx_info;
21550 +       unsigned long totalram, freeram;
21551 +       rlim_t v;
21552 +
21553 +       /* we blindly accept the max */
21554 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21555 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21556 +
21557 +       /* total minus used equals free */
21558 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21559 +       freeram = (v < totalram) ? totalram - v : 0;
21560 +
21561 +       val->totalram = totalram;
21562 +       val->freeram = freeram;
21563 +       val->bufferram = 0;
21564 +       val->totalhigh = 0;
21565 +       val->freehigh = 0;
21566 +       return;
21567 +}
21568 +
21569 +void vx_vsi_swapinfo(struct sysinfo *val)
21570 +{
21571 +       struct vx_info *vxi = current->vx_info;
21572 +       unsigned long totalswap, freeswap;
21573 +       rlim_t v, w;
21574 +
21575 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21576 +       if (v == RLIM_INFINITY) {
21577 +               val->freeswap = val->totalswap;
21578 +               return;
21579 +       }
21580 +
21581 +       /* we blindly accept the max */
21582 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21583 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21584 +
21585 +       /* currently 'used' swap */
21586 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21587 +       w -= (w > v) ? v : w;
21588 +
21589 +       /* total minus used equals free */
21590 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21591 +
21592 +       val->totalswap = totalswap;
21593 +       val->freeswap = freeswap;
21594 +       return;
21595 +}
21596 +
21597 +
21598 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21599 +{
21600 +       struct vx_info *vxi = mm->mm_vx_info;
21601 +       unsigned long points;
21602 +       rlim_t v, w;
21603 +
21604 +       if (!vxi)
21605 +               return 0;
21606 +
21607 +       points = vxi->vx_badness_bias;
21608 +
21609 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21610 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21611 +       points += (v > w) ? (v - w) : 0;
21612 +
21613 +       return points;
21614 +}
21615 +
21616 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/limit_init.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/limit_init.h
21617 --- linux-2.6.27.10/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
21618 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/limit_init.h    2008-10-13 14:54:20.000000000 +0200
21619 @@ -0,0 +1,31 @@
21620 +
21621 +
21622 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21623 +{
21624 +       int lim;
21625 +
21626 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21627 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21628 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21629 +               __rlim_set(limit, lim, 0);
21630 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21631 +               __rlim_rmin(limit, lim) = 0;
21632 +               __rlim_rmax(limit, lim) = 0;
21633 +       }
21634 +}
21635 +
21636 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21637 +{
21638 +       rlim_t value;
21639 +       int lim;
21640 +
21641 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21642 +               if ((1 << lim) & VLIM_NOCHECK)
21643 +                       continue;
21644 +               value = __rlim_get(limit, lim);
21645 +               vxwprintk_xid(value,
21646 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21647 +                       limit, vlimit_name[lim], lim, (long)value);
21648 +       }
21649 +}
21650 +
21651 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/limit_proc.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/limit_proc.h
21652 --- linux-2.6.27.10/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
21653 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/limit_proc.h    2008-10-13 14:54:20.000000000 +0200
21654 @@ -0,0 +1,57 @@
21655 +#ifndef _VX_LIMIT_PROC_H
21656 +#define _VX_LIMIT_PROC_H
21657 +
21658 +#include <linux/vserver/limit_int.h>
21659 +
21660 +
21661 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21662 +#define VX_LIMIT_TOP   \
21663 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21664 +
21665 +#define VX_LIMIT_ARG(r)                                \
21666 +       (unsigned long)__rlim_get(limit, r),    \
21667 +       (unsigned long)__rlim_rmin(limit, r),   \
21668 +       (unsigned long)__rlim_rmax(limit, r),   \
21669 +       VX_VLIM(__rlim_soft(limit, r)),         \
21670 +       VX_VLIM(__rlim_hard(limit, r)),         \
21671 +       atomic_read(&__rlim_lhit(limit, r))
21672 +
21673 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21674 +{
21675 +       vx_limit_fixup(limit, -1);
21676 +       return sprintf(buffer, VX_LIMIT_TOP
21677 +               "PROC"  VX_LIMIT_FMT
21678 +               "VM"    VX_LIMIT_FMT
21679 +               "VML"   VX_LIMIT_FMT
21680 +               "RSS"   VX_LIMIT_FMT
21681 +               "ANON"  VX_LIMIT_FMT
21682 +               "RMAP"  VX_LIMIT_FMT
21683 +               "FILES" VX_LIMIT_FMT
21684 +               "OFD"   VX_LIMIT_FMT
21685 +               "LOCKS" VX_LIMIT_FMT
21686 +               "SOCK"  VX_LIMIT_FMT
21687 +               "MSGQ"  VX_LIMIT_FMT
21688 +               "SHM"   VX_LIMIT_FMT
21689 +               "SEMA"  VX_LIMIT_FMT
21690 +               "SEMS"  VX_LIMIT_FMT
21691 +               "DENT"  VX_LIMIT_FMT,
21692 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21693 +               VX_LIMIT_ARG(RLIMIT_AS),
21694 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21695 +               VX_LIMIT_ARG(RLIMIT_RSS),
21696 +               VX_LIMIT_ARG(VLIMIT_ANON),
21697 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21698 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21699 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21700 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21701 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21702 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21703 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21704 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21705 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21706 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21707 +}
21708 +
21709 +#endif /* _VX_LIMIT_PROC_H */
21710 +
21711 +
21712 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/Makefile linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/Makefile
21713 --- linux-2.6.27.10/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
21714 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/Makefile        2008-10-13 14:54:20.000000000 +0200
21715 @@ -0,0 +1,18 @@
21716 +#
21717 +# Makefile for the Linux vserver routines.
21718 +#
21719 +
21720 +
21721 +obj-y          += vserver.o
21722 +
21723 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21724 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21725 +                  dlimit.o tag.o
21726 +
21727 +vserver-$(CONFIG_INET) += inet.o
21728 +vserver-$(CONFIG_PROC_FS) += proc.o
21729 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21730 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21731 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21732 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21733 +
21734 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/monitor.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/monitor.c
21735 --- linux-2.6.27.10/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
21736 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/monitor.c       2008-10-13 14:54:20.000000000 +0200
21737 @@ -0,0 +1,138 @@
21738 +/*
21739 + *  kernel/vserver/monitor.c
21740 + *
21741 + *  Virtual Context Scheduler Monitor
21742 + *
21743 + *  Copyright (C) 2006-2007 Herbert Pötzl
21744 + *
21745 + *  V0.01  basic design
21746 + *
21747 + */
21748 +
21749 +#include <linux/module.h>
21750 +#include <linux/jiffies.h>
21751 +#include <asm/uaccess.h>
21752 +#include <asm/atomic.h>
21753 +
21754 +#include <linux/vserver/monitor.h>
21755 +#include <linux/vserver/debug_cmd.h>
21756 +
21757 +
21758 +#ifdef CONFIG_VSERVER_MONITOR
21759 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21760 +#else
21761 +#define VXM_SIZE       64
21762 +#endif
21763 +
21764 +struct _vx_monitor {
21765 +       unsigned int counter;
21766 +
21767 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21768 +};
21769 +
21770 +
21771 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21772 +
21773 +unsigned volatile int vxm_active = 1;
21774 +
21775 +static atomic_t sequence = ATOMIC_INIT(0);
21776 +
21777 +
21778 +/*     vxm_advance()
21779 +
21780 +       * requires disabled preemption                          */
21781 +
21782 +struct _vx_mon_entry *vxm_advance(int cpu)
21783 +{
21784 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21785 +       struct _vx_mon_entry *entry;
21786 +       unsigned int index;
21787 +
21788 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21789 +       entry = &mon->entry[index];
21790 +
21791 +       entry->ev.seq = atomic_inc_return(&sequence);
21792 +       entry->ev.jif = jiffies;
21793 +       return entry;
21794 +}
21795 +
21796 +EXPORT_SYMBOL_GPL(vxm_advance);
21797 +
21798 +
21799 +int do_read_monitor(struct __user _vx_mon_entry *data,
21800 +       int cpu, uint32_t *index, uint32_t *count)
21801 +{
21802 +       int pos, ret = 0;
21803 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21804 +       int end = mon->counter;
21805 +       int start = end - VXM_SIZE + 2;
21806 +       int idx = *index;
21807 +
21808 +       /* special case: get current pos */
21809 +       if (!*count) {
21810 +               *index = end;
21811 +               return 0;
21812 +       }
21813 +
21814 +       /* have we lost some data? */
21815 +       if (idx < start)
21816 +               idx = start;
21817 +
21818 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21819 +               struct _vx_mon_entry *entry =
21820 +                       &mon->entry[idx % VXM_SIZE];
21821 +
21822 +               /* send entry to userspace */
21823 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21824 +               if (ret)
21825 +                       break;
21826 +       }
21827 +       /* save new index and count */
21828 +       *index = idx;
21829 +       *count = pos;
21830 +       return ret ? ret : (*index < end);
21831 +}
21832 +
21833 +int vc_read_monitor(uint32_t id, void __user *data)
21834 +{
21835 +       struct vcmd_read_monitor_v0 vc_data;
21836 +       int ret;
21837 +
21838 +       if (id >= NR_CPUS)
21839 +               return -EINVAL;
21840 +
21841 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21842 +               return -EFAULT;
21843 +
21844 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21845 +               id, &vc_data.index, &vc_data.count);
21846 +
21847 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21848 +               return -EFAULT;
21849 +       return ret;
21850 +}
21851 +
21852 +#ifdef CONFIG_COMPAT
21853 +
21854 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21855 +{
21856 +       struct vcmd_read_monitor_v0_x32 vc_data;
21857 +       int ret;
21858 +
21859 +       if (id >= NR_CPUS)
21860 +               return -EINVAL;
21861 +
21862 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21863 +               return -EFAULT;
21864 +
21865 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21866 +               compat_ptr(vc_data.data_ptr),
21867 +               id, &vc_data.index, &vc_data.count);
21868 +
21869 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21870 +               return -EFAULT;
21871 +       return ret;
21872 +}
21873 +
21874 +#endif /* CONFIG_COMPAT */
21875 +
21876 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/network.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/network.c
21877 --- linux-2.6.27.10/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
21878 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/network.c       2008-10-13 14:54:20.000000000 +0200
21879 @@ -0,0 +1,864 @@
21880 +/*
21881 + *  linux/kernel/vserver/network.c
21882 + *
21883 + *  Virtual Server: Network Support
21884 + *
21885 + *  Copyright (C) 2003-2007  Herbert Pötzl
21886 + *
21887 + *  V0.01  broken out from vcontext V0.05
21888 + *  V0.02  cleaned up implementation
21889 + *  V0.03  added equiv nx commands
21890 + *  V0.04  switch to RCU based hash
21891 + *  V0.05  and back to locking again
21892 + *  V0.06  changed vcmds to nxi arg
21893 + *  V0.07  have __create claim() the nxi
21894 + *
21895 + */
21896 +
21897 +#include <linux/err.h>
21898 +#include <linux/slab.h>
21899 +#include <linux/rcupdate.h>
21900 +
21901 +#include <linux/vs_network.h>
21902 +#include <linux/vs_pid.h>
21903 +#include <linux/vserver/network_cmd.h>
21904 +
21905 +
21906 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21907 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21908 +
21909 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21910 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21911 +
21912 +
21913 +static int __init init_network(void)
21914 +{
21915 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21916 +               sizeof(struct nx_addr_v4), 0,
21917 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21918 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21919 +               sizeof(struct nx_addr_v6), 0,
21920 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21921 +       return 0;
21922 +}
21923 +
21924 +
21925 +/*     __alloc_nx_addr_v4()                                    */
21926 +
21927 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21928 +{
21929 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21930 +               nx_addr_v4_cachep, GFP_KERNEL);
21931 +
21932 +       if (!IS_ERR(nxa))
21933 +               memset(nxa, 0, sizeof(*nxa));
21934 +       return nxa;
21935 +}
21936 +
21937 +/*     __dealloc_nx_addr_v4()                                  */
21938 +
21939 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21940 +{
21941 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21942 +}
21943 +
21944 +/*     __dealloc_nx_addr_v4_all()                              */
21945 +
21946 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21947 +{
21948 +       while (nxa) {
21949 +               struct nx_addr_v4 *next = nxa->next;
21950 +
21951 +               __dealloc_nx_addr_v4(nxa);
21952 +               nxa = next;
21953 +       }
21954 +}
21955 +
21956 +
21957 +#ifdef CONFIG_IPV6
21958 +
21959 +/*     __alloc_nx_addr_v6()                                    */
21960 +
21961 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21962 +{
21963 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21964 +               nx_addr_v6_cachep, GFP_KERNEL);
21965 +
21966 +       if (!IS_ERR(nxa))
21967 +               memset(nxa, 0, sizeof(*nxa));
21968 +       return nxa;
21969 +}
21970 +
21971 +/*     __dealloc_nx_addr_v6()                                  */
21972 +
21973 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21974 +{
21975 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21976 +}
21977 +
21978 +/*     __dealloc_nx_addr_v6_all()                              */
21979 +
21980 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21981 +{
21982 +       while (nxa) {
21983 +               struct nx_addr_v6 *next = nxa->next;
21984 +
21985 +               __dealloc_nx_addr_v6(nxa);
21986 +               nxa = next;
21987 +       }
21988 +}
21989 +
21990 +#endif /* CONFIG_IPV6 */
21991 +
21992 +/*     __alloc_nx_info()
21993 +
21994 +       * allocate an initialized nx_info struct
21995 +       * doesn't make it visible (hash)                        */
21996 +
21997 +static struct nx_info *__alloc_nx_info(nid_t nid)
21998 +{
21999 +       struct nx_info *new = NULL;
22000 +
22001 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22002 +
22003 +       /* would this benefit from a slab cache? */
22004 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22005 +       if (!new)
22006 +               return 0;
22007 +
22008 +       memset(new, 0, sizeof(struct nx_info));
22009 +       new->nx_id = nid;
22010 +       INIT_HLIST_NODE(&new->nx_hlist);
22011 +       atomic_set(&new->nx_usecnt, 0);
22012 +       atomic_set(&new->nx_tasks, 0);
22013 +       new->nx_state = 0;
22014 +
22015 +       new->nx_flags = NXF_INIT_SET;
22016 +
22017 +       /* rest of init goes here */
22018 +
22019 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22020 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22021 +
22022 +       vxdprintk(VXD_CBIT(nid, 0),
22023 +               "alloc_nx_info(%d) = %p", nid, new);
22024 +       atomic_inc(&nx_global_ctotal);
22025 +       return new;
22026 +}
22027 +
22028 +/*     __dealloc_nx_info()
22029 +
22030 +       * final disposal of nx_info                             */
22031 +
22032 +static void __dealloc_nx_info(struct nx_info *nxi)
22033 +{
22034 +       vxdprintk(VXD_CBIT(nid, 0),
22035 +               "dealloc_nx_info(%p)", nxi);
22036 +
22037 +       nxi->nx_hlist.next = LIST_POISON1;
22038 +       nxi->nx_id = -1;
22039 +
22040 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22041 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22042 +
22043 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22044 +
22045 +       nxi->nx_state |= NXS_RELEASED;
22046 +       kfree(nxi);
22047 +       atomic_dec(&nx_global_ctotal);
22048 +}
22049 +
22050 +static void __shutdown_nx_info(struct nx_info *nxi)
22051 +{
22052 +       nxi->nx_state |= NXS_SHUTDOWN;
22053 +       vs_net_change(nxi, VSC_NETDOWN);
22054 +}
22055 +
22056 +/*     exported stuff                                          */
22057 +
22058 +void free_nx_info(struct nx_info *nxi)
22059 +{
22060 +       /* context shutdown is mandatory */
22061 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22062 +
22063 +       /* context must not be hashed */
22064 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22065 +
22066 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22067 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22068 +
22069 +       __dealloc_nx_info(nxi);
22070 +}
22071 +
22072 +
22073 +void __nx_set_lback(struct nx_info *nxi)
22074 +{
22075 +       int nid = nxi->nx_id;
22076 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22077 +
22078 +       nxi->v4_lback.s_addr = lback;
22079 +}
22080 +
22081 +extern int __nx_inet_add_lback(__be32 addr);
22082 +extern int __nx_inet_del_lback(__be32 addr);
22083 +
22084 +
22085 +/*     hash table for nx_info hash */
22086 +
22087 +#define NX_HASH_SIZE   13
22088 +
22089 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22090 +
22091 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22092 +
22093 +
22094 +static inline unsigned int __hashval(nid_t nid)
22095 +{
22096 +       return (nid % NX_HASH_SIZE);
22097 +}
22098 +
22099 +
22100 +
22101 +/*     __hash_nx_info()
22102 +
22103 +       * add the nxi to the global hash table
22104 +       * requires the hash_lock to be held                     */
22105 +
22106 +static inline void __hash_nx_info(struct nx_info *nxi)
22107 +{
22108 +       struct hlist_head *head;
22109 +
22110 +       vxd_assert_lock(&nx_info_hash_lock);
22111 +       vxdprintk(VXD_CBIT(nid, 4),
22112 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22113 +
22114 +       /* context must not be hashed */
22115 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22116 +
22117 +       nxi->nx_state |= NXS_HASHED;
22118 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22119 +       hlist_add_head(&nxi->nx_hlist, head);
22120 +       atomic_inc(&nx_global_cactive);
22121 +}
22122 +
22123 +/*     __unhash_nx_info()
22124 +
22125 +       * remove the nxi from the global hash table
22126 +       * requires the hash_lock to be held                     */
22127 +
22128 +static inline void __unhash_nx_info(struct nx_info *nxi)
22129 +{
22130 +       vxd_assert_lock(&nx_info_hash_lock);
22131 +       vxdprintk(VXD_CBIT(nid, 4),
22132 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22133 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22134 +
22135 +       /* context must be hashed */
22136 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22137 +       /* but without tasks */
22138 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22139 +
22140 +       nxi->nx_state &= ~NXS_HASHED;
22141 +       hlist_del(&nxi->nx_hlist);
22142 +       atomic_dec(&nx_global_cactive);
22143 +}
22144 +
22145 +
22146 +/*     __lookup_nx_info()
22147 +
22148 +       * requires the hash_lock to be held
22149 +       * doesn't increment the nx_refcnt                       */
22150 +
22151 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22152 +{
22153 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22154 +       struct hlist_node *pos;
22155 +       struct nx_info *nxi;
22156 +
22157 +       vxd_assert_lock(&nx_info_hash_lock);
22158 +       hlist_for_each(pos, head) {
22159 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22160 +
22161 +               if (nxi->nx_id == nid)
22162 +                       goto found;
22163 +       }
22164 +       nxi = NULL;
22165 +found:
22166 +       vxdprintk(VXD_CBIT(nid, 0),
22167 +               "__lookup_nx_info(#%u): %p[#%u]",
22168 +               nid, nxi, nxi ? nxi->nx_id : 0);
22169 +       return nxi;
22170 +}
22171 +
22172 +
22173 +/*     __create_nx_info()
22174 +
22175 +       * create the requested context
22176 +       * get(), claim() and hash it                            */
22177 +
22178 +static struct nx_info *__create_nx_info(int id)
22179 +{
22180 +       struct nx_info *new, *nxi = NULL;
22181 +
22182 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22183 +
22184 +       if (!(new = __alloc_nx_info(id)))
22185 +               return ERR_PTR(-ENOMEM);
22186 +
22187 +       /* required to make dynamic xids unique */
22188 +       spin_lock(&nx_info_hash_lock);
22189 +
22190 +       /* static context requested */
22191 +       if ((nxi = __lookup_nx_info(id))) {
22192 +               vxdprintk(VXD_CBIT(nid, 0),
22193 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22194 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22195 +                       nxi = ERR_PTR(-EBUSY);
22196 +               else
22197 +                       nxi = ERR_PTR(-EEXIST);
22198 +               goto out_unlock;
22199 +       }
22200 +       /* new context */
22201 +       vxdprintk(VXD_CBIT(nid, 0),
22202 +               "create_nx_info(%d) = %p (new)", id, new);
22203 +       claim_nx_info(new, NULL);
22204 +       __nx_set_lback(new);
22205 +       __hash_nx_info(get_nx_info(new));
22206 +       nxi = new, new = NULL;
22207 +
22208 +out_unlock:
22209 +       spin_unlock(&nx_info_hash_lock);
22210 +       if (new)
22211 +               __dealloc_nx_info(new);
22212 +       return nxi;
22213 +}
22214 +
22215 +
22216 +
22217 +/*     exported stuff                                          */
22218 +
22219 +
22220 +void unhash_nx_info(struct nx_info *nxi)
22221 +{
22222 +       __shutdown_nx_info(nxi);
22223 +       spin_lock(&nx_info_hash_lock);
22224 +       __unhash_nx_info(nxi);
22225 +       spin_unlock(&nx_info_hash_lock);
22226 +}
22227 +
22228 +/*     lookup_nx_info()
22229 +
22230 +       * search for a nx_info and get() it
22231 +       * negative id means current                             */
22232 +
22233 +struct nx_info *lookup_nx_info(int id)
22234 +{
22235 +       struct nx_info *nxi = NULL;
22236 +
22237 +       if (id < 0) {
22238 +               nxi = get_nx_info(current->nx_info);
22239 +       } else if (id > 1) {
22240 +               spin_lock(&nx_info_hash_lock);
22241 +               nxi = get_nx_info(__lookup_nx_info(id));
22242 +               spin_unlock(&nx_info_hash_lock);
22243 +       }
22244 +       return nxi;
22245 +}
22246 +
22247 +/*     nid_is_hashed()
22248 +
22249 +       * verify that nid is still hashed                       */
22250 +
22251 +int nid_is_hashed(nid_t nid)
22252 +{
22253 +       int hashed;
22254 +
22255 +       spin_lock(&nx_info_hash_lock);
22256 +       hashed = (__lookup_nx_info(nid) != NULL);
22257 +       spin_unlock(&nx_info_hash_lock);
22258 +       return hashed;
22259 +}
22260 +
22261 +
22262 +#ifdef CONFIG_PROC_FS
22263 +
22264 +/*     get_nid_list()
22265 +
22266 +       * get a subset of hashed nids for proc
22267 +       * assumes size is at least one                          */
22268 +
22269 +int get_nid_list(int index, unsigned int *nids, int size)
22270 +{
22271 +       int hindex, nr_nids = 0;
22272 +
22273 +       /* only show current and children */
22274 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22275 +               if (index > 0)
22276 +                       return 0;
22277 +               nids[nr_nids] = nx_current_nid();
22278 +               return 1;
22279 +       }
22280 +
22281 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22282 +               struct hlist_head *head = &nx_info_hash[hindex];
22283 +               struct hlist_node *pos;
22284 +
22285 +               spin_lock(&nx_info_hash_lock);
22286 +               hlist_for_each(pos, head) {
22287 +                       struct nx_info *nxi;
22288 +
22289 +                       if (--index > 0)
22290 +                               continue;
22291 +
22292 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22293 +                       nids[nr_nids] = nxi->nx_id;
22294 +                       if (++nr_nids >= size) {
22295 +                               spin_unlock(&nx_info_hash_lock);
22296 +                               goto out;
22297 +                       }
22298 +               }
22299 +               /* keep the lock time short */
22300 +               spin_unlock(&nx_info_hash_lock);
22301 +       }
22302 +out:
22303 +       return nr_nids;
22304 +}
22305 +#endif
22306 +
22307 +
22308 +/*
22309 + *     migrate task to new network
22310 + *     gets nxi, puts old_nxi on change
22311 + */
22312 +
22313 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22314 +{
22315 +       struct nx_info *old_nxi;
22316 +       int ret = 0;
22317 +
22318 +       if (!p || !nxi)
22319 +               BUG();
22320 +
22321 +       vxdprintk(VXD_CBIT(nid, 5),
22322 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22323 +               p, nxi, nxi->nx_id,
22324 +               atomic_read(&nxi->nx_usecnt),
22325 +               atomic_read(&nxi->nx_tasks));
22326 +
22327 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22328 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22329 +               return -EACCES;
22330 +
22331 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22332 +               return -EFAULT;
22333 +
22334 +       /* maybe disallow this completely? */
22335 +       old_nxi = task_get_nx_info(p);
22336 +       if (old_nxi == nxi)
22337 +               goto out;
22338 +
22339 +       task_lock(p);
22340 +       if (old_nxi)
22341 +               clr_nx_info(&p->nx_info);
22342 +       claim_nx_info(nxi, p);
22343 +       set_nx_info(&p->nx_info, nxi);
22344 +       p->nid = nxi->nx_id;
22345 +       task_unlock(p);
22346 +
22347 +       vxdprintk(VXD_CBIT(nid, 5),
22348 +               "moved task %p into nxi:%p[#%d]",
22349 +               p, nxi, nxi->nx_id);
22350 +
22351 +       if (old_nxi)
22352 +               release_nx_info(old_nxi, p);
22353 +       ret = 0;
22354 +out:
22355 +       put_nx_info(old_nxi);
22356 +       return ret;
22357 +}
22358 +
22359 +
22360 +void nx_set_persistent(struct nx_info *nxi)
22361 +{
22362 +       vxdprintk(VXD_CBIT(nid, 6),
22363 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22364 +
22365 +       get_nx_info(nxi);
22366 +       claim_nx_info(nxi, NULL);
22367 +}
22368 +
22369 +void nx_clear_persistent(struct nx_info *nxi)
22370 +{
22371 +       vxdprintk(VXD_CBIT(nid, 6),
22372 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22373 +
22374 +       release_nx_info(nxi, NULL);
22375 +       put_nx_info(nxi);
22376 +}
22377 +
22378 +void nx_update_persistent(struct nx_info *nxi)
22379 +{
22380 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22381 +               nx_set_persistent(nxi);
22382 +       else
22383 +               nx_clear_persistent(nxi);
22384 +}
22385 +
22386 +/* vserver syscall commands below here */
22387 +
22388 +/* taks nid and nx_info functions */
22389 +
22390 +#include <asm/uaccess.h>
22391 +
22392 +
22393 +int vc_task_nid(uint32_t id)
22394 +{
22395 +       nid_t nid;
22396 +
22397 +       if (id) {
22398 +               struct task_struct *tsk;
22399 +
22400 +               read_lock(&tasklist_lock);
22401 +               tsk = find_task_by_real_pid(id);
22402 +               nid = (tsk) ? tsk->nid : -ESRCH;
22403 +               read_unlock(&tasklist_lock);
22404 +       } else
22405 +               nid = nx_current_nid();
22406 +       return nid;
22407 +}
22408 +
22409 +
22410 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22411 +{
22412 +       struct vcmd_nx_info_v0 vc_data;
22413 +
22414 +       vc_data.nid = nxi->nx_id;
22415 +
22416 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22417 +               return -EFAULT;
22418 +       return 0;
22419 +}
22420 +
22421 +
22422 +/* network functions */
22423 +
22424 +int vc_net_create(uint32_t nid, void __user *data)
22425 +{
22426 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22427 +       struct nx_info *new_nxi;
22428 +       int ret;
22429 +
22430 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22431 +               return -EFAULT;
22432 +
22433 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22434 +               return -EINVAL;
22435 +
22436 +       new_nxi = __create_nx_info(nid);
22437 +       if (IS_ERR(new_nxi))
22438 +               return PTR_ERR(new_nxi);
22439 +
22440 +       /* initial flags */
22441 +       new_nxi->nx_flags = vc_data.flagword;
22442 +
22443 +       ret = -ENOEXEC;
22444 +       if (vs_net_change(new_nxi, VSC_NETUP))
22445 +               goto out;
22446 +
22447 +       ret = nx_migrate_task(current, new_nxi);
22448 +       if (ret)
22449 +               goto out;
22450 +
22451 +       /* return context id on success */
22452 +       ret = new_nxi->nx_id;
22453 +
22454 +       /* get a reference for persistent contexts */
22455 +       if ((vc_data.flagword & NXF_PERSISTENT))
22456 +               nx_set_persistent(new_nxi);
22457 +out:
22458 +       release_nx_info(new_nxi, NULL);
22459 +       put_nx_info(new_nxi);
22460 +       return ret;
22461 +}
22462 +
22463 +
22464 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22465 +{
22466 +       return nx_migrate_task(current, nxi);
22467 +}
22468 +
22469 +
22470 +
22471 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22472 +       uint16_t type, uint16_t flags)
22473 +{
22474 +       struct nx_addr_v4 *nxa = &nxi->v4;
22475 +
22476 +       if (NX_IPV4(nxi)) {
22477 +               /* locate last entry */
22478 +               for (; nxa->next; nxa = nxa->next);
22479 +               nxa->next = __alloc_nx_addr_v4();
22480 +               nxa = nxa->next;
22481 +
22482 +               if (IS_ERR(nxa))
22483 +                       return PTR_ERR(nxa);
22484 +       }
22485 +
22486 +       if (nxi->v4.next)
22487 +               /* remove single ip for ip list */
22488 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22489 +
22490 +       nxa->ip[0].s_addr = ip;
22491 +       nxa->ip[1].s_addr = ip2;
22492 +       nxa->mask.s_addr = mask;
22493 +       nxa->type = type;
22494 +       nxa->flags = flags;
22495 +       return 0;
22496 +}
22497 +
22498 +
22499 +int vc_net_add(struct nx_info *nxi, void __user *data)
22500 +{
22501 +       struct vcmd_net_addr_v0 vc_data;
22502 +       int index, ret = 0;
22503 +
22504 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22505 +               return -EFAULT;
22506 +
22507 +       switch (vc_data.type) {
22508 +       case NXA_TYPE_IPV4:
22509 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22510 +                       return -EINVAL;
22511 +
22512 +               index = 0;
22513 +               while (index < vc_data.count) {
22514 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22515 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22516 +                       if (ret)
22517 +                               return ret;
22518 +                       index++;
22519 +               }
22520 +               ret = index;
22521 +               break;
22522 +
22523 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22524 +               nxi->v4_bcast = vc_data.ip[0];
22525 +               ret = 1;
22526 +               break;
22527 +
22528 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22529 +               nxi->v4_lback = vc_data.ip[0];
22530 +               ret = 1;
22531 +               break;
22532 +
22533 +       default:
22534 +               ret = -EINVAL;
22535 +               break;
22536 +       }
22537 +       return ret;
22538 +}
22539 +
22540 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22541 +{
22542 +       struct vcmd_net_addr_v0 vc_data;
22543 +
22544 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22545 +               return -EFAULT;
22546 +
22547 +       switch (vc_data.type) {
22548 +       case NXA_TYPE_ANY:
22549 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22550 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22551 +               break;
22552 +
22553 +       default:
22554 +               return -EINVAL;
22555 +       }
22556 +       return 0;
22557 +}
22558 +
22559 +
22560 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22561 +{
22562 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22563 +
22564 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22565 +               return -EFAULT;
22566 +
22567 +       switch (vc_data.type) {
22568 +       case NXA_TYPE_ADDR:
22569 +       case NXA_TYPE_RANGE:
22570 +       case NXA_TYPE_MASK:
22571 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22572 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22573 +
22574 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22575 +               nxi->v4_bcast = vc_data.ip;
22576 +               break;
22577 +
22578 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22579 +               nxi->v4_lback = vc_data.ip;
22580 +               break;
22581 +
22582 +       default:
22583 +               return -EINVAL;
22584 +       }
22585 +       return 0;
22586 +}
22587 +
22588 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22589 +{
22590 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22591 +
22592 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22593 +               return -EFAULT;
22594 +
22595 +       switch (vc_data.type) {
22596 +/*     case NXA_TYPE_ADDR:
22597 +               break;          */
22598 +
22599 +       case NXA_TYPE_ANY:
22600 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22601 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22602 +               break;
22603 +
22604 +       default:
22605 +               return -EINVAL;
22606 +       }
22607 +       return 0;
22608 +}
22609 +
22610 +
22611 +#ifdef CONFIG_IPV6
22612 +
22613 +int do_add_v6_addr(struct nx_info *nxi,
22614 +       struct in6_addr *ip, struct in6_addr *mask,
22615 +       uint32_t prefix, uint16_t type, uint16_t flags)
22616 +{
22617 +       struct nx_addr_v6 *nxa = &nxi->v6;
22618 +
22619 +       if (NX_IPV6(nxi)) {
22620 +               /* locate last entry */
22621 +               for (; nxa->next; nxa = nxa->next);
22622 +               nxa->next = __alloc_nx_addr_v6();
22623 +               nxa = nxa->next;
22624 +
22625 +               if (IS_ERR(nxa))
22626 +                       return PTR_ERR(nxa);
22627 +       }
22628 +
22629 +       nxa->ip = *ip;
22630 +       nxa->mask = *mask;
22631 +       nxa->prefix = prefix;
22632 +       nxa->type = type;
22633 +       nxa->flags = flags;
22634 +       return 0;
22635 +}
22636 +
22637 +
22638 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22639 +{
22640 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22641 +
22642 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22643 +               return -EFAULT;
22644 +
22645 +       switch (vc_data.type) {
22646 +       case NXA_TYPE_ADDR:
22647 +       case NXA_TYPE_MASK:
22648 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22649 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22650 +       default:
22651 +               return -EINVAL;
22652 +       }
22653 +       return 0;
22654 +}
22655 +
22656 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22657 +{
22658 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22659 +
22660 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22661 +               return -EFAULT;
22662 +
22663 +       switch (vc_data.type) {
22664 +       case NXA_TYPE_ANY:
22665 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22666 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22667 +               break;
22668 +
22669 +       default:
22670 +               return -EINVAL;
22671 +       }
22672 +       return 0;
22673 +}
22674 +
22675 +#endif /* CONFIG_IPV6 */
22676 +
22677 +
22678 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22679 +{
22680 +       struct vcmd_net_flags_v0 vc_data;
22681 +
22682 +       vc_data.flagword = nxi->nx_flags;
22683 +
22684 +       /* special STATE flag handling */
22685 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22686 +
22687 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22688 +               return -EFAULT;
22689 +       return 0;
22690 +}
22691 +
22692 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22693 +{
22694 +       struct vcmd_net_flags_v0 vc_data;
22695 +       uint64_t mask, trigger;
22696 +
22697 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22698 +               return -EFAULT;
22699 +
22700 +       /* special STATE flag handling */
22701 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22702 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22703 +
22704 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22705 +               vc_data.flagword, mask);
22706 +       if (trigger & NXF_PERSISTENT)
22707 +               nx_update_persistent(nxi);
22708 +
22709 +       return 0;
22710 +}
22711 +
22712 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22713 +{
22714 +       struct vcmd_net_caps_v0 vc_data;
22715 +
22716 +       vc_data.ncaps = nxi->nx_ncaps;
22717 +       vc_data.cmask = ~0ULL;
22718 +
22719 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22720 +               return -EFAULT;
22721 +       return 0;
22722 +}
22723 +
22724 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22725 +{
22726 +       struct vcmd_net_caps_v0 vc_data;
22727 +
22728 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22729 +               return -EFAULT;
22730 +
22731 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22732 +               vc_data.ncaps, vc_data.cmask);
22733 +       return 0;
22734 +}
22735 +
22736 +
22737 +#include <linux/module.h>
22738 +
22739 +module_init(init_network);
22740 +
22741 +EXPORT_SYMBOL_GPL(free_nx_info);
22742 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22743 +
22744 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/proc.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/proc.c
22745 --- linux-2.6.27.10/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
22746 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/proc.c  2008-10-31 18:15:28.000000000 +0100
22747 @@ -0,0 +1,1092 @@
22748 +/*
22749 + *  linux/kernel/vserver/proc.c
22750 + *
22751 + *  Virtual Context Support
22752 + *
22753 + *  Copyright (C) 2003-2007  Herbert Pötzl
22754 + *
22755 + *  V0.01  basic structure
22756 + *  V0.02  adaptation vs1.3.0
22757 + *  V0.03  proc permissions
22758 + *  V0.04  locking/generic
22759 + *  V0.05  next generation procfs
22760 + *  V0.06  inode validation
22761 + *  V0.07  generic rewrite vid
22762 + *  V0.08  remove inode type
22763 + *
22764 + */
22765 +
22766 +#include <linux/proc_fs.h>
22767 +#include <asm/unistd.h>
22768 +
22769 +#include <linux/vs_context.h>
22770 +#include <linux/vs_network.h>
22771 +#include <linux/vs_cvirt.h>
22772 +
22773 +#include <linux/in.h>
22774 +#include <linux/inetdevice.h>
22775 +#include <linux/vs_inet.h>
22776 +#include <linux/vs_inet6.h>
22777 +
22778 +#include <linux/vserver/global.h>
22779 +
22780 +#include "cvirt_proc.h"
22781 +#include "cacct_proc.h"
22782 +#include "limit_proc.h"
22783 +#include "sched_proc.h"
22784 +#include "vci_config.h"
22785 +
22786 +
22787 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22788 +{
22789 +       unsigned __capi;
22790 +
22791 +       CAP_FOR_EACH_U32(__capi) {
22792 +               buffer += sprintf(buffer, "%08x",
22793 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22794 +       }
22795 +       return buffer;
22796 +}
22797 +
22798 +
22799 +static struct proc_dir_entry *proc_virtual;
22800 +
22801 +static struct proc_dir_entry *proc_virtnet;
22802 +
22803 +
22804 +/* first the actual feeds */
22805 +
22806 +
22807 +static int proc_vci(char *buffer)
22808 +{
22809 +       return sprintf(buffer,
22810 +               "VCIVersion:\t%04x:%04x\n"
22811 +               "VCISyscall:\t%d\n"
22812 +               "VCIKernel:\t%08x\n",
22813 +               VCI_VERSION >> 16,
22814 +               VCI_VERSION & 0xFFFF,
22815 +               __NR_vserver,
22816 +               vci_kernel_config());
22817 +}
22818 +
22819 +static int proc_virtual_info(char *buffer)
22820 +{
22821 +       return proc_vci(buffer);
22822 +}
22823 +
22824 +static int proc_virtual_status(char *buffer)
22825 +{
22826 +       return sprintf(buffer,
22827 +               "#CTotal:\t%d\n"
22828 +               "#CActive:\t%d\n"
22829 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n",
22830 +               atomic_read(&vx_global_ctotal),
22831 +               atomic_read(&vx_global_cactive),
22832 +               atomic_read(&vs_global_nsproxy),
22833 +               atomic_read(&vs_global_fs),
22834 +               atomic_read(&vs_global_mnt_ns),
22835 +               atomic_read(&vs_global_uts_ns),
22836 +               atomic_read(&vs_global_ipc_ns),
22837 +               atomic_read(&vs_global_user_ns),
22838 +               atomic_read(&vs_global_pid_ns));
22839 +}
22840 +
22841 +
22842 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22843 +{
22844 +       int length;
22845 +
22846 +       length = sprintf(buffer,
22847 +               "ID:\t%d\n"
22848 +               "Info:\t%p\n"
22849 +               "Init:\t%d\n"
22850 +               "OOM:\t%lld\n",
22851 +               vxi->vx_id,
22852 +               vxi,
22853 +               vxi->vx_initpid,
22854 +               vxi->vx_badness_bias);
22855 +       return length;
22856 +}
22857 +
22858 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22859 +{
22860 +       char *orig = buffer;
22861 +
22862 +       buffer += sprintf(buffer,
22863 +               "UseCnt:\t%d\n"
22864 +               "Tasks:\t%d\n"
22865 +               "Flags:\t%016llx\n",
22866 +               atomic_read(&vxi->vx_usecnt),
22867 +               atomic_read(&vxi->vx_tasks),
22868 +               (unsigned long long)vxi->vx_flags);
22869 +
22870 +       buffer += sprintf(buffer, "BCaps:\t");
22871 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22872 +       buffer += sprintf(buffer, "\n");
22873 +
22874 +       buffer += sprintf(buffer,
22875 +               "CCaps:\t%016llx\n"
22876 +               "Spaces:\t%08lx %08lx\n",
22877 +               (unsigned long long)vxi->vx_ccaps,
22878 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22879 +       return buffer - orig;
22880 +}
22881 +
22882 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22883 +{
22884 +       return vx_info_proc_limit(&vxi->limit, buffer);
22885 +}
22886 +
22887 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22888 +{
22889 +       int cpu, length;
22890 +
22891 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22892 +       for_each_online_cpu(cpu) {
22893 +               length += vx_info_proc_sched_pc(
22894 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22895 +                       buffer + length, cpu);
22896 +       }
22897 +       return length;
22898 +}
22899 +
22900 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22901 +{
22902 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22903 +}
22904 +
22905 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22906 +{
22907 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22908 +}
22909 +
22910 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22911 +{
22912 +       int cpu, length;
22913 +
22914 +       vx_update_load(vxi);
22915 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22916 +       for_each_online_cpu(cpu) {
22917 +               length += vx_info_proc_cvirt_pc(
22918 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22919 +                       buffer + length, cpu);
22920 +       }
22921 +       return length;
22922 +}
22923 +
22924 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22925 +{
22926 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22927 +}
22928 +
22929 +
22930 +static int proc_virtnet_info(char *buffer)
22931 +{
22932 +       return proc_vci(buffer);
22933 +}
22934 +
22935 +static int proc_virtnet_status(char *buffer)
22936 +{
22937 +       return sprintf(buffer,
22938 +               "#CTotal:\t%d\n"
22939 +               "#CActive:\t%d\n",
22940 +               atomic_read(&nx_global_ctotal),
22941 +               atomic_read(&nx_global_cactive));
22942 +}
22943 +
22944 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22945 +{
22946 +       struct nx_addr_v4 *v4a;
22947 +#ifdef CONFIG_IPV6
22948 +       struct nx_addr_v6 *v6a;
22949 +#endif
22950 +       int length, i;
22951 +
22952 +       length = sprintf(buffer,
22953 +               "ID:\t%d\n"
22954 +               "Info:\t%p\n"
22955 +               "Bcast:\t" NIPQUAD_FMT "\n"
22956 +               "Lback:\t" NIPQUAD_FMT "\n",
22957 +               nxi->nx_id,
22958 +               nxi,
22959 +               NIPQUAD(nxi->v4_bcast.s_addr),
22960 +               NIPQUAD(nxi->v4_lback.s_addr));
22961 +
22962 +       if (!NX_IPV4(nxi))
22963 +               goto skip_v4;
22964 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22965 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22966 +                       i, NXAV4(v4a));
22967 +skip_v4:
22968 +#ifdef CONFIG_IPV6
22969 +       if (!NX_IPV6(nxi))
22970 +               goto skip_v6;
22971 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22972 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22973 +                       i, NXAV6(v6a));
22974 +skip_v6:
22975 +#endif
22976 +       return length;
22977 +}
22978 +
22979 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22980 +{
22981 +       int length;
22982 +
22983 +       length = sprintf(buffer,
22984 +               "UseCnt:\t%d\n"
22985 +               "Tasks:\t%d\n"
22986 +               "Flags:\t%016llx\n"
22987 +               "NCaps:\t%016llx\n",
22988 +               atomic_read(&nxi->nx_usecnt),
22989 +               atomic_read(&nxi->nx_tasks),
22990 +               (unsigned long long)nxi->nx_flags,
22991 +               (unsigned long long)nxi->nx_ncaps);
22992 +       return length;
22993 +}
22994 +
22995 +
22996 +
22997 +/* here the inode helpers */
22998 +
22999 +struct vs_entry {
23000 +       int len;
23001 +       char *name;
23002 +       mode_t mode;
23003 +       struct inode_operations *iop;
23004 +       struct file_operations *fop;
23005 +       union proc_op op;
23006 +};
23007 +
23008 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23009 +{
23010 +       struct inode *inode = new_inode(sb);
23011 +
23012 +       if (!inode)
23013 +               goto out;
23014 +
23015 +       inode->i_mode = p->mode;
23016 +       if (p->iop)
23017 +               inode->i_op = p->iop;
23018 +       if (p->fop)
23019 +               inode->i_fop = p->fop;
23020 +
23021 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23022 +       inode->i_flags |= S_IMMUTABLE;
23023 +
23024 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23025 +
23026 +       inode->i_uid = 0;
23027 +       inode->i_gid = 0;
23028 +       inode->i_tag = 0;
23029 +out:
23030 +       return inode;
23031 +}
23032 +
23033 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23034 +       struct dentry *dentry, int id, void *ptr)
23035 +{
23036 +       struct vs_entry *p = ptr;
23037 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23038 +       struct dentry *error = ERR_PTR(-EINVAL);
23039 +
23040 +       if (!inode)
23041 +               goto out;
23042 +
23043 +       PROC_I(inode)->op = p->op;
23044 +       PROC_I(inode)->fd = id;
23045 +       d_add(dentry, inode);
23046 +       error = NULL;
23047 +out:
23048 +       return error;
23049 +}
23050 +
23051 +/* Lookups */
23052 +
23053 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23054 +
23055 +/*
23056 + * Fill a directory entry.
23057 + *
23058 + * If possible create the dcache entry and derive our inode number and
23059 + * file type from dcache entry.
23060 + *
23061 + * Since all of the proc inode numbers are dynamically generated, the inode
23062 + * numbers do not exist until the inode is cache.  This means creating the
23063 + * the dcache entry in readdir is necessary to keep the inode numbers
23064 + * reported by readdir in sync with the inode numbers reported
23065 + * by stat.
23066 + */
23067 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23068 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23069 +{
23070 +       struct dentry *child, *dir = filp->f_dentry;
23071 +       struct inode *inode;
23072 +       struct qstr qname;
23073 +       ino_t ino = 0;
23074 +       unsigned type = DT_UNKNOWN;
23075 +
23076 +       qname.name = name;
23077 +       qname.len  = len;
23078 +       qname.hash = full_name_hash(name, len);
23079 +
23080 +       child = d_lookup(dir, &qname);
23081 +       if (!child) {
23082 +               struct dentry *new;
23083 +               new = d_alloc(dir, &qname);
23084 +               if (new) {
23085 +                       child = instantiate(dir->d_inode, new, id, ptr);
23086 +                       if (child)
23087 +                               dput(new);
23088 +                       else
23089 +                               child = new;
23090 +               }
23091 +       }
23092 +       if (!child || IS_ERR(child) || !child->d_inode)
23093 +               goto end_instantiate;
23094 +       inode = child->d_inode;
23095 +       if (inode) {
23096 +               ino = inode->i_ino;
23097 +               type = inode->i_mode >> 12;
23098 +       }
23099 +       dput(child);
23100 +end_instantiate:
23101 +       if (!ino)
23102 +               ino = find_inode_number(dir, &qname);
23103 +       if (!ino)
23104 +               ino = 1;
23105 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23106 +}
23107 +
23108 +
23109 +
23110 +/* get and revalidate vx_info/xid */
23111 +
23112 +static inline
23113 +struct vx_info *get_proc_vx_info(struct inode *inode)
23114 +{
23115 +       return lookup_vx_info(PROC_I(inode)->fd);
23116 +}
23117 +
23118 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23119 +{
23120 +       struct inode *inode = dentry->d_inode;
23121 +       xid_t xid = PROC_I(inode)->fd;
23122 +
23123 +       if (!xid || xid_is_hashed(xid))
23124 +               return 1;
23125 +       d_drop(dentry);
23126 +       return 0;
23127 +}
23128 +
23129 +
23130 +/* get and revalidate nx_info/nid */
23131 +
23132 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23133 +{
23134 +       struct inode *inode = dentry->d_inode;
23135 +       nid_t nid = PROC_I(inode)->fd;
23136 +
23137 +       if (!nid || nid_is_hashed(nid))
23138 +               return 1;
23139 +       d_drop(dentry);
23140 +       return 0;
23141 +}
23142 +
23143 +
23144 +
23145 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23146 +
23147 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23148 +                         size_t count, loff_t *ppos)
23149 +{
23150 +       struct inode *inode = file->f_dentry->d_inode;
23151 +       unsigned long page;
23152 +       ssize_t length = 0;
23153 +
23154 +       if (count > PROC_BLOCK_SIZE)
23155 +               count = PROC_BLOCK_SIZE;
23156 +
23157 +       /* fade that out as soon as stable */
23158 +       WARN_ON(PROC_I(inode)->fd);
23159 +
23160 +       if (!(page = __get_free_page(GFP_KERNEL)))
23161 +               return -ENOMEM;
23162 +
23163 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23164 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23165 +
23166 +       if (length >= 0)
23167 +               length = simple_read_from_buffer(buf, count, ppos,
23168 +                       (char *)page, length);
23169 +
23170 +       free_page(page);
23171 +       return length;
23172 +}
23173 +
23174 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23175 +                         size_t count, loff_t *ppos)
23176 +{
23177 +       struct inode *inode = file->f_dentry->d_inode;
23178 +       struct vx_info *vxi = NULL;
23179 +       xid_t xid = PROC_I(inode)->fd;
23180 +       unsigned long page;
23181 +       ssize_t length = 0;
23182 +
23183 +       if (count > PROC_BLOCK_SIZE)
23184 +               count = PROC_BLOCK_SIZE;
23185 +
23186 +       /* fade that out as soon as stable */
23187 +       WARN_ON(!xid);
23188 +       vxi = lookup_vx_info(xid);
23189 +       if (!vxi)
23190 +               goto out;
23191 +
23192 +       length = -ENOMEM;
23193 +       if (!(page = __get_free_page(GFP_KERNEL)))
23194 +               goto out_put;
23195 +
23196 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23197 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23198 +
23199 +       if (length >= 0)
23200 +               length = simple_read_from_buffer(buf, count, ppos,
23201 +                       (char *)page, length);
23202 +
23203 +       free_page(page);
23204 +out_put:
23205 +       put_vx_info(vxi);
23206 +out:
23207 +       return length;
23208 +}
23209 +
23210 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23211 +                         size_t count, loff_t *ppos)
23212 +{
23213 +       struct inode *inode = file->f_dentry->d_inode;
23214 +       struct nx_info *nxi = NULL;
23215 +       nid_t nid = PROC_I(inode)->fd;
23216 +       unsigned long page;
23217 +       ssize_t length = 0;
23218 +
23219 +       if (count > PROC_BLOCK_SIZE)
23220 +               count = PROC_BLOCK_SIZE;
23221 +
23222 +       /* fade that out as soon as stable */
23223 +       WARN_ON(!nid);
23224 +       nxi = lookup_nx_info(nid);
23225 +       if (!nxi)
23226 +               goto out;
23227 +
23228 +       length = -ENOMEM;
23229 +       if (!(page = __get_free_page(GFP_KERNEL)))
23230 +               goto out_put;
23231 +
23232 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23233 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23234 +
23235 +       if (length >= 0)
23236 +               length = simple_read_from_buffer(buf, count, ppos,
23237 +                       (char *)page, length);
23238 +
23239 +       free_page(page);
23240 +out_put:
23241 +       put_nx_info(nxi);
23242 +out:
23243 +       return length;
23244 +}
23245 +
23246 +
23247 +
23248 +/* here comes the lower level */
23249 +
23250 +
23251 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23252 +       .len  = sizeof(NAME) - 1,       \
23253 +       .name = (NAME),                 \
23254 +       .mode = MODE,                   \
23255 +       .iop  = IOP,                    \
23256 +       .fop  = FOP,                    \
23257 +       .op   = OP,                     \
23258 +}
23259 +
23260 +
23261 +#define DIR(NAME, MODE, OTYPE)                         \
23262 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23263 +               &proc_ ## OTYPE ## _inode_operations,   \
23264 +               &proc_ ## OTYPE ## _file_operations, { } )
23265 +
23266 +#define INF(NAME, MODE, OTYPE)                         \
23267 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23268 +               &proc_vs_info_file_operations,          \
23269 +               { .proc_vs_read = &proc_##OTYPE } )
23270 +
23271 +#define VINF(NAME, MODE, OTYPE)                                \
23272 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23273 +               &proc_vx_info_file_operations,          \
23274 +               { .proc_vxi_read = &proc_##OTYPE } )
23275 +
23276 +#define NINF(NAME, MODE, OTYPE)                                \
23277 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23278 +               &proc_nx_info_file_operations,          \
23279 +               { .proc_nxi_read = &proc_##OTYPE } )
23280 +
23281 +
23282 +static struct file_operations proc_vs_info_file_operations = {
23283 +       .read =         proc_vs_info_read,
23284 +};
23285 +
23286 +static struct file_operations proc_vx_info_file_operations = {
23287 +       .read =         proc_vx_info_read,
23288 +};
23289 +
23290 +static struct dentry_operations proc_xid_dentry_operations = {
23291 +       .d_revalidate = proc_xid_revalidate,
23292 +};
23293 +
23294 +static struct vs_entry vx_base_stuff[] = {
23295 +       VINF("info",    S_IRUGO, vxi_info),
23296 +       VINF("status",  S_IRUGO, vxi_status),
23297 +       VINF("limit",   S_IRUGO, vxi_limit),
23298 +       VINF("sched",   S_IRUGO, vxi_sched),
23299 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23300 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23301 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23302 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23303 +       {}
23304 +};
23305 +
23306 +
23307 +
23308 +
23309 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23310 +       struct dentry *dentry, int id, void *ptr)
23311 +{
23312 +       dentry->d_op = &proc_xid_dentry_operations;
23313 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23314 +}
23315 +
23316 +static struct dentry *proc_xid_lookup(struct inode *dir,
23317 +       struct dentry *dentry, struct nameidata *nd)
23318 +{
23319 +       struct vs_entry *p = vx_base_stuff;
23320 +       struct dentry *error = ERR_PTR(-ENOENT);
23321 +
23322 +       for (; p->name; p++) {
23323 +               if (p->len != dentry->d_name.len)
23324 +                       continue;
23325 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23326 +                       break;
23327 +       }
23328 +       if (!p->name)
23329 +               goto out;
23330 +
23331 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23332 +out:
23333 +       return error;
23334 +}
23335 +
23336 +static int proc_xid_readdir(struct file *filp,
23337 +       void *dirent, filldir_t filldir)
23338 +{
23339 +       struct dentry *dentry = filp->f_dentry;
23340 +       struct inode *inode = dentry->d_inode;
23341 +       struct vs_entry *p = vx_base_stuff;
23342 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23343 +       int pos, index;
23344 +       u64 ino;
23345 +
23346 +       pos = filp->f_pos;
23347 +       switch (pos) {
23348 +       case 0:
23349 +               ino = inode->i_ino;
23350 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23351 +                       goto out;
23352 +               pos++;
23353 +               /* fall through */
23354 +       case 1:
23355 +               ino = parent_ino(dentry);
23356 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23357 +                       goto out;
23358 +               pos++;
23359 +               /* fall through */
23360 +       default:
23361 +               index = pos - 2;
23362 +               if (index >= size)
23363 +                       goto out;
23364 +               for (p += index; p->name; p++) {
23365 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23366 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23367 +                               goto out;
23368 +                       pos++;
23369 +               }
23370 +       }
23371 +out:
23372 +       filp->f_pos = pos;
23373 +       return 1;
23374 +}
23375 +
23376 +
23377 +
23378 +static struct file_operations proc_nx_info_file_operations = {
23379 +       .read =         proc_nx_info_read,
23380 +};
23381 +
23382 +static struct dentry_operations proc_nid_dentry_operations = {
23383 +       .d_revalidate = proc_nid_revalidate,
23384 +};
23385 +
23386 +static struct vs_entry nx_base_stuff[] = {
23387 +       NINF("info",    S_IRUGO, nxi_info),
23388 +       NINF("status",  S_IRUGO, nxi_status),
23389 +       {}
23390 +};
23391 +
23392 +
23393 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23394 +       struct dentry *dentry, int id, void *ptr)
23395 +{
23396 +       dentry->d_op = &proc_nid_dentry_operations;
23397 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23398 +}
23399 +
23400 +static struct dentry *proc_nid_lookup(struct inode *dir,
23401 +       struct dentry *dentry, struct nameidata *nd)
23402 +{
23403 +       struct vs_entry *p = nx_base_stuff;
23404 +       struct dentry *error = ERR_PTR(-ENOENT);
23405 +
23406 +       for (; p->name; p++) {
23407 +               if (p->len != dentry->d_name.len)
23408 +                       continue;
23409 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23410 +                       break;
23411 +       }
23412 +       if (!p->name)
23413 +               goto out;
23414 +
23415 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23416 +out:
23417 +       return error;
23418 +}
23419 +
23420 +static int proc_nid_readdir(struct file *filp,
23421 +       void *dirent, filldir_t filldir)
23422 +{
23423 +       struct dentry *dentry = filp->f_dentry;
23424 +       struct inode *inode = dentry->d_inode;
23425 +       struct vs_entry *p = nx_base_stuff;
23426 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23427 +       int pos, index;
23428 +       u64 ino;
23429 +
23430 +       pos = filp->f_pos;
23431 +       switch (pos) {
23432 +       case 0:
23433 +               ino = inode->i_ino;
23434 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23435 +                       goto out;
23436 +               pos++;
23437 +               /* fall through */
23438 +       case 1:
23439 +               ino = parent_ino(dentry);
23440 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23441 +                       goto out;
23442 +               pos++;
23443 +               /* fall through */
23444 +       default:
23445 +               index = pos - 2;
23446 +               if (index >= size)
23447 +                       goto out;
23448 +               for (p += index; p->name; p++) {
23449 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23450 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23451 +                               goto out;
23452 +                       pos++;
23453 +               }
23454 +       }
23455 +out:
23456 +       filp->f_pos = pos;
23457 +       return 1;
23458 +}
23459 +
23460 +
23461 +#define MAX_MULBY10    ((~0U - 9) / 10)
23462 +
23463 +static inline int atovid(const char *str, int len)
23464 +{
23465 +       int vid, c;
23466 +
23467 +       vid = 0;
23468 +       while (len-- > 0) {
23469 +               c = *str - '0';
23470 +               str++;
23471 +               if (c > 9)
23472 +                       return -1;
23473 +               if (vid >= MAX_MULBY10)
23474 +                       return -1;
23475 +               vid *= 10;
23476 +               vid += c;
23477 +               if (!vid)
23478 +                       return -1;
23479 +       }
23480 +       return vid;
23481 +}
23482 +
23483 +/* now the upper level (virtual) */
23484 +
23485 +
23486 +static struct file_operations proc_xid_file_operations = {
23487 +       .read =         generic_read_dir,
23488 +       .readdir =      proc_xid_readdir,
23489 +};
23490 +
23491 +static struct inode_operations proc_xid_inode_operations = {
23492 +       .lookup =       proc_xid_lookup,
23493 +};
23494 +
23495 +static struct vs_entry vx_virtual_stuff[] = {
23496 +       INF("info",     S_IRUGO, virtual_info),
23497 +       INF("status",   S_IRUGO, virtual_status),
23498 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23499 +};
23500 +
23501 +
23502 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23503 +       struct dentry *dentry, struct nameidata *nd)
23504 +{
23505 +       struct vs_entry *p = vx_virtual_stuff;
23506 +       struct dentry *error = ERR_PTR(-ENOENT);
23507 +       int id = 0;
23508 +
23509 +       for (; p->name; p++) {
23510 +               if (p->len != dentry->d_name.len)
23511 +                       continue;
23512 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23513 +                       break;
23514 +       }
23515 +       if (p->name)
23516 +               goto instantiate;
23517 +
23518 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23519 +       if ((id < 0) || !xid_is_hashed(id))
23520 +               goto out;
23521 +
23522 +instantiate:
23523 +       error = proc_xid_instantiate(dir, dentry, id, p);
23524 +out:
23525 +       return error;
23526 +}
23527 +
23528 +static struct file_operations proc_nid_file_operations = {
23529 +       .read =         generic_read_dir,
23530 +       .readdir =      proc_nid_readdir,
23531 +};
23532 +
23533 +static struct inode_operations proc_nid_inode_operations = {
23534 +       .lookup =       proc_nid_lookup,
23535 +};
23536 +
23537 +static struct vs_entry nx_virtnet_stuff[] = {
23538 +       INF("info",     S_IRUGO, virtnet_info),
23539 +       INF("status",   S_IRUGO, virtnet_status),
23540 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23541 +};
23542 +
23543 +
23544 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23545 +       struct dentry *dentry, struct nameidata *nd)
23546 +{
23547 +       struct vs_entry *p = nx_virtnet_stuff;
23548 +       struct dentry *error = ERR_PTR(-ENOENT);
23549 +       int id = 0;
23550 +
23551 +       for (; p->name; p++) {
23552 +               if (p->len != dentry->d_name.len)
23553 +                       continue;
23554 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23555 +                       break;
23556 +       }
23557 +       if (p->name)
23558 +               goto instantiate;
23559 +
23560 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23561 +       if ((id < 0) || !nid_is_hashed(id))
23562 +               goto out;
23563 +
23564 +instantiate:
23565 +       error = proc_nid_instantiate(dir, dentry, id, p);
23566 +out:
23567 +       return error;
23568 +}
23569 +
23570 +
23571 +#define PROC_MAXVIDS 32
23572 +
23573 +int proc_virtual_readdir(struct file *filp,
23574 +       void *dirent, filldir_t filldir)
23575 +{
23576 +       struct dentry *dentry = filp->f_dentry;
23577 +       struct inode *inode = dentry->d_inode;
23578 +       struct vs_entry *p = vx_virtual_stuff;
23579 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23580 +       int pos, index;
23581 +       unsigned int xid_array[PROC_MAXVIDS];
23582 +       char buf[PROC_NUMBUF];
23583 +       unsigned int nr_xids, i;
23584 +       u64 ino;
23585 +
23586 +       pos = filp->f_pos;
23587 +       switch (pos) {
23588 +       case 0:
23589 +               ino = inode->i_ino;
23590 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23591 +                       goto out;
23592 +               pos++;
23593 +               /* fall through */
23594 +       case 1:
23595 +               ino = parent_ino(dentry);
23596 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23597 +                       goto out;
23598 +               pos++;
23599 +               /* fall through */
23600 +       default:
23601 +               index = pos - 2;
23602 +               if (index >= size)
23603 +                       goto entries;
23604 +               for (p += index; p->name; p++) {
23605 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23606 +                               vs_proc_instantiate, 0, p))
23607 +                               goto out;
23608 +                       pos++;
23609 +               }
23610 +       entries:
23611 +               index = pos - size;
23612 +               p = &vx_virtual_stuff[size - 1];
23613 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23614 +               for (i = 0; i < nr_xids; i++) {
23615 +                       int n, xid = xid_array[i];
23616 +                       unsigned int j = PROC_NUMBUF;
23617 +
23618 +                       n = xid;
23619 +                       do
23620 +                               buf[--j] = '0' + (n % 10);
23621 +                       while (n /= 10);
23622 +
23623 +                       if (proc_fill_cache(filp, dirent, filldir,
23624 +                               buf + j, PROC_NUMBUF - j,
23625 +                               vs_proc_instantiate, xid, p))
23626 +                               goto out;
23627 +                       pos++;
23628 +               }
23629 +       }
23630 +out:
23631 +       filp->f_pos = pos;
23632 +       return 0;
23633 +}
23634 +
23635 +static int proc_virtual_getattr(struct vfsmount *mnt,
23636 +       struct dentry *dentry, struct kstat *stat)
23637 +{
23638 +       struct inode *inode = dentry->d_inode;
23639 +
23640 +       generic_fillattr(inode, stat);
23641 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23642 +       return 0;
23643 +}
23644 +
23645 +static struct file_operations proc_virtual_dir_operations = {
23646 +       .read =         generic_read_dir,
23647 +       .readdir =      proc_virtual_readdir,
23648 +};
23649 +
23650 +static struct inode_operations proc_virtual_dir_inode_operations = {
23651 +       .getattr =      proc_virtual_getattr,
23652 +       .lookup =       proc_virtual_lookup,
23653 +};
23654 +
23655 +
23656 +
23657 +
23658 +
23659 +int proc_virtnet_readdir(struct file *filp,
23660 +       void *dirent, filldir_t filldir)
23661 +{
23662 +       struct dentry *dentry = filp->f_dentry;
23663 +       struct inode *inode = dentry->d_inode;
23664 +       struct vs_entry *p = nx_virtnet_stuff;
23665 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23666 +       int pos, index;
23667 +       unsigned int nid_array[PROC_MAXVIDS];
23668 +       char buf[PROC_NUMBUF];
23669 +       unsigned int nr_nids, i;
23670 +       u64 ino;
23671 +
23672 +       pos = filp->f_pos;
23673 +       switch (pos) {
23674 +       case 0:
23675 +               ino = inode->i_ino;
23676 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23677 +                       goto out;
23678 +               pos++;
23679 +               /* fall through */
23680 +       case 1:
23681 +               ino = parent_ino(dentry);
23682 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23683 +                       goto out;
23684 +               pos++;
23685 +               /* fall through */
23686 +       default:
23687 +               index = pos - 2;
23688 +               if (index >= size)
23689 +                       goto entries;
23690 +               for (p += index; p->name; p++) {
23691 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23692 +                               vs_proc_instantiate, 0, p))
23693 +                               goto out;
23694 +                       pos++;
23695 +               }
23696 +       entries:
23697 +               index = pos - size;
23698 +               p = &nx_virtnet_stuff[size - 1];
23699 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23700 +               for (i = 0; i < nr_nids; i++) {
23701 +                       int n, nid = nid_array[i];
23702 +                       unsigned int j = PROC_NUMBUF;
23703 +
23704 +                       n = nid;
23705 +                       do
23706 +                               buf[--j] = '0' + (n % 10);
23707 +                       while (n /= 10);
23708 +
23709 +                       if (proc_fill_cache(filp, dirent, filldir,
23710 +                               buf + j, PROC_NUMBUF - j,
23711 +                               vs_proc_instantiate, nid, p))
23712 +                               goto out;
23713 +                       pos++;
23714 +               }
23715 +       }
23716 +out:
23717 +       filp->f_pos = pos;
23718 +       return 0;
23719 +}
23720 +
23721 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23722 +       struct dentry *dentry, struct kstat *stat)
23723 +{
23724 +       struct inode *inode = dentry->d_inode;
23725 +
23726 +       generic_fillattr(inode, stat);
23727 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23728 +       return 0;
23729 +}
23730 +
23731 +static struct file_operations proc_virtnet_dir_operations = {
23732 +       .read =         generic_read_dir,
23733 +       .readdir =      proc_virtnet_readdir,
23734 +};
23735 +
23736 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23737 +       .getattr =      proc_virtnet_getattr,
23738 +       .lookup =       proc_virtnet_lookup,
23739 +};
23740 +
23741 +
23742 +
23743 +void proc_vx_init(void)
23744 +{
23745 +       struct proc_dir_entry *ent;
23746 +
23747 +       ent = proc_mkdir("virtual", 0);
23748 +       if (ent) {
23749 +               ent->proc_fops = &proc_virtual_dir_operations;
23750 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23751 +       }
23752 +       proc_virtual = ent;
23753 +
23754 +       ent = proc_mkdir("virtnet", 0);
23755 +       if (ent) {
23756 +               ent->proc_fops = &proc_virtnet_dir_operations;
23757 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23758 +       }
23759 +       proc_virtnet = ent;
23760 +}
23761 +
23762 +
23763 +
23764 +
23765 +/* per pid info */
23766 +
23767 +
23768 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23769 +{
23770 +       struct vx_info *vxi;
23771 +       char *orig = buffer;
23772 +
23773 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23774 +
23775 +       vxi = task_get_vx_info(p);
23776 +       if (!vxi)
23777 +               goto out;
23778 +
23779 +       buffer += sprintf(buffer, "BCaps:\t");
23780 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23781 +       buffer += sprintf(buffer, "\n");
23782 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23783 +               (unsigned long long)vxi->vx_ccaps);
23784 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23785 +               (unsigned long long)vxi->vx_flags);
23786 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23787 +
23788 +       put_vx_info(vxi);
23789 +out:
23790 +       return buffer - orig;
23791 +}
23792 +
23793 +
23794 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23795 +{
23796 +       struct nx_info *nxi;
23797 +       struct nx_addr_v4 *v4a;
23798 +#ifdef CONFIG_IPV6
23799 +       struct nx_addr_v6 *v6a;
23800 +#endif
23801 +       char *orig = buffer;
23802 +       int i;
23803 +
23804 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23805 +
23806 +       nxi = task_get_nx_info(p);
23807 +       if (!nxi)
23808 +               goto out;
23809 +
23810 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23811 +               (unsigned long long)nxi->nx_ncaps);
23812 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23813 +               (unsigned long long)nxi->nx_flags);
23814 +
23815 +       buffer += sprintf(buffer,
23816 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23817 +               NIPQUAD(nxi->v4_bcast.s_addr));
23818 +       buffer += sprintf (buffer,
23819 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23820 +               NIPQUAD(nxi->v4_lback.s_addr));
23821 +       if (!NX_IPV4(nxi))
23822 +               goto skip_v4;
23823 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23824 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23825 +                       i, NXAV4(v4a));
23826 +skip_v4:
23827 +#ifdef CONFIG_IPV6
23828 +       if (!NX_IPV6(nxi))
23829 +               goto skip_v6;
23830 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23831 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23832 +                       i, NXAV6(v6a));
23833 +skip_v6:
23834 +#endif
23835 +       put_nx_info(nxi);
23836 +out:
23837 +       return buffer - orig;
23838 +}
23839 +
23840 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/sched.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sched.c
23841 --- linux-2.6.27.10/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
23842 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sched.c 2008-10-13 14:54:20.000000000 +0200
23843 @@ -0,0 +1,413 @@
23844 +/*
23845 + *  linux/kernel/vserver/sched.c
23846 + *
23847 + *  Virtual Server: Scheduler Support
23848 + *
23849 + *  Copyright (C) 2004-2007  Herbert Pötzl
23850 + *
23851 + *  V0.01  adapted Sam Vilains version to 2.6.3
23852 + *  V0.02  removed legacy interface
23853 + *  V0.03  changed vcmds to vxi arg
23854 + *  V0.04  removed older and legacy interfaces
23855 + *
23856 + */
23857 +
23858 +#include <linux/vs_context.h>
23859 +#include <linux/vs_sched.h>
23860 +#include <linux/vserver/sched_cmd.h>
23861 +
23862 +#include <asm/uaccess.h>
23863 +
23864 +
23865 +#define vxd_check_range(val, min, max) do {            \
23866 +       vxlprintk((val < min) || (val > max),           \
23867 +               "check_range(%ld,%ld,%ld)",             \
23868 +               (long)val, (long)min, (long)max,        \
23869 +               __FILE__, __LINE__);                    \
23870 +       } while (0)
23871 +
23872 +
23873 +void vx_update_sched_param(struct _vx_sched *sched,
23874 +       struct _vx_sched_pc *sched_pc)
23875 +{
23876 +       unsigned int set_mask = sched->update_mask;
23877 +
23878 +       if (set_mask & VXSM_FILL_RATE)
23879 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23880 +       if (set_mask & VXSM_INTERVAL)
23881 +               sched_pc->interval[0] = sched->interval[0];
23882 +       if (set_mask & VXSM_FILL_RATE2)
23883 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23884 +       if (set_mask & VXSM_INTERVAL2)
23885 +               sched_pc->interval[1] = sched->interval[1];
23886 +       if (set_mask & VXSM_TOKENS)
23887 +               sched_pc->tokens = sched->tokens;
23888 +       if (set_mask & VXSM_TOKENS_MIN)
23889 +               sched_pc->tokens_min = sched->tokens_min;
23890 +       if (set_mask & VXSM_TOKENS_MAX)
23891 +               sched_pc->tokens_max = sched->tokens_max;
23892 +       if (set_mask & VXSM_PRIO_BIAS)
23893 +               sched_pc->prio_bias = sched->prio_bias;
23894 +
23895 +       if (set_mask & VXSM_IDLE_TIME)
23896 +               sched_pc->flags |= VXSF_IDLE_TIME;
23897 +       else
23898 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23899 +
23900 +       /* reset time */
23901 +       sched_pc->norm_time = jiffies;
23902 +}
23903 +
23904 +
23905 +/*
23906 + * recalculate the context's scheduling tokens
23907 + *
23908 + * ret > 0 : number of tokens available
23909 + * ret < 0 : on hold, check delta_min[]
23910 + *          -1 only jiffies
23911 + *          -2 also idle time
23912 + *
23913 + */
23914 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23915 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23916 +{
23917 +       long delta;
23918 +       long tokens = 0;
23919 +       int flags = sched_pc->flags;
23920 +
23921 +       /* how much time did pass? */
23922 +       delta = *norm_time - sched_pc->norm_time;
23923 +       vxd_check_range(delta, 0, INT_MAX);
23924 +
23925 +       if (delta >= sched_pc->interval[0]) {
23926 +               long tokens, integral;
23927 +
23928 +               /* calc integral token part */
23929 +               tokens = delta / sched_pc->interval[0];
23930 +               integral = tokens * sched_pc->interval[0];
23931 +               tokens *= sched_pc->fill_rate[0];
23932 +#ifdef CONFIG_VSERVER_HARDCPU
23933 +               delta_min[0] = delta - integral;
23934 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23935 +#endif
23936 +               /* advance time */
23937 +               sched_pc->norm_time += delta;
23938 +
23939 +               /* add tokens */
23940 +               sched_pc->tokens += tokens;
23941 +               sched_pc->token_time += tokens;
23942 +       } else
23943 +               delta_min[0] = delta;
23944 +
23945 +#ifdef CONFIG_VSERVER_IDLETIME
23946 +       if (!(flags & VXSF_IDLE_TIME))
23947 +               goto skip_idle;
23948 +
23949 +       /* how much was the idle skip? */
23950 +       delta = *idle_time - sched_pc->idle_time;
23951 +       vxd_check_range(delta, 0, INT_MAX);
23952 +
23953 +       if (delta >= sched_pc->interval[1]) {
23954 +               long tokens, integral;
23955 +
23956 +               /* calc fair share token part */
23957 +               tokens = delta / sched_pc->interval[1];
23958 +               integral = tokens * sched_pc->interval[1];
23959 +               tokens *= sched_pc->fill_rate[1];
23960 +               delta_min[1] = delta - integral;
23961 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23962 +
23963 +               /* advance idle time */
23964 +               sched_pc->idle_time += integral;
23965 +
23966 +               /* add tokens */
23967 +               sched_pc->tokens += tokens;
23968 +               sched_pc->token_time += tokens;
23969 +       } else
23970 +               delta_min[1] = delta;
23971 +skip_idle:
23972 +#endif
23973 +
23974 +       /* clip at maximum */
23975 +       if (sched_pc->tokens > sched_pc->tokens_max)
23976 +               sched_pc->tokens = sched_pc->tokens_max;
23977 +       tokens = sched_pc->tokens;
23978 +
23979 +       if ((flags & VXSF_ONHOLD)) {
23980 +               /* can we unhold? */
23981 +               if (tokens >= sched_pc->tokens_min) {
23982 +                       flags &= ~VXSF_ONHOLD;
23983 +                       sched_pc->hold_ticks +=
23984 +                               *norm_time - sched_pc->onhold;
23985 +               } else
23986 +                       goto on_hold;
23987 +       } else {
23988 +               /* put on hold? */
23989 +               if (tokens <= 0) {
23990 +                       flags |= VXSF_ONHOLD;
23991 +                       sched_pc->onhold = *norm_time;
23992 +                       goto on_hold;
23993 +               }
23994 +       }
23995 +       sched_pc->flags = flags;
23996 +       return tokens;
23997 +
23998 +on_hold:
23999 +       tokens = sched_pc->tokens_min - tokens;
24000 +       sched_pc->flags = flags;
24001 +       BUG_ON(tokens < 0);
24002 +
24003 +#ifdef CONFIG_VSERVER_HARDCPU
24004 +       /* next interval? */
24005 +       if (!sched_pc->fill_rate[0])
24006 +               delta_min[0] = HZ;
24007 +       else if (tokens > sched_pc->fill_rate[0])
24008 +               delta_min[0] += sched_pc->interval[0] *
24009 +                       tokens / sched_pc->fill_rate[0];
24010 +       else
24011 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24012 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24013 +
24014 +#ifdef CONFIG_VSERVER_IDLETIME
24015 +       if (!(flags & VXSF_IDLE_TIME))
24016 +               return -1;
24017 +
24018 +       /* next interval? */
24019 +       if (!sched_pc->fill_rate[1])
24020 +               delta_min[1] = HZ;
24021 +       else if (tokens > sched_pc->fill_rate[1])
24022 +               delta_min[1] += sched_pc->interval[1] *
24023 +                       tokens / sched_pc->fill_rate[1];
24024 +       else
24025 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24026 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24027 +
24028 +       return -2;
24029 +#else
24030 +       return -1;
24031 +#endif /* CONFIG_VSERVER_IDLETIME */
24032 +#else
24033 +       return 0;
24034 +#endif /* CONFIG_VSERVER_HARDCPU */
24035 +}
24036 +
24037 +static inline unsigned long msec_to_ticks(unsigned long msec)
24038 +{
24039 +       return msecs_to_jiffies(msec);
24040 +}
24041 +
24042 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24043 +{
24044 +       return jiffies_to_msecs(ticks);
24045 +}
24046 +
24047 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24048 +{
24049 +       return jiffies_to_usecs(ticks);
24050 +}
24051 +
24052 +
24053 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24054 +{
24055 +       unsigned int set_mask = data->mask;
24056 +       unsigned int update_mask;
24057 +       int i, cpu;
24058 +
24059 +       /* Sanity check data values */
24060 +       if (data->tokens_max <= 0)
24061 +               data->tokens_max = HZ;
24062 +       if (data->tokens_min < 0)
24063 +               data->tokens_min = HZ / 3;
24064 +       if (data->tokens_min >= data->tokens_max)
24065 +               data->tokens_min = data->tokens_max;
24066 +
24067 +       if (data->prio_bias > MAX_PRIO_BIAS)
24068 +               data->prio_bias = MAX_PRIO_BIAS;
24069 +       if (data->prio_bias < MIN_PRIO_BIAS)
24070 +               data->prio_bias = MIN_PRIO_BIAS;
24071 +
24072 +       spin_lock(&vxi->sched.tokens_lock);
24073 +
24074 +       /* sync up on delayed updates */
24075 +       for_each_cpu_mask(cpu, vxi->sched.update)
24076 +               vx_update_sched_param(&vxi->sched,
24077 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24078 +
24079 +       if (set_mask & VXSM_FILL_RATE)
24080 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24081 +       if (set_mask & VXSM_FILL_RATE2)
24082 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24083 +       if (set_mask & VXSM_INTERVAL)
24084 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24085 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24086 +       if (set_mask & VXSM_INTERVAL2)
24087 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24088 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24089 +       if (set_mask & VXSM_TOKENS)
24090 +               vxi->sched.tokens = data->tokens;
24091 +       if (set_mask & VXSM_TOKENS_MIN)
24092 +               vxi->sched.tokens_min = data->tokens_min;
24093 +       if (set_mask & VXSM_TOKENS_MAX)
24094 +               vxi->sched.tokens_max = data->tokens_max;
24095 +       if (set_mask & VXSM_PRIO_BIAS)
24096 +               vxi->sched.prio_bias = data->prio_bias;
24097 +
24098 +       /* Sanity check rate/interval */
24099 +       for (i = 0; i < 2; i++) {
24100 +               if (data->fill_rate[i] < 0)
24101 +                       data->fill_rate[i] = 0;
24102 +               if (data->interval[i] <= 0)
24103 +                       data->interval[i] = HZ;
24104 +       }
24105 +
24106 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24107 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24108 +       vxi->sched.update_mask = update_mask;
24109 +
24110 +#ifdef CONFIG_SMP
24111 +       rmb();
24112 +       if (set_mask & VXSM_CPU_ID) {
24113 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24114 +               cpus_and(vxi->sched.update, cpu_online_map,
24115 +                       vxi->sched.update);
24116 +       } else
24117 +               vxi->sched.update = cpu_online_map;
24118 +
24119 +       /* forced reload? */
24120 +       if (set_mask & VXSM_FORCE) {
24121 +               for_each_cpu_mask(cpu, vxi->sched.update)
24122 +                       vx_update_sched_param(&vxi->sched,
24123 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24124 +               vxi->sched.update = CPU_MASK_NONE;
24125 +       }
24126 +#else
24127 +       /* on UP we update immediately */
24128 +       vx_update_sched_param(&vxi->sched,
24129 +               &vx_per_cpu(vxi, sched_pc, 0));
24130 +#endif
24131 +
24132 +       spin_unlock(&vxi->sched.tokens_lock);
24133 +       return 0;
24134 +}
24135 +
24136 +
24137 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24138 +#define COPY_PRI(C) C(prio_bias)
24139 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24140 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24141 +                   C(fill_rate[1]); C(interval[1]);
24142 +
24143 +#define COPY_VALUE(name) vc_data.name = data->name
24144 +
24145 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24146 +{
24147 +       struct vcmd_sched_v5 vc_data;
24148 +
24149 +       vc_data.mask = data->set_mask;
24150 +       COPY_IDS(COPY_VALUE);
24151 +       COPY_PRI(COPY_VALUE);
24152 +       COPY_TOK(COPY_VALUE);
24153 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24154 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24155 +       return do_set_sched(vxi, &vc_data);
24156 +}
24157 +
24158 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24159 +{
24160 +       struct vcmd_set_sched_v4 vc_data;
24161 +
24162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24163 +               return -EFAULT;
24164 +
24165 +       return do_set_sched_v4(vxi, &vc_data);
24166 +}
24167 +
24168 +       /* latest interface is v5 */
24169 +
24170 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24171 +{
24172 +       struct vcmd_sched_v5 vc_data;
24173 +
24174 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24175 +               return -EFAULT;
24176 +
24177 +       return do_set_sched(vxi, &vc_data);
24178 +}
24179 +
24180 +
24181 +#define COPY_PRI(C) C(prio_bias)
24182 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24183 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24184 +                   C(fill_rate[1]); C(interval[1]);
24185 +
24186 +#define COPY_VALUE(name) vc_data.name = data->name
24187 +
24188 +
24189 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24190 +{
24191 +       struct vcmd_sched_v5 vc_data;
24192 +
24193 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24194 +               return -EFAULT;
24195 +
24196 +       if (vc_data.mask & VXSM_CPU_ID) {
24197 +               int cpu = vc_data.cpu_id;
24198 +               struct _vx_sched_pc *data;
24199 +
24200 +               if (!cpu_possible(cpu))
24201 +                       return -EINVAL;
24202 +
24203 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24204 +               COPY_TOK(COPY_VALUE);
24205 +               COPY_PRI(COPY_VALUE);
24206 +               COPY_FRI(COPY_VALUE);
24207 +
24208 +               if (data->flags & VXSF_IDLE_TIME)
24209 +                       vc_data.mask |= VXSM_IDLE_TIME;
24210 +       } else {
24211 +               struct _vx_sched *data = &vxi->sched;
24212 +
24213 +               COPY_TOK(COPY_VALUE);
24214 +               COPY_PRI(COPY_VALUE);
24215 +               COPY_FRI(COPY_VALUE);
24216 +       }
24217 +
24218 +       if (vc_data.mask & VXSM_MSEC) {
24219 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24220 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24221 +       }
24222 +
24223 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24224 +               return -EFAULT;
24225 +       return 0;
24226 +}
24227 +
24228 +
24229 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24230 +{
24231 +       struct vcmd_sched_info vc_data;
24232 +       int cpu;
24233 +
24234 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24235 +               return -EFAULT;
24236 +
24237 +       cpu = vc_data.cpu_id;
24238 +       if (!cpu_possible(cpu))
24239 +               return -EINVAL;
24240 +
24241 +       if (vxi) {
24242 +               struct _vx_sched_pc *sched_pc =
24243 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24244 +
24245 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24246 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24247 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24248 +               vc_data.vavavoom = sched_pc->vavavoom;
24249 +       }
24250 +       vc_data.token_usec = ticks_to_usec(1);
24251 +
24252 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24253 +               return -EFAULT;
24254 +       return 0;
24255 +}
24256 +
24257 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/sched_init.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sched_init.h
24258 --- linux-2.6.27.10/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
24259 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sched_init.h    2008-10-13 14:54:20.000000000 +0200
24260 @@ -0,0 +1,50 @@
24261 +
24262 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24263 +{
24264 +       static struct lock_class_key tokens_lock_key;
24265 +
24266 +       /* scheduling; hard code starting values as constants */
24267 +       sched->fill_rate[0]     = 1;
24268 +       sched->interval[0]      = 4;
24269 +       sched->fill_rate[1]     = 1;
24270 +       sched->interval[1]      = 8;
24271 +       sched->tokens           = HZ >> 2;
24272 +       sched->tokens_min       = HZ >> 4;
24273 +       sched->tokens_max       = HZ >> 1;
24274 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24275 +       sched->prio_bias        = 0;
24276 +
24277 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24278 +}
24279 +
24280 +static inline
24281 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24282 +{
24283 +       sched_pc->fill_rate[0]  = 1;
24284 +       sched_pc->interval[0]   = 4;
24285 +       sched_pc->fill_rate[1]  = 1;
24286 +       sched_pc->interval[1]   = 8;
24287 +       sched_pc->tokens        = HZ >> 2;
24288 +       sched_pc->tokens_min    = HZ >> 4;
24289 +       sched_pc->tokens_max    = HZ >> 1;
24290 +       sched_pc->prio_bias     = 0;
24291 +       sched_pc->vavavoom      = 0;
24292 +       sched_pc->token_time    = 0;
24293 +       sched_pc->idle_time     = 0;
24294 +       sched_pc->norm_time     = jiffies;
24295 +
24296 +       sched_pc->user_ticks = 0;
24297 +       sched_pc->sys_ticks = 0;
24298 +       sched_pc->hold_ticks = 0;
24299 +}
24300 +
24301 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24302 +{
24303 +       return;
24304 +}
24305 +
24306 +static inline
24307 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24308 +{
24309 +       return;
24310 +}
24311 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/sched_proc.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sched_proc.h
24312 --- linux-2.6.27.10/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
24313 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sched_proc.h    2008-10-13 14:54:20.000000000 +0200
24314 @@ -0,0 +1,57 @@
24315 +#ifndef _VX_SCHED_PROC_H
24316 +#define _VX_SCHED_PROC_H
24317 +
24318 +
24319 +static inline
24320 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24321 +{
24322 +       int length = 0;
24323 +
24324 +       length += sprintf(buffer,
24325 +               "FillRate:\t%8d,%d\n"
24326 +               "Interval:\t%8d,%d\n"
24327 +               "TokensMin:\t%8d\n"
24328 +               "TokensMax:\t%8d\n"
24329 +               "PrioBias:\t%8d\n",
24330 +               sched->fill_rate[0],
24331 +               sched->fill_rate[1],
24332 +               sched->interval[0],
24333 +               sched->interval[1],
24334 +               sched->tokens_min,
24335 +               sched->tokens_max,
24336 +               sched->prio_bias);
24337 +       return length;
24338 +}
24339 +
24340 +static inline
24341 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24342 +       char *buffer, int cpu)
24343 +{
24344 +       int length = 0;
24345 +
24346 +       length += sprintf(buffer + length,
24347 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24348 +               (unsigned long long)sched_pc->user_ticks,
24349 +               (unsigned long long)sched_pc->sys_ticks,
24350 +               (unsigned long long)sched_pc->hold_ticks,
24351 +               sched_pc->token_time,
24352 +               sched_pc->idle_time);
24353 +       length += sprintf(buffer + length,
24354 +               " %c%c %d %d %d %d/%d %d/%d",
24355 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24356 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24357 +               sched_pc->tokens,
24358 +               sched_pc->tokens_min,
24359 +               sched_pc->tokens_max,
24360 +               sched_pc->fill_rate[0],
24361 +               sched_pc->interval[0],
24362 +               sched_pc->fill_rate[1],
24363 +               sched_pc->interval[1]);
24364 +       length += sprintf(buffer + length,
24365 +               " %d %d\n",
24366 +               sched_pc->prio_bias,
24367 +               sched_pc->vavavoom);
24368 +       return length;
24369 +}
24370 +
24371 +#endif /* _VX_SCHED_PROC_H */
24372 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/signal.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/signal.c
24373 --- linux-2.6.27.10/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
24374 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/signal.c        2008-10-13 14:54:20.000000000 +0200
24375 @@ -0,0 +1,132 @@
24376 +/*
24377 + *  linux/kernel/vserver/signal.c
24378 + *
24379 + *  Virtual Server: Signal Support
24380 + *
24381 + *  Copyright (C) 2003-2007  Herbert Pötzl
24382 + *
24383 + *  V0.01  broken out from vcontext V0.05
24384 + *  V0.02  changed vcmds to vxi arg
24385 + *  V0.03  adjusted siginfo for kill
24386 + *
24387 + */
24388 +
24389 +#include <asm/uaccess.h>
24390 +
24391 +#include <linux/vs_context.h>
24392 +#include <linux/vs_pid.h>
24393 +#include <linux/vserver/signal_cmd.h>
24394 +
24395 +
24396 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24397 +{
24398 +       int retval, count = 0;
24399 +       struct task_struct *p;
24400 +       struct siginfo *sip = SEND_SIG_PRIV;
24401 +
24402 +       retval = -ESRCH;
24403 +       vxdprintk(VXD_CBIT(misc, 4),
24404 +               "vx_info_kill(%p[#%d],%d,%d)*",
24405 +               vxi, vxi->vx_id, pid, sig);
24406 +       read_lock(&tasklist_lock);
24407 +       switch (pid) {
24408 +       case  0:
24409 +       case -1:
24410 +               for_each_process(p) {
24411 +                       int err = 0;
24412 +
24413 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24414 +                               (pid && vxi->vx_initpid == p->pid))
24415 +                               continue;
24416 +
24417 +                       err = group_send_sig_info(sig, sip, p);
24418 +                       ++count;
24419 +                       if (err != -EPERM)
24420 +                               retval = err;
24421 +               }
24422 +               break;
24423 +
24424 +       case 1:
24425 +               if (vxi->vx_initpid) {
24426 +                       pid = vxi->vx_initpid;
24427 +                       /* for now, only SIGINT to private init ... */
24428 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24429 +                               /* ... as long as there are tasks left */
24430 +                               (atomic_read(&vxi->vx_tasks) > 1))
24431 +                               sig = SIGINT;
24432 +               }
24433 +               /* fallthrough */
24434 +       default:
24435 +               p = find_task_by_real_pid(pid);
24436 +               if (p) {
24437 +                       if (vx_task_xid(p) == vxi->vx_id)
24438 +                               retval = group_send_sig_info(sig, sip, p);
24439 +               }
24440 +               break;
24441 +       }
24442 +       read_unlock(&tasklist_lock);
24443 +       vxdprintk(VXD_CBIT(misc, 4),
24444 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24445 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24446 +       return retval;
24447 +}
24448 +
24449 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24450 +{
24451 +       struct vcmd_ctx_kill_v0 vc_data;
24452 +
24453 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24454 +               return -EFAULT;
24455 +
24456 +       /* special check to allow guest shutdown */
24457 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24458 +               /* forbid killall pid=0 when init is present */
24459 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24460 +               (vc_data.pid > 1)))
24461 +               return -EACCES;
24462 +
24463 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24464 +}
24465 +
24466 +
24467 +static int __wait_exit(struct vx_info *vxi)
24468 +{
24469 +       DECLARE_WAITQUEUE(wait, current);
24470 +       int ret = 0;
24471 +
24472 +       add_wait_queue(&vxi->vx_wait, &wait);
24473 +       set_current_state(TASK_INTERRUPTIBLE);
24474 +
24475 +wait:
24476 +       if (vx_info_state(vxi,
24477 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24478 +               goto out;
24479 +       if (signal_pending(current)) {
24480 +               ret = -ERESTARTSYS;
24481 +               goto out;
24482 +       }
24483 +       schedule();
24484 +       goto wait;
24485 +
24486 +out:
24487 +       set_current_state(TASK_RUNNING);
24488 +       remove_wait_queue(&vxi->vx_wait, &wait);
24489 +       return ret;
24490 +}
24491 +
24492 +
24493 +
24494 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24495 +{
24496 +       struct vcmd_wait_exit_v0 vc_data;
24497 +       int ret;
24498 +
24499 +       ret = __wait_exit(vxi);
24500 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24501 +       vc_data.exit_code = vxi->exit_code;
24502 +
24503 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24504 +               ret = -EFAULT;
24505 +       return ret;
24506 +}
24507 +
24508 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/space.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/space.c
24509 --- linux-2.6.27.10/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
24510 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/space.c 2008-10-31 18:15:28.000000000 +0100
24511 @@ -0,0 +1,398 @@
24512 +/*
24513 + *  linux/kernel/vserver/space.c
24514 + *
24515 + *  Virtual Server: Context Space Support
24516 + *
24517 + *  Copyright (C) 2003-2007  Herbert Pötzl
24518 + *
24519 + *  V0.01  broken out from context.c 0.07
24520 + *  V0.02  added task locking for namespace
24521 + *  V0.03  broken out vx_enter_namespace
24522 + *  V0.04  added *space support and commands
24523 + *
24524 + */
24525 +
24526 +#include <linux/utsname.h>
24527 +#include <linux/nsproxy.h>
24528 +#include <linux/err.h>
24529 +#include <asm/uaccess.h>
24530 +
24531 +#include <linux/vs_context.h>
24532 +#include <linux/vserver/space.h>
24533 +#include <linux/vserver/space_cmd.h>
24534 +
24535 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24536 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24537 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24538 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24539 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24540 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24541 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24542 +
24543 +
24544 +/* namespace functions */
24545 +
24546 +#include <linux/mnt_namespace.h>
24547 +#include <linux/user_namespace.h>
24548 +#include <linux/pid_namespace.h>
24549 +#include <linux/ipc_namespace.h>
24550 +#include <net/net_namespace.h>
24551 +
24552 +
24553 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24554 +       .mask = CLONE_FS |
24555 +               CLONE_NEWNS |
24556 +               CLONE_NEWUTS |
24557 +               CLONE_NEWIPC |
24558 +               CLONE_NEWUSER |
24559 +               0
24560 +};
24561 +
24562 +static const struct vcmd_space_mask_v1 space_mask = {
24563 +       .mask = CLONE_FS |
24564 +               CLONE_NEWNS |
24565 +               CLONE_NEWUTS |
24566 +               CLONE_NEWIPC |
24567 +               CLONE_NEWUSER |
24568 +#ifdef CONFIG_PID_NS
24569 +               CLONE_NEWPID |
24570 +#endif
24571 +#ifdef CONFIG_NET_NS
24572 +               CLONE_NEWNET |
24573 +#endif
24574 +               0
24575 +};
24576 +
24577 +static const struct vcmd_space_mask_v1 default_space_mask = {
24578 +       .mask = CLONE_FS |
24579 +               CLONE_NEWNS |
24580 +               CLONE_NEWUTS |
24581 +               CLONE_NEWIPC |
24582 +               CLONE_NEWUSER |
24583 +#ifdef CONFIG_PID_NS
24584 +//             CLONE_NEWPID |
24585 +#endif
24586 +               0
24587 +};
24588 +
24589 +/*
24590 + *     build a new nsproxy mix
24591 + *      assumes that both proxies are 'const'
24592 + *     does not touch nsproxy refcounts
24593 + *     will hold a reference on the result.
24594 + */
24595 +
24596 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24597 +       struct nsproxy *new_nsproxy, unsigned long mask)
24598 +{
24599 +       struct mnt_namespace *old_ns;
24600 +       struct uts_namespace *old_uts;
24601 +       struct ipc_namespace *old_ipc;
24602 +       struct user_namespace *old_user;
24603 +#ifdef CONFIG_PID_NS
24604 +       struct pid_namespace *old_pid;
24605 +#endif
24606 +#ifdef CONFIG_NET_NS
24607 +       struct net *old_net;
24608 +#endif
24609 +       struct nsproxy *nsproxy;
24610 +
24611 +       nsproxy = copy_nsproxy(old_nsproxy);
24612 +       if (!nsproxy)
24613 +               goto out;
24614 +
24615 +       if (mask & CLONE_NEWNS) {
24616 +               old_ns = nsproxy->mnt_ns;
24617 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24618 +               if (nsproxy->mnt_ns)
24619 +                       get_mnt_ns(nsproxy->mnt_ns);
24620 +       } else
24621 +               old_ns = NULL;
24622 +
24623 +       if (mask & CLONE_NEWUTS) {
24624 +               old_uts = nsproxy->uts_ns;
24625 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24626 +               if (nsproxy->uts_ns)
24627 +                       get_uts_ns(nsproxy->uts_ns);
24628 +       } else
24629 +               old_uts = NULL;
24630 +
24631 +       if (mask & CLONE_NEWIPC) {
24632 +               old_ipc = nsproxy->ipc_ns;
24633 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24634 +               if (nsproxy->ipc_ns)
24635 +                       get_ipc_ns(nsproxy->ipc_ns);
24636 +       } else
24637 +               old_ipc = NULL;
24638 +
24639 +       if (mask & CLONE_NEWUSER) {
24640 +               old_user = nsproxy->user_ns;
24641 +               nsproxy->user_ns = new_nsproxy->user_ns;
24642 +               if (nsproxy->user_ns)
24643 +                       get_user_ns(nsproxy->user_ns);
24644 +       } else
24645 +               old_user = NULL;
24646 +
24647 +#ifdef CONFIG_PID_NS
24648 +       if (mask & CLONE_NEWPID) {
24649 +               old_pid = nsproxy->pid_ns;
24650 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24651 +               if (nsproxy->pid_ns)
24652 +                       get_pid_ns(nsproxy->pid_ns);
24653 +       } else
24654 +               old_pid = NULL;
24655 +#endif
24656 +#ifdef CONFIG_NET_NS
24657 +       if (mask & CLONE_NEWNET) {
24658 +               old_net = nsproxy->net_ns;
24659 +               nsproxy->net_ns = new_nsproxy->net_ns;
24660 +               if (nsproxy->net_ns)
24661 +                       get_net(nsproxy->net_ns);
24662 +       } else
24663 +               old_net = NULL;
24664 +#endif
24665 +       if (old_ns)
24666 +               put_mnt_ns(old_ns);
24667 +       if (old_uts)
24668 +               put_uts_ns(old_uts);
24669 +       if (old_ipc)
24670 +               put_ipc_ns(old_ipc);
24671 +       if (old_user)
24672 +               put_user_ns(old_user);
24673 +#ifdef CONFIG_PID_NS
24674 +       if (old_pid)
24675 +               put_pid_ns(old_pid);
24676 +#endif
24677 +#ifdef CONFIG_NET_NS
24678 +       if (old_net)
24679 +               put_net(old_net);
24680 +#endif
24681 +out:
24682 +       return nsproxy;
24683 +}
24684 +
24685 +
24686 +/*
24687 + *     merge two nsproxy structs into a new one.
24688 + *     will hold a reference on the result.
24689 + */
24690 +
24691 +static inline
24692 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24693 +       struct nsproxy *proxy, unsigned long mask)
24694 +{
24695 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24696 +
24697 +       if (!proxy)
24698 +               return NULL;
24699 +
24700 +       if (mask) {
24701 +               /* vs_mix_nsproxy returns with reference */
24702 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24703 +                       proxy, mask);
24704 +       }
24705 +       get_nsproxy(proxy);
24706 +       return proxy;
24707 +}
24708 +
24709 +/*
24710 + *     merge two fs structs into a new one.
24711 + *     will take a reference on the result.
24712 + */
24713 +
24714 +static inline
24715 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
24716 +       struct fs_struct *fs, unsigned long mask)
24717 +{
24718 +       if (!(mask & CLONE_FS)) {
24719 +               if (old)
24720 +                       atomic_inc(&old->count);
24721 +               return old;
24722 +       }
24723 +
24724 +       if (!fs)
24725 +               return NULL;
24726 +
24727 +       return copy_fs_struct(fs);
24728 +}
24729 +
24730 +
24731 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24732 +{
24733 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24734 +       struct fs_struct *fs, *fs_cur, *fs_new;
24735 +       int ret;
24736 +
24737 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24738 +               vxi, vxi->vx_id, mask, index);
24739 +
24740 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24741 +               return -EACCES;
24742 +
24743 +       if (!mask)
24744 +               mask = vxi->vx_nsmask[index];
24745 +
24746 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24747 +               return -EINVAL;
24748 +
24749 +       proxy = vxi->vx_nsproxy[index];
24750 +       fs = vxi->vx_fs[index];
24751 +
24752 +       task_lock(current);
24753 +       fs_cur = current->fs;
24754 +       atomic_inc(&fs_cur->count);
24755 +       proxy_cur = current->nsproxy;
24756 +       get_nsproxy(proxy_cur);
24757 +       task_unlock(current);
24758 +
24759 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
24760 +       if (IS_ERR(fs_new)) {
24761 +               ret = PTR_ERR(fs_new);
24762 +               goto out_put;
24763 +       }
24764 +
24765 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24766 +       if (IS_ERR(proxy_new)) {
24767 +               ret = PTR_ERR(proxy_new);
24768 +               goto out_put_fs;
24769 +       }
24770 +
24771 +       fs_new = xchg(&current->fs, fs_new);
24772 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24773 +       ret = 0;
24774 +
24775 +       if (proxy_new)
24776 +               put_nsproxy(proxy_new);
24777 +out_put_fs:
24778 +       if (fs_new)
24779 +               put_fs_struct(fs_new);
24780 +out_put:
24781 +       if (proxy_cur)
24782 +               put_nsproxy(proxy_cur);
24783 +       if (fs_cur)
24784 +               put_fs_struct(fs_cur);
24785 +       return ret;
24786 +}
24787 +
24788 +
24789 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24790 +{
24791 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24792 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
24793 +       int ret;
24794 +
24795 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24796 +               vxi, vxi->vx_id, mask, index);
24797 +#if 0
24798 +       if (!mask)
24799 +               mask = default_space_mask.mask;
24800 +#endif
24801 +       if ((mask & space_mask.mask) != mask)
24802 +               return -EINVAL;
24803 +
24804 +       proxy_vxi = vxi->vx_nsproxy[index];
24805 +       fs_vxi = vxi->vx_fs[index];
24806 +
24807 +       task_lock(current);
24808 +       fs_cur = current->fs;
24809 +       atomic_inc(&fs_cur->count);
24810 +       proxy_cur = current->nsproxy;
24811 +       get_nsproxy(proxy_cur);
24812 +       task_unlock(current);
24813 +
24814 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
24815 +       if (IS_ERR(fs_new)) {
24816 +               ret = PTR_ERR(fs_new);
24817 +               goto out_put;
24818 +       }
24819 +
24820 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24821 +       if (IS_ERR(proxy_new)) {
24822 +               ret = PTR_ERR(proxy_new);
24823 +               goto out_put_fs;
24824 +       }
24825 +
24826 +       fs_new = xchg(&vxi->vx_fs[index], fs_new);
24827 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24828 +       vxi->vx_nsmask[index] |= mask;
24829 +       ret = 0;
24830 +
24831 +       if (proxy_new)
24832 +               put_nsproxy(proxy_new);
24833 +out_put_fs:
24834 +       if (fs_new)
24835 +               put_fs_struct(fs_new);
24836 +out_put:
24837 +       if (proxy_cur)
24838 +               put_nsproxy(proxy_cur);
24839 +       if (fs_cur)
24840 +               put_fs_struct(fs_cur);
24841 +       return ret;
24842 +}
24843 +
24844 +
24845 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24846 +{
24847 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24848 +
24849 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24850 +               return -EFAULT;
24851 +
24852 +       return vx_enter_space(vxi, vc_data.mask, 0);
24853 +}
24854 +
24855 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24856 +{
24857 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24858 +
24859 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24860 +               return -EFAULT;
24861 +
24862 +       if (vc_data.index >= VX_SPACES)
24863 +               return -EINVAL;
24864 +
24865 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24866 +}
24867 +
24868 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24869 +{
24870 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24871 +
24872 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24873 +               return -EFAULT;
24874 +
24875 +       return vx_set_space(vxi, vc_data.mask, 0);
24876 +}
24877 +
24878 +int vc_set_space(struct vx_info *vxi, void __user *data)
24879 +{
24880 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24881 +
24882 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24883 +               return -EFAULT;
24884 +
24885 +       if (vc_data.index >= VX_SPACES)
24886 +               return -EINVAL;
24887 +
24888 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24889 +}
24890 +
24891 +int vc_get_space_mask(void __user *data, int type)
24892 +{
24893 +       const struct vcmd_space_mask_v1 *mask;
24894 +
24895 +       if (type == 0)
24896 +               mask = &space_mask_v0;
24897 +       else if (type == 1)
24898 +               mask = &space_mask;
24899 +       else
24900 +               mask = &default_space_mask;
24901 +
24902 +       vxdprintk(VXD_CBIT(space, 10),
24903 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24904 +
24905 +       if (copy_to_user(data, mask, sizeof(*mask)))
24906 +               return -EFAULT;
24907 +       return 0;
24908 +}
24909 +
24910 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/switch.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/switch.c
24911 --- linux-2.6.27.10/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
24912 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/switch.c        2008-10-31 04:42:36.000000000 +0100
24913 @@ -0,0 +1,543 @@
24914 +/*
24915 + *  linux/kernel/vserver/switch.c
24916 + *
24917 + *  Virtual Server: Syscall Switch
24918 + *
24919 + *  Copyright (C) 2003-2007  Herbert Pötzl
24920 + *
24921 + *  V0.01  syscall switch
24922 + *  V0.02  added signal to context
24923 + *  V0.03  added rlimit functions
24924 + *  V0.04  added iattr, task/xid functions
24925 + *  V0.05  added debug/history stuff
24926 + *  V0.06  added compat32 layer
24927 + *  V0.07  vcmd args and perms
24928 + *  V0.08  added status commands
24929 + *  V0.09  added tag commands
24930 + *  V0.10  added oom bias
24931 + *  V0.11  added device commands
24932 + *
24933 + */
24934 +
24935 +#include <linux/vs_context.h>
24936 +#include <linux/vs_network.h>
24937 +#include <linux/vserver/switch.h>
24938 +
24939 +#include "vci_config.h"
24940 +
24941 +
24942 +static inline
24943 +int vc_get_version(uint32_t id)
24944 +{
24945 +       return VCI_VERSION;
24946 +}
24947 +
24948 +static inline
24949 +int vc_get_vci(uint32_t id)
24950 +{
24951 +       return vci_kernel_config();
24952 +}
24953 +
24954 +#include <linux/vserver/context_cmd.h>
24955 +#include <linux/vserver/cvirt_cmd.h>
24956 +#include <linux/vserver/cacct_cmd.h>
24957 +#include <linux/vserver/limit_cmd.h>
24958 +#include <linux/vserver/network_cmd.h>
24959 +#include <linux/vserver/sched_cmd.h>
24960 +#include <linux/vserver/debug_cmd.h>
24961 +#include <linux/vserver/inode_cmd.h>
24962 +#include <linux/vserver/dlimit_cmd.h>
24963 +#include <linux/vserver/signal_cmd.h>
24964 +#include <linux/vserver/space_cmd.h>
24965 +#include <linux/vserver/tag_cmd.h>
24966 +#include <linux/vserver/device_cmd.h>
24967 +
24968 +#include <linux/vserver/inode.h>
24969 +#include <linux/vserver/dlimit.h>
24970 +
24971 +
24972 +#ifdef CONFIG_COMPAT
24973 +#define __COMPAT(name, id, data, compat)       \
24974 +       (compat) ? name ## _x32(id, data) : name(id, data)
24975 +#define __COMPAT_NO_ID(name, data, compat)     \
24976 +       (compat) ? name ## _x32(data) : name(data)
24977 +#else
24978 +#define __COMPAT(name, id, data, compat)       \
24979 +       name(id, data)
24980 +#define __COMPAT_NO_ID(name, data, compat)     \
24981 +       name(data)
24982 +#endif
24983 +
24984 +
24985 +static inline
24986 +long do_vcmd(uint32_t cmd, uint32_t id,
24987 +       struct vx_info *vxi, struct nx_info *nxi,
24988 +       void __user *data, int compat)
24989 +{
24990 +       switch (cmd) {
24991 +
24992 +       case VCMD_get_version:
24993 +               return vc_get_version(id);
24994 +       case VCMD_get_vci:
24995 +               return vc_get_vci(id);
24996 +
24997 +       case VCMD_task_xid:
24998 +               return vc_task_xid(id);
24999 +       case VCMD_vx_info:
25000 +               return vc_vx_info(vxi, data);
25001 +
25002 +       case VCMD_task_nid:
25003 +               return vc_task_nid(id);
25004 +       case VCMD_nx_info:
25005 +               return vc_nx_info(nxi, data);
25006 +
25007 +       case VCMD_task_tag:
25008 +               return vc_task_tag(id);
25009 +
25010 +       case VCMD_set_space_v1:
25011 +               return vc_set_space_v1(vxi, data);
25012 +       /* this is version 2 */
25013 +       case VCMD_set_space:
25014 +               return vc_set_space(vxi, data);
25015 +
25016 +       case VCMD_get_space_mask_v0:
25017 +               return vc_get_space_mask(data, 0);
25018 +       /* this is version 1 */
25019 +       case VCMD_get_space_mask:
25020 +               return vc_get_space_mask(data, 1);
25021 +
25022 +       case VCMD_get_space_default:
25023 +               return vc_get_space_mask(data, -1);
25024 +
25025 +#ifdef CONFIG_IA32_EMULATION
25026 +       case VCMD_get_rlimit:
25027 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25028 +       case VCMD_set_rlimit:
25029 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25030 +#else
25031 +       case VCMD_get_rlimit:
25032 +               return vc_get_rlimit(vxi, data);
25033 +       case VCMD_set_rlimit:
25034 +               return vc_set_rlimit(vxi, data);
25035 +#endif
25036 +       case VCMD_get_rlimit_mask:
25037 +               return vc_get_rlimit_mask(id, data);
25038 +       case VCMD_reset_minmax:
25039 +               return vc_reset_minmax(vxi, data);
25040 +
25041 +       case VCMD_get_vhi_name:
25042 +               return vc_get_vhi_name(vxi, data);
25043 +       case VCMD_set_vhi_name:
25044 +               return vc_set_vhi_name(vxi, data);
25045 +
25046 +       case VCMD_ctx_stat:
25047 +               return vc_ctx_stat(vxi, data);
25048 +       case VCMD_virt_stat:
25049 +               return vc_virt_stat(vxi, data);
25050 +       case VCMD_sock_stat:
25051 +               return vc_sock_stat(vxi, data);
25052 +       case VCMD_rlimit_stat:
25053 +               return vc_rlimit_stat(vxi, data);
25054 +
25055 +       case VCMD_set_cflags:
25056 +               return vc_set_cflags(vxi, data);
25057 +       case VCMD_get_cflags:
25058 +               return vc_get_cflags(vxi, data);
25059 +
25060 +       /* this is version 1 */
25061 +       case VCMD_set_ccaps:
25062 +               return vc_set_ccaps(vxi, data);
25063 +       /* this is version 1 */
25064 +       case VCMD_get_ccaps:
25065 +               return vc_get_ccaps(vxi, data);
25066 +       case VCMD_set_bcaps:
25067 +               return vc_set_bcaps(vxi, data);
25068 +       case VCMD_get_bcaps:
25069 +               return vc_get_bcaps(vxi, data);
25070 +
25071 +       case VCMD_set_badness:
25072 +               return vc_set_badness(vxi, data);
25073 +       case VCMD_get_badness:
25074 +               return vc_get_badness(vxi, data);
25075 +
25076 +       case VCMD_set_nflags:
25077 +               return vc_set_nflags(nxi, data);
25078 +       case VCMD_get_nflags:
25079 +               return vc_get_nflags(nxi, data);
25080 +
25081 +       case VCMD_set_ncaps:
25082 +               return vc_set_ncaps(nxi, data);
25083 +       case VCMD_get_ncaps:
25084 +               return vc_get_ncaps(nxi, data);
25085 +
25086 +       case VCMD_set_sched_v4:
25087 +               return vc_set_sched_v4(vxi, data);
25088 +       /* this is version 5 */
25089 +       case VCMD_set_sched:
25090 +               return vc_set_sched(vxi, data);
25091 +       case VCMD_get_sched:
25092 +               return vc_get_sched(vxi, data);
25093 +       case VCMD_sched_info:
25094 +               return vc_sched_info(vxi, data);
25095 +
25096 +       case VCMD_add_dlimit:
25097 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25098 +       case VCMD_rem_dlimit:
25099 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25100 +       case VCMD_set_dlimit:
25101 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25102 +       case VCMD_get_dlimit:
25103 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25104 +
25105 +       case VCMD_ctx_kill:
25106 +               return vc_ctx_kill(vxi, data);
25107 +
25108 +       case VCMD_wait_exit:
25109 +               return vc_wait_exit(vxi, data);
25110 +
25111 +       case VCMD_get_iattr:
25112 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25113 +       case VCMD_set_iattr:
25114 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25115 +
25116 +       case VCMD_fget_iattr:
25117 +               return vc_fget_iattr(id, data);
25118 +       case VCMD_fset_iattr:
25119 +               return vc_fset_iattr(id, data);
25120 +
25121 +       case VCMD_enter_space_v0:
25122 +               return vc_enter_space_v1(vxi, NULL);
25123 +       case VCMD_enter_space_v1:
25124 +               return vc_enter_space_v1(vxi, data);
25125 +       /* this is version 2 */
25126 +       case VCMD_enter_space:
25127 +               return vc_enter_space(vxi, data);
25128 +
25129 +       case VCMD_ctx_create_v0:
25130 +               return vc_ctx_create(id, NULL);
25131 +       case VCMD_ctx_create:
25132 +               return vc_ctx_create(id, data);
25133 +       case VCMD_ctx_migrate_v0:
25134 +               return vc_ctx_migrate(vxi, NULL);
25135 +       case VCMD_ctx_migrate:
25136 +               return vc_ctx_migrate(vxi, data);
25137 +
25138 +       case VCMD_net_create_v0:
25139 +               return vc_net_create(id, NULL);
25140 +       case VCMD_net_create:
25141 +               return vc_net_create(id, data);
25142 +       case VCMD_net_migrate:
25143 +               return vc_net_migrate(nxi, data);
25144 +
25145 +       case VCMD_tag_migrate:
25146 +               return vc_tag_migrate(id);
25147 +
25148 +       case VCMD_net_add:
25149 +               return vc_net_add(nxi, data);
25150 +       case VCMD_net_remove:
25151 +               return vc_net_remove(nxi, data);
25152 +
25153 +       case VCMD_net_add_ipv4:
25154 +               return vc_net_add_ipv4(nxi, data);
25155 +       case VCMD_net_remove_ipv4:
25156 +               return vc_net_remove_ipv4(nxi, data);
25157 +#ifdef CONFIG_IPV6
25158 +       case VCMD_net_add_ipv6:
25159 +               return vc_net_add_ipv6(nxi, data);
25160 +       case VCMD_net_remove_ipv6:
25161 +               return vc_net_remove_ipv6(nxi, data);
25162 +#endif
25163 +/*     case VCMD_add_match_ipv4:
25164 +               return vc_add_match_ipv4(nxi, data);
25165 +       case VCMD_get_match_ipv4:
25166 +               return vc_get_match_ipv4(nxi, data);
25167 +#ifdef CONFIG_IPV6
25168 +       case VCMD_add_match_ipv6:
25169 +               return vc_add_match_ipv6(nxi, data);
25170 +       case VCMD_get_match_ipv6:
25171 +               return vc_get_match_ipv6(nxi, data);
25172 +#endif */
25173 +
25174 +#ifdef CONFIG_VSERVER_DEVICE
25175 +       case VCMD_set_mapping:
25176 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25177 +       case VCMD_unset_mapping:
25178 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25179 +#endif
25180 +#ifdef CONFIG_VSERVER_HISTORY
25181 +       case VCMD_dump_history:
25182 +               return vc_dump_history(id);
25183 +       case VCMD_read_history:
25184 +               return __COMPAT(vc_read_history, id, data, compat);
25185 +#endif
25186 +#ifdef CONFIG_VSERVER_MONITOR
25187 +       case VCMD_read_monitor:
25188 +               return __COMPAT(vc_read_monitor, id, data, compat);
25189 +#endif
25190 +       default:
25191 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25192 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25193 +       }
25194 +       return -ENOSYS;
25195 +}
25196 +
25197 +
25198 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25199 +       case VCMD_ ## vcmd: perm = _perm;               \
25200 +               args = _args; flags = _flags; break
25201 +
25202 +
25203 +#define VCA_NONE       0x00
25204 +#define VCA_VXI                0x01
25205 +#define VCA_NXI                0x02
25206 +
25207 +#define VCF_NONE       0x00
25208 +#define VCF_INFO       0x01
25209 +#define VCF_ADMIN      0x02
25210 +#define VCF_ARES       0x06    /* includes admin */
25211 +#define VCF_SETUP      0x08
25212 +
25213 +#define VCF_ZIDOK      0x10    /* zero id okay */
25214 +
25215 +
25216 +static inline
25217 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25218 +{
25219 +       long ret;
25220 +       int permit = -1, state = 0;
25221 +       int perm = -1, args = 0, flags = 0;
25222 +       struct vx_info *vxi = NULL;
25223 +       struct nx_info *nxi = NULL;
25224 +
25225 +       switch (cmd) {
25226 +       /* unpriviledged commands */
25227 +       __VCMD(get_version,      0, VCA_NONE,   0);
25228 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25229 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25230 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25231 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25232 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25233 +
25234 +       /* info commands */
25235 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25236 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25237 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25238 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25239 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25240 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25241 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25242 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25243 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25244 +
25245 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25246 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25247 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25248 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25249 +
25250 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25251 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25252 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25253 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25254 +
25255 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25256 +
25257 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25258 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25259 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25260 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25261 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25262 +
25263 +       /* lower admin commands */
25264 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25265 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25266 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25267 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25268 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25269 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25270 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25271 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25272 +
25273 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25274 +       __VCMD(net_create,       5, VCA_NONE,   0);
25275 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25276 +
25277 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25278 +
25279 +       /* higher admin commands */
25280 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25281 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25282 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25283 +
25284 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25285 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25286 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25287 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25288 +
25289 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25290 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25291 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25292 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25293 +
25294 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25295 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25296 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25297 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25298 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25299 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25300 +#ifdef CONFIG_IPV6
25301 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25302 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25303 +#endif
25304 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25305 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25306 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25307 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25308 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25309 +
25310 +#ifdef CONFIG_VSERVER_DEVICE
25311 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25312 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25313 +#endif
25314 +       /* debug level admin commands */
25315 +#ifdef CONFIG_VSERVER_HISTORY
25316 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25317 +       __VCMD(read_history,     9, VCA_NONE,   0);
25318 +#endif
25319 +#ifdef CONFIG_VSERVER_MONITOR
25320 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25321 +#endif
25322 +
25323 +       default:
25324 +               perm = -1;
25325 +       }
25326 +
25327 +       vxdprintk(VXD_CBIT(switch, 0),
25328 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25329 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25330 +               VC_VERSION(cmd), id, data, compat,
25331 +               perm, args, flags);
25332 +
25333 +       ret = -ENOSYS;
25334 +       if (perm < 0)
25335 +               goto out;
25336 +
25337 +       state = 1;
25338 +       if (!capable(CAP_CONTEXT))
25339 +               goto out;
25340 +
25341 +       state = 2;
25342 +       /* moved here from the individual commands */
25343 +       ret = -EPERM;
25344 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25345 +               goto out;
25346 +
25347 +       state = 3;
25348 +       /* vcmd involves resource management  */
25349 +       ret = -EPERM;
25350 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25351 +               goto out;
25352 +
25353 +       state = 4;
25354 +       /* various legacy exceptions */
25355 +       switch (cmd) {
25356 +       /* will go away when spectator is a cap */
25357 +       case VCMD_ctx_migrate_v0:
25358 +       case VCMD_ctx_migrate:
25359 +               if (id == 1) {
25360 +                       current->xid = 1;
25361 +                       ret = 1;
25362 +                       goto out;
25363 +               }
25364 +               break;
25365 +
25366 +       /* will go away when spectator is a cap */
25367 +       case VCMD_net_migrate:
25368 +               if (id == 1) {
25369 +                       current->nid = 1;
25370 +                       ret = 1;
25371 +                       goto out;
25372 +               }
25373 +               break;
25374 +       }
25375 +
25376 +       /* vcmds are fine by default */
25377 +       permit = 1;
25378 +
25379 +       /* admin type vcmds require admin ... */
25380 +       if (flags & VCF_ADMIN)
25381 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25382 +
25383 +       /* ... but setup type vcmds override that */
25384 +       if (!permit && (flags & VCF_SETUP))
25385 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25386 +
25387 +       state = 5;
25388 +       ret = -EPERM;
25389 +       if (!permit)
25390 +               goto out;
25391 +
25392 +       state = 6;
25393 +       if (!id && (flags & VCF_ZIDOK))
25394 +               goto skip_id;
25395 +
25396 +       ret = -ESRCH;
25397 +       if (args & VCA_VXI) {
25398 +               vxi = lookup_vx_info(id);
25399 +               if (!vxi)
25400 +                       goto out;
25401 +
25402 +               if ((flags & VCF_ADMIN) &&
25403 +                       /* special case kill for shutdown */
25404 +                       (cmd != VCMD_ctx_kill) &&
25405 +                       /* can context be administrated? */
25406 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25407 +                       ret = -EACCES;
25408 +                       goto out_vxi;
25409 +               }
25410 +       }
25411 +       state = 7;
25412 +       if (args & VCA_NXI) {
25413 +               nxi = lookup_nx_info(id);
25414 +               if (!nxi)
25415 +                       goto out_vxi;
25416 +
25417 +               if ((flags & VCF_ADMIN) &&
25418 +                       /* can context be administrated? */
25419 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25420 +                       ret = -EACCES;
25421 +                       goto out_nxi;
25422 +               }
25423 +       }
25424 +skip_id:
25425 +       state = 8;
25426 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25427 +
25428 +out_nxi:
25429 +       if ((args & VCA_NXI) && nxi)
25430 +               put_nx_info(nxi);
25431 +out_vxi:
25432 +       if ((args & VCA_VXI) && vxi)
25433 +               put_vx_info(vxi);
25434 +out:
25435 +       vxdprintk(VXD_CBIT(switch, 1),
25436 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25437 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25438 +               VC_VERSION(cmd), ret, ret, state, permit);
25439 +       return ret;
25440 +}
25441 +
25442 +asmlinkage long
25443 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25444 +{
25445 +       return do_vserver(cmd, id, data, 0);
25446 +}
25447 +
25448 +#ifdef CONFIG_COMPAT
25449 +
25450 +asmlinkage long
25451 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25452 +{
25453 +       return do_vserver(cmd, id, data, 1);
25454 +}
25455 +
25456 +#endif /* CONFIG_COMPAT */
25457 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/sysctl.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sysctl.c
25458 --- linux-2.6.27.10/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
25459 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/sysctl.c        2008-10-13 14:54:20.000000000 +0200
25460 @@ -0,0 +1,244 @@
25461 +/*
25462 + *  kernel/vserver/sysctl.c
25463 + *
25464 + *  Virtual Context Support
25465 + *
25466 + *  Copyright (C) 2004-2007  Herbert Pötzl
25467 + *
25468 + *  V0.01  basic structure
25469 + *
25470 + */
25471 +
25472 +#include <linux/module.h>
25473 +#include <linux/ctype.h>
25474 +#include <linux/sysctl.h>
25475 +#include <linux/parser.h>
25476 +#include <asm/uaccess.h>
25477 +
25478 +
25479 +enum {
25480 +       CTL_DEBUG_ERROR         = 0,
25481 +       CTL_DEBUG_SWITCH        = 1,
25482 +       CTL_DEBUG_XID,
25483 +       CTL_DEBUG_NID,
25484 +       CTL_DEBUG_TAG,
25485 +       CTL_DEBUG_NET,
25486 +       CTL_DEBUG_LIMIT,
25487 +       CTL_DEBUG_CRES,
25488 +       CTL_DEBUG_DLIM,
25489 +       CTL_DEBUG_QUOTA,
25490 +       CTL_DEBUG_CVIRT,
25491 +       CTL_DEBUG_SPACE,
25492 +       CTL_DEBUG_MISC,
25493 +};
25494 +
25495 +
25496 +unsigned int vx_debug_switch   = 0;
25497 +unsigned int vx_debug_xid      = 0;
25498 +unsigned int vx_debug_nid      = 0;
25499 +unsigned int vx_debug_tag      = 0;
25500 +unsigned int vx_debug_net      = 0;
25501 +unsigned int vx_debug_limit    = 0;
25502 +unsigned int vx_debug_cres     = 0;
25503 +unsigned int vx_debug_dlim     = 0;
25504 +unsigned int vx_debug_quota    = 0;
25505 +unsigned int vx_debug_cvirt    = 0;
25506 +unsigned int vx_debug_space    = 0;
25507 +unsigned int vx_debug_misc     = 0;
25508 +
25509 +
25510 +static struct ctl_table_header *vserver_table_header;
25511 +static ctl_table vserver_root_table[];
25512 +
25513 +
25514 +void vserver_register_sysctl(void)
25515 +{
25516 +       if (!vserver_table_header) {
25517 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25518 +       }
25519 +
25520 +}
25521 +
25522 +void vserver_unregister_sysctl(void)
25523 +{
25524 +       if (vserver_table_header) {
25525 +               unregister_sysctl_table(vserver_table_header);
25526 +               vserver_table_header = NULL;
25527 +       }
25528 +}
25529 +
25530 +
25531 +static int proc_dodebug(ctl_table *table, int write,
25532 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25533 +{
25534 +       char            tmpbuf[20], *p, c;
25535 +       unsigned int    value;
25536 +       size_t          left, len;
25537 +
25538 +       if ((*ppos && !write) || !*lenp) {
25539 +               *lenp = 0;
25540 +               return 0;
25541 +       }
25542 +
25543 +       left = *lenp;
25544 +
25545 +       if (write) {
25546 +               if (!access_ok(VERIFY_READ, buffer, left))
25547 +                       return -EFAULT;
25548 +               p = (char *)buffer;
25549 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25550 +                       left--, p++;
25551 +               if (!left)
25552 +                       goto done;
25553 +
25554 +               if (left > sizeof(tmpbuf) - 1)
25555 +                       return -EINVAL;
25556 +               if (copy_from_user(tmpbuf, p, left))
25557 +                       return -EFAULT;
25558 +               tmpbuf[left] = '\0';
25559 +
25560 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25561 +                       value = 10 * value + (*p - '0');
25562 +               if (*p && !isspace(*p))
25563 +                       return -EINVAL;
25564 +               while (left && isspace(*p))
25565 +                       left--, p++;
25566 +               *(unsigned int *)table->data = value;
25567 +       } else {
25568 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25569 +                       return -EFAULT;
25570 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25571 +               if (len > left)
25572 +                       len = left;
25573 +               if (__copy_to_user(buffer, tmpbuf, len))
25574 +                       return -EFAULT;
25575 +               if ((left -= len) > 0) {
25576 +                       if (put_user('\n', (char *)buffer + len))
25577 +                               return -EFAULT;
25578 +                       left--;
25579 +               }
25580 +       }
25581 +
25582 +done:
25583 +       *lenp -= left;
25584 +       *ppos += *lenp;
25585 +       return 0;
25586 +}
25587 +
25588 +static int zero;
25589 +
25590 +#define        CTL_ENTRY(ctl, name)                            \
25591 +       {                                               \
25592 +               .ctl_name       = ctl,                  \
25593 +               .procname       = #name,                \
25594 +               .data           = &vx_ ## name,         \
25595 +               .maxlen         = sizeof(int),          \
25596 +               .mode           = 0644,                 \
25597 +               .proc_handler   = &proc_dodebug,        \
25598 +               .strategy       = &sysctl_intvec,       \
25599 +               .extra1         = &zero,                \
25600 +       }
25601 +
25602 +static ctl_table vserver_debug_table[] = {
25603 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25604 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25605 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25606 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25607 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25608 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25609 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25610 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25611 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25612 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25613 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25614 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25615 +       { .ctl_name = 0 }
25616 +};
25617 +
25618 +static ctl_table vserver_root_table[] = {
25619 +       {
25620 +               .ctl_name       = CTL_VSERVER,
25621 +               .procname       = "vserver",
25622 +               .mode           = 0555,
25623 +               .child          = vserver_debug_table
25624 +       },
25625 +       { .ctl_name = 0 }
25626 +};
25627 +
25628 +
25629 +static match_table_t tokens = {
25630 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25631 +       { CTL_DEBUG_XID,        "xid=%x"        },
25632 +       { CTL_DEBUG_NID,        "nid=%x"        },
25633 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25634 +       { CTL_DEBUG_NET,        "net=%x"        },
25635 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25636 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25637 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25638 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25639 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25640 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25641 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25642 +       { CTL_DEBUG_ERROR,      NULL            }
25643 +};
25644 +
25645 +#define        HANDLE_CASE(id, name, val)                              \
25646 +       case CTL_DEBUG_ ## id:                                  \
25647 +               vx_debug_ ## name = val;                        \
25648 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25649 +               break
25650 +
25651 +
25652 +static int __init vs_debug_setup(char *str)
25653 +{
25654 +       char *p;
25655 +       int token;
25656 +
25657 +       printk("vs_debug_setup(%s)\n", str);
25658 +       while ((p = strsep(&str, ",")) != NULL) {
25659 +               substring_t args[MAX_OPT_ARGS];
25660 +               unsigned int value;
25661 +
25662 +               if (!*p)
25663 +                       continue;
25664 +
25665 +               token = match_token(p, tokens, args);
25666 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25667 +
25668 +               switch (token) {
25669 +               HANDLE_CASE(SWITCH, switch, value);
25670 +               HANDLE_CASE(XID,    xid,    value);
25671 +               HANDLE_CASE(NID,    nid,    value);
25672 +               HANDLE_CASE(TAG,    tag,    value);
25673 +               HANDLE_CASE(NET,    net,    value);
25674 +               HANDLE_CASE(LIMIT,  limit,  value);
25675 +               HANDLE_CASE(CRES,   cres,   value);
25676 +               HANDLE_CASE(DLIM,   dlim,   value);
25677 +               HANDLE_CASE(QUOTA,  quota,  value);
25678 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25679 +               HANDLE_CASE(SPACE,  space,  value);
25680 +               HANDLE_CASE(MISC,   misc,   value);
25681 +               default:
25682 +                       return -EINVAL;
25683 +                       break;
25684 +               }
25685 +       }
25686 +       return 1;
25687 +}
25688 +
25689 +__setup("vsdebug=", vs_debug_setup);
25690 +
25691 +
25692 +
25693 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25694 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25695 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25696 +EXPORT_SYMBOL_GPL(vx_debug_net);
25697 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25698 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25699 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25700 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25701 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25702 +EXPORT_SYMBOL_GPL(vx_debug_space);
25703 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25704 +
25705 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/tag.c linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/tag.c
25706 --- linux-2.6.27.10/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
25707 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/tag.c   2008-10-13 14:54:20.000000000 +0200
25708 @@ -0,0 +1,63 @@
25709 +/*
25710 + *  linux/kernel/vserver/tag.c
25711 + *
25712 + *  Virtual Server: Shallow Tag Space
25713 + *
25714 + *  Copyright (C) 2007  Herbert Pötzl
25715 + *
25716 + *  V0.01  basic implementation
25717 + *
25718 + */
25719 +
25720 +#include <linux/sched.h>
25721 +#include <linux/vserver/debug.h>
25722 +#include <linux/vs_pid.h>
25723 +#include <linux/vs_tag.h>
25724 +
25725 +#include <linux/vserver/tag_cmd.h>
25726 +
25727 +
25728 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25729 +{
25730 +       if (!p)
25731 +               BUG();
25732 +
25733 +       vxdprintk(VXD_CBIT(tag, 5),
25734 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25735 +
25736 +       task_lock(p);
25737 +       p->tag = tag;
25738 +       task_unlock(p);
25739 +
25740 +       vxdprintk(VXD_CBIT(tag, 5),
25741 +               "moved task %p into [#%d]", p, tag);
25742 +       return 0;
25743 +}
25744 +
25745 +/* vserver syscall commands below here */
25746 +
25747 +/* taks xid and vx_info functions */
25748 +
25749 +
25750 +int vc_task_tag(uint32_t id)
25751 +{
25752 +       tag_t tag;
25753 +
25754 +       if (id) {
25755 +               struct task_struct *tsk;
25756 +               read_lock(&tasklist_lock);
25757 +               tsk = find_task_by_real_pid(id);
25758 +               tag = (tsk) ? tsk->tag : -ESRCH;
25759 +               read_unlock(&tasklist_lock);
25760 +       } else
25761 +               tag = dx_current_tag();
25762 +       return tag;
25763 +}
25764 +
25765 +
25766 +int vc_tag_migrate(uint32_t tag)
25767 +{
25768 +       return dx_migrate_task(current, tag & 0xFFFF);
25769 +}
25770 +
25771 +
25772 diff -NurpP --minimal linux-2.6.27.10/kernel/vserver/vci_config.h linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/vci_config.h
25773 --- linux-2.6.27.10/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
25774 +++ linux-2.6.27.10-vs2.3.0.36.4/kernel/vserver/vci_config.h    2008-10-31 18:16:04.000000000 +0100
25775 @@ -0,0 +1,81 @@
25776 +
25777 +/*  interface version */
25778 +
25779 +#define VCI_VERSION            0x00020304
25780 +
25781 +
25782 +enum {
25783 +       VCI_KCBIT_NO_DYNAMIC = 0,
25784 +
25785 +       VCI_KCBIT_PROC_SECURE = 4,
25786 +       VCI_KCBIT_HARDCPU = 5,
25787 +       VCI_KCBIT_IDLELIMIT = 6,
25788 +       VCI_KCBIT_IDLETIME = 7,
25789 +
25790 +       VCI_KCBIT_COWBL = 8,
25791 +       VCI_KCBIT_FULLCOWBL = 9,
25792 +       VCI_KCBIT_SPACES = 10,
25793 +       VCI_KCBIT_NETV2 = 11,
25794 +
25795 +       VCI_KCBIT_DEBUG = 16,
25796 +       VCI_KCBIT_HISTORY = 20,
25797 +       VCI_KCBIT_TAGGED = 24,
25798 +       VCI_KCBIT_PPTAG = 28,
25799 +
25800 +       VCI_KCBIT_MORE = 31,
25801 +};
25802 +
25803 +
25804 +static inline uint32_t vci_kernel_config(void)
25805 +{
25806 +       return
25807 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25808 +
25809 +       /* configured features */
25810 +#ifdef CONFIG_VSERVER_PROC_SECURE
25811 +       (1 << VCI_KCBIT_PROC_SECURE) |
25812 +#endif
25813 +#ifdef CONFIG_VSERVER_HARDCPU
25814 +       (1 << VCI_KCBIT_HARDCPU) |
25815 +#endif
25816 +#ifdef CONFIG_VSERVER_IDLELIMIT
25817 +       (1 << VCI_KCBIT_IDLELIMIT) |
25818 +#endif
25819 +#ifdef CONFIG_VSERVER_IDLETIME
25820 +       (1 << VCI_KCBIT_IDLETIME) |
25821 +#endif
25822 +#ifdef CONFIG_VSERVER_COWBL
25823 +       (1 << VCI_KCBIT_COWBL) |
25824 +       (1 << VCI_KCBIT_FULLCOWBL) |
25825 +#endif
25826 +       (1 << VCI_KCBIT_SPACES) |
25827 +       (1 << VCI_KCBIT_NETV2) |
25828 +
25829 +       /* debug options */
25830 +#ifdef CONFIG_VSERVER_DEBUG
25831 +       (1 << VCI_KCBIT_DEBUG) |
25832 +#endif
25833 +#ifdef CONFIG_VSERVER_HISTORY
25834 +       (1 << VCI_KCBIT_HISTORY) |
25835 +#endif
25836 +
25837 +       /* inode context tagging */
25838 +#if    defined(CONFIG_TAGGING_NONE)
25839 +       (0 << VCI_KCBIT_TAGGED) |
25840 +#elif  defined(CONFIG_TAGGING_UID16)
25841 +       (1 << VCI_KCBIT_TAGGED) |
25842 +#elif  defined(CONFIG_TAGGING_GID16)
25843 +       (2 << VCI_KCBIT_TAGGED) |
25844 +#elif  defined(CONFIG_TAGGING_ID24)
25845 +       (3 << VCI_KCBIT_TAGGED) |
25846 +#elif  defined(CONFIG_TAGGING_INTERN)
25847 +       (4 << VCI_KCBIT_TAGGED) |
25848 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25849 +       (5 << VCI_KCBIT_TAGGED) |
25850 +#else
25851 +       (7 << VCI_KCBIT_TAGGED) |
25852 +#endif
25853 +       (1 << VCI_KCBIT_PPTAG) |
25854 +       0;
25855 +}
25856 +
25857 diff -NurpP --minimal linux-2.6.27.10/Makefile linux-2.6.27.10-vs2.3.0.36.4/Makefile
25858 --- linux-2.6.27.10/Makefile    2008-12-19 12:03:05.000000000 +0100
25859 +++ linux-2.6.27.10-vs2.3.0.36.4/Makefile       2009-01-04 03:26:49.000000000 +0100
25860 @@ -1,7 +1,7 @@
25861  VERSION = 2
25862  PATCHLEVEL = 6
25863  SUBLEVEL = 27
25864 -EXTRAVERSION = .10
25865 +EXTRAVERSION = .10-vs2.3.0.36.4
25866  NAME = Trembling Tortoise
25867  
25868  # *DOCUMENTATION*
25869 diff -NurpP --minimal linux-2.6.27.10/mm/filemap_xip.c linux-2.6.27.10-vs2.3.0.36.4/mm/filemap_xip.c
25870 --- linux-2.6.27.10/mm/filemap_xip.c    2008-10-13 14:52:09.000000000 +0200
25871 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/filemap_xip.c       2008-10-13 14:54:20.000000000 +0200
25872 @@ -17,6 +17,7 @@
25873  #include <linux/sched.h>
25874  #include <linux/seqlock.h>
25875  #include <linux/mutex.h>
25876 +#include <linux/vs_memory.h>
25877  #include <asm/tlbflush.h>
25878  #include <asm/io.h>
25879  
25880 diff -NurpP --minimal linux-2.6.27.10/mm/fremap.c linux-2.6.27.10-vs2.3.0.36.4/mm/fremap.c
25881 --- linux-2.6.27.10/mm/fremap.c 2008-10-13 14:52:09.000000000 +0200
25882 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/fremap.c    2008-10-13 14:54:20.000000000 +0200
25883 @@ -16,6 +16,7 @@
25884  #include <linux/module.h>
25885  #include <linux/syscalls.h>
25886  #include <linux/mmu_notifier.h>
25887 +#include <linux/vs_memory.h>
25888  
25889  #include <asm/mmu_context.h>
25890  #include <asm/cacheflush.h>
25891 diff -NurpP --minimal linux-2.6.27.10/mm/hugetlb.c linux-2.6.27.10-vs2.3.0.36.4/mm/hugetlb.c
25892 --- linux-2.6.27.10/mm/hugetlb.c        2008-12-19 12:03:14.000000000 +0100
25893 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/hugetlb.c   2008-12-08 04:52:52.000000000 +0100
25894 @@ -23,6 +23,7 @@
25895  #include <asm/io.h>
25896  
25897  #include <linux/hugetlb.h>
25898 +#include <linux/vs_memory.h>
25899  #include "internal.h"
25900  
25901  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25902 diff -NurpP --minimal linux-2.6.27.10/mm/memory.c linux-2.6.27.10-vs2.3.0.36.4/mm/memory.c
25903 --- linux-2.6.27.10/mm/memory.c 2008-10-13 14:52:09.000000000 +0200
25904 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/memory.c    2008-10-13 14:54:20.000000000 +0200
25905 @@ -562,6 +562,9 @@ static int copy_pte_range(struct mm_stru
25906         int progress = 0;
25907         int rss[2];
25908  
25909 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25910 +               return -ENOMEM;
25911 +
25912  again:
25913         rss[1] = rss[0] = 0;
25914         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25915 @@ -2294,6 +2297,11 @@ static int do_swap_page(struct mm_struct
25916                 goto out;
25917         }
25918  
25919 +       if (!vx_rss_avail(mm, 1)) {
25920 +               ret = VM_FAULT_OOM;
25921 +               goto out;
25922 +       }
25923 +
25924         mark_page_accessed(page);
25925         lock_page(page);
25926         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
25927 @@ -2365,6 +2373,8 @@ static int do_anonymous_page(struct mm_s
25928         /* Allocate our own private page. */
25929         pte_unmap(page_table);
25930  
25931 +       if (!vx_rss_avail(mm, 1))
25932 +               goto oom;
25933         if (unlikely(anon_vma_prepare(vma)))
25934                 goto oom;
25935         page = alloc_zeroed_user_highpage_movable(vma, address);
25936 @@ -2626,6 +2636,7 @@ static inline int handle_pte_fault(struc
25937  {
25938         pte_t entry;
25939         spinlock_t *ptl;
25940 +       int ret = 0, type = VXPT_UNKNOWN;
25941  
25942         entry = *pte;
25943         if (!pte_present(entry)) {
25944 @@ -2650,9 +2661,12 @@ static inline int handle_pte_fault(struc
25945         if (unlikely(!pte_same(*pte, entry)))
25946                 goto unlock;
25947         if (write_access) {
25948 -               if (!pte_write(entry))
25949 -                       return do_wp_page(mm, vma, address,
25950 +               if (!pte_write(entry)) {
25951 +                       ret = do_wp_page(mm, vma, address,
25952                                         pte, pmd, ptl, entry);
25953 +                       type = VXPT_WRITE;
25954 +                       goto out;
25955 +               }
25956                 entry = pte_mkdirty(entry);
25957         }
25958         entry = pte_mkyoung(entry);
25959 @@ -2670,7 +2684,10 @@ static inline int handle_pte_fault(struc
25960         }
25961  unlock:
25962         pte_unmap_unlock(pte, ptl);
25963 -       return 0;
25964 +       ret = 0;
25965 +out:
25966 +       vx_page_fault(mm, vma, type, ret);
25967 +       return ret;
25968  }
25969  
25970  /*
25971 diff -NurpP --minimal linux-2.6.27.10/mm/mlock.c linux-2.6.27.10-vs2.3.0.36.4/mm/mlock.c
25972 --- linux-2.6.27.10/mm/mlock.c  2008-10-13 14:52:09.000000000 +0200
25973 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/mlock.c     2008-10-13 14:54:20.000000000 +0200
25974 @@ -12,6 +12,7 @@
25975  #include <linux/syscalls.h>
25976  #include <linux/sched.h>
25977  #include <linux/module.h>
25978 +#include <linux/vs_memory.h>
25979  
25980  int can_do_mlock(void)
25981  {
25982 @@ -76,7 +77,7 @@ success:
25983                         ret = make_pages_present(start, end);
25984         }
25985  
25986 -       mm->locked_vm -= pages;
25987 +       vx_vmlocked_sub(mm, pages);
25988  out:
25989         return ret;
25990  }
25991 @@ -132,7 +133,7 @@ static int do_mlock(unsigned long start,
25992  
25993  asmlinkage long sys_mlock(unsigned long start, size_t len)
25994  {
25995 -       unsigned long locked;
25996 +       unsigned long locked, grow;
25997         unsigned long lock_limit;
25998         int error = -ENOMEM;
25999  
26000 @@ -143,8 +144,10 @@ asmlinkage long sys_mlock(unsigned long 
26001         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26002         start &= PAGE_MASK;
26003  
26004 -       locked = len >> PAGE_SHIFT;
26005 -       locked += current->mm->locked_vm;
26006 +       grow = len >> PAGE_SHIFT;
26007 +       if (!vx_vmlocked_avail(current->mm, grow))
26008 +               goto out;
26009 +       locked = current->mm->locked_vm + grow;
26010  
26011         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26012         lock_limit >>= PAGE_SHIFT;
26013 @@ -152,6 +155,7 @@ asmlinkage long sys_mlock(unsigned long 
26014         /* check against resource limits */
26015         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26016                 error = do_mlock(start, len, 1);
26017 +out:
26018         up_write(&current->mm->mmap_sem);
26019         return error;
26020  }
26021 @@ -211,6 +215,8 @@ asmlinkage long sys_mlockall(int flags)
26022         lock_limit >>= PAGE_SHIFT;
26023  
26024         ret = -ENOMEM;
26025 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26026 +               goto out;
26027         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26028             capable(CAP_IPC_LOCK))
26029                 ret = do_mlockall(flags);
26030 diff -NurpP --minimal linux-2.6.27.10/mm/mmap.c linux-2.6.27.10-vs2.3.0.36.4/mm/mmap.c
26031 --- linux-2.6.27.10/mm/mmap.c   2008-10-13 14:52:09.000000000 +0200
26032 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/mmap.c      2008-10-13 14:54:20.000000000 +0200
26033 @@ -1221,10 +1221,10 @@ munmap_back:
26034         if (correct_wcount)
26035                 atomic_inc(&inode->i_writecount);
26036  out:
26037 -       mm->total_vm += len >> PAGE_SHIFT;
26038 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26039         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26040         if (vm_flags & VM_LOCKED) {
26041 -               mm->locked_vm += len >> PAGE_SHIFT;
26042 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26043                 make_pages_present(addr, addr + len);
26044         }
26045         if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26046 @@ -1573,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
26047                 return -ENOMEM;
26048  
26049         /* Ok, everything looks good - let it rip */
26050 -       mm->total_vm += grow;
26051 +       vx_vmpages_add(mm, grow);
26052         if (vma->vm_flags & VM_LOCKED)
26053 -               mm->locked_vm += grow;
26054 +               vx_vmlocked_add(mm, grow);
26055         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26056         return 0;
26057  }
26058 @@ -1746,9 +1746,9 @@ static void remove_vma_list(struct mm_st
26059         do {
26060                 long nrpages = vma_pages(vma);
26061  
26062 -               mm->total_vm -= nrpages;
26063 +               vx_vmpages_sub(mm, nrpages);
26064                 if (vma->vm_flags & VM_LOCKED)
26065 -                       mm->locked_vm -= nrpages;
26066 +                       vx_vmlocked_sub(mm, nrpages);
26067                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26068                 vma = remove_vma(vma);
26069         } while (vma);
26070 @@ -1995,6 +1995,8 @@ unsigned long do_brk(unsigned long addr,
26071                 lock_limit >>= PAGE_SHIFT;
26072                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26073                         return -EAGAIN;
26074 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26075 +                       return -ENOMEM;
26076         }
26077  
26078         /*
26079 @@ -2021,7 +2023,8 @@ unsigned long do_brk(unsigned long addr,
26080         if (mm->map_count > sysctl_max_map_count)
26081                 return -ENOMEM;
26082  
26083 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26084 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26085 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26086                 return -ENOMEM;
26087  
26088         /* Can we just expand an old private anonymous mapping? */
26089 @@ -2046,9 +2049,9 @@ unsigned long do_brk(unsigned long addr,
26090         vma->vm_page_prot = vm_get_page_prot(flags);
26091         vma_link(mm, vma, prev, rb_link, rb_parent);
26092  out:
26093 -       mm->total_vm += len >> PAGE_SHIFT;
26094 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26095         if (flags & VM_LOCKED) {
26096 -               mm->locked_vm += len >> PAGE_SHIFT;
26097 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26098                 make_pages_present(addr, addr + len);
26099         }
26100         return addr;
26101 @@ -2078,6 +2081,11 @@ void exit_mmap(struct mm_struct *mm)
26102         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26103         tlb_finish_mmu(tlb, 0, end);
26104  
26105 +       set_mm_counter(mm, file_rss, 0);
26106 +       set_mm_counter(mm, anon_rss, 0);
26107 +       vx_vmpages_sub(mm, mm->total_vm);
26108 +       vx_vmlocked_sub(mm, mm->locked_vm);
26109 +
26110         /*
26111          * Walk the list again, actually closing and freeing it,
26112          * with preemption enabled, without holding any MM locks.
26113 @@ -2117,7 +2125,8 @@ int insert_vm_struct(struct mm_struct * 
26114         if (__vma && __vma->vm_start < vma->vm_end)
26115                 return -ENOMEM;
26116         if ((vma->vm_flags & VM_ACCOUNT) &&
26117 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26118 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26119 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26120                 return -ENOMEM;
26121         vma_link(mm, vma, prev, rb_link, rb_parent);
26122         return 0;
26123 @@ -2193,6 +2202,8 @@ int may_expand_vm(struct mm_struct *mm, 
26124  
26125         if (cur + npages > lim)
26126                 return 0;
26127 +       if (!vx_vmpages_avail(mm, npages))
26128 +               return 0;
26129         return 1;
26130  }
26131  
26132 @@ -2270,8 +2281,7 @@ int install_special_mapping(struct mm_st
26133                 return -ENOMEM;
26134         }
26135  
26136 -       mm->total_vm += len >> PAGE_SHIFT;
26137 -
26138 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26139         return 0;
26140  }
26141  
26142 diff -NurpP --minimal linux-2.6.27.10/mm/mremap.c linux-2.6.27.10-vs2.3.0.36.4/mm/mremap.c
26143 --- linux-2.6.27.10/mm/mremap.c 2008-10-13 14:52:09.000000000 +0200
26144 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/mremap.c    2008-10-13 14:54:20.000000000 +0200
26145 @@ -19,6 +19,7 @@
26146  #include <linux/security.h>
26147  #include <linux/syscalls.h>
26148  #include <linux/mmu_notifier.h>
26149 +#include <linux/vs_memory.h>
26150  
26151  #include <asm/uaccess.h>
26152  #include <asm/cacheflush.h>
26153 @@ -218,7 +219,7 @@ static unsigned long move_vma(struct vm_
26154          * If this were a serious issue, we'd add a flag to do_munmap().
26155          */
26156         hiwater_vm = mm->hiwater_vm;
26157 -       mm->total_vm += new_len >> PAGE_SHIFT;
26158 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26159         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26160  
26161         if (do_munmap(mm, old_addr, old_len) < 0) {
26162 @@ -236,7 +237,7 @@ static unsigned long move_vma(struct vm_
26163         }
26164  
26165         if (vm_flags & VM_LOCKED) {
26166 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26167 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26168                 if (new_len > old_len)
26169                         make_pages_present(new_addr + old_len,
26170                                            new_addr + new_len);
26171 @@ -347,6 +348,9 @@ unsigned long do_mremap(unsigned long ad
26172                 ret = -EAGAIN;
26173                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26174                         goto out;
26175 +               if (!vx_vmlocked_avail(current->mm,
26176 +                       (new_len - old_len) >> PAGE_SHIFT))
26177 +                       goto out;
26178         }
26179         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26180                 ret = -ENOMEM;
26181 @@ -375,10 +379,10 @@ unsigned long do_mremap(unsigned long ad
26182                         vma_adjust(vma, vma->vm_start,
26183                                 addr + new_len, vma->vm_pgoff, NULL);
26184  
26185 -                       mm->total_vm += pages;
26186 +                       vx_vmpages_add(mm, pages);
26187                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26188                         if (vma->vm_flags & VM_LOCKED) {
26189 -                               mm->locked_vm += pages;
26190 +                               vx_vmlocked_add(mm, pages);
26191                                 make_pages_present(addr + old_len,
26192                                                    addr + new_len);
26193                         }
26194 diff -NurpP --minimal linux-2.6.27.10/mm/nommu.c linux-2.6.27.10-vs2.3.0.36.4/mm/nommu.c
26195 --- linux-2.6.27.10/mm/nommu.c  2008-10-13 14:52:09.000000000 +0200
26196 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/nommu.c     2008-10-13 14:54:20.000000000 +0200
26197 @@ -1028,7 +1028,7 @@ unsigned long do_mmap_pgoff(struct file 
26198         realalloc += kobjsize(vma);
26199         askedalloc += sizeof(*vma);
26200  
26201 -       current->mm->total_vm += len >> PAGE_SHIFT;
26202 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26203  
26204         add_nommu_vma(vma);
26205  
26206 @@ -1160,7 +1160,7 @@ int do_munmap(struct mm_struct *mm, unsi
26207         kfree(vml);
26208  
26209         update_hiwater_vm(mm);
26210 -       mm->total_vm -= len >> PAGE_SHIFT;
26211 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
26212  
26213  #ifdef DEBUG
26214         show_process_blocks();
26215 @@ -1193,7 +1193,7 @@ void exit_mmap(struct mm_struct * mm)
26216                 printk("Exit_mmap:\n");
26217  #endif
26218  
26219 -               mm->total_vm = 0;
26220 +               vx_vmpages_sub(mm, mm->total_vm);
26221  
26222                 while ((tmp = mm->context.vmlist)) {
26223                         mm->context.vmlist = tmp->next;
26224 diff -NurpP --minimal linux-2.6.27.10/mm/oom_kill.c linux-2.6.27.10-vs2.3.0.36.4/mm/oom_kill.c
26225 --- linux-2.6.27.10/mm/oom_kill.c       2008-10-13 14:52:09.000000000 +0200
26226 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/oom_kill.c  2008-10-13 14:54:20.000000000 +0200
26227 @@ -27,6 +27,7 @@
26228  #include <linux/notifier.h>
26229  #include <linux/memcontrol.h>
26230  #include <linux/security.h>
26231 +#include <linux/vs_memory.h>
26232  
26233  int sysctl_panic_on_oom;
26234  int sysctl_oom_kill_allocating_task;
26235 @@ -73,6 +74,12 @@ unsigned long badness(struct task_struct
26236         points = mm->total_vm;
26237  
26238         /*
26239 +        * add points for context badness
26240 +        */
26241 +
26242 +       points += vx_badness(p, mm);
26243 +
26244 +       /*
26245          * After this unlock we can no longer dereference local variable `mm'
26246          */
26247         task_unlock(p);
26248 @@ -163,8 +170,8 @@ unsigned long badness(struct task_struct
26249         }
26250  
26251  #ifdef DEBUG
26252 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26253 -       p->pid, p->comm, points);
26254 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26255 +               task_pid_nr(p), p->xid, p->comm, points);
26256  #endif
26257         return points;
26258  }
26259 @@ -325,8 +332,8 @@ static void __oom_kill_task(struct task_
26260         }
26261  
26262         if (verbose)
26263 -               printk(KERN_ERR "Killed process %d (%s)\n",
26264 -                               task_pid_nr(p), p->comm);
26265 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26266 +                               task_pid_nr(p), p->xid, p->comm);
26267  
26268         /*
26269          * We give our sacrificial lamb high priority and access to
26270 @@ -406,8 +413,8 @@ static int oom_kill_process(struct task_
26271                 return 0;
26272         }
26273  
26274 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26275 -                                       message, task_pid_nr(p), p->comm, points);
26276 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26277 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26278  
26279         /* Try to kill a child first */
26280         list_for_each_entry(c, &p->children, sibling) {
26281 diff -NurpP --minimal linux-2.6.27.10/mm/page_alloc.c linux-2.6.27.10-vs2.3.0.36.4/mm/page_alloc.c
26282 --- linux-2.6.27.10/mm/page_alloc.c     2008-12-19 12:03:14.000000000 +0100
26283 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/page_alloc.c        2008-12-19 12:09:14.000000000 +0100
26284 @@ -46,6 +46,8 @@
26285  #include <linux/page-isolation.h>
26286  #include <linux/memcontrol.h>
26287  #include <linux/debugobjects.h>
26288 +#include <linux/vs_base.h>
26289 +#include <linux/vs_limit.h>
26290  
26291  #include <asm/tlbflush.h>
26292  #include <asm/div64.h>
26293 @@ -1823,6 +1825,9 @@ void si_meminfo(struct sysinfo *val)
26294         val->totalhigh = totalhigh_pages;
26295         val->freehigh = nr_free_highpages();
26296         val->mem_unit = PAGE_SIZE;
26297 +
26298 +       if (vx_flags(VXF_VIRT_MEM, 0))
26299 +               vx_vsi_meminfo(val);
26300  }
26301  
26302  EXPORT_SYMBOL(si_meminfo);
26303 @@ -1843,6 +1848,9 @@ void si_meminfo_node(struct sysinfo *val
26304         val->freehigh = 0;
26305  #endif
26306         val->mem_unit = PAGE_SIZE;
26307 +
26308 +       if (vx_flags(VXF_VIRT_MEM, 0))
26309 +               vx_vsi_meminfo(val);
26310  }
26311  #endif
26312  
26313 diff -NurpP --minimal linux-2.6.27.10/mm/rmap.c linux-2.6.27.10-vs2.3.0.36.4/mm/rmap.c
26314 --- linux-2.6.27.10/mm/rmap.c   2008-12-19 12:03:14.000000000 +0100
26315 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/rmap.c      2008-10-30 01:17:01.000000000 +0100
26316 @@ -50,6 +50,7 @@
26317  #include <linux/kallsyms.h>
26318  #include <linux/memcontrol.h>
26319  #include <linux/mmu_notifier.h>
26320 +#include <linux/vs_memory.h>
26321  
26322  #include <asm/tlbflush.h>
26323  
26324 diff -NurpP --minimal linux-2.6.27.10/mm/shmem.c linux-2.6.27.10-vs2.3.0.36.4/mm/shmem.c
26325 --- linux-2.6.27.10/mm/shmem.c  2008-10-13 14:52:09.000000000 +0200
26326 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/shmem.c     2008-10-13 14:54:20.000000000 +0200
26327 @@ -56,7 +56,6 @@
26328  #include <asm/pgtable.h>
26329  
26330  /* This magic number is used in glibc for posix shared memory */
26331 -#define TMPFS_MAGIC    0x01021994
26332  
26333  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
26334  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
26335 @@ -1738,7 +1737,7 @@ static int shmem_statfs(struct dentry *d
26336  {
26337         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26338  
26339 -       buf->f_type = TMPFS_MAGIC;
26340 +       buf->f_type = TMPFS_SUPER_MAGIC;
26341         buf->f_bsize = PAGE_CACHE_SIZE;
26342         buf->f_namelen = NAME_MAX;
26343         spin_lock(&sbinfo->stat_lock);
26344 @@ -2306,7 +2305,7 @@ static int shmem_fill_super(struct super
26345         sb->s_maxbytes = SHMEM_MAX_BYTES;
26346         sb->s_blocksize = PAGE_CACHE_SIZE;
26347         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26348 -       sb->s_magic = TMPFS_MAGIC;
26349 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26350         sb->s_op = &shmem_ops;
26351         sb->s_time_gran = 1;
26352  #ifdef CONFIG_TMPFS_POSIX_ACL
26353 diff -NurpP --minimal linux-2.6.27.10/mm/slab.c linux-2.6.27.10-vs2.3.0.36.4/mm/slab.c
26354 --- linux-2.6.27.10/mm/slab.c   2008-10-13 14:52:09.000000000 +0200
26355 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/slab.c      2008-10-13 14:54:20.000000000 +0200
26356 @@ -508,6 +508,8 @@ struct kmem_cache {
26357  #define STATS_INC_FREEMISS(x)  do { } while (0)
26358  #endif
26359  
26360 +#include "slab_vs.h"
26361 +
26362  #if DEBUG
26363  
26364  /*
26365 @@ -3337,6 +3339,7 @@ retry:
26366  
26367         obj = slab_get_obj(cachep, slabp, nodeid);
26368         check_slabp(cachep, slabp);
26369 +       vx_slab_alloc(cachep, flags);
26370         l3->free_objects--;
26371         /* move slabp to correct slabp list: */
26372         list_del(&slabp->list);
26373 @@ -3409,6 +3412,7 @@ __cache_alloc_node(struct kmem_cache *ca
26374         /* ___cache_alloc_node can fall back to other nodes */
26375         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26376    out:
26377 +       vx_slab_alloc(cachep, flags);
26378         local_irq_restore(save_flags);
26379         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26380  
26381 @@ -3580,6 +3584,7 @@ static inline void __cache_free(struct k
26382  
26383         check_irq_off();
26384         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26385 +       vx_slab_free(cachep);
26386  
26387         /*
26388          * Skip calling cache_free_alien() when the platform is not numa.
26389 diff -NurpP --minimal linux-2.6.27.10/mm/slab_vs.h linux-2.6.27.10-vs2.3.0.36.4/mm/slab_vs.h
26390 --- linux-2.6.27.10/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
26391 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/slab_vs.h   2008-10-13 14:54:20.000000000 +0200
26392 @@ -0,0 +1,27 @@
26393 +
26394 +#include <linux/vserver/context.h>
26395 +
26396 +#include <linux/vs_context.h>
26397 +
26398 +static inline
26399 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26400 +{
26401 +       int what = gfp_zone(cachep->gfpflags);
26402 +
26403 +       if (!current->vx_info)
26404 +               return;
26405 +
26406 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26407 +}
26408 +
26409 +static inline
26410 +void vx_slab_free(struct kmem_cache *cachep)
26411 +{
26412 +       int what = gfp_zone(cachep->gfpflags);
26413 +
26414 +       if (!current->vx_info)
26415 +               return;
26416 +
26417 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26418 +}
26419 +
26420 diff -NurpP --minimal linux-2.6.27.10/mm/swapfile.c linux-2.6.27.10-vs2.3.0.36.4/mm/swapfile.c
26421 --- linux-2.6.27.10/mm/swapfile.c       2008-10-13 14:52:09.000000000 +0200
26422 +++ linux-2.6.27.10-vs2.3.0.36.4/mm/swapfile.c  2008-10-13 14:54:20.000000000 +0200
26423 @@ -32,6 +32,8 @@
26424  #include <asm/pgtable.h>
26425  #include <asm/tlbflush.h>
26426  #include <linux/swapops.h>
26427 +#include <linux/vs_base.h>
26428 +#include <linux/vs_memory.h>
26429  
26430  static DEFINE_SPINLOCK(swap_lock);
26431  static unsigned int nr_swapfiles;
26432 @@ -1748,6 +1750,8 @@ void si_swapinfo(struct sysinfo *val)
26433         val->freeswap = nr_swap_pages + nr_to_be_unused;
26434         val->totalswap = total_swap_pages + nr_to_be_unused;
26435         spin_unlock(&swap_lock);
26436 +       if (vx_flags(VXF_VIRT_MEM, 0))
26437 +               vx_vsi_swapinfo(val);
26438  }
26439  
26440  /*
26441 diff -NurpP --minimal linux-2.6.27.10/net/core/dev.c linux-2.6.27.10-vs2.3.0.36.4/net/core/dev.c
26442 --- linux-2.6.27.10/net/core/dev.c      2008-12-19 12:03:14.000000000 +0100
26443 +++ linux-2.6.27.10-vs2.3.0.36.4/net/core/dev.c 2008-12-19 12:09:14.000000000 +0100
26444 @@ -127,6 +127,7 @@
26445  #include <linux/in.h>
26446  #include <linux/jhash.h>
26447  #include <linux/random.h>
26448 +#include <linux/vs_inet.h>
26449  
26450  #include "net-sysfs.h"
26451  
26452 @@ -925,10 +926,15 @@ int dev_change_name(struct net_device *d
26453                 strlcpy(dev->name, newname, IFNAMSIZ);
26454  
26455  rollback:
26456 -       err = device_rename(&dev->dev, dev->name);
26457 -       if (err) {
26458 -               memcpy(dev->name, oldname, IFNAMSIZ);
26459 -               return err;
26460 +       /* For now only devices in the initial network namespace
26461 +        * are in sysfs.
26462 +        */
26463 +       if (net == &init_net) {
26464 +               ret = device_rename(&dev->dev, dev->name);
26465 +               if (ret) {
26466 +                       memcpy(dev->name, oldname, IFNAMSIZ);
26467 +                       return ret;
26468 +               }
26469         }
26470  
26471         write_lock_bh(&dev_base_lock);
26472 @@ -2515,6 +2521,8 @@ static int dev_ifconf(struct net *net, c
26473  
26474         total = 0;
26475         for_each_netdev(net, dev) {
26476 +               if (!nx_dev_visible(current->nx_info, dev))
26477 +                       continue;
26478                 for (i = 0; i < NPROTO; i++) {
26479                         if (gifconf_list[i]) {
26480                                 int done;
26481 @@ -2583,6 +2591,9 @@ static void dev_seq_printf_stats(struct 
26482  {
26483         struct net_device_stats *stats = dev->get_stats(dev);
26484  
26485 +       if (!nx_dev_visible(current->nx_info, dev))
26486 +               return;
26487 +
26488         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26489                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26490                    dev->name, stats->rx_bytes, stats->rx_packets,
26491 @@ -4385,6 +4396,15 @@ int dev_change_net_namespace(struct net_
26492         if (dev->features & NETIF_F_NETNS_LOCAL)
26493                 goto out;
26494  
26495 +#ifdef CONFIG_SYSFS
26496 +       /* Don't allow real devices to be moved when sysfs
26497 +        * is enabled.
26498 +        */
26499 +       err = -EINVAL;
26500 +       if (dev->dev.parent)
26501 +               goto out;
26502 +#endif
26503 +
26504         /* Ensure the device has been registrered */
26505         err = -EINVAL;
26506         if (dev->reg_state != NETREG_REGISTERED)
26507 @@ -4442,6 +4462,8 @@ int dev_change_net_namespace(struct net_
26508          */
26509         dev_addr_discard(dev);
26510  
26511 +       netdev_unregister_kobject(dev);
26512 +
26513         /* Actually switch the network namespace */
26514         dev_net_set(dev, net);
26515  
26516 @@ -4458,7 +4480,6 @@ int dev_change_net_namespace(struct net_
26517         }
26518  
26519         /* Fixup kobjects */
26520 -       netdev_unregister_kobject(dev);
26521         err = netdev_register_kobject(dev);
26522         WARN_ON(err);
26523  
26524 diff -NurpP --minimal linux-2.6.27.10/net/core/net-sysfs.c linux-2.6.27.10-vs2.3.0.36.4/net/core/net-sysfs.c
26525 --- linux-2.6.27.10/net/core/net-sysfs.c        2008-10-13 14:52:09.000000000 +0200
26526 +++ linux-2.6.27.10-vs2.3.0.36.4/net/core/net-sysfs.c   2008-11-20 15:21:32.000000000 +0100
26527 @@ -440,6 +440,10 @@ void netdev_unregister_kobject(struct ne
26528         struct device *dev = &(net->dev);
26529  
26530         kobject_get(&dev->kobj);
26531 +
26532 +       if (dev_net(net) != &init_net)
26533 +               return;
26534 +
26535         device_del(dev);
26536  }
26537  
26538 @@ -465,6 +469,9 @@ int netdev_register_kobject(struct net_d
26539  #endif
26540  #endif /* CONFIG_SYSFS */
26541  
26542 +       if (dev_net(net) != &init_net)
26543 +               return 0;
26544 +
26545         return device_add(dev);
26546  }
26547  
26548 diff -NurpP --minimal linux-2.6.27.10/net/core/rtnetlink.c linux-2.6.27.10-vs2.3.0.36.4/net/core/rtnetlink.c
26549 --- linux-2.6.27.10/net/core/rtnetlink.c        2008-10-13 14:52:09.000000000 +0200
26550 +++ linux-2.6.27.10-vs2.3.0.36.4/net/core/rtnetlink.c   2008-10-13 14:54:20.000000000 +0200
26551 @@ -686,6 +686,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26552  
26553         idx = 0;
26554         for_each_netdev(net, dev) {
26555 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26556 +                       continue;
26557                 if (idx < s_idx)
26558                         goto cont;
26559                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26560 @@ -1219,6 +1221,9 @@ void rtmsg_ifinfo(int type, struct net_d
26561         struct sk_buff *skb;
26562         int err = -ENOBUFS;
26563  
26564 +       if (!nx_dev_visible(current->nx_info, dev))
26565 +               return;
26566 +
26567         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26568         if (skb == NULL)
26569                 goto errout;
26570 diff -NurpP --minimal linux-2.6.27.10/net/core/sock.c linux-2.6.27.10-vs2.3.0.36.4/net/core/sock.c
26571 --- linux-2.6.27.10/net/core/sock.c     2008-10-13 14:52:09.000000000 +0200
26572 +++ linux-2.6.27.10-vs2.3.0.36.4/net/core/sock.c        2008-10-13 14:54:20.000000000 +0200
26573 @@ -124,6 +124,10 @@
26574  #include <linux/ipsec.h>
26575  
26576  #include <linux/filter.h>
26577 +#include <linux/vs_socket.h>
26578 +#include <linux/vs_limit.h>
26579 +#include <linux/vs_context.h>
26580 +#include <linux/vs_network.h>
26581  
26582  #ifdef CONFIG_INET
26583  #include <net/tcp.h>
26584 @@ -897,6 +901,8 @@ static struct sock *sk_prot_alloc(struct
26585                 if (!try_module_get(prot->owner))
26586                         goto out_free_sec;
26587         }
26588 +               sock_vx_init(sk);
26589 +               sock_nx_init(sk);
26590  
26591         return sk;
26592  
26593 @@ -973,6 +979,11 @@ void sk_free(struct sock *sk)
26594                        __func__, atomic_read(&sk->sk_omem_alloc));
26595  
26596         put_net(sock_net(sk));
26597 +       vx_sock_dec(sk);
26598 +       clr_vx_info(&sk->sk_vx_info);
26599 +       sk->sk_xid = -1;
26600 +       clr_nx_info(&sk->sk_nx_info);
26601 +       sk->sk_nid = -1;
26602         sk_prot_free(sk->sk_prot_creator, sk);
26603  }
26604  
26605 @@ -1008,6 +1019,8 @@ struct sock *sk_clone(const struct sock 
26606  
26607                 /* SANITY */
26608                 get_net(sock_net(newsk));
26609 +               sock_vx_init(newsk);
26610 +               sock_nx_init(newsk);
26611                 sk_node_init(&newsk->sk_node);
26612                 sock_lock_init(newsk);
26613                 bh_lock_sock(newsk);
26614 @@ -1054,6 +1067,12 @@ struct sock *sk_clone(const struct sock 
26615                 newsk->sk_priority = 0;
26616                 atomic_set(&newsk->sk_refcnt, 2);
26617  
26618 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26619 +               newsk->sk_xid = sk->sk_xid;
26620 +               vx_sock_inc(newsk);
26621 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26622 +               newsk->sk_nid = sk->sk_nid;
26623 +
26624                 /*
26625                  * Increment the counter in the same struct proto as the master
26626                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26627 @@ -1738,6 +1757,11 @@ void sock_init_data(struct socket *sock,
26628  
26629         sk->sk_stamp = ktime_set(-1L, 0);
26630  
26631 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26632 +       sk->sk_xid = vx_current_xid();
26633 +       vx_sock_inc(sk);
26634 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26635 +       sk->sk_nid = nx_current_nid();
26636         atomic_set(&sk->sk_refcnt, 1);
26637         atomic_set(&sk->sk_drops, 0);
26638  }
26639 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/af_inet.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/af_inet.c
26640 --- linux-2.6.27.10/net/ipv4/af_inet.c  2008-10-13 14:52:09.000000000 +0200
26641 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/af_inet.c     2008-10-13 14:54:20.000000000 +0200
26642 @@ -114,6 +114,7 @@
26643  #ifdef CONFIG_IP_MROUTE
26644  #include <linux/mroute.h>
26645  #endif
26646 +#include <linux/vs_limit.h>
26647  
26648  extern void ip_mc_drop_socket(struct sock *sk);
26649  
26650 @@ -325,9 +326,12 @@ lookup_protocol:
26651         }
26652  
26653         err = -EPERM;
26654 +       if ((protocol == IPPROTO_ICMP) &&
26655 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26656 +               goto override;
26657         if (answer->capability > 0 && !capable(answer->capability))
26658                 goto out_rcu_unlock;
26659 -
26660 +override:
26661         err = -EAFNOSUPPORT;
26662         if (!inet_netns_ok(net, protocol))
26663                 goto out_rcu_unlock;
26664 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26665         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26666         struct sock *sk = sock->sk;
26667         struct inet_sock *inet = inet_sk(sk);
26668 +       struct nx_v4_sock_addr nsa;
26669         unsigned short snum;
26670         int chk_addr_ret;
26671         int err;
26672 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26673         if (addr_len < sizeof(struct sockaddr_in))
26674                 goto out;
26675  
26676 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26677 +       err = v4_map_sock_addr(inet, addr, &nsa);
26678 +       if (err)
26679 +               goto out;
26680 +
26681 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26682  
26683         /* Not specified by any standard per-se, however it breaks too
26684          * many applications when removed.  It is unfortunate since
26685 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26686         err = -EADDRNOTAVAIL;
26687         if (!sysctl_ip_nonlocal_bind &&
26688             !inet->freebind &&
26689 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26690 +           nsa.saddr != htonl(INADDR_ANY) &&
26691             chk_addr_ret != RTN_LOCAL &&
26692             chk_addr_ret != RTN_MULTICAST &&
26693             chk_addr_ret != RTN_BROADCAST)
26694 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26695         if (sk->sk_state != TCP_CLOSE || inet->num)
26696                 goto out_release_sock;
26697  
26698 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26699 +       v4_set_sock_addr(inet, &nsa);
26700         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26701                 inet->saddr = 0;  /* Use device */
26702  
26703 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26704                      peer == 1))
26705                         return -ENOTCONN;
26706                 sin->sin_port = inet->dport;
26707 -               sin->sin_addr.s_addr = inet->daddr;
26708 +               sin->sin_addr.s_addr =
26709 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26710         } else {
26711                 __be32 addr = inet->rcv_saddr;
26712                 if (!addr)
26713                         addr = inet->saddr;
26714 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26715                 sin->sin_port = inet->sport;
26716                 sin->sin_addr.s_addr = addr;
26717         }
26718 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/devinet.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/devinet.c
26719 --- linux-2.6.27.10/net/ipv4/devinet.c  2008-10-13 14:52:09.000000000 +0200
26720 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/devinet.c     2008-10-13 14:54:20.000000000 +0200
26721 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
26722         return in_dev;
26723  }
26724  
26725 +
26726  /* Called only from RTNL semaphored context. No locks. */
26727  
26728  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26729 @@ -662,6 +663,8 @@ int devinet_ioctl(struct net *net, unsig
26730                 *colon = ':';
26731  
26732         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26733 +               struct nx_info *nxi = current->nx_info;
26734 +
26735                 if (tryaddrmatch) {
26736                         /* Matthias Andree */
26737                         /* compare label and address (4.4BSD style) */
26738 @@ -670,6 +673,8 @@ int devinet_ioctl(struct net *net, unsig
26739                            This is checked above. */
26740                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26741                              ifap = &ifa->ifa_next) {
26742 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26743 +                                       continue;
26744                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26745                                     sin_orig.sin_addr.s_addr ==
26746                                                         ifa->ifa_address) {
26747 @@ -682,9 +687,12 @@ int devinet_ioctl(struct net *net, unsig
26748                    comparing just the label */
26749                 if (!ifa) {
26750                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26751 -                            ifap = &ifa->ifa_next)
26752 +                            ifap = &ifa->ifa_next) {
26753 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26754 +                                       continue;
26755                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26756                                         break;
26757 +                       }
26758                 }
26759         }
26760  
26761 @@ -835,6 +843,8 @@ static int inet_gifconf(struct net_devic
26762                 goto out;
26763  
26764         for (; ifa; ifa = ifa->ifa_next) {
26765 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26766 +                       continue;
26767                 if (!buf) {
26768                         done += sizeof(ifr);
26769                         continue;
26770 @@ -1165,6 +1175,7 @@ static int inet_dump_ifaddr(struct sk_bu
26771         struct net_device *dev;
26772         struct in_device *in_dev;
26773         struct in_ifaddr *ifa;
26774 +       struct sock *sk = skb->sk;
26775         int s_ip_idx, s_idx = cb->args[0];
26776  
26777         s_ip_idx = ip_idx = cb->args[1];
26778 @@ -1179,6 +1190,8 @@ static int inet_dump_ifaddr(struct sk_bu
26779  
26780                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26781                      ifa = ifa->ifa_next, ip_idx++) {
26782 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26783 +                               continue;
26784                         if (ip_idx < s_ip_idx)
26785                                 continue;
26786                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26787 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/fib_hash.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/fib_hash.c
26788 --- linux-2.6.27.10/net/ipv4/fib_hash.c 2008-10-13 14:52:09.000000000 +0200
26789 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/fib_hash.c    2008-10-13 14:54:20.000000000 +0200
26790 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26791         prefix  = f->fn_key;
26792         mask    = FZ_MASK(iter->zone);
26793         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26794 -       if (fi)
26795 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26796                 seq_printf(seq,
26797                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26798                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26799 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/inet_connection_sock.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/inet_connection_sock.c
26800 --- linux-2.6.27.10/net/ipv4/inet_connection_sock.c     2008-10-13 14:52:09.000000000 +0200
26801 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/inet_connection_sock.c        2008-10-13 14:54:20.000000000 +0200
26802 @@ -47,10 +47,40 @@ void inet_get_local_port_range(int *low,
26803  }
26804  EXPORT_SYMBOL(inet_get_local_port_range);
26805  
26806 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26807 +{
26808 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26809 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26810 +
26811 +       if (inet_v6_ipv6only(sk2))
26812 +               return 0;
26813 +
26814 +       if (sk1_rcv_saddr &&
26815 +           sk2_rcv_saddr &&
26816 +           sk1_rcv_saddr == sk2_rcv_saddr)
26817 +               return 1;
26818 +
26819 +       if (sk1_rcv_saddr &&
26820 +           !sk2_rcv_saddr &&
26821 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26822 +               return 1;
26823 +
26824 +       if (sk2_rcv_saddr &&
26825 +           !sk1_rcv_saddr &&
26826 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26827 +               return 1;
26828 +
26829 +       if (!sk1_rcv_saddr &&
26830 +           !sk2_rcv_saddr &&
26831 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26832 +               return 1;
26833 +
26834 +       return 0;
26835 +}
26836 +
26837  int inet_csk_bind_conflict(const struct sock *sk,
26838                            const struct inet_bind_bucket *tb)
26839  {
26840 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26841         struct sock *sk2;
26842         struct hlist_node *node;
26843         int reuse = sk->sk_reuse;
26844 @@ -70,9 +100,7 @@ int inet_csk_bind_conflict(const struct 
26845                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26846                         if (!reuse || !sk2->sk_reuse ||
26847                             sk2->sk_state == TCP_LISTEN) {
26848 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26849 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26850 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26851 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26852                                         break;
26853                         }
26854                 }
26855 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/inet_diag.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/inet_diag.c
26856 --- linux-2.6.27.10/net/ipv4/inet_diag.c        2008-10-13 14:52:09.000000000 +0200
26857 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/inet_diag.c   2008-10-13 14:54:20.000000000 +0200
26858 @@ -32,6 +32,8 @@
26859  #include <linux/stddef.h>
26860  
26861  #include <linux/inet_diag.h>
26862 +#include <linux/vs_network.h>
26863 +#include <linux/vs_inet.h>
26864  
26865  static const struct inet_diag_handler **inet_diag_table;
26866  
26867 @@ -120,8 +122,8 @@ static int inet_csk_diag_fill(struct soc
26868  
26869         r->id.idiag_sport = inet->sport;
26870         r->id.idiag_dport = inet->dport;
26871 -       r->id.idiag_src[0] = inet->rcv_saddr;
26872 -       r->id.idiag_dst[0] = inet->daddr;
26873 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26874 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26875  
26876  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26877         if (r->idiag_family == AF_INET6) {
26878 @@ -208,8 +210,8 @@ static int inet_twsk_diag_fill(struct in
26879         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26880         r->id.idiag_sport     = tw->tw_sport;
26881         r->id.idiag_dport     = tw->tw_dport;
26882 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26883 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26884 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26885 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26886         r->idiag_state        = tw->tw_substate;
26887         r->idiag_timer        = 3;
26888         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26889 @@ -266,6 +268,7 @@ static int inet_diag_get_exact(struct sk
26890         err = -EINVAL;
26891  
26892         if (req->idiag_family == AF_INET) {
26893 +               /* TODO: lback */
26894                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26895                                  req->id.idiag_dport, req->id.idiag_src[0],
26896                                  req->id.idiag_sport, req->id.idiag_if);
26897 @@ -508,6 +511,7 @@ static int inet_csk_diag_dump(struct soc
26898                 } else
26899  #endif
26900                 {
26901 +                       /* TODO: lback */
26902                         entry.saddr = &inet->rcv_saddr;
26903                         entry.daddr = &inet->daddr;
26904                 }
26905 @@ -544,6 +548,7 @@ static int inet_twsk_diag_dump(struct in
26906                 } else
26907  #endif
26908                 {
26909 +                       /* TODO: lback */
26910                         entry.saddr = &tw->tw_rcv_saddr;
26911                         entry.daddr = &tw->tw_daddr;
26912                 }
26913 @@ -590,8 +595,8 @@ static int inet_diag_fill_req(struct sk_
26914  
26915         r->id.idiag_sport = inet->sport;
26916         r->id.idiag_dport = ireq->rmt_port;
26917 -       r->id.idiag_src[0] = ireq->loc_addr;
26918 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26919 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26920 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26921         r->idiag_expires = jiffies_to_msecs(tmo);
26922         r->idiag_rqueue = 0;
26923         r->idiag_wqueue = 0;
26924 @@ -661,6 +666,7 @@ static int inet_diag_dump_reqs(struct sk
26925                                 continue;
26926  
26927                         if (bc) {
26928 +                               /* TODO: lback */
26929                                 entry.saddr =
26930  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26931                                         (entry.family == AF_INET6) ?
26932 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26933                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
26934                                 struct inet_sock *inet = inet_sk(sk);
26935  
26936 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26937 +                                       continue;
26938                                 if (num < s_num) {
26939                                         num++;
26940                                         continue;
26941 @@ -790,6 +798,8 @@ skip_listen_ht:
26942                 sk_for_each(sk, node, &head->chain) {
26943                         struct inet_sock *inet = inet_sk(sk);
26944  
26945 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26946 +                               continue;
26947                         if (num < s_num)
26948                                 goto next_normal;
26949                         if (!(r->idiag_states & (1 << sk->sk_state)))
26950 @@ -814,6 +824,8 @@ next_normal:
26951                         inet_twsk_for_each(tw, node,
26952                                     &head->twchain) {
26953  
26954 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26955 +                                       continue;
26956                                 if (num < s_num)
26957                                         goto next_dying;
26958                                 if (r->id.idiag_sport != tw->tw_sport &&
26959 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/inet_hashtables.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/inet_hashtables.c
26960 --- linux-2.6.27.10/net/ipv4/inet_hashtables.c  2008-10-13 14:52:09.000000000 +0200
26961 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/inet_hashtables.c     2008-10-13 14:54:20.000000000 +0200
26962 @@ -21,6 +21,7 @@
26963  
26964  #include <net/inet_connection_sock.h>
26965  #include <net/inet_hashtables.h>
26966 +#include <net/route.h>
26967  #include <net/ip.h>
26968  
26969  /*
26970 @@ -163,11 +164,10 @@ static struct sock *inet_lookup_listener
26971                         const __be32 rcv_saddr = inet->rcv_saddr;
26972                         int score = sk->sk_family == PF_INET ? 1 : 0;
26973  
26974 -                       if (rcv_saddr) {
26975 -                               if (rcv_saddr != daddr)
26976 -                                       continue;
26977 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
26978                                 score += 2;
26979 -                       }
26980 +                       else
26981 +                               continue;
26982                         if (sk->sk_bound_dev_if) {
26983                                 if (sk->sk_bound_dev_if != dif)
26984                                         continue;
26985 @@ -199,7 +199,7 @@ struct sock *__inet_lookup_listener(stru
26986                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
26987  
26988                 if (inet->num == hnum && !sk->sk_node.next &&
26989 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
26990 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
26991                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
26992                     !sk->sk_bound_dev_if && net_eq(sock_net(sk), net))
26993                         goto sherry_cache;
26994 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/netfilter/nf_nat_helper.c
26995 --- linux-2.6.27.10/net/ipv4/netfilter/nf_nat_helper.c  2008-07-13 23:51:29.000000000 +0200
26996 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/netfilter/nf_nat_helper.c     2008-10-13 14:54:20.000000000 +0200
26997 @@ -18,6 +18,7 @@
26998  #include <net/tcp.h>
26999  
27000  #include <linux/netfilter_ipv4.h>
27001 +#include <net/route.h>
27002  #include <net/netfilter/nf_conntrack.h>
27003  #include <net/netfilter/nf_conntrack_helper.h>
27004  #include <net/netfilter/nf_conntrack_ecache.h>
27005 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/netfilter.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/netfilter.c
27006 --- linux-2.6.27.10/net/ipv4/netfilter.c        2008-07-13 23:51:29.000000000 +0200
27007 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/netfilter.c   2008-10-13 14:54:20.000000000 +0200
27008 @@ -4,7 +4,7 @@
27009  #include <linux/netfilter_ipv4.h>
27010  #include <linux/ip.h>
27011  #include <linux/skbuff.h>
27012 -#include <net/route.h>
27013 +// #include <net/route.h>
27014  #include <net/xfrm.h>
27015  #include <net/ip.h>
27016  #include <net/netfilter/nf_queue.h>
27017 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/raw.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/raw.c
27018 --- linux-2.6.27.10/net/ipv4/raw.c      2008-10-13 14:52:09.000000000 +0200
27019 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/raw.c 2008-10-13 14:54:20.000000000 +0200
27020 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27021  
27022                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27023                     !(inet->daddr && inet->daddr != raddr)              &&
27024 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27025 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27026                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27027                         goto found; /* gotcha */
27028         }
27029 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
27030                 icmp_out_count(net, ((struct icmphdr *)
27031                         skb_transport_header(skb))->type);
27032  
27033 +       err = -EPERM;
27034 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27035 +               sk->sk_nx_info &&
27036 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27037 +               goto error_free;
27038 +
27039         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27040                       dst_output);
27041         if (err > 0)
27042 @@ -383,6 +389,7 @@ out:
27043  
27044  error_fault:
27045         err = -EFAULT;
27046 +error_free:
27047         kfree_skb(skb);
27048  error:
27049         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
27050 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
27051                 }
27052  
27053                 security_sk_classify_flow(sk, &fl);
27054 +               if (sk->sk_nx_info) {
27055 +                       err = ip_v4_find_src(sock_net(sk),
27056 +                               sk->sk_nx_info, &rt, &fl);
27057 +
27058 +                       if (err)
27059 +                               goto done;
27060 +               }
27061                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27062         }
27063         if (err)
27064 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
27065  {
27066         struct inet_sock *inet = inet_sk(sk);
27067         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27068 +       struct nx_v4_sock_addr nsa = { 0 };
27069         int ret = -EINVAL;
27070         int chk_addr_ret;
27071  
27072         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27073                 goto out;
27074 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27075 +       v4_map_sock_addr(inet, addr, &nsa);
27076 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27077         ret = -EADDRNOTAVAIL;
27078 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27079 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27080             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27081                 goto out;
27082 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27083 +       v4_set_sock_addr(inet, &nsa);
27084         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27085                 inet->saddr = 0;  /* Use device */
27086         sk_dst_reset(sk);
27087 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
27088         /* Copy the address. */
27089         if (sin) {
27090                 sin->sin_family = AF_INET;
27091 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27092 +               sin->sin_addr.s_addr =
27093 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27094                 sin->sin_port = 0;
27095                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27096         }
27097 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
27098                 struct hlist_node *node;
27099  
27100                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27101 -                       if (sock_net(sk) == seq_file_net(seq))
27102 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27103 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27104                                 goto found;
27105         }
27106         sk = NULL;
27107 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
27108                 sk = sk_next(sk);
27109  try_again:
27110                 ;
27111 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27112 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27113 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27114  
27115         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27116                 sk = sk_head(&state->h->ht[state->bucket]);
27117 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
27118  
27119         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27120                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27121 -               i, src, srcp, dest, destp, sp->sk_state,
27122 +               i,
27123 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27124 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27125 +               sp->sk_state,
27126                 atomic_read(&sp->sk_wmem_alloc),
27127                 atomic_read(&sp->sk_rmem_alloc),
27128                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27129 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/syncookies.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/syncookies.c
27130 --- linux-2.6.27.10/net/ipv4/syncookies.c       2008-10-13 14:52:09.000000000 +0200
27131 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/syncookies.c  2008-10-13 14:54:20.000000000 +0200
27132 @@ -16,6 +16,7 @@
27133  #include <linux/cryptohash.h>
27134  #include <linux/kernel.h>
27135  #include <net/tcp.h>
27136 +#include <net/route.h>
27137  
27138  /* Timestamps: lowest 9 bits store TCP options */
27139  #define TSBITS 9
27140 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/tcp.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/tcp.c
27141 --- linux-2.6.27.10/net/ipv4/tcp.c      2008-10-13 14:52:09.000000000 +0200
27142 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/tcp.c 2008-10-13 14:54:20.000000000 +0200
27143 @@ -264,6 +264,7 @@
27144  #include <linux/cache.h>
27145  #include <linux/err.h>
27146  #include <linux/crypto.h>
27147 +#include <linux/in.h>
27148  
27149  #include <net/icmp.h>
27150  #include <net/tcp.h>
27151 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/tcp_ipv4.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/tcp_ipv4.c
27152 --- linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-10-13 14:52:09.000000000 +0200
27153 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/tcp_ipv4.c    2008-10-13 14:54:20.000000000 +0200
27154 @@ -1886,6 +1886,12 @@ static void *listening_get_next(struct s
27155                 req = req->dl_next;
27156                 while (1) {
27157                         while (req) {
27158 +                               vxdprintk(VXD_CBIT(net, 6),
27159 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27160 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27161 +                               if (req->sk &&
27162 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27163 +                                       continue;
27164                                 if (req->rsk_ops->family == st->family) {
27165                                         cur = req;
27166                                         goto out;
27167 @@ -1910,6 +1916,10 @@ get_req:
27168         }
27169  get_sk:
27170         sk_for_each_from(sk, node) {
27171 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27172 +                       sk, sk->sk_nid, nx_current_nid());
27173 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27174 +                       continue;
27175                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27176                         cur = sk;
27177                         goto out;
27178 @@ -1960,6 +1970,11 @@ static void *established_get_first(struc
27179  
27180                 read_lock_bh(lock);
27181                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27182 +                       vxdprintk(VXD_CBIT(net, 6),
27183 +                               "sk,egf: %p [#%d] (from %d)",
27184 +                               sk, sk->sk_nid, nx_current_nid());
27185 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27186 +                               continue;
27187                         if (sk->sk_family != st->family ||
27188                             !net_eq(sock_net(sk), net)) {
27189                                 continue;
27190 @@ -1970,6 +1985,11 @@ static void *established_get_first(struc
27191                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27192                 inet_twsk_for_each(tw, node,
27193                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27194 +                       vxdprintk(VXD_CBIT(net, 6),
27195 +                               "tw: %p [#%d] (from %d)",
27196 +                               tw, tw->tw_nid, nx_current_nid());
27197 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27198 +                               continue;
27199                         if (tw->tw_family != st->family ||
27200                             !net_eq(twsk_net(tw), net)) {
27201                                 continue;
27202 @@ -1998,7 +2018,9 @@ static void *established_get_next(struct
27203                 tw = cur;
27204                 tw = tw_next(tw);
27205  get_tw:
27206 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27207 +               while (tw && (tw->tw_family != st->family ||
27208 +                       !net_eq(twsk_net(tw), net) ||
27209 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27210                         tw = tw_next(tw);
27211                 }
27212                 if (tw) {
27213 @@ -2019,6 +2041,11 @@ get_tw:
27214                 sk = sk_next(sk);
27215  
27216         sk_for_each_from(sk, node) {
27217 +               vxdprintk(VXD_CBIT(net, 6),
27218 +                       "sk,egn: %p [#%d] (from %d)",
27219 +                       sk, sk->sk_nid, nx_current_nid());
27220 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27221 +                       continue;
27222                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27223                         goto found;
27224         }
27225 @@ -2173,9 +2200,9 @@ static void get_openreq4(struct sock *sk
27226         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27227                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27228                 i,
27229 -               ireq->loc_addr,
27230 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27231                 ntohs(inet_sk(sk)->sport),
27232 -               ireq->rmt_addr,
27233 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27234                 ntohs(ireq->rmt_port),
27235                 TCP_SYN_RECV,
27236                 0, 0, /* could print option size, but that is af dependent. */
27237 @@ -2218,7 +2245,10 @@ static void get_tcp4_sock(struct sock *s
27238  
27239         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27240                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27241 -               i, src, srcp, dest, destp, sk->sk_state,
27242 +               i,
27243 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27244 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27245 +               sk->sk_state,
27246                 tp->write_seq - tp->snd_una,
27247                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27248                                              (tp->rcv_nxt - tp->copied_seq),
27249 @@ -2254,7 +2284,10 @@ static void get_timewait4_sock(struct in
27250  
27251         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27252                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27253 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27254 +               i,
27255 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27256 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27257 +               tw->tw_substate, 0, 0,
27258                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27259                 atomic_read(&tw->tw_refcnt), tw, len);
27260  }
27261 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/tcp_minisocks.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/tcp_minisocks.c
27262 --- linux-2.6.27.10/net/ipv4/tcp_minisocks.c    2008-10-13 14:52:09.000000000 +0200
27263 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/tcp_minisocks.c       2008-10-13 14:54:20.000000000 +0200
27264 @@ -26,6 +26,10 @@
27265  #include <net/inet_common.h>
27266  #include <net/xfrm.h>
27267  
27268 +#include <linux/vs_limit.h>
27269 +#include <linux/vs_socket.h>
27270 +#include <linux/vs_context.h>
27271 +
27272  #ifdef CONFIG_SYSCTL
27273  #define SYNC_INIT 0 /* let the user enable it */
27274  #else
27275 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27276                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27277                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27278  
27279 +               tw->tw_xid              = sk->sk_xid;
27280 +               tw->tw_vx_info          = NULL;
27281 +               tw->tw_nid              = sk->sk_nid;
27282 +               tw->tw_nx_info          = NULL;
27283 +
27284  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27285                 if (tw->tw_family == PF_INET6) {
27286                         struct ipv6_pinfo *np = inet6_sk(sk);
27287 diff -NurpP --minimal linux-2.6.27.10/net/ipv4/udp.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/udp.c
27288 --- linux-2.6.27.10/net/ipv4/udp.c      2008-12-19 12:03:15.000000000 +0100
27289 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv4/udp.c 2008-12-19 12:09:14.000000000 +0100
27290 @@ -234,20 +234,14 @@ fail:
27291         return error;
27292  }
27293  
27294 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27295 -{
27296 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27297 -
27298 -       return  ( !ipv6_only_sock(sk2)  &&
27299 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27300 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27301 -}
27302 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27303  
27304  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27305  {
27306         return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal);
27307  }
27308  
27309 +
27310  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27311   * harder than this. -DaveM
27312   */
27313 @@ -267,10 +261,16 @@ static struct sock *__udp4_lib_lookup(st
27314                 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
27315                                 !ipv6_only_sock(sk)) {
27316                         int score = (sk->sk_family == PF_INET ? 1 : 0);
27317 +
27318                         if (inet->rcv_saddr) {
27319                                 if (inet->rcv_saddr != daddr)
27320                                         continue;
27321                                 score+=2;
27322 +                       } else {
27323 +                               /* block non nx_info ips */
27324 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
27325 +                                       daddr, NXA_MASK_BIND))
27326 +                                       continue;
27327                         }
27328                         if (inet->daddr) {
27329                                 if (inet->daddr != saddr)
27330 @@ -296,6 +296,7 @@ static struct sock *__udp4_lib_lookup(st
27331                         }
27332                 }
27333         }
27334 +
27335         if (result)
27336                 sock_hold(result);
27337         read_unlock(&udp_hash_lock);
27338 @@ -318,7 +319,7 @@ static inline struct sock *udp_v4_mcast_
27339                     s->sk_hash != hnum                                  ||
27340                     (inet->daddr && inet->daddr != rmt_addr)            ||
27341                     (inet->dport != rmt_port && inet->dport)            ||
27342 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27343 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27344                     ipv6_only_sock(s)                                   ||
27345                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27346                         continue;
27347 @@ -655,8 +656,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27348                                                { .sport = inet->sport,
27349                                                  .dport = dport } } };
27350                 struct net *net = sock_net(sk);
27351 +               struct nx_info *nxi = sk->sk_nx_info;
27352  
27353                 security_sk_classify_flow(sk, &fl);
27354 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27355 +               if (err)
27356 +                       goto out;
27357 +
27358                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27359                 if (err) {
27360                         if (err == -ENETUNREACH)
27361 @@ -901,7 +907,8 @@ try_again:
27362         {
27363                 sin->sin_family = AF_INET;
27364                 sin->sin_port = udp_hdr(skb)->source;
27365 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27366 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27367 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27368                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27369         }
27370         if (inet->cmsg_flags)
27371 @@ -1530,6 +1537,8 @@ static struct sock *udp_get_first(struct
27372                 sk_for_each(sk, node, state->hashtable + state->bucket) {
27373                         if (!net_eq(sock_net(sk), net))
27374                                 continue;
27375 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27376 +                               continue;
27377                         if (sk->sk_family == state->family)
27378                                 goto found;
27379                 }
27380 @@ -1548,7 +1557,9 @@ static struct sock *udp_get_next(struct 
27381                 sk = sk_next(sk);
27382  try_again:
27383                 ;
27384 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27385 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27386 +               sk->sk_family != state->family ||
27387 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27388  
27389         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
27390                 sk = sk_head(state->hashtable + state->bucket);
27391 @@ -1649,7 +1660,10 @@ static void udp4_format_sock(struct sock
27392  
27393         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27394                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27395 -               bucket, src, srcp, dest, destp, sp->sk_state,
27396 +               bucket,
27397 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27398 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27399 +               sp->sk_state,
27400                 atomic_read(&sp->sk_wmem_alloc),
27401                 atomic_read(&sp->sk_rmem_alloc),
27402                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27403 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/addrconf.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/addrconf.c
27404 --- linux-2.6.27.10/net/ipv6/addrconf.c 2008-10-13 14:52:09.000000000 +0200
27405 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/addrconf.c    2008-11-21 13:32:00.000000000 +0100
27406 @@ -85,6 +85,8 @@
27407  
27408  #include <linux/proc_fs.h>
27409  #include <linux/seq_file.h>
27410 +#include <linux/vs_network.h>
27411 +#include <linux/vs_inet6.h>
27412  
27413  /* Set to 3 to get tracing... */
27414  #define ACONF_DEBUG 2
27415 @@ -1108,7 +1110,7 @@ out:
27416  
27417  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27418                        const struct in6_addr *daddr, unsigned int prefs,
27419 -                      struct in6_addr *saddr)
27420 +                      struct in6_addr *saddr, struct nx_info *nxi)
27421  {
27422         struct ipv6_saddr_score scores[2],
27423                                 *score = &scores[0], *hiscore = &scores[1];
27424 @@ -1181,6 +1183,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27425                                                dev->name);
27426                                 continue;
27427                         }
27428 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27429 +                               continue;
27430  
27431                         score->rule = -1;
27432                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27433 @@ -1364,35 +1368,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27434         return ifp;
27435  }
27436  
27437 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27438 +
27439  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27440  {
27441         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27442         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27443 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27444         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27445         int sk_ipv6only = ipv6_only_sock(sk);
27446         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27447         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27448         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27449  
27450 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27451 +       /* FIXME: needs handling for v4 ANY */
27452 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27453                 return 1;
27454  
27455         if (addr_type2 == IPV6_ADDR_ANY &&
27456 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27457 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27458 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27459                 return 1;
27460  
27461         if (addr_type == IPV6_ADDR_ANY &&
27462 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27463 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27464 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27465 +               return 1;
27466 +
27467 +       if (addr_type == IPV6_ADDR_ANY &&
27468 +           addr_type2 == IPV6_ADDR_ANY &&
27469 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27470                 return 1;
27471  
27472         if (sk2_rcv_saddr6 &&
27473 +           addr_type != IPV6_ADDR_ANY &&
27474 +           addr_type != IPV6_ADDR_ANY &&
27475             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27476                 return 1;
27477  
27478         if (addr_type == IPV6_ADDR_MAPPED &&
27479             !sk2_ipv6only &&
27480 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27481 +           ipv4_rcv_saddr_equal(sk, sk2))
27482                 return 1;
27483  
27484         return 0;
27485 @@ -2986,7 +3001,10 @@ static void if6_seq_stop(struct seq_file
27486  static int if6_seq_show(struct seq_file *seq, void *v)
27487  {
27488         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27489 -       seq_printf(seq,
27490 +
27491 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27492 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27493 +               seq_printf(seq,
27494                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
27495                    NIP6(ifp->addr),
27496                    ifp->idev->dev->ifindex,
27497 @@ -3481,6 +3499,12 @@ static int inet6_dump_addr(struct sk_buf
27498         struct ifmcaddr6 *ifmca;
27499         struct ifacaddr6 *ifaca;
27500         struct net *net = sock_net(skb->sk);
27501 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27502 +
27503 +       /* disable ipv6 on non v6 guests */
27504 +       if (nxi && !nx_info_has_v6(nxi))
27505 +               return skb->len;
27506 +
27507  
27508         s_idx = cb->args[0];
27509         s_ip_idx = ip_idx = cb->args[1];
27510 @@ -3502,6 +3526,8 @@ static int inet6_dump_addr(struct sk_buf
27511                              ifa = ifa->if_next, ip_idx++) {
27512                                 if (ip_idx < s_ip_idx)
27513                                         continue;
27514 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27515 +                                       continue;
27516                                 err = inet6_fill_ifaddr(skb, ifa,
27517                                                         NETLINK_CB(cb->skb).pid,
27518                                                         cb->nlh->nlmsg_seq,
27519 @@ -3515,6 +3541,8 @@ static int inet6_dump_addr(struct sk_buf
27520                              ifmca = ifmca->next, ip_idx++) {
27521                                 if (ip_idx < s_ip_idx)
27522                                         continue;
27523 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27524 +                                       continue;
27525                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27526                                                           NETLINK_CB(cb->skb).pid,
27527                                                           cb->nlh->nlmsg_seq,
27528 @@ -3528,6 +3556,8 @@ static int inet6_dump_addr(struct sk_buf
27529                              ifaca = ifaca->aca_next, ip_idx++) {
27530                                 if (ip_idx < s_ip_idx)
27531                                         continue;
27532 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27533 +                                       continue;
27534                                 err = inet6_fill_ifacaddr(skb, ifaca,
27535                                                           NETLINK_CB(cb->skb).pid,
27536                                                           cb->nlh->nlmsg_seq,
27537 @@ -3813,12 +3843,19 @@ static int inet6_dump_ifinfo(struct sk_b
27538         int s_idx = cb->args[0];
27539         struct net_device *dev;
27540         struct inet6_dev *idev;
27541 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27542 +
27543 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27544 +       if (skb->sk && skb->sk->sk_vx_info)
27545 +               return skb->len; */
27546  
27547         read_lock(&dev_base_lock);
27548         idx = 0;
27549         for_each_netdev(net, dev) {
27550                 if (idx < s_idx)
27551                         goto cont;
27552 +               if (!v6_dev_in_nx_info(dev, nxi))
27553 +                       goto cont;
27554                 if ((idev = in6_dev_get(dev)) == NULL)
27555                         goto cont;
27556                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27557 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/af_inet6.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/af_inet6.c
27558 --- linux-2.6.27.10/net/ipv6/af_inet6.c 2008-10-13 14:52:09.000000000 +0200
27559 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/af_inet6.c    2008-10-13 14:54:20.000000000 +0200
27560 @@ -41,6 +41,8 @@
27561  #include <linux/netdevice.h>
27562  #include <linux/icmpv6.h>
27563  #include <linux/netfilter_ipv6.h>
27564 +#include <linux/vs_inet.h>
27565 +#include <linux/vs_inet6.h>
27566  
27567  #include <net/ip.h>
27568  #include <net/ipv6.h>
27569 @@ -49,6 +51,7 @@
27570  #include <net/tcp.h>
27571  #include <net/ipip.h>
27572  #include <net/protocol.h>
27573 +#include <net/route.h>
27574  #include <net/inet_common.h>
27575  #include <net/transp_v6.h>
27576  #include <net/ip6_route.h>
27577 @@ -141,9 +144,12 @@ lookup_protocol:
27578         }
27579  
27580         err = -EPERM;
27581 +       if ((protocol == IPPROTO_ICMPV6) &&
27582 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27583 +               goto override;
27584         if (answer->capability > 0 && !capable(answer->capability))
27585                 goto out_rcu_unlock;
27586 -
27587 +override:
27588         sock->ops = answer->ops;
27589         answer_prot = answer->prot;
27590         answer_no_check = answer->no_check;
27591 @@ -242,6 +248,7 @@ int inet6_bind(struct socket *sock, stru
27592         struct inet_sock *inet = inet_sk(sk);
27593         struct ipv6_pinfo *np = inet6_sk(sk);
27594         struct net *net = sock_net(sk);
27595 +       struct nx_v6_sock_addr nsa;
27596         __be32 v4addr = 0;
27597         unsigned short snum;
27598         int addr_type = 0;
27599 @@ -253,6 +260,11 @@ int inet6_bind(struct socket *sock, stru
27600  
27601         if (addr_len < SIN6_LEN_RFC2133)
27602                 return -EINVAL;
27603 +
27604 +       err = v6_map_sock_addr(inet, addr, &nsa);
27605 +       if (err)
27606 +               return err;
27607 +
27608         addr_type = ipv6_addr_type(&addr->sin6_addr);
27609         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27610                 return -EINVAL;
27611 @@ -276,6 +288,10 @@ int inet6_bind(struct socket *sock, stru
27612                         err = -EADDRNOTAVAIL;
27613                         goto out;
27614                 }
27615 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27616 +                       err = -EADDRNOTAVAIL;
27617 +                       goto out;
27618 +               }
27619         } else {
27620                 if (addr_type != IPV6_ADDR_ANY) {
27621                         struct net_device *dev = NULL;
27622 @@ -301,6 +317,11 @@ int inet6_bind(struct socket *sock, stru
27623                                 }
27624                         }
27625  
27626 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27627 +                               err = -EADDRNOTAVAIL;
27628 +                               goto out;
27629 +                       }
27630 +
27631                         /* ipv4 addr of the socket is invalid.  Only the
27632                          * unspecified and mapped address have a v4 equivalent.
27633                          */
27634 @@ -319,6 +340,8 @@ int inet6_bind(struct socket *sock, stru
27635                 }
27636         }
27637  
27638 +       v6_set_sock_addr(inet, &nsa);
27639 +
27640         inet->rcv_saddr = v4addr;
27641         inet->saddr = v4addr;
27642  
27643 @@ -411,9 +434,11 @@ int inet6_getname(struct socket *sock, s
27644                         return -ENOTCONN;
27645                 sin->sin6_port = inet->dport;
27646                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27647 +               /* FIXME: remap lback? */
27648                 if (np->sndflow)
27649                         sin->sin6_flowinfo = np->flow_label;
27650         } else {
27651 +               /* FIXME: remap lback? */
27652                 if (ipv6_addr_any(&np->rcv_saddr))
27653                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27654                 else
27655 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/fib6_rules.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/fib6_rules.c
27656 --- linux-2.6.27.10/net/ipv6/fib6_rules.c       2008-10-13 14:52:09.000000000 +0200
27657 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/fib6_rules.c  2008-10-13 14:54:20.000000000 +0200
27658 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27659                         if (ipv6_dev_get_saddr(net,
27660                                                ip6_dst_idev(&rt->u.dst)->dev,
27661                                                &flp->fl6_dst, srcprefs,
27662 -                                              &saddr))
27663 +                                              &saddr, NULL))
27664                                 goto again;
27665                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27666                                                r->src.plen))
27667 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/inet6_hashtables.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/inet6_hashtables.c
27668 --- linux-2.6.27.10/net/ipv6/inet6_hashtables.c 2008-10-13 14:52:09.000000000 +0200
27669 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/inet6_hashtables.c    2008-10-13 14:54:20.000000000 +0200
27670 @@ -16,6 +16,7 @@
27671  
27672  #include <linux/module.h>
27673  #include <linux/random.h>
27674 +#include <linux/vs_inet6.h>
27675  
27676  #include <net/inet_connection_sock.h>
27677  #include <net/inet_hashtables.h>
27678 @@ -115,6 +116,9 @@ struct sock *inet6_lookup_listener(struc
27679                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27680                                         continue;
27681                                 score++;
27682 +                       } else {
27683 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27684 +                                       continue;
27685                         }
27686                         if (sk->sk_bound_dev_if) {
27687                                 if (sk->sk_bound_dev_if != dif)
27688 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/ip6_output.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/ip6_output.c
27689 --- linux-2.6.27.10/net/ipv6/ip6_output.c       2008-10-13 14:52:09.000000000 +0200
27690 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/ip6_output.c  2008-10-13 14:54:20.000000000 +0200
27691 @@ -937,7 +937,7 @@ static int ip6_dst_lookup_tail(struct so
27692                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27693                                          &fl->fl6_dst,
27694                                          sk ? inet6_sk(sk)->srcprefs : 0,
27695 -                                        &fl->fl6_src);
27696 +                                        &fl->fl6_src, sk->sk_nx_info);
27697                 if (err)
27698                         goto out_err_release;
27699         }
27700 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/Kconfig linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/Kconfig
27701 --- linux-2.6.27.10/net/ipv6/Kconfig    2008-10-13 14:52:09.000000000 +0200
27702 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/Kconfig       2008-10-13 14:54:20.000000000 +0200
27703 @@ -4,8 +4,8 @@
27704  
27705  #   IPv6 as module will cause a CRASH if you try to unload it
27706  menuconfig IPV6
27707 -       tristate "The IPv6 protocol"
27708 -       default m
27709 +       bool "The IPv6 protocol"
27710 +       default n
27711         ---help---
27712           This is complemental support for the IP version 6.
27713           You will still be able to do traditional IPv4 networking as well.
27714 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/ndisc.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/ndisc.c
27715 --- linux-2.6.27.10/net/ipv6/ndisc.c    2008-10-13 14:52:09.000000000 +0200
27716 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/ndisc.c       2008-10-13 14:54:20.000000000 +0200
27717 @@ -551,7 +551,7 @@ static void ndisc_send_na(struct net_dev
27718         } else {
27719                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27720                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27721 -                                      &tmpaddr))
27722 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27723                         return;
27724                 src_addr = &tmpaddr;
27725         }
27726 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/raw.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/raw.c
27727 --- linux-2.6.27.10/net/ipv6/raw.c      2008-10-13 14:52:09.000000000 +0200
27728 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/raw.c 2008-11-21 13:32:00.000000000 +0100
27729 @@ -29,6 +29,7 @@
27730  #include <linux/icmpv6.h>
27731  #include <linux/netfilter.h>
27732  #include <linux/netfilter_ipv6.h>
27733 +#include <linux/vs_inet6.h>
27734  #include <linux/skbuff.h>
27735  #include <asm/uaccess.h>
27736  #include <asm/ioctls.h>
27737 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27738                         }
27739                 }
27740  
27741 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27742 +                       err = -EADDRNOTAVAIL;
27743 +                       if (dev)
27744 +                               dev_put(dev);
27745 +                       goto out;
27746 +               }
27747 +
27748                 /* ipv4 addr of the socket is invalid.  Only the
27749                  * unspecified and mapped address have a v4 equivalent.
27750                  */
27751 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/route.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/route.c
27752 --- linux-2.6.27.10/net/ipv6/route.c    2008-10-13 14:52:09.000000000 +0200
27753 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/route.c       2008-10-13 14:54:20.000000000 +0200
27754 @@ -2191,7 +2191,8 @@ static int rt6_fill_node(struct net *net
27755                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27756                 struct in6_addr saddr_buf;
27757                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27758 -                                      dst, 0, &saddr_buf) == 0)
27759 +                       dst, 0, &saddr_buf,
27760 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27761                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27762         }
27763  
27764 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/tcp_ipv6.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/tcp_ipv6.c
27765 --- linux-2.6.27.10/net/ipv6/tcp_ipv6.c 2008-12-19 12:03:15.000000000 +0100
27766 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/tcp_ipv6.c    2008-11-17 18:20:41.000000000 +0100
27767 @@ -67,6 +67,7 @@
27768  
27769  #include <linux/crypto.h>
27770  #include <linux/scatterlist.h>
27771 +#include <linux/vs_inet6.h>
27772  
27773  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27774  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27775 @@ -155,8 +156,15 @@ static int tcp_v6_connect(struct sock *s
27776          *      connect() to INADDR_ANY means loopback (BSD'ism).
27777          */
27778  
27779 -       if(ipv6_addr_any(&usin->sin6_addr))
27780 -               usin->sin6_addr.s6_addr[15] = 0x1;
27781 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27782 +               struct nx_info *nxi =  sk->sk_nx_info;
27783 +
27784 +               if (nxi && nx_info_has_v6(nxi))
27785 +                       /* FIXME: remap lback? */
27786 +                       usin->sin6_addr = nxi->v6.ip;
27787 +               else
27788 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27789 +       }
27790  
27791         addr_type = ipv6_addr_type(&usin->sin6_addr);
27792  
27793 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/udp.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/udp.c
27794 --- linux-2.6.27.10/net/ipv6/udp.c      2008-12-19 12:03:15.000000000 +0100
27795 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/udp.c 2008-12-19 12:09:14.000000000 +0100
27796 @@ -47,6 +47,7 @@
27797  
27798  #include <linux/proc_fs.h>
27799  #include <linux/seq_file.h>
27800 +#include <linux/vs_inet6.h>
27801  #include "udp_impl.h"
27802  
27803  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27804 @@ -81,6 +82,10 @@ static struct sock *__udp6_lib_lookup(st
27805                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27806                                         continue;
27807                                 score++;
27808 +                       } else {
27809 +                               /* block non nx_info ips */
27810 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27811 +                                       continue;
27812                         }
27813                         if (!ipv6_addr_any(&np->daddr)) {
27814                                 if (!ipv6_addr_equal(&np->daddr, saddr))
27815 diff -NurpP --minimal linux-2.6.27.10/net/ipv6/xfrm6_policy.c linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/xfrm6_policy.c
27816 --- linux-2.6.27.10/net/ipv6/xfrm6_policy.c     2008-10-13 14:52:09.000000000 +0200
27817 +++ linux-2.6.27.10-vs2.3.0.36.4/net/ipv6/xfrm6_policy.c        2008-10-13 14:54:20.000000000 +0200
27818 @@ -61,7 +61,7 @@ static int xfrm6_get_saddr(xfrm_address_
27819         dev = ip6_dst_idev(dst)->dev;
27820         ipv6_dev_get_saddr(dev_net(dev), dev,
27821                            (struct in6_addr *)&daddr->a6, 0,
27822 -                          (struct in6_addr *)&saddr->a6);
27823 +                          (struct in6_addr *)&saddr->a6, NULL);
27824         dst_release(dst);
27825         return 0;
27826  }
27827 diff -NurpP --minimal linux-2.6.27.10/net/Kconfig linux-2.6.27.10-vs2.3.0.36.4/net/Kconfig
27828 --- linux-2.6.27.10/net/Kconfig 2008-10-13 14:52:09.000000000 +0200
27829 +++ linux-2.6.27.10-vs2.3.0.36.4/net/Kconfig    2008-11-20 15:21:32.000000000 +0100
27830 @@ -27,7 +27,7 @@ menu "Networking options"
27831  config NET_NS
27832         bool "Network namespace support"
27833         default n
27834 -       depends on EXPERIMENTAL && !SYSFS && NAMESPACES
27835 +       depends on EXPERIMENTAL && NAMESPACES
27836         help
27837           Allow user space to create what appear to be multiple instances
27838           of the network stack.
27839 diff -NurpP --minimal linux-2.6.27.10/net/netlink/af_netlink.c linux-2.6.27.10-vs2.3.0.36.4/net/netlink/af_netlink.c
27840 --- linux-2.6.27.10/net/netlink/af_netlink.c    2008-10-13 14:52:09.000000000 +0200
27841 +++ linux-2.6.27.10-vs2.3.0.36.4/net/netlink/af_netlink.c       2008-10-13 14:54:20.000000000 +0200
27842 @@ -55,6 +55,9 @@
27843  #include <linux/types.h>
27844  #include <linux/audit.h>
27845  #include <linux/mutex.h>
27846 +#include <linux/vs_context.h>
27847 +#include <linux/vs_network.h>
27848 +#include <linux/vs_limit.h>
27849  
27850  #include <net/net_namespace.h>
27851  #include <net/sock.h>
27852 @@ -1761,6 +1764,8 @@ static struct sock *netlink_seq_socket_i
27853                         sk_for_each(s, node, &hash->table[j]) {
27854                                 if (sock_net(s) != seq_file_net(seq))
27855                                         continue;
27856 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27857 +                                       continue;
27858                                 if (off == pos) {
27859                                         iter->link = i;
27860                                         iter->hash_idx = j;
27861 @@ -1795,7 +1800,8 @@ static void *netlink_seq_next(struct seq
27862         s = v;
27863         do {
27864                 s = sk_next(s);
27865 -       } while (s && sock_net(s) != seq_file_net(seq));
27866 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27867 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27868         if (s)
27869                 return s;
27870  
27871 @@ -1807,7 +1813,8 @@ static void *netlink_seq_next(struct seq
27872  
27873                 for (; j <= hash->mask; j++) {
27874                         s = sk_head(&hash->table[j]);
27875 -                       while (s && sock_net(s) != seq_file_net(seq))
27876 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27877 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27878                                 s = sk_next(s);
27879                         if (s) {
27880                                 iter->link = i;
27881 diff -NurpP --minimal linux-2.6.27.10/net/sctp/ipv6.c linux-2.6.27.10-vs2.3.0.36.4/net/sctp/ipv6.c
27882 --- linux-2.6.27.10/net/sctp/ipv6.c     2008-10-13 14:52:09.000000000 +0200
27883 +++ linux-2.6.27.10-vs2.3.0.36.4/net/sctp/ipv6.c        2008-10-13 14:54:20.000000000 +0200
27884 @@ -323,7 +323,8 @@ static void sctp_v6_get_saddr(struct sct
27885                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27886                                    &daddr->v6.sin6_addr,
27887                                    inet6_sk(&sk->inet.sk)->srcprefs,
27888 -                                  &saddr->v6.sin6_addr);
27889 +                                  &saddr->v6.sin6_addr,
27890 +                                  asoc->base.sk->sk_nx_info);
27891                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
27892                                   NIP6(saddr->v6.sin6_addr));
27893                 return;
27894 diff -NurpP --minimal linux-2.6.27.10/net/socket.c linux-2.6.27.10-vs2.3.0.36.4/net/socket.c
27895 --- linux-2.6.27.10/net/socket.c        2008-10-13 14:52:09.000000000 +0200
27896 +++ linux-2.6.27.10-vs2.3.0.36.4/net/socket.c   2008-10-13 14:54:20.000000000 +0200
27897 @@ -96,6 +96,10 @@
27898  
27899  #include <net/sock.h>
27900  #include <linux/netfilter.h>
27901 +#include <linux/vs_base.h>
27902 +#include <linux/vs_socket.h>
27903 +#include <linux/vs_inet.h>
27904 +#include <linux/vs_inet6.h>
27905  
27906  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27907  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27908 @@ -550,7 +554,7 @@ static inline int __sock_sendmsg(struct 
27909                                  struct msghdr *msg, size_t size)
27910  {
27911         struct sock_iocb *si = kiocb_to_siocb(iocb);
27912 -       int err;
27913 +       int err, len;
27914  
27915         si->sock = sock;
27916         si->scm = NULL;
27917 @@ -561,7 +565,22 @@ static inline int __sock_sendmsg(struct 
27918         if (err)
27919                 return err;
27920  
27921 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27922 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27923 +       if (sock->sk) {
27924 +               if (len == size)
27925 +                       vx_sock_send(sock->sk, size);
27926 +               else
27927 +                       vx_sock_fail(sock->sk, size);
27928 +       }
27929 +       vxdprintk(VXD_CBIT(net, 7),
27930 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27931 +               sock, sock->sk,
27932 +               (sock->sk)?sock->sk->sk_nx_info:0,
27933 +               (sock->sk)?sock->sk->sk_vx_info:0,
27934 +               (sock->sk)?sock->sk->sk_xid:0,
27935 +               (sock->sk)?sock->sk->sk_nid:0,
27936 +               (unsigned int)size, len);
27937 +       return len;
27938  }
27939  
27940  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27941 @@ -630,7 +649,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27942  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27943                                  struct msghdr *msg, size_t size, int flags)
27944  {
27945 -       int err;
27946 +       int err, len;
27947         struct sock_iocb *si = kiocb_to_siocb(iocb);
27948  
27949         si->sock = sock;
27950 @@ -643,7 +662,18 @@ static inline int __sock_recvmsg(struct 
27951         if (err)
27952                 return err;
27953  
27954 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27955 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27956 +       if ((len >= 0) && sock->sk)
27957 +               vx_sock_recv(sock->sk, len);
27958 +       vxdprintk(VXD_CBIT(net, 7),
27959 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27960 +               sock, sock->sk,
27961 +               (sock->sk)?sock->sk->sk_nx_info:0,
27962 +               (sock->sk)?sock->sk->sk_vx_info:0,
27963 +               (sock->sk)?sock->sk->sk_xid:0,
27964 +               (sock->sk)?sock->sk->sk_nid:0,
27965 +               (unsigned int)size, len);
27966 +       return len;
27967  }
27968  
27969  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27970 @@ -1108,6 +1138,13 @@ static int __sock_create(struct net *net
27971         if (type < 0 || type >= SOCK_MAX)
27972                 return -EINVAL;
27973  
27974 +       if (!nx_check(0, VS_ADMIN)) {
27975 +               if (family == PF_INET && !current_nx_info_has_v4())
27976 +                       return -EAFNOSUPPORT;
27977 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27978 +                       return -EAFNOSUPPORT;
27979 +       }
27980 +
27981         /* Compatibility.
27982  
27983            This uglymoron is moved from INET layer to here to avoid
27984 @@ -1240,6 +1277,7 @@ asmlinkage long sys_socket(int family, i
27985         if (retval < 0)
27986                 goto out;
27987  
27988 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27989         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27990         if (retval < 0)
27991                 goto out_release;
27992 @@ -1281,10 +1319,12 @@ asmlinkage long sys_socketpair(int famil
27993         err = sock_create(family, type, protocol, &sock1);
27994         if (err < 0)
27995                 goto out;
27996 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27997  
27998         err = sock_create(family, type, protocol, &sock2);
27999         if (err < 0)
28000                 goto out_release_1;
28001 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28002  
28003         err = sock1->ops->socketpair(sock1, sock2);
28004         if (err < 0)
28005 diff -NurpP --minimal linux-2.6.27.10/net/sunrpc/auth.c linux-2.6.27.10-vs2.3.0.36.4/net/sunrpc/auth.c
28006 --- linux-2.6.27.10/net/sunrpc/auth.c   2008-07-13 23:51:29.000000000 +0200
28007 +++ linux-2.6.27.10-vs2.3.0.36.4/net/sunrpc/auth.c      2008-10-13 14:54:20.000000000 +0200
28008 @@ -14,6 +14,7 @@
28009  #include <linux/hash.h>
28010  #include <linux/sunrpc/clnt.h>
28011  #include <linux/spinlock.h>
28012 +#include <linux/vs_tag.h>
28013  
28014  #ifdef RPC_DEBUG
28015  # define RPCDBG_FACILITY       RPCDBG_AUTH
28016 @@ -353,6 +354,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28017         struct auth_cred acred = {
28018                 .uid = current->fsuid,
28019                 .gid = current->fsgid,
28020 +               .tag = dx_current_tag(),
28021                 .group_info = current->group_info,
28022         };
28023         struct rpc_cred *ret;
28024 @@ -398,6 +400,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28025         struct auth_cred acred = {
28026                 .uid = 0,
28027                 .gid = 0,
28028 +               .tag = dx_current_tag(),
28029         };
28030         struct rpc_cred *ret;
28031  
28032 diff -NurpP --minimal linux-2.6.27.10/net/sunrpc/auth_unix.c linux-2.6.27.10-vs2.3.0.36.4/net/sunrpc/auth_unix.c
28033 --- linux-2.6.27.10/net/sunrpc/auth_unix.c      2008-10-13 14:52:09.000000000 +0200
28034 +++ linux-2.6.27.10-vs2.3.0.36.4/net/sunrpc/auth_unix.c 2008-10-13 14:54:20.000000000 +0200
28035 @@ -11,12 +11,14 @@
28036  #include <linux/module.h>
28037  #include <linux/sunrpc/clnt.h>
28038  #include <linux/sunrpc/auth.h>
28039 +#include <linux/vs_tag.h>
28040  
28041  #define NFS_NGROUPS    16
28042  
28043  struct unx_cred {
28044         struct rpc_cred         uc_base;
28045         gid_t                   uc_gid;
28046 +       tag_t                   uc_tag;
28047         gid_t                   uc_gids[NFS_NGROUPS];
28048  };
28049  #define uc_uid                 uc_base.cr_uid
28050 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28051                 groups = NFS_NGROUPS;
28052  
28053         cred->uc_gid = acred->gid;
28054 +       cred->uc_tag = acred->tag;
28055         for (i = 0; i < groups; i++)
28056                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28057         if (i < NFS_NGROUPS)
28058 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28059         unsigned int i;
28060  
28061  
28062 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28063 +       if (cred->uc_uid != acred->uid ||
28064 +               cred->uc_gid != acred->gid ||
28065 +               cred->uc_tag != acred->tag)
28066                 return 0;
28067  
28068         if (acred->group_info != NULL)
28069 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
28070         struct rpc_clnt *clnt = task->tk_client;
28071         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28072         __be32          *base, *hold;
28073 -       int             i;
28074 +       int             i, tag;
28075  
28076         *p++ = htonl(RPC_AUTH_UNIX);
28077         base = p++;
28078 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
28079          * Copy the UTS nodename captured when the client was created.
28080          */
28081         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28082 +       tag = task->tk_client->cl_tag;
28083  
28084 -       *p++ = htonl((u32) cred->uc_uid);
28085 -       *p++ = htonl((u32) cred->uc_gid);
28086 +       *p++ = htonl((u32) TAGINO_UID(tag,
28087 +               cred->uc_uid, cred->uc_tag));
28088 +       *p++ = htonl((u32) TAGINO_GID(tag,
28089 +               cred->uc_gid, cred->uc_tag));
28090         hold = p++;
28091         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28092                 *p++ = htonl((u32) cred->uc_gids[i]);
28093 diff -NurpP --minimal linux-2.6.27.10/net/sunrpc/clnt.c linux-2.6.27.10-vs2.3.0.36.4/net/sunrpc/clnt.c
28094 --- linux-2.6.27.10/net/sunrpc/clnt.c   2008-10-13 14:52:09.000000000 +0200
28095 +++ linux-2.6.27.10-vs2.3.0.36.4/net/sunrpc/clnt.c      2008-10-13 14:54:20.000000000 +0200
28096 @@ -32,6 +32,7 @@
28097  #include <linux/utsname.h>
28098  #include <linux/workqueue.h>
28099  #include <linux/in6.h>
28100 +#include <linux/vs_cvirt.h>
28101  
28102  #include <linux/sunrpc/clnt.h>
28103  #include <linux/sunrpc/rpc_pipe_fs.h>
28104 @@ -327,6 +328,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28105         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28106                 clnt->cl_chatty = 1;
28107  
28108 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28109 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28110 +               clnt->cl_tag = 1; */
28111         return clnt;
28112  }
28113  EXPORT_SYMBOL_GPL(rpc_create);
28114 diff -NurpP --minimal linux-2.6.27.10/net/unix/af_unix.c linux-2.6.27.10-vs2.3.0.36.4/net/unix/af_unix.c
28115 --- linux-2.6.27.10/net/unix/af_unix.c  2008-12-19 12:03:15.000000000 +0100
28116 +++ linux-2.6.27.10-vs2.3.0.36.4/net/unix/af_unix.c     2008-12-19 12:09:14.000000000 +0100
28117 @@ -114,6 +114,8 @@
28118  #include <linux/mount.h>
28119  #include <net/checksum.h>
28120  #include <linux/security.h>
28121 +#include <linux/vs_context.h>
28122 +#include <linux/vs_limit.h>
28123  
28124  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28125  static DEFINE_SPINLOCK(unix_table_lock);
28126 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28127                 if (!net_eq(sock_net(s), net))
28128                         continue;
28129  
28130 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28131 +                       continue;
28132                 if (u->addr->len == len &&
28133                     !memcmp(u->addr->name, sunname, len))
28134                         goto found;
28135 @@ -2103,6 +2107,8 @@ static struct sock *unix_seq_idx(struct 
28136         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28137                 if (sock_net(s) != seq_file_net(seq))
28138                         continue;
28139 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28140 +                       continue;
28141                 if (off == pos)
28142                         return s;
28143                 ++off;
28144 @@ -2128,7 +2134,8 @@ static void *unix_seq_next(struct seq_fi
28145                 sk = first_unix_socket(&iter->i);
28146         else
28147                 sk = next_unix_socket(&iter->i, sk);
28148 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28149 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28150 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28151                 sk = next_unix_socket(&iter->i, sk);
28152         return sk;
28153  }
28154 diff -NurpP --minimal linux-2.6.27.10/net/x25/af_x25.c linux-2.6.27.10-vs2.3.0.36.4/net/x25/af_x25.c
28155 --- linux-2.6.27.10/net/x25/af_x25.c    2008-10-13 14:52:10.000000000 +0200
28156 +++ linux-2.6.27.10-vs2.3.0.36.4/net/x25/af_x25.c       2008-10-13 14:54:20.000000000 +0200
28157 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
28158  
28159         x25 = x25_sk(sk);
28160  
28161 -       sock_init_data(sock, sk);
28162 +       sk->sk_socket = sock;
28163 +       sk->sk_type = sock->type;
28164 +       sk->sk_sleep = &sock->wait;
28165 +       sock->sk = sk;
28166  
28167         x25_init_timers(sk);
28168  
28169 diff -NurpP --minimal linux-2.6.27.10/scripts/checksyscalls.sh linux-2.6.27.10-vs2.3.0.36.4/scripts/checksyscalls.sh
28170 --- linux-2.6.27.10/scripts/checksyscalls.sh    2008-07-13 23:51:29.000000000 +0200
28171 +++ linux-2.6.27.10-vs2.3.0.36.4/scripts/checksyscalls.sh       2008-10-13 14:54:20.000000000 +0200
28172 @@ -108,7 +108,6 @@ cat << EOF
28173  #define __IGNORE_afs_syscall
28174  #define __IGNORE_getpmsg
28175  #define __IGNORE_putpmsg
28176 -#define __IGNORE_vserver
28177  EOF
28178  }
28179  
28180 diff -NurpP --minimal linux-2.6.27.10/security/commoncap.c linux-2.6.27.10-vs2.3.0.36.4/security/commoncap.c
28181 --- linux-2.6.27.10/security/commoncap.c        2008-12-19 12:03:15.000000000 +0100
28182 +++ linux-2.6.27.10-vs2.3.0.36.4/security/commoncap.c   2008-11-17 18:20:42.000000000 +0100
28183 @@ -26,10 +26,11 @@
28184  #include <linux/sched.h>
28185  #include <linux/prctl.h>
28186  #include <linux/securebits.h>
28187 +#include <linux/vs_context.h>
28188  
28189  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28190  {
28191 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
28192 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current->cap_effective);
28193         return 0;
28194  }
28195  
28196 @@ -50,9 +51,24 @@ EXPORT_SYMBOL(cap_netlink_recv);
28197   */
28198  int cap_capable (struct task_struct *tsk, int cap)
28199  {
28200 +       struct vx_info *vxi = tsk->vx_info;
28201 +
28202 +#if 0
28203 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28204 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28205 +               cap_raised(tsk->cap_effective, cap),
28206 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28207 +#endif
28208 +
28209 +       /* special case SETUP */
28210 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28211 +               cap_raised(tsk->cap_effective, cap))
28212 +               return 0;
28213 +
28214         /* Derived from include/linux/sched.h:capable. */
28215 -       if (cap_raised(tsk->cap_effective, cap))
28216 +       if (vx_cap_raised(vxi, tsk->cap_effective, cap))
28217                 return 0;
28218 +
28219         return -EPERM;
28220  }
28221  
28222 @@ -696,7 +712,8 @@ void cap_task_reparent_to_init (struct t
28223  
28224  int cap_syslog (int type)
28225  {
28226 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28227 +       if ((type != 3 && type != 10) &&
28228 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28229                 return -EPERM;
28230         return 0;
28231  }
28232 diff -NurpP --minimal linux-2.6.27.10/security/selinux/hooks.c linux-2.6.27.10-vs2.3.0.36.4/security/selinux/hooks.c
28233 --- linux-2.6.27.10/security/selinux/hooks.c    2008-10-13 14:52:10.000000000 +0200
28234 +++ linux-2.6.27.10-vs2.3.0.36.4/security/selinux/hooks.c       2008-10-13 14:54:20.000000000 +0200
28235 @@ -64,7 +64,6 @@
28236  #include <linux/dccp.h>
28237  #include <linux/quota.h>
28238  #include <linux/un.h>          /* for Unix socket types */
28239 -#include <net/af_unix.h>       /* for Unix socket types */
28240  #include <linux/parser.h>
28241  #include <linux/nfs_mount.h>
28242  #include <net/ipv6.h>
This page took 2.44503 seconds and 3 git commands to generate.